blob: 30a6f03449861181a9c5eeb13fdffec614c07462 [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
arunvoddub1365e62024-07-31 09:42:31 +0000483 private static final int LINE1_NUMBER_MAX_LEN = 50;
484
sandeepjsb6c87872021-09-27 15:34:44 +0000485 /**
486 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
487 * one ICCID active at the same time.
488 * Apps should use below API signatures if targeting SDK is T and beyond.
489 *
490 * @hide
491 */
492 @ChangeId
493 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
494 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800495
Naina Nallurid63128d2019-09-17 14:10:30 -0700496 /**
Chen Xu540470b2021-12-14 17:15:47 -0800497 * Apps targeting on Android T and beyond will get exception whenever icc close channel
498 * operation fails.
499 */
500 @ChangeId
501 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
502 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
503
504 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700505 * A request object to use for transmitting data to an ICC.
506 */
507 private static final class IccAPDUArgument {
508 public int channel, cla, command, p1, p2, p3;
509 public String data;
510
511 public IccAPDUArgument(int channel, int cla, int command,
512 int p1, int p2, int p3, String data) {
513 this.channel = channel;
514 this.cla = cla;
515 this.command = command;
516 this.p1 = p1;
517 this.p2 = p2;
518 this.p3 = p3;
519 this.data = data;
520 }
521 }
522
523 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700524 * A request object to use for transmitting data to an ICC.
525 */
526 private static final class ManualNetworkSelectionArgument {
527 public OperatorInfo operatorInfo;
528 public boolean persistSelection;
529
530 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
531 this.operatorInfo = operatorInfo;
532 this.persistSelection = persistSelection;
533 }
534 }
535
Sarah Chin71b3a852022-09-28 15:54:19 -0700536 private static final class PurchasePremiumCapabilityArgument {
537 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700538 public @NonNull IIntegerConsumer callback;
539
540 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800541 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700542 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700543 this.callback = callback;
544 }
545 }
546
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700547 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700548 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
549 * request after sending. The main thread will notify the request when it is complete.
550 */
551 private static final class MainThreadRequest {
552 /** The argument to use for the request */
553 public Object argument;
554 /** The result of the request that is run on the main thread */
555 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800556 // The subscriber id that this request applies to. Defaults to
557 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
558 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700559
Nathan Harold92bed182018-10-12 18:16:49 -0700560 // In cases where subId is unavailable, the caller needs to specify the phone.
561 public Phone phone;
562
vagdeviaf9a5b92018-08-15 16:01:53 -0700563 public WorkSource workSource;
564
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700565 public MainThreadRequest(Object argument) {
566 this.argument = argument;
567 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800568
Nathan Harold92bed182018-10-12 18:16:49 -0700569 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
570 this.argument = argument;
571 if (phone != null) {
572 this.phone = phone;
573 }
574 this.workSource = workSource;
575 }
576
vagdeviaf9a5b92018-08-15 16:01:53 -0700577 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800578 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800579 if (subId != null) {
580 this.subId = subId;
581 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700582 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800583 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700584 }
585
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800586 private static final class IncomingThirdPartyCallArgs {
587 public final ComponentName component;
588 public final String callId;
589 public final String callerDisplayName;
590
591 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
592 String callerDisplayName) {
593 this.component = component;
594 this.callId = callId;
595 this.callerDisplayName = callerDisplayName;
596 }
597 }
598
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700599 /**
600 * A handler that processes messages on the main thread in the phone process. Since many
601 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
602 * inbound binder threads to the main thread in the phone process. The Binder thread
603 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
604 * on, which will be notified when the operation completes and will contain the result of the
605 * request.
606 *
607 * <p>If a MainThreadRequest object is provided in the msg.obj field,
608 * note that request.result must be set to something non-null for the calling thread to
609 * unblock.
610 */
611 private final class MainThreadHandler extends Handler {
612 @Override
613 public void handleMessage(Message msg) {
614 MainThreadRequest request;
615 Message onCompleted;
616 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000617 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700618 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800619 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700620
621 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700622 case CMD_HANDLE_USSD_REQUEST: {
623 request = (MainThreadRequest) msg.obj;
624 final Phone phone = getPhoneFromRequest(request);
625 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800626 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700627 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700628
Pengquan Menga1bb6272018-09-06 09:59:22 -0700629 if (!isUssdApiAllowed(request.subId)) {
630 // Carrier does not support use of this API, return failure.
631 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
632 UssdResponse response = new UssdResponse(ussdRequest, null);
633 Bundle returnData = new Bundle();
634 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
635 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700636
Pengquan Menga1bb6272018-09-06 09:59:22 -0700637 request.result = true;
638 notifyRequester(request);
639 return;
640 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700641
Pengquan Menga1bb6272018-09-06 09:59:22 -0700642 try {
643 request.result = phone != null
644 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
645 } catch (CallStateException cse) {
646 request.result = false;
647 }
648 // Wake up the requesting thread
649 notifyRequester(request);
650 break;
pkanwar32d516d2016-10-14 19:37:38 -0700651 }
652
Yorke Lee716f67e2015-06-17 15:39:16 -0700653 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700654 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700655 final Phone phone = getPhoneFromRequest(request);
656 request.result = phone != null ?
657 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
658 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700659 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700660 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700661 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700662 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700663
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700664 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700665 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700666 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000667 uiccPort = getUiccPortFromRequest(request);
668 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700669 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800670 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700671 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700672 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700673 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800674 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000675 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800676 iccArgument.channel, iccArgument.cla, iccArgument.command,
677 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
678 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700679 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700680 break;
681
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700682 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700683 ar = (AsyncResult) msg.obj;
684 request = (MainThreadRequest) ar.userObj;
685 if (ar.exception == null && ar.result != null) {
686 request.result = ar.result;
687 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800688 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700689 if (ar.result == null) {
690 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800691 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700692 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800693 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700694 } else {
695 loge("iccTransmitApduLogicalChannel: Unknown exception");
696 }
697 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700698 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700699 break;
700
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700701 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
702 request = (MainThreadRequest) msg.obj;
703 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000704 uiccPort = getUiccPortFromRequest(request);
705 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700706 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800707 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700708 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700709 } else {
710 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800711 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000712 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800713 iccArgument.cla, iccArgument.command, iccArgument.p1,
714 iccArgument.p2,
715 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700716 }
717 break;
718
719 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
720 ar = (AsyncResult) msg.obj;
721 request = (MainThreadRequest) ar.userObj;
722 if (ar.exception == null && ar.result != null) {
723 request.result = ar.result;
724 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800725 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700726 if (ar.result == null) {
727 loge("iccTransmitApduBasicChannel: Empty response");
728 } else if (ar.exception instanceof CommandException) {
729 loge("iccTransmitApduBasicChannel: CommandException: " +
730 ar.exception);
731 } else {
732 loge("iccTransmitApduBasicChannel: Unknown exception");
733 }
734 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700735 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700736 break;
737
738 case CMD_EXCHANGE_SIM_IO:
739 request = (MainThreadRequest) msg.obj;
740 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000741 uiccPort = getUiccPortFromRequest(request);
742 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700743 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800744 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700745 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700746 } else {
747 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
748 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000749 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700750 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
751 iccArgument.data, onCompleted);
752 }
753 break;
754
755 case EVENT_EXCHANGE_SIM_IO_DONE:
756 ar = (AsyncResult) msg.obj;
757 request = (MainThreadRequest) ar.userObj;
758 if (ar.exception == null && ar.result != null) {
759 request.result = ar.result;
760 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800761 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700762 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700763 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700764 break;
765
Derek Tan4d5e5c12014-02-04 11:54:58 -0800766 case CMD_SEND_ENVELOPE:
767 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000768 uiccPort = getUiccPortFromRequest(request);
769 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700770 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800771 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700772 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700773 } else {
774 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800775 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700776 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800777 break;
778
779 case EVENT_SEND_ENVELOPE_DONE:
780 ar = (AsyncResult) msg.obj;
781 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700782 if (ar.exception == null && ar.result != null) {
783 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800784 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800785 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700786 if (ar.result == null) {
787 loge("sendEnvelopeWithStatus: Empty response");
788 } else if (ar.exception instanceof CommandException) {
789 loge("sendEnvelopeWithStatus: CommandException: " +
790 ar.exception);
791 } else {
792 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
793 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800794 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700795 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800796 break;
797
Shishir Agrawal566b7612013-10-28 14:41:00 -0700798 case CMD_OPEN_CHANNEL:
799 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000800 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800801 IccLogicalChannelRequest openChannelRequest =
802 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000803 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700804 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800805 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800806 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700807 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700808 } else {
809 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800810 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
811 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700812 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700813 break;
814
815 case EVENT_OPEN_CHANNEL_DONE:
816 ar = (AsyncResult) msg.obj;
817 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700818 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700819 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700820 int[] result = (int[]) ar.result;
821 int channelId = result[0];
822 byte[] selectResponse = null;
823 if (result.length > 1) {
824 selectResponse = new byte[result.length - 1];
825 for (int i = 1; i < result.length; ++i) {
826 selectResponse[i - 1] = (byte) result[i];
827 }
828 }
829 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800830 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800831
832 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700833 if (uiccPort == null) {
834 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
835 } else {
836 IccLogicalChannelRequest channelRequest =
837 (IccLogicalChannelRequest) request.argument;
838 channelRequest.channel = channelId;
839 uiccPort.onLogicalChannelOpened(channelRequest);
840 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700841 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700842 if (ar.result == null) {
843 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700844 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700845 if (ar.exception != null) {
846 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
847 }
848
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700849 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700850 if (ar.exception instanceof CommandException) {
851 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800852 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700853 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700854 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700855 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700856 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700857 }
858 }
859 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800860 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700861 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700862 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700863 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700864 break;
865
866 case CMD_CLOSE_CHANNEL:
867 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000868 uiccPort = getUiccPortFromRequest(request);
869 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700870 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800871 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800872 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800873 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700874 } else {
875 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000876 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700877 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700878 break;
879
880 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800881 ar = (AsyncResult) msg.obj;
882 request = (MainThreadRequest) ar.userObj;
883 if (ar.exception == null) {
884 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800885 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700886 if (uiccPort == null) {
887 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
888 } else {
889 final int channelId = (Integer) request.argument;
890 uiccPort.onLogicalChannelClosed(channelId);
891 }
Chen Xu540470b2021-12-14 17:15:47 -0800892 } else {
893 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800894 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800895 if (ar.exception instanceof CommandException) {
896 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
897 CommandException.Error error =
898 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800899 if (error == CommandException.Error.INVALID_ARGUMENTS) {
900 // should only throw exceptions from the binder threads.
901 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800902 "iccCloseLogicalChannel: invalid argument ");
903 }
904 } else {
905 loge("iccCloseLogicalChannel: Unknown exception");
906 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800907 request.result = (exception != null) ? exception :
908 new IllegalStateException(
909 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800910 }
911 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800912 break;
913
914 case CMD_NV_READ_ITEM:
915 request = (MainThreadRequest) msg.obj;
916 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800917 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
918 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800919 break;
920
921 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700922 ar = (AsyncResult) msg.obj;
923 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800924 if (ar.exception == null && ar.result != null) {
925 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700926 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800927 request.result = "";
928 if (ar.result == null) {
929 loge("nvReadItem: Empty response");
930 } else if (ar.exception instanceof CommandException) {
931 loge("nvReadItem: CommandException: " +
932 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700933 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800934 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700935 }
936 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700937 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700938 break;
939
Jake Hambye994d462014-02-03 13:10:13 -0800940 case CMD_NV_WRITE_ITEM:
941 request = (MainThreadRequest) msg.obj;
942 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
943 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800944 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700945 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800946 break;
947
948 case EVENT_NV_WRITE_ITEM_DONE:
949 handleNullReturnEvent(msg, "nvWriteItem");
950 break;
951
952 case CMD_NV_WRITE_CDMA_PRL:
953 request = (MainThreadRequest) msg.obj;
954 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800955 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800956 break;
957
958 case EVENT_NV_WRITE_CDMA_PRL_DONE:
959 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
960 break;
961
chen xu6dac5ab2018-10-26 17:39:23 -0700962 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800963 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700964 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800965 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800966 break;
967
chen xu6dac5ab2018-10-26 17:39:23 -0700968 case EVENT_RESET_MODEM_CONFIG_DONE:
969 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800970 break;
971
Sooraj Sasindran37444802020-08-11 10:40:43 -0700972 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
973 request = (MainThreadRequest) msg.obj;
974 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
975 request);
976 Phone phone = getPhoneFromRequest(request);
977 if (phone != null) {
978 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
979 } else {
980 loge("isNRDualConnectivityEnabled: No phone object");
981 request.result = false;
982 notifyRequester(request);
983 }
984 break;
985 }
986
987 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
988 ar = (AsyncResult) msg.obj;
989 request = (MainThreadRequest) ar.userObj;
990 if (ar.exception == null && ar.result != null) {
991 request.result = ar.result;
992 } else {
993 // request.result must be set to something non-null
994 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700995 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700996 request.result = ar.result;
997 } else {
998 request.result = false;
999 }
1000 if (ar.result == null) {
1001 loge("isNRDualConnectivityEnabled: Empty response");
1002 } else if (ar.exception instanceof CommandException) {
1003 loge("isNRDualConnectivityEnabled: CommandException: "
1004 + ar.exception);
1005 } else {
1006 loge("isNRDualConnectivityEnabled: Unknown exception");
1007 }
1008 }
1009 notifyRequester(request);
1010 break;
1011
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001012 case CMD_IS_VONR_ENABLED: {
1013 request = (MainThreadRequest) msg.obj;
1014 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
1015 request);
1016 Phone phone = getPhoneFromRequest(request);
1017 if (phone != null) {
1018 phone.isVoNrEnabled(onCompleted, request.workSource);
1019 } else {
1020 loge("isVoNrEnabled: No phone object");
1021 request.result = false;
1022 notifyRequester(request);
1023 }
1024 break;
1025 }
1026
1027 case EVENT_IS_VONR_ENABLED_DONE:
1028 ar = (AsyncResult) msg.obj;
1029 request = (MainThreadRequest) ar.userObj;
1030 if (ar.exception == null && ar.result != null) {
1031 request.result = ar.result;
1032 } else {
1033 // request.result must be set to something non-null
1034 // for the calling thread to unblock
1035 if (ar.result != null) {
1036 request.result = ar.result;
1037 } else {
1038 request.result = false;
1039 }
1040 if (ar.result == null) {
1041 loge("isVoNrEnabled: Empty response");
1042 } else if (ar.exception instanceof CommandException) {
1043 loge("isVoNrEnabled: CommandException: "
1044 + ar.exception);
1045 } else {
1046 loge("isVoNrEnabled: Unknown exception");
1047 }
1048 }
1049 notifyRequester(request);
1050 break;
1051
Sooraj Sasindran37444802020-08-11 10:40:43 -07001052 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1053 request = (MainThreadRequest) msg.obj;
1054 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1055 Phone phone = getPhoneFromRequest(request);
1056 if (phone != null) {
1057 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1058 request.workSource);
1059 } else {
1060 loge("enableNrDualConnectivity: No phone object");
1061 request.result =
1062 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1063 notifyRequester(request);
1064 }
1065 break;
1066 }
1067
1068 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1069 ar = (AsyncResult) msg.obj;
1070 request = (MainThreadRequest) ar.userObj;
1071 if (ar.exception == null) {
1072 request.result =
1073 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1074 } else {
1075 request.result =
1076 TelephonyManager
1077 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1078 if (ar.exception instanceof CommandException) {
1079 CommandException.Error error =
1080 ((CommandException) (ar.exception)).getCommandError();
1081 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1082 request.result =
1083 TelephonyManager
1084 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001085 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1086 request.result =
1087 TelephonyManager
1088 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001089 }
1090 loge("enableNrDualConnectivity" + ": CommandException: "
1091 + ar.exception);
1092 } else {
1093 loge("enableNrDualConnectivity" + ": Unknown exception");
1094 }
1095 }
1096 notifyRequester(request);
1097 break;
1098 }
1099
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001100 case CMD_ENABLE_VONR: {
1101 request = (MainThreadRequest) msg.obj;
1102 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1103 Phone phone = getPhoneFromRequest(request);
1104 if (phone != null) {
1105 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1106 request.workSource);
1107 } else {
1108 loge("setVoNrEnabled: No phone object");
1109 request.result =
1110 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1111 notifyRequester(request);
1112 }
1113 break;
1114 }
1115
1116 case EVENT_ENABLE_VONR_DONE: {
1117 ar = (AsyncResult) msg.obj;
1118 request = (MainThreadRequest) ar.userObj;
1119 if (ar.exception == null) {
1120 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1121 } else {
1122 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1123 if (ar.exception instanceof CommandException) {
1124 CommandException.Error error =
1125 ((CommandException) (ar.exception)).getCommandError();
1126 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1127 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1128 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1129 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1130 } else {
1131 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1132 }
1133 loge("setVoNrEnabled" + ": CommandException: "
1134 + ar.exception);
1135 } else {
1136 loge("setVoNrEnabled" + ": Unknown exception");
1137 }
1138 }
1139 notifyRequester(request);
1140 break;
1141 }
1142
SongFerngWang3ef3e072020-12-21 16:41:52 +08001143 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001144 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001145 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1146 request);
1147 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001148 break;
1149
SongFerngWang3ef3e072020-12-21 16:41:52 +08001150 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001151 ar = (AsyncResult) msg.obj;
1152 request = (MainThreadRequest) ar.userObj;
1153 if (ar.exception == null && ar.result != null) {
1154 request.result = ar.result; // Integer
1155 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301156 // request.result must be set to something non-null
1157 // for the calling thread to unblock
1158 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001159 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001160 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001161 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001162 loge("getAllowedNetworkTypesBitmask: CommandException: "
1163 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001164 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001165 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001166 }
1167 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001168 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001169 break;
1170
SongFerngWang3ef3e072020-12-21 16:41:52 +08001171 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001172 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001173 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1174 request);
1175 Pair<Integer, Long> reasonWithNetworkTypes =
1176 (Pair<Integer, Long>) request.argument;
1177 getPhoneFromRequest(request).setAllowedNetworkTypes(
1178 reasonWithNetworkTypes.first,
1179 reasonWithNetworkTypes.second,
1180 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001181 break;
1182
SongFerngWang3ef3e072020-12-21 16:41:52 +08001183 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1184 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001185 break;
1186
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001187 case CMD_SET_VOICEMAIL_NUMBER:
1188 request = (MainThreadRequest) msg.obj;
1189 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1190 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001191 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1192 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001193 break;
1194
1195 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1196 handleNullReturnEvent(msg, "setVoicemailNumber");
1197 break;
1198
Stuart Scott54788802015-03-30 13:18:01 -07001199 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1200 request = (MainThreadRequest) msg.obj;
1201 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1202 request);
1203 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1204 break;
1205
1206 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1207 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1208 break;
1209
Shishir Agrawal302c8692015-06-19 13:49:39 -07001210 case CMD_PERFORM_NETWORK_SCAN:
1211 request = (MainThreadRequest) msg.obj;
1212 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1213 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1214 break;
1215
Hall Liu27d24262020-09-18 19:04:59 -07001216 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001217 request = (MainThreadRequest) msg.obj;
1218 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001219 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1220 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1221 request.argument;
1222 int callForwardingReason = args.first;
1223 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001224 break;
Hall Liu27d24262020-09-18 19:04:59 -07001225 }
1226 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001227 ar = (AsyncResult) msg.obj;
1228 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001229 TelephonyManager.CallForwardingInfoCallback callback =
1230 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1231 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001232 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001233 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001234 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1235 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1236 // Service Class is a bit mask per 3gpp 27.007. Search for
1237 // any service for voice call.
1238 if ((callForwardInfo.serviceClass
1239 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001240 callForwardingInfo = new CallForwardingInfo(
1241 callForwardInfo.status
1242 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001243 callForwardInfo.reason,
1244 callForwardInfo.number,
1245 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001246 break;
1247 }
1248 }
1249 // Didn't find a call forward info for voice call.
1250 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001251 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1252 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001253 }
Hall Liu27d24262020-09-18 19:04:59 -07001254 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001255 } else {
1256 if (ar.result == null) {
1257 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1258 }
1259 if (ar.exception != null) {
1260 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1261 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001262 int errorCode = TelephonyManager
1263 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001264 if (ar.exception instanceof CommandException) {
1265 CommandException.Error error =
1266 ((CommandException) (ar.exception)).getCommandError();
1267 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001268 errorCode = TelephonyManager
1269 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001270 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001271 errorCode = TelephonyManager
1272 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001273 }
1274 }
Hall Liu27d24262020-09-18 19:04:59 -07001275 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001276 }
Shuo Qian4a594052020-01-23 11:59:30 -08001277 break;
Hall Liu27d24262020-09-18 19:04:59 -07001278 }
Shuo Qian4a594052020-01-23 11:59:30 -08001279
Hall Liu27d24262020-09-18 19:04:59 -07001280 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001281 request = (MainThreadRequest) msg.obj;
1282 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001283 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001284 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001285 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1286 request.argument).first;
1287 request.phone.setCallForwardingOption(
1288 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001289 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001290 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001291 callForwardingInfoToSet.getReason(),
1292 callForwardingInfoToSet.getNumber(),
1293 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1294 break;
Hall Liu27d24262020-09-18 19:04:59 -07001295 }
Shuo Qian4a594052020-01-23 11:59:30 -08001296
Hall Liu27d24262020-09-18 19:04:59 -07001297 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001298 ar = (AsyncResult) msg.obj;
1299 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001300 Consumer<Integer> callback =
1301 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1302 request.argument).second;
1303 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001304 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001305 int errorCode = TelephonyManager.CallForwardingInfoCallback
1306 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001307 if (ar.exception instanceof CommandException) {
1308 CommandException.Error error =
1309 ((CommandException) (ar.exception)).getCommandError();
1310 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001311 errorCode = TelephonyManager.CallForwardingInfoCallback
1312 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001313 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001314 errorCode = TelephonyManager.CallForwardingInfoCallback
1315 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001316 }
1317 }
1318 callback.accept(errorCode);
1319 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001320 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001321 }
Shuo Qian4a594052020-01-23 11:59:30 -08001322 break;
Hall Liu27d24262020-09-18 19:04:59 -07001323 }
Shuo Qian4a594052020-01-23 11:59:30 -08001324
Hall Liu27d24262020-09-18 19:04:59 -07001325 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001326 request = (MainThreadRequest) msg.obj;
1327 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1328 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1329 break;
Hall Liu27d24262020-09-18 19:04:59 -07001330 }
Shuo Qian4a594052020-01-23 11:59:30 -08001331
Hall Liu27d24262020-09-18 19:04:59 -07001332 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001333 ar = (AsyncResult) msg.obj;
1334 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001335 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001336 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001337 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001338 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001339 // Service Class is a bit mask per 3gpp 27.007.
1340 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001341 if (callForwardResults.length > 1
1342 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001343 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001344 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001345 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1346 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001347 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001348 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001349 }
1350 } else {
1351 if (ar.result == null) {
1352 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1353 }
1354 if (ar.exception != null) {
1355 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1356 }
1357 if (ar.exception instanceof CommandException) {
1358 CommandException.Error error =
1359 ((CommandException) (ar.exception)).getCommandError();
1360 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001361 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001362 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001363 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1364 callWaitingStatus =
1365 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001366 }
1367 }
1368 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001369 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001370 break;
Hall Liu27d24262020-09-18 19:04:59 -07001371 }
Shuo Qian4a594052020-01-23 11:59:30 -08001372
Hall Liu27d24262020-09-18 19:04:59 -07001373 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001374 request = (MainThreadRequest) msg.obj;
1375 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001376 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1377 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001378 break;
Hall Liu27d24262020-09-18 19:04:59 -07001379 }
Shuo Qian4a594052020-01-23 11:59:30 -08001380
Hall Liu27d24262020-09-18 19:04:59 -07001381 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001382 ar = (AsyncResult) msg.obj;
1383 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001384 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1385 Consumer<Integer> callback =
1386 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1387 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001388 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001389 if (ar.exception instanceof CommandException) {
1390 CommandException.Error error =
1391 ((CommandException) (ar.exception)).getCommandError();
1392 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1393 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001394 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1395 callback.accept(
1396 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001397 } else {
1398 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1399 }
1400 } else {
1401 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1402 }
1403 } else {
1404 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1405 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001406 }
Shuo Qian4a594052020-01-23 11:59:30 -08001407 break;
Hall Liu27d24262020-09-18 19:04:59 -07001408 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001409 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1410 ar = (AsyncResult) msg.obj;
1411 request = (MainThreadRequest) ar.userObj;
1412 CellNetworkScanResult cellScanResult;
1413 if (ar.exception == null && ar.result != null) {
1414 cellScanResult = new CellNetworkScanResult(
1415 CellNetworkScanResult.STATUS_SUCCESS,
1416 (List<OperatorInfo>) ar.result);
1417 } else {
1418 if (ar.result == null) {
1419 loge("getCellNetworkScanResults: Empty response");
1420 }
1421 if (ar.exception != null) {
1422 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1423 }
1424 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1425 if (ar.exception instanceof CommandException) {
1426 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001427 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001428 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1429 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1430 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1431 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1432 }
1433 }
1434 cellScanResult = new CellNetworkScanResult(errorCode, null);
1435 }
1436 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001437 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001438 break;
1439
1440 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1441 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001442 ManualNetworkSelectionArgument selArg =
1443 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001444 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1445 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001446 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1447 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001448 break;
1449
1450 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001451 ar = (AsyncResult) msg.obj;
1452 request = (MainThreadRequest) ar.userObj;
1453 if (ar.exception == null) {
1454 request.result = true;
1455 } else {
1456 request.result = false;
1457 loge("setNetworkSelectionModeManual " + ar.exception);
1458 }
1459 notifyRequester(request);
1460 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001461 break;
1462
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001463 case CMD_GET_MODEM_ACTIVITY_INFO:
1464 request = (MainThreadRequest) msg.obj;
1465 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001466 if (defaultPhone != null) {
1467 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001468 } else {
1469 ResultReceiver result = (ResultReceiver) request.argument;
1470 Bundle bundle = new Bundle();
1471 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001472 new ModemActivityInfo(0, 0, 0,
1473 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001474 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001475 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001476 break;
1477
Hall Liud0f208c2020-10-14 16:54:44 -07001478 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001479 ar = (AsyncResult) msg.obj;
1480 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001481 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001482 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001483 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001484 if (mLastModemActivityInfo == null) {
1485 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1486 mLastModemActivitySpecificInfo[0] =
1487 new ActivityStatsTechSpecificInfo(
1488 0,
1489 0,
1490 new int[ModemActivityInfo.getNumTxPowerLevels()],
1491 0);
1492 mLastModemActivityInfo =
1493 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1494 }
1495
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001496 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001497 // Update the last modem activity info and the result of the request.
1498 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1499 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001500 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001501 } else {
1502 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001503 }
Kai Shi917fdc62022-11-28 14:01:02 -08001504 // This is needed to decouple ret from mLastModemActivityInfo
1505 // We don't want to return mLastModemActivityInfo which is updated
1506 // inside mergeModemActivityInfo()
1507 ret = new ModemActivityInfo(
1508 mLastModemActivityInfo.getTimestampMillis(),
1509 mLastModemActivityInfo.getSleepTimeMillis(),
1510 mLastModemActivityInfo.getIdleTimeMillis(),
1511 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001512
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001513 } else {
1514 if (ar.result == null) {
1515 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001516 error = TelephonyManager.ModemActivityInfoException
1517 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001518 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001519 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001520 error = TelephonyManager.ModemActivityInfoException
1521 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001522 } else {
1523 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001524 error = TelephonyManager.ModemActivityInfoException
1525 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001526 }
1527 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001528 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001529 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001530 bundle.putParcelable(
1531 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001532 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001533 } else {
1534 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1535 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001536 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001537 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001538 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001539 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001540
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001541 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001542 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001543 CarrierRestrictionRules argument =
1544 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001545 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001546 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001547 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001548 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001549
1550 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1551 ar = (AsyncResult) msg.obj;
1552 request = (MainThreadRequest) ar.userObj;
1553 if (ar.exception == null && ar.result != null) {
1554 request.result = ar.result;
1555 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001556 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1557 if (ar.exception instanceof CommandException) {
1558 loge("setAllowedCarriers: CommandException: " + ar.exception);
1559 CommandException.Error error =
1560 ((CommandException) (ar.exception)).getCommandError();
1561 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1562 request.result =
1563 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1564 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001565 } else {
1566 loge("setAllowedCarriers: Unknown exception");
1567 }
1568 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001569 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001570 break;
1571
1572 case CMD_GET_ALLOWED_CARRIERS:
1573 request = (MainThreadRequest) msg.obj;
1574 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001575 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001576 break;
1577
1578 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1579 ar = (AsyncResult) msg.obj;
1580 request = (MainThreadRequest) ar.userObj;
1581 if (ar.exception == null && ar.result != null) {
1582 request.result = ar.result;
1583 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001584 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001585 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001586 if (ar.result == null) {
1587 loge("getAllowedCarriers: Empty response");
1588 } else if (ar.exception instanceof CommandException) {
1589 loge("getAllowedCarriers: CommandException: " +
1590 ar.exception);
1591 } else {
1592 loge("getAllowedCarriers: Unknown exception");
1593 }
1594 }
arunvoddud7401012022-12-15 16:08:12 +00001595 if (request.argument != null) {
1596 // This is for the implementation of carrierRestrictionStatus.
1597 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1598 Consumer<Integer> callback = callbackInfo.getConsumer();
Steve Statia28b7cb32024-03-11 23:58:50 +00001599 Set<Integer> callerCarrierIds = callbackInfo.getCarrierIds();
arunvoddud7401012022-12-15 16:08:12 +00001600 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1601 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1602 CarrierRestrictionRules carrierRestrictionRules =
1603 (CarrierRestrictionRules) ar.result;
1604 int carrierId = -1;
1605 try {
1606 CarrierIdentifier carrierIdentifier =
1607 carrierRestrictionRules.getAllowedCarriers().get(0);
1608 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1609 carrierIdentifier);
1610 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1611 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1612 }
1613 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
Steve Statia28b7cb32024-03-11 23:58:50 +00001614 int restrictedStatus =
1615 TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED;
1616 if (carrierId != -1 && callerCarrierIds.contains(carrierId) &&
1617 lockStatus == restrictedStatus) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001618 lockStatus = TelephonyManager
1619 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001620 }
1621 } else {
1622 Rlog.e(LOG_TAG,
1623 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1624 }
1625 callback.accept(lockStatus);
1626 } else {
1627 // This is for the implementation of getAllowedCarriers.
1628 notifyRequester(request);
1629 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001630 break;
1631
Nathan Haroldb3014052017-01-25 15:57:32 -08001632 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1633 ar = (AsyncResult) msg.obj;
1634 request = (MainThreadRequest) ar.userObj;
1635 if (ar.exception == null && ar.result != null) {
1636 request.result = ar.result;
1637 } else {
1638 request.result = new IllegalArgumentException(
1639 "Failed to retrieve Forbidden Plmns");
1640 if (ar.result == null) {
1641 loge("getForbiddenPlmns: Empty response");
1642 } else {
1643 loge("getForbiddenPlmns: Unknown exception");
1644 }
1645 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001646 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001647 break;
1648
1649 case CMD_GET_FORBIDDEN_PLMNS:
1650 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001651 uiccPort = getUiccPortFromRequest(request);
1652 if (uiccPort == null) {
1653 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001654 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001655 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001656 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001657 break;
1658 }
1659 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001660 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001661 if (uiccApp == null) {
1662 loge("getForbiddenPlmns() no app with specified type -- "
1663 + appType);
1664 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001665 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001666 break;
1667 } else {
1668 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1669 + " specified type -- " + appType);
1670 }
1671 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1672 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001673 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001674 break;
1675
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001676 case CMD_SWITCH_SLOTS:
1677 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001678 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001679 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001680 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001681 break;
1682
1683 case EVENT_SWITCH_SLOTS_DONE:
1684 ar = (AsyncResult) msg.obj;
1685 request = (MainThreadRequest) ar.userObj;
1686 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001687 notifyRequester(request);
1688 break;
1689 case CMD_GET_NETWORK_SELECTION_MODE:
1690 request = (MainThreadRequest) msg.obj;
1691 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1692 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1693 break;
1694
1695 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1696 ar = (AsyncResult) msg.obj;
1697 request = (MainThreadRequest) ar.userObj;
1698 if (ar.exception != null) {
1699 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1700 } else {
1701 int mode = ((int[]) ar.result)[0];
1702 if (mode == 0) {
1703 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1704 } else {
1705 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1706 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001707 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001708 notifyRequester(request);
1709 break;
1710 case CMD_GET_CDMA_ROAMING_MODE:
1711 request = (MainThreadRequest) msg.obj;
1712 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1713 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1714 break;
1715 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1716 ar = (AsyncResult) msg.obj;
1717 request = (MainThreadRequest) ar.userObj;
1718 if (ar.exception != null) {
1719 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1720 } else {
1721 request.result = ((int[]) ar.result)[0];
1722 }
1723 notifyRequester(request);
1724 break;
1725 case CMD_SET_CDMA_ROAMING_MODE:
1726 request = (MainThreadRequest) msg.obj;
1727 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1728 int mode = (int) request.argument;
1729 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1730 break;
1731 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1732 ar = (AsyncResult) msg.obj;
1733 request = (MainThreadRequest) ar.userObj;
1734 request.result = ar.exception == null;
1735 notifyRequester(request);
1736 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001737 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1738 request = (MainThreadRequest) msg.obj;
1739 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1740 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1741 break;
1742 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1743 ar = (AsyncResult) msg.obj;
1744 request = (MainThreadRequest) ar.userObj;
1745 if (ar.exception != null) {
1746 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1747 } else {
1748 request.result = ((int[]) ar.result)[0];
1749 }
1750 notifyRequester(request);
1751 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001752 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1753 request = (MainThreadRequest) msg.obj;
1754 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1755 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001756 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1757 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001758 break;
1759 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1760 ar = (AsyncResult) msg.obj;
1761 request = (MainThreadRequest) ar.userObj;
1762 request.result = ar.exception == null;
1763 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001764 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001765 case CMD_GET_ALL_CELL_INFO:
1766 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001767 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001768 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001769 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001770 case EVENT_GET_ALL_CELL_INFO_DONE:
1771 ar = (AsyncResult) msg.obj;
1772 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001773 // If a timeout occurs, the response will be null
1774 request.result = (ar.exception == null && ar.result != null)
1775 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001776 synchronized (request) {
1777 request.notifyAll();
1778 }
1779 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001780 case CMD_REQUEST_CELL_INFO_UPDATE:
1781 request = (MainThreadRequest) msg.obj;
1782 request.phone.requestCellInfoUpdate(request.workSource,
1783 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1784 break;
1785 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1786 ar = (AsyncResult) msg.obj;
1787 request = (MainThreadRequest) ar.userObj;
1788 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1789 try {
1790 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001791 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001792 cb.onError(
1793 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1794 ar.exception.getClass().getName(),
1795 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001796 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001797 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001798 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001799 } else {
1800 // use the result as returned
1801 cb.onCellInfo((List<CellInfo>) ar.result);
1802 }
1803 } catch (RemoteException re) {
1804 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1805 }
1806 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001807 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001808 request = (MainThreadRequest) msg.obj;
1809 WorkSource ws = (WorkSource) request.argument;
1810 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001811 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001812 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001813 }
1814 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001815 ar = (AsyncResult) msg.obj;
1816 request = (MainThreadRequest) ar.userObj;
1817 if (ar.exception == null) {
1818 request.result = ar.result;
1819 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001820 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001821 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001822 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001823 }
1824
1825 synchronized (request) {
1826 request.notifyAll();
1827 }
1828 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001829 }
chen xu6dac5ab2018-10-26 17:39:23 -07001830 case CMD_MODEM_REBOOT:
1831 request = (MainThreadRequest) msg.obj;
1832 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001833 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001834 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001835 case EVENT_CMD_MODEM_REBOOT_DONE:
1836 handleNullReturnEvent(msg, "rebootModem");
1837 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001838 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001839 request = (MainThreadRequest) msg.obj;
1840 boolean enable = (boolean) request.argument;
1841 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001842 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001843 PhoneConfigurationManager.getInstance()
1844 .enablePhone(request.phone, enable, onCompleted);
1845 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001846 }
Michele Berionne5e411512020-11-13 02:36:59 +00001847 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001848 ar = (AsyncResult) msg.obj;
1849 request = (MainThreadRequest) ar.userObj;
1850 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001851 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001852 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001853 if ((boolean) request.result) {
1854 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1855 updateModemStateMetrics();
1856 } else {
1857 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1858 + ar.exception);
1859 }
1860 notifyRequester(request);
1861 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001862 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001863 case CMD_GET_MODEM_STATUS:
1864 request = (MainThreadRequest) msg.obj;
1865 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1866 PhoneConfigurationManager.getInstance()
1867 .getPhoneStatusFromModem(request.phone, onCompleted);
1868 break;
1869 case EVENT_GET_MODEM_STATUS_DONE:
1870 ar = (AsyncResult) msg.obj;
1871 request = (MainThreadRequest) ar.userObj;
1872 int id = request.phone.getPhoneId();
1873 if (ar.exception == null && ar.result != null) {
1874 request.result = ar.result;
1875 //update the cache as modem status has changed
1876 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1877 (boolean) request.result);
1878 } else {
1879 // Return true if modem status cannot be retrieved. For most cases,
1880 // modem status is on. And for older version modems, GET_MODEM_STATUS
1881 // and disable modem are not supported. Modem is always on.
1882 // TODO: this should be fixed in R to support a third
1883 // status UNKNOWN b/131631629
1884 request.result = true;
1885 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1886 + ar.exception);
1887 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001888 notifyRequester(request);
1889 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001890 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1891 request = (MainThreadRequest) msg.obj;
1892 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1893 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1894 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1895 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1896 break;
1897 }
1898 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1899 ar = (AsyncResult) msg.obj;
1900 request = (MainThreadRequest) ar.userObj;
1901 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1902 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1903 args.second.accept(ar.exception == null);
1904 notifyRequester(request);
1905 break;
1906 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001907 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1908 request = (MainThreadRequest) msg.obj;
1909 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1910 Phone phone = getPhoneFromRequest(request);
1911 if (phone != null) {
1912 phone.getSystemSelectionChannels(onCompleted);
1913 } else {
1914 loge("getSystemSelectionChannels: No phone object");
1915 request.result = new ArrayList<RadioAccessSpecifier>();
1916 notifyRequester(request);
1917 }
1918 break;
1919 }
1920 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1921 ar = (AsyncResult) msg.obj;
1922 request = (MainThreadRequest) ar.userObj;
1923 if (ar.exception == null && ar.result != null) {
1924 request.result = ar.result;
1925 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001926 request.result = new IllegalStateException(
1927 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001928 if (ar.result == null) {
1929 loge("getSystemSelectionChannels: Empty response");
1930 } else {
1931 loge("getSystemSelectionChannels: Unknown exception");
1932 }
1933 }
1934 notifyRequester(request);
1935 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001936 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1937 ar = (AsyncResult) msg.obj;
1938 request = (MainThreadRequest) ar.userObj;
1939 if (ar.exception == null && ar.result != null) {
1940 request.result = ar.result;
1941 } else {
1942 request.result = -1;
1943 loge("Failed to set Forbidden Plmns");
1944 if (ar.result == null) {
1945 loge("setForbidenPlmns: Empty response");
1946 } else if (ar.exception != null) {
1947 loge("setForbiddenPlmns: Exception: " + ar.exception);
1948 request.result = -1;
1949 } else {
1950 loge("setForbiddenPlmns: Unknown exception");
1951 }
1952 }
1953 notifyRequester(request);
1954 break;
1955 case CMD_SET_FORBIDDEN_PLMNS:
1956 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001957 uiccPort = getUiccPortFromRequest(request);
1958 if (uiccPort == null) {
1959 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001960 request.result = -1;
1961 notifyRequester(request);
1962 break;
1963 }
1964 Pair<Integer, List<String>> setFplmnsArgs =
1965 (Pair<Integer, List<String>>) request.argument;
1966 appType = setFplmnsArgs.first;
1967 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001968 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001969 if (uiccApp == null) {
1970 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1971 request.result = -1;
1972 loge("Failed to get UICC App");
1973 notifyRequester(request);
1974 } else {
1975 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1976 ((SIMRecords) uiccApp.getIccRecords())
1977 .setForbiddenPlmns(onCompleted, fplmns);
1978 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001979 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001980 case CMD_ERASE_MODEM_CONFIG:
1981 request = (MainThreadRequest) msg.obj;
1982 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1983 defaultPhone.eraseModemConfig(onCompleted);
1984 break;
1985 case EVENT_ERASE_MODEM_CONFIG_DONE:
1986 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001987 break;
zoey chene02881a2019-12-30 16:11:23 +08001988
Kai Shif70f46f2021-03-03 13:59:46 -08001989 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1990 request = (MainThreadRequest) msg.obj;
1991 request.result = defaultPhone.eraseDataInSharedPreferences();
1992 notifyRequester(request);
1993 break;
1994
zoey chene02881a2019-12-30 16:11:23 +08001995 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1996 request = (MainThreadRequest) msg.obj;
1997 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1998 Pair<String, String> changed = (Pair<String, String>) request.argument;
1999 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
2000 changed.first, changed.second, onCompleted);
2001 break;
2002 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
2003 ar = (AsyncResult) msg.obj;
2004 request = (MainThreadRequest) ar.userObj;
2005 if (ar.exception == null) {
2006 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002007 // If the operation is successful, update the PIN storage
2008 Pair<String, String> passwords = (Pair<String, String>) request.argument;
2009 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00002010 UiccController.getInstance().getPinStorage()
2011 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08002012 } else {
2013 request.result = msg.arg1;
2014 }
2015 notifyRequester(request);
2016 break;
2017
Michele Berionne5e411512020-11-13 02:36:59 +00002018 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08002019 request = (MainThreadRequest) msg.obj;
2020 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
2021 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2022 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2023 enabled.first, enabled.second, onCompleted);
2024 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002025 }
zoey chene02881a2019-12-30 16:11:23 +08002026 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2027 ar = (AsyncResult) msg.obj;
2028 request = (MainThreadRequest) ar.userObj;
2029 if (ar.exception == null) {
2030 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002031 // If the operation is successful, update the PIN storage
2032 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2033 int phoneId = getPhoneFromRequest(request).getPhoneId();
2034 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002035 UiccController.getInstance().getPinStorage()
2036 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002037 } else {
2038 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2039 }
zoey chene02881a2019-12-30 16:11:23 +08002040 } else {
2041 request.result = msg.arg1;
2042 }
Michele Berionne5e411512020-11-13 02:36:59 +00002043
2044
zoey chene02881a2019-12-30 16:11:23 +08002045 notifyRequester(request);
2046 break;
2047
Peter Wangdafb9ac2020-01-15 14:13:38 -08002048 case MSG_NOTIFY_USER_ACTIVITY:
2049 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002050 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002051 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2052 getDefaultPhone().getContext().sendBroadcastAsUser(
2053 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2054 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002055
2056 case CMD_SET_DATA_THROTTLING: {
2057 request = (MainThreadRequest) msg.obj;
2058 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2059 DataThrottlingRequest dataThrottlingRequest =
2060 (DataThrottlingRequest) request.argument;
2061 Phone phone = getPhoneFromRequest(request);
2062 if (phone != null) {
2063 phone.setDataThrottling(onCompleted,
2064 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2065 dataThrottlingRequest.getCompletionDurationMillis());
2066 } else {
2067 loge("setDataThrottling: No phone object");
2068 request.result =
2069 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2070 notifyRequester(request);
2071 }
2072
2073 break;
2074 }
2075 case EVENT_SET_DATA_THROTTLING_DONE:
2076 ar = (AsyncResult) msg.obj;
2077 request = (MainThreadRequest) ar.userObj;
2078
2079 if (ar.exception == null) {
2080 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2081 } else if (ar.exception instanceof CommandException) {
2082 loge("setDataThrottling: CommandException: " + ar.exception);
2083 CommandException.Error error =
2084 ((CommandException) (ar.exception)).getCommandError();
2085
2086 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2087 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002088 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002089 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2090 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002091 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2092 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002093 } else {
2094 request.result =
2095 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2096 }
2097 } else {
2098 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2099 }
2100 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2101 notifyRequester(request);
2102 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002103
2104 case CMD_SET_SIM_POWER: {
2105 request = (MainThreadRequest) msg.obj;
2106 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2107 request = (MainThreadRequest) msg.obj;
2108 int stateToSet =
2109 ((Pair<Integer, IIntegerConsumer>)
2110 request.argument).first;
2111 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2112 break;
2113 }
2114 case EVENT_SET_SIM_POWER_DONE: {
2115 ar = (AsyncResult) msg.obj;
2116 request = (MainThreadRequest) ar.userObj;
2117 IIntegerConsumer callback =
2118 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2119 if (ar.exception != null) {
2120 loge("setSimPower exception: " + ar.exception);
2121 int errorCode = TelephonyManager.CallForwardingInfoCallback
2122 .RESULT_ERROR_UNKNOWN;
2123 if (ar.exception instanceof CommandException) {
2124 CommandException.Error error =
2125 ((CommandException) (ar.exception)).getCommandError();
2126 if (error == CommandException.Error.SIM_ERR) {
2127 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2128 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2129 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2130 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2131 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2132 } else {
2133 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2134 }
2135 }
2136 try {
2137 callback.accept(errorCode);
2138 } catch (RemoteException e) {
2139 // Ignore if the remote process is no longer available to call back.
2140 Log.w(LOG_TAG, "setSimPower: callback not available.");
2141 }
2142 } else {
2143 try {
2144 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2145 } catch (RemoteException e) {
2146 // Ignore if the remote process is no longer available to call back.
2147 Log.w(LOG_TAG, "setSimPower: callback not available.");
2148 }
2149 }
2150 break;
2151 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002152 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2153 request = (MainThreadRequest) msg.obj;
2154
2155 final Phone phone = getPhoneFromRequest(request);
2156 if (phone == null || phone.getServiceStateTracker() == null) {
2157 request.result = new IllegalStateException("Phone or SST is null");
2158 notifyRequester(request);
2159 break;
2160 }
2161
2162 Pair<Integer, SignalStrengthUpdateRequest> pair =
2163 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2164 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2165 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002166 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002167 request.subId, pair.first /*callingUid*/,
2168 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002169 break;
2170 }
2171 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2172 ar = (AsyncResult) msg.obj;
2173 request = (MainThreadRequest) ar.userObj;
2174 // request.result will be the exception of ar if present, true otherwise.
2175 // Be cautious not to leave result null which will wait() forever
2176 request.result = ar.exception != null ? ar.exception : true;
2177 notifyRequester(request);
2178 break;
2179 }
2180 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2181 request = (MainThreadRequest) msg.obj;
2182
2183 Phone phone = getPhoneFromRequest(request);
2184 if (phone == null || phone.getServiceStateTracker() == null) {
2185 request.result = new IllegalStateException("Phone or SST is null");
2186 notifyRequester(request);
2187 break;
2188 }
2189
2190 Pair<Integer, SignalStrengthUpdateRequest> pair =
2191 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2192 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2193 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002194 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002195 request.subId, pair.first /*callingUid*/,
2196 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002197 break;
2198 }
2199 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2200 ar = (AsyncResult) msg.obj;
2201 request = (MainThreadRequest) ar.userObj;
2202 request.result = ar.exception != null ? ar.exception : true;
2203 notifyRequester(request);
2204 break;
2205 }
Jordan Liu109698e2020-11-24 14:50:34 -08002206
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002207 case CMD_GET_SLICING_CONFIG: {
2208 request = (MainThreadRequest) msg.obj;
2209 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2210 request.phone.getSlicingConfig(onCompleted);
2211 break;
2212 }
2213 case EVENT_GET_SLICING_CONFIG_DONE: {
2214 ar = (AsyncResult) msg.obj;
2215 request = (MainThreadRequest) ar.userObj;
2216 ResultReceiver result = (ResultReceiver) request.argument;
2217
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002218 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002219 Bundle bundle = new Bundle();
2220 int resultCode = 0;
2221 if (ar.exception != null) {
2222 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2223 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002224 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002225 } else if (ar.result == null) {
2226 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002227 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002228 } else {
2229 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002230 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2231 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002232 }
2233
2234 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002235 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002236 }
2237 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2238 result.send(resultCode, bundle);
2239 notifyRequester(request);
2240 break;
2241 }
2242
Sarah Chin71b3a852022-09-28 15:54:19 -07002243 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002244 request = (MainThreadRequest) msg.obj;
2245 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002246 PurchasePremiumCapabilityArgument arg =
2247 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chincc5446f2023-10-23 17:57:19 -07002248 SlicePurchaseController.getInstance(request.phone, mFeatureFlags)
2249 .purchasePremiumCapability(arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002250 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002251 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002252
Sarah Chin71b3a852022-09-28 15:54:19 -07002253 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002254 ar = (AsyncResult) msg.obj;
2255 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002256 PurchasePremiumCapabilityArgument arg =
2257 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002258 try {
2259 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002260 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002261 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002262 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chinff8b1802023-04-11 14:22:14 -07002263 + ", result="
Sarah Chin2ec39f62022-08-31 17:03:26 -07002264 + TelephonyManager.convertPurchaseResultToString(result));
2265 } catch (RemoteException e) {
2266 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002267 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002268 + " failed: " + e;
2269 if (DBG) log(logStr);
2270 AnomalyReporter.reportAnomaly(
2271 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2272 }
2273 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002274 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002275
Michele Berionne5e411512020-11-13 02:36:59 +00002276 case CMD_PREPARE_UNATTENDED_REBOOT:
2277 request = (MainThreadRequest) msg.obj;
2278 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002279 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002280 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002281 notifyRequester(request);
2282 break;
2283
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002284 default:
2285 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2286 break;
2287 }
2288 }
Jake Hambye994d462014-02-03 13:10:13 -08002289
Pengquan Menga1bb6272018-09-06 09:59:22 -07002290 private void notifyRequester(MainThreadRequest request) {
2291 synchronized (request) {
2292 request.notifyAll();
2293 }
2294 }
2295
Jake Hambye994d462014-02-03 13:10:13 -08002296 private void handleNullReturnEvent(Message msg, String command) {
2297 AsyncResult ar = (AsyncResult) msg.obj;
2298 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2299 if (ar.exception == null) {
2300 request.result = true;
2301 } else {
2302 request.result = false;
2303 if (ar.exception instanceof CommandException) {
2304 loge(command + ": CommandException: " + ar.exception);
2305 } else {
2306 loge(command + ": Unknown exception");
2307 }
2308 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002309 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002310 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002311 }
2312
2313 /**
2314 * Posts the specified command to be executed on the main thread,
2315 * waits for the request to complete, and returns the result.
2316 * @see #sendRequestAsync
2317 */
2318 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002319 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2320 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002321 }
2322
2323 /**
2324 * Posts the specified command to be executed on the main thread,
2325 * waits for the request to complete, and returns the result.
2326 * @see #sendRequestAsync
2327 */
2328 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2329 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002330 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002331 }
2332
2333 /**
2334 * Posts the specified command to be executed on the main thread,
2335 * waits for the request to complete, and returns the result.
2336 * @see #sendRequestAsync
2337 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002338 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002339 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2340 }
2341
2342 /**
2343 * Posts the specified command to be executed on the main thread,
2344 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2345 * if not timeout or null otherwise.
2346 * @see #sendRequestAsync
2347 */
2348 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2349 long timeoutInMs) {
2350 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002351 }
2352
2353 /**
2354 * Posts the specified command to be executed on the main thread,
2355 * waits for the request to complete, and returns the result.
2356 * @see #sendRequestAsync
2357 */
Nathan Harold92bed182018-10-12 18:16:49 -07002358 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002359 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002360 }
2361
2362 /**
2363 * Posts the specified command to be executed on the main thread,
2364 * waits for the request to complete, and returns the result.
2365 * @see #sendRequestAsync
2366 */
2367 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002368 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2369 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002370 }
2371
2372 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002373 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2374 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2375 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002376 * @see #sendRequestAsync
2377 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002378 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2379 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002380 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2381 throw new RuntimeException("This method will deadlock if called from the main thread.");
2382 }
2383
Nathan Harold92bed182018-10-12 18:16:49 -07002384 MainThreadRequest request = null;
2385 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2386 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2387 } else if (phone != null) {
2388 request = new MainThreadRequest(argument, phone, workSource);
2389 } else {
2390 request = new MainThreadRequest(argument, subId, workSource);
2391 }
2392
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002393 Message msg = mMainThreadHandler.obtainMessage(command, request);
2394 msg.sendToTarget();
2395
Rambo Wang0f050d82021-02-12 11:43:36 -08002396
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002397 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002398 if (timeoutInMs >= 0) {
2399 // Wait for at least timeoutInMs before returning null request result
2400 long now = SystemClock.elapsedRealtime();
2401 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002402 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002403 try {
2404 request.wait(deadline - now);
2405 } catch (InterruptedException e) {
2406 // Do nothing, go back and check if request is completed or timeout
2407 } finally {
2408 now = SystemClock.elapsedRealtime();
2409 }
2410 }
2411 } else {
2412 // Wait for the request to complete
2413 while (request.result == null) {
2414 try {
2415 request.wait();
2416 } catch (InterruptedException e) {
2417 // Do nothing, go back and wait until the request is complete
2418 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002419 }
2420 }
2421 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002422 if (request.result == null) {
2423 Log.wtf(LOG_TAG,
2424 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2425 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002426 return request.result;
2427 }
2428
2429 /**
2430 * Asynchronous ("fire and forget") version of sendRequest():
2431 * Posts the specified command to be executed on the main thread, and
2432 * returns immediately.
2433 * @see #sendRequest
2434 */
2435 private void sendRequestAsync(int command) {
2436 mMainThreadHandler.sendEmptyMessage(command);
2437 }
2438
2439 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002440 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002441 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002442 */
2443 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002444 sendRequestAsync(command, argument, null, null);
2445 }
2446
2447 /**
2448 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2449 * @see {@link #sendRequest(int,Object)}
2450 */
2451 private void sendRequestAsync(
2452 int command, Object argument, Phone phone, WorkSource workSource) {
2453 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002454 Message msg = mMainThreadHandler.obtainMessage(command, request);
2455 msg.sendToTarget();
2456 }
2457
2458 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002459 * Initialize the singleton PhoneInterfaceManager instance.
2460 * This is only done once, at startup, from PhoneApp.onCreate().
2461 */
Sarah Chincc5446f2023-10-23 17:57:19 -07002462 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002463 synchronized (PhoneInterfaceManager.class) {
2464 if (sInstance == null) {
Sarah Chincc5446f2023-10-23 17:57:19 -07002465 sInstance = new PhoneInterfaceManager(app, featureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002466 } else {
2467 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2468 }
2469 return sInstance;
2470 }
2471 }
2472
2473 /** Private constructor; @see init() */
Sarah Chincc5446f2023-10-23 17:57:19 -07002474 private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002475 mApp = app;
Sarah Chincc5446f2023-10-23 17:57:19 -07002476 mFeatureFlags = featureFlags;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -08002477 mTelecomFeatureFlags = new com.android.server.telecom.flags.FeatureFlagsImpl();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002478 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002479 mImsResolver = ImsResolver.getInstance();
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +00002480 mSatelliteController = SatelliteController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002481 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002482 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2483 mMainThreadHandler = new MainThreadHandler();
Sarah Chin4beb2b72023-02-14 14:47:54 -08002484 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002485 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002486 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002487 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002488 mNotifyUserActivity = new AtomicBoolean(false);
joonhunshin4ac60942023-11-15 15:23:39 +00002489 mPackageManager = app.getPackageManager();
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -08002490 mSatelliteAccessController = SatelliteAccessController.getOrCreateInstance(
2491 getDefaultPhone().getContext(), featureFlags);
joonhunshinf624b2a2024-04-18 04:42:12 +00002492 mVendorApiLevel = SystemProperties.getInt(
2493 "ro.vendor.api_level", Build.VERSION.DEVICE_INITIAL_SDK_INT);
2494
Tyler Gunn64144d92022-03-17 14:16:41 -07002495 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002496 publish();
arunvoddud7401012022-12-15 16:08:12 +00002497 CarrierAllowListInfo.loadInstance(mApp);
Hyosun Kim240214a2023-11-02 13:30:15 +00002498
2499 // Create the SatelliteEntitlementController singleton, for using the get the
2500 // entitlementStatus for satellite service.
2501 SatelliteEntitlementController.make(mApp, mFeatureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002502 }
2503
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002504 @VisibleForTesting
2505 public SharedPreferences getSharedPreferences() {
2506 return mTelephonySharedPreferences;
2507 }
2508
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002509 /**
2510 * Get the default phone for this device.
2511 */
2512 @VisibleForTesting
2513 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002514 Phone thePhone = getPhone(getDefaultSubscription());
2515 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2516 }
2517
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002518 private void publish() {
2519 if (DBG) log("publish: " + this);
2520
Peter Wangc035ce42020-01-08 21:00:22 -08002521 TelephonyFrameworkInitializer
2522 .getTelephonyServiceManager()
2523 .getTelephonyServiceRegisterer()
2524 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002525 }
2526
Stuart Scott584921c2015-01-15 17:10:34 -08002527 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002528 if (request.phone != null) {
2529 return request.phone;
2530 } else {
2531 return getPhoneFromSubId(request.subId);
2532 }
2533 }
2534
2535 private Phone getPhoneFromSubId(int subId) {
2536 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2537 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002538 }
2539
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002540 /**
2541 * Get phone object associated with a subscription.
2542 * Return default phone if phone object associated with subscription is null
2543 * @param subId - subscriptionId
2544 * @return phone object associated with a subscription or default phone if null.
2545 */
Ling Mac28f0212023-03-24 16:07:15 -07002546 private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) {
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002547 Phone phone = getPhoneFromSubId(subId);
2548 if (phone == null) {
Ling Mac28f0212023-03-24 16:07:15 -07002549 loge("Called with invalid subId: " + subId + ". Retrying with default phone.");
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002550 phone = getDefaultPhone();
2551 }
2552 return phone;
2553 }
2554
Rambo Wange53e07d2022-05-10 13:01:13 -07002555 @Nullable
2556 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002557 Phone phone = getPhoneFromRequest(request);
2558 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002559 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002560 }
2561
Ling Mac28f0212023-03-24 16:07:15 -07002562 /**
2563 * @param subId The sub Id that associates the phone. If the device has no active SIM, passing
2564 * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <=
2565 * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}.
2566 * @return The Phone associated the sub Id
2567 */
2568 private @Nullable Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002569 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002570 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002571
Kai Shif70f46f2021-03-03 13:59:46 -08002572 private void sendEraseModemConfig(@NonNull Phone phone) {
2573 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2574 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2575 }
2576
2577 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2578 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2579 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002580 }
2581
Peter Wang44b186e2020-01-13 23:33:09 -08002582 private boolean isImsAvailableOnDevice() {
2583 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2584 if (pm == null) {
2585 // For some reason package manger is not available.. This will fail internally anyway,
2586 // so do not throw error and allow.
2587 return true;
2588 }
2589 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2590 }
2591
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002592 public void dial(String number) {
joonhunshin4ac60942023-11-15 15:23:39 +00002593 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2594 PackageManager.FEATURE_TELEPHONY_CALLING, "dial");
2595
Wink Savilleadd7cc52014-09-08 14:23:09 -07002596 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002597 }
2598
Wink Savilleb564aae2014-10-23 10:18:09 -07002599 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002600 if (DBG) log("dial: " + number);
2601 // No permission check needed here: This is just a wrapper around the
2602 // ACTION_DIAL intent, which is available to any app since it puts up
2603 // the UI before it does anything.
2604
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002605 final long identity = Binder.clearCallingIdentity();
2606 try {
2607 String url = createTelUrl(number);
2608 if (url == null) {
2609 return;
2610 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002611
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002612 // PENDING: should we just silently fail if phone is offhook or ringing?
2613 PhoneConstants.State state = mCM.getState(subId);
2614 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2615 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2616 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2617 mApp.startActivity(intent);
2618 }
2619 } finally {
2620 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002621 }
2622 }
2623
2624 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002625 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002626 }
2627
Wink Savilleb564aae2014-10-23 10:18:09 -07002628 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002629 if (DBG) log("call: " + number);
2630
2631 // This is just a wrapper around the ACTION_CALL intent, but we still
2632 // need to do a permission check since we're calling startActivity()
2633 // from the context of the phone app.
2634 enforceCallPermission();
2635
Jordan Liu1617b712019-07-10 15:06:26 -07002636 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002637 != AppOpsManager.MODE_ALLOWED) {
2638 return;
2639 }
2640
joonhunshin4ac60942023-11-15 15:23:39 +00002641 enforceTelephonyFeatureWithException(callingPackage,
2642 PackageManager.FEATURE_TELEPHONY_CALLING, "call");
2643
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002644 final long identity = Binder.clearCallingIdentity();
2645 try {
2646 String url = createTelUrl(number);
2647 if (url == null) {
2648 return;
2649 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002650
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002651 boolean isValid = false;
2652 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2653 if (slist != null) {
2654 for (SubscriptionInfo subInfoRecord : slist) {
2655 if (subInfoRecord.getSubscriptionId() == subId) {
2656 isValid = true;
2657 break;
2658 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002659 }
Wink Saville08874612014-08-31 19:19:58 -07002660 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002661 if (!isValid) {
2662 return;
2663 }
Wink Saville08874612014-08-31 19:19:58 -07002664
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002665 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2666 intent.putExtra(SUBSCRIPTION_KEY, subId);
2667 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2668 mApp.startActivity(intent);
2669 } finally {
2670 Binder.restoreCallingIdentity(identity);
2671 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002672 }
2673
Wink Savilleb564aae2014-10-23 10:18:09 -07002674 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002675 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002676 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2677 }
2678
Wink Savilleb564aae2014-10-23 10:18:09 -07002679 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002680 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002681 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2682 }
2683
Wink Savilleb564aae2014-10-23 10:18:09 -07002684 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002685 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002686
joonhunshin4ac60942023-11-15 15:23:39 +00002687 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2688 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
2689 "supplyPinReportResultForSubscriber");
2690
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002691 final long identity = Binder.clearCallingIdentity();
2692 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002693 Phone phone = getPhone(subId);
2694 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002695 checkSimPin.start();
2696 return checkSimPin.unlockSim(null, pin);
2697 } finally {
2698 Binder.restoreCallingIdentity(identity);
2699 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002700 }
2701
Wink Savilleb564aae2014-10-23 10:18:09 -07002702 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002703 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002704
joonhunshin4ac60942023-11-15 15:23:39 +00002705 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2706 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "supplyPukForSubscriber");
2707
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002708 final long identity = Binder.clearCallingIdentity();
2709 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002710 Phone phone = getPhone(subId);
2711 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002712 checkSimPuk.start();
2713 return checkSimPuk.unlockSim(puk, pin);
2714 } finally {
2715 Binder.restoreCallingIdentity(identity);
2716 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002717 }
2718
2719 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002720 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002721 * a synchronous one.
2722 */
2723 private static class UnlockSim extends Thread {
2724
2725 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002726 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002727
2728 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002729 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2730 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002731
2732 // For replies from SimCard interface
2733 private Handler mHandler;
2734
2735 // For async handler to identify request type
2736 private static final int SUPPLY_PIN_COMPLETE = 100;
arunvoddu7bf930c2024-05-20 04:24:40 +00002737 private static final int SUPPLY_PIN_DELAYED = 101;
2738 private static final int SUPPLY_PIN_DELAYED_TIMER_IN_MILLIS = 10000;
2739 private static final UUID SUPPLY_PIN_UUID = UUID.fromString(
2740 "d3768135-4323-491d-a6c8-bda01fc89040");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002741
Michele Berionne5e411512020-11-13 02:36:59 +00002742 UnlockSim(int phoneId, IccCard simCard) {
2743 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002744 mSimCard = simCard;
2745 }
2746
2747 @Override
2748 public void run() {
2749 Looper.prepare();
2750 synchronized (UnlockSim.this) {
2751 mHandler = new Handler() {
2752 @Override
2753 public void handleMessage(Message msg) {
2754 AsyncResult ar = (AsyncResult) msg.obj;
2755 switch (msg.what) {
2756 case SUPPLY_PIN_COMPLETE:
2757 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2758 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002759 mRetryCount = msg.arg1;
2760 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002761 CommandException.Error error = null;
2762 if (ar.exception instanceof CommandException) {
2763 error = ((CommandException) (ar.exception))
2764 .getCommandError();
2765 }
2766 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07002767 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002768 } else if (error == CommandException.Error.ABORTED) {
2769 /* When UiccCardApp dispose, handle message and return
2770 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08002771 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002772 } else {
2773 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2774 }
2775 } else {
2776 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2777 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002778 mDone = true;
arunvoddu7bf930c2024-05-20 04:24:40 +00002779 removeMessages(SUPPLY_PIN_DELAYED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002780 UnlockSim.this.notifyAll();
2781 }
2782 break;
arunvoddu7bf930c2024-05-20 04:24:40 +00002783 case SUPPLY_PIN_DELAYED:
2784 if(!mDone) {
2785 String logStr = "Delay in receiving SIM PIN response ";
2786 if (DBG) log(logStr);
2787 AnomalyReporter.reportAnomaly(SUPPLY_PIN_UUID, logStr);
2788 }
2789 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002790 }
2791 }
2792 };
2793 UnlockSim.this.notifyAll();
2794 }
2795 Looper.loop();
2796 }
2797
2798 /*
2799 * Use PIN or PUK to unlock SIM card
2800 *
2801 * If PUK is null, unlock SIM card with PIN
2802 *
2803 * If PUK is not null, unlock SIM card with PUK and set PIN code
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302804 *
2805 * Besides, since it is reused in class level, the thread's looper will be stopped to avoid
2806 * its thread leak.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002807 */
Wink Saville9de0f752013-10-22 19:04:03 -07002808 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002809
2810 while (mHandler == null) {
2811 try {
2812 wait();
2813 } catch (InterruptedException e) {
2814 Thread.currentThread().interrupt();
2815 }
2816 }
2817 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2818
2819 if (puk == null) {
2820 mSimCard.supplyPin(pin, callback);
2821 } else {
2822 mSimCard.supplyPuk(puk, pin, callback);
2823 }
2824
2825 while (!mDone) {
2826 try {
2827 Log.d(LOG_TAG, "wait for done");
arunvoddu7bf930c2024-05-20 04:24:40 +00002828 mHandler.sendEmptyMessageDelayed(SUPPLY_PIN_DELAYED,
2829 SUPPLY_PIN_DELAYED_TIMER_IN_MILLIS);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002830 wait();
2831 } catch (InterruptedException e) {
2832 // Restore the interrupted status
2833 Thread.currentThread().interrupt();
2834 }
2835 }
2836 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002837 int[] resultArray = new int[2];
2838 resultArray[0] = mResult;
2839 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002840
2841 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002842 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002843 }
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302844 // This instance is no longer reused, so quit its thread's looper.
2845 mHandler.getLooper().quitSafely();
Michele Berionne5e411512020-11-13 02:36:59 +00002846
Wink Saville9de0f752013-10-22 19:04:03 -07002847 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002848 }
2849 }
2850
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002851 /**
2852 * This method has been removed due to privacy and stability concerns.
2853 */
2854 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002855 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002856 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2857 return;
Wink Saville36469e72014-06-11 15:17:00 -07002858 }
2859
Nathan Harold1f889d82020-06-04 17:05:26 -07002860 @Override
2861 public void updateServiceLocationWithPackageName(String callingPackage) {
2862 mApp.getSystemService(AppOpsManager.class)
2863 .checkPackage(Binder.getCallingUid(), callingPackage);
2864
Nathan Haroldf096d982020-11-18 17:18:06 -08002865 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002866 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2867 // Callers targeting S have no business invoking this method.
2868 return;
2869 }
2870
2871 LocationAccessPolicy.LocationPermissionResult locationResult =
2872 LocationAccessPolicy.checkLocationPermission(mApp,
2873 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2874 .setCallingPackage(callingPackage)
2875 .setCallingFeatureId(null)
2876 .setCallingPid(Binder.getCallingPid())
2877 .setCallingUid(Binder.getCallingUid())
2878 .setMethod("updateServiceLocation")
2879 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2880 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2881 .build());
2882 // Apps that lack location permission have no business calling this method;
2883 // however, because no permission was declared in the public API, denials must
2884 // all be "soft".
2885 switch (locationResult) {
2886 case DENIED_HARD: /* fall through */
2887 case DENIED_SOFT:
2888 return;
2889 }
2890
2891 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002892 final long identity = Binder.clearCallingIdentity();
2893 try {
Ling Mac28f0212023-03-24 16:07:15 -07002894 getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002895 } finally {
2896 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002897 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002898 }
2899
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002900 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002901 @Override
2902 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002903 return isRadioOnWithFeature(callingPackage, null);
2904 }
2905
2906
2907 @Override
2908 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2909 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2910 callingFeatureId);
2911 }
2912
2913 @Deprecated
2914 @Override
2915 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2916 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002917 }
2918
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002919 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002920 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2921 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002922 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002923 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002924 return false;
2925 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002926
joonhunshin4ac60942023-11-15 15:23:39 +00002927 enforceTelephonyFeatureWithException(callingPackage,
2928 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isRadioOnWithFeature");
2929
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002930 final long identity = Binder.clearCallingIdentity();
2931 try {
2932 return isRadioOnForSubscriber(subId);
2933 } finally {
2934 Binder.restoreCallingIdentity(identity);
2935 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002936 }
2937
2938 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002939 final long identity = Binder.clearCallingIdentity();
2940 try {
2941 final Phone phone = getPhone(subId);
2942 if (phone != null) {
2943 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2944 } else {
2945 return false;
2946 }
2947 } finally {
2948 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002949 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002950 }
2951
2952 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002953 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002954 }
Wink Saville36469e72014-06-11 15:17:00 -07002955
Wink Savilleb564aae2014-10-23 10:18:09 -07002956 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002957 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002958
joonhunshin4ac60942023-11-15 15:23:39 +00002959 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2960 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "toggleRadioOnOffForSubscriber");
2961
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002962 final long identity = Binder.clearCallingIdentity();
2963 try {
2964 final Phone phone = getPhone(subId);
2965 if (phone != null) {
2966 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2967 }
2968 } finally {
2969 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002970 }
Wink Saville36469e72014-06-11 15:17:00 -07002971 }
2972
2973 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002974 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002975 }
2976
Wink Savilleb564aae2014-10-23 10:18:09 -07002977 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002978 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002979
2980 final long identity = Binder.clearCallingIdentity();
2981 try {
2982 final Phone phone = getPhone(subId);
2983 if (phone == null) {
2984 return false;
2985 }
2986 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2987 toggleRadioOnOffForSubscriber(subId);
2988 }
2989 return true;
2990 } finally {
2991 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002992 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002993 }
Wink Saville36469e72014-06-11 15:17:00 -07002994
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002995 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002996 enforceReadPrivilegedPermission("needMobileRadioShutdown");
joonhunshin4ac60942023-11-15 15:23:39 +00002997
2998 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2999 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needMobileRadioShutdown");
3000
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003001 /*
3002 * If any of the Radios are available, it will need to be
3003 * shutdown. So return true if any Radio is available.
3004 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003005 final long identity = Binder.clearCallingIdentity();
3006 try {
3007 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3008 Phone phone = PhoneFactory.getPhone(i);
3009 if (phone != null && phone.isRadioAvailable()) return true;
3010 }
3011 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
3012 return false;
3013 } finally {
3014 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003015 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003016 }
3017
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003018 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003019 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003020 enforceModifyPermission();
3021
joonhunshin4ac60942023-11-15 15:23:39 +00003022 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3023 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "shutdownMobileRadios");
3024
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003025 final long identity = Binder.clearCallingIdentity();
3026 try {
3027 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3028 logv("Shutting down Phone " + i);
3029 shutdownRadioUsingPhoneId(i);
3030 }
3031 } finally {
3032 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003033 }
3034 }
3035
3036 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003037 Phone phone = PhoneFactory.getPhone(phoneId);
3038 if (phone != null && phone.isRadioAvailable()) {
3039 phone.shutdownRadio();
3040 }
3041 }
3042
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003043 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07003044 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003045
Ling Ma83dc5ea2023-01-12 15:06:04 -08003046 if (!turnOn) {
3047 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
3048 }
3049
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003050 final long identity = Binder.clearCallingIdentity();
3051 try {
3052 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
3053 if (defaultPhone != null) {
3054 defaultPhone.setRadioPower(turnOn);
3055 return true;
3056 } else {
3057 loge("There's no default phone.");
3058 return false;
3059 }
3060 } finally {
3061 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07003062 }
Wink Saville36469e72014-06-11 15:17:00 -07003063 }
3064
Wink Savilleb564aae2014-10-23 10:18:09 -07003065 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003066 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003067
Ling Ma83dc5ea2023-01-12 15:06:04 -08003068 if (!turnOn) {
3069 log("setRadioPowerForSubscriber off: subId=" + subId
3070 + ",callingPackage=" + getCurrentPackageName());
3071 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003072 final long identity = Binder.clearCallingIdentity();
3073 try {
3074 final Phone phone = getPhone(subId);
3075 if (phone != null) {
3076 phone.setRadioPower(turnOn);
3077 return true;
3078 } else {
3079 return false;
3080 }
3081 } finally {
3082 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003083 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003084 }
3085
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003086 /**
3087 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3088 * no reason to power it off. When any of the voters want to power it off, it will be turned
3089 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3090 * powering it off, and these radio off votes will be cleared.
3091 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3092 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3093 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3094 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3095 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3096 * check its vote.
3097 *
3098 * @param subId The subscription ID.
3099 * @param reason The reason for powering off radio.
3100 * @return true on success and false on failure.
3101 */
3102 public boolean requestRadioPowerOffForReason(int subId,
3103 @TelephonyManager.RadioPowerReason int reason) {
3104 enforceModifyPermission();
3105
joonhunshin4ac60942023-11-15 15:23:39 +00003106 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3107 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestRadioPowerOffForReason");
3108
Ling Ma83dc5ea2023-01-12 15:06:04 -08003109 log("requestRadioPowerOffForReason: subId=" + subId
3110 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003111 final long identity = Binder.clearCallingIdentity();
3112 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003113 boolean result = false;
3114 for (Phone phone : PhoneFactory.getPhones()) {
3115 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003116 phone.setRadioPowerForReason(false, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003117 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003118 if (!result) {
3119 loge("requestRadioPowerOffForReason: no phone exists");
3120 }
3121 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003122 } finally {
3123 Binder.restoreCallingIdentity(identity);
3124 }
3125 }
3126
3127 /**
3128 * Remove the vote on powering off the radio for a reason, as requested by
3129 * {@link requestRadioPowerOffForReason}.
3130 *
3131 * @param subId The subscription ID.
3132 * @param reason The reason for powering off radio.
3133 * @return true on success and false on failure.
3134 */
3135 public boolean clearRadioPowerOffForReason(int subId,
3136 @TelephonyManager.RadioPowerReason int reason) {
3137 enforceModifyPermission();
3138
joonhunshin4ac60942023-11-15 15:23:39 +00003139 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3140 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearRadioPowerOffForReason");
3141
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003142 final long identity = Binder.clearCallingIdentity();
3143 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003144 boolean result = false;
3145 for (Phone phone : PhoneFactory.getPhones()) {
3146 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003147 phone.setRadioPowerForReason(true, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003148 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003149 if (!result) {
3150 loge("clearRadioPowerOffForReason: no phone exists");
3151 }
3152 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003153 } finally {
3154 Binder.restoreCallingIdentity(identity);
3155 }
3156 }
3157
3158 /**
3159 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3160 *
3161 * @param subId The subscription ID.
3162 * @param callingPackage The package making the call.
3163 * @param callingFeatureId The feature in the package.
3164 * @return List of reasons for powering off radio.
3165 */
3166 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3167 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3168
joonhunshin4ac60942023-11-15 15:23:39 +00003169 enforceTelephonyFeatureWithException(callingPackage,
3170 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerOffReasons");
3171
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003172 final long identity = Binder.clearCallingIdentity();
3173 List result = new ArrayList();
3174 try {
3175 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3176 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3177 return result;
3178 }
3179
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003180 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003181 if (phone != null) {
3182 result.addAll(phone.getRadioPowerOffReasons());
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003183 } else {
3184 loge("getRadioPowerOffReasons: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003185 }
3186 } finally {
3187 Binder.restoreCallingIdentity(identity);
3188 }
3189 return result;
3190 }
3191
Wink Saville36469e72014-06-11 15:17:00 -07003192 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003193 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003194 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003195 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003196
joonhunshin4ac60942023-11-15 15:23:39 +00003197 enforceTelephonyFeatureWithException(callingPackage,
3198 PackageManager.FEATURE_TELEPHONY_DATA, "enableDataConnectivity");
3199
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003200 final long identity = Binder.clearCallingIdentity();
3201 try {
Jack Yu285100e2022-12-02 22:48:35 -08003202 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003203 final Phone phone = getPhone(subId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00003204 if (phone != null && phone.getDataSettingsManager() != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003205 phone.getDataSettingsManager().setDataEnabled(
3206 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003207 return true;
3208 } else {
3209 return false;
3210 }
3211 } finally {
3212 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003213 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003214 }
3215
Wink Saville36469e72014-06-11 15:17:00 -07003216 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003217 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003218 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003219 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003220
joonhunshin4ac60942023-11-15 15:23:39 +00003221 enforceTelephonyFeatureWithException(callingPackage,
3222 PackageManager.FEATURE_TELEPHONY_DATA, "disableDataConnectivity");
3223
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003224 final long identity = Binder.clearCallingIdentity();
3225 try {
Jack Yu285100e2022-12-02 22:48:35 -08003226 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003227 final Phone phone = getPhone(subId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00003228 if (phone != null && phone.getDataSettingsManager() != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003229 phone.getDataSettingsManager().setDataEnabled(
3230 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003231 return true;
3232 } else {
3233 return false;
3234 }
3235 } finally {
3236 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003237 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003238 }
3239
Sanket Padawe356d7632015-06-22 14:03:32 -07003240 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003241 public boolean isDataConnectivityPossible(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003242 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3243 PackageManager.FEATURE_TELEPHONY_DATA, "isDataConnectivityPossible");
3244
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003245 final long identity = Binder.clearCallingIdentity();
3246 try {
3247 final Phone phone = getPhone(subId);
3248 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003249 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003250 } else {
3251 return false;
3252 }
3253 } finally {
3254 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003255 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003256 }
3257
3258 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003259 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003260 }
3261
pkanwarae03a6b2016-11-06 20:37:09 -08003262 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003263 enforceCallPermission();
3264
joonhunshin4ac60942023-11-15 15:23:39 +00003265 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3266 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "handleUssdRequest");
3267
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003268 final long identity = Binder.clearCallingIdentity();
3269 try {
3270 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3271 return;
3272 }
3273 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3274 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3275 } finally {
3276 Binder.restoreCallingIdentity(identity);
3277 }
pkanwar32d516d2016-10-14 19:37:38 -07003278 };
3279
Wink Savilleb564aae2014-10-23 10:18:09 -07003280 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003281 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003282
joonhunshin4ac60942023-11-15 15:23:39 +00003283 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3284 PackageManager.FEATURE_TELEPHONY_CALLING, "handlePinMmiForSubscriber");
3285
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003286 final long identity = Binder.clearCallingIdentity();
3287 try {
3288 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3289 return false;
3290 }
3291 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3292 } finally {
3293 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003294 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003295 }
3296
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003297 /**
3298 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3299 * tag on getCallState Binder call.
3300 */
3301 @Deprecated
3302 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003303 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003304 if (CompatChanges.isChangeEnabled(
3305 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3306 Binder.getCallingUid())) {
3307 // Do not allow this API to be called on API version 31+, it should only be
3308 // called on old apps using this Binder call directly.
3309 throw new SecurityException("This method can only be used for applications "
3310 + "targeting API version 30 or less.");
3311 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003312 final long identity = Binder.clearCallingIdentity();
3313 try {
Ling Mac28f0212023-03-24 16:07:15 -07003314 Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription());
3315 return PhoneConstantConversions.convertCallState(phone.getState());
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003316 } finally {
3317 Binder.restoreCallingIdentity(identity);
3318 }
3319 }
3320
3321 @Override
3322 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3323 if (CompatChanges.isChangeEnabled(
3324 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3325 Binder.getCallingUid())) {
3326 // Check READ_PHONE_STATE for API version 31+
3327 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3328 featureId, "getCallStateForSubscription")) {
3329 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3330 + "targeting API level 31+.");
3331 }
3332 }
joonhunshin4ac60942023-11-15 15:23:39 +00003333
3334 enforceTelephonyFeatureWithException(callingPackage,
3335 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallStateForSubscription");
3336
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003337 final long identity = Binder.clearCallingIdentity();
3338 try {
3339 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003340 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3341 PhoneConstantConversions.convertCallState(phone.getState());
3342 } finally {
3343 Binder.restoreCallingIdentity(identity);
3344 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003345 }
3346
Sanket Padawe356d7632015-06-22 14:03:32 -07003347 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003348 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003349 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003350 }
3351
3352 @Override
3353 public int getDataStateForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003354 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3355 PackageManager.FEATURE_TELEPHONY_DATA, "getDataStateForSubId");
3356
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003357 final long identity = Binder.clearCallingIdentity();
3358 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003359 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003360 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003361 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003362 } else {
3363 return PhoneConstantConversions.convertDataState(
3364 PhoneConstants.DataState.DISCONNECTED);
3365 }
3366 } finally {
3367 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003368 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003369 }
3370
Sanket Padawe356d7632015-06-22 14:03:32 -07003371 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003372 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003373 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003374 }
3375
3376 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003377 public @DataActivityType int getDataActivityForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003378 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3379 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivityForSubId");
3380
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003381 final long identity = Binder.clearCallingIdentity();
3382 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003383 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003384 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003385 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003386 } else {
3387 return TelephonyManager.DATA_ACTIVITY_NONE;
3388 }
3389 } finally {
3390 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003391 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003392 }
3393
3394 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003395 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003396 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003397 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003398
3399 LocationAccessPolicy.LocationPermissionResult locationResult =
3400 LocationAccessPolicy.checkLocationPermission(mApp,
3401 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3402 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003403 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003404 .setCallingPid(Binder.getCallingPid())
3405 .setCallingUid(Binder.getCallingUid())
3406 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003407 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003408 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3409 .build());
3410 switch (locationResult) {
3411 case DENIED_HARD:
3412 throw new SecurityException("Not allowed to access cell location");
3413 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003414 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3415 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003416 }
3417
joonhunshin4ac60942023-11-15 15:23:39 +00003418 enforceTelephonyFeatureWithException(callingPackage,
3419 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getCellLocation");
3420
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003421 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003422 final long identity = Binder.clearCallingIdentity();
3423 try {
3424 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003425 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003426 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003427 } finally {
3428 Binder.restoreCallingIdentity(identity);
3429 }
Svetoslav64fad262015-04-14 14:35:21 -07003430 }
3431
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003432 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003433 public String getNetworkCountryIsoForPhone(int phoneId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003434 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3435 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkCountryIsoForPhone");
3436
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003437 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3438 // registered cell info, so return a NULL country instead.
3439 final long identity = Binder.clearCallingIdentity();
3440 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003441 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3442 // Get default phone in this case.
3443 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3444 }
Jack Yu285100e2022-12-02 22:48:35 -08003445 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003446 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003447 if (phone == null) return "";
3448 ServiceStateTracker sst = phone.getServiceStateTracker();
3449 if (sst == null) return "";
3450 LocaleTracker lt = sst.getLocaleTracker();
3451 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003452 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003453 } finally {
3454 Binder.restoreCallingIdentity(identity);
3455 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003456 }
3457
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003458 /**
3459 * This method was removed due to potential issues caused by performing partial
3460 * updates of service state, and lack of a credible use case.
3461 *
3462 * This has the ability to break the telephony implementation by disabling notification of
3463 * changes in device connectivity. DO NOT USE THIS!
3464 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003465 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003466 public void enableLocationUpdates() {
3467 mApp.enforceCallingOrSelfPermission(
3468 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003469 }
3470
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003471 /**
3472 * This method was removed due to potential issues caused by performing partial
3473 * updates of service state, and lack of a credible use case.
3474 *
3475 * This has the ability to break the telephony implementation by disabling notification of
3476 * changes in device connectivity. DO NOT USE THIS!
3477 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003478 @Override
3479 public void disableLocationUpdates() {
3480 mApp.enforceCallingOrSelfPermission(
3481 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003482 }
3483
3484 @Override
3485 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003486 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3487 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003488 try {
3489 mApp.getSystemService(AppOpsManager.class)
3490 .checkPackage(Binder.getCallingUid(), callingPackage);
3491 } catch (SecurityException e) {
3492 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3493 throw e;
3494 }
3495
Nathan Haroldf096d982020-11-18 17:18:06 -08003496 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003497 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3498 throw new SecurityException(
3499 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3500 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003501
Jordan Liu1617b712019-07-10 15:06:26 -07003502 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003503 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3504 return null;
3505 }
Svetoslav64fad262015-04-14 14:35:21 -07003506
joonhunshin4ac60942023-11-15 15:23:39 +00003507 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3508 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNeighboringCellInfo");
3509
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003510 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003511
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003512 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003513 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003514
Nathan Haroldf180aac2018-06-01 18:43:55 -07003515 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3516 for (CellInfo ci : info) {
3517 if (ci instanceof CellInfoGsm) {
3518 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3519 } else if (ci instanceof CellInfoWcdma) {
3520 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3521 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003522 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003523 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003524 }
3525
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003526 private List<CellInfo> getCachedCellInfo() {
3527 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3528 for (Phone phone : PhoneFactory.getPhones()) {
3529 List<CellInfo> info = phone.getAllCellInfo();
3530 if (info != null) cellInfos.addAll(info);
3531 }
3532 return cellInfos;
3533 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003534
3535 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003536 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003537 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003538 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003539
3540 LocationAccessPolicy.LocationPermissionResult locationResult =
3541 LocationAccessPolicy.checkLocationPermission(mApp,
3542 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3543 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003544 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003545 .setCallingPid(Binder.getCallingPid())
3546 .setCallingUid(Binder.getCallingUid())
3547 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003548 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003549 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3550 .build());
3551 switch (locationResult) {
3552 case DENIED_HARD:
3553 throw new SecurityException("Not allowed to access cell info");
3554 case DENIED_SOFT:
3555 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003556 }
3557
Nathan Haroldf096d982020-11-18 17:18:06 -08003558 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003559 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3560 return getCachedCellInfo();
3561 }
3562
joonhunshin4ac60942023-11-15 15:23:39 +00003563 enforceTelephonyFeatureWithException(callingPackage,
3564 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllCellInfo");
3565
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003566 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003567 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003568 final long identity = Binder.clearCallingIdentity();
3569 try {
3570 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3571 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003572 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003573 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003574 if (info != null) cellInfos.addAll(info);
3575 }
3576 return cellInfos;
3577 } finally {
3578 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003579 }
3580 }
3581
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003582 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003583 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3584 String callingFeatureId) {
3585 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3586 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003587 }
3588
3589 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003590 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3591 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003592 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003593 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003594 }
3595
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003596 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3597 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003598 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003599 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003600
3601 LocationAccessPolicy.LocationPermissionResult locationResult =
3602 LocationAccessPolicy.checkLocationPermission(mApp,
3603 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3604 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003605 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003606 .setCallingPid(Binder.getCallingPid())
3607 .setCallingUid(Binder.getCallingUid())
3608 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003609 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3610 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003611 .build());
3612 switch (locationResult) {
3613 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003614 if (TelephonyPermissions
3615 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003616 // Safetynet logging for b/154934934
3617 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3618 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003619 throw new SecurityException("Not allowed to access cell info");
3620 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003621 if (TelephonyPermissions
3622 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003623 // Safetynet logging for b/154934934
3624 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3625 }
Nathan Harold5320c422019-05-09 10:26:08 -07003626 try {
3627 cb.onCellInfo(new ArrayList<CellInfo>());
3628 } catch (RemoteException re) {
3629 // Drop without consequences
3630 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003631 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003632 }
3633
joonhunshin4ac60942023-11-15 15:23:39 +00003634 enforceTelephonyFeatureWithException(callingPackage,
3635 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestCellInfoUpdateInternal");
Nathan Harolda939a962019-05-09 10:13:47 -07003636
3637 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003638 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3639
3640 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3641 }
3642
3643 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003644 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003645 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003646 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003647
3648 final long identity = Binder.clearCallingIdentity();
3649 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003650 Phone phone = getPhone(subId);
3651 if (phone == null) {
3652 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3653 } else {
3654 phone.setCellInfoListRate(rateInMillis, workSource);
3655 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003656 } finally {
3657 Binder.restoreCallingIdentity(identity);
3658 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003659 }
3660
Shishir Agrawala9f32182016-04-12 12:00:16 -07003661 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003662 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003663 Phone phone = PhoneFactory.getPhone(slotIndex);
3664 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003665 return null;
3666 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003667 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003668 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003669 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003670 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003671 return null;
3672 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003673
joonhunshin4ac60942023-11-15 15:23:39 +00003674 enforceTelephonyFeatureWithException(callingPackage,
3675 PackageManager.FEATURE_TELEPHONY_GSM, "getImeiForSlot");
3676
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003677 final long identity = Binder.clearCallingIdentity();
3678 try {
3679 return phone.getImei();
3680 } finally {
3681 Binder.restoreCallingIdentity(identity);
3682 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003683 }
3684
3685 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003686 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3687 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3688 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3689 callingFeatureId, "getPrimaryImei")) {
3690 throw new SecurityException("Caller does not have permission");
3691 }
joonhunshin4ac60942023-11-15 15:23:39 +00003692
3693 enforceTelephonyFeatureWithException(callingPackage,
3694 PackageManager.FEATURE_TELEPHONY_GSM, "getPrimaryImei");
3695
arunvoddud5c6ce02022-12-11 06:03:12 +00003696 final long identity = Binder.clearCallingIdentity();
3697 try {
3698 for (Phone phone : PhoneFactory.getPhones()) {
3699 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3700 return phone.getImei();
3701 }
3702 }
3703 throw new UnsupportedOperationException("Operation not supported");
3704 } finally {
3705 Binder.restoreCallingIdentity(identity);
3706 }
3707 }
3708
3709 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003710 public String getTypeAllocationCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003711 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3712 PackageManager.FEATURE_TELEPHONY_GSM, "getTypeAllocationCodeForSlot");
3713
David Kelly5e06a7f2018-03-12 14:10:59 +00003714 Phone phone = PhoneFactory.getPhone(slotIndex);
3715 String tac = null;
3716 if (phone != null) {
3717 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003718 try {
3719 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3720 } catch (IndexOutOfBoundsException e) {
3721 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3722 return null;
3723 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003724 }
3725 return tac;
3726 }
3727
3728 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003729 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003730 try {
3731 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3732 } catch (SecurityException se) {
3733 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3734 throw new SecurityException("Package " + callingPackage + " does not belong to "
3735 + Binder.getCallingUid());
3736 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003737 Phone phone = PhoneFactory.getPhone(slotIndex);
3738 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003739 return null;
3740 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003741
Jeff Davidson913390f2018-02-23 17:11:49 -08003742 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003743 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003744 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003745 return null;
3746 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003747
joonhunshin4ac60942023-11-15 15:23:39 +00003748 enforceTelephonyFeatureWithException(callingPackage,
3749 PackageManager.FEATURE_TELEPHONY_CDMA, "getMeidForSlot");
3750
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003751 final long identity = Binder.clearCallingIdentity();
3752 try {
3753 return phone.getMeid();
3754 } finally {
3755 Binder.restoreCallingIdentity(identity);
3756 }
Jack Yu2af8d712017-03-15 17:14:14 -07003757 }
3758
3759 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003760 public String getManufacturerCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003761 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3762 PackageManager.FEATURE_TELEPHONY_CDMA, "getManufacturerCodeForSlot");
3763
David Kelly5e06a7f2018-03-12 14:10:59 +00003764 Phone phone = PhoneFactory.getPhone(slotIndex);
3765 String manufacturerCode = null;
3766 if (phone != null) {
3767 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003768 try {
3769 manufacturerCode =
3770 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3771 } catch (IndexOutOfBoundsException e) {
3772 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3773 return null;
3774 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003775 }
3776 return manufacturerCode;
3777 }
3778
3779 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003780 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3781 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003782 Phone phone = PhoneFactory.getPhone(slotIndex);
3783 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003784 return null;
3785 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003786 int subId = phone.getSubId();
3787 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003788 mApp, subId, callingPackage, callingFeatureId,
3789 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003790 return null;
3791 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003792
joonhunshin4ac60942023-11-15 15:23:39 +00003793 enforceTelephonyFeatureWithException(callingPackage,
3794 PackageManager.FEATURE_TELEPHONY, "getDeviceSoftwareVersionForSlot");
3795
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003796 final long identity = Binder.clearCallingIdentity();
3797 try {
3798 return phone.getDeviceSvn();
3799 } finally {
3800 Binder.restoreCallingIdentity(identity);
3801 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003802 }
3803
fionaxu43304da2017-11-27 22:51:16 -08003804 @Override
3805 public int getSubscriptionCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003806 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3807 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierId");
3808
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003809 final long identity = Binder.clearCallingIdentity();
3810 try {
3811 final Phone phone = getPhone(subId);
3812 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3813 } finally {
3814 Binder.restoreCallingIdentity(identity);
3815 }
fionaxu43304da2017-11-27 22:51:16 -08003816 }
3817
3818 @Override
3819 public String getSubscriptionCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003820 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3821 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierName");
3822
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003823 final long identity = Binder.clearCallingIdentity();
3824 try {
3825 final Phone phone = getPhone(subId);
3826 return phone == null ? null : phone.getCarrierName();
3827 } finally {
3828 Binder.restoreCallingIdentity(identity);
3829 }
fionaxu43304da2017-11-27 22:51:16 -08003830 }
3831
calvinpanffe225e2018-11-01 19:43:06 +08003832 @Override
chen xu0026ca62019-03-06 15:28:50 -08003833 public int getSubscriptionSpecificCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003834 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3835 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionSpecificCarrierId");
3836
chen xu25637222018-11-04 17:17:00 -08003837 final long identity = Binder.clearCallingIdentity();
3838 try {
3839 final Phone phone = getPhone(subId);
3840 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003841 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003842 } finally {
3843 Binder.restoreCallingIdentity(identity);
3844 }
3845 }
3846
3847 @Override
chen xu0026ca62019-03-06 15:28:50 -08003848 public String getSubscriptionSpecificCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003849 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3850 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
3851 "getSubscriptionSpecificCarrierName");
3852
chen xu25637222018-11-04 17:17:00 -08003853 final long identity = Binder.clearCallingIdentity();
3854 try {
3855 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003856 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003857 } finally {
3858 Binder.restoreCallingIdentity(identity);
3859 }
3860 }
3861
chen xu651eec72018-11-11 19:03:44 -08003862 @Override
chen xu864e11c2018-12-06 22:10:03 -08003863 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3864 if (!isSubscriptionMccMnc) {
3865 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3866 }
chen xu651eec72018-11-11 19:03:44 -08003867 final Phone phone = PhoneFactory.getPhone(slotIndex);
3868 if (phone == null) {
3869 return TelephonyManager.UNKNOWN_CARRIER_ID;
3870 }
joonhunshin4ac60942023-11-15 15:23:39 +00003871
3872 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3873 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromMccMnc");
3874
chen xu651eec72018-11-11 19:03:44 -08003875 final long identity = Binder.clearCallingIdentity();
3876 try {
3877 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3878 } finally {
3879 Binder.restoreCallingIdentity(identity);
3880 }
3881 }
3882
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003883 //
3884 // Internal helper methods.
3885 //
3886
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003887 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003888 * Make sure the caller is the calling package itself
3889 *
3890 * @throws SecurityException if the caller is not the calling package
3891 */
3892 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3893 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003894 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3895 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003896 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003897 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003898 } catch (PackageManager.NameNotFoundException e) {
3899 // packageUid is -1
3900 }
3901 if (packageUid != callingUid) {
3902 throw new SecurityException(message + ": Package " + callingPackage
3903 + " does not belong to " + callingUid);
3904 }
3905 }
3906
3907 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003908 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3909 *
3910 * @throws SecurityException if the caller does not have the required permission
3911 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003912 @VisibleForTesting
3913 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003914 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3915 }
3916
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003917 /**
arunvoddud7401012022-12-15 16:08:12 +00003918 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003919 *
3920 * @throws SecurityException if the caller does not have the required permission
3921 */
3922 @VisibleForTesting
3923 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003924 enforceReadPermission(null);
3925 }
3926
3927 /**
3928 * Make sure the caller has the READ_PHONE_STATE permissions.
3929 *
3930 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3931 */
3932 @VisibleForTesting
3933 public void enforceReadPermission(String msg) {
3934 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003935 }
3936
Shuo Qian3b6ee772019-11-13 17:43:31 -08003937 private void enforceActiveEmergencySessionPermission() {
3938 mApp.enforceCallingOrSelfPermission(
3939 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3940 }
3941
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003942 /**
3943 * Make sure the caller has the CALL_PHONE permission.
3944 *
3945 * @throws SecurityException if the caller does not have the required permission
3946 */
3947 private void enforceCallPermission() {
3948 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3949 }
3950
paulhu5a773602019-08-23 19:17:33 +08003951 private void enforceSettingsPermission() {
3952 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003953 }
3954
Michele Berionne5e411512020-11-13 02:36:59 +00003955 private void enforceRebootPermission() {
3956 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3957 }
3958
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003959 /**
3960 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3961 * @param message - log message to print.
3962 * @throws SecurityException if the caller does not have the required permission
3963 */
3964 private void enforceSatelliteCommunicationPermission(String message) {
3965 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3966 }
3967
Aishwarya Mallampatif265cea2024-06-04 19:55:41 +00003968 /**
3969 * Make sure the caller has PACKAGE_USAGE_STATS permission.
3970 * @param message - log message to print.
3971 * @throws SecurityException if the caller does not have the required permission
3972 */
3973 private void enforcePackageUsageStatsPermission(String message) {
3974 mApp.enforceCallingOrSelfPermission(permission.PACKAGE_USAGE_STATS, message);
3975 }
3976
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003977 private String createTelUrl(String number) {
3978 if (TextUtils.isEmpty(number)) {
3979 return null;
3980 }
3981
Jake Hambye994d462014-02-03 13:10:13 -08003982 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003983 }
3984
Ihab Awadf9e92732013-12-05 18:02:52 -08003985 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003986 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003987 }
3988
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003989 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003990 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003991 }
3992
Ihab Awadf9e92732013-12-05 18:02:52 -08003993 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003994 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003995 }
3996
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003997 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003998 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003999 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07004000 }
4001
Sanket Padawe356d7632015-06-22 14:03:32 -07004002 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004003 public int getActivePhoneTypeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00004004 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4005 PackageManager.FEATURE_TELEPHONY, "getActivePhoneTypeForSlot");
4006
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004007 final long identity = Binder.clearCallingIdentity();
4008 try {
4009 final Phone phone = PhoneFactory.getPhone(slotIndex);
4010 if (phone == null) {
4011 return PhoneConstants.PHONE_TYPE_NONE;
4012 } else {
4013 return phone.getPhoneType();
4014 }
4015 } finally {
4016 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004017 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004018 }
4019
4020 /**
4021 * Returns the CDMA ERI icon index to display
4022 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004023 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004024 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
4025 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
4026 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004027 }
4028
Sanket Padawe356d7632015-06-22 14:03:32 -07004029 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004030 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
4031 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004032 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004033 mApp, subId, callingPackage, callingFeatureId,
4034 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004035 return -1;
4036 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004037
joonhunshin4ac60942023-11-15 15:23:39 +00004038 enforceTelephonyFeatureWithException(callingPackage,
4039 PackageManager.FEATURE_TELEPHONY_CDMA,
4040 "getCdmaEriIconIndexForSubscriber");
4041
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004042 final long identity = Binder.clearCallingIdentity();
4043 try {
4044 final Phone phone = getPhone(subId);
4045 if (phone != null) {
4046 return phone.getCdmaEriIconIndex();
4047 } else {
4048 return -1;
4049 }
4050 } finally {
4051 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004052 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004053 }
4054
4055 /**
4056 * Returns the CDMA ERI icon mode,
4057 * 0 - ON
4058 * 1 - FLASHING
4059 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004060 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004061 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
4062 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
4063 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004064 }
4065
Sanket Padawe356d7632015-06-22 14:03:32 -07004066 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004067 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
4068 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004069 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004070 mApp, subId, callingPackage, callingFeatureId,
4071 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004072 return -1;
4073 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004074
4075 final long identity = Binder.clearCallingIdentity();
4076 try {
4077 final Phone phone = getPhone(subId);
4078 if (phone != null) {
4079 return phone.getCdmaEriIconMode();
4080 } else {
4081 return -1;
4082 }
4083 } finally {
4084 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004085 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004086 }
4087
4088 /**
4089 * Returns the CDMA ERI text,
4090 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004091 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004092 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
4093 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
4094 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004095 }
4096
Sanket Padawe356d7632015-06-22 14:03:32 -07004097 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004098 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
4099 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004100 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004101 mApp, subId, callingPackage, callingFeatureId,
4102 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004103 return null;
4104 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004105
4106 final long identity = Binder.clearCallingIdentity();
4107 try {
4108 final Phone phone = getPhone(subId);
4109 if (phone != null) {
4110 return phone.getCdmaEriText();
4111 } else {
4112 return null;
4113 }
4114 } finally {
4115 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004116 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004117 }
4118
4119 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07004120 * Returns the CDMA MDN.
4121 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004122 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004123 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004124 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4125 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004126
joonhunshin4ac60942023-11-15 15:23:39 +00004127 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4128 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMdn");
4129
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004130 final long identity = Binder.clearCallingIdentity();
4131 try {
4132 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004133 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004134 return phone.getLine1Number();
4135 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004136 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004137 return null;
4138 }
4139 } finally {
4140 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004141 }
4142 }
4143
4144 /**
4145 * Returns the CDMA MIN.
4146 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004147 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004148 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004149 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4150 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004151
joonhunshin4ac60942023-11-15 15:23:39 +00004152 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4153 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMin");
4154
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004155 final long identity = Binder.clearCallingIdentity();
4156 try {
4157 final Phone phone = getPhone(subId);
4158 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
4159 return phone.getCdmaMin();
4160 } else {
4161 return null;
4162 }
4163 } finally {
4164 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004165 }
4166 }
4167
Hall Liud892bec2018-11-30 14:51:45 -08004168 @Override
4169 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
4170 INumberVerificationCallback callback, String callingPackage) {
4171 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
4172 != PERMISSION_GRANTED) {
4173 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
4174 }
4175 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4176
4177 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
4178 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08004179 throw new SecurityException("Calling package must be configured in the device config: "
4180 + "calling package: " + callingPackage
4181 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004182 }
4183
joonhunshin4ac60942023-11-15 15:23:39 +00004184 enforceTelephonyFeatureWithException(callingPackage,
4185 PackageManager.FEATURE_TELEPHONY_CALLING, "requestNumberVerification");
4186
Hall Liud892bec2018-11-30 14:51:45 -08004187 if (range == null) {
4188 throw new NullPointerException("Range must be non-null");
4189 }
4190
4191 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004192 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004193
4194 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4195 }
4196
Junda Liuca05d5d2014-08-14 22:36:34 -07004197 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004198 * Returns true if CDMA provisioning needs to run.
4199 */
4200 public boolean needsOtaServiceProvisioning() {
joonhunshin4ac60942023-11-15 15:23:39 +00004201 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4202 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needsOtaServiceProvisioning");
4203
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004204 final long identity = Binder.clearCallingIdentity();
4205 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004206 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004207 } finally {
4208 Binder.restoreCallingIdentity(identity);
4209 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004210 }
4211
4212 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004213 * Sets the voice mail number of a given subId.
4214 */
4215 @Override
4216 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004217 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4218 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004219
joonhunshin4ac60942023-11-15 15:23:39 +00004220 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4221 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceMailNumber");
4222
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004223 final long identity = Binder.clearCallingIdentity();
4224 try {
4225 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4226 new Pair<String, String>(alphaTag, number), new Integer(subId));
4227 return success;
4228 } finally {
4229 Binder.restoreCallingIdentity(identity);
4230 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004231 }
4232
Ta-wei Yen87c49842016-05-13 21:19:52 -07004233 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004234 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4235 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004236 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4237 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004238 if (!TextUtils.equals(callingPackage, systemDialer)) {
4239 throw new SecurityException("caller must be system dialer");
4240 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004241
joonhunshin4ac60942023-11-15 15:23:39 +00004242 enforceTelephonyFeatureWithException(callingPackage,
4243 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailSettings");
4244
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004245 final long identity = Binder.clearCallingIdentity();
4246 try {
4247 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4248 if (phoneAccountHandle == null) {
4249 return null;
4250 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004251 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004252 } finally {
4253 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004254 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004255 }
4256
4257 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004258 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4259 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004260 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004261 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004262 mApp, subId, callingPackage, callingFeatureId,
4263 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004264 return null;
4265 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004266
joonhunshin4ac60942023-11-15 15:23:39 +00004267 enforceTelephonyFeatureWithException(callingPackage,
4268 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailPackageName");
4269
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004270 final long identity = Binder.clearCallingIdentity();
4271 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004272 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004273 } finally {
4274 Binder.restoreCallingIdentity(identity);
4275 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004276 }
4277
4278 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004279 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4280 VisualVoicemailSmsFilterSettings settings) {
4281 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Thomas Stuart1c55f992024-06-06 22:34:33 +00004282 enforceVisualVoicemailPackage(callingPackage, subId);
joonhunshin4ac60942023-11-15 15:23:39 +00004283 enforceTelephonyFeatureWithException(callingPackage,
4284 PackageManager.FEATURE_TELEPHONY_CALLING, "enableVisualVoicemailSmsFilter");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004285 final long identity = Binder.clearCallingIdentity();
4286 try {
4287 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004288 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004289 } finally {
4290 Binder.restoreCallingIdentity(identity);
4291 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004292 }
4293
4294 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004295 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4296 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Thomas Stuart9aee7c72024-06-28 17:33:03 +00004297 enforceVisualVoicemailPackage(callingPackage, subId);
joonhunshin4ac60942023-11-15 15:23:39 +00004298 enforceTelephonyFeatureWithException(callingPackage,
4299 PackageManager.FEATURE_TELEPHONY_CALLING, "disableVisualVoicemailSmsFilter");
4300
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004301 final long identity = Binder.clearCallingIdentity();
4302 try {
4303 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004304 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004305 } finally {
4306 Binder.restoreCallingIdentity(identity);
4307 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004308 }
4309
4310 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004311 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4312 String callingPackage, int subId) {
4313 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004314
4315 final long identity = Binder.clearCallingIdentity();
4316 try {
4317 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004318 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004319 } finally {
4320 Binder.restoreCallingIdentity(identity);
4321 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004322 }
4323
4324 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004325 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004326 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004327
4328 final long identity = Binder.clearCallingIdentity();
4329 try {
4330 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004331 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004332 } finally {
4333 Binder.restoreCallingIdentity(identity);
4334 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004335 }
4336
4337 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004338 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4339 String callingAttributionTag, int subId, String number, int port, String text,
4340 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004341 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004342 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004343 enforceSendSmsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00004344
4345 enforceTelephonyFeatureWithException(callingPackage,
4346 PackageManager.FEATURE_TELEPHONY_CALLING, "sendVisualVoicemailSmsForSubscriber");
4347
Amit Mahajandccb3f12019-05-13 13:48:32 -07004348 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004349 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4350 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004351 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004352
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004353 /**
fionaxu0152e512016-11-14 13:36:14 -08004354 * Sets the voice activation state of a given subId.
4355 */
4356 @Override
4357 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004358 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4359 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004360
joonhunshin4ac60942023-11-15 15:23:39 +00004361 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4362 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState");
4363
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004364 final long identity = Binder.clearCallingIdentity();
4365 try {
4366 final Phone phone = getPhone(subId);
4367 if (phone != null) {
4368 phone.setVoiceActivationState(activationState);
4369 } else {
4370 loge("setVoiceActivationState fails with invalid subId: " + subId);
4371 }
4372 } finally {
4373 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004374 }
4375 }
4376
4377 /**
4378 * Sets the data activation state of a given subId.
4379 */
4380 @Override
4381 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004382 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4383 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004384
joonhunshin4ac60942023-11-15 15:23:39 +00004385 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4386 PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState");
4387
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004388 final long identity = Binder.clearCallingIdentity();
4389 try {
4390 final Phone phone = getPhone(subId);
4391 if (phone != null) {
4392 phone.setDataActivationState(activationState);
4393 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004394 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004395 }
4396 } finally {
4397 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004398 }
4399 }
4400
4401 /**
4402 * Returns the voice activation state of a given subId.
4403 */
4404 @Override
4405 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004406 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004407
joonhunshin4ac60942023-11-15 15:23:39 +00004408 enforceTelephonyFeatureWithException(callingPackage,
4409 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState");
4410
fionaxu0152e512016-11-14 13:36:14 -08004411 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004412 final long identity = Binder.clearCallingIdentity();
4413 try {
4414 if (phone != null) {
4415 return phone.getVoiceActivationState();
4416 } else {
4417 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4418 }
4419 } finally {
4420 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004421 }
4422 }
4423
4424 /**
4425 * Returns the data activation state of a given subId.
4426 */
4427 @Override
4428 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004429 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004430
joonhunshin4ac60942023-11-15 15:23:39 +00004431 enforceTelephonyFeatureWithException(callingPackage,
4432 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState");
4433
fionaxu0152e512016-11-14 13:36:14 -08004434 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004435 final long identity = Binder.clearCallingIdentity();
4436 try {
4437 if (phone != null) {
4438 return phone.getDataActivationState();
4439 } else {
4440 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4441 }
4442 } finally {
4443 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004444 }
4445 }
4446
4447 /**
Wink Saville36469e72014-06-11 15:17:00 -07004448 * Returns the unread count of voicemails for a subId
4449 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004450 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004451 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4452 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004453 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004454 mApp, subId, callingPackage, callingFeatureId,
4455 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004456 return 0;
4457 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004458 final long identity = Binder.clearCallingIdentity();
4459 try {
4460 final Phone phone = getPhone(subId);
4461 if (phone != null) {
4462 return phone.getVoiceMessageCount();
4463 } else {
4464 return 0;
4465 }
4466 } finally {
4467 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004468 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004469 }
4470
4471 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004472 * returns true, if the device is in a state where both voice and data
4473 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004474 */
4475 @Override
4476 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00004477 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4478 PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed");
4479
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004480 final long identity = Binder.clearCallingIdentity();
4481 try {
Ling Mac28f0212023-03-24 16:07:15 -07004482 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004483 } finally {
4484 Binder.restoreCallingIdentity(identity);
4485 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004486 }
4487
4488 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004489 * Send the dialer code if called from the current default dialer or the caller has
4490 * carrier privilege.
4491 * @param inputCode The dialer code to send
4492 */
4493 @Override
4494 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004495 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004496 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004497 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4498 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004499 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004500 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004501 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004502 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004503
joonhunshin4ac60942023-11-15 15:23:39 +00004504 enforceTelephonyFeatureWithException(callingPackage,
4505 PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode");
4506
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004507 final long identity = Binder.clearCallingIdentity();
4508 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004509 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004510 } finally {
4511 Binder.restoreCallingIdentity(identity);
4512 }
fionaxu235cc5e2017-03-06 22:25:57 -08004513 }
4514
Pengquan Menga1bb6272018-09-06 09:59:22 -07004515 @Override
4516 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004517 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004518 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4519 mApp, subId, "getNetworkSelectionMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004520
4521 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4522 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode");
4523
shilufc958392020-01-20 11:36:01 -08004524 final long identity = Binder.clearCallingIdentity();
4525 try {
4526 if (!isActiveSubscription(subId)) {
4527 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4528 }
4529 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4530 } finally {
4531 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004532 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004533 }
4534
Brad Ebinger35c841c2018-10-01 10:40:55 -07004535 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004536 public boolean isInEmergencySmsMode() {
4537 enforceReadPrivilegedPermission("isInEmergencySmsMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004538
4539 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4540 PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode");
4541
Brad Ebingerb2b65522019-03-15 13:48:47 -07004542 final long identity = Binder.clearCallingIdentity();
4543 try {
4544 for (Phone phone : PhoneFactory.getPhones()) {
4545 if (phone.isInEmergencySmsMode()) {
4546 return true;
4547 }
4548 }
4549 } finally {
4550 Binder.restoreCallingIdentity(identity);
4551 }
4552 return false;
4553 }
4554
shilu366312e2019-12-17 09:28:10 -08004555 /**
4556 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4557 * @param subId The subscription to use to check the configuration.
4558 * @param c The callback that will be used to send the result.
4559 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004560 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004561 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4562 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004563 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004564 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004565
4566 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4567 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4568 "IMS not available on device.");
4569 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004570 final long token = Binder.clearCallingIdentity();
4571 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004572 int slotId = getSlotIndexOrException(subId);
4573 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004574
4575 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4576 if (controller != null) {
4577 ImsManager imsManager = controller.getImsManager(subId);
4578 if (imsManager != null) {
4579 imsManager.addRegistrationCallbackForSubscription(c, subId);
4580 } else {
4581 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4582 }
4583 } else {
4584 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4585 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004586 } catch (ImsException e) {
4587 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004588 } finally {
4589 Binder.restoreCallingIdentity(token);
4590 }
4591 }
4592
shilu366312e2019-12-17 09:28:10 -08004593 /**
4594 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4595 * @param subId The subscription to use to check the configuration.
4596 * @param c The callback that will be used to send the result.
4597 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004598 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004599 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004600 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004601 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004602 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4603 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4604 }
Meng Wangafbc5852019-09-19 17:37:13 -07004605 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004606
Meng Wangafbc5852019-09-19 17:37:13 -07004607 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004608 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4609 if (controller != null) {
4610 ImsManager imsManager = controller.getImsManager(subId);
4611 if (imsManager != null) {
4612 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4613 } else {
4614 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4615 + "is inactive, ignoring unregister.");
4616 // If the ImsManager is not valid, just return, since the callback
4617 // will already have been removed internally.
4618 }
4619 }
Meng Wangafbc5852019-09-19 17:37:13 -07004620 } finally {
4621 Binder.restoreCallingIdentity(token);
4622 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004623 }
4624
Brad Ebingera34a6c22019-10-22 17:36:18 -07004625 /**
Hidayat Khan99ea48f2023-12-11 04:37:45 +00004626 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4627 * @param subId The subscription to use to check the configuration.
4628 * @param c The callback that will be used to send the result.
4629 */
4630 @Override
4631 public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c)
4632 throws RemoteException {
4633 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4634 mApp, subId, "registerImsEmergencyRegistrationCallback");
4635
4636 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4637 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4638 "IMS not available on device.");
4639 }
4640 final long token = Binder.clearCallingIdentity();
4641 try {
4642 int slotId = getSlotIndexOrException(subId);
4643 verifyImsMmTelConfiguredOrThrow(slotId);
4644
4645 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4646 if (controller != null) {
4647 ImsManager imsManager = controller.getImsManager(subId);
4648 if (imsManager != null) {
4649 imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId);
4650 } else {
4651 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4652 }
4653 } else {
4654 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4655 }
4656 } catch (ImsException e) {
4657 throw new ServiceSpecificException(e.getCode());
4658 } finally {
4659 Binder.restoreCallingIdentity(token);
4660 }
4661 }
4662
4663 /**
4664 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4665 * @param subId The subscription to use to check the configuration.
4666 * @param c The callback that will be used to send the result.
4667 */
4668 @Override
4669 public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) {
4670 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4671 mApp, subId, "unregisterImsEmergencyRegistrationCallback");
4672 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4673 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4674 }
4675 final long token = Binder.clearCallingIdentity();
4676
4677 try {
4678 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4679 if (controller != null) {
4680 ImsManager imsManager = controller.getImsManager(subId);
4681 if (imsManager != null) {
4682 imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId);
4683 } else {
4684 Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId
4685 + "is inactive, ignoring unregister.");
4686 // If the ImsManager is not valid, just return, since the callback
4687 // will already have been removed internally.
4688 }
4689 }
4690 } finally {
4691 Binder.restoreCallingIdentity(token);
4692 }
4693 }
4694
4695 /**
Brad Ebingera34a6c22019-10-22 17:36:18 -07004696 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4697 */
4698 @Override
4699 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4700 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4701 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4702 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4703 "IMS not available on device.");
4704 }
4705 final long token = Binder.clearCallingIdentity();
4706 try {
4707 Phone phone = getPhone(subId);
4708 if (phone == null) {
4709 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4710 + subId + "'");
4711 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4712 }
4713 phone.getImsRegistrationState(regState -> {
4714 try {
4715 consumer.accept((regState == null)
4716 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4717 } catch (RemoteException e) {
4718 // Ignore if the remote process is no longer available to call back.
4719 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4720 }
4721 });
4722 } finally {
4723 Binder.restoreCallingIdentity(token);
4724 }
4725 }
4726
4727 /**
4728 * Get the transport type for the IMS service registration state.
4729 */
4730 @Override
4731 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004732 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004733 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004734 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4735 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4736 "IMS not available on device.");
4737 }
4738 final long token = Binder.clearCallingIdentity();
4739 try {
4740 Phone phone = getPhone(subId);
4741 if (phone == null) {
4742 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4743 + subId + "'");
4744 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4745 }
4746 phone.getImsRegistrationTech(regTech -> {
4747 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4748 int regTechConverted = (regTech == null)
4749 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4750 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4751 regTechConverted);
4752 try {
4753 consumer.accept(regTechConverted);
4754 } catch (RemoteException e) {
4755 // Ignore if the remote process is no longer available to call back.
4756 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4757 }
4758 });
4759 } finally {
4760 Binder.restoreCallingIdentity(token);
4761 }
4762 }
4763
shilu366312e2019-12-17 09:28:10 -08004764 /**
4765 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4766 * @param subId The subscription to use to check the configuration.
4767 * @param c The callback that will be used to send the result.
4768 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004769 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004770 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4771 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004772 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004773 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004774 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4775 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4776 "IMS not available on device.");
4777 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004778 final long token = Binder.clearCallingIdentity();
4779 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004780 int slotId = getSlotIndexOrException(subId);
4781 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004782
4783 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4784 if (controller != null) {
4785 ImsManager imsManager = controller.getImsManager(subId);
4786 if (imsManager != null) {
4787 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4788 } else {
4789 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4790 }
4791 } else {
4792 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4793 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004794 } catch (ImsException e) {
4795 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004796 } finally {
4797 Binder.restoreCallingIdentity(token);
4798 }
4799 }
4800
shilu366312e2019-12-17 09:28:10 -08004801 /**
4802 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4803 * @param subId The subscription to use to check the configuration.
4804 * @param c The callback that will be used to send the result.
4805 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004806 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004807 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004808 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004809 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004810 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4811 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4812 }
Meng Wangafbc5852019-09-19 17:37:13 -07004813
4814 final long token = Binder.clearCallingIdentity();
4815 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004816 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4817 if (controller != null) {
4818 ImsManager imsManager = controller.getImsManager(subId);
4819 if (imsManager != null) {
4820 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4821 } else {
4822 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4823 + " is inactive, ignoring unregister.");
4824 // If the ImsManager is not valid, just return, since the callback
4825 // will already have been removed internally.
4826 }
4827 }
Meng Wangafbc5852019-09-19 17:37:13 -07004828 } finally {
4829 Binder.restoreCallingIdentity(token);
4830 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004831 }
4832
4833 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004834 public boolean isCapable(int subId, int capability, int regTech) {
4835 enforceReadPrivilegedPermission("isCapable");
joonhunshin4ac60942023-11-15 15:23:39 +00004836
4837 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4838 FEATURE_TELEPHONY_IMS, "isCapable");
4839
Brad Ebinger35c841c2018-10-01 10:40:55 -07004840 final long token = Binder.clearCallingIdentity();
4841 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004842 int slotId = getSlotIndexOrException(subId);
4843 verifyImsMmTelConfiguredOrThrow(slotId);
4844 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4845 } catch (com.android.ims.ImsException e) {
4846 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4847 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004848 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004849 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4850 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004851 } finally {
4852 Binder.restoreCallingIdentity(token);
4853 }
4854 }
4855
4856 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004857 public boolean isAvailable(int subId, int capability, int regTech) {
4858 enforceReadPrivilegedPermission("isAvailable");
joonhunshin4ac60942023-11-15 15:23:39 +00004859
4860 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4861 FEATURE_TELEPHONY_IMS, "isAvailable");
4862
Brad Ebinger35c841c2018-10-01 10:40:55 -07004863 final long token = Binder.clearCallingIdentity();
4864 try {
4865 Phone phone = getPhone(subId);
4866 if (phone == null) return false;
4867 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004868 } catch (com.android.ims.ImsException e) {
4869 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4870 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004871 } finally {
4872 Binder.restoreCallingIdentity(token);
4873 }
4874 }
4875
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004876 /**
4877 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4878 * subscription.
4879 * @param subId The subscription to use to check the configuration.
4880 * @param callback The callback that will be used to send the result.
4881 * @param capability The MmTelFeature capability that will be used to send the result.
4882 * @param transportType The transport type of the MmTelFeature capability.
4883 */
4884 @Override
4885 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4886 int transportType) {
4887 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004888 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4889 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4890 "IMS not available on device.");
4891 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004892 final long token = Binder.clearCallingIdentity();
4893 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004894 int slotId = getSlotIndex(subId);
4895 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4896 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4897 + subId + "'");
4898 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4899 }
4900 verifyImsMmTelConfiguredOrThrow(slotId);
4901 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4902 transportType, aBoolean -> {
4903 try {
4904 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4905 } catch (RemoteException e) {
4906 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4907 + "running. Ignore");
4908 }
4909 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004910 } catch (ImsException e) {
4911 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004912 } finally {
4913 Binder.restoreCallingIdentity(token);
4914 }
4915 }
4916
shilu366312e2019-12-17 09:28:10 -08004917 /**
4918 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4919 * @param subId The subscription to use to check the configuration.
4920 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004921 @Override
4922 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004923 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004924 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004925
joonhunshin4ac60942023-11-15 15:23:39 +00004926 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4927 FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled");
4928
Brad Ebinger35c841c2018-10-01 10:40:55 -07004929 final long token = Binder.clearCallingIdentity();
4930 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004931 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004932 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004933 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004934 } catch (ImsException e) {
4935 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004936 } finally {
4937 Binder.restoreCallingIdentity(token);
4938 }
4939 }
4940
4941 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004942 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004943 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004944 "setAdvancedCallingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004945
4946 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4947 FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled");
4948
Brad Ebinger35c841c2018-10-01 10:40:55 -07004949 final long identity = Binder.clearCallingIdentity();
4950 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004951 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004952 // This setting doesn't require an active ImsService connection, so do not verify. The
4953 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004954 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004955 } catch (ImsException e) {
4956 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004957 } finally {
4958 Binder.restoreCallingIdentity(identity);
4959 }
4960 }
4961
shilu366312e2019-12-17 09:28:10 -08004962 /**
4963 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4964 * @param subId The subscription to use to check the configuration.
4965 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004966 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004967 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004968 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004969 mApp, subId, "isVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004970
4971 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4972 FEATURE_TELEPHONY_IMS, "isVtSettingEnabled");
4973
Brad Ebinger35c841c2018-10-01 10:40:55 -07004974 final long identity = Binder.clearCallingIdentity();
4975 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004976 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004977 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004978 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004979 } catch (ImsException e) {
4980 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004981 } finally {
4982 Binder.restoreCallingIdentity(identity);
4983 }
4984 }
4985
4986 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004987 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004988 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004989 "setVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004990
4991 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4992 FEATURE_TELEPHONY_IMS, "setVtSettingEnabled");
4993
Brad Ebinger35c841c2018-10-01 10:40:55 -07004994 final long identity = Binder.clearCallingIdentity();
4995 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004996 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004997 // This setting doesn't require an active ImsService connection, so do not verify. The
4998 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004999 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005000 } catch (ImsException e) {
5001 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005002 } finally {
5003 Binder.restoreCallingIdentity(identity);
5004 }
5005 }
5006
shilu366312e2019-12-17 09:28:10 -08005007 /**
5008 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5009 * @param subId The subscription to use to check the configuration.
5010 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005011 @Override
5012 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005013 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005014 mApp, subId, "isVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005015
5016 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5017 FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled");
5018
Brad Ebinger35c841c2018-10-01 10:40:55 -07005019 final long identity = Binder.clearCallingIdentity();
5020 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005021 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005022 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005023 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005024 } catch (ImsException e) {
5025 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005026 } finally {
5027 Binder.restoreCallingIdentity(identity);
5028 }
5029 }
5030
5031 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005032 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005033 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005034 "setVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005035
5036 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5037 FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled");
5038
Brad Ebinger35c841c2018-10-01 10:40:55 -07005039 final long identity = Binder.clearCallingIdentity();
5040 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005041 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005042 // This setting doesn't require an active ImsService connection, so do not verify. The
5043 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005044 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005045 } catch (ImsException e) {
5046 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005047 } finally {
5048 Binder.restoreCallingIdentity(identity);
5049 }
5050 }
5051
shilu366312e2019-12-17 09:28:10 -08005052 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005053 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
5054 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5055 * @param subId The subscription to use to check the configuration.
5056 */
5057 @Override
5058 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005059 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005060 mApp, subId, "isCrossSimCallingEnabledByUser");
joonhunshin4ac60942023-11-15 15:23:39 +00005061
5062 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5063 FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser");
5064
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005065 final long identity = Binder.clearCallingIdentity();
5066 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005067 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005068 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005069 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005070 } catch (ImsException e) {
5071 throw new ServiceSpecificException(e.getCode());
5072 } finally {
5073 Binder.restoreCallingIdentity(identity);
5074 }
5075 }
5076
5077 /**
5078 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
5079 * Requires MODIFY_PHONE_STATE permission.
5080 * @param subId The subscription to use to check the configuration.
5081 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
5082 * false otherwise
5083 */
5084 @Override
5085 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
5086 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5087 "setCrossSimCallingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005088
5089 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5090 FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled");
5091
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005092 final long identity = Binder.clearCallingIdentity();
5093 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005094 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005095 // This setting doesn't require an active ImsService connection, so do not verify. The
5096 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005097 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005098 } catch (ImsException e) {
5099 throw new ServiceSpecificException(e.getCode());
5100 } finally {
5101 Binder.restoreCallingIdentity(identity);
5102 }
5103 }
5104
5105 /**
shilu366312e2019-12-17 09:28:10 -08005106 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5107 * @param subId The subscription to use to check the configuration.
5108 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005109 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07005110
Brad Ebinger35c841c2018-10-01 10:40:55 -07005111 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005112 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005113 mApp, subId, "isVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005114
5115 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5116 FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled");
5117
Brad Ebinger35c841c2018-10-01 10:40:55 -07005118 final long identity = Binder.clearCallingIdentity();
5119 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005120 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005121 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005122 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005123 } catch (ImsException e) {
5124 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005125 } finally {
5126 Binder.restoreCallingIdentity(identity);
5127 }
5128 }
5129
5130 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005131 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005132 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005133 "setVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005134
5135 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5136 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled");
5137
Brad Ebinger35c841c2018-10-01 10:40:55 -07005138 final long identity = Binder.clearCallingIdentity();
5139 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005140 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005141 // This setting doesn't require an active ImsService connection, so do not verify. The
5142 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005143 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005144 } catch (ImsException e) {
5145 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005146 } finally {
5147 Binder.restoreCallingIdentity(identity);
5148 }
5149 }
5150
5151 @Override
5152 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
5153 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5154 "setVoWiFiNonPersistent");
joonhunshin4ac60942023-11-15 15:23:39 +00005155
5156 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5157 FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent");
5158
Brad Ebinger35c841c2018-10-01 10:40:55 -07005159 final long identity = Binder.clearCallingIdentity();
5160 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005161 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005162 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005163 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005164 } catch (ImsException e) {
5165 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005166 } finally {
5167 Binder.restoreCallingIdentity(identity);
5168 }
5169 }
5170
shilu366312e2019-12-17 09:28:10 -08005171 /**
5172 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5173 * @param subId The subscription to use to check the configuration.
5174 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005175 @Override
5176 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005177 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005178 mApp, subId, "getVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005179
5180 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5181 FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting");
5182
Brad Ebinger35c841c2018-10-01 10:40:55 -07005183 final long identity = Binder.clearCallingIdentity();
5184 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005185 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005186 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005187 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005188 } catch (ImsException e) {
5189 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005190 } finally {
5191 Binder.restoreCallingIdentity(identity);
5192 }
5193 }
5194
5195 @Override
5196 public void setVoWiFiModeSetting(int subId, int mode) {
5197 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5198 "setVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005199
5200 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5201 FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting");
5202
Brad Ebinger35c841c2018-10-01 10:40:55 -07005203 final long identity = Binder.clearCallingIdentity();
5204 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005205 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005206 // This setting doesn't require an active ImsService connection, so do not verify. The
5207 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005208 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005209 } catch (ImsException e) {
5210 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005211 } finally {
5212 Binder.restoreCallingIdentity(identity);
5213 }
5214 }
5215
5216 @Override
5217 public int getVoWiFiRoamingModeSetting(int subId) {
5218 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005219
5220 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5221 FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting");
5222
Brad Ebinger35c841c2018-10-01 10:40:55 -07005223 final long identity = Binder.clearCallingIdentity();
5224 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005225 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005226 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005227 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005228 } catch (ImsException e) {
5229 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005230 } finally {
5231 Binder.restoreCallingIdentity(identity);
5232 }
5233 }
5234
5235 @Override
5236 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
5237 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5238 "setVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005239
5240 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5241 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting");
5242
Brad Ebinger35c841c2018-10-01 10:40:55 -07005243 final long identity = Binder.clearCallingIdentity();
5244 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005245 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005246 // This setting doesn't require an active ImsService connection, so do not verify. The
5247 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005248 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005249 } catch (ImsException e) {
5250 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005251 } finally {
5252 Binder.restoreCallingIdentity(identity);
5253 }
5254 }
5255
5256 @Override
5257 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
5258 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5259 "setRttCapabilityEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005260
5261 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5262 FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting");
5263
Brad Ebinger35c841c2018-10-01 10:40:55 -07005264 final long identity = Binder.clearCallingIdentity();
5265 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005266 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005267 // This setting doesn't require an active ImsService connection, so do not verify. The
5268 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005269 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005270 } catch (ImsException e) {
5271 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005272 } finally {
5273 Binder.restoreCallingIdentity(identity);
5274 }
5275 }
5276
shilu366312e2019-12-17 09:28:10 -08005277 /**
5278 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5279 * @param subId The subscription to use to check the configuration.
5280 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005281 @Override
5282 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005283 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005284 mApp, subId, "isTtyOverVolteEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005285
5286 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5287 FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled");
5288
Brad Ebinger35c841c2018-10-01 10:40:55 -07005289 final long identity = Binder.clearCallingIdentity();
5290 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005291 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005292 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005293 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005294 } catch (ImsException e) {
5295 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005296 } finally {
5297 Binder.restoreCallingIdentity(identity);
5298 }
5299 }
5300
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005301 @Override
5302 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5303 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005304
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005305 final long identity = Binder.clearCallingIdentity();
5306 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005307 if (!isImsAvailableOnDevice()) {
5308 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5309 "IMS not available on device.");
5310 }
5311 int slotId = getSlotIndexOrException(subId);
5312 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005313
5314 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5315 if (controller != null) {
5316 ImsManager imsManager = controller.getImsManager(subId);
5317 if (imsManager != null) {
5318 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5319 } else {
5320 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5321 }
5322 } else {
5323 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5324 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005325 } catch (ImsException e) {
5326 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005327 } finally {
5328 Binder.restoreCallingIdentity(identity);
5329 }
5330 }
5331
5332 @Override
5333 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5334 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005335
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005336 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005337 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5338 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5339 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005340 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005341 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5342 if (controller != null) {
5343 ImsManager imsManager = controller.getImsManager(subId);
5344 if (imsManager != null) {
5345 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5346 } else {
5347 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5348 + " is inactive, ignoring unregister.");
5349 // If the ImsManager is not valid, just return, since the callback will already
5350 // have been removed internally.
5351 }
5352 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005353 } finally {
5354 Binder.restoreCallingIdentity(identity);
5355 }
5356 }
5357
joonhunshincffb7fc2021-11-28 07:32:01 +00005358 @Override
5359 public void registerFeatureProvisioningChangedCallback(int subId,
5360 IFeatureProvisioningCallback callback) {
5361 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5362 mApp, subId, "registerFeatureProvisioningChangedCallback");
5363
5364 final long identity = Binder.clearCallingIdentity();
5365 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5366 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5367 }
5368
joonhunshin91bc1952022-04-29 08:47:15 +00005369 try {
5370 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5371 if (controller == null) {
5372 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5373 "Device does not support IMS");
5374 }
5375 controller.addFeatureProvisioningChangedCallback(subId, callback);
5376 } finally {
5377 Binder.restoreCallingIdentity(identity);
5378 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005379 }
5380
5381 @Override
5382 public void unregisterFeatureProvisioningChangedCallback(int subId,
5383 IFeatureProvisioningCallback callback) {
5384 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5385 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5386
5387 final long identity = Binder.clearCallingIdentity();
5388 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5389 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5390 }
5391
joonhunshin91bc1952022-04-29 08:47:15 +00005392 try {
5393 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5394 if (controller == null) {
5395 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5396 return;
5397 }
5398 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5399 } finally {
5400 Binder.restoreCallingIdentity(identity);
5401 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005402 }
allenwtsu99c623b2020-01-03 18:24:23 +08005403
5404 private void checkModifyPhoneStatePermission(int subId, String message) {
5405 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5406 message);
5407 }
5408
allenwtsu99c623b2020-01-03 18:24:23 +08005409 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005410 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005411 boolean isProvisioned) {
5412 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5413
joonhunshin4ac60942023-11-15 15:23:39 +00005414 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5415 FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability");
5416
allenwtsu99c623b2020-01-03 18:24:23 +08005417 final long identity = Binder.clearCallingIdentity();
5418 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005419 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5420 if (controller == null) {
5421 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5422 return;
5423 }
5424 controller.setRcsProvisioningStatusForCapability(
5425 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005426 } finally {
5427 Binder.restoreCallingIdentity(identity);
5428 }
allenwtsu99c623b2020-01-03 18:24:23 +08005429 }
5430
5431
5432 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005433 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5434 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5435 mApp, subId, "getRcsProvisioningStatusForCapability");
5436
joonhunshin4ac60942023-11-15 15:23:39 +00005437 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5438 FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability");
5439
allenwtsu99c623b2020-01-03 18:24:23 +08005440 final long identity = Binder.clearCallingIdentity();
5441 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005442 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5443 if (controller == null) {
5444 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5445
5446 // device does not support IMS, this method will return true always.
5447 return true;
5448 }
5449 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005450 } finally {
5451 Binder.restoreCallingIdentity(identity);
5452 }
5453 }
5454
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005455 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005456 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5457 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005458 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005459
joonhunshin4ac60942023-11-15 15:23:39 +00005460 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5461 FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability");
5462
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005463 final long identity = Binder.clearCallingIdentity();
5464 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005465 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5466 if (controller == null) {
5467 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5468 return;
5469 }
5470 controller.setImsProvisioningStatusForCapability(
5471 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005472 } finally {
5473 Binder.restoreCallingIdentity(identity);
5474 }
5475 }
5476
5477 @Override
5478 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005479 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5480 mApp, subId, "getProvisioningStatusForCapability");
5481
joonhunshin4ac60942023-11-15 15:23:39 +00005482 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5483 FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability");
5484
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005485 final long identity = Binder.clearCallingIdentity();
5486 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005487 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5488 if (controller == null) {
5489 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005490
joonhunshin91bc1952022-04-29 08:47:15 +00005491 // device does not support IMS, this method will return true always.
5492 return true;
5493 }
5494 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005495 } finally {
5496 Binder.restoreCallingIdentity(identity);
5497 }
5498 }
5499
5500 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005501 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5502 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5503 mApp, subId, "isProvisioningRequiredForCapability");
5504
joonhunshin4ac60942023-11-15 15:23:39 +00005505 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5506 FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability");
5507
joonhunshincffb7fc2021-11-28 07:32:01 +00005508 final long identity = Binder.clearCallingIdentity();
5509 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005510 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5511 if (controller == null) {
5512 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5513
5514 // device does not support IMS, this method will return false
5515 return false;
5516 }
5517 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005518 } finally {
5519 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005520 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005521 }
5522
5523 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005524 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5525 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5526 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005527
joonhunshin4ac60942023-11-15 15:23:39 +00005528 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5529 FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability");
5530
joonhunshincffb7fc2021-11-28 07:32:01 +00005531 final long identity = Binder.clearCallingIdentity();
5532 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005533 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5534 if (controller == null) {
5535 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5536
5537 // device does not support IMS, this method will return false
5538 return false;
5539 }
5540 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005541 } finally {
5542 Binder.restoreCallingIdentity(identity);
5543 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005544 }
5545
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005546 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005547 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005548 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5549 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5550 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005551 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5552 mApp, subId, "getImsProvisioningInt");
5553
joonhunshin4ac60942023-11-15 15:23:39 +00005554 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5555 FEATURE_TELEPHONY_IMS, "getImsProvisioningInt");
5556
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005557 final long identity = Binder.clearCallingIdentity();
5558 try {
5559 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005560 int slotId = getSlotIndex(subId);
5561 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5562 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5563 + subId + "' for key:" + key);
5564 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5565 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005566
joonhunshin91bc1952022-04-29 08:47:15 +00005567 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5568 if (controller == null) {
5569 loge("getImsProvisioningInt: Device does not support IMS");
5570
5571 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5572 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5573 }
5574 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005575 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5576 return retVal;
5577 }
5578
calvinpanb5a34062021-02-08 19:59:36 +08005579 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005580 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005581 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5582 + subId + "' for key:" + key);
5583 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005584 } finally {
5585 Binder.restoreCallingIdentity(identity);
5586 }
5587 }
5588
5589 @Override
5590 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005591 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5592 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5593 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005594 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5595 mApp, subId, "getImsProvisioningString");
5596
joonhunshin4ac60942023-11-15 15:23:39 +00005597 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5598 FEATURE_TELEPHONY_IMS, "getImsProvisioningString");
5599
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005600 final long identity = Binder.clearCallingIdentity();
5601 try {
5602 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005603 int slotId = getSlotIndex(subId);
5604 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5605 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5606 + subId + "' for key:" + key);
5607 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5608 }
calvinpanb5a34062021-02-08 19:59:36 +08005609 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005610 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005611 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5612 + subId + "' for key:" + key);
5613 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005614 } finally {
5615 Binder.restoreCallingIdentity(identity);
5616 }
5617 }
5618
5619 @Override
5620 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005621 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5622 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5623 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005624 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5625 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005626
joonhunshin4ac60942023-11-15 15:23:39 +00005627 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5628 FEATURE_TELEPHONY_IMS, "setImsProvisioningInt");
5629
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005630 final long identity = Binder.clearCallingIdentity();
5631 try {
5632 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005633 int slotId = getSlotIndex(subId);
5634 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5635 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5636 + subId + "' for key:" + key);
5637 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5638 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005639
joonhunshin91bc1952022-04-29 08:47:15 +00005640 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5641 if (controller == null) {
5642 loge("setImsProvisioningInt: Device does not support IMS");
5643
5644 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5645 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5646 }
5647 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005648 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5649 return retVal;
5650 }
5651
calvinpanb5a34062021-02-08 19:59:36 +08005652 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5653 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005654 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005655 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005656 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005657 } finally {
5658 Binder.restoreCallingIdentity(identity);
5659 }
5660 }
5661
5662 @Override
5663 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005664 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5665 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5666 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005667 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5668 "setImsProvisioningString");
joonhunshin4ac60942023-11-15 15:23:39 +00005669
5670 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5671 FEATURE_TELEPHONY_IMS, "setImsProvisioningString");
5672
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005673 final long identity = Binder.clearCallingIdentity();
5674 try {
5675 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005676 int slotId = getSlotIndex(subId);
5677 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5678 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5679 + subId + "' for key:" + key);
5680 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5681 }
calvinpanb5a34062021-02-08 19:59:36 +08005682 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5683 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005684 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005685 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005686 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005687 } finally {
5688 Binder.restoreCallingIdentity(identity);
5689 }
5690 }
5691
Brad Ebinger919631e2021-06-02 17:46:35 -07005692 /**
5693 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5694 * for the given slot ID or no ImsResolver instance has been created.
5695 * @param slotId The slot ID that the IMS service is created for.
5696 * @throws ImsException If there is no ImsService configured for this slot.
5697 */
5698 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5699 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5700 ImsFeature.FEATURE_MMTEL)) {
5701 throw new ImsException("This subscription does not support MMTEL over IMS",
5702 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5703 }
5704 }
5705
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005706 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005707 int slotId = SubscriptionManager.getSlotIndex(subId);
5708 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005709 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5710 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005711 }
5712 return slotId;
5713 }
5714
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005715 private int getSlotIndex(int subId) {
5716 int slotId = SubscriptionManager.getSlotIndex(subId);
5717 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5718 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5719 }
5720 return slotId;
5721 }
5722
Wink Saville36469e72014-06-11 15:17:00 -07005723 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005724 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005725 */
5726 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005727 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5728 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005729 try {
5730 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5731 } catch (SecurityException se) {
5732 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5733 throw new SecurityException("Package " + callingPackage + " does not belong to "
5734 + Binder.getCallingUid());
5735 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005736 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005737 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005738 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005739 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005740 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005741 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005742 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005743 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5744 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005745
joonhunshin4ac60942023-11-15 15:23:39 +00005746 enforceTelephonyFeatureWithException(callingPackage,
5747 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber");
5748
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005749 final long identity = Binder.clearCallingIdentity();
5750 try {
5751 final Phone phone = getPhone(subId);
5752 if (phone != null) {
5753 return phone.getServiceState().getDataNetworkType();
5754 } else {
5755 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5756 }
5757 } finally {
5758 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005759 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005760 }
5761
5762 /**
5763 * Returns the data network type
5764 */
5765 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005766 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005767 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005768 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005769 }
5770
5771 /**
5772 * Returns the data network type for a subId
5773 */
5774 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005775 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5776 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005777 String functionName = "getDataNetworkTypeForSubscriber";
5778 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5779 mApp, functionName)) {
5780 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5781 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5782 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5783 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005784 }
5785
joonhunshin4ac60942023-11-15 15:23:39 +00005786 enforceTelephonyFeatureWithException(callingPackage,
5787 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber");
5788
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005789 final long identity = Binder.clearCallingIdentity();
5790 try {
5791 final Phone phone = getPhone(subId);
5792 if (phone != null) {
5793 return phone.getServiceState().getDataNetworkType();
5794 } else {
5795 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5796 }
5797 } finally {
5798 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005799 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005800 }
5801
5802 /**
Wink Saville36469e72014-06-11 15:17:00 -07005803 * Returns the Voice network type for a subId
5804 */
5805 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005806 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5807 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005808 String functionName = "getVoiceNetworkTypeForSubscriber";
5809 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5810 mApp, functionName)) {
5811 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5812 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5813 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5814 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005815 }
5816
joonhunshin4ac60942023-11-15 15:23:39 +00005817 enforceTelephonyFeatureWithException(callingPackage,
5818 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber");
5819
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005820 final long identity = Binder.clearCallingIdentity();
5821 try {
5822 final Phone phone = getPhone(subId);
5823 if (phone != null) {
5824 return phone.getServiceState().getVoiceNetworkType();
5825 } else {
5826 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5827 }
5828 } finally {
5829 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005830 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005831 }
5832
5833 /**
5834 * @return true if a ICC card is present
5835 */
5836 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005837 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005838 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005839 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005840 }
5841
5842 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005843 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005844 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005845 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005846 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00005847 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5848 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex");
5849
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005850 final long identity = Binder.clearCallingIdentity();
5851 try {
5852 final Phone phone = PhoneFactory.getPhone(slotIndex);
5853 if (phone != null) {
5854 return phone.getIccCard().hasIccCard();
5855 } else {
5856 return false;
5857 }
5858 } finally {
5859 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005860 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005861 }
5862
5863 /**
5864 * Return if the current radio is LTE on CDMA. This
5865 * is a tri-state return value as for a period of time
5866 * the mode may be unknown.
5867 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005868 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005869 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005870 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005871 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005872 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005873 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5874 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5875 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005876 }
5877
Sanket Padawe356d7632015-06-22 14:03:32 -07005878 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005879 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5880 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005881 try {
5882 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5883 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005884 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5885 }
5886
joonhunshin4ac60942023-11-15 15:23:39 +00005887 enforceTelephonyFeatureWithException(callingPackage,
5888 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber");
5889
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005890 final long identity = Binder.clearCallingIdentity();
5891 try {
5892 final Phone phone = getPhone(subId);
5893 if (phone == null) {
5894 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5895 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005896 return TelephonyProperties.lte_on_cdma_device()
5897 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005898 }
5899 } finally {
5900 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005901 }
Wink Saville36469e72014-06-11 15:17:00 -07005902 }
5903
Wink Saville36469e72014-06-11 15:17:00 -07005904 /**
5905 * {@hide}
5906 * Returns Default subId, 0 in the case of single standby.
5907 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005908 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005909 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005910 }
5911
Shishir Agrawala9f32182016-04-12 12:00:16 -07005912 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005913 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005914 }
5915
Wink Savilleb564aae2014-10-23 10:18:09 -07005916 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005917 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005918 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005919
Pengquan Menge92a50d2018-09-21 15:54:48 -07005920 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005921 return getSubscriptionManagerService().isActiveSubId(subId,
5922 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005923 }
5924
Ihab Awadf2177b72013-11-25 13:33:23 -08005925 /**
5926 * @see android.telephony.TelephonyManager.WifiCallingChoices
5927 */
5928 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005929 final long identity = Binder.clearCallingIdentity();
5930 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005931 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005932 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5933 getWhenToMakeWifiCallsDefaultPreference());
5934 } finally {
5935 Binder.restoreCallingIdentity(identity);
5936 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005937 }
5938
5939 /**
5940 * @see android.telephony.TelephonyManager.WifiCallingChoices
5941 */
5942 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005943 final long identity = Binder.clearCallingIdentity();
5944 try {
5945 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005946 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005947 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5948 } finally {
5949 Binder.restoreCallingIdentity(identity);
5950 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005951 }
5952
Sailesh Nepald1e68152013-12-12 19:08:02 -08005953 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005954 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005955 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005956 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005957
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005958 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5959 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5960 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005961 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005962 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005963 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005964 }
5965 return PhoneFactory.getPhone(phoneId);
5966 }
5967
Shishir Agrawal566b7612013-10-28 14:41:00 -07005968 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005969 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005970 @NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00005971
Rambo Wanga1782702021-11-10 20:15:19 -08005972 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5973 /*message=*/ "iccOpenLogicalChannel");
5974
5975 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5976 // Verify that the callingPackage in the request belongs to the calling UID
5977 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5978
joonhunshin4ac60942023-11-15 15:23:39 +00005979 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5980 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel");
5981
Rambo Wanga1782702021-11-10 20:15:19 -08005982 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005983 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005984
Rambo Wanga1782702021-11-10 20:15:19 -08005985 private Phone getPhoneFromValidIccLogicalChannelRequest(
5986 @NonNull IccLogicalChannelRequest request, String message) {
5987 Phone phone;
5988 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5989 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5990 mApp, request.subId, message);
5991 phone = getPhoneFromSubId(request.subId);
5992 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5993 enforceModifyPermission();
5994 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5995 } else {
5996 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005997 }
Rambo Wanga1782702021-11-10 20:15:19 -08005998 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005999 }
6000
6001 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08006002 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006003 final long identity = Binder.clearCallingIdentity();
6004 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006005 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006006 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006007 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6008 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08006009 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
6010 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006011 loge("The calling package is not allowed to access ISD-R.");
6012 throw new SecurityException(
6013 "The calling package is not allowed to access ISD-R.");
6014 }
Derek Tan740e1672017-06-27 14:56:27 -07006015 }
Derek Tan740e1672017-06-27 14:56:27 -07006016
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006017 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08006018 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
6019 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006020 return response;
6021 } finally {
6022 Binder.restoreCallingIdentity(identity);
6023 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006024 }
6025
6026 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08006027 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00006028 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6029 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel");
6030
Rambo Wanga1782702021-11-10 20:15:19 -08006031 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
6032 /*message=*/"iccCloseLogicalChannel");
6033
6034 if (DBG) log("iccCloseLogicalChannel: request=" + request);
6035
6036 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006037 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006038
Rambo Wanga1782702021-11-10 20:15:19 -08006039 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
6040 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08006041 // before this feature is enabled, this API should only return false if
6042 // the operation fails instead of throwing runtime exception for
6043 // backward-compatibility.
6044 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
6045 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006046 final long identity = Binder.clearCallingIdentity();
6047 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006048 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08006049 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006050 }
Chen Xue9d737e2022-01-01 23:41:31 -08006051 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08006052 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08006053 Boolean success = false;
6054 if (result instanceof RuntimeException) {
6055 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08006056 if (shouldThrowExceptionOnFailure) {
6057 throw (RuntimeException) result;
6058 } else {
6059 return false;
6060 }
Chen Xue9d737e2022-01-01 23:41:31 -08006061 } else if (result instanceof Boolean) {
6062 success = (Boolean) result;
6063 } else {
6064 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
6065 }
Rambo Wanga1782702021-11-10 20:15:19 -08006066 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006067 return success;
6068 } finally {
6069 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006070 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006071 }
6072
6073 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006074 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07006075 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006076 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6077 mApp, subId, "iccTransmitApduLogicalChannel");
joonhunshin4ac60942023-11-15 15:23:39 +00006078
6079 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6080 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel");
6081
Jordan Liu4c733742019-02-28 12:03:40 -08006082 if (DBG) {
6083 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
6084 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
6085 + p3 + " data=" + data);
6086 }
6087 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
6088 command, p1, p2, p3, data);
6089 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006090
Jordan Liu4c733742019-02-28 12:03:40 -08006091 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006092 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006093 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006094 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006095
6096 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6097 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
6098 "iccTransmitApduLogicalChannelBySlot");
6099
Jordan Liu4c733742019-02-28 12:03:40 -08006100 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006101 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006102 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
6103 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006104 }
6105 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006106 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
6107 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006108 }
6109
6110 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
6111 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006112 final long identity = Binder.clearCallingIdentity();
6113 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07006114 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006115 return "";
6116 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006117
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006118 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006119 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
6120 null /* workSource */);
6121 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006122
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006123 // Append the returned status code to the end of the response payload.
6124 String s = Integer.toHexString(
6125 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6126 if (response.payload != null) {
6127 s = IccUtils.bytesToHexString(response.payload) + s;
6128 }
6129 return s;
6130 } finally {
6131 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006132 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006133 }
Jake Hambye994d462014-02-03 13:10:13 -08006134
Evan Charltonc66da362014-05-16 14:06:40 -07006135 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006136 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
6137 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006138 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6139 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006140 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006141
6142 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6143 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel");
6144
Jordan Liu4c733742019-02-28 12:03:40 -08006145 if (DBG) {
6146 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
6147 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
6148 }
6149 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
6150 cla, command, p1, p2, p3, data);
6151 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006152
Jordan Liu4c733742019-02-28 12:03:40 -08006153 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006154 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006155 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006156 enforceModifyPermission();
6157 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006158
6159 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6160 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot");
6161
Jordan Liu4c733742019-02-28 12:03:40 -08006162 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006163 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006164 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
6165 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006166 }
6167
6168 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006169 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
6170 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006171 }
6172
6173 // open APDU basic channel assuming the caller has sufficient permissions
6174 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
6175 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006176 final long identity = Binder.clearCallingIdentity();
6177 try {
6178 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
6179 && TextUtils.equals(ISDR_AID, data)) {
6180 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006181 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6182 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006183 if (bestComponent == null
6184 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
6185 loge("The calling package is not allowed to select ISD-R.");
6186 throw new SecurityException(
6187 "The calling package is not allowed to select ISD-R.");
6188 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006189 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006190
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006191 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006192 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
6193 null /* workSource */);
6194 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006195
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006196 // Append the returned status code to the end of the response payload.
6197 String s = Integer.toHexString(
6198 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6199 if (response.payload != null) {
6200 s = IccUtils.bytesToHexString(response.payload) + s;
6201 }
6202 return s;
6203 } finally {
6204 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006205 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006206 }
6207
6208 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006209 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006210 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006211 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6212 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006213
joonhunshin4ac60942023-11-15 15:23:39 +00006214 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6215 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO");
6216
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006217 final long identity = Binder.clearCallingIdentity();
6218 try {
6219 if (DBG) {
6220 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
6221 + p1 + " " + p2 + " " + p3 + ":" + filePath);
6222 }
6223
6224 IccIoResult response =
6225 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
6226 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
6227 subId);
6228
6229 if (DBG) {
6230 log("Exchange SIM_IO [R]" + response);
6231 }
6232
6233 byte[] result = null;
6234 int length = 2;
6235 if (response.payload != null) {
6236 length = 2 + response.payload.length;
6237 result = new byte[length];
6238 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
6239 } else {
6240 result = new byte[length];
6241 }
6242
6243 result[length - 1] = (byte) response.sw2;
6244 result[length - 2] = (byte) response.sw1;
6245 return result;
6246 } finally {
6247 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006248 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006249 }
6250
Nathan Haroldb3014052017-01-25 15:57:32 -08006251 /**
6252 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
6253 * on a particular subscription
6254 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006255 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
6256 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07006257 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006258 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07006259 return null;
6260 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006261
joonhunshin4ac60942023-11-15 15:23:39 +00006262 enforceTelephonyFeatureWithException(callingPackage,
6263 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns");
6264
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006265 final long identity = Binder.clearCallingIdentity();
6266 try {
6267 if (appType != TelephonyManager.APPTYPE_USIM
6268 && appType != TelephonyManager.APPTYPE_SIM) {
6269 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
6270 return null;
6271 }
6272 Object response = sendRequest(
6273 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
6274 if (response instanceof String[]) {
6275 return (String[]) response;
6276 }
yincheng zhao2737e882019-09-06 17:06:54 -07006277 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006278 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08006279 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006280 } finally {
6281 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08006282 }
Nathan Haroldb3014052017-01-25 15:57:32 -08006283 }
6284
yincheng zhao2737e882019-09-06 17:06:54 -07006285 /**
6286 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
6287 * subscription.
6288 *
6289 * @param subId the id of the subscription.
6290 * @param appType the uicc app type, must be USIM or SIM.
6291 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
6292 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006293 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07006294 * @return number of fplmns that is successfully written to the SIM.
6295 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006296 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
6297 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07006298 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6299 mApp, subId, "setForbiddenPlmns");
6300
joonhunshin4ac60942023-11-15 15:23:39 +00006301 enforceTelephonyFeatureWithException(callingPackage,
6302 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns");
6303
yincheng zhao2737e882019-09-06 17:06:54 -07006304 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
6305 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
6306 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
6307 }
6308 if (fplmns == null) {
6309 throw new IllegalArgumentException("Fplmn List provided is null");
6310 }
6311 for (String fplmn : fplmns) {
6312 if (!CellIdentity.isValidPlmn(fplmn)) {
6313 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
6314 }
6315 }
6316 final long identity = Binder.clearCallingIdentity();
6317 try {
6318 Object response = sendRequest(
6319 CMD_SET_FORBIDDEN_PLMNS,
6320 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
6321 subId);
6322 return (int) response;
6323 } finally {
6324 Binder.restoreCallingIdentity(identity);
6325 }
6326 }
6327
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006328 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006329 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006330 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6331 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07006332
joonhunshin4ac60942023-11-15 15:23:39 +00006333 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6334 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus");
6335
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006336 final long identity = Binder.clearCallingIdentity();
6337 try {
6338 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
6339 if (response.payload == null) {
6340 return "";
6341 }
Evan Charltonc66da362014-05-16 14:06:40 -07006342
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006343 // Append the returned status code to the end of the response payload.
6344 String s = Integer.toHexString(
6345 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6346 s = IccUtils.bytesToHexString(response.payload) + s;
6347 return s;
6348 } finally {
6349 Binder.restoreCallingIdentity(identity);
6350 }
Evan Charltonc66da362014-05-16 14:06:40 -07006351 }
6352
Jake Hambye994d462014-02-03 13:10:13 -08006353 /**
6354 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6355 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6356 *
6357 * @param itemID the ID of the item to read
6358 * @return the NV item as a String, or null on error.
6359 */
6360 @Override
6361 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006362 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006363 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6364 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006365
6366 final long identity = Binder.clearCallingIdentity();
6367 try {
6368 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07006369 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006370 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
6371 return value;
6372 } finally {
6373 Binder.restoreCallingIdentity(identity);
6374 }
Jake Hambye994d462014-02-03 13:10:13 -08006375 }
6376
6377 /**
6378 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6379 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6380 *
6381 * @param itemID the ID of the item to read
6382 * @param itemValue the value to write, as a String
6383 * @return true on success; false on any failure
6384 */
6385 @Override
6386 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006387 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006388 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6389 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006390
6391 final long identity = Binder.clearCallingIdentity();
6392 try {
6393 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6394 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006395 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006396 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6397 return success;
6398 } finally {
6399 Binder.restoreCallingIdentity(identity);
6400 }
Jake Hambye994d462014-02-03 13:10:13 -08006401 }
6402
6403 /**
6404 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6405 * Used for device configuration by some CDMA operators.
6406 *
6407 * @param preferredRoamingList byte array containing the new PRL
6408 * @return true on success; false on any failure
6409 */
6410 @Override
6411 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006412 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6413 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006414
6415 final long identity = Binder.clearCallingIdentity();
6416 try {
6417 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6418 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6419 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6420 return success;
6421 } finally {
6422 Binder.restoreCallingIdentity(identity);
6423 }
Jake Hambye994d462014-02-03 13:10:13 -08006424 }
6425
6426 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006427 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006428 * Used for device configuration by some CDMA operators.
6429 *
chen xu6dac5ab2018-10-26 17:39:23 -07006430 * @param slotIndex - device slot.
6431 *
Jake Hambye994d462014-02-03 13:10:13 -08006432 * @return true on success; false on any failure
6433 */
6434 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006435 public boolean resetModemConfig(int slotIndex) {
6436 Phone phone = PhoneFactory.getPhone(slotIndex);
6437 if (phone != null) {
6438 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6439 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006440
joonhunshin4ac60942023-11-15 15:23:39 +00006441 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6442 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig");
6443
chen xu6dac5ab2018-10-26 17:39:23 -07006444 final long identity = Binder.clearCallingIdentity();
6445 try {
6446 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6447 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6448 return success;
6449 } finally {
6450 Binder.restoreCallingIdentity(identity);
6451 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006452 }
chen xu6dac5ab2018-10-26 17:39:23 -07006453 return false;
6454 }
6455
6456 /**
6457 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6458 *
6459 * @param slotIndex - device slot.
6460 *
6461 * @return true on success; false on any failure
6462 */
6463 @Override
6464 public boolean rebootModem(int slotIndex) {
6465 Phone phone = PhoneFactory.getPhone(slotIndex);
6466 if (phone != null) {
6467 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6468 mApp, phone.getSubId(), "rebootModem");
6469
joonhunshin4ac60942023-11-15 15:23:39 +00006470 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6471 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem");
6472
chen xu6dac5ab2018-10-26 17:39:23 -07006473 final long identity = Binder.clearCallingIdentity();
6474 try {
6475 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6476 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6477 return success;
6478 } finally {
6479 Binder.restoreCallingIdentity(identity);
6480 }
6481 }
6482 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006483 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006484
Brad Ebinger51f743a2017-01-23 13:50:20 -08006485 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006486 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6487 * {@link #disableIms(int)}.
6488 * @param slotIndex device slot.
6489 */
6490 public void resetIms(int slotIndex) {
6491 enforceModifyPermission();
6492
joonhunshin4ac60942023-11-15 15:23:39 +00006493 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6494 PackageManager.FEATURE_TELEPHONY_IMS, "resetIms");
6495
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006496 final long identity = Binder.clearCallingIdentity();
6497 try {
6498 if (mImsResolver == null) {
6499 // may happen if the does not support IMS.
6500 return;
6501 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006502 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006503 } finally {
6504 Binder.restoreCallingIdentity(identity);
6505 }
6506 }
6507
6508 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006509 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6510 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006511 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006512 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006513 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006514
6515 final long identity = Binder.clearCallingIdentity();
6516 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006517 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006518 // may happen if the device does not support IMS.
6519 return;
6520 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006521 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006522 } finally {
6523 Binder.restoreCallingIdentity(identity);
6524 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006525 }
6526
6527 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006528 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6529 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006530 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006531 public void disableIms(int slotId) {
6532 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006533
6534 final long identity = Binder.clearCallingIdentity();
6535 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006536 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006537 // may happen if the device does not support IMS.
6538 return;
6539 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006540 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006541 } finally {
6542 Binder.restoreCallingIdentity(identity);
6543 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006544 }
6545
6546 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006547 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6548 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006549 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006550 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006551 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006552 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006553
6554 final long identity = Binder.clearCallingIdentity();
6555 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006556 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006557 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6558 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006559 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006560 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006561 } finally {
6562 Binder.restoreCallingIdentity(identity);
6563 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006564 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006565 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006566 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6567 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006568 @Override
6569 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006570 enforceModifyPermission();
6571
6572 final long identity = Binder.clearCallingIdentity();
6573 try {
6574 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006575 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006576 } finally {
6577 Binder.restoreCallingIdentity(identity);
6578 }
6579 }
6580
6581 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006582 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006583 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006584 */
6585 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6586 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006587
6588 final long identity = Binder.clearCallingIdentity();
6589 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006590 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006591 // may happen if the device does not support IMS.
6592 return null;
6593 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006594 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006595 } finally {
6596 Binder.restoreCallingIdentity(identity);
6597 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006598 }
6599
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006600 /**
6601 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006602 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006603 */
6604 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6605 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006606
6607 final long identity = Binder.clearCallingIdentity();
6608 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006609 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006610 // may happen if the device does not support IMS.
6611 return null;
6612 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006613 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006614 } finally {
6615 Binder.restoreCallingIdentity(identity);
6616 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006617 }
6618
Brad Ebinger884c07b2018-02-15 16:17:40 -08006619 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006620 * Sets the ImsService Package Name that Telephony will bind to.
6621 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006622 * @param slotIndex the slot ID that the ImsService should bind for.
6623 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006624 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006625 * @param featureTypes An integer array of feature types associated with a packageName.
6626 * @param packageName The name of the package that the current configuration will be replaced
6627 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006628 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006629 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006630 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6631 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006632 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006633 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006634 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006635
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006636 final long identity = Binder.clearCallingIdentity();
6637 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006638 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006639 // may happen if the device does not support IMS.
6640 return false;
6641 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006642 Map<Integer, String> featureConfig = new HashMap<>();
6643 for (int featureType : featureTypes) {
6644 featureConfig.put(featureType, packageName);
6645 }
6646 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6647 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006648 } finally {
6649 Binder.restoreCallingIdentity(identity);
6650 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006651 }
6652
6653 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006654 * Clears any carrier ImsService overrides for the slot index specified that were previously
6655 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6656 *
6657 * This should only be used for testing.
6658 *
6659 * @param slotIndex the slot ID that the ImsService should bind for.
6660 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6661 */
6662 @Override
6663 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006664 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6665 "clearCarrierImsServiceOverride");
6666 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006667 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006668
6669 final long identity = Binder.clearCallingIdentity();
6670 try {
6671 if (mImsResolver == null) {
6672 // may happen if the device does not support IMS.
6673 return false;
6674 }
6675 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6676 } finally {
6677 Binder.restoreCallingIdentity(identity);
6678 }
6679 }
6680
6681 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006682 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006683 *
6684 * @param slotId The slot that the ImsService is associated with.
6685 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6686 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006687 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006688 * @return the package name of the ImsService configuration.
6689 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006690 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6691 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006692 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006693 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6694 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006695
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006696 final long identity = Binder.clearCallingIdentity();
6697 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006698 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006699 // may happen if the device does not support IMS.
6700 return "";
6701 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006702 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006703 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6704 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006705 } finally {
6706 Binder.restoreCallingIdentity(identity);
6707 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006708 }
6709
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006710 /**
6711 * Get the MmTelFeature state associated with the requested subscription id.
6712 * @param subId The subscription that the MmTelFeature is associated with.
6713 * @param callback A callback with an integer containing the
6714 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6715 */
6716 @Override
6717 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6718 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006719 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6720 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6721 "IMS not available on device.");
6722 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006723 final long token = Binder.clearCallingIdentity();
6724 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006725 int slotId = getSlotIndex(subId);
6726 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6727 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6728 + subId + "'");
6729 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6730 }
6731 verifyImsMmTelConfiguredOrThrow(slotId);
6732 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6733 try {
6734 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6735 } catch (RemoteException e) {
6736 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6737 + "Ignore");
6738 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006739 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006740 } catch (ImsException e) {
6741 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006742 } finally {
6743 Binder.restoreCallingIdentity(token);
6744 }
6745 }
6746
Daniel Brightbb5840b2021-01-12 15:48:18 -08006747 /**
6748 * Sets the ims registration state on all valid {@link Phone}s.
6749 */
6750 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006751 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006752
6753 final long identity = Binder.clearCallingIdentity();
6754 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006755 // NOTE: Before S, this method only set the default phone.
6756 for (final Phone phone : PhoneFactory.getPhones()) {
6757 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6758 phone.setImsRegistrationState(registered);
6759 }
6760 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006761 } finally {
6762 Binder.restoreCallingIdentity(identity);
6763 }
Wink Saville36469e72014-06-11 15:17:00 -07006764 }
6765
6766 /**
Stuart Scott54788802015-03-30 13:18:01 -07006767 * Set the network selection mode to automatic.
6768 *
6769 */
6770 @Override
6771 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006772 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6773 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006774
joonhunshin4ac60942023-11-15 15:23:39 +00006775 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6776 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic");
6777
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006778 final long identity = Binder.clearCallingIdentity();
6779 try {
shilufc958392020-01-20 11:36:01 -08006780 if (!isActiveSubscription(subId)) {
6781 return;
6782 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006783 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006784 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6785 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006786 } finally {
6787 Binder.restoreCallingIdentity(identity);
6788 }
Stuart Scott54788802015-03-30 13:18:01 -07006789 }
6790
Jack Yud10cdd42020-09-28 20:28:01 -07006791 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006792 * Ask the radio to connect to the input network and change selection mode to manual.
6793 *
6794 * @param subId the id of the subscription.
6795 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6796 * the operator to attach to.
6797 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6798 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6799 * normal network selection next time.
6800 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006801 */
6802 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006803 public boolean setNetworkSelectionModeManual(
6804 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006805 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6806 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006807
joonhunshin4ac60942023-11-15 15:23:39 +00006808 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6809 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual");
6810
Jack Yu285100e2022-12-02 22:48:35 -08006811 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006812 if (!isActiveSubscription(subId)) {
6813 return false;
6814 }
6815
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006816 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006817 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006818 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006819 if (DBG) {
6820 log("setNetworkSelectionModeManual: subId: " + subId
6821 + " operator: " + operatorInfo);
6822 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006823 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6824 } finally {
6825 Binder.restoreCallingIdentity(identity);
6826 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006827 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006828 /**
shilu84f6e8b2019-12-19 13:58:01 -08006829 * Get the manual network selection
6830 *
6831 * @param subId the id of the subscription.
6832 *
6833 * @return the previously saved user selected PLMN
6834 */
6835 @Override
6836 public String getManualNetworkSelectionPlmn(int subId) {
6837 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006838 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6839 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006840
joonhunshin4ac60942023-11-15 15:23:39 +00006841 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6842 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn");
6843
shilu84f6e8b2019-12-19 13:58:01 -08006844 final long identity = Binder.clearCallingIdentity();
6845 try {
6846 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006847 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006848 }
6849
6850 final Phone phone = getPhone(subId);
6851 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006852 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006853 }
6854 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6855 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006856 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006857 } finally {
6858 Binder.restoreCallingIdentity(identity);
6859 }
6860 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006861
6862 /**
6863 * Scans for available networks.
6864 */
6865 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006866 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6867 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006868 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6869 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006870 LocationAccessPolicy.LocationPermissionResult locationResult =
6871 LocationAccessPolicy.checkLocationPermission(mApp,
6872 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6873 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006874 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006875 .setCallingPid(Binder.getCallingPid())
6876 .setCallingUid(Binder.getCallingUid())
6877 .setMethod("getCellNetworkScanResults")
6878 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006879 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6880 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006881 .build());
6882 switch (locationResult) {
6883 case DENIED_HARD:
6884 throw new SecurityException("Not allowed to access scan results -- location");
6885 case DENIED_SOFT:
6886 return null;
6887 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006888
Pengquan Menga1bb6272018-09-06 09:59:22 -07006889 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006890 try {
6891 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006892 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006893 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006894 } finally {
6895 Binder.restoreCallingIdentity(identity);
6896 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006897 }
6898
6899 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006900 * Get the call forwarding info, given the call forwarding reason.
6901 */
6902 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006903 public void getCallForwarding(int subId, int callForwardingReason,
6904 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006905 enforceReadPrivilegedPermission("getCallForwarding");
joonhunshin4ac60942023-11-15 15:23:39 +00006906
6907 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6908 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding");
6909
Shuo Qian4a594052020-01-23 11:59:30 -08006910 long identity = Binder.clearCallingIdentity();
6911 try {
6912 if (DBG) {
6913 log("getCallForwarding: subId " + subId
6914 + " callForwardingReason" + callForwardingReason);
6915 }
Hall Liu27d24262020-09-18 19:04:59 -07006916
6917 Phone phone = getPhone(subId);
6918 if (phone == null) {
6919 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006920 callback.onError(
6921 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006922 } catch (RemoteException e) {
6923 // ignore
6924 }
6925 return;
6926 }
6927
6928 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6929 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6930 @Override
6931 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6932 try {
6933 callback.onCallForwardingInfoAvailable(info);
6934 } catch (RemoteException e) {
6935 // ignore
6936 }
6937 }
6938
6939 @Override
6940 public void onError(int error) {
6941 try {
6942 callback.onError(error);
6943 } catch (RemoteException e) {
6944 // ignore
6945 }
6946 }
6947 });
6948 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006949 } finally {
6950 Binder.restoreCallingIdentity(identity);
6951 }
6952 }
6953
6954 /**
6955 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6956 * reason, the number to forward, and the timeout before the forwarding is attempted.
6957 */
6958 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006959 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6960 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006961 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006962
6963 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6964 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding");
6965
Shuo Qian4a594052020-01-23 11:59:30 -08006966 long identity = Binder.clearCallingIdentity();
6967 try {
6968 if (DBG) {
6969 log("setCallForwarding: subId " + subId
6970 + " callForwardingInfo" + callForwardingInfo);
6971 }
Hall Liu27d24262020-09-18 19:04:59 -07006972
6973 Phone phone = getPhone(subId);
6974 if (phone == null) {
6975 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006976 callback.accept(
6977 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006978 } catch (RemoteException e) {
6979 // ignore
6980 }
6981 return;
6982 }
6983
6984 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6985 FunctionalUtils.ignoreRemoteException(callback::accept));
6986
6987 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006988 } finally {
6989 Binder.restoreCallingIdentity(identity);
6990 }
6991 }
6992
6993 /**
Hall Liu27d24262020-09-18 19:04:59 -07006994 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006995 */
6996 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006997 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006998 enforceReadPrivilegedPermission("getCallWaitingStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00006999
7000 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7001 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus");
7002
Shuo Qian4a594052020-01-23 11:59:30 -08007003 long identity = Binder.clearCallingIdentity();
7004 try {
Hall Liu27d24262020-09-18 19:04:59 -07007005 Phone phone = getPhone(subId);
7006 if (phone == null) {
7007 try {
7008 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7009 } catch (RemoteException e) {
7010 // ignore
7011 }
7012 return;
7013 }
SongFerngWang0e767992021-03-31 22:08:45 +08007014 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7015 PersistableBundle c = configManager.getConfigForSubId(subId);
7016 boolean requireUssd = c.getBoolean(
7017 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007018
Shuo Qian4a594052020-01-23 11:59:30 -08007019 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08007020 if (requireUssd) {
7021 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7022 getSubscriptionCarrierId(subId));
7023 String newUssdCommand = "";
7024 try {
7025 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007026 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007027 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
7028 } catch (NullPointerException e) {
7029 loge("Failed to generate USSD number" + e);
7030 }
7031 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7032 mMainThreadHandler, callback, carrierXmlParser,
7033 CarrierXmlParser.SsEntry.SSAction.QUERY);
7034 final String ussdCommand = newUssdCommand;
7035 Executors.newSingleThreadExecutor().execute(() -> {
7036 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7037 });
7038 } else {
7039 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
7040 callback::accept);
7041 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
7042 }
Shuo Qian4a594052020-01-23 11:59:30 -08007043 } finally {
7044 Binder.restoreCallingIdentity(identity);
7045 }
7046 }
7047
7048 /**
Hall Liu27d24262020-09-18 19:04:59 -07007049 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007050 */
7051 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007052 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007053 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007054
7055 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7056 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus");
7057
Shuo Qian4a594052020-01-23 11:59:30 -08007058 long identity = Binder.clearCallingIdentity();
7059 try {
Hall Liu27d24262020-09-18 19:04:59 -07007060 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
7061
7062 Phone phone = getPhone(subId);
7063 if (phone == null) {
7064 try {
7065 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7066 } catch (RemoteException e) {
7067 // ignore
7068 }
7069 return;
7070 }
7071
SongFerngWang0e767992021-03-31 22:08:45 +08007072 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7073 PersistableBundle c = configManager.getConfigForSubId(subId);
7074 boolean requireUssd = c.getBoolean(
7075 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007076
SongFerngWang0e767992021-03-31 22:08:45 +08007077 if (DBG) log("getCallWaitingStatus: subId " + subId);
7078 if (requireUssd) {
7079 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7080 getSubscriptionCarrierId(subId));
7081 CarrierXmlParser.SsEntry.SSAction ssAction =
7082 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
7083 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
7084 String newUssdCommand = "";
7085 try {
7086 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007087 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007088 .makeCommand(ssAction, null);
7089 } catch (NullPointerException e) {
7090 loge("Failed to generate USSD number" + e);
7091 }
7092 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7093 mMainThreadHandler, callback, carrierXmlParser, ssAction);
7094 final String ussdCommand = newUssdCommand;
7095 Executors.newSingleThreadExecutor().execute(() -> {
7096 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7097 });
7098 } else {
7099 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
7100 FunctionalUtils.ignoreRemoteException(callback::accept));
7101
7102 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
7103 }
Shuo Qian4a594052020-01-23 11:59:30 -08007104 } finally {
7105 Binder.restoreCallingIdentity(identity);
7106 }
7107 }
7108
7109 /**
yinxub1bed742017-04-17 11:45:04 -07007110 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07007111 *
yinxub1bed742017-04-17 11:45:04 -07007112 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007113 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
7114 * location related information which will be sent if the caller already possess
7115 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07007116 * @param request contains the radio access networks with bands/channels to scan
7117 * @param messenger callback messenger for scan results or errors
7118 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07007119 * @return the id of the requested scan which can be used to stop the scan.
7120 */
7121 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007122 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
7123 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007124 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007125 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7126 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08007127 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007128 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
7129 if (!renounceFineLocationAccess) {
7130 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007131 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7132 .setCallingPackage(callingPackage)
7133 .setCallingFeatureId(callingFeatureId)
7134 .setCallingPid(Binder.getCallingPid())
7135 .setCallingUid(Binder.getCallingUid())
7136 .setMethod("requestNetworkScan")
7137 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7138 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7139 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7140 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007141 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08007142 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07007143 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
7144 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08007145 if (e != null) {
7146 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
7147 throw e;
7148 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07007149 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08007150 return TelephonyScanManager.INVALID_SCAN_ID;
7151 }
7152 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007153 }
joonhunshin4ac60942023-11-15 15:23:39 +00007154
7155 enforceTelephonyFeatureWithException(callingPackage,
7156 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan");
7157
Hall Liu912dfd32019-04-25 14:02:26 -07007158 int callingUid = Binder.getCallingUid();
7159 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07007160 final long identity = Binder.clearCallingIdentity();
7161 try {
7162 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07007163 renounceFineLocationAccess, request, messenger, binder,
7164 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07007165 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07007166 } finally {
7167 Binder.restoreCallingIdentity(identity);
7168 }
yinxu504e1392017-04-12 16:03:22 -07007169 }
7170
Hall Liub2ac8ef2019-02-28 15:56:23 -08007171 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07007172 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00007173 boolean hasCarrierPriv;
7174 final long identity = Binder.clearCallingIdentity();
7175 try {
7176 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
7177 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
7178 } finally {
7179 Binder.restoreCallingIdentity(identity);
7180 }
Hall Liu558027f2019-05-15 19:14:05 -07007181 boolean hasNetworkScanPermission =
7182 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007183 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07007184
7185 if (!hasCarrierPriv && !hasNetworkScanPermission) {
7186 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
7187 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08007188 }
7189
7190 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
7191 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08007192 if (ras.getChannels() != null && ras.getChannels().length > 0) {
7193 return new SecurityException("Specific channels must not be"
7194 + " scanned without location access.");
7195 }
7196 }
7197 }
7198
Hall Liub2ac8ef2019-02-28 15:56:23 -08007199 return null;
7200 }
7201
yinxu504e1392017-04-12 16:03:22 -07007202 /**
7203 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07007204 *
7205 * @param subId id of the subscription
7206 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07007207 */
7208 @Override
7209 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007210 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7211 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007212
Hall Liu912dfd32019-04-25 14:02:26 -07007213 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007214 final long identity = Binder.clearCallingIdentity();
7215 try {
Hall Liu912dfd32019-04-25 14:02:26 -07007216 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007217 } finally {
7218 Binder.restoreCallingIdentity(identity);
7219 }
yinxu504e1392017-04-12 16:03:22 -07007220 }
7221
7222 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08007223 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07007224 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08007225 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07007226 */
7227 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08007228 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08007229 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007230 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08007231 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007232
joonhunshin4ac60942023-11-15 15:23:39 +00007233 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7234 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask");
7235
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007236 final long identity = Binder.clearCallingIdentity();
7237 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007238 if (DBG) log("getAllowedNetworkTypesBitmask");
7239 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
7240 int networkTypesBitmask = (result != null ? result[0] : -1);
7241 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
7242 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007243 } finally {
7244 Binder.restoreCallingIdentity(identity);
7245 }
Jake Hamby7c27be32014-03-03 13:25:59 -08007246 }
7247
7248 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007249 * Get the allowed network types for certain reason.
7250 *
7251 * @param subId the id of the subscription.
7252 * @param reason the reason the allowed network type change is taking place
7253 * @return the allowed network types.
7254 */
7255 @Override
7256 public long getAllowedNetworkTypesForReason(int subId,
7257 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07007258 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007259 mApp, subId, "getAllowedNetworkTypesForReason");
joonhunshin4ac60942023-11-15 15:23:39 +00007260
7261 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7262 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesForReason");
7263
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007264 final long identity = Binder.clearCallingIdentity();
7265 try {
Jack Yu7247ac82023-03-02 23:52:10 -08007266 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007267 } finally {
7268 Binder.restoreCallingIdentity(identity);
7269 }
7270 }
7271
7272 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07007273 * Enable/Disable E-UTRA-NR Dual Connectivity
7274 * @param subId subscription id of the sim card
7275 * @param nrDualConnectivityState expected NR dual connectivity state
7276 * This can be passed following states
7277 * <ol>
7278 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
7279 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
7280 * <li>Disable NR dual connectivity and force secondary cell to be released
7281 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
7282 * </ol>
7283 * @return operation result.
7284 */
7285 @Override
7286 public int setNrDualConnectivityState(int subId,
7287 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
7288 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7289 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007290 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007291 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7292 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
7293 }
7294
Sooraj Sasindran37444802020-08-11 10:40:43 -07007295 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7296 final long identity = Binder.clearCallingIdentity();
7297 try {
7298 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
7299 nrDualConnectivityState, subId,
7300 workSource);
7301 if (DBG) log("enableNRDualConnectivity result: " + result);
7302 return result;
7303 } finally {
7304 Binder.restoreCallingIdentity(identity);
7305 }
7306 }
7307
7308 /**
7309 * Is E-UTRA-NR Dual Connectivity enabled
7310 * @return true if dual connectivity is enabled else false
7311 */
7312 @Override
7313 public boolean isNrDualConnectivityEnabled(int subId) {
7314 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007315 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07007316 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007317 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007318 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7319 return false;
7320 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07007321 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7322 final long identity = Binder.clearCallingIdentity();
7323 try {
7324 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
7325 null, subId, workSource);
7326 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
7327 return isEnabled;
7328 } finally {
7329 Binder.restoreCallingIdentity(identity);
7330 }
7331 }
7332
7333 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007334 * Set the allowed network types of the device and
7335 * provide the reason triggering the allowed network change.
7336 *
7337 * @param subId the id of the subscription.
7338 * @param reason the reason the allowed network type change is taking place
7339 * @param allowedNetworkTypes the allowed network types.
7340 * @return true on success; false on any failure.
7341 */
7342 @Override
7343 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08007344 @TelephonyManager.AllowedNetworkTypesReason int reason,
7345 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007346 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7347 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007348 // If the caller only has carrier privileges, then they should not be able to override
7349 // any network types which were set for security reasons.
7350 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
7351 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007352 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007353 throw new SecurityException(
7354 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007355 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007356 }
joonhunshin4ac60942023-11-15 15:23:39 +00007357
7358 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7359 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason");
7360
SongFerngWang3ef3e072020-12-21 16:41:52 +08007361 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007362 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08007363 return false;
7364 }
7365 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
7366 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007367 return false;
7368 }
7369
Jack Yu5b494332023-01-23 18:18:04 +00007370 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
7371 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007372
Jack Yue37dd262022-12-16 11:53:37 -08007373 Phone phone = getPhone(subId);
7374 if (phone == null) {
7375 return false;
7376 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007377
Jack Yue37dd262022-12-16 11:53:37 -08007378 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007379 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007380 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08007381 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007382
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007383 final long identity = Binder.clearCallingIdentity();
7384 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007385 Boolean success = (Boolean) sendRequest(
7386 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
7387 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
7388
7389 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
7390 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007391 } finally {
7392 Binder.restoreCallingIdentity(identity);
7393 }
7394 }
7395
7396 /**
Miaoa84611c2019-03-15 09:21:10 +08007397 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08007398 *
Miaoa84611c2019-03-15 09:21:10 +08007399 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07007400 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08007401 * @hide
7402 */
7403 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08007404 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007405 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007406
7407 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7408 PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber");
7409
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007410 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08007411 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007412 try {
Miaoa84611c2019-03-15 09:21:10 +08007413 if (phone != null) {
7414 return phone.hasMatchedTetherApnSetting();
7415 } else {
7416 return false;
7417 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007418 } finally {
7419 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007420 }
Junda Liu475951f2014-11-07 16:45:03 -08007421 }
7422
7423 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007424 * Get the user enabled state of Mobile Data.
7425 *
7426 * TODO: remove and use isUserDataEnabled.
7427 * This can't be removed now because some vendor codes
7428 * calls through ITelephony directly while they should
7429 * use TelephonyManager.
7430 *
7431 * @return true on enabled
7432 */
7433 @Override
7434 public boolean getDataEnabled(int subId) {
7435 return isUserDataEnabled(subId);
7436 }
7437
7438 /**
7439 * Get whether mobile data is enabled per user setting.
7440 *
7441 * There are other factors deciding whether mobile data is actually enabled, but they are
7442 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007443 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007444 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7445 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007446 *
7447 * @return {@code true} if data is enabled else {@code false}
7448 */
7449 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007450 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007451 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007452 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007453 try {
7454 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7455 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007456 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007457 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7458 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007459 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007460 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007461 mApp, subId, functionName);
7462
Robert Greenwalt646120a2014-05-23 11:54:03 -07007463 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007464
7465 final long identity = Binder.clearCallingIdentity();
7466 try {
Jack Yu285100e2022-12-02 22:48:35 -08007467 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007468 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7469 Phone phone = PhoneFactory.getPhone(phoneId);
7470 if (phone != null) {
7471 boolean retVal = phone.isUserDataEnabled();
7472 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7473 return retVal;
7474 } else {
7475 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7476 return false;
7477 }
7478 } finally {
7479 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007480 }
7481 }
7482
7483 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007484 * Checks if the device is capable of mobile data by considering whether whether the
7485 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7486 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007487 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007488 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007489 */
7490 @Override
7491 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007492 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007493 try {
7494 try {
7495 mApp.enforceCallingOrSelfPermission(
7496 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007497 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007498 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007499 try {
7500 mApp.enforceCallingOrSelfPermission(
7501 android.Manifest.permission.READ_PHONE_STATE,
7502 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007503 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007504 mApp.enforceCallingOrSelfPermission(
7505 permission.READ_BASIC_PHONE_STATE, functionName);
7506 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007507 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007508 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007509 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007510 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007511
joonhunshin4ac60942023-11-15 15:23:39 +00007512 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7513 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled");
7514
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007515 final long identity = Binder.clearCallingIdentity();
7516 try {
Jack Yu285100e2022-12-02 22:48:35 -08007517 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007518 Phone phone = PhoneFactory.getPhone(phoneId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007519 if (phone != null && phone.getDataSettingsManager() != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007520 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007521 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007522 return retVal;
7523 } else {
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007524 if (DBG) {
7525 loge("isDataEnabled: no phone or no DataSettingsManager subId="
7526 + subId + " retVal=false");
7527 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007528 return false;
7529 }
7530 } finally {
7531 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007532 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007533 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007534
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007535 /**
7536 * Check if data is enabled for a specific reason
7537 * @param subId Subscription index
7538 * @param reason the reason the data enable change is taking place
7539 * @return {@code true} if the overall data is enabled; {@code false} if not.
7540 */
7541 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007542 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007543 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007544 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007545 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007546 try {
7547 mApp.enforceCallingOrSelfPermission(
7548 android.Manifest.permission.ACCESS_NETWORK_STATE,
7549 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007550 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007551 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7552 functionName);
7553 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007554 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007555 try {
7556 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007557 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007558 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007559 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007560 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007561 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007562 }
7563
joonhunshin4ac60942023-11-15 15:23:39 +00007564 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7565 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007566
7567 final long identity = Binder.clearCallingIdentity();
7568 try {
Jack Yu285100e2022-12-02 22:48:35 -08007569 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007570 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007571 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007572 + " reason=" + reason);
7573 }
7574 Phone phone = PhoneFactory.getPhone(phoneId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007575 if (phone != null && phone.getDataSettingsManager() != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007576 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007577 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007578 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007579 return retVal;
7580 } else {
7581 if (DBG) {
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007582 loge("isDataEnabledForReason: no phone or no DataSettingsManager subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007583 + subId + " retVal=false");
7584 }
7585 return false;
7586 }
7587 } finally {
7588 Binder.restoreCallingIdentity(identity);
7589 }
7590 }
7591
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007592 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007593 public int getCarrierPrivilegeStatus(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00007594 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7595 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus");
7596
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007597 // No permission needed; this only lets the caller inspect their own status.
7598 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007599 }
Junda Liu29340342014-07-10 15:23:27 -07007600
7601 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007602 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007603 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
joonhunshin4ac60942023-11-15 15:23:39 +00007604
7605 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7606 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatusForUid");
7607
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007608 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7609 }
7610
7611 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7612 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007613 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007614 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007615 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7616 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007617 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7618 if (cpt == null) {
7619 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007620 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7621 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007622 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007623 }
7624
7625 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007626 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007627 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
joonhunshin4ac60942023-11-15 15:23:39 +00007628
7629 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7630 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage");
7631
chen xuf7e9fe82019-05-09 19:31:02 -07007632 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007633 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007634 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007635 Phone phone = getPhone(subId);
7636 if (phone == null) {
7637 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7638 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7639 }
7640 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7641 if (cpt == null) {
7642 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007643 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7644 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007645 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007646 }
7647
7648 @Override
7649 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007650 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007651
7652 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7653 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7654 "checkCarrierPrivilegesForPackageAnyPhone");
7655
Rambo Wange7209ce2022-02-23 13:41:02 -08007656 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7657 }
7658
7659 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007660 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007661 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007662 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007663 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007664 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7665 Phone phone = PhoneFactory.getPhone(phoneId);
7666 if (phone == null) {
7667 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007668 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007669 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7670 if (cpt == null) {
7671 continue;
7672 }
7673 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007674 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7675 break;
7676 }
7677 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007678 return result;
Junda Liu29340342014-07-10 15:23:27 -07007679 }
Derek Tan89e89d42014-07-08 17:00:10 -07007680
7681 @Override
Junda Liue64de782015-04-16 17:19:16 -07007682 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007683 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007684
7685 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7686 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7687 "getCarrierPackageNamesForIntentAndPhone");
7688
Rambo Wang8a247eb2022-02-08 21:11:18 +00007689 Phone phone = PhoneFactory.getPhone(phoneId);
7690 if (phone == null) {
7691 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007692 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007693 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7694 if (cpt == null) {
7695 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007696 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007697 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007698 }
7699
Amith Yamasani6e118872016-02-19 12:53:51 -08007700 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007701 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007702 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007703 Phone phone = PhoneFactory.getPhone(phoneId);
7704 if (phone == null) {
7705 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007706 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007707 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7708 if (cpt == null) {
7709 return Collections.emptyList();
7710 }
7711 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007712 }
7713
chen xuf7e9fe82019-05-09 19:31:02 -07007714 @Override
7715 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007716 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
joonhunshin4ac60942023-11-15 15:23:39 +00007717
7718 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7719 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7720 "getPackagesWithCarrierPrivilegesForAllPhones");
7721
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007722 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007723 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007724 try {
7725 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7726 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7727 }
7728 } finally {
7729 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007730 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007731 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007732 }
7733
Rambo Wang6812ffb2022-03-15 16:54:17 -07007734 @Override
7735 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7736 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7737
joonhunshin4ac60942023-11-15 15:23:39 +00007738 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7739 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7740 "getCarrierServicePackageNameForLogicalSlot");
7741
Rambo Wang6812ffb2022-03-15 16:54:17 -07007742 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7743 if (phone == null) {
7744 return null;
7745 }
7746 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7747 if (cpt == null) {
7748 return null;
7749 }
7750 return cpt.getCarrierServicePackageName();
7751 }
7752
Wink Savilleb564aae2014-10-23 10:18:09 -07007753 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007754 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007755 UiccPort port = phone == null ? null : phone.getUiccPort();
7756 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007757 return null;
7758 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007759 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007760 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007761 return null;
7762 }
7763 return iccId;
7764 }
7765
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007766 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007767 public void setCallComposerStatus(int subId, int status) {
7768 enforceModifyPermission();
7769
joonhunshin4ac60942023-11-15 15:23:39 +00007770 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7771 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus");
7772
Shuo Qiane4e11672020-12-15 22:15:33 -08007773 final long identity = Binder.clearCallingIdentity();
7774 try {
7775 Phone phone = getPhone(subId);
7776 if (phone != null) {
7777 Phone defaultPhone = phone.getImsPhone();
7778 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7779 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7780 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007781 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7782 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007783 }
7784 }
Shuo Qian284ae752020-12-22 19:10:14 -08007785 } catch (ImsException e) {
7786 throw new ServiceSpecificException(e.getCode());
7787 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007788 Binder.restoreCallingIdentity(identity);
7789 }
7790 }
7791
7792 @Override
7793 public int getCallComposerStatus(int subId) {
7794 enforceReadPrivilegedPermission("getCallComposerStatus");
7795
joonhunshin4ac60942023-11-15 15:23:39 +00007796 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7797 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus");
7798
Shuo Qiane4e11672020-12-15 22:15:33 -08007799 final long identity = Binder.clearCallingIdentity();
7800 try {
7801 Phone phone = getPhone(subId);
7802 if (phone != null) {
7803 Phone defaultPhone = phone.getImsPhone();
7804 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7805 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7806 return imsPhone.getCallComposerStatus();
7807 }
7808 }
7809 } finally {
7810 Binder.restoreCallingIdentity(identity);
7811 }
7812 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7813 }
7814
7815 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007816 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7817 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007818 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007819 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007820
joonhunshin4ac60942023-11-15 15:23:39 +00007821 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7822 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7823 "setLine1NumberForDisplayForSubscriber");
7824
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007825 final long identity = Binder.clearCallingIdentity();
7826 try {
7827 final String iccId = getIccId(subId);
7828 final Phone phone = getPhone(subId);
7829 if (phone == null) {
7830 return false;
7831 }
arunvoddub1365e62024-07-31 09:42:31 +00007832 if (!TextUtils.isEmpty(number) && number.length() > LINE1_NUMBER_MAX_LEN) {
7833 Rlog.e(LOG_TAG, "Number is too long");
7834 return false;
7835 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007836 final String subscriberId = phone.getSubscriberId();
7837
7838 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007839 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007840 + subscriberId + " to " + number);
7841 }
7842
7843 if (TextUtils.isEmpty(iccId)) {
7844 return false;
7845 }
7846
7847 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7848
7849 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7850 if (alphaTag == null) {
7851 editor.remove(alphaTagPrefKey);
7852 } else {
7853 editor.putString(alphaTagPrefKey, alphaTag);
7854 }
7855
7856 // Record both the line number and IMSI for this ICCID, since we need to
7857 // track all merged IMSIs based on line number
7858 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7859 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7860 if (number == null) {
7861 editor.remove(numberPrefKey);
7862 editor.remove(subscriberPrefKey);
7863 } else {
7864 editor.putString(numberPrefKey, number);
7865 editor.putString(subscriberPrefKey, subscriberId);
7866 }
7867
7868 editor.commit();
7869 return true;
7870 } finally {
7871 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007872 }
Derek Tan7226c842014-07-02 17:42:23 -07007873 }
7874
7875 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007876 public String getLine1NumberForDisplay(int subId, String callingPackage,
7877 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007878 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007879 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007880 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007881 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007882 return null;
7883 }
Derek Tan97ebb422014-09-05 16:55:38 -07007884
joonhunshin4ac60942023-11-15 15:23:39 +00007885 enforceTelephonyFeatureWithException(callingPackage,
7886 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay");
7887
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007888 final long identity = Binder.clearCallingIdentity();
7889 try {
7890 String iccId = getIccId(subId);
7891 if (iccId != null) {
7892 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7893 if (DBG_MERGE) {
7894 log("getLine1NumberForDisplay returning "
7895 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7896 }
7897 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007898 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007899 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7900 return null;
7901 } finally {
7902 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007903 }
Derek Tan7226c842014-07-02 17:42:23 -07007904 }
7905
7906 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007907 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7908 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007909 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007910 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007911 return null;
7912 }
Derek Tan97ebb422014-09-05 16:55:38 -07007913
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007914 final long identity = Binder.clearCallingIdentity();
7915 try {
7916 String iccId = getIccId(subId);
7917 if (iccId != null) {
7918 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7919 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7920 }
7921 return null;
7922 } finally {
7923 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007924 }
Derek Tan7226c842014-07-02 17:42:23 -07007925 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007926
7927 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007928 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7929 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007930 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7931 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007932 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007933 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007934 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007935 return null;
7936 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007937
Jordan Liub49b04b2019-05-06 14:45:15 -07007938 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7939 // the process, where TelephonyManager was instantiated.
7940 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007941 final long identity = Binder.clearCallingIdentity();
7942 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007943 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007944 final TelephonyManager tele = TelephonyManager.from(context);
7945 final SubscriptionManager sub = SubscriptionManager.from(context);
7946
7947 // Figure out what subscribers are currently active
7948 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007949
Jordan Liub49b04b2019-05-06 14:45:15 -07007950 // Only consider subs which match the current subId
7951 // This logic can be simplified. See b/131189269 for progress.
7952 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007953 activeSubscriberIds.add(tele.getSubscriberId(subId));
7954 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007955
7956 // First pass, find a number override for an active subscriber
7957 String mergeNumber = null;
7958 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7959 for (String key : prefs.keySet()) {
7960 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7961 final String subscriberId = (String) prefs.get(key);
7962 if (activeSubscriberIds.contains(subscriberId)) {
7963 final String iccId = key.substring(
7964 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7965 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7966 mergeNumber = (String) prefs.get(numberKey);
7967 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007968 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007969 + " for active subscriber " + subscriberId);
7970 }
7971 if (!TextUtils.isEmpty(mergeNumber)) {
7972 break;
7973 }
7974 }
7975 }
7976 }
7977
7978 // Shortcut when no active merged subscribers
7979 if (TextUtils.isEmpty(mergeNumber)) {
7980 return null;
7981 }
7982
7983 // Second pass, find all subscribers under that line override
7984 final ArraySet<String> result = new ArraySet<>();
7985 for (String key : prefs.keySet()) {
7986 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7987 final String number = (String) prefs.get(key);
7988 if (mergeNumber.equals(number)) {
7989 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7990 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7991 final String subscriberId = (String) prefs.get(subscriberKey);
7992 if (!TextUtils.isEmpty(subscriberId)) {
7993 result.add(subscriberId);
7994 }
7995 }
7996 }
7997 }
7998
7999 final String[] resultArray = result.toArray(new String[result.size()]);
8000 Arrays.sort(resultArray);
8001 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08008002 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008003 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
8004 }
8005 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07008006 } finally {
8007 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08008008 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08008009 }
8010
8011 @Override
zoey chen38003472019-12-13 17:16:31 +08008012 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
8013 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07008014
joonhunshin4ac60942023-11-15 15:23:39 +00008015 enforceTelephonyFeatureWithException(callingPackage,
8016 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup");
8017
Malcolm Chen6ca97372019-07-01 16:28:21 -07008018 final long identity = Binder.clearCallingIdentity();
8019 try {
8020 final TelephonyManager telephonyManager = mApp.getSystemService(
8021 TelephonyManager.class);
8022 String subscriberId = telephonyManager.getSubscriberId(subId);
8023 if (subscriberId == null) {
8024 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08008025 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07008026 + subId);
8027 }
8028 return null;
8029 }
8030
Jack Yu3beaf9d2023-04-14 09:17:27 -07008031 final SubscriptionInfo info = getSubscriptionManagerService()
8032 .getSubscriptionInfo(subId);
8033 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07008034 // If it doesn't belong to any group, return just subscriberId of itself.
8035 if (groupUuid == null) {
8036 return new String[]{subscriberId};
8037 }
8038
8039 // Get all subscriberIds from the group.
8040 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07008041 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
8042 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
8043 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07008044 for (SubscriptionInfo subInfo : groupInfos) {
8045 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
8046 if (subscriberId != null) {
8047 mergedSubscriberIds.add(subscriberId);
8048 }
8049 }
8050
8051 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
8052 } finally {
8053 Binder.restoreCallingIdentity(identity);
8054
8055 }
8056 }
8057
8058 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008059 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008060 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08008061 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008062
joonhunshin4ac60942023-11-15 15:23:39 +00008063 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8064 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride");
8065
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008066 final long identity = Binder.clearCallingIdentity();
8067 try {
8068 final Phone phone = getPhone(subId);
8069 return phone == null ? false : phone.setOperatorBrandOverride(brand);
8070 } finally {
8071 Binder.restoreCallingIdentity(identity);
8072 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07008073 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05008074
8075 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008076 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008077 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
8078 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008079 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
8080 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008081
8082 final long identity = Binder.clearCallingIdentity();
8083 try {
8084 final Phone phone = getPhone(subId);
8085 if (phone == null) {
8086 return false;
8087 }
8088 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
8089 cdmaNonRoamingList);
8090 } finally {
8091 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008092 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008093 }
8094
8095 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07008096 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008097 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08008098 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008099 if (phone == null) {
8100 return raf;
8101 }
8102
Shuo Qiandee53402020-05-29 14:08:15 -07008103 try {
8104 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008105 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07008106 mApp, phone.getSubId(), "getRadioAccessFamily");
8107 } catch (SecurityException e) {
8108 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
8109 throw e;
8110 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008111
joonhunshin4ac60942023-11-15 15:23:39 +00008112 enforceTelephonyFeatureWithException(callingPackage,
8113 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily");
8114
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008115 final long identity = Binder.clearCallingIdentity();
8116 try {
chen xub97461a2018-10-26 14:17:57 -07008117 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008118 } finally {
8119 Binder.restoreCallingIdentity(identity);
8120 }
chen xub97461a2018-10-26 14:17:57 -07008121 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07008122 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008123
8124 @Override
Hall Liu82694d52020-12-11 18:22:04 -08008125 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08008126 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08008127 try {
8128 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
8129 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008130 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008131 }
8132 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008133 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008134 }
joonhunshin4ac60942023-11-15 15:23:39 +00008135
8136 enforceTelephonyFeatureWithException(callingPackage,
8137 PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture");
8138
Hall Liu82694d52020-12-11 18:22:04 -08008139 RoleManager rm = mApp.getSystemService(RoleManager.class);
8140 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
8141 if (!dialerRoleHolders.contains(callingPackage)) {
8142 throw new SecurityException("App must be the dialer role holder to"
8143 + " upload a call composer pic");
8144 }
8145
8146 Executors.newSingleThreadExecutor().execute(() -> {
8147 ByteArrayOutputStream output = new ByteArrayOutputStream(
8148 (int) TelephonyManager.getMaximumCallComposerPictureSize());
8149 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
8150 boolean readUntilEnd = false;
8151 int totalBytesRead = 0;
8152 byte[] buffer = new byte[16 * 1024];
8153 while (true) {
8154 int numRead;
8155 try {
8156 numRead = input.read(buffer);
8157 } catch (IOException e) {
8158 try {
8159 fd.checkError();
8160 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
8161 null);
8162 } catch (IOException e1) {
8163 // This means that the other side closed explicitly with an error. If this
8164 // happens, log and ignore.
8165 loge("Remote end of call composer picture pipe closed: " + e1);
8166 }
8167 break;
8168 }
8169 if (numRead == -1) {
8170 readUntilEnd = true;
8171 break;
8172 }
8173 totalBytesRead += numRead;
8174 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
8175 loge("Too many bytes read for call composer picture: " + totalBytesRead);
8176 try {
8177 input.close();
8178 } catch (IOException e) {
8179 // ignore
8180 }
8181 break;
8182 }
8183 output.write(buffer, 0, numRead);
8184 }
8185 // Generally, the remote end will close the file descriptors. The only case where we
8186 // close is above, where the picture size is too big.
8187
8188 try {
8189 fd.checkError();
8190 } catch (IOException e) {
8191 loge("Remote end for call composer closed with an error: " + e);
8192 return;
8193 }
8194
Hall Liuaa4211e2021-01-20 15:43:39 -08008195 if (!readUntilEnd) {
8196 loge("Did not finish reading entire image; aborting");
8197 return;
8198 }
Hall Liu82694d52020-12-11 18:22:04 -08008199
Hall Liuaa4211e2021-01-20 15:43:39 -08008200 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
8201 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
8202 new CallComposerPictureTransfer.Factory() {},
8203 imageData,
8204 (result) -> {
8205 if (result.first != null) {
8206 ParcelUuid parcelUuid = new ParcelUuid(result.first);
8207 Bundle outputResult = new Bundle();
8208 outputResult.putParcelable(
8209 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
8210 callback.send(TelephonyManager.CallComposerException.SUCCESS,
8211 outputResult);
8212 } else {
8213 callback.send(result.second, null);
8214 }
8215 }
8216 );
Hall Liu82694d52020-12-11 18:22:04 -08008217 });
8218 }
8219
8220 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07008221 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008222 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07008223 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008224
joonhunshin4ac60942023-11-15 15:23:39 +00008225 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8226 PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling");
8227
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008228 final long identity = Binder.clearCallingIdentity();
8229 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008230 ImsManager.getInstance(defaultPhone.getContext(),
8231 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008232 } finally {
8233 Binder.restoreCallingIdentity(identity);
8234 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008235 }
8236
8237 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008238 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008239 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008240 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
8241 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00008242 return false;
8243 }
Svet Ganovb320e182015-04-16 12:30:10 -07008244
joonhunshin4ac60942023-11-15 15:23:39 +00008245 enforceTelephonyFeatureWithException(callingPackage,
8246 PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled");
8247
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008248 final long identity = Binder.clearCallingIdentity();
8249 try {
8250 // Check the user preference and the system-level IMS setting. Even if the user has
8251 // enabled video calling, if IMS is disabled we aren't able to support video calling.
8252 // In the long run, we may instead need to check if there exists a connection service
8253 // which can support video calling.
8254 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008255 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008256 return imsManager.isVtEnabledByPlatform()
8257 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
8258 && imsManager.isVtEnabledByUser();
8259 } finally {
8260 Binder.restoreCallingIdentity(identity);
8261 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008262 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06008263
Andrew Leea1239f22015-03-02 17:44:07 -08008264 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008265 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
8266 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008267 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008268 mApp, subId, callingPackage, callingFeatureId,
8269 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008270 return false;
8271 }
8272
joonhunshin4ac60942023-11-15 15:23:39 +00008273 enforceTelephonyFeatureWithException(callingPackage,
8274 PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength");
8275
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008276 final long identity = Binder.clearCallingIdentity();
8277 try {
8278 CarrierConfigManager configManager =
8279 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008280 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008281 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
8282 } finally {
8283 Binder.restoreCallingIdentity(identity);
8284 }
Andrew Leea1239f22015-03-02 17:44:07 -08008285 }
8286
8287 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008288 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008289 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008290 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008291 return false;
8292 }
8293
joonhunshin4ac60942023-11-15 15:23:39 +00008294 enforceTelephonyFeatureWithException(callingPackage,
8295 PackageManager.FEATURE_TELEPHONY, "isWorldPhone");
8296
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008297 final long identity = Binder.clearCallingIdentity();
8298 try {
8299 CarrierConfigManager configManager =
8300 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008301 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008302 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
8303 } finally {
8304 Binder.restoreCallingIdentity(identity);
8305 }
Andrew Leea1239f22015-03-02 17:44:07 -08008306 }
8307
Andrew Lee9431b832015-03-09 18:46:45 -07008308 @Override
8309 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008310 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08008311 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07008312 }
8313
8314 @Override
8315 public boolean isHearingAidCompatibilitySupported() {
joonhunshin4ac60942023-11-15 15:23:39 +00008316 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8317 PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported");
8318
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008319 final long identity = Binder.clearCallingIdentity();
8320 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008321 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008322 } finally {
8323 Binder.restoreCallingIdentity(identity);
8324 }
Andrew Lee9431b832015-03-09 18:46:45 -07008325 }
8326
Hall Liuf6668912018-10-31 17:05:23 -07008327 /**
8328 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
8329 * support for the feature and device firmware support.
8330 *
8331 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
8332 */
8333 @Override
8334 public boolean isRttSupported(int subscriptionId) {
joonhunshin4ac60942023-11-15 15:23:39 +00008335 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8336 PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported");
8337
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008338 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008339 final Phone phone = getPhone(subscriptionId);
8340 if (phone == null) {
8341 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
8342 return false;
8343 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008344 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008345 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008346 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
joonhunshin4ac60942023-11-15 15:23:39 +00008347 boolean isDeviceSupported = (phone.getContext().getResources() != null)
8348 ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt)
8349 : false;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008350 return isCarrierSupported && isDeviceSupported;
8351 } finally {
8352 Binder.restoreCallingIdentity(identity);
8353 }
Hall Liu98187582018-01-22 19:15:32 -08008354 }
8355
Hall Liuf6668912018-10-31 17:05:23 -07008356 /**
Hall Liuf2daa022019-07-23 18:39:00 -07008357 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
8358 * RTT setting, will return true if the device and carrier both support RTT.
8359 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07008360 */
8361 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008362 final long identity = Binder.clearCallingIdentity();
8363 try {
joonhunshin4ac60942023-11-15 15:23:39 +00008364 if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) {
8365 if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
8366 return false;
8367 }
8368 }
8369
Hall Liu5bab75c2019-12-11 23:58:20 +00008370 boolean isRttSupported = isRttSupported(subscriptionId);
8371 boolean isUserRttSettingOn = Settings.Secure.getInt(
8372 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
8373 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
8374 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
8375 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008376 } finally {
8377 Binder.restoreCallingIdentity(identity);
8378 }
Hall Liu3ad5f012018-04-06 16:23:39 -07008379 }
8380
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008381 @Deprecated
8382 @Override
8383 public String getDeviceId(String callingPackage) {
8384 return getDeviceIdWithFeature(callingPackage, null);
8385 }
8386
Sanket Padawe7310cc72015-01-14 09:53:20 -08008387 /**
8388 * Returns the unique device ID of phone, for example, the IMEI for
8389 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
8390 *
8391 * <p>Requires Permission:
8392 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
8393 */
8394 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008395 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07008396 try {
8397 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
8398 } catch (SecurityException se) {
8399 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
8400 throw new SecurityException("Package " + callingPackage + " does not belong to "
8401 + Binder.getCallingUid());
8402 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008403 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008404 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008405 return null;
8406 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008407 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008408 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008409 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008410 return null;
8411 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008412
8413 final long identity = Binder.clearCallingIdentity();
8414 try {
8415 return phone.getDeviceId();
8416 } finally {
8417 Binder.restoreCallingIdentity(identity);
8418 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008419 }
8420
Ping Sunc67b7c22016-03-02 19:16:45 +08008421 /**
8422 * {@hide}
8423 * Returns the IMS Registration Status on a particular subid
8424 *
8425 * @param subId
8426 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008427 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008428 Phone phone = getPhone(subId);
8429 if (phone != null) {
8430 return phone.isImsRegistered();
8431 } else {
8432 return false;
8433 }
8434 }
8435
Santos Cordon7a1885b2015-02-03 11:15:19 -08008436 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008437 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008438 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008439 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008440 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008441 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8442 }
8443 final long identity = Binder.clearCallingIdentity();
8444 try {
8445 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8446 } finally {
8447 Binder.restoreCallingIdentity(identity);
8448 }
8449 }
8450
8451 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008452 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008453 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008454 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008455 mApp,
8456 subscriptionId,
8457 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
8458 + subscriptionId);
joonhunshin4ac60942023-11-15 15:23:39 +00008459
8460 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8461 PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId");
8462
Tyler Gunnf70ed162019-04-03 15:28:53 -07008463 final long identity = Binder.clearCallingIdentity();
8464 try {
8465 Phone phone = getPhone(subscriptionId);
8466 if (phone == null) {
8467 return null;
8468 }
8469 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8470 } finally {
8471 Binder.restoreCallingIdentity(identity);
8472 }
8473 }
8474
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008475 /**
8476 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008477 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008478 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008479 final long identity = Binder.clearCallingIdentity();
8480 try {
8481 Phone phone = getPhone(subId);
8482 if (phone != null) {
8483 return phone.isWifiCallingEnabled();
8484 } else {
8485 return false;
8486 }
8487 } finally {
8488 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008489 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008490 }
8491
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008492 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008493 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008494 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008495 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008496 final long identity = Binder.clearCallingIdentity();
8497 try {
8498 Phone phone = getPhone(subId);
8499 if (phone != null) {
8500 return phone.isVideoEnabled();
8501 } else {
8502 return false;
8503 }
8504 } finally {
8505 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008506 }
8507 }
8508
8509 /**
8510 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8511 * defined in {@link ImsRegistrationImplBase}.
8512 */
8513 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008514 final long identity = Binder.clearCallingIdentity();
8515 try {
8516 Phone phone = getPhone(subId);
8517 if (phone != null) {
8518 return phone.getImsRegistrationTech();
8519 } else {
8520 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8521 }
8522 } finally {
8523 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008524 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008525 }
8526
Stuart Scott8eef64f2015-04-08 15:13:54 -07008527 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008528 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008529 enforceSettingsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008530
8531 enforceTelephonyFeatureWithException(callingPackage,
8532 PackageManager.FEATURE_TELEPHONY, "factoryReset");
8533
Stuart Scott981d8582015-04-21 14:09:50 -07008534 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8535 return;
8536 }
Kai Shif70f46f2021-03-03 13:59:46 -08008537 Phone defaultPhone = getDefaultPhone();
8538 if (defaultPhone != null) {
8539 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8540 mApp, getDefaultPhone().getSubId(), "factoryReset");
8541 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008542 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008543
Svet Ganovcc087f82015-05-12 20:35:54 -07008544 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008545 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8546 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008547 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008548 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008549 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008550 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008551 cleanUpAllowedNetworkTypes(phone, subId);
Rambo Wang71f6aa62024-02-23 20:16:22 +00008552 setDataRoamingEnabled(subId, phone == null ? false
8553 : phone.getDataSettingsManager().isDefaultDataRoamingEnabled());
Jordan Liu857e73a2021-03-05 16:24:04 -08008554 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008555 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008556 // There has been issues when Sms raw table somehow stores orphan
8557 // fragments. They lead to garbled message when new fragments come
8558 // in and combined with those stale ones. In case this happens again,
8559 // user can reset all network settings which will clean up this table.
8560 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008561 // Clean up IMS settings as well here.
8562 int slotId = getSlotIndex(subId);
8563 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
8564 ImsManager.getInstance(mApp, slotId).factoryReset();
8565 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008566
Kai Shif70f46f2021-03-03 13:59:46 -08008567 if (defaultPhone == null) {
8568 return;
8569 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008570 // Erase modem config if erase modem on network setting is enabled.
8571 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8572 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8573 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008574 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008575 }
Kai Shif70f46f2021-03-03 13:59:46 -08008576
8577 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008578 } finally {
8579 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008580 }
8581 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008582
SongFerngWangfd89b102021-05-27 22:44:54 +08008583 @VisibleForTesting
8584 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8585 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8586 return;
8587 }
8588 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8589 RILConstants.PREFERRED_NETWORK_MODE);
8590 SubscriptionManager.setSubscriptionProperty(subId,
8591 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8592 "user=" + defaultNetworkType);
8593 phone.loadAllowedNetworksFromSubscriptionDatabase();
8594 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8595 defaultNetworkType, null);
8596 }
8597
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008598 private void cleanUpSmsRawTable(Context context) {
8599 ContentResolver resolver = context.getContentResolver();
8600 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8601 resolver.delete(uri, null, null);
8602 }
8603
Narayan Kamath1c496c22015-04-16 14:40:19 +01008604 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008605 public String getSimLocaleForSubscriber(int subId) {
8606 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
joonhunshin4ac60942023-11-15 15:23:39 +00008607
8608 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8609 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber");
8610
chen xu5d3637b2019-01-21 23:31:38 -08008611 final Phone phone = getPhone(subId);
8612 if (phone == null) {
8613 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008614 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008615 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008616 final long identity = Binder.clearCallingIdentity();
8617 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008618 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
8619 phone.getContext().getOpPackageName(),
8620 phone.getContext().getAttributionTag());
8621 if (info == null) {
8622 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8623 return null;
chen xu6291c472019-02-04 12:55:53 -08008624 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008625 // Try and fetch the locale from the carrier properties or from the SIM language
8626 // preferences (EF-PL and EF-LI)...
8627 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008628 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008629 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8630 if (localeFromDefaultSim != null) {
8631 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8632 if (DBG) log("Using locale from subId: " + subId + " locale: "
8633 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008634 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008635 } else {
8636 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008637 }
8638 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008639
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008640 // The SIM language preferences only store a language (e.g. fr = French), not an
8641 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8642 // the SIM and carrier preferences does not include a country we add the country
8643 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008644 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008645 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008646 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008647 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008648 }
8649
8650 if (DBG) log("No locale found - returning null");
8651 return null;
8652 } finally {
8653 Binder.restoreCallingIdentity(identity);
8654 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008655 }
8656
tom hsu0b59d292022-09-29 23:49:21 +08008657 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008658 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008659 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008660 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008661 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008662 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8663 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008664 Locale.forLanguageTag(localeTag).getCountry())) {
8665 return localeTag;
8666 }
8667 }
8668 return inputLocale.toLanguageTag();
8669 }
8670
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008671 /**
8672 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8673 */
8674 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008675 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Ling Ma9fa67412023-11-13 14:13:19 -08008676 mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/);
Narayan Kamath1c496c22015-04-16 14:40:19 +01008677 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008678
Gary Jian3aa9a762022-01-24 16:41:19 +08008679 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8680 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008681
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008682 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008683 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8684 * representing the state of the modem.
8685 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008686 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8687 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008688 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008689 */
8690 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008691 public void requestModemActivityInfo(ResultReceiver result) {
8692 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008693
8694 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8695 PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo");
8696
vagdeviaf9a5b92018-08-15 16:01:53 -07008697 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008698
8699 final long identity = Binder.clearCallingIdentity();
8700 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008701 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008702 } finally {
8703 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008704 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008705 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008706
Gary Jian76280a42022-12-07 16:18:33 +08008707 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008708 // less than total activity duration.
8709 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8710 if (info == null) {
8711 return false;
8712 }
8713 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008714 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008715 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8716
Hall Liu49656c02020-10-09 19:00:11 -07008717 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8718
Siddharth Rayb8114062018-06-17 15:02:38 -07008719 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008720 && (info.getSleepTimeMillis() <= activityDurationMs)
8721 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008722 }
8723
Gary Jian3aa9a762022-01-24 16:41:19 +08008724 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8725 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8726 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8727 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8728
8729 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8730 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8731 }
8732
8733 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8734 mLastModemActivityInfo.setReceiveTimeMillis(
8735 rat,
8736 freq,
8737 info.getReceiveTimeMillis(rat, freq)
8738 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8739 }
8740
8741 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8742 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8743 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8744 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8745
8746 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8747 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8748 }
8749 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8750 mLastModemActivityInfo.setReceiveTimeMillis(
8751 rat,
8752 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8753 }
8754
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008755 /**
8756 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8757 * @param info recent ModemActivityInfo
8758 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008759 private void mergeModemActivityInfo(ModemActivityInfo info) {
8760 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008761 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008762 boolean matched;
8763 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8764 matched = false;
8765 int rat = info.getSpecificInfoRat(i);
8766 int freq = info.getSpecificInfoFrequencyRange(i);
8767 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8768 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8769 //if it already exists
8770 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8771 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8772 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8773 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8774 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8775 updateLastModemActivityInfo(info, rat, freq);
8776 matched = true;
8777 }
8778 } else {
8779 updateLastModemActivityInfo(info, rat);
8780 matched = true;
8781 }
8782 }
8783 }
8784
8785 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008786 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008787 new ActivityStatsTechSpecificInfo(
8788 rat,
8789 freq,
8790 info.getTransmitTimeMillis(rat, freq),
8791 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008792 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008793 }
8794 }
8795 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8796 mLastModemActivitySpecificInfo =
8797 new ActivityStatsTechSpecificInfo[merged.size()];
8798 merged.toArray(mLastModemActivitySpecificInfo);
8799
8800 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8801 mLastModemActivityInfo.setSleepTimeMillis(
8802 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008803 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008804 mLastModemActivityInfo.setIdleTimeMillis(
8805 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008806 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008807
8808 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008809 new ModemActivityInfo(
8810 mLastModemActivityInfo.getTimestampMillis(),
8811 mLastModemActivityInfo.getSleepTimeMillis(),
8812 mLastModemActivityInfo.getIdleTimeMillis(),
8813 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008814 }
8815
8816 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8817 ActivityStatsTechSpecificInfo[] info) {
8818 int infoSize = info.length;
8819 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8820 for (int i = 0; i < infoSize; i++) {
8821 ret[i] = new ActivityStatsTechSpecificInfo(
8822 info[i].getRat(), info[i].getFrequencyRange(),
8823 info[i].getTransmitTimeMillis(),
8824 (int) info[i].getReceiveTimeMillis());
8825 }
8826 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008827 }
8828
Jack Yu85bd38a2015-11-09 11:34:32 -08008829 /**
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008830 * Returns the service state information on specified SIM slot.
Jack Yu85bd38a2015-11-09 11:34:32 -08008831 */
8832 @Override
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008833 public ServiceState getServiceStateForSlot(int slotIndex, boolean renounceFineLocationAccess,
8834 boolean renounceCoarseLocationAccess, String callingPackage, String callingFeatureId) {
8835 Phone phone = PhoneFactory.getPhone(slotIndex);
8836 if (phone == null) {
8837 loge("getServiceStateForSlot retuning null for invalid slotIndex=" + slotIndex);
8838 return null;
8839 }
8840
8841 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08008842 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008843 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008844 return null;
8845 }
8846
joonhunshin4ac60942023-11-15 15:23:39 +00008847 enforceTelephonyFeatureWithException(callingPackage,
8848 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber");
8849
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008850 boolean hasFinePermission = false;
8851 boolean hasCoarsePermission = false;
8852 if (!renounceFineLocationAccess) {
8853 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8854 LocationAccessPolicy.checkLocationPermission(mApp,
8855 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8856 .setCallingPackage(callingPackage)
8857 .setCallingFeatureId(callingFeatureId)
8858 .setCallingPid(Binder.getCallingPid())
8859 .setCallingUid(Binder.getCallingUid())
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008860 .setMethod("getServiceStateForSlot")
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008861 .setLogAsInfo(true)
8862 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8863 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8864 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8865 .build());
8866 hasFinePermission =
8867 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8868 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008869
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008870 if (!renounceCoarseLocationAccess) {
8871 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8872 LocationAccessPolicy.checkLocationPermission(mApp,
8873 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8874 .setCallingPackage(callingPackage)
8875 .setCallingFeatureId(callingFeatureId)
8876 .setCallingPid(Binder.getCallingPid())
8877 .setCallingUid(Binder.getCallingUid())
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008878 .setMethod("getServiceStateForSlot")
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008879 .setLogAsInfo(true)
8880 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8881 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8882 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8883 .build());
8884 hasCoarsePermission =
8885 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8886 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008887
Jordan Liu0f2bc442020-11-18 16:47:37 -08008888 final long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008889 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008890 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8891 .getSubscriptionInfoInternal(subId);
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008892 if (subInfo != null && !subInfo.isActive()) {
8893 log("getServiceStateForSlot returning null for inactive subId=" + subId);
Jack Yu3beaf9d2023-04-14 09:17:27 -07008894 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008895 }
8896
Hall Liuf19c44f2018-11-27 14:38:17 -08008897 ServiceState ss = phone.getServiceState();
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008898 boolean isCallingPackageDataService = phone.getDataServicePackages()
8899 .contains(callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08008900
8901 // Scrub out the location info in ServiceState depending on what level of access
8902 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008903 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008904 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8905 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008906 } finally {
8907 Binder.restoreCallingIdentity(identity);
8908 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008909 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008910
8911 /**
8912 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8913 *
8914 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8915 * voicemail ringtone.
8916 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8917 * PhoneAccount.
8918 */
8919 @Override
8920 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008921 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8922 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri");
8923
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008924 final long identity = Binder.clearCallingIdentity();
8925 try {
8926 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8927 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008928 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008929 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008930
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008931 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8932 } finally {
8933 Binder.restoreCallingIdentity(identity);
8934 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008935 }
8936
8937 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008938 * Sets the per-account voicemail ringtone.
8939 *
8940 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8941 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8942 *
8943 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8944 * voicemail ringtone.
8945 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8946 * PhoneAccount.
8947 */
8948 @Override
8949 public void setVoicemailRingtoneUri(String callingPackage,
8950 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008951 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008952 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008953 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8954 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008955 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8956 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8957 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008958 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008959
joonhunshin4ac60942023-11-15 15:23:39 +00008960 enforceTelephonyFeatureWithException(callingPackage,
8961 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri");
8962
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008963 final long identity = Binder.clearCallingIdentity();
8964 try {
8965 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8966 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008967 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008968 }
8969 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8970 } finally {
8971 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008972 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008973 }
8974
8975 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008976 * Returns whether vibration is set for voicemail notification in Phone settings.
8977 *
8978 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8979 * voicemail vibration setting.
8980 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8981 */
8982 @Override
8983 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008984 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8985 PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled");
8986
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008987 final long identity = Binder.clearCallingIdentity();
8988 try {
8989 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8990 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008991 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008992 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008993
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008994 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8995 } finally {
8996 Binder.restoreCallingIdentity(identity);
8997 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008998 }
8999
Youhan Wange64578a2016-05-02 15:32:42 -07009000 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009001 * Sets the per-account voicemail vibration.
9002 *
9003 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
9004 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9005 *
9006 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
9007 * voicemail vibration setting.
9008 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
9009 * specific PhoneAccount.
9010 */
9011 @Override
9012 public void setVoicemailVibrationEnabled(String callingPackage,
9013 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009014 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009015 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07009016 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
9017 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009018 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9019 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
9020 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009021 }
9022
joonhunshin4ac60942023-11-15 15:23:39 +00009023 enforceTelephonyFeatureWithException(callingPackage,
9024 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled");
9025
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009026 final long identity = Binder.clearCallingIdentity();
9027 try {
9028 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
9029 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009030 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009031 }
9032 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
9033 } finally {
9034 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009035 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009036 }
9037
9038 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009039 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
9040 *
9041 * @throws SecurityException if the caller does not have the required permission
9042 */
arunvoddud7401012022-12-15 16:08:12 +00009043 @VisibleForTesting
9044 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07009045 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07009046 message);
Youhan Wange64578a2016-05-02 15:32:42 -07009047 }
9048
9049 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009050 * Make sure either called from same process as self (phone) or IPC caller has send SMS
9051 * permission.
9052 *
9053 * @throws SecurityException if the caller does not have the required permission
9054 */
9055 private void enforceSendSmsPermission() {
9056 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
9057 }
9058
9059 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00009060 * Make sure either called from same process as self (phone) or IPC caller has interact across
9061 * users permission.
9062 *
9063 * @throws SecurityException if the caller does not have the required permission
9064 */
9065 private void enforceInteractAcrossUsersPermission(String message) {
9066 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
9067 }
9068
9069 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009070 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009071 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009072 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009073 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009074 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009075 final long identity = Binder.clearCallingIdentity();
9076 try {
9077 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009078 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009079 if (componentName == null) {
9080 throw new SecurityException(
9081 "Caller not current active visual voicemail package[null]");
9082 }
9083 String vvmPackage = componentName.getPackageName();
9084 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00009085 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009086 }
9087 } finally {
9088 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009089 }
9090 }
9091
9092 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009093 * Return the application ID for the app type.
9094 *
9095 * @param subId the subscription ID that this request applies to.
9096 * @param appType the uicc app type.
9097 * @return Application ID for specificied app type, or null if no uicc.
9098 */
9099 @Override
9100 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009101 enforceReadPrivilegedPermission("getAidForAppType");
joonhunshin4ac60942023-11-15 15:23:39 +00009102
9103 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9104 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType");
9105
Youhan Wange64578a2016-05-02 15:32:42 -07009106 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009107
9108 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07009109 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009110 if (phone == null) {
9111 return null;
9112 }
9113 String aid = null;
9114 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009115 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009116 .getApplicationByType(appType).getAid();
9117 } catch (Exception e) {
9118 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
9119 }
9120 return aid;
9121 } finally {
9122 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07009123 }
Youhan Wange64578a2016-05-02 15:32:42 -07009124 }
9125
Youhan Wang4001d252016-05-11 10:29:41 -07009126 /**
9127 * Return the Electronic Serial Number.
9128 *
9129 * @param subId the subscription ID that this request applies to.
9130 * @return ESN or null if error.
9131 */
9132 @Override
9133 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009134 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07009135 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009136
9137 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07009138 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009139 if (phone == null) {
9140 return null;
9141 }
9142 String esn = null;
9143 try {
9144 esn = phone.getEsn();
9145 } catch (Exception e) {
9146 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
9147 }
9148 return esn;
9149 } finally {
9150 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07009151 }
Youhan Wang4001d252016-05-11 10:29:41 -07009152 }
9153
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009154 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009155 * Return the Preferred Roaming List Version.
9156 *
9157 * @param subId the subscription ID that this request applies to.
9158 * @return PRLVersion or null if error.
9159 */
9160 @Override
9161 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009162 enforceReadPrivilegedPermission("getCdmaPrlVersion");
joonhunshin4ac60942023-11-15 15:23:39 +00009163
9164 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9165 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion");
9166
Youhan Wang66ad5d72016-07-18 17:56:58 -07009167 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009168
9169 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009170 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009171 if (phone == null) {
9172 return null;
9173 }
9174 String cdmaPrlVersion = null;
9175 try {
9176 cdmaPrlVersion = phone.getCdmaPrlVersion();
9177 } catch (Exception e) {
9178 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9179 }
9180 return cdmaPrlVersion;
9181 } finally {
9182 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009183 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009184 }
9185
9186 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009187 * Get snapshot of Telephony histograms
9188 * @return List of Telephony histograms
9189 * @hide
9190 */
9191 @Override
9192 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009193 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9194 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009195
9196 final long identity = Binder.clearCallingIdentity();
9197 try {
9198 return RIL.getTelephonyRILTimingHistograms();
9199 } finally {
9200 Binder.restoreCallingIdentity(identity);
9201 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009202 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009203
9204 /**
9205 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009206 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9207 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009208 * Require system privileges. In the future we may add this to carrier APIs.
9209 *
Michele Berionne482f8202018-11-27 18:57:59 -08009210 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009211 */
9212 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009213 @TelephonyManager.SetCarrierRestrictionResult
9214 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009215 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009216
9217 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9218 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers");
9219
vagdeviaf9a5b92018-08-15 16:01:53 -07009220 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009221
Michele Berionne482f8202018-11-27 18:57:59 -08009222 if (carrierRestrictionRules == null) {
9223 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009224 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009225
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009226 final long identity = Binder.clearCallingIdentity();
9227 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009228 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009229 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009230 } finally {
9231 Binder.restoreCallingIdentity(identity);
9232 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009233 }
9234
9235 /**
9236 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009237 * Get the allowed carrier list and the excluded carrier list, including the priority between
9238 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009239 * Require system privileges. In the future we may add this to carrier APIs.
9240 *
Michele Berionne482f8202018-11-27 18:57:59 -08009241 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009242 */
9243 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009244 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009245 enforceReadPrivilegedPermission("getAllowedCarriers");
joonhunshin4ac60942023-11-15 15:23:39 +00009246
9247 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9248 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers");
9249
vagdeviaf9a5b92018-08-15 16:01:53 -07009250 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009251
9252 final long identity = Binder.clearCallingIdentity();
9253 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009254 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9255 if (response instanceof CarrierRestrictionRules) {
9256 return (CarrierRestrictionRules) response;
9257 }
9258 // Response is an Exception of some kind,
9259 // which is signalled to the user as a NULL retval
9260 return null;
9261 } catch (Exception e) {
9262 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9263 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009264 } finally {
9265 Binder.restoreCallingIdentity(identity);
9266 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009267 }
9268
fionaxu59545b42016-05-25 15:53:37 -07009269 /**
arunvoddud7401012022-12-15 16:08:12 +00009270 * Fetches the carrier restriction status of the device and sends the status to the caller
9271 * through the callback.
9272 *
9273 * @param callback The callback that will be used to send the result.
9274 * @throws SecurityException if the caller does not have the required permission/privileges or
9275 * the caller is not allowlisted.
9276 */
9277 @Override
9278 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
9279 enforceReadPermission("getCarrierRestrictionStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00009280
9281 enforceTelephonyFeatureWithException(packageName,
9282 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierRestrictionStatus");
9283
Steve Statia28b7cb32024-03-11 23:58:50 +00009284 Set<Integer> carrierIds = validateCallerAndGetCarrierIds(packageName);
9285 if (carrierIds.contains(CarrierAllowListInfo.INVALID_CARRIER_ID)) {
arunvoddud7401012022-12-15 16:08:12 +00009286 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9287 throw new SecurityException("Not an authorized caller");
9288 }
9289 final long identity = Binder.clearCallingIdentity();
9290 try {
9291 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
Steve Statia28b7cb32024-03-11 23:58:50 +00009292 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierIds);
arunvoddud7401012022-12-15 16:08:12 +00009293 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9294 } finally {
9295 Binder.restoreCallingIdentity(identity);
9296 }
9297 }
9298
arunvoddu567f2b42023-04-25 17:22:00 +00009299 @Override
9300 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
9301 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
9302 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9303 return allowListInfo.getShaIdList(pkgName, carrierId);
9304 }
9305
arunvoddud7401012022-12-15 16:08:12 +00009306 @VisibleForTesting
Steve Statia28b7cb32024-03-11 23:58:50 +00009307 public Set<Integer> validateCallerAndGetCarrierIds(String packageName) {
arunvoddud7401012022-12-15 16:08:12 +00009308 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
Steve Statia28b7cb32024-03-11 23:58:50 +00009309 return allowListInfo.validateCallerAndGetCarrierIds(packageName);
arunvoddud7401012022-12-15 16:08:12 +00009310 }
9311
9312 /**
fionaxu59545b42016-05-25 15:53:37 -07009313 * Action set from carrier signalling broadcast receivers to enable/disable radio
9314 * @param subId the subscription ID that this action applies to.
9315 * @param enabled control enable or disable radio.
9316 * {@hide}
9317 */
9318 @Override
9319 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9320 enforceModifyPermission();
9321 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009322
9323 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009324 if (phone == null) {
9325 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9326 return;
9327 }
9328 try {
9329 phone.carrierActionSetRadioEnabled(enabled);
9330 } catch (Exception e) {
9331 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009332 } finally {
9333 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009334 }
9335 }
9336
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009337 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009338 * Enable or disable Voice over NR (VoNR)
9339 * @param subId the subscription ID that this action applies to.
9340 * @param enabled enable or disable VoNR.
9341 * @return operation result.
9342 */
9343 @Override
9344 public int setVoNrEnabled(int subId, boolean enabled) {
9345 enforceModifyPermission();
9346 final Phone phone = getPhone(subId);
9347
9348 final long identity = Binder.clearCallingIdentity();
9349 if (phone == null) {
9350 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9351 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9352 }
9353
9354 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9355 try {
9356 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9357 workSource);
9358 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009359
9360 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9361 if (DBG) {
9362 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9363 }
9364 SubscriptionManager.setSubscriptionProperty(
9365 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9366 (enabled ? "1" : "0"));
9367 }
9368
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009369 return result;
9370 } finally {
9371 Binder.restoreCallingIdentity(identity);
9372 }
9373 }
9374
9375 /**
9376 * Is voice over NR enabled
9377 * @return true if VoNR is enabled else false
9378 */
9379 @Override
9380 public boolean isVoNrEnabled(int subId) {
9381 enforceReadPrivilegedPermission("isVoNrEnabled");
9382 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9383 final long identity = Binder.clearCallingIdentity();
9384 try {
9385 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9386 null, subId, workSource);
9387 if (DBG) log("isVoNrEnabled: " + isEnabled);
9388 return isEnabled;
9389 } finally {
9390 Binder.restoreCallingIdentity(identity);
9391 }
9392 }
9393
9394 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009395 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9396 * network status based on which carrier apps could apply actions accordingly,
9397 * enable/disable default url handler for example.
9398 *
9399 * @param subId the subscription ID that this action applies to.
9400 * @param report control start/stop reporting the default network status.
9401 * {@hide}
9402 */
9403 @Override
9404 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9405 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009406
9407 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9408 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
9409 "carrierActionReportDefaultNetworkStatus");
9410
fionaxu8da9cb12017-05-23 15:02:46 -07009411 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009412
9413 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009414 if (phone == null) {
9415 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9416 return;
9417 }
9418 try {
9419 phone.carrierActionReportDefaultNetworkStatus(report);
9420 } catch (Exception e) {
9421 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009422 } finally {
9423 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009424 }
9425 }
9426
9427 /**
fionaxud9622282017-07-17 17:51:30 -07009428 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9429 * @param subId the subscription ID that this action applies to.
9430 * {@hide}
9431 */
9432 @Override
9433 public void carrierActionResetAll(int subId) {
9434 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009435
9436 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9437 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll");
9438
fionaxud9622282017-07-17 17:51:30 -07009439 final Phone phone = getPhone(subId);
9440 if (phone == null) {
9441 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9442 return;
9443 }
9444 try {
9445 phone.carrierActionResetAll();
9446 } catch (Exception e) {
9447 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9448 }
9449 }
9450
9451 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009452 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9453 * bug report is being generated.
9454 */
9455 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009456 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009457 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9458 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009459 writer.println("Permission Denial: can't dump Phone from pid="
9460 + Binder.getCallingPid()
9461 + ", uid=" + Binder.getCallingUid()
9462 + "without permission "
9463 + android.Manifest.permission.DUMP);
9464 return;
9465 }
Allen Xu4574a1a2024-05-13 23:10:02 +00009466 try {
9467 DumpsysHandler.dump(mApp, fd, writer, args);
9468 } catch (Exception e) {
9469 writer.println("Failed to dump phone information: " + e);
9470 }
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009471 }
Jack Yueb89b242016-06-22 13:27:47 -07009472
Brad Ebingerdac2f002018-04-03 15:17:52 -07009473 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009474 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9475 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9476 @NonNull String[] args) {
9477 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9478 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009479 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009480 }
9481
Jack Yueb89b242016-06-22 13:27:47 -07009482 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009483 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009484 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009485 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009486 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009487 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009488 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009489 */
9490 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009491 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009492 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009493 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9494 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9495 try {
9496 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009497 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009498 } catch (SecurityException se) {
9499 enforceModifyPermission();
9500 }
9501 } else {
9502 enforceModifyPermission();
9503 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009504
joonhunshin4ac60942023-11-15 15:23:39 +00009505 enforceTelephonyFeatureWithException(callingPackage,
9506 PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason");
9507
Nate Myren116695d2024-02-09 09:36:01 -08009508 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009509 final long identity = Binder.clearCallingIdentity();
9510 try {
Nate Myren116695d2024-02-09 09:36:01 -08009511 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
9512 && null != callingPackage && opEnableMobileDataByUser()) {
Nate Myren453c3472024-03-13 11:28:11 -07009513 mAppOps.noteOpNoThrow(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER,
Nate Myren116695d2024-02-09 09:36:01 -08009514 callingUid, callingPackage, null, null);
9515 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009516 Phone phone = getPhone(subId);
9517 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009518 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9519 phone.carrierActionSetMeteredApnsEnabled(enabled);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00009520 } else if (phone.getDataSettingsManager() != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07009521 phone.getDataSettingsManager().setDataEnabled(
9522 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009523 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009524 }
9525 } finally {
9526 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009527 }
9528 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009529
9530 /**
9531 * Get Client request stats
9532 * @return List of Client Request Stats
9533 * @hide
9534 */
9535 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009536 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9537 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009538 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009539 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009540 return null;
9541 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009542 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009543
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009544 final long identity = Binder.clearCallingIdentity();
9545 try {
9546 if (phone != null) {
9547 return phone.getClientRequestStats();
9548 }
9549
9550 return null;
9551 } finally {
9552 Binder.restoreCallingIdentity(identity);
9553 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009554 }
9555
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009556 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009557 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009558 if (uid == Process.ROOT_UID && packageName == null) {
9559 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9560 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9561 // exception. ROOT_UID seems not to have a valid package name returned by
9562 // PackageManager, so just fake it here to avoid issues when running telephony shell
9563 // commands that plumb through the RIL as root, like so:
9564 // $ adb root
9565 // $ adb shell cmd phone ...
9566 packageName = "root";
9567 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009568 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009569 }
Jack Yueb4124c2017-02-16 15:32:43 -08009570
9571 /**
Grace Chen70990072017-03-24 17:21:30 -07009572 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009573 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009574 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009575 * @param state State of SIM (power down, power up, pass through)
9576 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9577 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9578 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009579 *
9580 **/
9581 @Override
Grace Chen70990072017-03-24 17:21:30 -07009582 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009583 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009584
9585 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9586 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot");
9587
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009588 Phone phone = PhoneFactory.getPhone(slotIndex);
9589
vagdeviaf9a5b92018-08-15 16:01:53 -07009590 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9591
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009592 final long identity = Binder.clearCallingIdentity();
9593 try {
9594 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009595 phone.setSimPowerState(state, null, workSource);
9596 }
9597 } finally {
9598 Binder.restoreCallingIdentity(identity);
9599 }
9600 }
9601
9602 /**
9603 * Set SIM card power state.
9604 *
9605 * @param slotIndex SIM slot id.
9606 * @param state State of SIM (power down, power up, pass through)
9607 * @param callback callback to trigger after success or failure
9608 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9609 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9610 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9611 *
9612 **/
9613 @Override
9614 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9615 IIntegerConsumer callback) {
9616 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009617
9618 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9619 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
9620 "setSimPowerStateForSlotWithCallback");
9621
Jordan Liu109698e2020-11-24 14:50:34 -08009622 Phone phone = PhoneFactory.getPhone(slotIndex);
9623
9624 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9625
9626 final long identity = Binder.clearCallingIdentity();
9627 try {
9628 if (phone != null) {
9629 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9630 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009631 }
9632 } finally {
9633 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009634 }
9635 }
Shuo Qiandd210312017-04-12 22:11:33 +00009636
Tyler Gunn65d45c22017-06-05 11:22:26 -07009637 private boolean isUssdApiAllowed(int subId) {
9638 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009639 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009640 if (configManager == null) {
9641 return false;
9642 }
9643 PersistableBundle pb = configManager.getConfigForSubId(subId);
9644 if (pb == null) {
9645 return false;
9646 }
9647 return pb.getBoolean(
9648 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9649 }
9650
Shuo Qiandd210312017-04-12 22:11:33 +00009651 /**
Ling Mac28f0212023-03-24 16:07:15 -07009652 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00009653 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07009654 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00009655 */
goneil9c5f4872017-12-05 14:07:56 -08009656 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009657 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009658 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
joonhunshin4ac60942023-11-15 15:23:39 +00009659
9660 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9661 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode");
9662
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009663 final long identity = Binder.clearCallingIdentity();
9664 try {
Ling Mac28f0212023-03-24 16:07:15 -07009665 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009666 } finally {
9667 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009668 }
9669 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009670
9671 /**
9672 * Get the current signal strength information for the given subscription.
9673 * Because this information is not updated when the device is in a low power state
9674 * it should not be relied-upon to be current.
9675 * @param subId Subscription index
9676 * @return the most recent cached signal strength info from the modem
9677 */
9678 @Override
9679 public SignalStrength getSignalStrength(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00009680 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9681 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength");
9682
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009683 final long identity = Binder.clearCallingIdentity();
9684 try {
9685 Phone p = getPhone(subId);
9686 if (p == null) {
9687 return null;
9688 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009689
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009690 return p.getSignalStrength();
9691 } finally {
9692 Binder.restoreCallingIdentity(identity);
9693 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009694 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009695
Pengquan Meng77b7f132018-08-22 14:49:57 -07009696 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009697 * Get the current modem radio state for the given slot.
9698 * @param slotIndex slot index.
9699 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009700 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009701 * @return the current radio power state from the modem
9702 */
9703 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009704 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009705 Phone phone = PhoneFactory.getPhone(slotIndex);
9706 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009707 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9708 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009709 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9710 }
9711
joonhunshin4ac60942023-11-15 15:23:39 +00009712 enforceTelephonyFeatureWithException(callingPackage,
9713 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState");
9714
Chen Xuf792fd62018-10-17 17:54:36 +00009715 final long identity = Binder.clearCallingIdentity();
9716 try {
9717 return phone.getRadioPowerState();
9718 } finally {
9719 Binder.restoreCallingIdentity(identity);
9720 }
9721 }
9722 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9723 }
9724
9725 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009726 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9727 *
9728 * <p>Requires one of the following permissions:
9729 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009730 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009731 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9732 * privileges.
9733 *
9734 * @param subId subscription id
9735 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9736 * {@code false}.
9737 */
9738 @Override
9739 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009740 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009741 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009742 try {
9743 mApp.enforceCallingOrSelfPermission(
9744 android.Manifest.permission.ACCESS_NETWORK_STATE,
9745 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009746 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009747 mApp.enforceCallingOrSelfPermission(
9748 permission.READ_BASIC_PHONE_STATE, functionName);
9749 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009750 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009751 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009752 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009753 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009754
joonhunshin4ac60942023-11-15 15:23:39 +00009755 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9756 PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled");
9757
Pengquan Menga1bb6272018-09-06 09:59:22 -07009758 boolean isEnabled = false;
9759 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009760 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009761 Phone phone = getPhone(subId);
9762 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009763 } finally {
9764 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009765 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009766 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009767 }
9768
9769
9770 /**
9771 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9772 *
9773 * <p> Requires permission:
9774 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9775 * privileges.
9776 *
9777 * @param subId subscription id
9778 * @param isEnabled {@code true} means enable, {@code false} means disable.
9779 */
9780 @Override
9781 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009782 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9783 mApp, subId, "setDataRoamingEnabled");
9784
joonhunshin4ac60942023-11-15 15:23:39 +00009785 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9786 PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled");
9787
Pengquan Menga1bb6272018-09-06 09:59:22 -07009788 final long identity = Binder.clearCallingIdentity();
9789 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009790 Phone phone = getPhone(subId);
9791 if (phone != null) {
9792 phone.setDataRoamingEnabled(isEnabled);
9793 }
9794 } finally {
9795 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009796 }
9797 }
9798
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009799 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009800 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009801 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009802 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009803 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009804
joonhunshin4ac60942023-11-15 15:23:39 +00009805 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9806 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed");
9807
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009808 boolean isAllowed = true;
9809 final long identity = Binder.clearCallingIdentity();
9810 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009811 Phone phone = getPhone(subId);
9812 if (phone != null) {
9813 isAllowed = phone.isCspPlmnEnabled();
9814 }
9815 } finally {
9816 Binder.restoreCallingIdentity(identity);
9817 }
9818 return isAllowed;
9819 }
9820
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009821 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9822 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009823 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009824 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009825 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009826 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9827 if (phone == null) {
9828 return false;
9829 }
9830 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9831 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9832 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009833 }
9834
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009835 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009836 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009837 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009838 mApp.getSystemService(AppOpsManager.class)
9839 .checkPackage(Binder.getCallingUid(), callingPackage);
9840
Jordan Liu1e142fc2019-04-22 15:10:43 -07009841 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009842 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009843 try {
9844 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009845 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009846 } catch (SecurityException e) {
9847 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9848 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009849 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009850 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009851 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009852 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009853 }
joonhunshin4ac60942023-11-15 15:23:39 +00009854
9855 enforceTelephonyFeatureWithException(callingPackage,
9856 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo");
9857
sandeepjsb6c87872021-09-27 15:34:44 +00009858 // checking compatibility, if calling app's target SDK is T and beyond.
9859 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9860 Binder.getCallingUid())) {
9861 isIccIdAccessRestricted = true;
9862 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009863 final long identity = Binder.clearCallingIdentity();
9864 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009865 UiccController uiccController = UiccController.getInstance();
9866 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009867 if (hasReadPermission) {
9868 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009869 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009870
9871 // Remove private info if the caller doesn't have access
9872 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9873 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009874 //setting the value after compatibility check
9875 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009876 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9877 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009878 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009879 if (card == null) {
9880 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009881 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009882 continue;
9883 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009884 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9885 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009886 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009887 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009888 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009889 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9890 for (UiccPortInfo portInfo : portInfos) {
9891 UiccPort port = uiccController.getUiccPortForSlot(
9892 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9893 if (port == null) {
9894 // assume no access if port is null
9895 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9896 continue;
9897 }
9898 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9899 uiccPortInfos.add(portInfo);
9900 } else {
9901 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9902 }
9903 }
9904 filteredInfos.add(new UiccCardInfo(
9905 cardInfo.isEuicc(),
9906 cardInfo.getCardId(),
9907 null,
9908 cardInfo.getPhysicalSlotIndex(),
9909 cardInfo.isRemovable(),
9910 cardInfo.isMultipleEnabledProfilesSupported(),
9911 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009912 }
9913 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009914 } finally {
9915 Binder.restoreCallingIdentity(identity);
9916 }
9917 }
9918
sandeepjsb6c87872021-09-27 15:34:44 +00009919 /**
9920 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9921 * generally private and require carrier privileges to view.
9922 *
9923 * @hide
9924 */
9925 @NonNull
9926 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9927 List<UiccPortInfo> portinfo = new ArrayList<>();
9928 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9929 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9930 }
9931 return new UiccCardInfo(
9932 cardInfo.isEuicc(),
9933 cardInfo.getCardId(),
9934 null,
9935 cardInfo.getPhysicalSlotIndex(),
9936 cardInfo.isRemovable(),
9937 cardInfo.isMultipleEnabledProfilesSupported(),
9938 portinfo
9939 );
9940 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009941
sandeepjsb6c87872021-09-27 15:34:44 +00009942 /**
9943 * @hide
9944 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9945 * These values are generally private and require carrier privileges to view.
9946 */
9947 @NonNull
9948 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9949 return new UiccPortInfo(
9950 UiccPortInfo.ICCID_REDACTED,
9951 portInfo.getPortIndex(),
9952 portInfo.getLogicalSlotIndex(),
9953 portInfo.isActive()
9954 );
9955 }
9956 @Override
9957 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009958 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009959 mApp.getSystemService(AppOpsManager.class)
9960 .checkPackage(Binder.getCallingUid(), callingPackage);
9961
sandeepjsb6c87872021-09-27 15:34:44 +00009962 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009963
Aman Guptaf3c90b32022-03-17 04:54:16 +00009964 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9965 // we are reading iccId which is PII data.
9966 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009967
joonhunshin4ac60942023-11-15 15:23:39 +00009968 enforceTelephonyFeatureWithException(callingPackage,
9969 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo");
9970
sandeepjsb6c87872021-09-27 15:34:44 +00009971 // checking compatibility, if calling app's target SDK is T and beyond.
9972 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9973 Binder.getCallingUid())) {
9974 isLogicalSlotAccessRestricted = true;
9975 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009976 final long identity = Binder.clearCallingIdentity();
9977 try {
9978 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009979 if (slots == null || slots.length == 0) {
9980 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009981 return null;
9982 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009983 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9984 for (int i = 0; i < slots.length; i++) {
9985 UiccSlot slot = slots[i];
9986 if (slot == null) {
9987 continue;
9988 }
9989
Jordan Liu7be7e652019-05-06 18:55:02 +00009990 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009991 UiccCard card = slot.getUiccCard();
9992 if (card != null) {
9993 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009994 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009995 cardId = slot.getEid();
9996 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009997 // If cardId is null, use iccId of default port as cardId.
9998 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009999 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010000 }
10001
Jordan Liu857451f2019-05-09 16:35:35 -070010002 if (cardId != null) {
10003 // if cardId is an ICCID, strip off trailing Fs before exposing to user
10004 // if cardId is an EID, it's all digits so this is fine
10005 cardId = IccUtils.stripTrailingFs(cardId);
10006 }
10007
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010008 int cardState = 0;
10009 switch (slot.getCardState()) {
10010 case CARDSTATE_ABSENT:
10011 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
10012 break;
10013 case CARDSTATE_PRESENT:
10014 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
10015 break;
10016 case CARDSTATE_ERROR:
10017 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
10018 break;
10019 case CARDSTATE_RESTRICTED:
10020 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
10021 break;
10022 default:
10023 break;
10024
10025 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010026 List<UiccPortInfo> portInfos = new ArrayList<>();
10027 int[] portIndexes = slot.getPortList();
10028 for (int portIdx : portIndexes) {
10029 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +000010030 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +000010031 portInfos.add(new UiccPortInfo(iccId, portIdx,
10032 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010033 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010034 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010035 slot.isEuicc(),
10036 cardId,
10037 cardState,
Jordan Liua2619582019-02-14 12:56:40 -080010038 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010039 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +000010040 //setting the value after compatibility check
10041 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010042 }
10043 return infos;
10044 } finally {
10045 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -070010046 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010047 }
10048
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010049 /* Returns null if doesn't have read permission or carrier privilege access. */
10050 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
10051 boolean hasReadPermission) {
10052 String iccId = slot.getIccId(portIndex);
10053 if (hasReadPermission) { // if has read permission
10054 return iccId;
10055 } else {
10056 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
10057 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
10058 // if no read permission, checking carrier privilege access
10059 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
10060 return iccId;
10061 }
10062 }
10063 }
10064 // No read permission or carrier privilege access.
10065 return UiccPortInfo.ICCID_REDACTED;
10066 }
10067
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010068 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010069 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010070 public boolean switchSlots(int[] physicalSlots) {
10071 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010072
joonhunshin4ac60942023-11-15 15:23:39 +000010073 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10074 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots");
10075
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010076 final long identity = Binder.clearCallingIdentity();
10077 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010078 List<UiccSlotMapping> slotMappings = new ArrayList<>();
10079 for (int i = 0; i < physicalSlots.length; i++) {
10080 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
10081 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
10082 physicalSlots[i], i));
10083 }
10084 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010085 } finally {
10086 Binder.restoreCallingIdentity(identity);
10087 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010088 }
Jack Yu4c988042018-02-27 15:30:01 -080010089
10090 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010091 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
10092 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
10093 enforceModifyPermission();
10094
joonhunshin4ac60942023-11-15 15:23:39 +000010095 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10096 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping");
10097
sandeepjsb6c87872021-09-27 15:34:44 +000010098 final long identity = Binder.clearCallingIdentity();
10099 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010100 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +000010101 } finally {
10102 Binder.restoreCallingIdentity(identity);
10103 }
10104 }
10105
10106 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -080010107 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
joonhunshin4ac60942023-11-15 15:23:39 +000010108 enforceTelephonyFeatureWithException(callingPackage,
10109 PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc");
10110
Jordan Liu7de49fa2018-12-06 14:48:49 -080010111 final long identity = Binder.clearCallingIdentity();
10112 try {
10113 return UiccController.getInstance().getCardIdForDefaultEuicc();
10114 } finally {
10115 Binder.restoreCallingIdentity(identity);
10116 }
10117 }
10118
Pengquan Meng85728fb2018-03-12 16:31:21 -070010119 /**
goneil47ffb6e2018-04-06 15:40:58 -070010120 * A test API to reload the UICC profile.
10121 *
10122 * <p>Requires that the calling app has permission
10123 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
10124 * @hide
10125 */
10126 @Override
10127 public void refreshUiccProfile(int subId) {
10128 enforceModifyPermission();
10129
10130 final long identity = Binder.clearCallingIdentity();
10131 try {
10132 Phone phone = getPhone(subId);
10133 if (phone == null) {
10134 return;
10135 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010136 UiccPort uiccPort = phone.getUiccPort();
10137 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -070010138 return;
10139 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010140 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -070010141 if (uiccProfile == null) {
10142 return;
10143 }
10144 uiccProfile.refresh();
10145 } finally {
10146 Binder.restoreCallingIdentity(identity);
10147 }
10148 }
10149
10150 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010151 * Returns false if the mobile data is disabled by default, otherwise return true.
10152 */
10153 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010154 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010155 }
10156
10157 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010158 * Returns the default network type for the given {@code subId}, if the default network type is
10159 * not set, return {@link Phone#PREFERRED_NT_MODE}.
10160 */
10161 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010162 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -080010163 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +090010164 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
10165 return list.get(phoneId);
10166 }
10167 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -070010168 }
fionaxua13278b2018-03-21 00:08:13 -070010169
10170 @Override
10171 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -070010172 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -070010173 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010174
10175 final long identity = Binder.clearCallingIdentity();
10176 try {
10177 final Phone phone = getPhone(subId);
10178 if (phone == null) {
10179 loge("setCarrierTestOverride fails with invalid subId: " + subId);
10180 return;
10181 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -080010182 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10183 if (cpt != null) {
10184 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
10185 }
10186 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -070010187 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
10188 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -070010189 if (carrierPrivilegeRules == null) {
10190 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
10191 } else {
10192 mCarrierPrivilegeTestOverrideSubIds.add(subId);
10193 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010194 } finally {
10195 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010196 }
fionaxua13278b2018-03-21 00:08:13 -070010197 }
10198
10199 @Override
Benedict Wong66477622023-02-03 23:30:57 +000010200 public void setCarrierServicePackageOverride(
10201 int subId, String carrierServicePackage, String callingPackage) {
10202 TelephonyPermissions.enforceShellOnly(
10203 Binder.getCallingUid(), "setCarrierServicePackageOverride");
10204
Benedict Wong66477622023-02-03 23:30:57 +000010205 final long identity = Binder.clearCallingIdentity();
10206 try {
10207 final Phone phone = getPhone(subId);
10208 if (phone == null || phone.getSubId() != subId) {
10209 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
10210 throw new IllegalArgumentException("No phone for subid");
10211 }
10212 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10213 if (cpt == null) {
10214 loge("setCarrierServicePackageOverride failed with no CPT for phone");
10215 throw new IllegalStateException("No CPT for phone");
10216 }
10217 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
10218 } finally {
10219 Binder.restoreCallingIdentity(identity);
10220 }
10221 }
10222
10223 @Override
fionaxua13278b2018-03-21 00:08:13 -070010224 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -070010225 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010226
10227 final long identity = Binder.clearCallingIdentity();
10228 try {
10229 final Phone phone = getPhone(subId);
10230 if (phone == null) {
10231 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
10232 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
10233 }
10234 return phone.getCarrierIdListVersion();
10235 } finally {
10236 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010237 }
fionaxua13278b2018-03-21 00:08:13 -070010238 }
Malcolm Chen2c63d402018-08-14 16:00:53 -070010239
10240 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010241 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
10242 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010243 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010244 mApp, subId, callingPackage, callingFeatureId,
10245 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010246 return -1;
10247 }
10248
10249 final long identity = Binder.clearCallingIdentity();
10250 try {
10251 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10252 } finally {
10253 Binder.restoreCallingIdentity(identity);
10254 }
10255 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010256
10257 @Override
10258 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +080010259 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010260 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010261 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010262
joonhunshin4ac60942023-11-15 15:23:39 +000010263 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10264 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode");
10265
Pengquan Menga1bb6272018-09-06 09:59:22 -070010266 final long identity = Binder.clearCallingIdentity();
10267 try {
10268 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10269 } finally {
10270 Binder.restoreCallingIdentity(identity);
10271 }
10272 }
10273
10274 @Override
10275 public boolean setCdmaRoamingMode(int subId, int mode) {
10276 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10277 mApp, subId, "setCdmaRoamingMode");
10278
joonhunshin4ac60942023-11-15 15:23:39 +000010279 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10280 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode");
10281
Pengquan Menga1bb6272018-09-06 09:59:22 -070010282 final long identity = Binder.clearCallingIdentity();
10283 try {
10284 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10285 } finally {
10286 Binder.restoreCallingIdentity(identity);
10287 }
10288 }
10289
10290 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010291 public int getCdmaSubscriptionMode(int subId) {
10292 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010293 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010294 mApp, subId, "getCdmaSubscriptionMode");
10295
joonhunshin4ac60942023-11-15 15:23:39 +000010296 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10297 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode");
10298
Sarah Chinbaab1432020-10-28 13:46:24 -070010299 final long identity = Binder.clearCallingIdentity();
10300 try {
10301 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10302 } finally {
10303 Binder.restoreCallingIdentity(identity);
10304 }
10305 }
10306
10307 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010308 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10309 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10310 mApp, subId, "setCdmaSubscriptionMode");
10311
joonhunshin4ac60942023-11-15 15:23:39 +000010312 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10313 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode");
10314
Pengquan Menga1bb6272018-09-06 09:59:22 -070010315 final long identity = Binder.clearCallingIdentity();
10316 try {
10317 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10318 } finally {
10319 Binder.restoreCallingIdentity(identity);
10320 }
10321 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010322
sqianc5eccab2018-10-19 18:46:41 -070010323 @Override
sqian8c685422019-02-22 15:55:18 -080010324 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010325 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010326 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010327 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10328 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010329 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10330 }
joonhunshin4ac60942023-11-15 15:23:39 +000010331
10332 enforceTelephonyFeatureWithException(callingPackage,
10333 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList");
10334
sqian11b7a0e2018-12-05 18:48:28 -080010335 final long identity = Binder.clearCallingIdentity();
10336 try {
sqian854d44b2018-12-12 16:48:18 -080010337 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10338 for (Phone phone: PhoneFactory.getPhones()) {
10339 if (phone.getEmergencyNumberTracker() != null
10340 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10341 emergencyNumberListInternal.put(
10342 phone.getSubId(),
10343 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10344 }
sqian11b7a0e2018-12-05 18:48:28 -080010345 }
sqian854d44b2018-12-12 16:48:18 -080010346 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010347 } finally {
10348 Binder.restoreCallingIdentity(identity);
10349 }
sqianc5eccab2018-10-19 18:46:41 -070010350 }
10351
10352 @Override
sqian8c685422019-02-22 15:55:18 -080010353 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010354 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010355 if (!exactMatch) {
10356 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010357 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010358 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010359 }
joonhunshin4ac60942023-11-15 15:23:39 +000010360
10361 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10362 PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber");
10363
sqian11b7a0e2018-12-05 18:48:28 -080010364 final long identity = Binder.clearCallingIdentity();
10365 try {
sqian854d44b2018-12-12 16:48:18 -080010366 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010367 //Note: we ignore passed in param exactMatch. We can remove it once
10368 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010369 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010370 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010371 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010372 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010373 }
sqian11b7a0e2018-12-05 18:48:28 -080010374 }
10375 return false;
10376 } finally {
10377 Binder.restoreCallingIdentity(identity);
10378 }
10379 }
10380
sqianf4ca7ed2019-01-15 18:32:07 -080010381 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010382 * Start emergency callback mode for GsmCdmaPhone for testing.
10383 */
10384 @Override
10385 public void startEmergencyCallbackMode() {
10386 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10387 "startEmergencyCallbackMode");
10388 enforceModifyPermission();
10389 final long identity = Binder.clearCallingIdentity();
10390 try {
10391 for (Phone phone : PhoneFactory.getPhones()) {
10392 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10393 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10394 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10395 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10396 gsmCdmaPhone.obtainMessage(
10397 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10398 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10399 }
10400 }
10401 } finally {
10402 Binder.restoreCallingIdentity(identity);
10403 }
10404 }
10405
10406 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010407 * Update emergency number list for test mode.
10408 */
10409 @Override
10410 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10411 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10412 "updateEmergencyNumberListTestMode");
10413
10414 final long identity = Binder.clearCallingIdentity();
10415 try {
10416 for (Phone phone: PhoneFactory.getPhones()) {
10417 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10418 if (tracker != null) {
10419 tracker.executeEmergencyNumberTestModeCommand(action, num);
10420 }
10421 }
10422 } finally {
10423 Binder.restoreCallingIdentity(identity);
10424 }
10425 }
10426
10427 /**
10428 * Get the full emergency number list for test mode.
10429 */
10430 @Override
10431 public List<String> getEmergencyNumberListTestMode() {
10432 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10433 "getEmergencyNumberListTestMode");
10434
10435 final long identity = Binder.clearCallingIdentity();
10436 try {
10437 Set<String> emergencyNumbers = new HashSet<>();
10438 for (Phone phone: PhoneFactory.getPhones()) {
10439 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10440 if (tracker != null) {
10441 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10442 emergencyNumbers.add(num.getNumber());
10443 }
10444 }
10445 }
10446 return new ArrayList<>(emergencyNumbers);
10447 } finally {
10448 Binder.restoreCallingIdentity(identity);
10449 }
10450 }
10451
chen xud6b45bd2018-10-30 22:27:10 -070010452 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010453 public int getEmergencyNumberDbVersion(int subId) {
10454 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10455
joonhunshin4ac60942023-11-15 15:23:39 +000010456 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10457 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion");
10458
Shuo Qian3b6ee772019-11-13 17:43:31 -080010459 final long identity = Binder.clearCallingIdentity();
10460 try {
10461 final Phone phone = getPhone(subId);
10462 if (phone == null) {
10463 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10464 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10465 }
10466 return phone.getEmergencyNumberDbVersion();
10467 } finally {
10468 Binder.restoreCallingIdentity(identity);
10469 }
10470 }
10471
10472 @Override
10473 public void notifyOtaEmergencyNumberDbInstalled() {
10474 enforceModifyPermission();
10475
joonhunshin4ac60942023-11-15 15:23:39 +000010476 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10477 PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled");
10478
Shuo Qian3b6ee772019-11-13 17:43:31 -080010479 final long identity = Binder.clearCallingIdentity();
10480 try {
10481 for (Phone phone: PhoneFactory.getPhones()) {
10482 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10483 if (tracker != null) {
10484 tracker.updateOtaEmergencyNumberDatabase();
10485 }
10486 }
10487 } finally {
10488 Binder.restoreCallingIdentity(identity);
10489 }
10490 }
10491
10492 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010493 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010494 enforceActiveEmergencySessionPermission();
10495
joonhunshin4ac60942023-11-15 15:23:39 +000010496 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10497 PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath");
10498
Shuo Qian3b6ee772019-11-13 17:43:31 -080010499 final long identity = Binder.clearCallingIdentity();
10500 try {
10501 for (Phone phone: PhoneFactory.getPhones()) {
10502 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10503 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010504 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10505 }
10506 }
10507 } finally {
10508 Binder.restoreCallingIdentity(identity);
10509 }
10510 }
10511
10512 @Override
10513 public void resetOtaEmergencyNumberDbFilePath() {
10514 enforceActiveEmergencySessionPermission();
10515
joonhunshin4ac60942023-11-15 15:23:39 +000010516 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10517 PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath");
10518
Shuo Qianc373f112020-03-05 17:55:34 -080010519 final long identity = Binder.clearCallingIdentity();
10520 try {
10521 for (Phone phone: PhoneFactory.getPhones()) {
10522 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10523 if (tracker != null) {
10524 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010525 }
10526 }
10527 } finally {
10528 Binder.restoreCallingIdentity(identity);
10529 }
10530 }
10531
10532 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010533 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10534 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10535 Phone phone = getPhone(subId);
10536 if (phone == null) {
10537 return null;
10538 }
10539 final long identity = Binder.clearCallingIdentity();
10540 try {
10541 UiccProfile profile = UiccController.getInstance()
10542 .getUiccProfileForPhone(phone.getPhoneId());
10543 if (profile != null) {
10544 return profile.getCertsFromCarrierPrivilegeAccessRules();
10545 }
10546 } finally {
10547 Binder.restoreCallingIdentity(identity);
10548 }
10549 return null;
10550 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010551
10552 /**
10553 * Enable or disable a modem stack.
10554 */
10555 @Override
10556 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10557 enforceModifyPermission();
10558
joonhunshin4ac60942023-11-15 15:23:39 +000010559 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10560 PackageManager.FEATURE_TELEPHONY, "enableModemForSlot");
10561
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010562 final long identity = Binder.clearCallingIdentity();
10563 try {
10564 Phone phone = PhoneFactory.getPhone(slotIndex);
10565 if (phone == null) {
10566 return false;
10567 } else {
10568 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10569 }
10570 } finally {
10571 Binder.restoreCallingIdentity(identity);
10572 }
10573 }
Michelecea4cf22018-12-21 15:00:11 -080010574
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010575 /**
10576 * Whether a modem stack is enabled or not.
10577 */
10578 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010579 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10580 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010581 Phone phone = PhoneFactory.getPhone(slotIndex);
10582 if (phone == null) return false;
10583
10584 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010585 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10586 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010587 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10588 }
10589
joonhunshin4ac60942023-11-15 15:23:39 +000010590 enforceTelephonyFeatureWithException(callingPackage,
10591 PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot");
10592
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010593 final long identity = Binder.clearCallingIdentity();
10594 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010595 try {
10596 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10597 } catch (NoSuchElementException ex) {
10598 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10599 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010600 } finally {
10601 Binder.restoreCallingIdentity(identity);
10602 }
10603 }
10604
Michelecea4cf22018-12-21 15:00:11 -080010605 @Override
Michele0ea7d782019-03-19 14:58:42 -070010606 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010607 enforceModifyPermission();
10608
joonhunshin4ac60942023-11-15 15:23:39 +000010609 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10610 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction");
10611
Michelecea4cf22018-12-21 15:00:11 -080010612 final long identity = Binder.clearCallingIdentity();
10613 try {
10614 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010615 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010616 .commit();
10617 } finally {
10618 Binder.restoreCallingIdentity(identity);
10619 }
10620 }
10621
10622 @Override
Michele0ea7d782019-03-19 14:58:42 -070010623 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010624 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010625 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010626 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10627 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010628 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010629 }
Michelecea4cf22018-12-21 15:00:11 -080010630
joonhunshin4ac60942023-11-15 15:23:39 +000010631 enforceTelephonyFeatureWithException(callingPackage,
10632 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported");
10633
Michelecea4cf22018-12-21 15:00:11 -080010634 final long identity = Binder.clearCallingIdentity();
10635 try {
Michele0ea7d782019-03-19 14:58:42 -070010636 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010637 } finally {
10638 Binder.restoreCallingIdentity(identity);
10639 }
10640 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010641
Michele0ea7d782019-03-19 14:58:42 -070010642 @TelephonyManager.IsMultiSimSupportedResult
10643 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010644 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10645 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10646 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010647 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10648 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010649 }
10650 // Check if the hardware supports multisim functionality. If usage of multisim is not
10651 // supported by the modem, indicate that it is restricted.
10652 PhoneCapability staticCapability =
10653 mPhoneConfigurationManager.getStaticPhoneCapability();
10654 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010655 loge("isMultiSimSupportedInternal: no static configuration available");
10656 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010657 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010658 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010659 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10660 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010661 }
10662 // Check if support of multiple SIMs is restricted by carrier
10663 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010664 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010665 }
10666
Michele0ea7d782019-03-19 14:58:42 -070010667 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010668 }
10669
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010670 /**
10671 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010672 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10673 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10674 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010675 * @param numOfSims number of active sims we want to switch to
10676 */
10677 @Override
10678 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010679 if (numOfSims == 1) {
10680 enforceModifyPermission();
10681 } else {
10682 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10683 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10684 }
joonhunshin4ac60942023-11-15 15:23:39 +000010685
10686 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10687 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig");
10688
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010689 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010690
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010691 try {
Michele30b57b22019-03-01 12:01:14 -080010692 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010693 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010694 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10695 return;
10696 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010697 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10698 } finally {
10699 Binder.restoreCallingIdentity(identity);
10700 }
10701 }
10702
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010703 @Override
10704 public boolean isApplicationOnUicc(int subId, int appType) {
10705 enforceReadPrivilegedPermission("isApplicationOnUicc");
joonhunshin4ac60942023-11-15 15:23:39 +000010706
10707 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10708 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc");
10709
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010710 Phone phone = getPhone(subId);
10711 if (phone == null) {
10712 return false;
10713 }
10714 final long identity = Binder.clearCallingIdentity();
10715 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010716 UiccPort uiccPort = phone.getUiccPort();
10717 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010718 return false;
10719 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010720 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010721 if (uiccProfile == null) {
10722 return false;
10723 }
10724 if (TelephonyManager.APPTYPE_SIM <= appType
10725 && appType <= TelephonyManager.APPTYPE_ISIM) {
10726 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10727 }
10728 return false;
10729 } finally {
10730 Binder.restoreCallingIdentity(identity);
10731 }
10732 }
10733
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010734 /**
chen xub4baa772019-04-03 10:23:41 -070010735 * Get whether making changes to modem configurations will trigger reboot.
10736 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010737 */
10738 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010739 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10740 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010741 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010742 mApp, subId, callingPackage, callingFeatureId,
10743 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010744 return false;
10745 }
joonhunshin4ac60942023-11-15 15:23:39 +000010746
10747 enforceTelephonyFeatureWithException(callingPackage,
10748 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
10749 "doesSwitchMultiSimConfigTriggerReboot");
10750
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010751 final long identity = Binder.clearCallingIdentity();
10752 try {
10753 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10754 } finally {
10755 Binder.restoreCallingIdentity(identity);
10756 }
10757 }
10758
Nathan Harold29f5f052019-02-15 13:41:57 -080010759 private void updateModemStateMetrics() {
10760 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10761 // TODO: check the state for each modem if the api is ready.
10762 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10763 }
10764
Pengquan Meng3889a572019-01-23 11:16:29 -080010765 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010766 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010767 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010768 // Verify that the callingPackage belongs to the calling UID
10769 mApp.getSystemService(AppOpsManager.class)
10770 .checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000010771
10772 enforceTelephonyFeatureWithException(callingPackage,
10773 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping");
10774
Pengquan Meng3889a572019-01-23 11:16:29 -080010775 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010776 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010777 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010778 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10779 if (slotInfos != null) {
10780 for (int i = 0; i < slotInfos.length; i++) {
10781 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10782 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10783 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10784 portInfo.getLogicalSlotIndex()));
10785 }
10786 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010787 }
10788 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010789 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010790 } finally {
10791 Binder.restoreCallingIdentity(identity);
10792 }
10793 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010794
10795 /**
10796 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010797 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010798 */
jimsunf9ec1622022-09-13 21:18:43 +080010799 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010800 @Override
10801 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010802 return getHalVersion(HAL_SERVICE_RADIO);
10803 }
10804
10805 /**
10806 * Get the HAL Version of a specific service
10807 */
10808 @Override
10809 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010810 Phone phone = getDefaultPhone();
10811 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010812 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010813 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10814 return hv.major * 100 + hv.minor;
10815 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010816
10817 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010818 * Get the current calling package name.
sangyun097dcf72024-01-04 10:35:49 +090010819 *
10820 * @return the current calling package name, or null if there is no known package.
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010821 */
10822 @Override
sangyun097dcf72024-01-04 10:35:49 +090010823 public @Nullable String getCurrentPackageName() {
10824 PackageManager pm = mApp.getPackageManager();
10825 String[] packageNames = pm == null ? null : pm.getPackagesForUid(Binder.getCallingUid());
10826 return packageNames == null ? null : packageNames[0];
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010827 }
10828
10829 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010830 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10831 * corresponding network requests on a subId.
10832 *
10833 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010834 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010835 * 2) APN is un-metered for this subscription, or
10836 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010837 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010838 *
10839 * @return whether data is allowed for a apn type.
10840 *
10841 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010842 */
10843 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010844 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010845 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10846 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010847
joonhunshin4ac60942023-11-15 15:23:39 +000010848 enforceTelephonyFeatureWithException(callingPackage,
10849 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn");
10850
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010851 // Now that all security checks passes, perform the operation as ourselves.
10852 final long identity = Binder.clearCallingIdentity();
10853 try {
10854 Phone phone = getPhone(subId);
10855 if (phone == null) return false;
10856
Jack Yu27422a52022-03-21 10:38:05 -070010857 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010858 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010859 isMetered = phone.getDataNetworkController().getDataConfigManager()
10860 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10861 phone.getServiceState().getDataRoaming());
Hunsuk Choibf761bf2024-06-18 08:34:32 +000010862 isDataEnabled = (phone.getDataSettingsManager() != null)
10863 ? phone.getDataSettingsManager().isDataEnabled(apnType) : false;
Jack Yu99e87332021-12-17 23:14:15 -080010864 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010865 } finally {
10866 Binder.restoreCallingIdentity(identity);
10867 }
10868 }
10869
10870 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010871 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010872 enforceReadPrivilegedPermission("isApnMetered");
10873
joonhunshin4ac60942023-11-15 15:23:39 +000010874 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10875 PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered");
10876
Malcolm Chene5ad5792019-04-18 13:51:02 -070010877 // Now that all security checks passes, perform the operation as ourselves.
10878 final long identity = Binder.clearCallingIdentity();
10879 try {
10880 Phone phone = getPhone(subId);
10881 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010882 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10883 DataUtils.apnTypeToNetworkCapability(apnType),
10884 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010885 } finally {
10886 Binder.restoreCallingIdentity(identity);
10887 }
10888 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010889
10890 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010891 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10892 int subscriptionId, IBooleanConsumer resultCallback) {
10893 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +000010894
10895 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10896 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels");
10897
Hall Liu73f5d362020-01-20 13:42:00 -080010898 long token = Binder.clearCallingIdentity();
10899 try {
10900 Phone phone = getPhone(subscriptionId);
10901 if (phone == null) {
10902 try {
10903 if (resultCallback != null) {
10904 resultCallback.accept(false);
10905 }
10906 } catch (RemoteException e) {
10907 // ignore
10908 }
10909 return;
10910 }
10911 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10912 Pair.create(specifiers, (x) -> {
10913 try {
10914 if (resultCallback != null) {
10915 resultCallback.accept(x);
10916 }
10917 } catch (RemoteException e) {
10918 // ignore
10919 }
10920 });
10921 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10922 } finally {
10923 Binder.restoreCallingIdentity(token);
10924 }
10925 }
10926
10927 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010928 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10929 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010930 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010931 mApp, subId, "getSystemSelectionChannels");
joonhunshin4ac60942023-11-15 15:23:39 +000010932
10933 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10934 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels");
10935
Sarah Chin679c08a2020-11-18 13:39:35 -080010936 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10937 final long identity = Binder.clearCallingIdentity();
10938 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010939 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10940 if (result instanceof IllegalStateException) {
10941 throw (IllegalStateException) result;
10942 }
10943 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010944 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10945 return specifiers;
10946 } finally {
10947 Binder.restoreCallingIdentity(identity);
10948 }
10949 }
10950
10951 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010952 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010953 enforceReadPrivilegedPermission("isMvnoMatched");
joonhunshin4ac60942023-11-15 15:23:39 +000010954
10955 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10956 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched");
10957
Jack Yu8b766fc2022-03-21 09:42:33 -070010958 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010959 }
10960
10961 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010962 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10963 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010964 if (callingPackage == null) {
10965 callingPackage = getCurrentPackageName();
10966 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010967 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10968 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010969 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10970 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010971 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10972 }
10973 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10974 Intent intent = new Intent();
10975 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10976 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10977 // Bring up choose default SMS subscription dialog right now
10978 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10979 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10980 mApp.startActivity(intent);
10981 }
chen xud5ca2d52019-05-28 15:20:57 -070010982
10983 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010984 public void showSwitchToManagedProfileDialog() {
10985 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000010986 try {
10987 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
10988 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
10989 // for work telephony.
10990 Intent intent = new Intent(Intent.ACTION_SENDTO);
10991 intent.setData(Uri.parse("smsto:"));
10992 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10993 mApp.startActivity(intent);
10994 } catch (ActivityNotFoundException e) {
10995 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
10996 Intent intent = new Intent();
10997 intent.setClass(mApp, ErrorDialogActivity.class);
10998 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10999 mApp.startActivity(intent);
11000 }
Ayush Sharma787854b2022-12-12 14:55:02 +000011001 }
11002
11003 @Override
chen xud5ca2d52019-05-28 15:20:57 -070011004 public String getMmsUAProfUrl(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000011005 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11006 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl");
11007
chen xud5ca2d52019-05-28 15:20:57 -070011008 //TODO investigate if this API should require proper permission check in R b/133791609
11009 final long identity = Binder.clearCallingIdentity();
11010 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011011 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
11012 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
11013 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
11014 return carrierUAProfUrl;
11015 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011016 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11017 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070011018 } finally {
11019 Binder.restoreCallingIdentity(identity);
11020 }
11021 }
11022
11023 @Override
11024 public String getMmsUserAgent(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000011025 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11026 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent");
11027
chen xud5ca2d52019-05-28 15:20:57 -070011028 //TODO investigate if this API should require proper permission check in R b/133791609
11029 final long identity = Binder.clearCallingIdentity();
11030 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011031 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
11032 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
11033 if (!TextUtils.isEmpty(carrierUserAgent)) {
11034 return carrierUserAgent;
11035 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011036 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11037 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070011038 } finally {
11039 Binder.restoreCallingIdentity(identity);
11040 }
11041 }
Jack Yub07d4972019-05-28 16:12:25 -070011042
11043 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070011044 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
11045 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070011046
joonhunshin4ac60942023-11-15 15:23:39 +000011047 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11048 PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled");
11049
Jack Yub07d4972019-05-28 16:12:25 -070011050 final long identity = Binder.clearCallingIdentity();
11051 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011052 Phone phone = getPhone(subscriptionId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +000011053 if (phone == null || phone.getDataSettingsManager() == null) return false;
Jack Yub07d4972019-05-28 16:12:25 -070011054
Ling Maf188d502022-09-16 15:22:36 -070011055 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070011056 } finally {
11057 Binder.restoreCallingIdentity(identity);
11058 }
11059 }
11060
11061 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080011062 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070011063 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080011064 enforceModifyPermission();
11065
joonhunshin4ac60942023-11-15 15:23:39 +000011066 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11067 PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled");
11068
changbettyd5c246e2019-12-24 15:40:37 +080011069 final long identity = Binder.clearCallingIdentity();
11070 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011071 Phone phone = getPhone(subscriptionId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +000011072 if (phone == null || phone.getDataSettingsManager() == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080011073
Ling Maf188d502022-09-16 15:22:36 -070011074 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080011075 } finally {
11076 Binder.restoreCallingIdentity(identity);
11077 }
11078 }
11079
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011080 /**
Hall Liu746e03c2020-09-25 11:13:49 -070011081 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011082 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
11083 * otherwise.
11084 */
11085 @Override
11086 public void setCepEnabled(boolean isCepEnabled) {
11087 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
11088
11089 final long identity = Binder.clearCallingIdentity();
11090 try {
11091 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
11092 for (Phone phone : PhoneFactory.getPhones()) {
11093 Phone defaultPhone = phone.getImsPhone();
11094 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
11095 ImsPhone imsPhone = (ImsPhone) defaultPhone;
11096 ImsPhoneCallTracker imsPhoneCallTracker =
11097 (ImsPhoneCallTracker) imsPhone.getCallTracker();
11098 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
11099 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
11100 + imsPhone.getMsisdn());
11101 }
11102 }
11103 } finally {
11104 Binder.restoreCallingIdentity(identity);
11105 }
11106 }
allenwtsu46dcc572020-01-08 18:24:03 +080011107
11108 /**
11109 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
11110 *
11111 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
11112 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
11113 * before being read.
11114 */
11115 @Override
11116 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
11117 isCompressed) {
11118 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11119 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011120 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11121 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11122 }
joonhunshin4ac60942023-11-15 15:23:39 +000011123
11124 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11125 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11126 Binder.getCallingUserHandle())) {
11127 if (!isImsAvailableOnDevice()) {
11128 // ProvisioningManager can not handle ServiceSpecificException.
11129 // Throw the IllegalStateException and annotate ProvisioningManager.
11130 throw new IllegalStateException("IMS not available on device.");
11131 }
11132 } else {
11133 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11134 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11135 "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011136 }
11137
11138 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080011139 try {
Hui Wang761a6682020-10-31 05:12:53 +000011140 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
11141 } finally {
11142 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080011143 }
11144 }
zoey chene02881a2019-12-30 16:11:23 +080011145
11146 @Override
11147 public boolean isIccLockEnabled(int subId) {
11148 enforceReadPrivilegedPermission("isIccLockEnabled");
11149
joonhunshin4ac60942023-11-15 15:23:39 +000011150 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11151 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled");
11152
zoey chene02881a2019-12-30 16:11:23 +080011153 // Now that all security checks passes, perform the operation as ourselves.
11154 final long identity = Binder.clearCallingIdentity();
11155 try {
11156 Phone phone = getPhone(subId);
11157 if (phone != null && phone.getIccCard() != null) {
11158 return phone.getIccCard().getIccLockEnabled();
11159 } else {
11160 return false;
11161 }
11162 } finally {
11163 Binder.restoreCallingIdentity(identity);
11164 }
11165 }
11166
11167 /**
11168 * Set the ICC pin lock enabled or disabled.
11169 *
11170 * @return an integer representing the status of IccLock enabled or disabled in the following
11171 * three cases:
11172 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
11173 * successfully.
11174 * - Positive number and zero for remaining password attempts.
11175 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11176 *
11177 */
11178 @Override
11179 public int setIccLockEnabled(int subId, boolean enabled, String password) {
11180 enforceModifyPermission();
11181
joonhunshin4ac60942023-11-15 15:23:39 +000011182 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11183 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled");
11184
zoey chene02881a2019-12-30 16:11:23 +080011185 Phone phone = getPhone(subId);
11186 if (phone == null) {
11187 return 0;
11188 }
11189 // Now that all security checks passes, perform the operation as ourselves.
11190 final long identity = Binder.clearCallingIdentity();
11191 try {
11192 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
11193 new Pair<Boolean, String>(enabled, password), phone, null);
11194 return attemptsRemaining;
11195
11196 } catch (Exception e) {
11197 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
11198 } finally {
11199 Binder.restoreCallingIdentity(identity);
11200 }
11201 return 0;
11202 }
11203
11204 /**
11205 * Change the ICC password used in ICC pin lock.
11206 *
11207 * @return an integer representing the status of IccLock changed in the following three cases:
11208 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
11209 * - Positive number and zero for remaining password attempts.
11210 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11211 *
11212 */
11213 @Override
11214 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
11215 enforceModifyPermission();
11216
joonhunshin4ac60942023-11-15 15:23:39 +000011217 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11218 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword");
11219
zoey chene02881a2019-12-30 16:11:23 +080011220 Phone phone = getPhone(subId);
11221 if (phone == null) {
11222 return 0;
11223 }
11224 // Now that all security checks passes, perform the operation as ourselves.
11225 final long identity = Binder.clearCallingIdentity();
11226 try {
11227 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
11228 new Pair<String, String>(oldPassword, newPassword), phone, null);
11229 return attemptsRemaining;
11230
11231 } catch (Exception e) {
11232 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
11233 } finally {
11234 Binder.restoreCallingIdentity(identity);
11235 }
11236 return 0;
11237 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080011238
11239 /**
11240 * Request for receiving user activity notification
11241 */
11242 @Override
11243 public void requestUserActivityNotification() {
11244 if (!mNotifyUserActivity.get()
11245 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
11246 mNotifyUserActivity.set(true);
11247 }
11248 }
11249
11250 /**
11251 * Called when userActivity is signalled in the power manager.
11252 * This is safe to call from any thread, with any window manager locks held or not.
11253 */
11254 @Override
11255 public void userActivity() {
11256 // ***************************************
11257 // * Inherited from PhoneWindowManager *
11258 // ***************************************
11259 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
11260 // WITH ITS LOCKS HELD.
11261 //
11262 // This code must be VERY careful about the locks
11263 // it acquires.
11264 // In fact, the current code acquires way too many,
11265 // and probably has lurking deadlocks.
11266
11267 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
11268 throw new SecurityException("Only the OS may call notifyUserActivity()");
11269 }
11270
11271 if (mNotifyUserActivity.getAndSet(false)) {
11272 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
11273 USER_ACTIVITY_NOTIFICATION_DELAY);
11274 }
11275 }
Malcolm Chen4639c562020-04-13 11:59:40 -070011276
11277 @Override
11278 public boolean canConnectTo5GInDsdsMode() {
11279 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
11280 }
Jack Yud10cdd42020-09-28 20:28:01 -070011281
11282 @Override
11283 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
11284 String callingFeatureId) {
11285 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
11286 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
11287 throw new SecurityException("Requires READ_PHONE_STATE permission.");
11288 }
11289
joonhunshin4ac60942023-11-15 15:23:39 +000011290 enforceTelephonyFeatureWithException(callingPackage,
11291 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns");
11292
Jack Yud10cdd42020-09-28 20:28:01 -070011293 Phone phone = getPhone(subId);
11294 if (phone == null) {
11295 throw new RuntimeException("phone is not available");
11296 }
11297 // Now that all security checks passes, perform the operation as ourselves.
11298 final long identity = Binder.clearCallingIdentity();
11299 try {
11300 return phone.getEquivalentHomePlmns();
11301 } finally {
11302 Binder.restoreCallingIdentity(identity);
11303 }
11304 }
Daniel Bright59e67312020-11-13 11:49:37 -080011305
11306 @Override
11307 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011308 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
joonhunshin4ac60942023-11-15 15:23:39 +000011309 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11310 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
11311 "isRadioInterfaceCapabilitySupported");
11312
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011313 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080011314 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080011315 if (radioInterfaceCapabilities == null) {
11316 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080011317 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011318 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080011319 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011320
Hui Wang641e81c2020-10-12 12:14:23 -070011321 @Override
11322 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
11323 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000011324 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
11325 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11326 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
11327 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11328 Manifest.permission.MODIFY_PHONE_STATE);
joonhunshin4ac60942023-11-15 15:23:39 +000011329
11330 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11331 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest");
11332
Hui Wang641e81c2020-10-12 12:14:23 -070011333 if (DBG) {
11334 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
11335 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
11336 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
11337 }
11338
11339 if (!SubscriptionManager.isValidSubscriptionId(subId)
11340 || appType < TelephonyManager.APPTYPE_UNKNOWN
11341 || appType > TelephonyManager.APPTYPE_ISIM
11342 || nafUrl == null || securityProtocol == null || callback == null) {
11343 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
11344 if (callback != null) {
11345 try {
11346 callback.onAuthenticationFailure(
11347 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
11348 } catch (RemoteException exception) {
11349 log("Fail to notify onAuthenticationFailure due to " + exception);
11350 }
11351 return;
11352 }
11353 }
11354
11355 final long token = Binder.clearCallingIdentity();
11356 try {
11357 getGbaManager(subId).bootstrapAuthenticationRequest(
11358 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011359 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070011360 } finally {
11361 Binder.restoreCallingIdentity(token);
11362 }
11363 }
11364
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011365 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011366 * Attempts to set the radio power state for all phones for thermal reason.
11367 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011368 * requested radio power state will actually be set. See {@link
11369 * PhoneInternalInterface#setRadioPowerForReason} for more details.
11370 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011371 * @param enable {@code true} if trying to turn radio on.
11372 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
11373 * false}.
11374 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011375 private boolean setRadioPowerForThermal(boolean enable) {
11376 boolean isPhoneAvailable = false;
11377 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
11378 Phone phone = PhoneFactory.getPhone(i);
11379 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011380 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011381 isPhoneAvailable = true;
11382 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011383 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011384
11385 // return true if successfully informed the phone object about the thermal radio power
11386 // request.
11387 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011388 }
11389
11390 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011391 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011392 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11393 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11394 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11395 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11396 throw new IllegalArgumentException("modem does not support data throttling");
11397 }
11398
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011399 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11400 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011401 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011402 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11403 }
11404
Sarah Chinecc78c42022-03-31 21:16:48 -070011405 setDataEnabledForReason(
11406 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011407
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011408 if (isDataThrottlingSupported) {
11409 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011410 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011411 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11412 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11413 } else if (thermalMitigationResult
11414 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011415 log("Modem likely does not support data throttling on secondary carrier. Data " +
11416 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11417 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011418 }
11419 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011420 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011421
11422 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011423 }
11424
Jack Nudelman644b91a2021-03-12 14:09:48 -080011425 private static List<String> getThermalMitigationAllowlist(Context context) {
11426 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11427 for (String pckg : context.getResources()
11428 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11429 sThermalMitigationAllowlistedPackages.add(pckg);
11430 }
11431 }
11432
11433 return sThermalMitigationAllowlistedPackages;
11434 }
11435
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011436 private boolean isAnyPhoneInEmergencyState() {
11437 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11438 if (tm.isInEmergencyCall()) {
11439 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11440 return true;
11441 }
11442 for (Phone phone : PhoneFactory.getPhones()) {
11443 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11444 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011445 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11446 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011447 return true;
11448 }
11449 }
11450
11451 return false;
11452 }
11453
Jack Nudelman644b91a2021-03-12 14:09:48 -080011454 /**
11455 * Used by shell commands to add an authorized package name for thermal mitigation.
11456 * @param packageName name of package to be allowlisted
11457 * @param context
11458 */
11459 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11460 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11461 sThermalMitigationAllowlistedPackages.add(packageName);
11462 }
11463
11464 /**
11465 * Used by shell commands to remove an authorized package name for thermal mitigation.
11466 * @param packageName name of package to remove from allowlist
11467 * @param context
11468 */
11469 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11470 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11471 sThermalMitigationAllowlistedPackages.remove(packageName);
11472 }
11473
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011474 /**
11475 * Thermal mitigation request to control functionalities at modem.
11476 *
11477 * @param subId the id of the subscription.
11478 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011479 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011480 *
11481 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11482 */
11483 @Override
11484 @ThermalMitigationResult
11485 public int sendThermalMitigationRequest(
11486 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011487 ThermalMitigationRequest thermalMitigationRequest,
11488 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011489 enforceModifyPermission();
11490
Jack Nudelman644b91a2021-03-12 14:09:48 -080011491 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000011492
11493 enforceTelephonyFeatureWithException(callingPackage,
11494 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest");
11495
Jack Nudelman644b91a2021-03-12 14:09:48 -080011496 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11497 .contains(callingPackage)) {
11498 throw new SecurityException("Calling package must be configured in the device config. "
11499 + "calling package: " + callingPackage);
11500 }
11501
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011502 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11503 final long identity = Binder.clearCallingIdentity();
11504
11505 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11506 try {
11507 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11508 switch (thermalMitigationAction) {
11509 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11510 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011511 handleDataThrottlingRequest(subId,
11512 thermalMitigationRequest.getDataThrottlingRequest(),
11513 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011514 break;
11515 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11516 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11517 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11518 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11519 }
11520
11521 // Ensure that radio is on. If not able to power on due to phone being
11522 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011523 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011524 thermalMitigationResult =
11525 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11526 break;
11527 }
11528
11529 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011530 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011531 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11532 break;
11533 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11534 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11535 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11536 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11537 }
11538
11539 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11540 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011541 Phone phone = getPhone(subId);
11542 if (phone == null) {
11543 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011544 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011545 break;
11546 }
11547
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011548 TelephonyConnectionService service =
11549 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011550 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011551 Log.e(LOG_TAG, "An emergency call is pending");
11552 thermalMitigationResult =
11553 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11554 break;
11555 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011556 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011557 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011558 break;
11559 }
11560 } else {
11561 thermalMitigationResult =
11562 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11563 break;
11564 }
11565
11566 // Turn radio off. If not able to power off due to phone being unavailable,
11567 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011568 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011569 thermalMitigationResult =
11570 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11571 break;
11572 }
11573 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011574 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011575 break;
11576 default:
11577 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11578 + "not exist. Requested action: " + thermalMitigationAction);
11579 }
11580 } catch (IllegalArgumentException e) {
11581 throw e;
11582 } catch (Exception e) {
11583 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11584 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11585 } finally {
11586 Binder.restoreCallingIdentity(identity);
11587 }
11588
11589 if (DBG) {
11590 log("thermalMitigationRequest returning with thermalMitigationResult: "
11591 + thermalMitigationResult);
11592 }
11593
11594 return thermalMitigationResult;
11595 }
Hui Wang641e81c2020-10-12 12:14:23 -070011596
11597 /**
11598 * Set the GbaService Package Name that Telephony will bind to.
11599 *
11600 * @param subId The sim that the GbaService is associated with.
11601 * @param packageName The name of the package to be replaced with.
11602 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11603 */
11604 @Override
11605 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11606 enforceModifyPermission();
11607
11608 final long identity = Binder.clearCallingIdentity();
11609 try {
11610 return getGbaManager(subId).overrideServicePackage(packageName);
11611 } finally {
11612 Binder.restoreCallingIdentity(identity);
11613 }
11614 }
11615
11616 /**
11617 * Return the package name of the currently bound GbaService.
11618 *
11619 * @param subId The sim that the GbaService is associated with.
11620 * @return the package name of the GbaService configuration, null if GBA is not supported.
11621 */
11622 @Override
11623 public String getBoundGbaService(int subId) {
11624 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11625
11626 final long identity = Binder.clearCallingIdentity();
11627 try {
11628 return getGbaManager(subId).getServicePackage();
11629 } finally {
11630 Binder.restoreCallingIdentity(identity);
11631 }
11632 }
11633
11634 /**
11635 * Set the release time for telephony to unbind GbaService.
11636 *
11637 * @param subId The sim that the GbaService is associated with.
11638 * @param interval The release time to unbind GbaService by millisecond.
11639 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11640 */
11641 @Override
11642 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11643 enforceModifyPermission();
11644
11645 final long identity = Binder.clearCallingIdentity();
11646 try {
11647 return getGbaManager(subId).overrideReleaseTime(interval);
11648 } finally {
11649 Binder.restoreCallingIdentity(identity);
11650 }
11651 }
11652
11653 /**
11654 * Return the release time for telephony to unbind GbaService.
11655 *
11656 * @param subId The sim that the GbaService is associated with.
11657 * @return The release time to unbind GbaService by millisecond.
11658 */
11659 @Override
11660 public int getGbaReleaseTime(int subId) {
11661 enforceReadPrivilegedPermission("getGbaReleaseTime");
11662
11663 final long identity = Binder.clearCallingIdentity();
11664 try {
11665 return getGbaManager(subId).getReleaseTime();
11666 } finally {
11667 Binder.restoreCallingIdentity(identity);
11668 }
11669 }
11670
11671 private GbaManager getGbaManager(int subId) {
11672 GbaManager instance = GbaManager.getInstance(subId);
11673 if (instance == null) {
11674 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11675 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11676 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11677 }
11678 return instance;
11679 }
Hui Wang761a6682020-10-31 05:12:53 +000011680
11681 /**
11682 * indicate whether the device and the carrier can support
11683 * RCS VoLTE single registration.
11684 */
11685 @Override
11686 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011687 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11688 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11689 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11690 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011691
11692 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11693 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11694 }
11695
11696 final long identity = Binder.clearCallingIdentity();
11697 try {
11698 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11699 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011700 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11701 if (isCapable != null) {
11702 return isCapable;
11703 }
Hui Wang761a6682020-10-31 05:12:53 +000011704 }
Hui Wang67af90e2021-06-04 16:57:15 -070011705 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11706 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011707 } finally {
11708 Binder.restoreCallingIdentity(identity);
11709 }
11710 }
11711
11712 /**
11713 * Register RCS provisioning callback.
11714 */
11715 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011716 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011717 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011718 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011719 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011720 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11721 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011722
11723 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11724 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11725 }
joonhunshin4ac60942023-11-15 15:23:39 +000011726 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11727 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11728 Binder.getCallingUserHandle())) {
11729 if (!isImsAvailableOnDevice()) {
11730 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11731 "IMS not available on device.");
11732 }
11733 } else {
11734 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11735 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011736 }
11737
11738 final long identity = Binder.clearCallingIdentity();
11739 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011740 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011741 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011742 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11743 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011744 }
Hui Wang761a6682020-10-31 05:12:53 +000011745 } finally {
11746 Binder.restoreCallingIdentity(identity);
11747 }
11748 }
11749
11750 /**
11751 * Unregister RCS provisioning callback.
11752 */
11753 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011754 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011755 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011756 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011757 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011758 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11759 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011760
11761 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11762 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11763 }
joonhunshin4ac60942023-11-15 15:23:39 +000011764
11765 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11766 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11767 Binder.getCallingUserHandle())) {
11768 if (!isImsAvailableOnDevice()) {
11769 // operation failed silently
11770 Rlog.w(LOG_TAG, "IMS not available on device.");
11771 return;
11772 }
11773 } else {
11774 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11775 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11776 "unregisterRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011777 }
11778
11779 final long identity = Binder.clearCallingIdentity();
11780 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011781 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011782 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011783 } finally {
11784 Binder.restoreCallingIdentity(identity);
11785 }
11786 }
11787
11788 /**
11789 * trigger RCS reconfiguration.
11790 */
11791 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011792 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11793 "triggerRcsReconfiguration",
11794 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011795
11796 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11797 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11798 }
joonhunshin4ac60942023-11-15 15:23:39 +000011799 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11800 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11801 Binder.getCallingUserHandle())) {
11802 if (!isImsAvailableOnDevice()) {
11803 // ProvisioningManager can not handle ServiceSpecificException.
11804 // Throw the IllegalStateException and annotate ProvisioningManager.
11805 throw new IllegalStateException("IMS not available on device.");
11806 }
11807 } else {
11808 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11809 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011810 }
11811
11812 final long identity = Binder.clearCallingIdentity();
11813 try {
11814 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11815 } finally {
11816 Binder.restoreCallingIdentity(identity);
11817 }
11818 }
11819
11820 /**
11821 * Provide the client configuration parameters of the RCS application.
11822 */
11823 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011824 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11825 "setRcsClientConfiguration",
11826 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011827
11828 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11829 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11830 }
joonhunshin4ac60942023-11-15 15:23:39 +000011831 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11832 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11833 Binder.getCallingUserHandle())) {
11834 if (!isImsAvailableOnDevice()) {
11835 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11836 "IMS not available on device.");
11837 }
11838 } else {
11839 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11840 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011841 }
11842
11843 final long identity = Binder.clearCallingIdentity();
11844
11845 try {
11846 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11847 if (configBinder == null) {
11848 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011849 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11850 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011851 } else {
11852 configBinder.setRcsClientConfiguration(rcc);
11853 }
joonhunshin3e154242021-09-17 06:33:39 +000011854
11855 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11856 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011857 } catch (RemoteException e) {
11858 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011859 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11860 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011861 } finally {
11862 Binder.restoreCallingIdentity(identity);
11863 }
11864 }
11865
11866 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011867 * Enables or disables the test mode for RCS VoLTE single registration.
11868 */
11869 @Override
11870 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11871 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11872 "setRcsSingleRegistrationTestModeEnabled");
11873
11874 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11875 }
11876
11877 /**
11878 * Gets the test mode for RCS VoLTE single registration.
11879 */
11880 @Override
11881 public boolean getRcsSingleRegistrationTestModeEnabled() {
11882 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11883 "getRcsSingleRegistrationTestModeEnabled");
11884
11885 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11886 }
11887
11888 /**
Hui Wang761a6682020-10-31 05:12:53 +000011889 * Overrides the config of RCS VoLTE single registration enabled for the device.
11890 */
11891 @Override
11892 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11893 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11894 "setDeviceSingleRegistrationEnabledOverride");
11895 enforceModifyPermission();
11896
11897 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11898 : Boolean.parseBoolean(enabledStr);
11899 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011900 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011901 }
11902
11903 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011904 * Sends a device to device communication message. Only usable via shell.
11905 * @param message message to send.
11906 * @param value message value.
11907 */
11908 @Override
11909 public void sendDeviceToDeviceMessage(int message, int value) {
11910 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011911 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011912 enforceModifyPermission();
11913
11914 final long identity = Binder.clearCallingIdentity();
11915 try {
11916 TelephonyConnectionService service =
11917 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11918 if (service == null) {
11919 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11920 return;
11921 }
11922 service.sendTestDeviceToDeviceMessage(message, value);
11923 } finally {
11924 Binder.restoreCallingIdentity(identity);
11925 }
11926 }
11927
Tyler Gunnbabbda02021-02-10 11:05:02 -080011928 /**
11929 * Sets the specified device to device transport active.
11930 * @param transport The transport to set active.
11931 */
11932 @Override
11933 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11934 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11935 "setActiveDeviceToDeviceTransport");
11936 enforceModifyPermission();
11937
11938 final long identity = Binder.clearCallingIdentity();
11939 try {
11940 TelephonyConnectionService service =
11941 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11942 if (service == null) {
11943 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11944 return;
11945 }
11946 service.setActiveDeviceToDeviceTransport(transport);
11947 } finally {
11948 Binder.restoreCallingIdentity(identity);
11949 }
11950 }
Tyler Gunn92479152021-01-20 16:30:10 -080011951
Tyler Gunnd4339262021-05-03 14:46:49 -070011952 @Override
11953 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11954 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11955 "setDeviceToDeviceForceEnabled");
11956
11957 final long identity = Binder.clearCallingIdentity();
11958 try {
11959 Arrays.stream(PhoneFactory.getPhones()).forEach(
11960 p -> {
11961 Phone thePhone = p.getImsPhone();
11962 if (thePhone != null && thePhone instanceof ImsPhone) {
11963 ImsPhone imsPhone = (ImsPhone) thePhone;
11964 CallTracker tracker = imsPhone.getCallTracker();
11965 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11966 ImsPhoneCallTracker imsPhoneCallTracker =
11967 (ImsPhoneCallTracker) tracker;
11968 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11969 }
11970 }
11971 }
11972 );
11973 } finally {
11974 Binder.restoreCallingIdentity(identity);
11975 }
11976 }
11977
Tyler Gunn92479152021-01-20 16:30:10 -080011978 /**
Hui Wang761a6682020-10-31 05:12:53 +000011979 * Gets the config of RCS VoLTE single registration enabled for the device.
11980 */
11981 @Override
11982 public boolean getDeviceSingleRegistrationEnabled() {
11983 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11984 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11985 }
11986
11987 /**
11988 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11989 */
11990 @Override
11991 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11992 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11993 "setCarrierSingleRegistrationEnabledOverride");
11994 enforceModifyPermission();
11995
11996 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11997 : Boolean.parseBoolean(enabledStr);
11998 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11999 subId, enabled);
12000 }
12001
12002 /**
12003 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
12004 */
12005 @Override
12006 public boolean getCarrierSingleRegistrationEnabled(int subId) {
12007 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
12008 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
12009 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080012010
12011 /**
Hui Wangb647abe2021-02-26 09:33:38 -080012012 * Overrides the ims feature validation result
12013 */
12014 @Override
12015 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
12016 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12017 "setImsFeatureValidationOverride");
12018
12019 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
12020 : Boolean.parseBoolean(enabledStr);
12021 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
12022 subId, enabled);
12023 }
12024
12025 /**
12026 * Gets the ims feature validation override value
12027 */
12028 @Override
12029 public boolean getImsFeatureValidationOverride(int subId) {
12030 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12031 "getImsFeatureValidationOverride");
12032 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
12033 }
12034
12035 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080012036 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
12037 * their mobile plan.
12038 */
12039 @Override
12040 public String getMobileProvisioningUrl() {
12041 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
12042 final long identity = Binder.clearCallingIdentity();
12043 try {
12044 return getDefaultPhone().getMobileProvisioningUrl();
12045 } finally {
12046 Binder.restoreCallingIdentity(identity);
12047 }
12048 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012049
James.cf Linbcdf8b32021-01-14 16:44:13 +080012050 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080012051 * Get the EAB contact from the EAB database.
12052 */
12053 @Override
12054 public String getContactFromEab(String contact) {
12055 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
12056 enforceModifyPermission();
12057 final long identity = Binder.clearCallingIdentity();
12058 try {
12059 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
12060 } finally {
12061 Binder.restoreCallingIdentity(identity);
12062 }
12063 }
12064
12065 /**
Calvin Pana1434322021-07-01 19:27:01 +080012066 * Get the EAB capability from the EAB database.
12067 */
12068 @Override
12069 public String getCapabilityFromEab(String contact) {
12070 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
12071 enforceModifyPermission();
12072 final long identity = Binder.clearCallingIdentity();
12073 try {
12074 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
12075 } finally {
12076 Binder.restoreCallingIdentity(identity);
12077 }
12078 }
12079
12080 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080012081 * Remove the EAB contacts from the EAB database.
12082 */
12083 @Override
12084 public int removeContactFromEab(int subId, String contacts) {
12085 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
12086 enforceModifyPermission();
12087 final long identity = Binder.clearCallingIdentity();
12088 try {
12089 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
12090 } finally {
12091 Binder.restoreCallingIdentity(identity);
12092 }
12093 }
12094
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012095 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080012096 public boolean getDeviceUceEnabled() {
12097 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
12098 final long identity = Binder.clearCallingIdentity();
12099 try {
12100 return mApp.getDeviceUceEnabled();
12101 } finally {
12102 Binder.restoreCallingIdentity(identity);
12103 }
12104 }
12105
12106 @Override
12107 public void setDeviceUceEnabled(boolean isEnabled) {
12108 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
12109 final long identity = Binder.clearCallingIdentity();
12110 try {
12111 mApp.setDeviceUceEnabled(isEnabled);
12112 } finally {
12113 Binder.restoreCallingIdentity(identity);
12114 }
12115 }
12116
Brad Ebinger14d467f2021-02-12 06:18:28 +000012117 /**
12118 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
12119 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12120 */
12121 // Used for SHELL command only right now.
12122 @Override
12123 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
12124 List<String> featureTags) {
12125 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12126 "addUceRegistrationOverrideShell");
12127 final long identity = Binder.clearCallingIdentity();
12128 try {
12129 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
12130 new ArraySet<>(featureTags));
12131 } catch (ImsException e) {
12132 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12133 } finally {
12134 Binder.restoreCallingIdentity(identity);
12135 }
12136 }
12137
12138 /**
12139 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
12140 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12141 */
12142 // Used for SHELL command only right now.
12143 @Override
12144 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
12145 List<String> featureTags) {
12146 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12147 "removeUceRegistrationOverrideShell");
12148 final long identity = Binder.clearCallingIdentity();
12149 try {
12150 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
12151 new ArraySet<>(featureTags));
12152 } catch (ImsException e) {
12153 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12154 } finally {
12155 Binder.restoreCallingIdentity(identity);
12156 }
12157 }
12158
12159 /**
12160 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
12161 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12162 */
12163 // Used for SHELL command only right now.
12164 @Override
12165 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
12166 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12167 "clearUceRegistrationOverrideShell");
12168 final long identity = Binder.clearCallingIdentity();
12169 try {
12170 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
12171 } catch (ImsException e) {
12172 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12173 } finally {
12174 Binder.restoreCallingIdentity(identity);
12175 }
12176 }
12177
12178 /**
12179 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12180 */
12181 // Used for SHELL command only right now.
12182 @Override
12183 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
12184 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12185 "getLatestRcsContactUceCapabilityShell");
12186 final long identity = Binder.clearCallingIdentity();
12187 try {
12188 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
12189 } catch (ImsException e) {
12190 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12191 } finally {
12192 Binder.restoreCallingIdentity(identity);
12193 }
12194 }
12195
12196 /**
12197 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
12198 * device does not have an active PUBLISH.
12199 */
12200 // Used for SHELL command only right now.
12201 @Override
12202 public String getLastUcePidfXmlShell(int subId) {
12203 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
12204 final long identity = Binder.clearCallingIdentity();
12205 try {
12206 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
12207 } catch (ImsException e) {
12208 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12209 } finally {
12210 Binder.restoreCallingIdentity(identity);
12211 }
12212 }
12213
James.cf Line8713a42021-04-29 16:04:26 +080012214 /**
12215 * Remove UCE requests cannot be sent to the network status.
12216 */
12217 // Used for SHELL command only right now.
12218 @Override
12219 public boolean removeUceRequestDisallowedStatus(int subId) {
12220 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
12221 final long identity = Binder.clearCallingIdentity();
12222 try {
12223 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
12224 } catch (ImsException e) {
12225 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12226 } finally {
12227 Binder.restoreCallingIdentity(identity);
12228 }
12229 }
12230
James.cf Lin18bb9002021-05-25 01:37:38 +080012231 /**
12232 * Remove UCE requests cannot be sent to the network status.
12233 */
12234 // Used for SHELL command only.
12235 @Override
12236 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
12237 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
12238 final long identity = Binder.clearCallingIdentity();
12239 try {
12240 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
12241 } catch (ImsException e) {
12242 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12243 } finally {
12244 Binder.restoreCallingIdentity(identity);
12245 }
12246 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000012247
James.cf Lin4b784aa2021-01-31 03:25:15 +080012248 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012249 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12250 String callingPackage) {
12251 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12252 mApp, subId, "setSignalStrengthUpdateRequest");
12253
joonhunshin4ac60942023-11-15 15:23:39 +000012254 enforceTelephonyFeatureWithException(callingPackage,
12255 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest");
12256
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012257 final int callingUid = Binder.getCallingUid();
12258 // Verify that tha callingPackage belongs to the calling UID
12259 mApp.getSystemService(AppOpsManager.class)
12260 .checkPackage(callingUid, callingPackage);
12261
Rambo Wang3607f502021-02-01 21:51:40 -080012262 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012263
12264 final long identity = Binder.clearCallingIdentity();
12265 try {
12266 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
12267 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12268
12269 if (result instanceof IllegalStateException) {
12270 throw (IllegalStateException) result;
12271 }
12272 } finally {
12273 Binder.restoreCallingIdentity(identity);
12274 }
12275 }
12276
12277 @Override
12278 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12279 String callingPackage) {
12280 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12281 mApp, subId, "clearSignalStrengthUpdateRequest");
12282
joonhunshin4ac60942023-11-15 15:23:39 +000012283 enforceTelephonyFeatureWithException(callingPackage,
12284 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest");
12285
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012286 final int callingUid = Binder.getCallingUid();
12287 // Verify that tha callingPackage belongs to the calling UID
12288 mApp.getSystemService(AppOpsManager.class)
12289 .checkPackage(callingUid, callingPackage);
12290
12291 final long identity = Binder.clearCallingIdentity();
12292 try {
12293 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
12294 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12295
12296 if (result instanceof IllegalStateException) {
12297 throw (IllegalStateException) result;
12298 }
12299 } finally {
12300 Binder.restoreCallingIdentity(identity);
12301 }
12302 }
12303
Rambo Wang3607f502021-02-01 21:51:40 -080012304 private static void validateSignalStrengthUpdateRequest(Context context,
12305 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wangb7a95a42024-03-07 04:57:29 +000012306 if (TelephonyPermissions.isSystemOrPhone(callingUid)) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012307 // phone/system process do not have further restriction on request
12308 return;
12309 }
12310
12311 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080012312 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012313 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080012314 context.enforceCallingOrSelfPermission(
12315 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
12316 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012317 }
12318
12319 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000012320 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012321 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012322 || info.isEnabled()) {
12323 throw new IllegalArgumentException(
12324 "Only system can set hide fields in SignalThresholdInfo");
12325 }
12326
12327 // Thresholds length for each RAN need in range. This has been validated in
12328 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
12329 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
12330 final int[] thresholds = info.getThresholds();
12331 Objects.requireNonNull(thresholds);
12332 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
12333 || thresholds.length
12334 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
12335 throw new IllegalArgumentException(
12336 "thresholds length is out of range: " + thresholds.length);
12337 }
12338 }
12339 }
SongFerngWang8236caa2021-01-17 21:51:44 +080012340
12341 /**
12342 * Gets the current phone capability.
12343 *
12344 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
12345 * @return the PhoneCapability which describes the data connection capability of modem.
12346 * It's used to evaluate possible phone config change, for example from single
12347 * SIM device to multi-SIM device.
12348 */
12349 @Override
12350 public PhoneCapability getPhoneCapability() {
12351 enforceReadPrivilegedPermission("getPhoneCapability");
joonhunshin4ac60942023-11-15 15:23:39 +000012352
12353 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12354 PackageManager.FEATURE_TELEPHONY, "getPhoneCapability");
12355
SongFerngWang8236caa2021-01-17 21:51:44 +080012356 final long identity = Binder.clearCallingIdentity();
12357 try {
12358 return mPhoneConfigurationManager.getCurrentPhoneCapability();
12359 } finally {
12360 Binder.restoreCallingIdentity(identity);
12361 }
12362 }
Michele Berionne5e411512020-11-13 02:36:59 +000012363
12364 /**
12365 * Prepare TelephonyManager for an unattended reboot. The reboot is
12366 * required to be done shortly after the API is invoked.
12367 */
12368 @Override
12369 @TelephonyManager.PrepareUnattendedRebootResult
12370 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012371 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000012372 enforceRebootPermission();
12373
joonhunshin4ac60942023-11-15 15:23:39 +000012374 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12375 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot");
12376
Michele Berionne5e411512020-11-13 02:36:59 +000012377 final long identity = Binder.clearCallingIdentity();
12378 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012379 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000012380 } finally {
12381 Binder.restoreCallingIdentity(identity);
12382 }
12383 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012384
12385 /**
12386 * Request to get the current slicing configuration including URSP rules and
12387 * NSSAIs (configured, allowed and rejected).
12388 *
12389 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
12390 */
12391 @Override
12392 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000012393 TelephonyPermissions
12394 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
12395 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012396
joonhunshin4ac60942023-11-15 15:23:39 +000012397 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12398 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
12399 "getSlicingConfig");
12400
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012401 final long identity = Binder.clearCallingIdentity();
12402 try {
12403 Phone phone = getDefaultPhone();
12404 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
12405 } finally {
12406 Binder.restoreCallingIdentity(identity);
12407 }
12408 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012409
12410 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070012411 * Check whether the given premium capability is available for purchase from the carrier.
12412 *
12413 * @param capability The premium capability to check.
12414 * @param subId The subId to check the premium capability for.
12415 *
12416 * @return Whether the given premium capability is available to purchase.
12417 */
12418 @Override
12419 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
12420 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12421 mApp, "isPremiumCapabilityAvailableForPurchase")) {
12422 log("Premium capability "
12423 + TelephonyManager.convertPremiumCapabilityToString(capability)
12424 + " is not available for purchase due to missing permissions.");
12425 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
12426 + "permission READ_BASIC_PHONE_STATE.");
12427 }
12428
joonhunshin4ac60942023-11-15 15:23:39 +000012429 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12430 PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase");
12431
Sarah Chin2ec39f62022-08-31 17:03:26 -070012432 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080012433 if (phone == null) {
12434 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12435 return false;
12436 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012437 final long identity = Binder.clearCallingIdentity();
12438 try {
Sarah Chincc5446f2023-10-23 17:57:19 -070012439 return SlicePurchaseController.getInstance(phone, mFeatureFlags)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012440 .isPremiumCapabilityAvailableForPurchase(capability);
12441 } finally {
12442 Binder.restoreCallingIdentity(identity);
12443 }
12444 }
12445
12446 /**
12447 * Purchase the given premium capability from the carrier.
12448 *
12449 * @param capability The premium capability to purchase.
12450 * @param callback The result of the purchase request.
12451 * @param subId The subId to purchase the premium capability for.
12452 */
12453 @Override
12454 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12455 log("purchasePremiumCapability: capability="
12456 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12457 + getCurrentPackageName());
12458
12459 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12460 mApp, "purchasePremiumCapability")) {
12461 log("purchasePremiumCapability "
12462 + TelephonyManager.convertPremiumCapabilityToString(capability)
12463 + " failed due to missing permissions.");
12464 throw new SecurityException("purchasePremiumCapability requires permission "
12465 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012466 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12467 mApp, "purchasePremiumCapability")) {
12468 log("purchasePremiumCapability "
12469 + TelephonyManager.convertPremiumCapabilityToString(capability)
12470 + " failed due to missing permissions.");
12471 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012472 }
12473
joonhunshin4ac60942023-11-15 15:23:39 +000012474 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12475 PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability");
12476
Sarah Chin2ec39f62022-08-31 17:03:26 -070012477 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012478 if (phone == null) {
12479 try {
12480 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12481 callback.accept(result);
12482 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12483 } catch (RemoteException e) {
12484 String logStr = "Purchase premium capability "
12485 + TelephonyManager.convertPremiumCapabilityToString(capability)
12486 + " failed due to RemoteException handling null phone: " + e;
12487 if (DBG) log(logStr);
12488 AnomalyReporter.reportAnomaly(
12489 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12490 }
12491 return;
12492 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012493
12494 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012495 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012496 callingProcess = mApp.getPackageManager().getApplicationInfo(
12497 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070012498 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012499 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012500 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012501
12502 boolean isVisible = false;
12503 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12504 if (am != null) {
12505 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12506 if (processes != null) {
12507 for (ActivityManager.RunningAppProcessInfo process : processes) {
12508 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070012509 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080012510 if (process.processName.equals(callingProcess) && process.importance
12511 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12512 isVisible = true;
12513 break;
12514 }
12515 }
12516 }
12517 }
12518
12519 if (!isVisible) {
12520 try {
12521 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12522 callback.accept(result);
12523 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12524 } catch (RemoteException e) {
12525 String logStr = "Purchase premium capability "
12526 + TelephonyManager.convertPremiumCapabilityToString(capability)
12527 + " failed due to RemoteException handling background application: " + e;
12528 if (DBG) log(logStr);
12529 AnomalyReporter.reportAnomaly(
12530 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12531 }
12532 return;
12533 }
12534
Sarah Chin71b3a852022-09-28 15:54:19 -070012535 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012536 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012537 }
12538
12539 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012540 * Register an IMS connection state callback
12541 */
12542 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012543 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12544 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012545 if (feature == ImsFeature.FEATURE_MMTEL) {
12546 // ImsMmTelManager
12547 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12548 TelephonyPermissions
12549 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12550 mApp, subId, "registerImsStateCallback");
12551 } else if (feature == ImsFeature.FEATURE_RCS) {
12552 // ImsRcsManager or SipDelegateManager
12553 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12554 Binder.getCallingUid(), "registerImsStateCallback",
12555 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12556 Manifest.permission.READ_PRECISE_PHONE_STATE,
12557 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12558 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12559 }
12560
12561 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12562 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12563 "IMS not available on device.");
12564 }
12565
12566 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12567 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12568 }
12569
12570 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12571 if (controller == null) {
12572 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12573 "IMS not available on device.");
12574 }
12575
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012576 if (callingPackage == null) {
12577 callingPackage = getCurrentPackageName();
12578 }
12579
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012580 final long token = Binder.clearCallingIdentity();
12581 try {
12582 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012583 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012584 } catch (ImsException e) {
12585 throw new ServiceSpecificException(e.getCode());
12586 } finally {
12587 Binder.restoreCallingIdentity(token);
12588 }
12589 }
12590
12591 /**
12592 * Unregister an IMS connection state callback
12593 */
12594 @Override
12595 public void unregisterImsStateCallback(IImsStateCallback cb) {
12596 final long token = Binder.clearCallingIdentity();
12597 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12598 if (controller == null) {
12599 return;
12600 }
12601 try {
12602 controller.unregisterImsStateCallback(cb);
12603 } finally {
12604 Binder.restoreCallingIdentity(token);
12605 }
12606 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012607
12608 /**
12609 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12610 *
12611 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012612 * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012613 * SecurityException.
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012614 *
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012615 * If there is current registered network this value will be same as the registered cell
12616 * identity. If the device goes out of service the previous cell identity is cached and
12617 * will be returned. If the cache age of the Cell identity is more than 24 hours
12618 * it will be cleared and null will be returned.
12619 *
12620 */
12621 @Override
12622 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12623 String callingFeatureId) {
12624 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12625 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12626 LocationAccessPolicy.checkLocationPermission(mApp,
12627 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12628 .setCallingPackage(callingPackage)
12629 .setCallingFeatureId(callingFeatureId)
12630 .setCallingPid(Binder.getCallingPid())
12631 .setCallingUid(Binder.getCallingUid())
12632 .setMethod("getLastKnownCellIdentity")
12633 .setLogAsInfo(true)
12634 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12635 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12636 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12637 .build());
12638
12639 boolean hasFinePermission =
12640 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12641 if (!hasFinePermission
12642 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12643 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012644 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012645 }
12646
12647 final long identity = Binder.clearCallingIdentity();
12648 try {
Ling Mac28f0212023-03-24 16:07:15 -070012649 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012650 if (sst == null) return null;
12651 return sst.getLastKnownCellIdentity();
12652 } finally {
12653 Binder.restoreCallingIdentity(identity);
12654 }
12655 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012656
jimsun3b9ccac2021-10-26 15:01:23 +080012657 /**
12658 * Sets the modem service class Name that Telephony will bind to.
12659 *
12660 * @param serviceName The class name of the modem service.
12661 * @return true if the operation is succeed, otherwise false.
12662 */
12663 public boolean setModemService(String serviceName) {
12664 Log.d(LOG_TAG, "setModemService - " + serviceName);
12665 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12666 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012667 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12668 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012669 return mPhoneConfigurationManager.setModemService(serviceName);
12670 }
12671
12672 /**
12673 * Return the class name of the currently bounded modem service.
12674 *
12675 * @return the class name of the modem service.
12676 */
12677 public String getModemService() {
12678 String result;
12679 Log.d(LOG_TAG, "getModemService");
12680 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12681 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012682 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012683 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12684 "getModemService");
12685 result = mPhoneConfigurationManager.getModemService();
12686 Log.d(LOG_TAG, "result = " + result);
12687 return result;
12688 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012689
Hakjun Choi3ee81112023-12-19 15:40:58 +000012690 /**
12691 * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources,
12692 * including carrier config, entitlement server, and config update.
12693 *
12694 * @param subId subId The subscription ID of the carrier.
12695 *
12696 * @return List of plmns for carrier satellite service. If no plmn is available, empty list will
12697 * be returned.
12698 *
12699 * @throws SecurityException if the caller doesn't have the required permission.
12700 */
Hakjun Choi74c16be2024-01-19 08:18:09 +000012701 @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) {
12702 enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier");
Hakjun Choi3ee81112023-12-19 15:40:58 +000012703 final long identity = Binder.clearCallingIdentity();
12704 try {
Hakjun Choi74c16be2024-01-19 08:18:09 +000012705 return mSatelliteController.getSatellitePlmnsForCarrier(subId);
Hakjun Choi3ee81112023-12-19 15:40:58 +000012706 } finally {
12707 Binder.restoreCallingIdentity(identity);
12708 }
12709 }
12710
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012711 @Override
12712 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12713 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12714 mApp.enforceCallingOrSelfPermission(
12715 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12716 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12717
12718 final long identity = Binder.clearCallingIdentity();
12719 try {
12720 Phone phone = getPhone(subId);
12721 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012722 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12723 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012724 phone.setVoiceServiceStateOverride(hasService);
12725 } finally {
12726 Binder.restoreCallingIdentity(identity);
12727 }
12728 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012729
12730 /**
12731 * set removable eSIM as default eUICC.
12732 *
12733 * @hide
12734 */
12735 @Override
12736 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12737 enforceModifyPermission();
12738 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12739
12740 final long identity = Binder.clearCallingIdentity();
12741 try {
12742 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12743 } finally {
12744 Binder.restoreCallingIdentity(identity);
12745 }
12746 }
12747
12748 /**
12749 * Returns whether the removable eSIM is default eUICC or not.
12750 *
12751 * @hide
12752 */
12753 @Override
12754 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12755 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12756 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12757
12758 final long identity = Binder.clearCallingIdentity();
12759 try {
12760 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12761 } finally {
12762 Binder.restoreCallingIdentity(identity);
12763 }
12764 }
12765
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012766 /**
12767 * Get the component name of the default app to direct respond-via-message intent for the
12768 * user associated with this subscription, update the cache if there is no respond-via-message
12769 * application currently configured for this user.
12770 * @return component name of the app and class to direct Respond Via Message intent to, or
12771 * {@code null} if the functionality is not supported.
12772 * @hide
12773 */
12774 @Override
12775 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12776 boolean updateIfNeeded) {
12777 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012778
joonhunshin4ac60942023-11-15 15:23:39 +000012779 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12780 PackageManager.FEATURE_TELEPHONY_MESSAGING,
12781 "getDefaultRespondViaMessageApplication");
12782
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012783 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12784
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012785 UserHandle userHandle = null;
12786 final long identity = Binder.clearCallingIdentity();
12787 try {
12788 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12789 } finally {
12790 Binder.restoreCallingIdentity(identity);
12791 }
12792 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12793 updateIfNeeded, userHandle);
12794 }
Jack Yuf5badd92022-12-08 00:50:53 -080012795
12796 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012797 * Set whether the device is able to connect with null ciphering or integrity
12798 * algorithms. This is a global setting and will apply to all active subscriptions
12799 * and all new subscriptions after this.
12800 *
12801 * @param enabled when true, null cipher and integrity algorithms are allowed.
12802 * @hide
12803 */
12804 @Override
12805 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12806 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12807 enforceModifyPermission();
12808 checkForNullCipherAndIntegritySupport();
12809
12810 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12811 // for listening to these preference changes and applying them immediately.
12812 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12813 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12814 editor.apply();
12815
12816 for (Phone phone: PhoneFactory.getPhones()) {
12817 phone.handleNullCipherEnabledChange();
12818 }
12819 }
12820
12821
12822 /**
12823 * Get whether the device is able to connect with null ciphering or integrity
12824 * algorithms. Note that this retrieves the phone-global preference and not
12825 * the state of the radio.
12826 *
12827 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12828 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12829 * version for this feature.
12830 * @hide
12831 */
12832 @Override
12833 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12834 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12835 enforceReadPermission();
12836 checkForNullCipherAndIntegritySupport();
12837 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12838 }
12839
12840 private void checkForNullCipherAndIntegritySupport() {
12841 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12842 throw new UnsupportedOperationException(
12843 "Null cipher and integrity operations require HAL 2.1 or above");
12844 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012845 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12846 throw new UnsupportedOperationException(
12847 "Null cipher and integrity operations unsupported by modem");
12848 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012849 }
12850
Gil Cukierman06403e12023-11-29 16:33:03 +000012851 private void checkForIdentifierDisclosureNotificationSupport() {
12852 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) {
12853 throw new UnsupportedOperationException(
12854 "Cellular identifier disclosure transparency operations require HAL 2.2 or "
12855 + "above");
12856 }
12857 if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) {
12858 throw new UnsupportedOperationException(
12859 "Cellular identifier disclosure transparency operations unsupported by modem");
12860 }
12861 }
12862
Michael Groover826b71d2023-12-21 22:08:06 -060012863 private void checkForNullCipherNotificationSupport() {
12864 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) {
12865 throw new UnsupportedOperationException(
12866 "Null cipher notification operations require HAL 2.2 or above");
12867 }
12868 if (!getDefaultPhone().isNullCipherNotificationSupported()) {
12869 throw new UnsupportedOperationException(
12870 "Null cipher notification operations unsupported by modem");
12871 }
12872 }
12873
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012874 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012875 * Get the SIM state for the slot index.
12876 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12877 *
12878 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12879 */
12880 @Override
12881 @SimState
12882 public int getSimStateForSlotIndex(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +000012883 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12884 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex");
12885
Jack Yuf5badd92022-12-08 00:50:53 -080012886 IccCardConstants.State simState;
12887 if (slotIndex < 0) {
12888 simState = IccCardConstants.State.UNKNOWN;
12889 } else {
12890 Phone phone = null;
12891 try {
12892 phone = PhoneFactory.getPhone(slotIndex);
12893 } catch (IllegalStateException e) {
12894 // ignore
12895 }
12896 if (phone == null) {
12897 simState = IccCardConstants.State.UNKNOWN;
12898 } else {
12899 IccCard icc = phone.getIccCard();
12900 if (icc == null) {
12901 simState = IccCardConstants.State.UNKNOWN;
12902 } else {
12903 simState = icc.getState();
12904 }
12905 }
12906 }
12907 return simState.ordinal();
12908 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012909
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012910 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
12911 boolean enableLogcat,
12912 long logcatStartTimestampMillis, boolean enableTelecomDump,
12913 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012914 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012915 TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder =
12916 new TelephonyManager.EmergencyCallDiagnosticData.Builder();
12917 ecdDataBuilder
12918 .setTelecomDumpsysCollectionEnabled(enableTelecomDump)
12919 .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012920 if (enableLogcat) {
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012921 ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012922 }
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012923 TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build();
12924 Log.d(LOG_TAG, "persisting with Params " + ecdData.toString());
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012925 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
12926 Executors.newCachedThreadPool(), db,
12927 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012928 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012929 }
12930
12931 /**
12932 * Request telephony to persist state for debugging emergency call failures.
12933 *
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012934 * @param dropboxTag Tag to use when persisting data to dropbox service.
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012935 * @param enableLogcat whether to collect logcat output
12936 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
12937 * @param enableTelecomDump whether to collect telecom dumpsys
12938 * @param enableTelephonyDump whether to collect telephony dumpsys
12939 */
12940 @Override
12941 @RequiresPermission(android.Manifest.permission.DUMP)
12942 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
12943 long logcatStartTimestampMillis, boolean enableTelecomDump,
12944 boolean enableTelephonyDump) {
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -080012945 // Verify that the caller has READ_DROPBOX_DATA permission.
12946 if (mTelecomFeatureFlags.telecomResolveHiddenDependencies()
12947 && Flags.enableReadDropboxPermission()) {
12948 mApp.enforceCallingPermission(permission.READ_DROPBOX_DATA,
12949 "persistEmergencyCallDiagnosticData");
12950 } else {
12951 // Otherwise, enforce legacy permission.
12952 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
12953 "persistEmergencyCallDiagnosticData");
12954 }
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012955 final long identity = Binder.clearCallingIdentity();
12956 try {
12957 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
12958 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
12959
12960 } finally {
12961 Binder.restoreCallingIdentity(identity);
12962 }
12963 }
12964
Hui Wang9b5793a2022-12-05 14:38:06 -060012965 /**
12966 * Get current cell broadcast ranges.
12967 */
12968 @Override
12969 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12970 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12971 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12972 "getCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012973
12974 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12975 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges");
12976
Hui Wang9b5793a2022-12-05 14:38:06 -060012977 final long identity = Binder.clearCallingIdentity();
12978 try {
12979 return getPhone(subId).getCellBroadcastIdRanges();
12980 } finally {
12981 Binder.restoreCallingIdentity(identity);
12982 }
12983 }
12984
12985 /**
12986 * Set reception of cell broadcast messages with the list of the given ranges
12987 *
12988 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12989 */
12990 @Override
12991 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12992 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12993 @Nullable IIntegerConsumer callback) {
12994 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12995 "setCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012996
12997 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12998 PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges");
12999
Hui Wang9b5793a2022-12-05 14:38:06 -060013000 final long identity = Binder.clearCallingIdentity();
13001 try {
13002 Phone phone = getPhoneFromSubId(subId);
13003 if (DBG) {
13004 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
13005 }
13006 phone.setCellBroadcastIdRanges(ranges, result -> {
13007 if (callback != null) {
13008 try {
13009 callback.accept(result);
13010 } catch (RemoteException e) {
13011 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
13012 }
13013 }
13014 });
13015 } finally {
13016 Binder.restoreCallingIdentity(identity);
13017 }
13018 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000013019
13020 /**
13021 * Returns whether the device supports the domain selection service.
13022 *
13023 * @return {@code true} if the device supports the domain selection service.
13024 */
13025 @Override
13026 public boolean isDomainSelectionSupported() {
13027 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
13028 "isDomainSelectionSupported");
13029
13030 final long identity = Binder.clearCallingIdentity();
13031 try {
13032 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
13033 } finally {
13034 Binder.restoreCallingIdentity(identity);
13035 }
13036 }
arunvoddud5c6ce02022-12-11 06:03:12 +000013037
13038 /**
Hunsuk Choi9c69a802024-04-11 20:39:23 +000013039 * Returns whether the AOSP domain selection service is supported.
13040 *
13041 * @return {@code true} if the AOSP domain selection service is supported,
13042 * {@code false} otherwise.
13043 */
13044 @Override
13045 public boolean isAospDomainSelectionService() {
13046 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
13047 "isAospDomainSelectionService");
13048
13049 final long identity = Binder.clearCallingIdentity();
13050 try {
13051 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13052 String dssComponentName = mApp.getResources().getString(
13053 R.string.config_domain_selection_service_component_name);
13054 ComponentName componentName = ComponentName.createRelative(mApp.getPackageName(),
13055 TelephonyDomainSelectionService.class.getName());
13056 Log.i(LOG_TAG, "isAospDomainSelectionService dss=" + dssComponentName
13057 + ", aosp=" + componentName.flattenToString());
13058 return TextUtils.equals(componentName.flattenToString(), dssComponentName);
13059 }
13060 } finally {
13061 Binder.restoreCallingIdentity(identity);
13062 }
13063 return false;
13064 }
13065
13066 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013067 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
13068 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
13069 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080013070 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013071 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chinabf081b2023-03-09 23:00:57 -080013072 * @param enableSatellite {@code true} to enable the satellite modem and
13073 * {@code false} to disable.
13074 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
Thomas Nguyena8062672024-02-05 14:18:19 -080013075 * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise.
Sarah Chinabf081b2023-03-09 23:00:57 -080013076 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080013077 *
13078 * @throws SecurityException if the caller doesn't have the required permission.
13079 */
13080 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013081 public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode,
Thomas Nguyena8062672024-02-05 14:18:19 -080013082 boolean isEmergency, @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013083 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013084 if (enableSatellite) {
13085 ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) {
13086 @Override
13087 protected void onReceiveResult(int resultCode, Bundle resultData) {
13088 Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode
13089 + ", resultData=" + resultData);
13090 boolean isAllowed = false;
13091 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(
13092 callback::accept);
13093 if (resultCode == SATELLITE_RESULT_SUCCESS) {
13094 if (resultData != null
13095 && resultData.containsKey(KEY_SATELLITE_COMMUNICATION_ALLOWED)) {
13096 isAllowed = resultData.getBoolean(KEY_SATELLITE_COMMUNICATION_ALLOWED);
13097 } else {
13098 loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist.");
13099 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013100 } else {
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013101 result.accept(resultCode);
13102 return;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013103 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013104 if (isAllowed) {
13105 mSatelliteController.requestSatelliteEnabled(
Hyosun Kimab304792024-03-29 09:18:03 +000013106 subId, enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013107 } else {
13108 result.accept(SATELLITE_RESULT_ACCESS_BARRED);
13109 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013110 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013111 };
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013112 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013113 subId, resultReceiver);
13114 } else {
13115 // No need to check if satellite is allowed at current location when disabling satellite
13116 mSatelliteController.requestSatelliteEnabled(
Hyosun Kimab304792024-03-29 09:18:03 +000013117 subId, enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013118 }
Sarah Chin503828c2023-02-01 23:54:20 -080013119 }
13120
13121 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013122 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080013123 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013124 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013125 * @param result The result receiver that returns whether the satellite modem is enabled
13126 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013127 *
13128 * @throws SecurityException if the caller doesn't have the required permission.
13129 */
13130 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013131 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
13132 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013133 mSatelliteController.requestIsSatelliteEnabled(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013134 }
13135
13136 /**
Sarah Chin43457982023-02-15 17:50:38 -080013137 * Request to get whether the satellite service demo mode is enabled.
13138 *
13139 * @param subId The subId of the subscription to check whether the satellite demo mode
13140 * is enabled for.
13141 * @param result The result receiver that returns whether the satellite demo mode is enabled
13142 * if the request is successful or an error code if the request failed.
13143 *
13144 * @throws SecurityException if the caller doesn't have the required permission.
13145 */
13146 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013147 public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
13148 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
13149 mSatelliteController.requestIsDemoModeEnabled(subId, result);
Sarah Chin43457982023-02-15 17:50:38 -080013150 }
13151
13152 /**
Thomas Nguyena8062672024-02-05 14:18:19 -080013153 * Request to get whether the satellite service is enabled with emergency mode.
13154 *
13155 * @param subId The subId of the subscription to check whether the satellite demo mode
13156 * is enabled for.
13157 * @param result The result receiver that returns whether the satellite emergency mode is
13158 * enabled if the request is successful or an error code if the request failed.
13159 *
13160 * @throws SecurityException if the caller doesn't have the required permission.
13161 */
13162 @Override
13163 public void requestIsEmergencyModeEnabled(int subId, @NonNull ResultReceiver result) {
13164 enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled");
13165 result.send(SATELLITE_RESULT_REQUEST_NOT_SUPPORTED, null);
13166 }
13167
13168 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013169 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080013170 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013171 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013172 * @param result The result receiver that returns whether the satellite service is supported on
13173 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013174 */
13175 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013176 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013177 mSatelliteController.requestIsSatelliteSupported(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013178 }
13179
13180 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013181 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080013182 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013183 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013184 * @param result The result receiver that returns the {@link SatelliteCapabilities}
13185 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013186 *
13187 * @throws SecurityException if the caller doesn't have required permission.
13188 */
13189 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013190 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
13191 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013192 mSatelliteController.requestSatelliteCapabilities(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013193 }
13194
13195 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013196 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013197 * This can be called by the pointing UI when the user starts pointing to the satellite.
13198 * Modem should continue to report the pointing input as the device or satellite moves.
13199 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013200 * @param subId The subId of the subscription to start satellite transmission updates for.
13201 * @param resultCallback The callback to get the result of the request.
13202 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080013203 *
13204 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013205 */
13206 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013207 public void startSatelliteTransmissionUpdates(int subId,
13208 @NonNull IIntegerConsumer resultCallback,
13209 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13210 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
13211 mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080013212 }
13213
13214 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013215 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013216 * This can be called by the pointing UI when the user stops pointing to the satellite.
13217 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013218 * @param subId The subId of the subscription to stop satellite transmission updates for.
13219 * @param resultCallback The callback to get the result of the request.
13220 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
13221 * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080013222 *
13223 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013224 */
13225 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013226 public void stopSatelliteTransmissionUpdates(int subId,
13227 @NonNull IIntegerConsumer resultCallback,
13228 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13229 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
13230 mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013231 }
13232
13233 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013234 * Register the subscription with a satellite provider.
13235 * This is needed to register the subscription if the provider allows dynamic registration.
13236 *
13237 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013238 * @param token The token to be used as a unique identifier for provisioning with satellite
13239 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013240 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080013241 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013242 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013243 * @return The signal transport used by the caller to cancel the provision request,
13244 * or {@code null} if the request failed.
13245 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013246 * @throws SecurityException if the caller doesn't have the required permission.
13247 */
13248 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013249 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013250 @NonNull String token, @NonNull byte[] provisionData,
13251 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013252 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013253 return mSatelliteController.provisionSatelliteService(subId, token, provisionData,
13254 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013255 }
13256
13257 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013258 * Unregister the device/subscription with the satellite provider.
13259 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013260 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013261 * should report as deprovisioned.
13262 *
13263 * @param subId The subId of the subscription to be deprovisioned.
13264 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080013265 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013266 *
13267 * @throws SecurityException if the caller doesn't have the required permission.
13268 */
13269 @Override
13270 public void deprovisionSatelliteService(int subId,
13271 @NonNull String token, @NonNull IIntegerConsumer callback) {
13272 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013273 mSatelliteController.deprovisionSatelliteService(subId, token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013274 }
13275
13276 /**
Sarah Chin43457982023-02-15 17:50:38 -080013277 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013278 *
Sarah Chin43457982023-02-15 17:50:38 -080013279 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013280 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013281 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013282 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013283 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013284 * @throws SecurityException if the caller doesn't have the required permission.
13285 */
13286 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013287 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
13288 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013289 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013290 return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013291 }
13292
13293 /**
Sarah Chin43457982023-02-15 17:50:38 -080013294 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013295 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013296 *
Sarah Chin43457982023-02-15 17:50:38 -080013297 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013298 * @param callback The callback that was passed to
13299 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013300 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013301 * @throws SecurityException if the caller doesn't have the required permission.
13302 */
13303 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013304 public void unregisterForSatelliteProvisionStateChanged(
13305 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013306 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013307 mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013308 }
13309
13310 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013311 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013312 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013313 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013314 * @param result The result receiver that returns whether the device is provisioned with a
13315 * satellite provider if the request is successful or an error code if the
13316 * request failed.
13317 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013318 * @throws SecurityException if the caller doesn't have the required permission.
13319 */
13320 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013321 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
13322 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013323 mSatelliteController.requestIsSatelliteProvisioned(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013324 }
13325
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013326 /**
Sarah Chin43457982023-02-15 17:50:38 -080013327 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013328 *
Sarah Chin43457982023-02-15 17:50:38 -080013329 * @param subId The subId of the subscription to register for satellite modem state changed.
13330 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080013331 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013332 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013333 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013334 * @throws SecurityException if the caller doesn't have the required permission.
13335 */
13336 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013337 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013338 @NonNull ISatelliteModemStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080013339 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013340 return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013341 }
13342
13343 /**
Sarah Chin43457982023-02-15 17:50:38 -080013344 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013345 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013346 *
Sarah Chin43457982023-02-15 17:50:38 -080013347 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080013348 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013349 * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013350 *
13351 * @throws SecurityException if the caller doesn't have the required permission.
13352 */
13353 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013354 public void unregisterForModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013355 @NonNull ISatelliteModemStateCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013356 enforceSatelliteCommunicationPermission("unregisterForModemStateChanged");
13357 mSatelliteController.unregisterForModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013358 }
13359
13360 /**
13361 * Register to receive incoming datagrams over satellite.
13362 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013363 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Sarah Chindf715ec2023-02-13 13:46:24 -080013364 * @param callback The callback to handle incoming datagrams over satellite.
13365 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013366 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013367 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013368 * @throws SecurityException if the caller doesn't have the required permission.
13369 */
13370 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013371 @SatelliteManager.SatelliteResult public int registerForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013372 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013373 enforceSatelliteCommunicationPermission("registerForIncomingDatagram");
13374 return mSatelliteController.registerForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013375 }
13376
13377 /**
13378 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013379 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013380 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013381 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
13382 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013383 * {@link #registerForIncomingDatagram(int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013384 *
13385 * @throws SecurityException if the caller doesn't have the required permission.
13386 */
13387 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013388 public void unregisterForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013389 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013390 enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram");
13391 mSatelliteController.unregisterForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013392 }
13393
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013394 /**
13395 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013396 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013397 * This method requests modem to check if there are any pending datagrams to be received over
13398 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000013399 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080013400 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013401 * @param subId The subId of the subscription used for receiving datagrams.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013402 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013403 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013404 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013405 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013406 public void pollPendingDatagrams(int subId, IIntegerConsumer callback) {
13407 enforceSatelliteCommunicationPermission("pollPendingDatagrams");
13408 mSatelliteController.pollPendingDatagrams(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013409 }
13410
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013411 /**
13412 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013413 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013414 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
13415 * input to this method. Datagram received here will be passed down to modem without any
13416 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080013417 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013418 * @param subId The subId of the subscription to send satellite datagrams for.
13419 * @param datagramType datagram type indicating whether the datagram is of type
13420 * SOS_SMS or LOCATION_SHARING.
13421 * @param datagram encoded gateway datagram which is encrypted by the caller.
13422 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000013423 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
13424 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013425 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013426 *
13427 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013428 */
13429 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013430 public void sendDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000013431 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
13432 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013433 enforceSatelliteCommunicationPermission("sendDatagram");
13434 mSatelliteController.sendDatagram(subId, datagramType, datagram, needFullScreenPointingUI,
13435 callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013436 }
13437
Sarah Chindf715ec2023-02-13 13:46:24 -080013438 /**
13439 * Request to get whether satellite communication is allowed for the current location.
13440 *
13441 * @param subId The subId of the subscription to check whether satellite communication is
13442 * allowed for the current location for.
13443 * @param result The result receiver that returns whether satellite communication is allowed
13444 * for the current location if the request is successful or an error code
13445 * if the request failed.
13446 *
13447 * @throws SecurityException if the caller doesn't have the required permission.
13448 */
13449 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013450 public void requestIsCommunicationAllowedForCurrentLocation(int subId,
Sarah Chindf715ec2023-02-13 13:46:24 -080013451 @NonNull ResultReceiver result) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013452 enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation");
13453 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(subId,
13454 result);
Sarah Chindf715ec2023-02-13 13:46:24 -080013455 }
13456
13457 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013458 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080013459 *
Sarah Chin5f57c582023-02-14 04:16:10 -080013460 * @param subId The subId to get the time after which the satellite will be visible for.
13461 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080013462 * be visible if the request is successful or an error code if the request failed.
13463 *
13464 * @throws SecurityException if the caller doesn't have the required permission.
13465 */
13466 @Override
13467 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
13468 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013469 mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013470 }
13471
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013472 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013473 * Inform that Device is aligned to satellite for demo mode.
13474 *
13475 * @param subId The subId to get the time after which the satellite will be visible for.
13476 * @param isAligned {@code true} Device is aligned with the satellite for demo mode
13477 * {@code false} Device fails to align with the satellite for demo mode.
13478 *
13479 * @throws SecurityException if the caller doesn't have required permission.
13480 */
13481 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
13482
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013483 public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) {
Hakjun Choiae365972023-04-25 11:00:31 +000013484 enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite");
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013485 mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned);
Hakjun Choiae365972023-04-25 11:00:31 +000013486 }
13487
13488 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000013489 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
13490 * by modem.
13491 *
13492 * @param subId The subId of the subscription to request for.
13493 * @param reason Reason for disallowing satellite communication for carrier.
Hakjun Choif92ac752024-03-18 19:34:29 +000013494 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013495 * operation.
13496 *
13497 * @throws SecurityException if the caller doesn't have required permission.
13498 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013499 public void addAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013500 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13501 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013502 enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013503 final long identity = Binder.clearCallingIdentity();
13504 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013505 mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013506 } finally {
13507 Binder.restoreCallingIdentity(identity);
13508 }
13509 }
13510
13511 /**
13512 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
13513 * by modem.
13514 *
13515 * @param subId The subId of the subscription to request for.
13516 * @param reason Reason for disallowing satellite communication.
Hakjun Choif92ac752024-03-18 19:34:29 +000013517 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013518 * operation.
13519 *
13520 * @throws SecurityException if the caller doesn't have required permission.
13521 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013522 public void removeAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013523 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13524 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013525 enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013526 final long identity = Binder.clearCallingIdentity();
13527 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013528 mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013529 } finally {
13530 Binder.restoreCallingIdentity(identity);
13531 }
13532 }
13533
13534 /**
13535 * Get reasons for disallowing satellite communication, as requested by
Hakjun Choif92ac752024-03-18 19:34:29 +000013536 * {@link #addAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
Hakjun Choicb39db92023-07-14 15:51:12 +000013537 *
13538 * @param subId The subId of the subscription to request for.
13539 *
13540 * @return Integer array of reasons for disallowing satellite communication.
13541 *
13542 * @throws SecurityException if the caller doesn't have the required permission.
13543 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013544 public @NonNull int[] getAttachRestrictionReasonsForCarrier(
Hakjun Choicb39db92023-07-14 15:51:12 +000013545 int subId) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013546 enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013547 final long identity = Binder.clearCallingIdentity();
13548 try {
13549 Set<Integer> reasonSet =
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013550 mSatelliteController.getAttachRestrictionReasonsForCarrier(subId);
Hakjun Choicb39db92023-07-14 15:51:12 +000013551 return reasonSet.stream().mapToInt(i->i).toArray();
13552 } finally {
13553 Binder.restoreCallingIdentity(identity);
13554 }
13555 }
13556
13557 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000013558 * Request to get the signal strength of the satellite connection.
13559 *
13560 * @param subId The subId of the subscription to request for.
13561 * @param result Result receiver to get the error code of the request and the current signal
13562 * strength of the satellite connection.
13563 *
13564 * @throws SecurityException if the caller doesn't have required permission.
13565 */
13566 @Override
13567 public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) {
13568 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
13569 final long identity = Binder.clearCallingIdentity();
13570 try {
13571 mSatelliteController.requestNtnSignalStrength(subId, result);
13572 } finally {
13573 Binder.restoreCallingIdentity(identity);
13574 }
13575 }
13576
13577 /**
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013578 * Registers for NTN signal strength changed from satellite modem. If the registration operation
13579 * is not successful, a {@link ServiceSpecificException} that contains
13580 * {@link SatelliteManager.SatelliteResult} will be thrown.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013581 *
13582 * @param subId The subId of the subscription to request for.
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013583 * @param callback The callback to handle the NTN signal strength changed event. If the
13584 * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged(
13585 * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of
13586 * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial
13587 * network has changed.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013588 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013589 * @throws SecurityException If the caller doesn't have the required permission.
13590 * @throws ServiceSpecificException If the callback registration operation fails.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013591 */
13592 @Override
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013593 public void registerForNtnSignalStrengthChanged(int subId,
13594 @NonNull INtnSignalStrengthCallback callback) throws RemoteException {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013595 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
13596 final long identity = Binder.clearCallingIdentity();
13597 try {
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013598 mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013599 } finally {
13600 Binder.restoreCallingIdentity(identity);
13601 }
13602 }
13603
13604 /**
13605 * Unregisters for NTN signal strength changed from satellite modem.
13606 * If callback was not registered before, the request will be ignored.
13607 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013608 * @param subId The subId of the subscription to unregister for listening NTN signal strength
13609 * changed event.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013610 * @param callback The callback that was passed to
13611 * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)}
13612 *
13613 * @throws SecurityException if the caller doesn't have the required permission.
13614 */
13615 @Override
13616 public void unregisterForNtnSignalStrengthChanged(
13617 int subId, @NonNull INtnSignalStrengthCallback callback) {
13618 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
13619 final long identity = Binder.clearCallingIdentity();
13620 try {
13621 mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback);
13622 } finally {
13623 Binder.restoreCallingIdentity(identity);
13624 }
13625 }
13626
13627 /**
Hakjun Choi8d96a562023-10-26 15:01:40 +000013628 * Registers for satellite capabilities change event from the satellite service.
13629 *
13630 * @param subId The subId of the subscription to request for.
13631 * @param callback The callback to handle the satellite capabilities changed event.
13632 *
13633 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13634 *
13635 * @throws SecurityException if the caller doesn't have required permission.
13636 */
13637 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013638 @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged(
Hakjun Choi8d96a562023-10-26 15:01:40 +000013639 int subId, @NonNull ISatelliteCapabilitiesCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013640 enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013641 final long identity = Binder.clearCallingIdentity();
13642 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013643 return mSatelliteController.registerForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013644 } finally {
13645 Binder.restoreCallingIdentity(identity);
13646 }
13647 }
13648
13649 /**
13650 * Unregisters for satellite capabilities change event from the satellite service.
13651 * If callback was not registered before, the request will be ignored.
13652 *
13653 * @param subId The subId of the subscription to unregister for satellite capabilities change.
13654 * @param callback The callback that was passed to.
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013655 * {@link #registerForCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}.
Hakjun Choi8d96a562023-10-26 15:01:40 +000013656 *
13657 * @throws SecurityException if the caller doesn't have required permission.
13658 */
13659 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013660 public void unregisterForCapabilitiesChanged(int subId,
13661 @NonNull ISatelliteCapabilitiesCallback callback) {
13662 enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013663 final long identity = Binder.clearCallingIdentity();
13664 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013665 mSatelliteController.unregisterForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013666 } finally {
13667 Binder.restoreCallingIdentity(identity);
13668 }
13669 }
13670
13671 /**
Hakjun Choif92ac752024-03-18 19:34:29 +000013672 * Registers for the satellite supported state changed.
13673 *
13674 * @param subId The subId of the subscription to register for supported state changed.
13675 * @param callback The callback to handle the satellite supported state changed event.
13676 *
13677 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13678 *
13679 * @throws SecurityException if the caller doesn't have the required permission.
13680 */
13681 @Override
13682 @SatelliteManager.SatelliteResult public int registerForSatelliteSupportedStateChanged(
13683 int subId, @NonNull ISatelliteSupportedStateCallback callback) {
13684 enforceSatelliteCommunicationPermission("registerForSatelliteSupportedStateChanged");
13685 return mSatelliteController.registerForSatelliteSupportedStateChanged(subId, callback);
13686 }
13687
13688 /**
13689 * Unregisters for the satellite supported state changed.
13690 * If callback was not registered before, the request will be ignored.
13691 *
13692 * @param subId The subId of the subscription to unregister for supported state changed.
13693 * @param callback The callback that was passed to
13694 * {@link #registerForSatelliteSupportedStateChanged(int, ISatelliteSupportedStateCallback)}.
13695 *
13696 * @throws SecurityException if the caller doesn't have the required permission.
13697 */
13698 @Override
13699 public void unregisterForSatelliteSupportedStateChanged(
13700 int subId, @NonNull ISatelliteSupportedStateCallback callback) {
13701 enforceSatelliteCommunicationPermission("unregisterForSatelliteSupportedStateChanged");
13702 mSatelliteController.unregisterForSatelliteSupportedStateChanged(subId, callback);
13703 }
13704
13705 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013706 * This API can be used by only CTS to update satellite vendor service package name.
13707 *
13708 * @param servicePackageName The package name of the satellite vendor service.
13709 * @return {@code true} if the satellite vendor service is set successfully,
13710 * {@code false} otherwise.
13711 */
13712 public boolean setSatelliteServicePackageName(String servicePackageName) {
13713 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName);
13714 TelephonyPermissions.enforceShellOnly(
13715 Binder.getCallingUid(), "setSatelliteServicePackageName");
13716 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13717 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13718 "setSatelliteServicePackageName");
13719 return mSatelliteController.setSatelliteServicePackageName(servicePackageName);
13720 }
13721
13722 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070013723 * This API can be used by only CTS to update satellite gateway service package name.
13724 *
13725 * @param servicePackageName The package name of the satellite gateway service.
13726 * @return {@code true} if the satellite gateway service is set successfully,
13727 * {@code false} otherwise.
13728 */
13729 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
13730 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
13731 TelephonyPermissions.enforceShellOnly(
13732 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
13733 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13734 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13735 "setSatelliteGatewayServicePackageName");
13736 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
13737 }
13738
13739 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070013740 * This API can be used by only CTS to update satellite pointing UI app package and class names.
13741 *
13742 * @param packageName The package name of the satellite pointing UI app.
13743 * @param className The class name of the satellite pointing UI app.
13744 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
13745 * {@code false} otherwise.
13746 */
13747 public boolean setSatellitePointingUiClassName(
13748 @Nullable String packageName, @Nullable String className) {
13749 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
13750 + ", className=" + className);
13751 TelephonyPermissions.enforceShellOnly(
13752 Binder.getCallingUid(), "setSatellitePointingUiClassName");
13753 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13754 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13755 "setSatelliteGatewayServicePackageName");
13756 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
13757 }
13758
13759 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070013760 * This API can be used by only CTS to update the timeout duration in milliseconds that
13761 * satellite should stay at listening mode to wait for the next incoming page before disabling
13762 * listening mode.
13763 *
13764 * @param timeoutMillis The timeout duration in millisecond.
13765 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13766 */
13767 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
13768 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
13769 TelephonyPermissions.enforceShellOnly(
13770 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
13771 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13772 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13773 "setSatelliteListeningTimeoutDuration");
13774 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
13775 }
13776
13777 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013778 * This API can be used by only CTS to override the timeout durations used by the
13779 * DatagramController module.
Hakjun Choiae365972023-04-25 11:00:31 +000013780 *
13781 * @param timeoutMillis The timeout duration in millisecond.
13782 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13783 */
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013784 public boolean setDatagramControllerTimeoutDuration(
13785 boolean reset, int timeoutType, long timeoutMillis) {
13786 Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset="
13787 + reset + ", timeoutMillis=" + timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013788 TelephonyPermissions.enforceShellOnly(
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013789 Binder.getCallingUid(), "setDatagramControllerTimeoutDuration");
Hakjun Choiae365972023-04-25 11:00:31 +000013790 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13791 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013792 "setDatagramControllerTimeoutDuration");
13793 return mSatelliteController.setDatagramControllerTimeoutDuration(
13794 reset, timeoutType, timeoutMillis);
13795 }
13796
13797 /**
Aishwarya Mallampati3f0ef9b2024-05-17 22:47:04 +000013798 * This API can be used by only CTS to override the boolean configs used by the
13799 * DatagramController module.
13800 *
13801 * @param enable Whether to enable or disable boolean config.
13802 * @return {@code true} if the boolean config is set successfully, {@code false} otherwise.
13803 */
13804 public boolean setDatagramControllerBooleanConfig(
13805 boolean reset, int booleanType, boolean enable) {
13806 Log.d(LOG_TAG, "setDatagramControllerBooleanConfig: booleanType=" + booleanType
13807 + ", reset=" + reset + ", enable=" + enable);
13808 TelephonyPermissions.enforceShellOnly(
13809 Binder.getCallingUid(), "setDatagramControllerBooleanConfig");
13810 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13811 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13812 "ssetDatagramControllerBooleanConfig");
13813 return mSatelliteController.setDatagramControllerBooleanConfig(reset, booleanType, enable);
13814 }
13815
13816
13817 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013818 * This API can be used by only CTS to override the timeout durations used by the
13819 * SatelliteController module.
13820 *
13821 * @param timeoutMillis The timeout duration in millisecond.
13822 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13823 */
13824 public boolean setSatelliteControllerTimeoutDuration(
13825 boolean reset, int timeoutType, long timeoutMillis) {
13826 Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset="
13827 + reset + ", timeoutMillis=" + timeoutMillis);
13828 TelephonyPermissions.enforceShellOnly(
13829 Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration");
13830 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13831 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13832 "setSatelliteControllerTimeoutDuration");
13833 return mSatelliteController.setSatelliteControllerTimeoutDuration(
13834 reset, timeoutType, timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013835 }
13836
13837 /**
Thomas Nguyen11a051f2023-10-25 10:14:55 -070013838 * This API can be used in only testing to override connectivity status in monitoring emergency
13839 * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.
13840 *
13841 * @param handoverType The type of handover from emergency call to satellite messaging. Use one
13842 * of the following values to enable the override:
13843 * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS
13844 * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911
13845 * To disable the override, use -1 for handoverType.
13846 * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer
13847 * delaySeconds after the emergency call starts.
13848 * @return {@code true} if the handover type is set successfully, {@code false} otherwise.
13849 */
13850 public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) {
13851 Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType);
13852 TelephonyPermissions.enforceShellOnly(
13853 Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType");
13854 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13855 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13856 "setEmergencyCallToSatelliteHandoverType");
13857 return mSatelliteController.setEmergencyCallToSatelliteHandoverType(
13858 handoverType, delaySeconds);
13859 }
13860
13861 /**
Thomas Nguyen3d602742024-01-19 11:29:35 -080013862 * This API can be used in only testing to override oem-enabled satellite provision status.
13863 *
13864 * @param reset {@code true} mean the overriding status should not be used, {@code false}
13865 * otherwise.
13866 * @param isProvisioned The overriding provision status.
13867 * @return {@code true} if the provision status is set successfully, {@code false} otherwise.
13868 */
13869 public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) {
13870 Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset
13871 + ", isProvisioned=" + isProvisioned);
13872 TelephonyPermissions.enforceShellOnly(
13873 Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus");
13874 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13875 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13876 "setOemEnabledSatelliteProvisionStatus");
13877 return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned);
13878 }
13879
13880 /**
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013881 * This API should be used by only CTS tests to forcefully set telephony country codes.
13882 *
13883 * @return {@code true} if the country code is set successfully, {@code false} otherwise.
13884 */
13885 public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes,
13886 Map cachedNetworkCountryCodes, String locationCountryCode,
13887 long locationCountryCodeTimestampNanos) {
13888 Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes="
13889 + String.join(", ", currentNetworkCountryCodes)
13890 + ", locationCountryCode=" + locationCountryCode
13891 + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos
13892 + ", reset=" + reset + ", cachedNetworkCountryCodes="
13893 + String.join(", ", cachedNetworkCountryCodes.keySet()));
13894 TelephonyPermissions.enforceShellOnly(
13895 Binder.getCallingUid(), "setCachedLocationCountryCode");
13896 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13897 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13898 "setCachedLocationCountryCode");
13899 return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext()).setCountryCodes(
13900 reset, currentNetworkCountryCodes, cachedNetworkCountryCodes, locationCountryCode,
13901 locationCountryCodeTimestampNanos);
13902 }
13903
13904 /**
13905 * This API should be used by only CTS tests to override the overlay configs of satellite
13906 * access controller.
13907 *
13908 * @param reset {@code true} mean the overridden configs should not be used, {@code false}
13909 * otherwise.
13910 * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise.
13911 */
13912 public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed,
13913 String s2CellFile, long locationFreshDurationNanos,
13914 List<String> satelliteCountryCodes) {
13915 Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset
13916 + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile
13917 + ", locationFreshDurationNanos=" + locationFreshDurationNanos
13918 + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null)
13919 ? String.join(", ", satelliteCountryCodes) : null));
13920 TelephonyPermissions.enforceShellOnly(
13921 Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs");
13922 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13923 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13924 "setSatelliteAccessControlOverlayConfigs");
13925 return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset, isAllowed,
13926 s2CellFile, locationFreshDurationNanos, satelliteCountryCodes);
13927 }
13928
13929 /**
Hakjun Choibc6ce992023-11-07 16:04:33 +000013930 * This API can be used by only CTS to override the cached value for the device overlay config
13931 * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether
13932 * outgoing satellite datagrams should be sent to modem in demo mode.
13933 *
13934 * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to
13935 * satellite modem or not.
13936 *
13937 * @return {@code true} if the operation is successful, {@code false} otherwise.
13938 */
13939 public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) {
13940 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
13941 Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is "
13942 + "disabled");
13943 return false;
13944 }
13945 Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode");
13946 TelephonyPermissions.enforceShellOnly(
13947 Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode");
13948 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13949 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13950 "setShouldSendDatagramToModemInDemoMode");
13951 return mSatelliteController.setShouldSendDatagramToModemInDemoMode(
13952 shouldSendToModemInDemoMode);
13953 }
13954
13955 /**
Hakjun Choi4a832d12024-05-28 22:23:55 +000013956 * This API can be used by only CTS to set the cache whether satellite communication is allowed.
13957 *
13958 * @param state a state indicates whether satellite access allowed state should be cached and
13959 * the allowed state.
13960 * @return {@code true} if the setting is successful, {@code false} otherwise.
13961 */
13962 public boolean setIsSatelliteCommunicationAllowedForCurrentLocationCache(String state) {
13963 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
13964 Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: "
13965 + "oemEnabledSatelliteFlag is disabled");
13966 return false;
13967 }
13968
13969 Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: "
13970 + "state=" + state);
13971 TelephonyPermissions.enforceShellOnly(
13972 Binder.getCallingUid(),
13973 "setIsSatelliteCommunicationAllowedForCurrentLocationCache");
13974 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13975 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13976 "setIsSatelliteCommunicationAllowedForCurrentLocationCache");
13977 return mSatelliteAccessController.setIsSatelliteCommunicationAllowedForCurrentLocationCache(
13978 state);
13979 }
13980
13981 /**
Hunsuk Choi13078be2023-09-13 10:55:21 +000013982 * Sets the service defined in ComponentName to be bound.
13983 *
13984 * This should only be used for testing.
13985 * @return {@code true} if the DomainSelectionService to bind to was set,
13986 * {@code false} otherwise.
13987 */
13988 @Override
13989 public boolean setDomainSelectionServiceOverride(ComponentName componentName) {
13990 Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName);
13991
13992 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
13993 "setDomainSelectionServiceOverride");
13994 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13995 getDefaultSubscription(), "setDomainSelectionServiceOverride");
13996
13997 final long identity = Binder.clearCallingIdentity();
13998 try {
13999 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
14000 return DomainSelectionResolver.getInstance()
14001 .setDomainSelectionServiceOverride(componentName);
14002 }
14003 } finally {
14004 Binder.restoreCallingIdentity(identity);
14005 }
14006 return false;
14007 }
14008
14009 /**
14010 * Clears the DomainSelectionService override.
14011 *
14012 * This should only be used for testing.
14013 * @return {@code true} if the DomainSelectionService override was cleared,
14014 * {@code false} otherwise.
14015 */
14016 @Override
14017 public boolean clearDomainSelectionServiceOverride() {
14018 Log.i(LOG_TAG, "clearDomainSelectionServiceOverride");
14019
14020 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
14021 "clearDomainSelectionServiceOverride");
14022 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14023 getDefaultSubscription(), "clearDomainSelectionServiceOverride");
14024
14025 final long identity = Binder.clearCallingIdentity();
14026 try {
14027 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
14028 return DomainSelectionResolver.getInstance()
14029 .clearDomainSelectionServiceOverride();
14030 }
14031 } finally {
14032 Binder.restoreCallingIdentity(identity);
14033 }
14034 return false;
14035 }
14036
14037 /**
Gil Cukierman06403e12023-11-29 16:33:03 +000014038 * Enable or disable notifications sent for cellular identifier disclosure events.
14039 *
14040 * Disclosure events are defined as instances where a device has sent a cellular identifier
14041 * on the Non-access stratum (NAS) before a security context is established. As a result the
14042 * identifier is sent in the clear, which has privacy implications for the user.
14043 *
14044 * @param enable if notifications about disclosure events should be enabled
14045 * @throws SecurityException if the caller does not have the required privileges
14046 * @throws UnsupportedOperationException if the modem does not support this feature.
14047 */
14048 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000014049 public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) {
Gil Cukierman06403e12023-11-29 16:33:03 +000014050 enforceModifyPermission();
14051 checkForIdentifierDisclosureNotificationSupport();
14052
14053 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
14054 editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable);
14055 editor.apply();
14056
14057 // Each phone instance is responsible for updating its respective modem immediately
14058 // after we've made a preference change.
14059 for (Phone phone : PhoneFactory.getPhones()) {
14060 phone.handleIdentifierDisclosureNotificationPreferenceChange();
14061 }
14062 }
14063
14064 /**
14065 * Get whether or not cellular identifier disclosure notifications are enabled.
14066 *
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.READ_PRIVILEGED_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000014071 public boolean isCellularIdentifierDisclosureNotificationsEnabled() {
Gil Cukierman06403e12023-11-29 16:33:03 +000014072 enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled");
14073 checkForIdentifierDisclosureNotificationSupport();
14074 return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled();
14075 }
14076
14077 /**
Michael Groover826b71d2023-12-21 22:08:06 -060014078 * Enables or disables notifications sent when cellular null cipher or integrity algorithms
14079 * are in use by the cellular modem.
14080 *
14081 * @throws IllegalStateException if the Telephony process is not currently available
14082 * @throws SecurityException if the caller does not have the required privileges
14083 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14084 * and integrity algorithms in use
14085 * @hide
14086 */
14087 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Michael Grooverae447b22024-01-24 22:35:46 -060014088 public void setNullCipherNotificationsEnabled(boolean enable) {
Michael Groover826b71d2023-12-21 22:08:06 -060014089 enforceModifyPermission();
14090 checkForNullCipherNotificationSupport();
14091
14092 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
14093 editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable);
14094 editor.apply();
14095
14096 // Each phone instance is responsible for updating its respective modem immediately
14097 // after a preference change.
14098 for (Phone phone : PhoneFactory.getPhones()) {
14099 phone.handleNullCipherNotificationPreferenceChanged();
14100 }
14101 }
14102
14103 /**
14104 * Get whether notifications are enabled for null cipher or integrity algorithms in use by the
14105 * cellular modem.
14106 *
14107 * @throws IllegalStateException if the Telephony process is not currently available
14108 * @throws SecurityException if the caller does not have the required privileges
14109 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14110 * and integrity algorithms in use
14111 * @hide
14112 */
14113 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
14114 public boolean isNullCipherNotificationsEnabled() {
14115 enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled");
14116 checkForNullCipherNotificationSupport();
14117 return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled();
14118 }
14119
14120 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000014121 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
14122 *
14123 * <p>This method behaves in one of the following ways:
14124 * <ul>
14125 * <li>return true : if the calling package has the appop permission {@link
14126 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
14127 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
14128 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
14129 * Owner device identifier access check, or the calling package has carrier privileges</>
14130 * <li>throw SecurityException: if the caller does not meet any of the requirements.
14131 * </ul>
14132 */
14133 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
14134 String callingPackage, @Nullable String callingFeatureId, String message) {
14135 for (Phone phone : PhoneFactory.getPhones()) {
14136 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
14137 phone.getSubId(), callingPackage, callingFeatureId, message)) {
14138 return true;
14139 }
14140 }
14141 return false;
14142 }
arunvoddud7401012022-12-15 16:08:12 +000014143
14144 /**
Jack Yufa8ed012023-02-11 15:42:28 -080014145 * @return The subscription manager service instance.
14146 */
14147 public SubscriptionManagerService getSubscriptionManagerService() {
14148 return SubscriptionManagerService.getInstance();
14149 }
14150
14151 /**
arunvoddud7401012022-12-15 16:08:12 +000014152 * Class binds the consumer[callback] and carrierId.
14153 */
14154 private static class CallerCallbackInfo {
14155 private final Consumer<Integer> mConsumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014156 private final Set<Integer> mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014157
Steve Statia28b7cb32024-03-11 23:58:50 +000014158 public CallerCallbackInfo(Consumer<Integer> consumer, Set<Integer> carrierIds) {
arunvoddud7401012022-12-15 16:08:12 +000014159 mConsumer = consumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014160 mCarrierIds = carrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014161 }
14162
14163 public Consumer<Integer> getConsumer() {
14164 return mConsumer;
14165 }
14166
Steve Statia28b7cb32024-03-11 23:58:50 +000014167 public Set<Integer> getCarrierIds() {
14168 return mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014169 }
14170 }
joonhunshin4ac60942023-11-15 15:23:39 +000014171
14172 /*
14173 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14174 * But the context that is passed in is unused if the phone app is already alive.
14175 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14176 */
14177 @VisibleForTesting
14178 public void setPackageManager(PackageManager packageManager) {
14179 mPackageManager = packageManager;
14180 }
14181
14182 /*
Nate Myren453c3472024-03-13 11:28:11 -070014183 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14184 * But the context that is passed in is unused if the phone app is already alive.
14185 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14186 */
14187 @VisibleForTesting
14188 public void setAppOpsManager(AppOpsManager appOps) {
14189 mAppOps = appOps;
14190 }
14191
14192 /*
joonhunshin4ac60942023-11-15 15:23:39 +000014193 * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags.
14194 * But the FeatureFlags that is passed in is unused if the phone app is already alive.
14195 * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test.
14196 */
14197 @VisibleForTesting
14198 public void setFeatureFlags(FeatureFlags featureFlags) {
14199 mFeatureFlags = featureFlags;
14200 }
14201
14202 /**
14203 * Make sure the device has required telephony feature
14204 *
14205 * @throws UnsupportedOperationException if the device does not have required telephony feature
14206 */
14207 private void enforceTelephonyFeatureWithException(@Nullable String callingPackage,
14208 @NonNull String telephonyFeature, @NonNull String methodName) {
14209 if (callingPackage == null || mPackageManager == null) {
14210 return;
14211 }
14212
14213 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
14214 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage,
joonhunshinf624b2a2024-04-18 04:42:12 +000014215 Binder.getCallingUserHandle())
14216 || mVendorApiLevel < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
14217 // Skip to check associated telephony feature,
14218 // if compatibility change is not enabled for the current process or
14219 // the SDK version of vendor partition is less than Android V.
joonhunshin4ac60942023-11-15 15:23:39 +000014220 return;
14221 }
14222
14223 if (!mPackageManager.hasSystemFeature(telephonyFeature)) {
14224 throw new UnsupportedOperationException(
14225 methodName + " is unsupported without " + telephonyFeature);
14226 }
14227 }
youngtaecha5d483d52024-04-29 17:05:45 +000014228
14229 /**
14230 * Registers for the satellite communication allowed state changed.
14231 *
14232 * @param subId The subId of the subscription to register for the satellite communication
14233 * allowed state changed.
14234 * @param callback The callback to handle the satellite communication allowed
14235 * state changed event.
14236 *
14237 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
14238 *
14239 * @throws SecurityException if the caller doesn't have the required permission.
14240 */
14241 @Override
14242 @SatelliteManager.SatelliteResult public int registerForCommunicationAllowedStateChanged(
14243 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14244 enforceSatelliteCommunicationPermission("registerForCommunicationAllowedStateChanged");
14245 return mSatelliteAccessController.registerForCommunicationAllowedStateChanged(
14246 subId, callback);
14247 }
14248
14249 /**
14250 * Unregisters for the satellite communication allowed state changed.
14251 * If callback was not registered before, the request will be ignored.
14252 *
14253 * @param subId The subId of the subscription to unregister for the satellite communication
14254 * allowed state changed.
14255 * @param callback The callback that was passed to
14256 * {@link #registerForCommunicationAllowedStateChanged(int,
14257 * ISatelliteCommunicationAllowedStateCallback)}. *
14258 * @throws SecurityException if the caller doesn't have the required permission.
14259 */
14260 @Override
14261 public void unregisterForCommunicationAllowedStateChanged(
14262 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14263 enforceSatelliteCommunicationPermission("unregisterForCommunicationAllowedStateChanged");
14264 mSatelliteAccessController.unregisterForCommunicationAllowedStateChanged(subId, callback);
14265 }
Aishwarya Mallampatif265cea2024-06-04 19:55:41 +000014266
14267 /**
14268 * Request to get the {@link SatelliteSessionStats} of the satellite service.
14269 *
14270 * @param subId The subId of the subscription to the satellite session stats for.
14271 * @param result The result receiver that returns the {@link SatelliteSessionStats}
14272 * if the request is successful or an error code if the request failed.
14273 *
14274 * @throws SecurityException if the caller doesn't have required permission.
14275 */
14276 @Override
14277 public void requestSatelliteSessionStats(int subId, @NonNull ResultReceiver result) {
14278 enforceModifyPermission();
14279 enforcePackageUsageStatsPermission("requestSatelliteSessionStats");
14280 mSatelliteController.requestSatelliteSessionStats(subId, result);
14281 }
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014282
14283 /**
14284 * Request to get list of prioritized satellite subscriber ids to be used for provision.
14285 *
14286 * @param result The result receiver, which returns the list of prioritized satellite tokens
14287 * to be used for provision if the request is successful or an error code if the request failed.
14288 *
14289 * @throws SecurityException if the caller doesn't have the required permission.
14290 */
14291 @Override
14292 public void requestProvisionSubscriberIds(@NonNull ResultReceiver result) {
14293 enforceSatelliteCommunicationPermission("requestProvisionSubscriberIds");
14294 mSatelliteController.requestProvisionSubscriberIds(result);
14295 }
14296
14297 /**
14298 * Request to get provisioned status for given a satellite subscriber id.
14299 *
14300 * @param satelliteSubscriberId Satellite subscriber id requiring provisioned status check.
14301 * @param result The result receiver, which returns the provisioned status of the token if the
14302 * request is successful or an error code if the request failed.
14303 *
14304 * @throws SecurityException if the caller doesn't have the required permission.
14305 */
14306 @Override
14307 public void requestIsProvisioned(String satelliteSubscriberId, @NonNull ResultReceiver result) {
14308 enforceSatelliteCommunicationPermission("requestIsProvisioned");
14309 mSatelliteController.requestIsProvisioned(satelliteSubscriberId, result);
14310 }
14311
14312 /**
14313 * Deliver the list of provisioned satellite subscriber ids.
14314 *
14315 * @param list List of provisioned satellite subscriber ids.
14316 * @param result The result receiver that returns whether deliver success or fail.
14317 *
14318 * @throws SecurityException if the caller doesn't have the required permission.
14319 */
14320 @Override
14321 public void provisionSatellite(List<ProvisionSubscriberId> list,
14322 @NonNull ResultReceiver result) {
14323 enforceSatelliteCommunicationPermission("provisionSatellite");
14324 mSatelliteController.provisionSatellite(list, result);
14325 }
Jack Yufa8ed012023-02-11 15:42:28 -080014326}