blob: 356a79e5fa858dbcb9833cd66e4d84b5bfbef101 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
joonhunshin4ac60942023-11-15 15:23:39 +000019import static android.content.pm.PackageManager.FEATURE_TELEPHONY_IMS;
20import static android.content.pm.PackageManager.FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION;
Hall Liud892bec2018-11-30 14:51:45 -080021import static android.content.pm.PackageManager.PERMISSION_GRANTED;
Nate Myrenae97d192023-06-09 15:22:31 -070022import static android.permission.flags.Flags.opEnableMobileDataByUser;
joonhunshin4ac60942023-11-15 15:23:39 +000023import static android.telephony.TelephonyManager.ENABLE_FEATURE_MAPPING;
Gil Cukierman1c0eb932022-12-06 22:28:24 +000024import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK;
jimsunf9ec1622022-09-13 21:18:43 +080025import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080026import static android.telephony.satellite.SatelliteManager.KEY_SATELLITE_COMMUNICATION_ALLOWED;
27import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_ACCESS_BARRED;
Thomas Nguyena8062672024-02-05 14:18:19 -080028import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_REQUEST_NOT_SUPPORTED;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080029import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_SUCCESS;
Hall Liud892bec2018-11-30 14:51:45 -080030
Shuo Qianccbaf742021-02-22 18:32:21 -080031import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
32import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070033import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070034import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000035import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070036
Brad Ebinger34c09a52021-02-17 23:23:21 +000037import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080038import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080039import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070040import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000041import android.annotation.RequiresPermission;
Sarah Chin532d6bb2022-12-28 22:50:43 -080042import android.app.ActivityManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070043import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080044import android.app.PendingIntent;
Tyler Gunn64144d92022-03-17 14:16:41 -070045import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000046import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080047import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000048import android.compat.annotation.ChangeId;
49import android.compat.annotation.EnabledSince;
Anthony Alridge70ba5572023-05-02 12:14:14 +000050import android.content.ActivityNotFoundException;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070051import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070052import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.content.Context;
54import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070055import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070056import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070057import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070058import android.net.Uri;
59import android.os.AsyncResult;
60import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080061import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070062import android.os.Bundle;
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080063import android.os.DropBoxManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070065import android.os.IBinder;
Thomas Nguyen8ee49682023-02-01 11:46:09 -080066import android.os.ICancellationSignal;
tom hsu0b59d292022-09-29 23:49:21 +080067import android.os.LocaleList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070068import android.os.Looper;
69import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070070import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080071import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070072import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070073import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080074import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080075import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070076import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070077import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080078import android.os.SystemClock;
joonhunshinf624b2a2024-04-18 04:42:12 +000079import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070080import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070081import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070082import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070083import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070084import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080085import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070086import android.provider.Telephony;
arunvoddud7401012022-12-15 16:08:12 +000087import android.service.carrier.CarrierIdentifier;
Inseob Kim14bb3d02018-12-13 17:11:34 +090088import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080089import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080090import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070091import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080092import android.telephony.AccessNetworkConstants;
93import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070094import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070095import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080096import android.telephony.Annotation.ThermalMitigationResult;
Sarah Chin2ec39f62022-08-31 17:03:26 -070097import android.telephony.AnomalyReporter;
Shuo Qian4a594052020-01-23 11:59:30 -080098import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070099import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -0800100import android.telephony.CarrierRestrictionRules;
Hui Wang9b5793a2022-12-05 14:38:06 -0600101import android.telephony.CellBroadcastIdRange;
yincheng zhao2737e882019-09-06 17:06:54 -0700102import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -0800103import android.telephony.CellIdentityCdma;
104import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700105import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -0700106import android.telephony.CellInfoGsm;
107import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700108import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800109import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -0700110import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700111import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700112import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -0800113import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700114import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -0800115import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -0700116import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -0800117import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800118import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700119import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800120import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700121import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800122import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800123import android.telephony.SignalStrengthUpdateRequest;
124import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800125import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800126import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800127import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700128import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700129import android.telephony.TelephonyManager;
Jack Yuf5badd92022-12-08 00:50:53 -0800130import android.telephony.TelephonyManager.SimState;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800131import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800132import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800133import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000134import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000135import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000136import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700137import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700138import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800139import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800140import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700141import android.telephony.gba.GbaAuthRequest;
142import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700143import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800144import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000145import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000146import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700147import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000148import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700149import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800150import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700151import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800152import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700153import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000154import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700155import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800156import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800157import android.telephony.ims.stub.ImsRegistrationImplBase;
Hakjun Choifa3e6172023-09-22 03:56:34 +0000158import android.telephony.satellite.INtnSignalStrengthCallback;
Hakjun Choi8d96a562023-10-26 15:01:40 +0000159import android.telephony.satellite.ISatelliteCapabilitiesCallback;
youngtaecha5d483d52024-04-29 17:05:45 +0000160import android.telephony.satellite.ISatelliteCommunicationAllowedStateCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800161import android.telephony.satellite.ISatelliteDatagramCallback;
Hakjun Choid4a52a22023-12-13 09:48:24 +0000162import android.telephony.satellite.ISatelliteModemStateCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800163import android.telephony.satellite.ISatelliteProvisionStateCallback;
Hakjun Choif92ac752024-03-18 19:34:29 +0000164import android.telephony.satellite.ISatelliteSupportedStateCallback;
Sarah Chinabf081b2023-03-09 23:00:57 -0800165import android.telephony.satellite.ISatelliteTransmissionUpdateCallback;
Hakjun Choi4c3668a2023-12-05 11:55:36 +0000166import android.telephony.satellite.NtnSignalStrength;
167import android.telephony.satellite.NtnSignalStrengthCallback;
Hyosun Kim8bac3be2024-06-28 13:35:30 +0000168import android.telephony.satellite.ProvisionSubscriberId;
Sarah Chin503828c2023-02-01 23:54:20 -0800169import android.telephony.satellite.SatelliteCapabilities;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000170import android.telephony.satellite.SatelliteDatagram;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800171import android.telephony.satellite.SatelliteDatagramCallback;
Sarah Chineccfbd12023-01-20 19:00:35 -0800172import android.telephony.satellite.SatelliteManager;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800173import android.telephony.satellite.SatelliteProvisionStateCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700174import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800175import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700176import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700177import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800178import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800179
Andrew Lee312e8172014-10-23 17:01:36 -0700180import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800181import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800182import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800183import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800184import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700185import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700186import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700187import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800188import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800189import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700190import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700191import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800192import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700193import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800194import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800195import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800196import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700197import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000198import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700199import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800200import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700201import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800202import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800203import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800204import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700205import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700206import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700207import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700208import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700209import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800210import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700211import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700212import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700213import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700214import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800215import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800216import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700217import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000218import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700219import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700220import com.android.internal.telephony.SmsPermissions;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800221import com.android.internal.telephony.TelephonyCountryDetector;
Peter Wang59571be2020-01-27 12:35:15 +0800222import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800223import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700224import com.android.internal.telephony.data.DataUtils;
Hunsuk Choi42cc62a2022-10-16 06:03:40 +0000225import com.android.internal.telephony.domainselection.DomainSelectionResolver;
sqianf4ca7ed2019-01-15 18:32:07 -0800226import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700227import com.android.internal.telephony.euicc.EuiccConnector;
Sarah Chincc5446f2023-10-23 17:57:19 -0700228import com.android.internal.telephony.flags.FeatureFlags;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800229import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700230import com.android.internal.telephony.imsphone.ImsPhone;
231import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000232import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800233import com.android.internal.telephony.metrics.TelephonyMetrics;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000234import com.android.internal.telephony.satellite.SatelliteController;
Jack Yu285100e2022-12-02 22:48:35 -0800235import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
236import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700237import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700238import com.android.internal.telephony.uicc.IccIoResult;
239import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800240import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700241import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800242import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700243import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000244import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800245import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000246import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800247import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000248import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700249import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700250import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800251import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800252import com.android.phone.callcomposer.CallComposerPictureManager;
253import com.android.phone.callcomposer.CallComposerPictureTransfer;
254import com.android.phone.callcomposer.ImageData;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800255import com.android.phone.satellite.accesscontrol.SatelliteAccessController;
Hyosun Kim240214a2023-11-02 13:30:15 +0000256import com.android.phone.satellite.entitlement.SatelliteEntitlementController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700257import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700258import com.android.phone.slice.SlicePurchaseController;
arunvoddud7401012022-12-15 16:08:12 +0000259import com.android.phone.utils.CarrierAllowListInfo;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700260import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800261import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700262import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700263import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -0800264import com.android.server.feature.flags.Flags;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800265import com.android.services.telephony.TelecomAccountRegistry;
266import com.android.services.telephony.TelephonyConnectionService;
Hunsuk Choi9c69a802024-04-11 20:39:23 +0000267import com.android.services.telephony.domainselection.TelephonyDomainSelectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800268import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800269
Hall Liu82694d52020-12-11 18:22:04 -0800270import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700271import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800272import java.io.IOException;
273import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700274import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700275import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800276import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000277import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800278import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800279import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800280import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800281import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100282import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800283import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700284import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800285import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800286import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700287import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800288import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800289import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800290import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700291
292/**
293 * Implementation of the ITelephony interface.
294 */
Santos Cordon117fee72014-05-16 17:56:12 -0700295public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700296 private static final String LOG_TAG = "PhoneInterfaceManager";
297 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
298 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800299 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700300
301 // Message codes used with mMainThreadHandler
302 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700303 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
304 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700305 private static final int CMD_OPEN_CHANNEL = 9;
306 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
307 private static final int CMD_CLOSE_CHANNEL = 11;
308 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800309 private static final int CMD_NV_READ_ITEM = 13;
310 private static final int EVENT_NV_READ_ITEM_DONE = 14;
311 private static final int CMD_NV_WRITE_ITEM = 15;
312 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
313 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
314 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700315 private static final int CMD_RESET_MODEM_CONFIG = 19;
316 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800317 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
318 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800319 private static final int CMD_SEND_ENVELOPE = 25;
320 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700321 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
322 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
323 private static final int CMD_EXCHANGE_SIM_IO = 31;
324 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800325 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
326 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700327 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
328 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700329 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
330 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700331 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
332 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
333 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
334 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700335 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
336 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
337 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
338 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700339 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800340 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
341 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000342 private static final int CMD_SWITCH_SLOTS = 50;
343 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700344 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
345 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
346 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
347 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
348 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
349 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
350 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
351 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700352 private static final int CMD_GET_ALL_CELL_INFO = 60;
353 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
354 private static final int CMD_GET_CELL_LOCATION = 62;
355 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700356 private static final int CMD_MODEM_REBOOT = 64;
357 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700358 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
359 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800360 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
361 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700362 private static final int CMD_GET_MODEM_STATUS = 70;
363 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700364 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
365 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700366 private static final int CMD_ERASE_MODEM_CONFIG = 74;
367 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800368 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
369 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
370 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
371 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800372 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
373 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800374 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800375 private static final int CMD_GET_CALL_FORWARDING = 83;
376 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
377 private static final int CMD_SET_CALL_FORWARDING = 85;
378 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
379 private static final int CMD_GET_CALL_WAITING = 87;
380 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
381 private static final int CMD_SET_CALL_WAITING = 89;
382 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700383 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
384 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
385 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
386 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700387 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
388 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800389 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
390 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800391 private static final int CMD_SET_DATA_THROTTLING = 99;
392 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800393 private static final int CMD_SET_SIM_POWER = 101;
394 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800395 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
396 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
397 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
398 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800399 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
400 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000401 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800402 private static final int CMD_GET_SLICING_CONFIG = 110;
403 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800404 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700405 private static final int CMD_ENABLE_VONR = 113;
406 private static final int EVENT_ENABLE_VONR_DONE = 114;
407 private static final int CMD_IS_VONR_ENABLED = 115;
408 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700409 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
410 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000411
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800412 // Parameters of select command.
413 private static final int SELECT_COMMAND = 0xA4;
414 private static final int SELECT_P1 = 0x04;
415 private static final int SELECT_P2 = 0;
416 private static final int SELECT_P3 = 0x10;
417
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000418 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
419 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
Gil Cukierman06403e12023-11-29 16:33:03 +0000420 // Cellular identifier disclosure transparency was added in IRadioNetwork 2.2
421 private static final int MIN_IDENTIFIER_DISCLOSURE_VERSION = 202;
Michael Groover826b71d2023-12-21 22:08:06 -0600422 // Null cipher notification support was added in IRadioNetwork 2.2
423 private static final int MIN_NULL_CIPHER_NOTIFICATION_VERSION = 202;
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000424
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700425 /** The singleton instance. */
426 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800427 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700428
Sarah Chin4beb2b72023-02-14 14:47:54 -0800429 private final PhoneGlobals mApp;
joonhunshin4ac60942023-11-15 15:23:39 +0000430 private FeatureFlags mFeatureFlags;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -0800431 private com.android.server.telecom.flags.FeatureFlags mTelecomFeatureFlags;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800432 private final CallManager mCM;
433 private final ImsResolver mImsResolver;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000434
435 private final SatelliteController mSatelliteController;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800436 private final SatelliteAccessController mSatelliteAccessController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800437 private final UserManager mUserManager;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800438 private final MainThreadHandler mMainThreadHandler;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800439 private final SharedPreferences mTelephonySharedPreferences;
440 private final PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800441 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Nate Myren453c3472024-03-13 11:28:11 -0700442 private AppOpsManager mAppOps;
joonhunshin4ac60942023-11-15 15:23:39 +0000443 private PackageManager mPackageManager;
joonhunshinf624b2a2024-04-18 04:42:12 +0000444 private final int mVendorApiLevel;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700445
Peter Wangdafb9ac2020-01-15 14:13:38 -0800446 /** User Activity */
Sarah Chin4beb2b72023-02-14 14:47:54 -0800447 private final AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800448 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800449 private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800450
Derek Tan97ebb422014-09-05 16:55:38 -0700451 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
452 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800453 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800454 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700455
Michelecea4cf22018-12-21 15:00:11 -0800456 // String to store multi SIM allowed
457 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
458
Derek Tan740e1672017-06-27 14:56:27 -0700459 // The AID of ISD-R.
460 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
461
yinxub1bed742017-04-17 11:45:04 -0700462 private NetworkScanRequestTracker mNetworkScanRequestTracker;
463
David Kelly5e06a7f2018-03-12 14:10:59 +0000464 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
465 private static final int MANUFACTURER_CODE_LENGTH = 8;
466
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800467 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800468 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800469
Sarah Chin2ec39f62022-08-31 17:03:26 -0700470 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
471 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
472
Derek Tan89e89d42014-07-08 17:00:10 -0700473 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700474 * Experiment flag to enable erase modem config on reset network, default value is false
475 */
476 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
477 "reset_network_erase_modem_config_enabled";
478
Rambo Wang0f050d82021-02-12 11:43:36 -0800479 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800480
Gary Jian76280a42022-12-07 16:18:33 +0800481 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
482
sandeepjsb6c87872021-09-27 15:34:44 +0000483 /**
484 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
485 * one ICCID active at the same time.
486 * Apps should use below API signatures if targeting SDK is T and beyond.
487 *
488 * @hide
489 */
490 @ChangeId
491 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
492 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800493
Naina Nallurid63128d2019-09-17 14:10:30 -0700494 /**
Chen Xu540470b2021-12-14 17:15:47 -0800495 * Apps targeting on Android T and beyond will get exception whenever icc close channel
496 * operation fails.
497 */
498 @ChangeId
499 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
500 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
501
502 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700503 * A request object to use for transmitting data to an ICC.
504 */
505 private static final class IccAPDUArgument {
506 public int channel, cla, command, p1, p2, p3;
507 public String data;
508
509 public IccAPDUArgument(int channel, int cla, int command,
510 int p1, int p2, int p3, String data) {
511 this.channel = channel;
512 this.cla = cla;
513 this.command = command;
514 this.p1 = p1;
515 this.p2 = p2;
516 this.p3 = p3;
517 this.data = data;
518 }
519 }
520
521 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700522 * A request object to use for transmitting data to an ICC.
523 */
524 private static final class ManualNetworkSelectionArgument {
525 public OperatorInfo operatorInfo;
526 public boolean persistSelection;
527
528 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
529 this.operatorInfo = operatorInfo;
530 this.persistSelection = persistSelection;
531 }
532 }
533
Sarah Chin71b3a852022-09-28 15:54:19 -0700534 private static final class PurchasePremiumCapabilityArgument {
535 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700536 public @NonNull IIntegerConsumer callback;
537
538 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800539 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700540 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700541 this.callback = callback;
542 }
543 }
544
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700545 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700546 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
547 * request after sending. The main thread will notify the request when it is complete.
548 */
549 private static final class MainThreadRequest {
550 /** The argument to use for the request */
551 public Object argument;
552 /** The result of the request that is run on the main thread */
553 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800554 // The subscriber id that this request applies to. Defaults to
555 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
556 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700557
Nathan Harold92bed182018-10-12 18:16:49 -0700558 // In cases where subId is unavailable, the caller needs to specify the phone.
559 public Phone phone;
560
vagdeviaf9a5b92018-08-15 16:01:53 -0700561 public WorkSource workSource;
562
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700563 public MainThreadRequest(Object argument) {
564 this.argument = argument;
565 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800566
Nathan Harold92bed182018-10-12 18:16:49 -0700567 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
568 this.argument = argument;
569 if (phone != null) {
570 this.phone = phone;
571 }
572 this.workSource = workSource;
573 }
574
vagdeviaf9a5b92018-08-15 16:01:53 -0700575 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800576 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800577 if (subId != null) {
578 this.subId = subId;
579 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700580 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800581 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700582 }
583
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800584 private static final class IncomingThirdPartyCallArgs {
585 public final ComponentName component;
586 public final String callId;
587 public final String callerDisplayName;
588
589 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
590 String callerDisplayName) {
591 this.component = component;
592 this.callId = callId;
593 this.callerDisplayName = callerDisplayName;
594 }
595 }
596
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700597 /**
598 * A handler that processes messages on the main thread in the phone process. Since many
599 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
600 * inbound binder threads to the main thread in the phone process. The Binder thread
601 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
602 * on, which will be notified when the operation completes and will contain the result of the
603 * request.
604 *
605 * <p>If a MainThreadRequest object is provided in the msg.obj field,
606 * note that request.result must be set to something non-null for the calling thread to
607 * unblock.
608 */
609 private final class MainThreadHandler extends Handler {
610 @Override
611 public void handleMessage(Message msg) {
612 MainThreadRequest request;
613 Message onCompleted;
614 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000615 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700616 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800617 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700618
619 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700620 case CMD_HANDLE_USSD_REQUEST: {
621 request = (MainThreadRequest) msg.obj;
622 final Phone phone = getPhoneFromRequest(request);
623 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800624 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700625 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700626
Pengquan Menga1bb6272018-09-06 09:59:22 -0700627 if (!isUssdApiAllowed(request.subId)) {
628 // Carrier does not support use of this API, return failure.
629 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
630 UssdResponse response = new UssdResponse(ussdRequest, null);
631 Bundle returnData = new Bundle();
632 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
633 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700634
Pengquan Menga1bb6272018-09-06 09:59:22 -0700635 request.result = true;
636 notifyRequester(request);
637 return;
638 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700639
Pengquan Menga1bb6272018-09-06 09:59:22 -0700640 try {
641 request.result = phone != null
642 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
643 } catch (CallStateException cse) {
644 request.result = false;
645 }
646 // Wake up the requesting thread
647 notifyRequester(request);
648 break;
pkanwar32d516d2016-10-14 19:37:38 -0700649 }
650
Yorke Lee716f67e2015-06-17 15:39:16 -0700651 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700652 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700653 final Phone phone = getPhoneFromRequest(request);
654 request.result = phone != null ?
655 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
656 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700657 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700658 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700659 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700660 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700661
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700662 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700663 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700664 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000665 uiccPort = getUiccPortFromRequest(request);
666 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700667 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800668 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700669 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700670 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700671 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800672 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000673 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800674 iccArgument.channel, iccArgument.cla, iccArgument.command,
675 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
676 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700677 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700678 break;
679
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700680 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700681 ar = (AsyncResult) msg.obj;
682 request = (MainThreadRequest) ar.userObj;
683 if (ar.exception == null && ar.result != null) {
684 request.result = ar.result;
685 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800686 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700687 if (ar.result == null) {
688 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800689 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700690 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800691 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700692 } else {
693 loge("iccTransmitApduLogicalChannel: Unknown exception");
694 }
695 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700696 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700697 break;
698
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700699 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
700 request = (MainThreadRequest) msg.obj;
701 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000702 uiccPort = getUiccPortFromRequest(request);
703 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700704 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800705 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700706 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700707 } else {
708 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800709 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000710 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800711 iccArgument.cla, iccArgument.command, iccArgument.p1,
712 iccArgument.p2,
713 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700714 }
715 break;
716
717 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
718 ar = (AsyncResult) msg.obj;
719 request = (MainThreadRequest) ar.userObj;
720 if (ar.exception == null && ar.result != null) {
721 request.result = ar.result;
722 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800723 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700724 if (ar.result == null) {
725 loge("iccTransmitApduBasicChannel: Empty response");
726 } else if (ar.exception instanceof CommandException) {
727 loge("iccTransmitApduBasicChannel: CommandException: " +
728 ar.exception);
729 } else {
730 loge("iccTransmitApduBasicChannel: Unknown exception");
731 }
732 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700733 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700734 break;
735
736 case CMD_EXCHANGE_SIM_IO:
737 request = (MainThreadRequest) msg.obj;
738 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000739 uiccPort = getUiccPortFromRequest(request);
740 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700741 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800742 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700743 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700744 } else {
745 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
746 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000747 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700748 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
749 iccArgument.data, onCompleted);
750 }
751 break;
752
753 case EVENT_EXCHANGE_SIM_IO_DONE:
754 ar = (AsyncResult) msg.obj;
755 request = (MainThreadRequest) ar.userObj;
756 if (ar.exception == null && ar.result != null) {
757 request.result = ar.result;
758 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800759 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700760 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700761 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700762 break;
763
Derek Tan4d5e5c12014-02-04 11:54:58 -0800764 case CMD_SEND_ENVELOPE:
765 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000766 uiccPort = getUiccPortFromRequest(request);
767 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700768 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800769 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700770 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700771 } else {
772 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800773 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700774 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800775 break;
776
777 case EVENT_SEND_ENVELOPE_DONE:
778 ar = (AsyncResult) msg.obj;
779 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700780 if (ar.exception == null && ar.result != null) {
781 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800782 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800783 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700784 if (ar.result == null) {
785 loge("sendEnvelopeWithStatus: Empty response");
786 } else if (ar.exception instanceof CommandException) {
787 loge("sendEnvelopeWithStatus: CommandException: " +
788 ar.exception);
789 } else {
790 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
791 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800792 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700793 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800794 break;
795
Shishir Agrawal566b7612013-10-28 14:41:00 -0700796 case CMD_OPEN_CHANNEL:
797 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000798 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800799 IccLogicalChannelRequest openChannelRequest =
800 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000801 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700802 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800803 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800804 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700805 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700806 } else {
807 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800808 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
809 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700810 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700811 break;
812
813 case EVENT_OPEN_CHANNEL_DONE:
814 ar = (AsyncResult) msg.obj;
815 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700816 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700817 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700818 int[] result = (int[]) ar.result;
819 int channelId = result[0];
820 byte[] selectResponse = null;
821 if (result.length > 1) {
822 selectResponse = new byte[result.length - 1];
823 for (int i = 1; i < result.length; ++i) {
824 selectResponse[i - 1] = (byte) result[i];
825 }
826 }
827 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800828 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800829
830 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700831 if (uiccPort == null) {
832 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
833 } else {
834 IccLogicalChannelRequest channelRequest =
835 (IccLogicalChannelRequest) request.argument;
836 channelRequest.channel = channelId;
837 uiccPort.onLogicalChannelOpened(channelRequest);
838 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700839 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700840 if (ar.result == null) {
841 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700842 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700843 if (ar.exception != null) {
844 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
845 }
846
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700847 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700848 if (ar.exception instanceof CommandException) {
849 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800850 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700851 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700852 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700853 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700854 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700855 }
856 }
857 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800858 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700859 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700860 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700861 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700862 break;
863
864 case CMD_CLOSE_CHANNEL:
865 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000866 uiccPort = getUiccPortFromRequest(request);
867 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700868 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800869 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800870 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800871 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700872 } else {
873 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000874 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700875 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700876 break;
877
878 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800879 ar = (AsyncResult) msg.obj;
880 request = (MainThreadRequest) ar.userObj;
881 if (ar.exception == null) {
882 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800883 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700884 if (uiccPort == null) {
885 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
886 } else {
887 final int channelId = (Integer) request.argument;
888 uiccPort.onLogicalChannelClosed(channelId);
889 }
Chen Xu540470b2021-12-14 17:15:47 -0800890 } else {
891 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800892 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800893 if (ar.exception instanceof CommandException) {
894 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
895 CommandException.Error error =
896 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800897 if (error == CommandException.Error.INVALID_ARGUMENTS) {
898 // should only throw exceptions from the binder threads.
899 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800900 "iccCloseLogicalChannel: invalid argument ");
901 }
902 } else {
903 loge("iccCloseLogicalChannel: Unknown exception");
904 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800905 request.result = (exception != null) ? exception :
906 new IllegalStateException(
907 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800908 }
909 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800910 break;
911
912 case CMD_NV_READ_ITEM:
913 request = (MainThreadRequest) msg.obj;
914 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800915 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
916 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800917 break;
918
919 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700920 ar = (AsyncResult) msg.obj;
921 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800922 if (ar.exception == null && ar.result != null) {
923 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700924 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800925 request.result = "";
926 if (ar.result == null) {
927 loge("nvReadItem: Empty response");
928 } else if (ar.exception instanceof CommandException) {
929 loge("nvReadItem: CommandException: " +
930 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700931 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800932 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700933 }
934 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700935 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700936 break;
937
Jake Hambye994d462014-02-03 13:10:13 -0800938 case CMD_NV_WRITE_ITEM:
939 request = (MainThreadRequest) msg.obj;
940 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
941 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800942 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700943 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800944 break;
945
946 case EVENT_NV_WRITE_ITEM_DONE:
947 handleNullReturnEvent(msg, "nvWriteItem");
948 break;
949
950 case CMD_NV_WRITE_CDMA_PRL:
951 request = (MainThreadRequest) msg.obj;
952 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800953 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800954 break;
955
956 case EVENT_NV_WRITE_CDMA_PRL_DONE:
957 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
958 break;
959
chen xu6dac5ab2018-10-26 17:39:23 -0700960 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800961 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700962 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800963 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800964 break;
965
chen xu6dac5ab2018-10-26 17:39:23 -0700966 case EVENT_RESET_MODEM_CONFIG_DONE:
967 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800968 break;
969
Sooraj Sasindran37444802020-08-11 10:40:43 -0700970 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
971 request = (MainThreadRequest) msg.obj;
972 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
973 request);
974 Phone phone = getPhoneFromRequest(request);
975 if (phone != null) {
976 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
977 } else {
978 loge("isNRDualConnectivityEnabled: No phone object");
979 request.result = false;
980 notifyRequester(request);
981 }
982 break;
983 }
984
985 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
986 ar = (AsyncResult) msg.obj;
987 request = (MainThreadRequest) ar.userObj;
988 if (ar.exception == null && ar.result != null) {
989 request.result = ar.result;
990 } else {
991 // request.result must be set to something non-null
992 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700993 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700994 request.result = ar.result;
995 } else {
996 request.result = false;
997 }
998 if (ar.result == null) {
999 loge("isNRDualConnectivityEnabled: Empty response");
1000 } else if (ar.exception instanceof CommandException) {
1001 loge("isNRDualConnectivityEnabled: CommandException: "
1002 + ar.exception);
1003 } else {
1004 loge("isNRDualConnectivityEnabled: Unknown exception");
1005 }
1006 }
1007 notifyRequester(request);
1008 break;
1009
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001010 case CMD_IS_VONR_ENABLED: {
1011 request = (MainThreadRequest) msg.obj;
1012 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
1013 request);
1014 Phone phone = getPhoneFromRequest(request);
1015 if (phone != null) {
1016 phone.isVoNrEnabled(onCompleted, request.workSource);
1017 } else {
1018 loge("isVoNrEnabled: No phone object");
1019 request.result = false;
1020 notifyRequester(request);
1021 }
1022 break;
1023 }
1024
1025 case EVENT_IS_VONR_ENABLED_DONE:
1026 ar = (AsyncResult) msg.obj;
1027 request = (MainThreadRequest) ar.userObj;
1028 if (ar.exception == null && ar.result != null) {
1029 request.result = ar.result;
1030 } else {
1031 // request.result must be set to something non-null
1032 // for the calling thread to unblock
1033 if (ar.result != null) {
1034 request.result = ar.result;
1035 } else {
1036 request.result = false;
1037 }
1038 if (ar.result == null) {
1039 loge("isVoNrEnabled: Empty response");
1040 } else if (ar.exception instanceof CommandException) {
1041 loge("isVoNrEnabled: CommandException: "
1042 + ar.exception);
1043 } else {
1044 loge("isVoNrEnabled: Unknown exception");
1045 }
1046 }
1047 notifyRequester(request);
1048 break;
1049
Sooraj Sasindran37444802020-08-11 10:40:43 -07001050 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1051 request = (MainThreadRequest) msg.obj;
1052 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1053 Phone phone = getPhoneFromRequest(request);
1054 if (phone != null) {
1055 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1056 request.workSource);
1057 } else {
1058 loge("enableNrDualConnectivity: No phone object");
1059 request.result =
1060 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1061 notifyRequester(request);
1062 }
1063 break;
1064 }
1065
1066 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1067 ar = (AsyncResult) msg.obj;
1068 request = (MainThreadRequest) ar.userObj;
1069 if (ar.exception == null) {
1070 request.result =
1071 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1072 } else {
1073 request.result =
1074 TelephonyManager
1075 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1076 if (ar.exception instanceof CommandException) {
1077 CommandException.Error error =
1078 ((CommandException) (ar.exception)).getCommandError();
1079 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1080 request.result =
1081 TelephonyManager
1082 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001083 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1084 request.result =
1085 TelephonyManager
1086 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001087 }
1088 loge("enableNrDualConnectivity" + ": CommandException: "
1089 + ar.exception);
1090 } else {
1091 loge("enableNrDualConnectivity" + ": Unknown exception");
1092 }
1093 }
1094 notifyRequester(request);
1095 break;
1096 }
1097
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001098 case CMD_ENABLE_VONR: {
1099 request = (MainThreadRequest) msg.obj;
1100 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1101 Phone phone = getPhoneFromRequest(request);
1102 if (phone != null) {
1103 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1104 request.workSource);
1105 } else {
1106 loge("setVoNrEnabled: No phone object");
1107 request.result =
1108 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1109 notifyRequester(request);
1110 }
1111 break;
1112 }
1113
1114 case EVENT_ENABLE_VONR_DONE: {
1115 ar = (AsyncResult) msg.obj;
1116 request = (MainThreadRequest) ar.userObj;
1117 if (ar.exception == null) {
1118 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1119 } else {
1120 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1121 if (ar.exception instanceof CommandException) {
1122 CommandException.Error error =
1123 ((CommandException) (ar.exception)).getCommandError();
1124 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1125 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1126 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1127 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1128 } else {
1129 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1130 }
1131 loge("setVoNrEnabled" + ": CommandException: "
1132 + ar.exception);
1133 } else {
1134 loge("setVoNrEnabled" + ": Unknown exception");
1135 }
1136 }
1137 notifyRequester(request);
1138 break;
1139 }
1140
SongFerngWang3ef3e072020-12-21 16:41:52 +08001141 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001142 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001143 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1144 request);
1145 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001146 break;
1147
SongFerngWang3ef3e072020-12-21 16:41:52 +08001148 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001149 ar = (AsyncResult) msg.obj;
1150 request = (MainThreadRequest) ar.userObj;
1151 if (ar.exception == null && ar.result != null) {
1152 request.result = ar.result; // Integer
1153 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301154 // request.result must be set to something non-null
1155 // for the calling thread to unblock
1156 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001157 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001158 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001159 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001160 loge("getAllowedNetworkTypesBitmask: CommandException: "
1161 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001162 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001163 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001164 }
1165 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001166 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001167 break;
1168
SongFerngWang3ef3e072020-12-21 16:41:52 +08001169 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001170 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001171 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1172 request);
1173 Pair<Integer, Long> reasonWithNetworkTypes =
1174 (Pair<Integer, Long>) request.argument;
1175 getPhoneFromRequest(request).setAllowedNetworkTypes(
1176 reasonWithNetworkTypes.first,
1177 reasonWithNetworkTypes.second,
1178 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001179 break;
1180
SongFerngWang3ef3e072020-12-21 16:41:52 +08001181 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1182 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001183 break;
1184
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001185 case CMD_SET_VOICEMAIL_NUMBER:
1186 request = (MainThreadRequest) msg.obj;
1187 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1188 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001189 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1190 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001191 break;
1192
1193 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1194 handleNullReturnEvent(msg, "setVoicemailNumber");
1195 break;
1196
Stuart Scott54788802015-03-30 13:18:01 -07001197 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1198 request = (MainThreadRequest) msg.obj;
1199 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1200 request);
1201 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1202 break;
1203
1204 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1205 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1206 break;
1207
Shishir Agrawal302c8692015-06-19 13:49:39 -07001208 case CMD_PERFORM_NETWORK_SCAN:
1209 request = (MainThreadRequest) msg.obj;
1210 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1211 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1212 break;
1213
Hall Liu27d24262020-09-18 19:04:59 -07001214 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001215 request = (MainThreadRequest) msg.obj;
1216 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001217 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1218 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1219 request.argument;
1220 int callForwardingReason = args.first;
1221 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001222 break;
Hall Liu27d24262020-09-18 19:04:59 -07001223 }
1224 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001225 ar = (AsyncResult) msg.obj;
1226 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001227 TelephonyManager.CallForwardingInfoCallback callback =
1228 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1229 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001230 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001231 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001232 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1233 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1234 // Service Class is a bit mask per 3gpp 27.007. Search for
1235 // any service for voice call.
1236 if ((callForwardInfo.serviceClass
1237 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001238 callForwardingInfo = new CallForwardingInfo(
1239 callForwardInfo.status
1240 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001241 callForwardInfo.reason,
1242 callForwardInfo.number,
1243 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001244 break;
1245 }
1246 }
1247 // Didn't find a call forward info for voice call.
1248 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001249 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1250 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001251 }
Hall Liu27d24262020-09-18 19:04:59 -07001252 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001253 } else {
1254 if (ar.result == null) {
1255 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1256 }
1257 if (ar.exception != null) {
1258 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1259 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001260 int errorCode = TelephonyManager
1261 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001262 if (ar.exception instanceof CommandException) {
1263 CommandException.Error error =
1264 ((CommandException) (ar.exception)).getCommandError();
1265 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001266 errorCode = TelephonyManager
1267 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001268 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001269 errorCode = TelephonyManager
1270 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001271 }
1272 }
Hall Liu27d24262020-09-18 19:04:59 -07001273 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001274 }
Shuo Qian4a594052020-01-23 11:59:30 -08001275 break;
Hall Liu27d24262020-09-18 19:04:59 -07001276 }
Shuo Qian4a594052020-01-23 11:59:30 -08001277
Hall Liu27d24262020-09-18 19:04:59 -07001278 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001279 request = (MainThreadRequest) msg.obj;
1280 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001281 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001282 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001283 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1284 request.argument).first;
1285 request.phone.setCallForwardingOption(
1286 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001287 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001288 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001289 callForwardingInfoToSet.getReason(),
1290 callForwardingInfoToSet.getNumber(),
1291 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1292 break;
Hall Liu27d24262020-09-18 19:04:59 -07001293 }
Shuo Qian4a594052020-01-23 11:59:30 -08001294
Hall Liu27d24262020-09-18 19:04:59 -07001295 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001296 ar = (AsyncResult) msg.obj;
1297 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001298 Consumer<Integer> callback =
1299 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1300 request.argument).second;
1301 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001302 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001303 int errorCode = TelephonyManager.CallForwardingInfoCallback
1304 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001305 if (ar.exception instanceof CommandException) {
1306 CommandException.Error error =
1307 ((CommandException) (ar.exception)).getCommandError();
1308 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001309 errorCode = TelephonyManager.CallForwardingInfoCallback
1310 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001311 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001312 errorCode = TelephonyManager.CallForwardingInfoCallback
1313 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001314 }
1315 }
1316 callback.accept(errorCode);
1317 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001318 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001319 }
Shuo Qian4a594052020-01-23 11:59:30 -08001320 break;
Hall Liu27d24262020-09-18 19:04:59 -07001321 }
Shuo Qian4a594052020-01-23 11:59:30 -08001322
Hall Liu27d24262020-09-18 19:04:59 -07001323 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001324 request = (MainThreadRequest) msg.obj;
1325 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1326 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1327 break;
Hall Liu27d24262020-09-18 19:04:59 -07001328 }
Shuo Qian4a594052020-01-23 11:59:30 -08001329
Hall Liu27d24262020-09-18 19:04:59 -07001330 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001331 ar = (AsyncResult) msg.obj;
1332 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001333 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001334 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001335 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001336 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001337 // Service Class is a bit mask per 3gpp 27.007.
1338 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001339 if (callForwardResults.length > 1
1340 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001341 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001342 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001343 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1344 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001345 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001346 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001347 }
1348 } else {
1349 if (ar.result == null) {
1350 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1351 }
1352 if (ar.exception != null) {
1353 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1354 }
1355 if (ar.exception instanceof CommandException) {
1356 CommandException.Error error =
1357 ((CommandException) (ar.exception)).getCommandError();
1358 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001359 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001360 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001361 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1362 callWaitingStatus =
1363 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001364 }
1365 }
1366 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001367 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001368 break;
Hall Liu27d24262020-09-18 19:04:59 -07001369 }
Shuo Qian4a594052020-01-23 11:59:30 -08001370
Hall Liu27d24262020-09-18 19:04:59 -07001371 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001372 request = (MainThreadRequest) msg.obj;
1373 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001374 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1375 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001376 break;
Hall Liu27d24262020-09-18 19:04:59 -07001377 }
Shuo Qian4a594052020-01-23 11:59:30 -08001378
Hall Liu27d24262020-09-18 19:04:59 -07001379 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001380 ar = (AsyncResult) msg.obj;
1381 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001382 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1383 Consumer<Integer> callback =
1384 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1385 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001386 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001387 if (ar.exception instanceof CommandException) {
1388 CommandException.Error error =
1389 ((CommandException) (ar.exception)).getCommandError();
1390 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1391 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001392 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1393 callback.accept(
1394 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001395 } else {
1396 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1397 }
1398 } else {
1399 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1400 }
1401 } else {
1402 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1403 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001404 }
Shuo Qian4a594052020-01-23 11:59:30 -08001405 break;
Hall Liu27d24262020-09-18 19:04:59 -07001406 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001407 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1408 ar = (AsyncResult) msg.obj;
1409 request = (MainThreadRequest) ar.userObj;
1410 CellNetworkScanResult cellScanResult;
1411 if (ar.exception == null && ar.result != null) {
1412 cellScanResult = new CellNetworkScanResult(
1413 CellNetworkScanResult.STATUS_SUCCESS,
1414 (List<OperatorInfo>) ar.result);
1415 } else {
1416 if (ar.result == null) {
1417 loge("getCellNetworkScanResults: Empty response");
1418 }
1419 if (ar.exception != null) {
1420 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1421 }
1422 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1423 if (ar.exception instanceof CommandException) {
1424 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001425 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001426 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1427 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1428 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1429 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1430 }
1431 }
1432 cellScanResult = new CellNetworkScanResult(errorCode, null);
1433 }
1434 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001435 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001436 break;
1437
1438 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1439 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001440 ManualNetworkSelectionArgument selArg =
1441 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001442 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1443 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001444 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1445 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001446 break;
1447
1448 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001449 ar = (AsyncResult) msg.obj;
1450 request = (MainThreadRequest) ar.userObj;
1451 if (ar.exception == null) {
1452 request.result = true;
1453 } else {
1454 request.result = false;
1455 loge("setNetworkSelectionModeManual " + ar.exception);
1456 }
1457 notifyRequester(request);
1458 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001459 break;
1460
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001461 case CMD_GET_MODEM_ACTIVITY_INFO:
1462 request = (MainThreadRequest) msg.obj;
1463 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001464 if (defaultPhone != null) {
1465 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001466 } else {
1467 ResultReceiver result = (ResultReceiver) request.argument;
1468 Bundle bundle = new Bundle();
1469 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001470 new ModemActivityInfo(0, 0, 0,
1471 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001472 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001473 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001474 break;
1475
Hall Liud0f208c2020-10-14 16:54:44 -07001476 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001477 ar = (AsyncResult) msg.obj;
1478 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001479 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001480 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001481 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001482 if (mLastModemActivityInfo == null) {
1483 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1484 mLastModemActivitySpecificInfo[0] =
1485 new ActivityStatsTechSpecificInfo(
1486 0,
1487 0,
1488 new int[ModemActivityInfo.getNumTxPowerLevels()],
1489 0);
1490 mLastModemActivityInfo =
1491 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1492 }
1493
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001494 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001495 // Update the last modem activity info and the result of the request.
1496 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1497 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001498 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001499 } else {
1500 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001501 }
Kai Shi917fdc62022-11-28 14:01:02 -08001502 // This is needed to decouple ret from mLastModemActivityInfo
1503 // We don't want to return mLastModemActivityInfo which is updated
1504 // inside mergeModemActivityInfo()
1505 ret = new ModemActivityInfo(
1506 mLastModemActivityInfo.getTimestampMillis(),
1507 mLastModemActivityInfo.getSleepTimeMillis(),
1508 mLastModemActivityInfo.getIdleTimeMillis(),
1509 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001510
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001511 } else {
1512 if (ar.result == null) {
1513 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001514 error = TelephonyManager.ModemActivityInfoException
1515 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001516 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001517 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001518 error = TelephonyManager.ModemActivityInfoException
1519 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001520 } else {
1521 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001522 error = TelephonyManager.ModemActivityInfoException
1523 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001524 }
1525 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001526 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001527 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001528 bundle.putParcelable(
1529 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001530 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001531 } else {
1532 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1533 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001534 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001535 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001536 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001537 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001538
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001539 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001540 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001541 CarrierRestrictionRules argument =
1542 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001543 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001544 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001545 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001546 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001547
1548 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1549 ar = (AsyncResult) msg.obj;
1550 request = (MainThreadRequest) ar.userObj;
1551 if (ar.exception == null && ar.result != null) {
1552 request.result = ar.result;
1553 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001554 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1555 if (ar.exception instanceof CommandException) {
1556 loge("setAllowedCarriers: CommandException: " + ar.exception);
1557 CommandException.Error error =
1558 ((CommandException) (ar.exception)).getCommandError();
1559 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1560 request.result =
1561 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1562 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001563 } else {
1564 loge("setAllowedCarriers: Unknown exception");
1565 }
1566 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001567 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001568 break;
1569
1570 case CMD_GET_ALLOWED_CARRIERS:
1571 request = (MainThreadRequest) msg.obj;
1572 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001573 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001574 break;
1575
1576 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1577 ar = (AsyncResult) msg.obj;
1578 request = (MainThreadRequest) ar.userObj;
1579 if (ar.exception == null && ar.result != null) {
1580 request.result = ar.result;
1581 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001582 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001583 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001584 if (ar.result == null) {
1585 loge("getAllowedCarriers: Empty response");
1586 } else if (ar.exception instanceof CommandException) {
1587 loge("getAllowedCarriers: CommandException: " +
1588 ar.exception);
1589 } else {
1590 loge("getAllowedCarriers: Unknown exception");
1591 }
1592 }
arunvoddud7401012022-12-15 16:08:12 +00001593 if (request.argument != null) {
1594 // This is for the implementation of carrierRestrictionStatus.
1595 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1596 Consumer<Integer> callback = callbackInfo.getConsumer();
Steve Statia28b7cb32024-03-11 23:58:50 +00001597 Set<Integer> callerCarrierIds = callbackInfo.getCarrierIds();
arunvoddud7401012022-12-15 16:08:12 +00001598 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1599 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1600 CarrierRestrictionRules carrierRestrictionRules =
1601 (CarrierRestrictionRules) ar.result;
1602 int carrierId = -1;
1603 try {
1604 CarrierIdentifier carrierIdentifier =
1605 carrierRestrictionRules.getAllowedCarriers().get(0);
1606 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1607 carrierIdentifier);
1608 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1609 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1610 }
1611 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
Steve Statia28b7cb32024-03-11 23:58:50 +00001612 int restrictedStatus =
1613 TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED;
1614 if (carrierId != -1 && callerCarrierIds.contains(carrierId) &&
1615 lockStatus == restrictedStatus) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001616 lockStatus = TelephonyManager
1617 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001618 }
1619 } else {
1620 Rlog.e(LOG_TAG,
1621 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1622 }
1623 callback.accept(lockStatus);
1624 } else {
1625 // This is for the implementation of getAllowedCarriers.
1626 notifyRequester(request);
1627 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001628 break;
1629
Nathan Haroldb3014052017-01-25 15:57:32 -08001630 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1631 ar = (AsyncResult) msg.obj;
1632 request = (MainThreadRequest) ar.userObj;
1633 if (ar.exception == null && ar.result != null) {
1634 request.result = ar.result;
1635 } else {
1636 request.result = new IllegalArgumentException(
1637 "Failed to retrieve Forbidden Plmns");
1638 if (ar.result == null) {
1639 loge("getForbiddenPlmns: Empty response");
1640 } else {
1641 loge("getForbiddenPlmns: Unknown exception");
1642 }
1643 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001644 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001645 break;
1646
1647 case CMD_GET_FORBIDDEN_PLMNS:
1648 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001649 uiccPort = getUiccPortFromRequest(request);
1650 if (uiccPort == null) {
1651 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001652 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001653 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001654 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001655 break;
1656 }
1657 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001658 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001659 if (uiccApp == null) {
1660 loge("getForbiddenPlmns() no app with specified type -- "
1661 + appType);
1662 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001663 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001664 break;
1665 } else {
1666 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1667 + " specified type -- " + appType);
1668 }
1669 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1670 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001671 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001672 break;
1673
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001674 case CMD_SWITCH_SLOTS:
1675 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001676 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001677 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001678 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001679 break;
1680
1681 case EVENT_SWITCH_SLOTS_DONE:
1682 ar = (AsyncResult) msg.obj;
1683 request = (MainThreadRequest) ar.userObj;
1684 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001685 notifyRequester(request);
1686 break;
1687 case CMD_GET_NETWORK_SELECTION_MODE:
1688 request = (MainThreadRequest) msg.obj;
1689 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1690 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1691 break;
1692
1693 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1694 ar = (AsyncResult) msg.obj;
1695 request = (MainThreadRequest) ar.userObj;
1696 if (ar.exception != null) {
1697 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1698 } else {
1699 int mode = ((int[]) ar.result)[0];
1700 if (mode == 0) {
1701 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1702 } else {
1703 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1704 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001705 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001706 notifyRequester(request);
1707 break;
1708 case CMD_GET_CDMA_ROAMING_MODE:
1709 request = (MainThreadRequest) msg.obj;
1710 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1711 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1712 break;
1713 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1714 ar = (AsyncResult) msg.obj;
1715 request = (MainThreadRequest) ar.userObj;
1716 if (ar.exception != null) {
1717 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1718 } else {
1719 request.result = ((int[]) ar.result)[0];
1720 }
1721 notifyRequester(request);
1722 break;
1723 case CMD_SET_CDMA_ROAMING_MODE:
1724 request = (MainThreadRequest) msg.obj;
1725 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1726 int mode = (int) request.argument;
1727 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1728 break;
1729 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1730 ar = (AsyncResult) msg.obj;
1731 request = (MainThreadRequest) ar.userObj;
1732 request.result = ar.exception == null;
1733 notifyRequester(request);
1734 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001735 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1736 request = (MainThreadRequest) msg.obj;
1737 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1738 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1739 break;
1740 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1741 ar = (AsyncResult) msg.obj;
1742 request = (MainThreadRequest) ar.userObj;
1743 if (ar.exception != null) {
1744 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1745 } else {
1746 request.result = ((int[]) ar.result)[0];
1747 }
1748 notifyRequester(request);
1749 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001750 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1751 request = (MainThreadRequest) msg.obj;
1752 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1753 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001754 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1755 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001756 break;
1757 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1758 ar = (AsyncResult) msg.obj;
1759 request = (MainThreadRequest) ar.userObj;
1760 request.result = ar.exception == null;
1761 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001762 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001763 case CMD_GET_ALL_CELL_INFO:
1764 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001765 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001766 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001767 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001768 case EVENT_GET_ALL_CELL_INFO_DONE:
1769 ar = (AsyncResult) msg.obj;
1770 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001771 // If a timeout occurs, the response will be null
1772 request.result = (ar.exception == null && ar.result != null)
1773 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001774 synchronized (request) {
1775 request.notifyAll();
1776 }
1777 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001778 case CMD_REQUEST_CELL_INFO_UPDATE:
1779 request = (MainThreadRequest) msg.obj;
1780 request.phone.requestCellInfoUpdate(request.workSource,
1781 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1782 break;
1783 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1784 ar = (AsyncResult) msg.obj;
1785 request = (MainThreadRequest) ar.userObj;
1786 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1787 try {
1788 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001789 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001790 cb.onError(
1791 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1792 ar.exception.getClass().getName(),
1793 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001794 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001795 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001796 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001797 } else {
1798 // use the result as returned
1799 cb.onCellInfo((List<CellInfo>) ar.result);
1800 }
1801 } catch (RemoteException re) {
1802 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1803 }
1804 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001805 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001806 request = (MainThreadRequest) msg.obj;
1807 WorkSource ws = (WorkSource) request.argument;
1808 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001809 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001810 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001811 }
1812 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001813 ar = (AsyncResult) msg.obj;
1814 request = (MainThreadRequest) ar.userObj;
1815 if (ar.exception == null) {
1816 request.result = ar.result;
1817 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001818 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001819 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001820 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001821 }
1822
1823 synchronized (request) {
1824 request.notifyAll();
1825 }
1826 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001827 }
chen xu6dac5ab2018-10-26 17:39:23 -07001828 case CMD_MODEM_REBOOT:
1829 request = (MainThreadRequest) msg.obj;
1830 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001831 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001832 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001833 case EVENT_CMD_MODEM_REBOOT_DONE:
1834 handleNullReturnEvent(msg, "rebootModem");
1835 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001836 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001837 request = (MainThreadRequest) msg.obj;
1838 boolean enable = (boolean) request.argument;
1839 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001840 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001841 PhoneConfigurationManager.getInstance()
1842 .enablePhone(request.phone, enable, onCompleted);
1843 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001844 }
Michele Berionne5e411512020-11-13 02:36:59 +00001845 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001846 ar = (AsyncResult) msg.obj;
1847 request = (MainThreadRequest) ar.userObj;
1848 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001849 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001850 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001851 if ((boolean) request.result) {
1852 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1853 updateModemStateMetrics();
1854 } else {
1855 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1856 + ar.exception);
1857 }
1858 notifyRequester(request);
1859 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001860 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001861 case CMD_GET_MODEM_STATUS:
1862 request = (MainThreadRequest) msg.obj;
1863 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1864 PhoneConfigurationManager.getInstance()
1865 .getPhoneStatusFromModem(request.phone, onCompleted);
1866 break;
1867 case EVENT_GET_MODEM_STATUS_DONE:
1868 ar = (AsyncResult) msg.obj;
1869 request = (MainThreadRequest) ar.userObj;
1870 int id = request.phone.getPhoneId();
1871 if (ar.exception == null && ar.result != null) {
1872 request.result = ar.result;
1873 //update the cache as modem status has changed
1874 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1875 (boolean) request.result);
1876 } else {
1877 // Return true if modem status cannot be retrieved. For most cases,
1878 // modem status is on. And for older version modems, GET_MODEM_STATUS
1879 // and disable modem are not supported. Modem is always on.
1880 // TODO: this should be fixed in R to support a third
1881 // status UNKNOWN b/131631629
1882 request.result = true;
1883 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1884 + ar.exception);
1885 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001886 notifyRequester(request);
1887 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001888 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1889 request = (MainThreadRequest) msg.obj;
1890 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1891 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1892 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1893 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1894 break;
1895 }
1896 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1897 ar = (AsyncResult) msg.obj;
1898 request = (MainThreadRequest) ar.userObj;
1899 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1900 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1901 args.second.accept(ar.exception == null);
1902 notifyRequester(request);
1903 break;
1904 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001905 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1906 request = (MainThreadRequest) msg.obj;
1907 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1908 Phone phone = getPhoneFromRequest(request);
1909 if (phone != null) {
1910 phone.getSystemSelectionChannels(onCompleted);
1911 } else {
1912 loge("getSystemSelectionChannels: No phone object");
1913 request.result = new ArrayList<RadioAccessSpecifier>();
1914 notifyRequester(request);
1915 }
1916 break;
1917 }
1918 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1919 ar = (AsyncResult) msg.obj;
1920 request = (MainThreadRequest) ar.userObj;
1921 if (ar.exception == null && ar.result != null) {
1922 request.result = ar.result;
1923 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001924 request.result = new IllegalStateException(
1925 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001926 if (ar.result == null) {
1927 loge("getSystemSelectionChannels: Empty response");
1928 } else {
1929 loge("getSystemSelectionChannels: Unknown exception");
1930 }
1931 }
1932 notifyRequester(request);
1933 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001934 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1935 ar = (AsyncResult) msg.obj;
1936 request = (MainThreadRequest) ar.userObj;
1937 if (ar.exception == null && ar.result != null) {
1938 request.result = ar.result;
1939 } else {
1940 request.result = -1;
1941 loge("Failed to set Forbidden Plmns");
1942 if (ar.result == null) {
1943 loge("setForbidenPlmns: Empty response");
1944 } else if (ar.exception != null) {
1945 loge("setForbiddenPlmns: Exception: " + ar.exception);
1946 request.result = -1;
1947 } else {
1948 loge("setForbiddenPlmns: Unknown exception");
1949 }
1950 }
1951 notifyRequester(request);
1952 break;
1953 case CMD_SET_FORBIDDEN_PLMNS:
1954 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001955 uiccPort = getUiccPortFromRequest(request);
1956 if (uiccPort == null) {
1957 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001958 request.result = -1;
1959 notifyRequester(request);
1960 break;
1961 }
1962 Pair<Integer, List<String>> setFplmnsArgs =
1963 (Pair<Integer, List<String>>) request.argument;
1964 appType = setFplmnsArgs.first;
1965 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001966 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001967 if (uiccApp == null) {
1968 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1969 request.result = -1;
1970 loge("Failed to get UICC App");
1971 notifyRequester(request);
1972 } else {
1973 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1974 ((SIMRecords) uiccApp.getIccRecords())
1975 .setForbiddenPlmns(onCompleted, fplmns);
1976 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001977 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001978 case CMD_ERASE_MODEM_CONFIG:
1979 request = (MainThreadRequest) msg.obj;
1980 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1981 defaultPhone.eraseModemConfig(onCompleted);
1982 break;
1983 case EVENT_ERASE_MODEM_CONFIG_DONE:
1984 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001985 break;
zoey chene02881a2019-12-30 16:11:23 +08001986
Kai Shif70f46f2021-03-03 13:59:46 -08001987 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1988 request = (MainThreadRequest) msg.obj;
1989 request.result = defaultPhone.eraseDataInSharedPreferences();
1990 notifyRequester(request);
1991 break;
1992
zoey chene02881a2019-12-30 16:11:23 +08001993 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1994 request = (MainThreadRequest) msg.obj;
1995 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1996 Pair<String, String> changed = (Pair<String, String>) request.argument;
1997 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1998 changed.first, changed.second, onCompleted);
1999 break;
2000 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
2001 ar = (AsyncResult) msg.obj;
2002 request = (MainThreadRequest) ar.userObj;
2003 if (ar.exception == null) {
2004 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002005 // If the operation is successful, update the PIN storage
2006 Pair<String, String> passwords = (Pair<String, String>) request.argument;
2007 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00002008 UiccController.getInstance().getPinStorage()
2009 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08002010 } else {
2011 request.result = msg.arg1;
2012 }
2013 notifyRequester(request);
2014 break;
2015
Michele Berionne5e411512020-11-13 02:36:59 +00002016 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08002017 request = (MainThreadRequest) msg.obj;
2018 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
2019 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2020 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2021 enabled.first, enabled.second, onCompleted);
2022 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002023 }
zoey chene02881a2019-12-30 16:11:23 +08002024 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2025 ar = (AsyncResult) msg.obj;
2026 request = (MainThreadRequest) ar.userObj;
2027 if (ar.exception == null) {
2028 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002029 // If the operation is successful, update the PIN storage
2030 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2031 int phoneId = getPhoneFromRequest(request).getPhoneId();
2032 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002033 UiccController.getInstance().getPinStorage()
2034 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002035 } else {
2036 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2037 }
zoey chene02881a2019-12-30 16:11:23 +08002038 } else {
2039 request.result = msg.arg1;
2040 }
Michele Berionne5e411512020-11-13 02:36:59 +00002041
2042
zoey chene02881a2019-12-30 16:11:23 +08002043 notifyRequester(request);
2044 break;
2045
Peter Wangdafb9ac2020-01-15 14:13:38 -08002046 case MSG_NOTIFY_USER_ACTIVITY:
2047 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002048 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002049 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2050 getDefaultPhone().getContext().sendBroadcastAsUser(
2051 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2052 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002053
2054 case CMD_SET_DATA_THROTTLING: {
2055 request = (MainThreadRequest) msg.obj;
2056 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2057 DataThrottlingRequest dataThrottlingRequest =
2058 (DataThrottlingRequest) request.argument;
2059 Phone phone = getPhoneFromRequest(request);
2060 if (phone != null) {
2061 phone.setDataThrottling(onCompleted,
2062 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2063 dataThrottlingRequest.getCompletionDurationMillis());
2064 } else {
2065 loge("setDataThrottling: No phone object");
2066 request.result =
2067 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2068 notifyRequester(request);
2069 }
2070
2071 break;
2072 }
2073 case EVENT_SET_DATA_THROTTLING_DONE:
2074 ar = (AsyncResult) msg.obj;
2075 request = (MainThreadRequest) ar.userObj;
2076
2077 if (ar.exception == null) {
2078 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2079 } else if (ar.exception instanceof CommandException) {
2080 loge("setDataThrottling: CommandException: " + ar.exception);
2081 CommandException.Error error =
2082 ((CommandException) (ar.exception)).getCommandError();
2083
2084 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2085 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002086 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002087 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2088 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002089 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2090 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002091 } else {
2092 request.result =
2093 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2094 }
2095 } else {
2096 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2097 }
2098 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2099 notifyRequester(request);
2100 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002101
2102 case CMD_SET_SIM_POWER: {
2103 request = (MainThreadRequest) msg.obj;
2104 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2105 request = (MainThreadRequest) msg.obj;
2106 int stateToSet =
2107 ((Pair<Integer, IIntegerConsumer>)
2108 request.argument).first;
2109 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2110 break;
2111 }
2112 case EVENT_SET_SIM_POWER_DONE: {
2113 ar = (AsyncResult) msg.obj;
2114 request = (MainThreadRequest) ar.userObj;
2115 IIntegerConsumer callback =
2116 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2117 if (ar.exception != null) {
2118 loge("setSimPower exception: " + ar.exception);
2119 int errorCode = TelephonyManager.CallForwardingInfoCallback
2120 .RESULT_ERROR_UNKNOWN;
2121 if (ar.exception instanceof CommandException) {
2122 CommandException.Error error =
2123 ((CommandException) (ar.exception)).getCommandError();
2124 if (error == CommandException.Error.SIM_ERR) {
2125 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2126 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2127 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2128 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2129 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2130 } else {
2131 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2132 }
2133 }
2134 try {
2135 callback.accept(errorCode);
2136 } catch (RemoteException e) {
2137 // Ignore if the remote process is no longer available to call back.
2138 Log.w(LOG_TAG, "setSimPower: callback not available.");
2139 }
2140 } else {
2141 try {
2142 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2143 } catch (RemoteException e) {
2144 // Ignore if the remote process is no longer available to call back.
2145 Log.w(LOG_TAG, "setSimPower: callback not available.");
2146 }
2147 }
2148 break;
2149 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002150 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2151 request = (MainThreadRequest) msg.obj;
2152
2153 final Phone phone = getPhoneFromRequest(request);
2154 if (phone == null || phone.getServiceStateTracker() == null) {
2155 request.result = new IllegalStateException("Phone or SST is null");
2156 notifyRequester(request);
2157 break;
2158 }
2159
2160 Pair<Integer, SignalStrengthUpdateRequest> pair =
2161 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2162 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2163 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002164 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002165 request.subId, pair.first /*callingUid*/,
2166 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002167 break;
2168 }
2169 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2170 ar = (AsyncResult) msg.obj;
2171 request = (MainThreadRequest) ar.userObj;
2172 // request.result will be the exception of ar if present, true otherwise.
2173 // Be cautious not to leave result null which will wait() forever
2174 request.result = ar.exception != null ? ar.exception : true;
2175 notifyRequester(request);
2176 break;
2177 }
2178 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2179 request = (MainThreadRequest) msg.obj;
2180
2181 Phone phone = getPhoneFromRequest(request);
2182 if (phone == null || phone.getServiceStateTracker() == null) {
2183 request.result = new IllegalStateException("Phone or SST is null");
2184 notifyRequester(request);
2185 break;
2186 }
2187
2188 Pair<Integer, SignalStrengthUpdateRequest> pair =
2189 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2190 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2191 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002192 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002193 request.subId, pair.first /*callingUid*/,
2194 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002195 break;
2196 }
2197 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2198 ar = (AsyncResult) msg.obj;
2199 request = (MainThreadRequest) ar.userObj;
2200 request.result = ar.exception != null ? ar.exception : true;
2201 notifyRequester(request);
2202 break;
2203 }
Jordan Liu109698e2020-11-24 14:50:34 -08002204
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002205 case CMD_GET_SLICING_CONFIG: {
2206 request = (MainThreadRequest) msg.obj;
2207 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2208 request.phone.getSlicingConfig(onCompleted);
2209 break;
2210 }
2211 case EVENT_GET_SLICING_CONFIG_DONE: {
2212 ar = (AsyncResult) msg.obj;
2213 request = (MainThreadRequest) ar.userObj;
2214 ResultReceiver result = (ResultReceiver) request.argument;
2215
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002216 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002217 Bundle bundle = new Bundle();
2218 int resultCode = 0;
2219 if (ar.exception != null) {
2220 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2221 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002222 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002223 } else if (ar.result == null) {
2224 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002225 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002226 } else {
2227 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002228 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2229 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002230 }
2231
2232 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002233 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002234 }
2235 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2236 result.send(resultCode, bundle);
2237 notifyRequester(request);
2238 break;
2239 }
2240
Sarah Chin71b3a852022-09-28 15:54:19 -07002241 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002242 request = (MainThreadRequest) msg.obj;
2243 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002244 PurchasePremiumCapabilityArgument arg =
2245 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chincc5446f2023-10-23 17:57:19 -07002246 SlicePurchaseController.getInstance(request.phone, mFeatureFlags)
2247 .purchasePremiumCapability(arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002248 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002249 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002250
Sarah Chin71b3a852022-09-28 15:54:19 -07002251 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002252 ar = (AsyncResult) msg.obj;
2253 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002254 PurchasePremiumCapabilityArgument arg =
2255 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002256 try {
2257 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002258 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002259 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002260 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chinff8b1802023-04-11 14:22:14 -07002261 + ", result="
Sarah Chin2ec39f62022-08-31 17:03:26 -07002262 + TelephonyManager.convertPurchaseResultToString(result));
2263 } catch (RemoteException e) {
2264 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002265 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002266 + " failed: " + e;
2267 if (DBG) log(logStr);
2268 AnomalyReporter.reportAnomaly(
2269 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2270 }
2271 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002272 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002273
Michele Berionne5e411512020-11-13 02:36:59 +00002274 case CMD_PREPARE_UNATTENDED_REBOOT:
2275 request = (MainThreadRequest) msg.obj;
2276 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002277 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002278 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002279 notifyRequester(request);
2280 break;
2281
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002282 default:
2283 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2284 break;
2285 }
2286 }
Jake Hambye994d462014-02-03 13:10:13 -08002287
Pengquan Menga1bb6272018-09-06 09:59:22 -07002288 private void notifyRequester(MainThreadRequest request) {
2289 synchronized (request) {
2290 request.notifyAll();
2291 }
2292 }
2293
Jake Hambye994d462014-02-03 13:10:13 -08002294 private void handleNullReturnEvent(Message msg, String command) {
2295 AsyncResult ar = (AsyncResult) msg.obj;
2296 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2297 if (ar.exception == null) {
2298 request.result = true;
2299 } else {
2300 request.result = false;
2301 if (ar.exception instanceof CommandException) {
2302 loge(command + ": CommandException: " + ar.exception);
2303 } else {
2304 loge(command + ": Unknown exception");
2305 }
2306 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002307 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002308 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002309 }
2310
2311 /**
2312 * Posts the specified command to be executed on the main thread,
2313 * waits for the request to complete, and returns the result.
2314 * @see #sendRequestAsync
2315 */
2316 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002317 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2318 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002319 }
2320
2321 /**
2322 * Posts the specified command to be executed on the main thread,
2323 * waits for the request to complete, and returns the result.
2324 * @see #sendRequestAsync
2325 */
2326 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2327 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002328 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002329 }
2330
2331 /**
2332 * Posts the specified command to be executed on the main thread,
2333 * waits for the request to complete, and returns the result.
2334 * @see #sendRequestAsync
2335 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002336 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002337 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2338 }
2339
2340 /**
2341 * Posts the specified command to be executed on the main thread,
2342 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2343 * if not timeout or null otherwise.
2344 * @see #sendRequestAsync
2345 */
2346 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2347 long timeoutInMs) {
2348 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002349 }
2350
2351 /**
2352 * Posts the specified command to be executed on the main thread,
2353 * waits for the request to complete, and returns the result.
2354 * @see #sendRequestAsync
2355 */
Nathan Harold92bed182018-10-12 18:16:49 -07002356 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002357 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002358 }
2359
2360 /**
2361 * Posts the specified command to be executed on the main thread,
2362 * waits for the request to complete, and returns the result.
2363 * @see #sendRequestAsync
2364 */
2365 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002366 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2367 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002368 }
2369
2370 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002371 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2372 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2373 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002374 * @see #sendRequestAsync
2375 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002376 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2377 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002378 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2379 throw new RuntimeException("This method will deadlock if called from the main thread.");
2380 }
2381
Nathan Harold92bed182018-10-12 18:16:49 -07002382 MainThreadRequest request = null;
2383 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2384 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2385 } else if (phone != null) {
2386 request = new MainThreadRequest(argument, phone, workSource);
2387 } else {
2388 request = new MainThreadRequest(argument, subId, workSource);
2389 }
2390
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002391 Message msg = mMainThreadHandler.obtainMessage(command, request);
2392 msg.sendToTarget();
2393
Rambo Wang0f050d82021-02-12 11:43:36 -08002394
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002395 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002396 if (timeoutInMs >= 0) {
2397 // Wait for at least timeoutInMs before returning null request result
2398 long now = SystemClock.elapsedRealtime();
2399 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002400 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002401 try {
2402 request.wait(deadline - now);
2403 } catch (InterruptedException e) {
2404 // Do nothing, go back and check if request is completed or timeout
2405 } finally {
2406 now = SystemClock.elapsedRealtime();
2407 }
2408 }
2409 } else {
2410 // Wait for the request to complete
2411 while (request.result == null) {
2412 try {
2413 request.wait();
2414 } catch (InterruptedException e) {
2415 // Do nothing, go back and wait until the request is complete
2416 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002417 }
2418 }
2419 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002420 if (request.result == null) {
2421 Log.wtf(LOG_TAG,
2422 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2423 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002424 return request.result;
2425 }
2426
2427 /**
2428 * Asynchronous ("fire and forget") version of sendRequest():
2429 * Posts the specified command to be executed on the main thread, and
2430 * returns immediately.
2431 * @see #sendRequest
2432 */
2433 private void sendRequestAsync(int command) {
2434 mMainThreadHandler.sendEmptyMessage(command);
2435 }
2436
2437 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002438 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002439 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002440 */
2441 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002442 sendRequestAsync(command, argument, null, null);
2443 }
2444
2445 /**
2446 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2447 * @see {@link #sendRequest(int,Object)}
2448 */
2449 private void sendRequestAsync(
2450 int command, Object argument, Phone phone, WorkSource workSource) {
2451 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002452 Message msg = mMainThreadHandler.obtainMessage(command, request);
2453 msg.sendToTarget();
2454 }
2455
2456 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002457 * Initialize the singleton PhoneInterfaceManager instance.
2458 * This is only done once, at startup, from PhoneApp.onCreate().
2459 */
Sarah Chincc5446f2023-10-23 17:57:19 -07002460 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002461 synchronized (PhoneInterfaceManager.class) {
2462 if (sInstance == null) {
Sarah Chincc5446f2023-10-23 17:57:19 -07002463 sInstance = new PhoneInterfaceManager(app, featureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002464 } else {
2465 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2466 }
2467 return sInstance;
2468 }
2469 }
2470
2471 /** Private constructor; @see init() */
Sarah Chincc5446f2023-10-23 17:57:19 -07002472 private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002473 mApp = app;
Sarah Chincc5446f2023-10-23 17:57:19 -07002474 mFeatureFlags = featureFlags;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -08002475 mTelecomFeatureFlags = new com.android.server.telecom.flags.FeatureFlagsImpl();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002476 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002477 mImsResolver = ImsResolver.getInstance();
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +00002478 mSatelliteController = SatelliteController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002479 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002480 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2481 mMainThreadHandler = new MainThreadHandler();
Sarah Chin4beb2b72023-02-14 14:47:54 -08002482 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002483 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002484 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002485 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002486 mNotifyUserActivity = new AtomicBoolean(false);
joonhunshin4ac60942023-11-15 15:23:39 +00002487 mPackageManager = app.getPackageManager();
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -08002488 mSatelliteAccessController = SatelliteAccessController.getOrCreateInstance(
2489 getDefaultPhone().getContext(), featureFlags);
joonhunshinf624b2a2024-04-18 04:42:12 +00002490 mVendorApiLevel = SystemProperties.getInt(
2491 "ro.vendor.api_level", Build.VERSION.DEVICE_INITIAL_SDK_INT);
2492
Tyler Gunn64144d92022-03-17 14:16:41 -07002493 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002494 publish();
arunvoddud7401012022-12-15 16:08:12 +00002495 CarrierAllowListInfo.loadInstance(mApp);
Hyosun Kim240214a2023-11-02 13:30:15 +00002496
2497 // Create the SatelliteEntitlementController singleton, for using the get the
2498 // entitlementStatus for satellite service.
2499 SatelliteEntitlementController.make(mApp, mFeatureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002500 }
2501
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002502 @VisibleForTesting
2503 public SharedPreferences getSharedPreferences() {
2504 return mTelephonySharedPreferences;
2505 }
2506
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002507 /**
2508 * Get the default phone for this device.
2509 */
2510 @VisibleForTesting
2511 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002512 Phone thePhone = getPhone(getDefaultSubscription());
2513 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2514 }
2515
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002516 private void publish() {
2517 if (DBG) log("publish: " + this);
2518
Peter Wangc035ce42020-01-08 21:00:22 -08002519 TelephonyFrameworkInitializer
2520 .getTelephonyServiceManager()
2521 .getTelephonyServiceRegisterer()
2522 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002523 }
2524
Stuart Scott584921c2015-01-15 17:10:34 -08002525 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002526 if (request.phone != null) {
2527 return request.phone;
2528 } else {
2529 return getPhoneFromSubId(request.subId);
2530 }
2531 }
2532
2533 private Phone getPhoneFromSubId(int subId) {
2534 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2535 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002536 }
2537
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002538 /**
2539 * Get phone object associated with a subscription.
2540 * Return default phone if phone object associated with subscription is null
2541 * @param subId - subscriptionId
2542 * @return phone object associated with a subscription or default phone if null.
2543 */
Ling Mac28f0212023-03-24 16:07:15 -07002544 private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) {
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002545 Phone phone = getPhoneFromSubId(subId);
2546 if (phone == null) {
Ling Mac28f0212023-03-24 16:07:15 -07002547 loge("Called with invalid subId: " + subId + ". Retrying with default phone.");
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002548 phone = getDefaultPhone();
2549 }
2550 return phone;
2551 }
2552
Rambo Wange53e07d2022-05-10 13:01:13 -07002553 @Nullable
2554 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002555 Phone phone = getPhoneFromRequest(request);
2556 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002557 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002558 }
2559
Ling Mac28f0212023-03-24 16:07:15 -07002560 /**
2561 * @param subId The sub Id that associates the phone. If the device has no active SIM, passing
2562 * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <=
2563 * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}.
2564 * @return The Phone associated the sub Id
2565 */
2566 private @Nullable Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002567 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002568 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002569
Kai Shif70f46f2021-03-03 13:59:46 -08002570 private void sendEraseModemConfig(@NonNull Phone phone) {
2571 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2572 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2573 }
2574
2575 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2576 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2577 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002578 }
2579
Peter Wang44b186e2020-01-13 23:33:09 -08002580 private boolean isImsAvailableOnDevice() {
2581 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2582 if (pm == null) {
2583 // For some reason package manger is not available.. This will fail internally anyway,
2584 // so do not throw error and allow.
2585 return true;
2586 }
2587 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2588 }
2589
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002590 public void dial(String number) {
joonhunshin4ac60942023-11-15 15:23:39 +00002591 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2592 PackageManager.FEATURE_TELEPHONY_CALLING, "dial");
2593
Wink Savilleadd7cc52014-09-08 14:23:09 -07002594 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002595 }
2596
Wink Savilleb564aae2014-10-23 10:18:09 -07002597 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002598 if (DBG) log("dial: " + number);
2599 // No permission check needed here: This is just a wrapper around the
2600 // ACTION_DIAL intent, which is available to any app since it puts up
2601 // the UI before it does anything.
2602
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002603 final long identity = Binder.clearCallingIdentity();
2604 try {
2605 String url = createTelUrl(number);
2606 if (url == null) {
2607 return;
2608 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002609
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002610 // PENDING: should we just silently fail if phone is offhook or ringing?
2611 PhoneConstants.State state = mCM.getState(subId);
2612 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2613 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2614 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2615 mApp.startActivity(intent);
2616 }
2617 } finally {
2618 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002619 }
2620 }
2621
2622 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002623 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002624 }
2625
Wink Savilleb564aae2014-10-23 10:18:09 -07002626 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002627 if (DBG) log("call: " + number);
2628
2629 // This is just a wrapper around the ACTION_CALL intent, but we still
2630 // need to do a permission check since we're calling startActivity()
2631 // from the context of the phone app.
2632 enforceCallPermission();
2633
Jordan Liu1617b712019-07-10 15:06:26 -07002634 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002635 != AppOpsManager.MODE_ALLOWED) {
2636 return;
2637 }
2638
joonhunshin4ac60942023-11-15 15:23:39 +00002639 enforceTelephonyFeatureWithException(callingPackage,
2640 PackageManager.FEATURE_TELEPHONY_CALLING, "call");
2641
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002642 final long identity = Binder.clearCallingIdentity();
2643 try {
2644 String url = createTelUrl(number);
2645 if (url == null) {
2646 return;
2647 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002648
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002649 boolean isValid = false;
2650 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2651 if (slist != null) {
2652 for (SubscriptionInfo subInfoRecord : slist) {
2653 if (subInfoRecord.getSubscriptionId() == subId) {
2654 isValid = true;
2655 break;
2656 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002657 }
Wink Saville08874612014-08-31 19:19:58 -07002658 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002659 if (!isValid) {
2660 return;
2661 }
Wink Saville08874612014-08-31 19:19:58 -07002662
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002663 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2664 intent.putExtra(SUBSCRIPTION_KEY, subId);
2665 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2666 mApp.startActivity(intent);
2667 } finally {
2668 Binder.restoreCallingIdentity(identity);
2669 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002670 }
2671
Wink Savilleb564aae2014-10-23 10:18:09 -07002672 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002673 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002674 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2675 }
2676
Wink Savilleb564aae2014-10-23 10:18:09 -07002677 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002678 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002679 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2680 }
2681
Wink Savilleb564aae2014-10-23 10:18:09 -07002682 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002683 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002684
joonhunshin4ac60942023-11-15 15:23:39 +00002685 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2686 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
2687 "supplyPinReportResultForSubscriber");
2688
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002689 final long identity = Binder.clearCallingIdentity();
2690 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002691 Phone phone = getPhone(subId);
2692 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002693 checkSimPin.start();
2694 return checkSimPin.unlockSim(null, pin);
2695 } finally {
2696 Binder.restoreCallingIdentity(identity);
2697 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002698 }
2699
Wink Savilleb564aae2014-10-23 10:18:09 -07002700 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002701 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002702
joonhunshin4ac60942023-11-15 15:23:39 +00002703 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2704 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "supplyPukForSubscriber");
2705
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002706 final long identity = Binder.clearCallingIdentity();
2707 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002708 Phone phone = getPhone(subId);
2709 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002710 checkSimPuk.start();
2711 return checkSimPuk.unlockSim(puk, pin);
2712 } finally {
2713 Binder.restoreCallingIdentity(identity);
2714 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002715 }
2716
2717 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002718 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002719 * a synchronous one.
2720 */
2721 private static class UnlockSim extends Thread {
2722
2723 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002724 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002725
2726 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002727 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2728 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002729
2730 // For replies from SimCard interface
2731 private Handler mHandler;
2732
2733 // For async handler to identify request type
2734 private static final int SUPPLY_PIN_COMPLETE = 100;
arunvoddu7bf930c2024-05-20 04:24:40 +00002735 private static final int SUPPLY_PIN_DELAYED = 101;
2736 private static final int SUPPLY_PIN_DELAYED_TIMER_IN_MILLIS = 10000;
2737 private static final UUID SUPPLY_PIN_UUID = UUID.fromString(
2738 "d3768135-4323-491d-a6c8-bda01fc89040");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002739
Michele Berionne5e411512020-11-13 02:36:59 +00002740 UnlockSim(int phoneId, IccCard simCard) {
2741 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002742 mSimCard = simCard;
2743 }
2744
2745 @Override
2746 public void run() {
2747 Looper.prepare();
2748 synchronized (UnlockSim.this) {
2749 mHandler = new Handler() {
2750 @Override
2751 public void handleMessage(Message msg) {
2752 AsyncResult ar = (AsyncResult) msg.obj;
2753 switch (msg.what) {
2754 case SUPPLY_PIN_COMPLETE:
2755 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2756 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002757 mRetryCount = msg.arg1;
2758 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002759 CommandException.Error error = null;
2760 if (ar.exception instanceof CommandException) {
2761 error = ((CommandException) (ar.exception))
2762 .getCommandError();
2763 }
2764 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07002765 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002766 } else if (error == CommandException.Error.ABORTED) {
2767 /* When UiccCardApp dispose, handle message and return
2768 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08002769 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002770 } else {
2771 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2772 }
2773 } else {
2774 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2775 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002776 mDone = true;
arunvoddu7bf930c2024-05-20 04:24:40 +00002777 removeMessages(SUPPLY_PIN_DELAYED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002778 UnlockSim.this.notifyAll();
2779 }
2780 break;
arunvoddu7bf930c2024-05-20 04:24:40 +00002781 case SUPPLY_PIN_DELAYED:
2782 if(!mDone) {
2783 String logStr = "Delay in receiving SIM PIN response ";
2784 if (DBG) log(logStr);
2785 AnomalyReporter.reportAnomaly(SUPPLY_PIN_UUID, logStr);
2786 }
2787 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002788 }
2789 }
2790 };
2791 UnlockSim.this.notifyAll();
2792 }
2793 Looper.loop();
2794 }
2795
2796 /*
2797 * Use PIN or PUK to unlock SIM card
2798 *
2799 * If PUK is null, unlock SIM card with PIN
2800 *
2801 * If PUK is not null, unlock SIM card with PUK and set PIN code
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302802 *
2803 * Besides, since it is reused in class level, the thread's looper will be stopped to avoid
2804 * its thread leak.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002805 */
Wink Saville9de0f752013-10-22 19:04:03 -07002806 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002807
2808 while (mHandler == null) {
2809 try {
2810 wait();
2811 } catch (InterruptedException e) {
2812 Thread.currentThread().interrupt();
2813 }
2814 }
2815 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2816
2817 if (puk == null) {
2818 mSimCard.supplyPin(pin, callback);
2819 } else {
2820 mSimCard.supplyPuk(puk, pin, callback);
2821 }
2822
2823 while (!mDone) {
2824 try {
2825 Log.d(LOG_TAG, "wait for done");
arunvoddu7bf930c2024-05-20 04:24:40 +00002826 mHandler.sendEmptyMessageDelayed(SUPPLY_PIN_DELAYED,
2827 SUPPLY_PIN_DELAYED_TIMER_IN_MILLIS);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002828 wait();
2829 } catch (InterruptedException e) {
2830 // Restore the interrupted status
2831 Thread.currentThread().interrupt();
2832 }
2833 }
2834 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002835 int[] resultArray = new int[2];
2836 resultArray[0] = mResult;
2837 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002838
2839 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002840 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002841 }
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302842 // This instance is no longer reused, so quit its thread's looper.
2843 mHandler.getLooper().quitSafely();
Michele Berionne5e411512020-11-13 02:36:59 +00002844
Wink Saville9de0f752013-10-22 19:04:03 -07002845 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002846 }
2847 }
2848
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002849 /**
2850 * This method has been removed due to privacy and stability concerns.
2851 */
2852 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002853 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002854 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2855 return;
Wink Saville36469e72014-06-11 15:17:00 -07002856 }
2857
Nathan Harold1f889d82020-06-04 17:05:26 -07002858 @Override
2859 public void updateServiceLocationWithPackageName(String callingPackage) {
2860 mApp.getSystemService(AppOpsManager.class)
2861 .checkPackage(Binder.getCallingUid(), callingPackage);
2862
Nathan Haroldf096d982020-11-18 17:18:06 -08002863 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002864 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2865 // Callers targeting S have no business invoking this method.
2866 return;
2867 }
2868
2869 LocationAccessPolicy.LocationPermissionResult locationResult =
2870 LocationAccessPolicy.checkLocationPermission(mApp,
2871 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2872 .setCallingPackage(callingPackage)
2873 .setCallingFeatureId(null)
2874 .setCallingPid(Binder.getCallingPid())
2875 .setCallingUid(Binder.getCallingUid())
2876 .setMethod("updateServiceLocation")
2877 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2878 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2879 .build());
2880 // Apps that lack location permission have no business calling this method;
2881 // however, because no permission was declared in the public API, denials must
2882 // all be "soft".
2883 switch (locationResult) {
2884 case DENIED_HARD: /* fall through */
2885 case DENIED_SOFT:
2886 return;
2887 }
2888
2889 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002890 final long identity = Binder.clearCallingIdentity();
2891 try {
Ling Mac28f0212023-03-24 16:07:15 -07002892 getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002893 } finally {
2894 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002895 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002896 }
2897
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002898 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002899 @Override
2900 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002901 return isRadioOnWithFeature(callingPackage, null);
2902 }
2903
2904
2905 @Override
2906 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2907 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2908 callingFeatureId);
2909 }
2910
2911 @Deprecated
2912 @Override
2913 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2914 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002915 }
2916
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002917 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002918 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2919 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002920 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002921 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002922 return false;
2923 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002924
joonhunshin4ac60942023-11-15 15:23:39 +00002925 enforceTelephonyFeatureWithException(callingPackage,
2926 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isRadioOnWithFeature");
2927
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002928 final long identity = Binder.clearCallingIdentity();
2929 try {
2930 return isRadioOnForSubscriber(subId);
2931 } finally {
2932 Binder.restoreCallingIdentity(identity);
2933 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002934 }
2935
2936 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002937 final long identity = Binder.clearCallingIdentity();
2938 try {
2939 final Phone phone = getPhone(subId);
2940 if (phone != null) {
2941 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2942 } else {
2943 return false;
2944 }
2945 } finally {
2946 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002947 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002948 }
2949
2950 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002951 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002952 }
Wink Saville36469e72014-06-11 15:17:00 -07002953
Wink Savilleb564aae2014-10-23 10:18:09 -07002954 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002955 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002956
joonhunshin4ac60942023-11-15 15:23:39 +00002957 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2958 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "toggleRadioOnOffForSubscriber");
2959
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002960 final long identity = Binder.clearCallingIdentity();
2961 try {
2962 final Phone phone = getPhone(subId);
2963 if (phone != null) {
2964 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2965 }
2966 } finally {
2967 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002968 }
Wink Saville36469e72014-06-11 15:17:00 -07002969 }
2970
2971 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002972 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002973 }
2974
Wink Savilleb564aae2014-10-23 10:18:09 -07002975 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002976 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002977
2978 final long identity = Binder.clearCallingIdentity();
2979 try {
2980 final Phone phone = getPhone(subId);
2981 if (phone == null) {
2982 return false;
2983 }
2984 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2985 toggleRadioOnOffForSubscriber(subId);
2986 }
2987 return true;
2988 } finally {
2989 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002990 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002991 }
Wink Saville36469e72014-06-11 15:17:00 -07002992
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002993 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002994 enforceReadPrivilegedPermission("needMobileRadioShutdown");
joonhunshin4ac60942023-11-15 15:23:39 +00002995
2996 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2997 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needMobileRadioShutdown");
2998
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002999 /*
3000 * If any of the Radios are available, it will need to be
3001 * shutdown. So return true if any Radio is available.
3002 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003003 final long identity = Binder.clearCallingIdentity();
3004 try {
3005 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3006 Phone phone = PhoneFactory.getPhone(i);
3007 if (phone != null && phone.isRadioAvailable()) return true;
3008 }
3009 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
3010 return false;
3011 } finally {
3012 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003013 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003014 }
3015
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003016 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003017 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003018 enforceModifyPermission();
3019
joonhunshin4ac60942023-11-15 15:23:39 +00003020 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3021 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "shutdownMobileRadios");
3022
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003023 final long identity = Binder.clearCallingIdentity();
3024 try {
3025 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3026 logv("Shutting down Phone " + i);
3027 shutdownRadioUsingPhoneId(i);
3028 }
3029 } finally {
3030 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003031 }
3032 }
3033
3034 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003035 Phone phone = PhoneFactory.getPhone(phoneId);
3036 if (phone != null && phone.isRadioAvailable()) {
3037 phone.shutdownRadio();
3038 }
3039 }
3040
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003041 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07003042 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003043
Ling Ma83dc5ea2023-01-12 15:06:04 -08003044 if (!turnOn) {
3045 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
3046 }
3047
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003048 final long identity = Binder.clearCallingIdentity();
3049 try {
3050 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
3051 if (defaultPhone != null) {
3052 defaultPhone.setRadioPower(turnOn);
3053 return true;
3054 } else {
3055 loge("There's no default phone.");
3056 return false;
3057 }
3058 } finally {
3059 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07003060 }
Wink Saville36469e72014-06-11 15:17:00 -07003061 }
3062
Wink Savilleb564aae2014-10-23 10:18:09 -07003063 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003064 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003065
Ling Ma83dc5ea2023-01-12 15:06:04 -08003066 if (!turnOn) {
3067 log("setRadioPowerForSubscriber off: subId=" + subId
3068 + ",callingPackage=" + getCurrentPackageName());
3069 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003070 final long identity = Binder.clearCallingIdentity();
3071 try {
3072 final Phone phone = getPhone(subId);
3073 if (phone != null) {
3074 phone.setRadioPower(turnOn);
3075 return true;
3076 } else {
3077 return false;
3078 }
3079 } finally {
3080 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003081 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003082 }
3083
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003084 /**
3085 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3086 * no reason to power it off. When any of the voters want to power it off, it will be turned
3087 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3088 * powering it off, and these radio off votes will be cleared.
3089 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3090 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3091 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3092 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3093 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3094 * check its vote.
3095 *
3096 * @param subId The subscription ID.
3097 * @param reason The reason for powering off radio.
3098 * @return true on success and false on failure.
3099 */
3100 public boolean requestRadioPowerOffForReason(int subId,
3101 @TelephonyManager.RadioPowerReason int reason) {
3102 enforceModifyPermission();
3103
joonhunshin4ac60942023-11-15 15:23:39 +00003104 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3105 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestRadioPowerOffForReason");
3106
Ling Ma83dc5ea2023-01-12 15:06:04 -08003107 log("requestRadioPowerOffForReason: subId=" + subId
3108 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003109 final long identity = Binder.clearCallingIdentity();
3110 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003111 boolean result = false;
3112 for (Phone phone : PhoneFactory.getPhones()) {
3113 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003114 phone.setRadioPowerForReason(false, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003115 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003116 if (!result) {
3117 loge("requestRadioPowerOffForReason: no phone exists");
3118 }
3119 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003120 } finally {
3121 Binder.restoreCallingIdentity(identity);
3122 }
3123 }
3124
3125 /**
3126 * Remove the vote on powering off the radio for a reason, as requested by
3127 * {@link requestRadioPowerOffForReason}.
3128 *
3129 * @param subId The subscription ID.
3130 * @param reason The reason for powering off radio.
3131 * @return true on success and false on failure.
3132 */
3133 public boolean clearRadioPowerOffForReason(int subId,
3134 @TelephonyManager.RadioPowerReason int reason) {
3135 enforceModifyPermission();
3136
joonhunshin4ac60942023-11-15 15:23:39 +00003137 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3138 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearRadioPowerOffForReason");
3139
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003140 final long identity = Binder.clearCallingIdentity();
3141 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003142 boolean result = false;
3143 for (Phone phone : PhoneFactory.getPhones()) {
3144 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003145 phone.setRadioPowerForReason(true, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003146 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003147 if (!result) {
3148 loge("clearRadioPowerOffForReason: no phone exists");
3149 }
3150 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003151 } finally {
3152 Binder.restoreCallingIdentity(identity);
3153 }
3154 }
3155
3156 /**
3157 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3158 *
3159 * @param subId The subscription ID.
3160 * @param callingPackage The package making the call.
3161 * @param callingFeatureId The feature in the package.
3162 * @return List of reasons for powering off radio.
3163 */
3164 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3165 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3166
joonhunshin4ac60942023-11-15 15:23:39 +00003167 enforceTelephonyFeatureWithException(callingPackage,
3168 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerOffReasons");
3169
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003170 final long identity = Binder.clearCallingIdentity();
3171 List result = new ArrayList();
3172 try {
3173 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3174 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3175 return result;
3176 }
3177
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003178 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003179 if (phone != null) {
3180 result.addAll(phone.getRadioPowerOffReasons());
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003181 } else {
3182 loge("getRadioPowerOffReasons: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003183 }
3184 } finally {
3185 Binder.restoreCallingIdentity(identity);
3186 }
3187 return result;
3188 }
3189
Wink Saville36469e72014-06-11 15:17:00 -07003190 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003191 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003192 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003193 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003194
joonhunshin4ac60942023-11-15 15:23:39 +00003195 enforceTelephonyFeatureWithException(callingPackage,
3196 PackageManager.FEATURE_TELEPHONY_DATA, "enableDataConnectivity");
3197
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003198 final long identity = Binder.clearCallingIdentity();
3199 try {
Jack Yu285100e2022-12-02 22:48:35 -08003200 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003201 final Phone phone = getPhone(subId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00003202 if (phone != null && phone.getDataSettingsManager() != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003203 phone.getDataSettingsManager().setDataEnabled(
3204 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003205 return true;
3206 } else {
3207 return false;
3208 }
3209 } finally {
3210 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003211 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003212 }
3213
Wink Saville36469e72014-06-11 15:17:00 -07003214 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003215 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003216 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003217 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003218
joonhunshin4ac60942023-11-15 15:23:39 +00003219 enforceTelephonyFeatureWithException(callingPackage,
3220 PackageManager.FEATURE_TELEPHONY_DATA, "disableDataConnectivity");
3221
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003222 final long identity = Binder.clearCallingIdentity();
3223 try {
Jack Yu285100e2022-12-02 22:48:35 -08003224 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003225 final Phone phone = getPhone(subId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00003226 if (phone != null && phone.getDataSettingsManager() != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003227 phone.getDataSettingsManager().setDataEnabled(
3228 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003229 return true;
3230 } else {
3231 return false;
3232 }
3233 } finally {
3234 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003235 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003236 }
3237
Sanket Padawe356d7632015-06-22 14:03:32 -07003238 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003239 public boolean isDataConnectivityPossible(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003240 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3241 PackageManager.FEATURE_TELEPHONY_DATA, "isDataConnectivityPossible");
3242
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003243 final long identity = Binder.clearCallingIdentity();
3244 try {
3245 final Phone phone = getPhone(subId);
3246 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003247 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003248 } else {
3249 return false;
3250 }
3251 } finally {
3252 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003253 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003254 }
3255
3256 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003257 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003258 }
3259
pkanwarae03a6b2016-11-06 20:37:09 -08003260 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003261 enforceCallPermission();
3262
joonhunshin4ac60942023-11-15 15:23:39 +00003263 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3264 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "handleUssdRequest");
3265
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003266 final long identity = Binder.clearCallingIdentity();
3267 try {
3268 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3269 return;
3270 }
3271 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3272 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3273 } finally {
3274 Binder.restoreCallingIdentity(identity);
3275 }
pkanwar32d516d2016-10-14 19:37:38 -07003276 };
3277
Wink Savilleb564aae2014-10-23 10:18:09 -07003278 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003279 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003280
joonhunshin4ac60942023-11-15 15:23:39 +00003281 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3282 PackageManager.FEATURE_TELEPHONY_CALLING, "handlePinMmiForSubscriber");
3283
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003284 final long identity = Binder.clearCallingIdentity();
3285 try {
3286 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3287 return false;
3288 }
3289 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3290 } finally {
3291 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003292 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003293 }
3294
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003295 /**
3296 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3297 * tag on getCallState Binder call.
3298 */
3299 @Deprecated
3300 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003301 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003302 if (CompatChanges.isChangeEnabled(
3303 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3304 Binder.getCallingUid())) {
3305 // Do not allow this API to be called on API version 31+, it should only be
3306 // called on old apps using this Binder call directly.
3307 throw new SecurityException("This method can only be used for applications "
3308 + "targeting API version 30 or less.");
3309 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003310 final long identity = Binder.clearCallingIdentity();
3311 try {
Ling Mac28f0212023-03-24 16:07:15 -07003312 Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription());
3313 return PhoneConstantConversions.convertCallState(phone.getState());
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003314 } finally {
3315 Binder.restoreCallingIdentity(identity);
3316 }
3317 }
3318
3319 @Override
3320 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3321 if (CompatChanges.isChangeEnabled(
3322 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3323 Binder.getCallingUid())) {
3324 // Check READ_PHONE_STATE for API version 31+
3325 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3326 featureId, "getCallStateForSubscription")) {
3327 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3328 + "targeting API level 31+.");
3329 }
3330 }
joonhunshin4ac60942023-11-15 15:23:39 +00003331
3332 enforceTelephonyFeatureWithException(callingPackage,
3333 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallStateForSubscription");
3334
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003335 final long identity = Binder.clearCallingIdentity();
3336 try {
3337 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003338 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3339 PhoneConstantConversions.convertCallState(phone.getState());
3340 } finally {
3341 Binder.restoreCallingIdentity(identity);
3342 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003343 }
3344
Sanket Padawe356d7632015-06-22 14:03:32 -07003345 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003346 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003347 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003348 }
3349
3350 @Override
3351 public int getDataStateForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003352 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3353 PackageManager.FEATURE_TELEPHONY_DATA, "getDataStateForSubId");
3354
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003355 final long identity = Binder.clearCallingIdentity();
3356 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003357 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003358 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003359 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003360 } else {
3361 return PhoneConstantConversions.convertDataState(
3362 PhoneConstants.DataState.DISCONNECTED);
3363 }
3364 } finally {
3365 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003366 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003367 }
3368
Sanket Padawe356d7632015-06-22 14:03:32 -07003369 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003370 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003371 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003372 }
3373
3374 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003375 public @DataActivityType int getDataActivityForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003376 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3377 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivityForSubId");
3378
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003379 final long identity = Binder.clearCallingIdentity();
3380 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003381 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003382 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003383 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003384 } else {
3385 return TelephonyManager.DATA_ACTIVITY_NONE;
3386 }
3387 } finally {
3388 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003389 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003390 }
3391
3392 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003393 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003394 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003395 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003396
3397 LocationAccessPolicy.LocationPermissionResult locationResult =
3398 LocationAccessPolicy.checkLocationPermission(mApp,
3399 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3400 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003401 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003402 .setCallingPid(Binder.getCallingPid())
3403 .setCallingUid(Binder.getCallingUid())
3404 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003405 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003406 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3407 .build());
3408 switch (locationResult) {
3409 case DENIED_HARD:
3410 throw new SecurityException("Not allowed to access cell location");
3411 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003412 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3413 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003414 }
3415
joonhunshin4ac60942023-11-15 15:23:39 +00003416 enforceTelephonyFeatureWithException(callingPackage,
3417 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getCellLocation");
3418
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003419 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003420 final long identity = Binder.clearCallingIdentity();
3421 try {
3422 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003423 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003424 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003425 } finally {
3426 Binder.restoreCallingIdentity(identity);
3427 }
Svetoslav64fad262015-04-14 14:35:21 -07003428 }
3429
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003430 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003431 public String getNetworkCountryIsoForPhone(int phoneId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003432 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3433 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkCountryIsoForPhone");
3434
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003435 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3436 // registered cell info, so return a NULL country instead.
3437 final long identity = Binder.clearCallingIdentity();
3438 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003439 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3440 // Get default phone in this case.
3441 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3442 }
Jack Yu285100e2022-12-02 22:48:35 -08003443 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003444 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003445 if (phone == null) return "";
3446 ServiceStateTracker sst = phone.getServiceStateTracker();
3447 if (sst == null) return "";
3448 LocaleTracker lt = sst.getLocaleTracker();
3449 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003450 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003451 } finally {
3452 Binder.restoreCallingIdentity(identity);
3453 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003454 }
3455
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003456 /**
3457 * This method was removed due to potential issues caused by performing partial
3458 * updates of service state, and lack of a credible use case.
3459 *
3460 * This has the ability to break the telephony implementation by disabling notification of
3461 * changes in device connectivity. DO NOT USE THIS!
3462 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003463 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003464 public void enableLocationUpdates() {
3465 mApp.enforceCallingOrSelfPermission(
3466 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003467 }
3468
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003469 /**
3470 * This method was removed due to potential issues caused by performing partial
3471 * updates of service state, and lack of a credible use case.
3472 *
3473 * This has the ability to break the telephony implementation by disabling notification of
3474 * changes in device connectivity. DO NOT USE THIS!
3475 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003476 @Override
3477 public void disableLocationUpdates() {
3478 mApp.enforceCallingOrSelfPermission(
3479 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003480 }
3481
3482 @Override
3483 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003484 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3485 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003486 try {
3487 mApp.getSystemService(AppOpsManager.class)
3488 .checkPackage(Binder.getCallingUid(), callingPackage);
3489 } catch (SecurityException e) {
3490 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3491 throw e;
3492 }
3493
Nathan Haroldf096d982020-11-18 17:18:06 -08003494 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003495 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3496 throw new SecurityException(
3497 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3498 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003499
Jordan Liu1617b712019-07-10 15:06:26 -07003500 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003501 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3502 return null;
3503 }
Svetoslav64fad262015-04-14 14:35:21 -07003504
joonhunshin4ac60942023-11-15 15:23:39 +00003505 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3506 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNeighboringCellInfo");
3507
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003508 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003509
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003510 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003511 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003512
Nathan Haroldf180aac2018-06-01 18:43:55 -07003513 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3514 for (CellInfo ci : info) {
3515 if (ci instanceof CellInfoGsm) {
3516 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3517 } else if (ci instanceof CellInfoWcdma) {
3518 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3519 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003520 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003521 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003522 }
3523
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003524 private List<CellInfo> getCachedCellInfo() {
3525 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3526 for (Phone phone : PhoneFactory.getPhones()) {
3527 List<CellInfo> info = phone.getAllCellInfo();
3528 if (info != null) cellInfos.addAll(info);
3529 }
3530 return cellInfos;
3531 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003532
3533 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003534 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003535 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003536 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003537
3538 LocationAccessPolicy.LocationPermissionResult locationResult =
3539 LocationAccessPolicy.checkLocationPermission(mApp,
3540 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3541 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003542 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003543 .setCallingPid(Binder.getCallingPid())
3544 .setCallingUid(Binder.getCallingUid())
3545 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003546 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003547 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3548 .build());
3549 switch (locationResult) {
3550 case DENIED_HARD:
3551 throw new SecurityException("Not allowed to access cell info");
3552 case DENIED_SOFT:
3553 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003554 }
3555
Nathan Haroldf096d982020-11-18 17:18:06 -08003556 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003557 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3558 return getCachedCellInfo();
3559 }
3560
joonhunshin4ac60942023-11-15 15:23:39 +00003561 enforceTelephonyFeatureWithException(callingPackage,
3562 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllCellInfo");
3563
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003564 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003565 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003566 final long identity = Binder.clearCallingIdentity();
3567 try {
3568 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3569 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003570 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003571 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003572 if (info != null) cellInfos.addAll(info);
3573 }
3574 return cellInfos;
3575 } finally {
3576 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003577 }
3578 }
3579
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003580 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003581 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3582 String callingFeatureId) {
3583 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3584 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003585 }
3586
3587 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003588 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3589 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003590 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003591 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003592 }
3593
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003594 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3595 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003596 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003597 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003598
3599 LocationAccessPolicy.LocationPermissionResult locationResult =
3600 LocationAccessPolicy.checkLocationPermission(mApp,
3601 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3602 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003603 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003604 .setCallingPid(Binder.getCallingPid())
3605 .setCallingUid(Binder.getCallingUid())
3606 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003607 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3608 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003609 .build());
3610 switch (locationResult) {
3611 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003612 if (TelephonyPermissions
3613 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003614 // Safetynet logging for b/154934934
3615 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3616 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003617 throw new SecurityException("Not allowed to access cell info");
3618 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003619 if (TelephonyPermissions
3620 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003621 // Safetynet logging for b/154934934
3622 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3623 }
Nathan Harold5320c422019-05-09 10:26:08 -07003624 try {
3625 cb.onCellInfo(new ArrayList<CellInfo>());
3626 } catch (RemoteException re) {
3627 // Drop without consequences
3628 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003629 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003630 }
3631
joonhunshin4ac60942023-11-15 15:23:39 +00003632 enforceTelephonyFeatureWithException(callingPackage,
3633 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestCellInfoUpdateInternal");
Nathan Harolda939a962019-05-09 10:13:47 -07003634
3635 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003636 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3637
3638 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3639 }
3640
3641 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003642 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003643 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003644 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003645
3646 final long identity = Binder.clearCallingIdentity();
3647 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003648 Phone phone = getPhone(subId);
3649 if (phone == null) {
3650 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3651 } else {
3652 phone.setCellInfoListRate(rateInMillis, workSource);
3653 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003654 } finally {
3655 Binder.restoreCallingIdentity(identity);
3656 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003657 }
3658
Shishir Agrawala9f32182016-04-12 12:00:16 -07003659 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003660 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003661 Phone phone = PhoneFactory.getPhone(slotIndex);
3662 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003663 return null;
3664 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003665 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003666 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003667 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003668 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003669 return null;
3670 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003671
joonhunshin4ac60942023-11-15 15:23:39 +00003672 enforceTelephonyFeatureWithException(callingPackage,
3673 PackageManager.FEATURE_TELEPHONY_GSM, "getImeiForSlot");
3674
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003675 final long identity = Binder.clearCallingIdentity();
3676 try {
3677 return phone.getImei();
3678 } finally {
3679 Binder.restoreCallingIdentity(identity);
3680 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003681 }
3682
3683 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003684 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3685 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3686 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3687 callingFeatureId, "getPrimaryImei")) {
3688 throw new SecurityException("Caller does not have permission");
3689 }
joonhunshin4ac60942023-11-15 15:23:39 +00003690
3691 enforceTelephonyFeatureWithException(callingPackage,
3692 PackageManager.FEATURE_TELEPHONY_GSM, "getPrimaryImei");
3693
arunvoddud5c6ce02022-12-11 06:03:12 +00003694 final long identity = Binder.clearCallingIdentity();
3695 try {
3696 for (Phone phone : PhoneFactory.getPhones()) {
3697 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3698 return phone.getImei();
3699 }
3700 }
3701 throw new UnsupportedOperationException("Operation not supported");
3702 } finally {
3703 Binder.restoreCallingIdentity(identity);
3704 }
3705 }
3706
3707 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003708 public String getTypeAllocationCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003709 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3710 PackageManager.FEATURE_TELEPHONY_GSM, "getTypeAllocationCodeForSlot");
3711
David Kelly5e06a7f2018-03-12 14:10:59 +00003712 Phone phone = PhoneFactory.getPhone(slotIndex);
3713 String tac = null;
3714 if (phone != null) {
3715 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003716 try {
3717 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3718 } catch (IndexOutOfBoundsException e) {
3719 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3720 return null;
3721 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003722 }
3723 return tac;
3724 }
3725
3726 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003727 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003728 try {
3729 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3730 } catch (SecurityException se) {
3731 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3732 throw new SecurityException("Package " + callingPackage + " does not belong to "
3733 + Binder.getCallingUid());
3734 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003735 Phone phone = PhoneFactory.getPhone(slotIndex);
3736 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003737 return null;
3738 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003739
Jeff Davidson913390f2018-02-23 17:11:49 -08003740 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003741 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003742 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003743 return null;
3744 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003745
joonhunshin4ac60942023-11-15 15:23:39 +00003746 enforceTelephonyFeatureWithException(callingPackage,
3747 PackageManager.FEATURE_TELEPHONY_CDMA, "getMeidForSlot");
3748
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003749 final long identity = Binder.clearCallingIdentity();
3750 try {
3751 return phone.getMeid();
3752 } finally {
3753 Binder.restoreCallingIdentity(identity);
3754 }
Jack Yu2af8d712017-03-15 17:14:14 -07003755 }
3756
3757 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003758 public String getManufacturerCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003759 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3760 PackageManager.FEATURE_TELEPHONY_CDMA, "getManufacturerCodeForSlot");
3761
David Kelly5e06a7f2018-03-12 14:10:59 +00003762 Phone phone = PhoneFactory.getPhone(slotIndex);
3763 String manufacturerCode = null;
3764 if (phone != null) {
3765 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003766 try {
3767 manufacturerCode =
3768 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3769 } catch (IndexOutOfBoundsException e) {
3770 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3771 return null;
3772 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003773 }
3774 return manufacturerCode;
3775 }
3776
3777 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003778 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3779 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003780 Phone phone = PhoneFactory.getPhone(slotIndex);
3781 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003782 return null;
3783 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003784 int subId = phone.getSubId();
3785 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003786 mApp, subId, callingPackage, callingFeatureId,
3787 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003788 return null;
3789 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003790
joonhunshin4ac60942023-11-15 15:23:39 +00003791 enforceTelephonyFeatureWithException(callingPackage,
3792 PackageManager.FEATURE_TELEPHONY, "getDeviceSoftwareVersionForSlot");
3793
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003794 final long identity = Binder.clearCallingIdentity();
3795 try {
3796 return phone.getDeviceSvn();
3797 } finally {
3798 Binder.restoreCallingIdentity(identity);
3799 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003800 }
3801
fionaxu43304da2017-11-27 22:51:16 -08003802 @Override
3803 public int getSubscriptionCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003804 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3805 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierId");
3806
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003807 final long identity = Binder.clearCallingIdentity();
3808 try {
3809 final Phone phone = getPhone(subId);
3810 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3811 } finally {
3812 Binder.restoreCallingIdentity(identity);
3813 }
fionaxu43304da2017-11-27 22:51:16 -08003814 }
3815
3816 @Override
3817 public String getSubscriptionCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003818 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3819 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierName");
3820
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003821 final long identity = Binder.clearCallingIdentity();
3822 try {
3823 final Phone phone = getPhone(subId);
3824 return phone == null ? null : phone.getCarrierName();
3825 } finally {
3826 Binder.restoreCallingIdentity(identity);
3827 }
fionaxu43304da2017-11-27 22:51:16 -08003828 }
3829
calvinpanffe225e2018-11-01 19:43:06 +08003830 @Override
chen xu0026ca62019-03-06 15:28:50 -08003831 public int getSubscriptionSpecificCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003832 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3833 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionSpecificCarrierId");
3834
chen xu25637222018-11-04 17:17:00 -08003835 final long identity = Binder.clearCallingIdentity();
3836 try {
3837 final Phone phone = getPhone(subId);
3838 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003839 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003840 } finally {
3841 Binder.restoreCallingIdentity(identity);
3842 }
3843 }
3844
3845 @Override
chen xu0026ca62019-03-06 15:28:50 -08003846 public String getSubscriptionSpecificCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003847 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3848 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
3849 "getSubscriptionSpecificCarrierName");
3850
chen xu25637222018-11-04 17:17:00 -08003851 final long identity = Binder.clearCallingIdentity();
3852 try {
3853 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003854 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003855 } finally {
3856 Binder.restoreCallingIdentity(identity);
3857 }
3858 }
3859
chen xu651eec72018-11-11 19:03:44 -08003860 @Override
chen xu864e11c2018-12-06 22:10:03 -08003861 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3862 if (!isSubscriptionMccMnc) {
3863 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3864 }
chen xu651eec72018-11-11 19:03:44 -08003865 final Phone phone = PhoneFactory.getPhone(slotIndex);
3866 if (phone == null) {
3867 return TelephonyManager.UNKNOWN_CARRIER_ID;
3868 }
joonhunshin4ac60942023-11-15 15:23:39 +00003869
3870 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3871 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromMccMnc");
3872
chen xu651eec72018-11-11 19:03:44 -08003873 final long identity = Binder.clearCallingIdentity();
3874 try {
3875 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3876 } finally {
3877 Binder.restoreCallingIdentity(identity);
3878 }
3879 }
3880
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003881 //
3882 // Internal helper methods.
3883 //
3884
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003885 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003886 * Make sure the caller is the calling package itself
3887 *
3888 * @throws SecurityException if the caller is not the calling package
3889 */
3890 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3891 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003892 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3893 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003894 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003895 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003896 } catch (PackageManager.NameNotFoundException e) {
3897 // packageUid is -1
3898 }
3899 if (packageUid != callingUid) {
3900 throw new SecurityException(message + ": Package " + callingPackage
3901 + " does not belong to " + callingUid);
3902 }
3903 }
3904
3905 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003906 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3907 *
3908 * @throws SecurityException if the caller does not have the required permission
3909 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003910 @VisibleForTesting
3911 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003912 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3913 }
3914
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003915 /**
arunvoddud7401012022-12-15 16:08:12 +00003916 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003917 *
3918 * @throws SecurityException if the caller does not have the required permission
3919 */
3920 @VisibleForTesting
3921 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003922 enforceReadPermission(null);
3923 }
3924
3925 /**
3926 * Make sure the caller has the READ_PHONE_STATE permissions.
3927 *
3928 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3929 */
3930 @VisibleForTesting
3931 public void enforceReadPermission(String msg) {
3932 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003933 }
3934
Shuo Qian3b6ee772019-11-13 17:43:31 -08003935 private void enforceActiveEmergencySessionPermission() {
3936 mApp.enforceCallingOrSelfPermission(
3937 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3938 }
3939
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003940 /**
3941 * Make sure the caller has the CALL_PHONE permission.
3942 *
3943 * @throws SecurityException if the caller does not have the required permission
3944 */
3945 private void enforceCallPermission() {
3946 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3947 }
3948
paulhu5a773602019-08-23 19:17:33 +08003949 private void enforceSettingsPermission() {
3950 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003951 }
3952
Michele Berionne5e411512020-11-13 02:36:59 +00003953 private void enforceRebootPermission() {
3954 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3955 }
3956
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003957 /**
3958 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3959 * @param message - log message to print.
3960 * @throws SecurityException if the caller does not have the required permission
3961 */
3962 private void enforceSatelliteCommunicationPermission(String message) {
3963 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3964 }
3965
Aishwarya Mallampatif265cea2024-06-04 19:55:41 +00003966 /**
3967 * Make sure the caller has PACKAGE_USAGE_STATS permission.
3968 * @param message - log message to print.
3969 * @throws SecurityException if the caller does not have the required permission
3970 */
3971 private void enforcePackageUsageStatsPermission(String message) {
3972 mApp.enforceCallingOrSelfPermission(permission.PACKAGE_USAGE_STATS, message);
3973 }
3974
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003975 private String createTelUrl(String number) {
3976 if (TextUtils.isEmpty(number)) {
3977 return null;
3978 }
3979
Jake Hambye994d462014-02-03 13:10:13 -08003980 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003981 }
3982
Ihab Awadf9e92732013-12-05 18:02:52 -08003983 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003984 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003985 }
3986
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003987 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003988 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003989 }
3990
Ihab Awadf9e92732013-12-05 18:02:52 -08003991 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003992 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003993 }
3994
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003995 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003996 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003997 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003998 }
3999
Sanket Padawe356d7632015-06-22 14:03:32 -07004000 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004001 public int getActivePhoneTypeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00004002 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4003 PackageManager.FEATURE_TELEPHONY, "getActivePhoneTypeForSlot");
4004
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004005 final long identity = Binder.clearCallingIdentity();
4006 try {
4007 final Phone phone = PhoneFactory.getPhone(slotIndex);
4008 if (phone == null) {
4009 return PhoneConstants.PHONE_TYPE_NONE;
4010 } else {
4011 return phone.getPhoneType();
4012 }
4013 } finally {
4014 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004015 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004016 }
4017
4018 /**
4019 * Returns the CDMA ERI icon index to display
4020 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004021 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004022 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
4023 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
4024 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004025 }
4026
Sanket Padawe356d7632015-06-22 14:03:32 -07004027 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004028 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
4029 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004030 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004031 mApp, subId, callingPackage, callingFeatureId,
4032 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004033 return -1;
4034 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004035
joonhunshin4ac60942023-11-15 15:23:39 +00004036 enforceTelephonyFeatureWithException(callingPackage,
4037 PackageManager.FEATURE_TELEPHONY_CDMA,
4038 "getCdmaEriIconIndexForSubscriber");
4039
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004040 final long identity = Binder.clearCallingIdentity();
4041 try {
4042 final Phone phone = getPhone(subId);
4043 if (phone != null) {
4044 return phone.getCdmaEriIconIndex();
4045 } else {
4046 return -1;
4047 }
4048 } finally {
4049 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004050 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004051 }
4052
4053 /**
4054 * Returns the CDMA ERI icon mode,
4055 * 0 - ON
4056 * 1 - FLASHING
4057 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004058 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004059 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
4060 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
4061 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004062 }
4063
Sanket Padawe356d7632015-06-22 14:03:32 -07004064 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004065 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
4066 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004067 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004068 mApp, subId, callingPackage, callingFeatureId,
4069 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004070 return -1;
4071 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004072
4073 final long identity = Binder.clearCallingIdentity();
4074 try {
4075 final Phone phone = getPhone(subId);
4076 if (phone != null) {
4077 return phone.getCdmaEriIconMode();
4078 } else {
4079 return -1;
4080 }
4081 } finally {
4082 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004083 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004084 }
4085
4086 /**
4087 * Returns the CDMA ERI text,
4088 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004089 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004090 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
4091 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
4092 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004093 }
4094
Sanket Padawe356d7632015-06-22 14:03:32 -07004095 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004096 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
4097 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004098 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004099 mApp, subId, callingPackage, callingFeatureId,
4100 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004101 return null;
4102 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004103
4104 final long identity = Binder.clearCallingIdentity();
4105 try {
4106 final Phone phone = getPhone(subId);
4107 if (phone != null) {
4108 return phone.getCdmaEriText();
4109 } else {
4110 return null;
4111 }
4112 } finally {
4113 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004114 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004115 }
4116
4117 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07004118 * Returns the CDMA MDN.
4119 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004120 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004121 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004122 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4123 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004124
joonhunshin4ac60942023-11-15 15:23:39 +00004125 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4126 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMdn");
4127
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004128 final long identity = Binder.clearCallingIdentity();
4129 try {
4130 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004131 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004132 return phone.getLine1Number();
4133 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004134 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004135 return null;
4136 }
4137 } finally {
4138 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004139 }
4140 }
4141
4142 /**
4143 * Returns the CDMA MIN.
4144 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004145 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004146 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004147 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4148 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004149
joonhunshin4ac60942023-11-15 15:23:39 +00004150 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4151 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMin");
4152
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004153 final long identity = Binder.clearCallingIdentity();
4154 try {
4155 final Phone phone = getPhone(subId);
4156 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
4157 return phone.getCdmaMin();
4158 } else {
4159 return null;
4160 }
4161 } finally {
4162 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004163 }
4164 }
4165
Hall Liud892bec2018-11-30 14:51:45 -08004166 @Override
4167 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
4168 INumberVerificationCallback callback, String callingPackage) {
4169 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
4170 != PERMISSION_GRANTED) {
4171 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
4172 }
4173 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4174
4175 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
4176 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08004177 throw new SecurityException("Calling package must be configured in the device config: "
4178 + "calling package: " + callingPackage
4179 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004180 }
4181
joonhunshin4ac60942023-11-15 15:23:39 +00004182 enforceTelephonyFeatureWithException(callingPackage,
4183 PackageManager.FEATURE_TELEPHONY_CALLING, "requestNumberVerification");
4184
Hall Liud892bec2018-11-30 14:51:45 -08004185 if (range == null) {
4186 throw new NullPointerException("Range must be non-null");
4187 }
4188
4189 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004190 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004191
4192 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4193 }
4194
Junda Liuca05d5d2014-08-14 22:36:34 -07004195 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004196 * Returns true if CDMA provisioning needs to run.
4197 */
4198 public boolean needsOtaServiceProvisioning() {
joonhunshin4ac60942023-11-15 15:23:39 +00004199 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4200 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needsOtaServiceProvisioning");
4201
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004202 final long identity = Binder.clearCallingIdentity();
4203 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004204 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004205 } finally {
4206 Binder.restoreCallingIdentity(identity);
4207 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004208 }
4209
4210 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004211 * Sets the voice mail number of a given subId.
4212 */
4213 @Override
4214 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004215 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4216 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004217
joonhunshin4ac60942023-11-15 15:23:39 +00004218 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4219 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceMailNumber");
4220
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004221 final long identity = Binder.clearCallingIdentity();
4222 try {
4223 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4224 new Pair<String, String>(alphaTag, number), new Integer(subId));
4225 return success;
4226 } finally {
4227 Binder.restoreCallingIdentity(identity);
4228 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004229 }
4230
Ta-wei Yen87c49842016-05-13 21:19:52 -07004231 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004232 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4233 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004234 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4235 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004236 if (!TextUtils.equals(callingPackage, systemDialer)) {
4237 throw new SecurityException("caller must be system dialer");
4238 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004239
joonhunshin4ac60942023-11-15 15:23:39 +00004240 enforceTelephonyFeatureWithException(callingPackage,
4241 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailSettings");
4242
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004243 final long identity = Binder.clearCallingIdentity();
4244 try {
4245 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4246 if (phoneAccountHandle == null) {
4247 return null;
4248 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004249 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004250 } finally {
4251 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004252 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004253 }
4254
4255 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004256 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4257 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004258 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004259 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004260 mApp, subId, callingPackage, callingFeatureId,
4261 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004262 return null;
4263 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004264
joonhunshin4ac60942023-11-15 15:23:39 +00004265 enforceTelephonyFeatureWithException(callingPackage,
4266 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailPackageName");
4267
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004268 final long identity = Binder.clearCallingIdentity();
4269 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004270 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004271 } finally {
4272 Binder.restoreCallingIdentity(identity);
4273 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004274 }
4275
4276 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004277 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4278 VisualVoicemailSmsFilterSettings settings) {
4279 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Thomas Stuart1c55f992024-06-06 22:34:33 +00004280 enforceVisualVoicemailPackage(callingPackage, subId);
joonhunshin4ac60942023-11-15 15:23:39 +00004281 enforceTelephonyFeatureWithException(callingPackage,
4282 PackageManager.FEATURE_TELEPHONY_CALLING, "enableVisualVoicemailSmsFilter");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004283 final long identity = Binder.clearCallingIdentity();
4284 try {
4285 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004286 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004287 } finally {
4288 Binder.restoreCallingIdentity(identity);
4289 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004290 }
4291
4292 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004293 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4294 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Thomas Stuart9aee7c72024-06-28 17:33:03 +00004295 enforceVisualVoicemailPackage(callingPackage, subId);
joonhunshin4ac60942023-11-15 15:23:39 +00004296 enforceTelephonyFeatureWithException(callingPackage,
4297 PackageManager.FEATURE_TELEPHONY_CALLING, "disableVisualVoicemailSmsFilter");
4298
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004299 final long identity = Binder.clearCallingIdentity();
4300 try {
4301 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004302 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004303 } finally {
4304 Binder.restoreCallingIdentity(identity);
4305 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004306 }
4307
4308 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004309 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4310 String callingPackage, int subId) {
4311 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004312
4313 final long identity = Binder.clearCallingIdentity();
4314 try {
4315 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004316 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004317 } finally {
4318 Binder.restoreCallingIdentity(identity);
4319 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004320 }
4321
4322 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004323 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004324 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004325
4326 final long identity = Binder.clearCallingIdentity();
4327 try {
4328 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004329 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004330 } finally {
4331 Binder.restoreCallingIdentity(identity);
4332 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004333 }
4334
4335 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004336 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4337 String callingAttributionTag, int subId, String number, int port, String text,
4338 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004339 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004340 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004341 enforceSendSmsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00004342
4343 enforceTelephonyFeatureWithException(callingPackage,
4344 PackageManager.FEATURE_TELEPHONY_CALLING, "sendVisualVoicemailSmsForSubscriber");
4345
Amit Mahajandccb3f12019-05-13 13:48:32 -07004346 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004347 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4348 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004349 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004350
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004351 /**
fionaxu0152e512016-11-14 13:36:14 -08004352 * Sets the voice activation state of a given subId.
4353 */
4354 @Override
4355 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004356 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4357 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004358
joonhunshin4ac60942023-11-15 15:23:39 +00004359 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4360 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState");
4361
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004362 final long identity = Binder.clearCallingIdentity();
4363 try {
4364 final Phone phone = getPhone(subId);
4365 if (phone != null) {
4366 phone.setVoiceActivationState(activationState);
4367 } else {
4368 loge("setVoiceActivationState fails with invalid subId: " + subId);
4369 }
4370 } finally {
4371 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004372 }
4373 }
4374
4375 /**
4376 * Sets the data activation state of a given subId.
4377 */
4378 @Override
4379 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004380 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4381 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004382
joonhunshin4ac60942023-11-15 15:23:39 +00004383 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4384 PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState");
4385
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004386 final long identity = Binder.clearCallingIdentity();
4387 try {
4388 final Phone phone = getPhone(subId);
4389 if (phone != null) {
4390 phone.setDataActivationState(activationState);
4391 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004392 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004393 }
4394 } finally {
4395 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004396 }
4397 }
4398
4399 /**
4400 * Returns the voice activation state of a given subId.
4401 */
4402 @Override
4403 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004404 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004405
joonhunshin4ac60942023-11-15 15:23:39 +00004406 enforceTelephonyFeatureWithException(callingPackage,
4407 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState");
4408
fionaxu0152e512016-11-14 13:36:14 -08004409 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004410 final long identity = Binder.clearCallingIdentity();
4411 try {
4412 if (phone != null) {
4413 return phone.getVoiceActivationState();
4414 } else {
4415 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4416 }
4417 } finally {
4418 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004419 }
4420 }
4421
4422 /**
4423 * Returns the data activation state of a given subId.
4424 */
4425 @Override
4426 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004427 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004428
joonhunshin4ac60942023-11-15 15:23:39 +00004429 enforceTelephonyFeatureWithException(callingPackage,
4430 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState");
4431
fionaxu0152e512016-11-14 13:36:14 -08004432 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004433 final long identity = Binder.clearCallingIdentity();
4434 try {
4435 if (phone != null) {
4436 return phone.getDataActivationState();
4437 } else {
4438 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4439 }
4440 } finally {
4441 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004442 }
4443 }
4444
4445 /**
Wink Saville36469e72014-06-11 15:17:00 -07004446 * Returns the unread count of voicemails for a subId
4447 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004448 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004449 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4450 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004451 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004452 mApp, subId, callingPackage, callingFeatureId,
4453 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004454 return 0;
4455 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004456 final long identity = Binder.clearCallingIdentity();
4457 try {
4458 final Phone phone = getPhone(subId);
4459 if (phone != null) {
4460 return phone.getVoiceMessageCount();
4461 } else {
4462 return 0;
4463 }
4464 } finally {
4465 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004466 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004467 }
4468
4469 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004470 * returns true, if the device is in a state where both voice and data
4471 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004472 */
4473 @Override
4474 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00004475 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4476 PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed");
4477
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004478 final long identity = Binder.clearCallingIdentity();
4479 try {
Ling Mac28f0212023-03-24 16:07:15 -07004480 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004481 } finally {
4482 Binder.restoreCallingIdentity(identity);
4483 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004484 }
4485
4486 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004487 * Send the dialer code if called from the current default dialer or the caller has
4488 * carrier privilege.
4489 * @param inputCode The dialer code to send
4490 */
4491 @Override
4492 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004493 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004494 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004495 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4496 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004497 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004498 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004499 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004500 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004501
joonhunshin4ac60942023-11-15 15:23:39 +00004502 enforceTelephonyFeatureWithException(callingPackage,
4503 PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode");
4504
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004505 final long identity = Binder.clearCallingIdentity();
4506 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004507 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004508 } finally {
4509 Binder.restoreCallingIdentity(identity);
4510 }
fionaxu235cc5e2017-03-06 22:25:57 -08004511 }
4512
Pengquan Menga1bb6272018-09-06 09:59:22 -07004513 @Override
4514 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004515 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004516 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4517 mApp, subId, "getNetworkSelectionMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004518
4519 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4520 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode");
4521
shilufc958392020-01-20 11:36:01 -08004522 final long identity = Binder.clearCallingIdentity();
4523 try {
4524 if (!isActiveSubscription(subId)) {
4525 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4526 }
4527 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4528 } finally {
4529 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004530 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004531 }
4532
Brad Ebinger35c841c2018-10-01 10:40:55 -07004533 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004534 public boolean isInEmergencySmsMode() {
4535 enforceReadPrivilegedPermission("isInEmergencySmsMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004536
4537 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4538 PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode");
4539
Brad Ebingerb2b65522019-03-15 13:48:47 -07004540 final long identity = Binder.clearCallingIdentity();
4541 try {
4542 for (Phone phone : PhoneFactory.getPhones()) {
4543 if (phone.isInEmergencySmsMode()) {
4544 return true;
4545 }
4546 }
4547 } finally {
4548 Binder.restoreCallingIdentity(identity);
4549 }
4550 return false;
4551 }
4552
shilu366312e2019-12-17 09:28:10 -08004553 /**
4554 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4555 * @param subId The subscription to use to check the configuration.
4556 * @param c The callback that will be used to send the result.
4557 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004558 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004559 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4560 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004561 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004562 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004563
4564 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4565 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4566 "IMS not available on device.");
4567 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004568 final long token = Binder.clearCallingIdentity();
4569 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004570 int slotId = getSlotIndexOrException(subId);
4571 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004572
4573 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4574 if (controller != null) {
4575 ImsManager imsManager = controller.getImsManager(subId);
4576 if (imsManager != null) {
4577 imsManager.addRegistrationCallbackForSubscription(c, subId);
4578 } else {
4579 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4580 }
4581 } else {
4582 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4583 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004584 } catch (ImsException e) {
4585 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004586 } finally {
4587 Binder.restoreCallingIdentity(token);
4588 }
4589 }
4590
shilu366312e2019-12-17 09:28:10 -08004591 /**
4592 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4593 * @param subId The subscription to use to check the configuration.
4594 * @param c The callback that will be used to send the result.
4595 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004596 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004597 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004598 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004599 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004600 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4601 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4602 }
Meng Wangafbc5852019-09-19 17:37:13 -07004603 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004604
Meng Wangafbc5852019-09-19 17:37:13 -07004605 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004606 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4607 if (controller != null) {
4608 ImsManager imsManager = controller.getImsManager(subId);
4609 if (imsManager != null) {
4610 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4611 } else {
4612 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4613 + "is inactive, ignoring unregister.");
4614 // If the ImsManager is not valid, just return, since the callback
4615 // will already have been removed internally.
4616 }
4617 }
Meng Wangafbc5852019-09-19 17:37:13 -07004618 } finally {
4619 Binder.restoreCallingIdentity(token);
4620 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004621 }
4622
Brad Ebingera34a6c22019-10-22 17:36:18 -07004623 /**
Hidayat Khan99ea48f2023-12-11 04:37:45 +00004624 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4625 * @param subId The subscription to use to check the configuration.
4626 * @param c The callback that will be used to send the result.
4627 */
4628 @Override
4629 public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c)
4630 throws RemoteException {
4631 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4632 mApp, subId, "registerImsEmergencyRegistrationCallback");
4633
4634 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4635 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4636 "IMS not available on device.");
4637 }
4638 final long token = Binder.clearCallingIdentity();
4639 try {
4640 int slotId = getSlotIndexOrException(subId);
4641 verifyImsMmTelConfiguredOrThrow(slotId);
4642
4643 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4644 if (controller != null) {
4645 ImsManager imsManager = controller.getImsManager(subId);
4646 if (imsManager != null) {
4647 imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId);
4648 } else {
4649 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4650 }
4651 } else {
4652 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4653 }
4654 } catch (ImsException e) {
4655 throw new ServiceSpecificException(e.getCode());
4656 } finally {
4657 Binder.restoreCallingIdentity(token);
4658 }
4659 }
4660
4661 /**
4662 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4663 * @param subId The subscription to use to check the configuration.
4664 * @param c The callback that will be used to send the result.
4665 */
4666 @Override
4667 public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) {
4668 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4669 mApp, subId, "unregisterImsEmergencyRegistrationCallback");
4670 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4671 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4672 }
4673 final long token = Binder.clearCallingIdentity();
4674
4675 try {
4676 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4677 if (controller != null) {
4678 ImsManager imsManager = controller.getImsManager(subId);
4679 if (imsManager != null) {
4680 imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId);
4681 } else {
4682 Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId
4683 + "is inactive, ignoring unregister.");
4684 // If the ImsManager is not valid, just return, since the callback
4685 // will already have been removed internally.
4686 }
4687 }
4688 } finally {
4689 Binder.restoreCallingIdentity(token);
4690 }
4691 }
4692
4693 /**
Brad Ebingera34a6c22019-10-22 17:36:18 -07004694 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4695 */
4696 @Override
4697 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4698 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4699 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4700 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4701 "IMS not available on device.");
4702 }
4703 final long token = Binder.clearCallingIdentity();
4704 try {
4705 Phone phone = getPhone(subId);
4706 if (phone == null) {
4707 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4708 + subId + "'");
4709 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4710 }
4711 phone.getImsRegistrationState(regState -> {
4712 try {
4713 consumer.accept((regState == null)
4714 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4715 } catch (RemoteException e) {
4716 // Ignore if the remote process is no longer available to call back.
4717 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4718 }
4719 });
4720 } finally {
4721 Binder.restoreCallingIdentity(token);
4722 }
4723 }
4724
4725 /**
4726 * Get the transport type for the IMS service registration state.
4727 */
4728 @Override
4729 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004730 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004731 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004732 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4733 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4734 "IMS not available on device.");
4735 }
4736 final long token = Binder.clearCallingIdentity();
4737 try {
4738 Phone phone = getPhone(subId);
4739 if (phone == null) {
4740 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4741 + subId + "'");
4742 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4743 }
4744 phone.getImsRegistrationTech(regTech -> {
4745 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4746 int regTechConverted = (regTech == null)
4747 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4748 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4749 regTechConverted);
4750 try {
4751 consumer.accept(regTechConverted);
4752 } catch (RemoteException e) {
4753 // Ignore if the remote process is no longer available to call back.
4754 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4755 }
4756 });
4757 } finally {
4758 Binder.restoreCallingIdentity(token);
4759 }
4760 }
4761
shilu366312e2019-12-17 09:28:10 -08004762 /**
4763 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4764 * @param subId The subscription to use to check the configuration.
4765 * @param c The callback that will be used to send the result.
4766 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004767 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004768 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4769 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004770 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004771 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004772 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4773 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4774 "IMS not available on device.");
4775 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004776 final long token = Binder.clearCallingIdentity();
4777 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004778 int slotId = getSlotIndexOrException(subId);
4779 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004780
4781 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4782 if (controller != null) {
4783 ImsManager imsManager = controller.getImsManager(subId);
4784 if (imsManager != null) {
4785 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4786 } else {
4787 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4788 }
4789 } else {
4790 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4791 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004792 } catch (ImsException e) {
4793 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004794 } finally {
4795 Binder.restoreCallingIdentity(token);
4796 }
4797 }
4798
shilu366312e2019-12-17 09:28:10 -08004799 /**
4800 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4801 * @param subId The subscription to use to check the configuration.
4802 * @param c The callback that will be used to send the result.
4803 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004804 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004805 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004806 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004807 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004808 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4809 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4810 }
Meng Wangafbc5852019-09-19 17:37:13 -07004811
4812 final long token = Binder.clearCallingIdentity();
4813 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004814 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4815 if (controller != null) {
4816 ImsManager imsManager = controller.getImsManager(subId);
4817 if (imsManager != null) {
4818 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4819 } else {
4820 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4821 + " is inactive, ignoring unregister.");
4822 // If the ImsManager is not valid, just return, since the callback
4823 // will already have been removed internally.
4824 }
4825 }
Meng Wangafbc5852019-09-19 17:37:13 -07004826 } finally {
4827 Binder.restoreCallingIdentity(token);
4828 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004829 }
4830
4831 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004832 public boolean isCapable(int subId, int capability, int regTech) {
4833 enforceReadPrivilegedPermission("isCapable");
joonhunshin4ac60942023-11-15 15:23:39 +00004834
4835 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4836 FEATURE_TELEPHONY_IMS, "isCapable");
4837
Brad Ebinger35c841c2018-10-01 10:40:55 -07004838 final long token = Binder.clearCallingIdentity();
4839 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004840 int slotId = getSlotIndexOrException(subId);
4841 verifyImsMmTelConfiguredOrThrow(slotId);
4842 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4843 } catch (com.android.ims.ImsException e) {
4844 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4845 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004846 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004847 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4848 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004849 } finally {
4850 Binder.restoreCallingIdentity(token);
4851 }
4852 }
4853
4854 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004855 public boolean isAvailable(int subId, int capability, int regTech) {
4856 enforceReadPrivilegedPermission("isAvailable");
joonhunshin4ac60942023-11-15 15:23:39 +00004857
4858 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4859 FEATURE_TELEPHONY_IMS, "isAvailable");
4860
Brad Ebinger35c841c2018-10-01 10:40:55 -07004861 final long token = Binder.clearCallingIdentity();
4862 try {
4863 Phone phone = getPhone(subId);
4864 if (phone == null) return false;
4865 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004866 } catch (com.android.ims.ImsException e) {
4867 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4868 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004869 } finally {
4870 Binder.restoreCallingIdentity(token);
4871 }
4872 }
4873
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004874 /**
4875 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4876 * subscription.
4877 * @param subId The subscription to use to check the configuration.
4878 * @param callback The callback that will be used to send the result.
4879 * @param capability The MmTelFeature capability that will be used to send the result.
4880 * @param transportType The transport type of the MmTelFeature capability.
4881 */
4882 @Override
4883 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4884 int transportType) {
4885 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004886 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4887 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4888 "IMS not available on device.");
4889 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004890 final long token = Binder.clearCallingIdentity();
4891 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004892 int slotId = getSlotIndex(subId);
4893 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4894 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4895 + subId + "'");
4896 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4897 }
4898 verifyImsMmTelConfiguredOrThrow(slotId);
4899 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4900 transportType, aBoolean -> {
4901 try {
4902 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4903 } catch (RemoteException e) {
4904 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4905 + "running. Ignore");
4906 }
4907 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004908 } catch (ImsException e) {
4909 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004910 } finally {
4911 Binder.restoreCallingIdentity(token);
4912 }
4913 }
4914
shilu366312e2019-12-17 09:28:10 -08004915 /**
4916 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4917 * @param subId The subscription to use to check the configuration.
4918 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004919 @Override
4920 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004921 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004922 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004923
joonhunshin4ac60942023-11-15 15:23:39 +00004924 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4925 FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled");
4926
Brad Ebinger35c841c2018-10-01 10:40:55 -07004927 final long token = Binder.clearCallingIdentity();
4928 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004929 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004930 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004931 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004932 } catch (ImsException e) {
4933 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004934 } finally {
4935 Binder.restoreCallingIdentity(token);
4936 }
4937 }
4938
4939 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004940 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004941 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004942 "setAdvancedCallingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004943
4944 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4945 FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled");
4946
Brad Ebinger35c841c2018-10-01 10:40:55 -07004947 final long identity = Binder.clearCallingIdentity();
4948 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004949 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004950 // This setting doesn't require an active ImsService connection, so do not verify. The
4951 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004952 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004953 } catch (ImsException e) {
4954 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004955 } finally {
4956 Binder.restoreCallingIdentity(identity);
4957 }
4958 }
4959
shilu366312e2019-12-17 09:28:10 -08004960 /**
4961 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4962 * @param subId The subscription to use to check the configuration.
4963 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004964 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004965 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004966 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004967 mApp, subId, "isVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004968
4969 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4970 FEATURE_TELEPHONY_IMS, "isVtSettingEnabled");
4971
Brad Ebinger35c841c2018-10-01 10:40:55 -07004972 final long identity = Binder.clearCallingIdentity();
4973 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004974 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004975 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004976 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004977 } catch (ImsException e) {
4978 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004979 } finally {
4980 Binder.restoreCallingIdentity(identity);
4981 }
4982 }
4983
4984 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004985 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004986 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004987 "setVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004988
4989 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4990 FEATURE_TELEPHONY_IMS, "setVtSettingEnabled");
4991
Brad Ebinger35c841c2018-10-01 10:40:55 -07004992 final long identity = Binder.clearCallingIdentity();
4993 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004994 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004995 // This setting doesn't require an active ImsService connection, so do not verify. The
4996 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004997 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004998 } catch (ImsException e) {
4999 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005000 } finally {
5001 Binder.restoreCallingIdentity(identity);
5002 }
5003 }
5004
shilu366312e2019-12-17 09:28:10 -08005005 /**
5006 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5007 * @param subId The subscription to use to check the configuration.
5008 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005009 @Override
5010 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005011 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005012 mApp, subId, "isVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005013
5014 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5015 FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled");
5016
Brad Ebinger35c841c2018-10-01 10:40:55 -07005017 final long identity = Binder.clearCallingIdentity();
5018 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005019 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005020 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005021 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005022 } catch (ImsException e) {
5023 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005024 } finally {
5025 Binder.restoreCallingIdentity(identity);
5026 }
5027 }
5028
5029 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005030 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005031 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005032 "setVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005033
5034 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5035 FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled");
5036
Brad Ebinger35c841c2018-10-01 10:40:55 -07005037 final long identity = Binder.clearCallingIdentity();
5038 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005039 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005040 // This setting doesn't require an active ImsService connection, so do not verify. The
5041 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005042 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005043 } catch (ImsException e) {
5044 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005045 } finally {
5046 Binder.restoreCallingIdentity(identity);
5047 }
5048 }
5049
shilu366312e2019-12-17 09:28:10 -08005050 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005051 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
5052 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5053 * @param subId The subscription to use to check the configuration.
5054 */
5055 @Override
5056 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005057 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005058 mApp, subId, "isCrossSimCallingEnabledByUser");
joonhunshin4ac60942023-11-15 15:23:39 +00005059
5060 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5061 FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser");
5062
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005063 final long identity = Binder.clearCallingIdentity();
5064 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005065 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005066 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005067 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005068 } catch (ImsException e) {
5069 throw new ServiceSpecificException(e.getCode());
5070 } finally {
5071 Binder.restoreCallingIdentity(identity);
5072 }
5073 }
5074
5075 /**
5076 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
5077 * Requires MODIFY_PHONE_STATE permission.
5078 * @param subId The subscription to use to check the configuration.
5079 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
5080 * false otherwise
5081 */
5082 @Override
5083 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
5084 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5085 "setCrossSimCallingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005086
5087 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5088 FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled");
5089
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005090 final long identity = Binder.clearCallingIdentity();
5091 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005092 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005093 // This setting doesn't require an active ImsService connection, so do not verify. The
5094 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005095 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005096 } catch (ImsException e) {
5097 throw new ServiceSpecificException(e.getCode());
5098 } finally {
5099 Binder.restoreCallingIdentity(identity);
5100 }
5101 }
5102
5103 /**
shilu366312e2019-12-17 09:28:10 -08005104 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5105 * @param subId The subscription to use to check the configuration.
5106 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005107 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07005108
Brad Ebinger35c841c2018-10-01 10:40:55 -07005109 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005110 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005111 mApp, subId, "isVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005112
5113 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5114 FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled");
5115
Brad Ebinger35c841c2018-10-01 10:40:55 -07005116 final long identity = Binder.clearCallingIdentity();
5117 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005118 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005119 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005120 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005121 } catch (ImsException e) {
5122 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005123 } finally {
5124 Binder.restoreCallingIdentity(identity);
5125 }
5126 }
5127
5128 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005129 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005130 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005131 "setVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005132
5133 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5134 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled");
5135
Brad Ebinger35c841c2018-10-01 10:40:55 -07005136 final long identity = Binder.clearCallingIdentity();
5137 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005138 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005139 // This setting doesn't require an active ImsService connection, so do not verify. The
5140 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005141 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005142 } catch (ImsException e) {
5143 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005144 } finally {
5145 Binder.restoreCallingIdentity(identity);
5146 }
5147 }
5148
5149 @Override
5150 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
5151 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5152 "setVoWiFiNonPersistent");
joonhunshin4ac60942023-11-15 15:23:39 +00005153
5154 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5155 FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent");
5156
Brad Ebinger35c841c2018-10-01 10:40:55 -07005157 final long identity = Binder.clearCallingIdentity();
5158 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005159 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005160 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005161 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005162 } catch (ImsException e) {
5163 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005164 } finally {
5165 Binder.restoreCallingIdentity(identity);
5166 }
5167 }
5168
shilu366312e2019-12-17 09:28:10 -08005169 /**
5170 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5171 * @param subId The subscription to use to check the configuration.
5172 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005173 @Override
5174 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005175 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005176 mApp, subId, "getVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005177
5178 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5179 FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting");
5180
Brad Ebinger35c841c2018-10-01 10:40:55 -07005181 final long identity = Binder.clearCallingIdentity();
5182 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005183 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005184 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005185 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005186 } catch (ImsException e) {
5187 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005188 } finally {
5189 Binder.restoreCallingIdentity(identity);
5190 }
5191 }
5192
5193 @Override
5194 public void setVoWiFiModeSetting(int subId, int mode) {
5195 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5196 "setVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005197
5198 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5199 FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting");
5200
Brad Ebinger35c841c2018-10-01 10:40:55 -07005201 final long identity = Binder.clearCallingIdentity();
5202 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005203 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005204 // This setting doesn't require an active ImsService connection, so do not verify. The
5205 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005206 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005207 } catch (ImsException e) {
5208 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005209 } finally {
5210 Binder.restoreCallingIdentity(identity);
5211 }
5212 }
5213
5214 @Override
5215 public int getVoWiFiRoamingModeSetting(int subId) {
5216 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005217
5218 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5219 FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting");
5220
Brad Ebinger35c841c2018-10-01 10:40:55 -07005221 final long identity = Binder.clearCallingIdentity();
5222 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005223 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005224 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005225 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005226 } catch (ImsException e) {
5227 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005228 } finally {
5229 Binder.restoreCallingIdentity(identity);
5230 }
5231 }
5232
5233 @Override
5234 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
5235 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5236 "setVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005237
5238 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5239 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting");
5240
Brad Ebinger35c841c2018-10-01 10:40:55 -07005241 final long identity = Binder.clearCallingIdentity();
5242 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005243 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005244 // This setting doesn't require an active ImsService connection, so do not verify. The
5245 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005246 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005247 } catch (ImsException e) {
5248 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005249 } finally {
5250 Binder.restoreCallingIdentity(identity);
5251 }
5252 }
5253
5254 @Override
5255 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
5256 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5257 "setRttCapabilityEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005258
5259 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5260 FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting");
5261
Brad Ebinger35c841c2018-10-01 10:40:55 -07005262 final long identity = Binder.clearCallingIdentity();
5263 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005264 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005265 // This setting doesn't require an active ImsService connection, so do not verify. The
5266 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005267 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005268 } catch (ImsException e) {
5269 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005270 } finally {
5271 Binder.restoreCallingIdentity(identity);
5272 }
5273 }
5274
shilu366312e2019-12-17 09:28:10 -08005275 /**
5276 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5277 * @param subId The subscription to use to check the configuration.
5278 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005279 @Override
5280 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005281 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005282 mApp, subId, "isTtyOverVolteEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005283
5284 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5285 FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled");
5286
Brad Ebinger35c841c2018-10-01 10:40:55 -07005287 final long identity = Binder.clearCallingIdentity();
5288 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005289 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005290 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005291 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005292 } catch (ImsException e) {
5293 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005294 } finally {
5295 Binder.restoreCallingIdentity(identity);
5296 }
5297 }
5298
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005299 @Override
5300 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5301 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005302
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005303 final long identity = Binder.clearCallingIdentity();
5304 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005305 if (!isImsAvailableOnDevice()) {
5306 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5307 "IMS not available on device.");
5308 }
5309 int slotId = getSlotIndexOrException(subId);
5310 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005311
5312 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5313 if (controller != null) {
5314 ImsManager imsManager = controller.getImsManager(subId);
5315 if (imsManager != null) {
5316 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5317 } else {
5318 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5319 }
5320 } else {
5321 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5322 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005323 } catch (ImsException e) {
5324 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005325 } finally {
5326 Binder.restoreCallingIdentity(identity);
5327 }
5328 }
5329
5330 @Override
5331 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5332 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005333
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005334 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005335 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5336 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5337 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005338 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005339 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5340 if (controller != null) {
5341 ImsManager imsManager = controller.getImsManager(subId);
5342 if (imsManager != null) {
5343 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5344 } else {
5345 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5346 + " is inactive, ignoring unregister.");
5347 // If the ImsManager is not valid, just return, since the callback will already
5348 // have been removed internally.
5349 }
5350 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005351 } finally {
5352 Binder.restoreCallingIdentity(identity);
5353 }
5354 }
5355
joonhunshincffb7fc2021-11-28 07:32:01 +00005356 @Override
5357 public void registerFeatureProvisioningChangedCallback(int subId,
5358 IFeatureProvisioningCallback callback) {
5359 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5360 mApp, subId, "registerFeatureProvisioningChangedCallback");
5361
5362 final long identity = Binder.clearCallingIdentity();
5363 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5364 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5365 }
5366
joonhunshin91bc1952022-04-29 08:47:15 +00005367 try {
5368 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5369 if (controller == null) {
5370 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5371 "Device does not support IMS");
5372 }
5373 controller.addFeatureProvisioningChangedCallback(subId, callback);
5374 } finally {
5375 Binder.restoreCallingIdentity(identity);
5376 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005377 }
5378
5379 @Override
5380 public void unregisterFeatureProvisioningChangedCallback(int subId,
5381 IFeatureProvisioningCallback callback) {
5382 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5383 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5384
5385 final long identity = Binder.clearCallingIdentity();
5386 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5387 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5388 }
5389
joonhunshin91bc1952022-04-29 08:47:15 +00005390 try {
5391 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5392 if (controller == null) {
5393 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5394 return;
5395 }
5396 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5397 } finally {
5398 Binder.restoreCallingIdentity(identity);
5399 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005400 }
allenwtsu99c623b2020-01-03 18:24:23 +08005401
5402 private void checkModifyPhoneStatePermission(int subId, String message) {
5403 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5404 message);
5405 }
5406
allenwtsu99c623b2020-01-03 18:24:23 +08005407 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005408 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005409 boolean isProvisioned) {
5410 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5411
joonhunshin4ac60942023-11-15 15:23:39 +00005412 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5413 FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability");
5414
allenwtsu99c623b2020-01-03 18:24:23 +08005415 final long identity = Binder.clearCallingIdentity();
5416 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005417 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5418 if (controller == null) {
5419 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5420 return;
5421 }
5422 controller.setRcsProvisioningStatusForCapability(
5423 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005424 } finally {
5425 Binder.restoreCallingIdentity(identity);
5426 }
allenwtsu99c623b2020-01-03 18:24:23 +08005427 }
5428
5429
5430 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005431 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5432 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5433 mApp, subId, "getRcsProvisioningStatusForCapability");
5434
joonhunshin4ac60942023-11-15 15:23:39 +00005435 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5436 FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability");
5437
allenwtsu99c623b2020-01-03 18:24:23 +08005438 final long identity = Binder.clearCallingIdentity();
5439 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005440 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5441 if (controller == null) {
5442 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5443
5444 // device does not support IMS, this method will return true always.
5445 return true;
5446 }
5447 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005448 } finally {
5449 Binder.restoreCallingIdentity(identity);
5450 }
5451 }
5452
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005453 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005454 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5455 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005456 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005457
joonhunshin4ac60942023-11-15 15:23:39 +00005458 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5459 FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability");
5460
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005461 final long identity = Binder.clearCallingIdentity();
5462 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005463 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5464 if (controller == null) {
5465 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5466 return;
5467 }
5468 controller.setImsProvisioningStatusForCapability(
5469 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005470 } finally {
5471 Binder.restoreCallingIdentity(identity);
5472 }
5473 }
5474
5475 @Override
5476 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005477 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5478 mApp, subId, "getProvisioningStatusForCapability");
5479
joonhunshin4ac60942023-11-15 15:23:39 +00005480 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5481 FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability");
5482
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005483 final long identity = Binder.clearCallingIdentity();
5484 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005485 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5486 if (controller == null) {
5487 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005488
joonhunshin91bc1952022-04-29 08:47:15 +00005489 // device does not support IMS, this method will return true always.
5490 return true;
5491 }
5492 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005493 } finally {
5494 Binder.restoreCallingIdentity(identity);
5495 }
5496 }
5497
5498 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005499 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5500 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5501 mApp, subId, "isProvisioningRequiredForCapability");
5502
joonhunshin4ac60942023-11-15 15:23:39 +00005503 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5504 FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability");
5505
joonhunshincffb7fc2021-11-28 07:32:01 +00005506 final long identity = Binder.clearCallingIdentity();
5507 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005508 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5509 if (controller == null) {
5510 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5511
5512 // device does not support IMS, this method will return false
5513 return false;
5514 }
5515 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005516 } finally {
5517 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005518 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005519 }
5520
5521 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005522 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5523 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5524 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005525
joonhunshin4ac60942023-11-15 15:23:39 +00005526 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5527 FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability");
5528
joonhunshincffb7fc2021-11-28 07:32:01 +00005529 final long identity = Binder.clearCallingIdentity();
5530 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005531 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5532 if (controller == null) {
5533 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5534
5535 // device does not support IMS, this method will return false
5536 return false;
5537 }
5538 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005539 } finally {
5540 Binder.restoreCallingIdentity(identity);
5541 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005542 }
5543
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005544 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005545 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005546 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5547 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5548 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005549 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5550 mApp, subId, "getImsProvisioningInt");
5551
joonhunshin4ac60942023-11-15 15:23:39 +00005552 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5553 FEATURE_TELEPHONY_IMS, "getImsProvisioningInt");
5554
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005555 final long identity = Binder.clearCallingIdentity();
5556 try {
5557 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005558 int slotId = getSlotIndex(subId);
5559 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5560 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5561 + subId + "' for key:" + key);
5562 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5563 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005564
joonhunshin91bc1952022-04-29 08:47:15 +00005565 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5566 if (controller == null) {
5567 loge("getImsProvisioningInt: Device does not support IMS");
5568
5569 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5570 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5571 }
5572 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005573 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5574 return retVal;
5575 }
5576
calvinpanb5a34062021-02-08 19:59:36 +08005577 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005578 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005579 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5580 + subId + "' for key:" + key);
5581 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005582 } finally {
5583 Binder.restoreCallingIdentity(identity);
5584 }
5585 }
5586
5587 @Override
5588 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005589 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5590 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5591 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005592 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5593 mApp, subId, "getImsProvisioningString");
5594
joonhunshin4ac60942023-11-15 15:23:39 +00005595 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5596 FEATURE_TELEPHONY_IMS, "getImsProvisioningString");
5597
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005598 final long identity = Binder.clearCallingIdentity();
5599 try {
5600 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005601 int slotId = getSlotIndex(subId);
5602 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5603 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5604 + subId + "' for key:" + key);
5605 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5606 }
calvinpanb5a34062021-02-08 19:59:36 +08005607 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005608 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005609 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5610 + subId + "' for key:" + key);
5611 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005612 } finally {
5613 Binder.restoreCallingIdentity(identity);
5614 }
5615 }
5616
5617 @Override
5618 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005619 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5620 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5621 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005622 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5623 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005624
joonhunshin4ac60942023-11-15 15:23:39 +00005625 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5626 FEATURE_TELEPHONY_IMS, "setImsProvisioningInt");
5627
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005628 final long identity = Binder.clearCallingIdentity();
5629 try {
5630 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005631 int slotId = getSlotIndex(subId);
5632 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5633 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5634 + subId + "' for key:" + key);
5635 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5636 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005637
joonhunshin91bc1952022-04-29 08:47:15 +00005638 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5639 if (controller == null) {
5640 loge("setImsProvisioningInt: Device does not support IMS");
5641
5642 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5643 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5644 }
5645 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005646 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5647 return retVal;
5648 }
5649
calvinpanb5a34062021-02-08 19:59:36 +08005650 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5651 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005652 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005653 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005654 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005655 } finally {
5656 Binder.restoreCallingIdentity(identity);
5657 }
5658 }
5659
5660 @Override
5661 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005662 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5663 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5664 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005665 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5666 "setImsProvisioningString");
joonhunshin4ac60942023-11-15 15:23:39 +00005667
5668 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5669 FEATURE_TELEPHONY_IMS, "setImsProvisioningString");
5670
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005671 final long identity = Binder.clearCallingIdentity();
5672 try {
5673 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005674 int slotId = getSlotIndex(subId);
5675 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5676 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5677 + subId + "' for key:" + key);
5678 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5679 }
calvinpanb5a34062021-02-08 19:59:36 +08005680 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5681 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005682 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005683 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005684 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005685 } finally {
5686 Binder.restoreCallingIdentity(identity);
5687 }
5688 }
5689
Brad Ebinger919631e2021-06-02 17:46:35 -07005690 /**
5691 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5692 * for the given slot ID or no ImsResolver instance has been created.
5693 * @param slotId The slot ID that the IMS service is created for.
5694 * @throws ImsException If there is no ImsService configured for this slot.
5695 */
5696 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5697 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5698 ImsFeature.FEATURE_MMTEL)) {
5699 throw new ImsException("This subscription does not support MMTEL over IMS",
5700 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5701 }
5702 }
5703
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005704 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005705 int slotId = SubscriptionManager.getSlotIndex(subId);
5706 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005707 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5708 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005709 }
5710 return slotId;
5711 }
5712
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005713 private int getSlotIndex(int subId) {
5714 int slotId = SubscriptionManager.getSlotIndex(subId);
5715 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5716 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5717 }
5718 return slotId;
5719 }
5720
Wink Saville36469e72014-06-11 15:17:00 -07005721 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005722 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005723 */
5724 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005725 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5726 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005727 try {
5728 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5729 } catch (SecurityException se) {
5730 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5731 throw new SecurityException("Package " + callingPackage + " does not belong to "
5732 + Binder.getCallingUid());
5733 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005734 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005735 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005736 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005737 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005738 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005739 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005740 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005741 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5742 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005743
joonhunshin4ac60942023-11-15 15:23:39 +00005744 enforceTelephonyFeatureWithException(callingPackage,
5745 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber");
5746
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005747 final long identity = Binder.clearCallingIdentity();
5748 try {
5749 final Phone phone = getPhone(subId);
5750 if (phone != null) {
5751 return phone.getServiceState().getDataNetworkType();
5752 } else {
5753 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5754 }
5755 } finally {
5756 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005757 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005758 }
5759
5760 /**
5761 * Returns the data network type
5762 */
5763 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005764 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005765 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005766 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005767 }
5768
5769 /**
5770 * Returns the data network type for a subId
5771 */
5772 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005773 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5774 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005775 String functionName = "getDataNetworkTypeForSubscriber";
5776 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5777 mApp, functionName)) {
5778 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5779 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5780 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5781 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005782 }
5783
joonhunshin4ac60942023-11-15 15:23:39 +00005784 enforceTelephonyFeatureWithException(callingPackage,
5785 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber");
5786
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005787 final long identity = Binder.clearCallingIdentity();
5788 try {
5789 final Phone phone = getPhone(subId);
5790 if (phone != null) {
5791 return phone.getServiceState().getDataNetworkType();
5792 } else {
5793 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5794 }
5795 } finally {
5796 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005797 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005798 }
5799
5800 /**
Wink Saville36469e72014-06-11 15:17:00 -07005801 * Returns the Voice network type for a subId
5802 */
5803 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005804 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5805 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005806 String functionName = "getVoiceNetworkTypeForSubscriber";
5807 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5808 mApp, functionName)) {
5809 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5810 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5811 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5812 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005813 }
5814
joonhunshin4ac60942023-11-15 15:23:39 +00005815 enforceTelephonyFeatureWithException(callingPackage,
5816 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber");
5817
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005818 final long identity = Binder.clearCallingIdentity();
5819 try {
5820 final Phone phone = getPhone(subId);
5821 if (phone != null) {
5822 return phone.getServiceState().getVoiceNetworkType();
5823 } else {
5824 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5825 }
5826 } finally {
5827 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005828 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005829 }
5830
5831 /**
5832 * @return true if a ICC card is present
5833 */
5834 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005835 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005836 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005837 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005838 }
5839
5840 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005841 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005842 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005843 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005844 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00005845 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5846 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex");
5847
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005848 final long identity = Binder.clearCallingIdentity();
5849 try {
5850 final Phone phone = PhoneFactory.getPhone(slotIndex);
5851 if (phone != null) {
5852 return phone.getIccCard().hasIccCard();
5853 } else {
5854 return false;
5855 }
5856 } finally {
5857 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005858 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005859 }
5860
5861 /**
5862 * Return if the current radio is LTE on CDMA. This
5863 * is a tri-state return value as for a period of time
5864 * the mode may be unknown.
5865 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005866 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005867 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005868 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005869 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005870 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005871 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5872 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5873 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005874 }
5875
Sanket Padawe356d7632015-06-22 14:03:32 -07005876 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005877 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5878 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005879 try {
5880 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5881 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005882 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5883 }
5884
joonhunshin4ac60942023-11-15 15:23:39 +00005885 enforceTelephonyFeatureWithException(callingPackage,
5886 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber");
5887
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005888 final long identity = Binder.clearCallingIdentity();
5889 try {
5890 final Phone phone = getPhone(subId);
5891 if (phone == null) {
5892 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5893 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005894 return TelephonyProperties.lte_on_cdma_device()
5895 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005896 }
5897 } finally {
5898 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005899 }
Wink Saville36469e72014-06-11 15:17:00 -07005900 }
5901
Wink Saville36469e72014-06-11 15:17:00 -07005902 /**
5903 * {@hide}
5904 * Returns Default subId, 0 in the case of single standby.
5905 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005906 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005907 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005908 }
5909
Shishir Agrawala9f32182016-04-12 12:00:16 -07005910 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005911 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005912 }
5913
Wink Savilleb564aae2014-10-23 10:18:09 -07005914 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005915 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005916 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005917
Pengquan Menge92a50d2018-09-21 15:54:48 -07005918 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005919 return getSubscriptionManagerService().isActiveSubId(subId,
5920 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005921 }
5922
Ihab Awadf2177b72013-11-25 13:33:23 -08005923 /**
5924 * @see android.telephony.TelephonyManager.WifiCallingChoices
5925 */
5926 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005927 final long identity = Binder.clearCallingIdentity();
5928 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005929 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005930 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5931 getWhenToMakeWifiCallsDefaultPreference());
5932 } finally {
5933 Binder.restoreCallingIdentity(identity);
5934 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005935 }
5936
5937 /**
5938 * @see android.telephony.TelephonyManager.WifiCallingChoices
5939 */
5940 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005941 final long identity = Binder.clearCallingIdentity();
5942 try {
5943 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005944 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005945 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5946 } finally {
5947 Binder.restoreCallingIdentity(identity);
5948 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005949 }
5950
Sailesh Nepald1e68152013-12-12 19:08:02 -08005951 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005952 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005953 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005954 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005955
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005956 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5957 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5958 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005959 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005960 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005961 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005962 }
5963 return PhoneFactory.getPhone(phoneId);
5964 }
5965
Shishir Agrawal566b7612013-10-28 14:41:00 -07005966 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005967 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005968 @NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00005969
Rambo Wanga1782702021-11-10 20:15:19 -08005970 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5971 /*message=*/ "iccOpenLogicalChannel");
5972
5973 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5974 // Verify that the callingPackage in the request belongs to the calling UID
5975 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5976
joonhunshin4ac60942023-11-15 15:23:39 +00005977 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5978 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel");
5979
Rambo Wanga1782702021-11-10 20:15:19 -08005980 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005981 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005982
Rambo Wanga1782702021-11-10 20:15:19 -08005983 private Phone getPhoneFromValidIccLogicalChannelRequest(
5984 @NonNull IccLogicalChannelRequest request, String message) {
5985 Phone phone;
5986 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5987 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5988 mApp, request.subId, message);
5989 phone = getPhoneFromSubId(request.subId);
5990 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5991 enforceModifyPermission();
5992 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5993 } else {
5994 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005995 }
Rambo Wanga1782702021-11-10 20:15:19 -08005996 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005997 }
5998
5999 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08006000 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006001 final long identity = Binder.clearCallingIdentity();
6002 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006003 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006004 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006005 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6006 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08006007 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
6008 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006009 loge("The calling package is not allowed to access ISD-R.");
6010 throw new SecurityException(
6011 "The calling package is not allowed to access ISD-R.");
6012 }
Derek Tan740e1672017-06-27 14:56:27 -07006013 }
Derek Tan740e1672017-06-27 14:56:27 -07006014
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006015 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08006016 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
6017 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006018 return response;
6019 } finally {
6020 Binder.restoreCallingIdentity(identity);
6021 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006022 }
6023
6024 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08006025 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00006026 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6027 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel");
6028
Rambo Wanga1782702021-11-10 20:15:19 -08006029 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
6030 /*message=*/"iccCloseLogicalChannel");
6031
6032 if (DBG) log("iccCloseLogicalChannel: request=" + request);
6033
6034 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006035 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006036
Rambo Wanga1782702021-11-10 20:15:19 -08006037 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
6038 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08006039 // before this feature is enabled, this API should only return false if
6040 // the operation fails instead of throwing runtime exception for
6041 // backward-compatibility.
6042 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
6043 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006044 final long identity = Binder.clearCallingIdentity();
6045 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006046 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08006047 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006048 }
Chen Xue9d737e2022-01-01 23:41:31 -08006049 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08006050 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08006051 Boolean success = false;
6052 if (result instanceof RuntimeException) {
6053 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08006054 if (shouldThrowExceptionOnFailure) {
6055 throw (RuntimeException) result;
6056 } else {
6057 return false;
6058 }
Chen Xue9d737e2022-01-01 23:41:31 -08006059 } else if (result instanceof Boolean) {
6060 success = (Boolean) result;
6061 } else {
6062 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
6063 }
Rambo Wanga1782702021-11-10 20:15:19 -08006064 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006065 return success;
6066 } finally {
6067 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006068 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006069 }
6070
6071 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006072 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07006073 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006074 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6075 mApp, subId, "iccTransmitApduLogicalChannel");
joonhunshin4ac60942023-11-15 15:23:39 +00006076
6077 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6078 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel");
6079
Jordan Liu4c733742019-02-28 12:03:40 -08006080 if (DBG) {
6081 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
6082 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
6083 + p3 + " data=" + data);
6084 }
6085 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
6086 command, p1, p2, p3, data);
6087 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006088
Jordan Liu4c733742019-02-28 12:03:40 -08006089 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006090 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006091 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006092 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006093
6094 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6095 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
6096 "iccTransmitApduLogicalChannelBySlot");
6097
Jordan Liu4c733742019-02-28 12:03:40 -08006098 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006099 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006100 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
6101 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006102 }
6103 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006104 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
6105 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006106 }
6107
6108 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
6109 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006110 final long identity = Binder.clearCallingIdentity();
6111 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07006112 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006113 return "";
6114 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006115
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006116 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006117 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
6118 null /* workSource */);
6119 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006120
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006121 // Append the returned status code to the end of the response payload.
6122 String s = Integer.toHexString(
6123 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6124 if (response.payload != null) {
6125 s = IccUtils.bytesToHexString(response.payload) + s;
6126 }
6127 return s;
6128 } finally {
6129 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006130 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006131 }
Jake Hambye994d462014-02-03 13:10:13 -08006132
Evan Charltonc66da362014-05-16 14:06:40 -07006133 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006134 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
6135 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006136 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6137 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006138 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006139
6140 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6141 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel");
6142
Jordan Liu4c733742019-02-28 12:03:40 -08006143 if (DBG) {
6144 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
6145 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
6146 }
6147 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
6148 cla, command, p1, p2, p3, data);
6149 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006150
Jordan Liu4c733742019-02-28 12:03:40 -08006151 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006152 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006153 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006154 enforceModifyPermission();
6155 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006156
6157 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6158 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot");
6159
Jordan Liu4c733742019-02-28 12:03:40 -08006160 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006161 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006162 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
6163 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006164 }
6165
6166 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006167 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
6168 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006169 }
6170
6171 // open APDU basic channel assuming the caller has sufficient permissions
6172 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
6173 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006174 final long identity = Binder.clearCallingIdentity();
6175 try {
6176 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
6177 && TextUtils.equals(ISDR_AID, data)) {
6178 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006179 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6180 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006181 if (bestComponent == null
6182 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
6183 loge("The calling package is not allowed to select ISD-R.");
6184 throw new SecurityException(
6185 "The calling package is not allowed to select ISD-R.");
6186 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006187 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006188
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006189 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006190 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
6191 null /* workSource */);
6192 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006193
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006194 // Append the returned status code to the end of the response payload.
6195 String s = Integer.toHexString(
6196 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6197 if (response.payload != null) {
6198 s = IccUtils.bytesToHexString(response.payload) + s;
6199 }
6200 return s;
6201 } finally {
6202 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006203 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006204 }
6205
6206 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006207 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006208 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006209 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6210 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006211
joonhunshin4ac60942023-11-15 15:23:39 +00006212 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6213 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO");
6214
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006215 final long identity = Binder.clearCallingIdentity();
6216 try {
6217 if (DBG) {
6218 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
6219 + p1 + " " + p2 + " " + p3 + ":" + filePath);
6220 }
6221
6222 IccIoResult response =
6223 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
6224 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
6225 subId);
6226
6227 if (DBG) {
6228 log("Exchange SIM_IO [R]" + response);
6229 }
6230
6231 byte[] result = null;
6232 int length = 2;
6233 if (response.payload != null) {
6234 length = 2 + response.payload.length;
6235 result = new byte[length];
6236 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
6237 } else {
6238 result = new byte[length];
6239 }
6240
6241 result[length - 1] = (byte) response.sw2;
6242 result[length - 2] = (byte) response.sw1;
6243 return result;
6244 } finally {
6245 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006246 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006247 }
6248
Nathan Haroldb3014052017-01-25 15:57:32 -08006249 /**
6250 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
6251 * on a particular subscription
6252 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006253 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
6254 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07006255 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006256 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07006257 return null;
6258 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006259
joonhunshin4ac60942023-11-15 15:23:39 +00006260 enforceTelephonyFeatureWithException(callingPackage,
6261 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns");
6262
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006263 final long identity = Binder.clearCallingIdentity();
6264 try {
6265 if (appType != TelephonyManager.APPTYPE_USIM
6266 && appType != TelephonyManager.APPTYPE_SIM) {
6267 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
6268 return null;
6269 }
6270 Object response = sendRequest(
6271 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
6272 if (response instanceof String[]) {
6273 return (String[]) response;
6274 }
yincheng zhao2737e882019-09-06 17:06:54 -07006275 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006276 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08006277 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006278 } finally {
6279 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08006280 }
Nathan Haroldb3014052017-01-25 15:57:32 -08006281 }
6282
yincheng zhao2737e882019-09-06 17:06:54 -07006283 /**
6284 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
6285 * subscription.
6286 *
6287 * @param subId the id of the subscription.
6288 * @param appType the uicc app type, must be USIM or SIM.
6289 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
6290 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006291 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07006292 * @return number of fplmns that is successfully written to the SIM.
6293 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006294 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
6295 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07006296 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6297 mApp, subId, "setForbiddenPlmns");
6298
joonhunshin4ac60942023-11-15 15:23:39 +00006299 enforceTelephonyFeatureWithException(callingPackage,
6300 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns");
6301
yincheng zhao2737e882019-09-06 17:06:54 -07006302 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
6303 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
6304 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
6305 }
6306 if (fplmns == null) {
6307 throw new IllegalArgumentException("Fplmn List provided is null");
6308 }
6309 for (String fplmn : fplmns) {
6310 if (!CellIdentity.isValidPlmn(fplmn)) {
6311 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
6312 }
6313 }
6314 final long identity = Binder.clearCallingIdentity();
6315 try {
6316 Object response = sendRequest(
6317 CMD_SET_FORBIDDEN_PLMNS,
6318 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
6319 subId);
6320 return (int) response;
6321 } finally {
6322 Binder.restoreCallingIdentity(identity);
6323 }
6324 }
6325
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006326 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006327 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006328 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6329 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07006330
joonhunshin4ac60942023-11-15 15:23:39 +00006331 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6332 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus");
6333
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006334 final long identity = Binder.clearCallingIdentity();
6335 try {
6336 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
6337 if (response.payload == null) {
6338 return "";
6339 }
Evan Charltonc66da362014-05-16 14:06:40 -07006340
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006341 // Append the returned status code to the end of the response payload.
6342 String s = Integer.toHexString(
6343 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6344 s = IccUtils.bytesToHexString(response.payload) + s;
6345 return s;
6346 } finally {
6347 Binder.restoreCallingIdentity(identity);
6348 }
Evan Charltonc66da362014-05-16 14:06:40 -07006349 }
6350
Jake Hambye994d462014-02-03 13:10:13 -08006351 /**
6352 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6353 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6354 *
6355 * @param itemID the ID of the item to read
6356 * @return the NV item as a String, or null on error.
6357 */
6358 @Override
6359 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006360 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006361 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6362 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006363
6364 final long identity = Binder.clearCallingIdentity();
6365 try {
6366 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07006367 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006368 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
6369 return value;
6370 } finally {
6371 Binder.restoreCallingIdentity(identity);
6372 }
Jake Hambye994d462014-02-03 13:10:13 -08006373 }
6374
6375 /**
6376 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6377 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6378 *
6379 * @param itemID the ID of the item to read
6380 * @param itemValue the value to write, as a String
6381 * @return true on success; false on any failure
6382 */
6383 @Override
6384 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006385 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006386 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6387 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006388
6389 final long identity = Binder.clearCallingIdentity();
6390 try {
6391 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6392 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006393 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006394 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6395 return success;
6396 } finally {
6397 Binder.restoreCallingIdentity(identity);
6398 }
Jake Hambye994d462014-02-03 13:10:13 -08006399 }
6400
6401 /**
6402 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6403 * Used for device configuration by some CDMA operators.
6404 *
6405 * @param preferredRoamingList byte array containing the new PRL
6406 * @return true on success; false on any failure
6407 */
6408 @Override
6409 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006410 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6411 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006412
6413 final long identity = Binder.clearCallingIdentity();
6414 try {
6415 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6416 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6417 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6418 return success;
6419 } finally {
6420 Binder.restoreCallingIdentity(identity);
6421 }
Jake Hambye994d462014-02-03 13:10:13 -08006422 }
6423
6424 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006425 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006426 * Used for device configuration by some CDMA operators.
6427 *
chen xu6dac5ab2018-10-26 17:39:23 -07006428 * @param slotIndex - device slot.
6429 *
Jake Hambye994d462014-02-03 13:10:13 -08006430 * @return true on success; false on any failure
6431 */
6432 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006433 public boolean resetModemConfig(int slotIndex) {
6434 Phone phone = PhoneFactory.getPhone(slotIndex);
6435 if (phone != null) {
6436 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6437 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006438
joonhunshin4ac60942023-11-15 15:23:39 +00006439 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6440 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig");
6441
chen xu6dac5ab2018-10-26 17:39:23 -07006442 final long identity = Binder.clearCallingIdentity();
6443 try {
6444 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6445 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6446 return success;
6447 } finally {
6448 Binder.restoreCallingIdentity(identity);
6449 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006450 }
chen xu6dac5ab2018-10-26 17:39:23 -07006451 return false;
6452 }
6453
6454 /**
6455 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6456 *
6457 * @param slotIndex - device slot.
6458 *
6459 * @return true on success; false on any failure
6460 */
6461 @Override
6462 public boolean rebootModem(int slotIndex) {
6463 Phone phone = PhoneFactory.getPhone(slotIndex);
6464 if (phone != null) {
6465 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6466 mApp, phone.getSubId(), "rebootModem");
6467
joonhunshin4ac60942023-11-15 15:23:39 +00006468 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6469 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem");
6470
chen xu6dac5ab2018-10-26 17:39:23 -07006471 final long identity = Binder.clearCallingIdentity();
6472 try {
6473 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6474 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6475 return success;
6476 } finally {
6477 Binder.restoreCallingIdentity(identity);
6478 }
6479 }
6480 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006481 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006482
Brad Ebinger51f743a2017-01-23 13:50:20 -08006483 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006484 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6485 * {@link #disableIms(int)}.
6486 * @param slotIndex device slot.
6487 */
6488 public void resetIms(int slotIndex) {
6489 enforceModifyPermission();
6490
joonhunshin4ac60942023-11-15 15:23:39 +00006491 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6492 PackageManager.FEATURE_TELEPHONY_IMS, "resetIms");
6493
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006494 final long identity = Binder.clearCallingIdentity();
6495 try {
6496 if (mImsResolver == null) {
6497 // may happen if the does not support IMS.
6498 return;
6499 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006500 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006501 } finally {
6502 Binder.restoreCallingIdentity(identity);
6503 }
6504 }
6505
6506 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006507 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6508 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006509 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006510 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006511 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006512
6513 final long identity = Binder.clearCallingIdentity();
6514 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006515 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006516 // may happen if the device does not support IMS.
6517 return;
6518 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006519 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006520 } finally {
6521 Binder.restoreCallingIdentity(identity);
6522 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006523 }
6524
6525 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006526 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6527 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006528 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006529 public void disableIms(int slotId) {
6530 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006531
6532 final long identity = Binder.clearCallingIdentity();
6533 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006534 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006535 // may happen if the device does not support IMS.
6536 return;
6537 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006538 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006539 } finally {
6540 Binder.restoreCallingIdentity(identity);
6541 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006542 }
6543
6544 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006545 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6546 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006547 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006548 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006549 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006550 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006551
6552 final long identity = Binder.clearCallingIdentity();
6553 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006554 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006555 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6556 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006557 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006558 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006559 } finally {
6560 Binder.restoreCallingIdentity(identity);
6561 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006562 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006563 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006564 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6565 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006566 @Override
6567 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006568 enforceModifyPermission();
6569
6570 final long identity = Binder.clearCallingIdentity();
6571 try {
6572 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006573 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006574 } finally {
6575 Binder.restoreCallingIdentity(identity);
6576 }
6577 }
6578
6579 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006580 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006581 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006582 */
6583 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6584 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006585
6586 final long identity = Binder.clearCallingIdentity();
6587 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006588 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006589 // may happen if the device does not support IMS.
6590 return null;
6591 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006592 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006593 } finally {
6594 Binder.restoreCallingIdentity(identity);
6595 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006596 }
6597
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006598 /**
6599 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006600 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006601 */
6602 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6603 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006604
6605 final long identity = Binder.clearCallingIdentity();
6606 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006607 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006608 // may happen if the device does not support IMS.
6609 return null;
6610 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006611 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006612 } finally {
6613 Binder.restoreCallingIdentity(identity);
6614 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006615 }
6616
Brad Ebinger884c07b2018-02-15 16:17:40 -08006617 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006618 * Sets the ImsService Package Name that Telephony will bind to.
6619 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006620 * @param slotIndex the slot ID that the ImsService should bind for.
6621 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006622 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006623 * @param featureTypes An integer array of feature types associated with a packageName.
6624 * @param packageName The name of the package that the current configuration will be replaced
6625 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006626 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006627 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006628 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6629 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006630 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006631 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006632 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006633
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006634 final long identity = Binder.clearCallingIdentity();
6635 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006636 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006637 // may happen if the device does not support IMS.
6638 return false;
6639 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006640 Map<Integer, String> featureConfig = new HashMap<>();
6641 for (int featureType : featureTypes) {
6642 featureConfig.put(featureType, packageName);
6643 }
6644 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6645 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006646 } finally {
6647 Binder.restoreCallingIdentity(identity);
6648 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006649 }
6650
6651 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006652 * Clears any carrier ImsService overrides for the slot index specified that were previously
6653 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6654 *
6655 * This should only be used for testing.
6656 *
6657 * @param slotIndex the slot ID that the ImsService should bind for.
6658 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6659 */
6660 @Override
6661 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006662 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6663 "clearCarrierImsServiceOverride");
6664 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006665 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006666
6667 final long identity = Binder.clearCallingIdentity();
6668 try {
6669 if (mImsResolver == null) {
6670 // may happen if the device does not support IMS.
6671 return false;
6672 }
6673 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6674 } finally {
6675 Binder.restoreCallingIdentity(identity);
6676 }
6677 }
6678
6679 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006680 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006681 *
6682 * @param slotId The slot that the ImsService is associated with.
6683 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6684 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006685 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006686 * @return the package name of the ImsService configuration.
6687 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006688 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6689 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006690 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006691 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6692 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006693
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006694 final long identity = Binder.clearCallingIdentity();
6695 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006696 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006697 // may happen if the device does not support IMS.
6698 return "";
6699 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006700 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006701 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6702 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006703 } finally {
6704 Binder.restoreCallingIdentity(identity);
6705 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006706 }
6707
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006708 /**
6709 * Get the MmTelFeature state associated with the requested subscription id.
6710 * @param subId The subscription that the MmTelFeature is associated with.
6711 * @param callback A callback with an integer containing the
6712 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6713 */
6714 @Override
6715 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6716 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006717 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6718 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6719 "IMS not available on device.");
6720 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006721 final long token = Binder.clearCallingIdentity();
6722 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006723 int slotId = getSlotIndex(subId);
6724 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6725 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6726 + subId + "'");
6727 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6728 }
6729 verifyImsMmTelConfiguredOrThrow(slotId);
6730 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6731 try {
6732 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6733 } catch (RemoteException e) {
6734 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6735 + "Ignore");
6736 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006737 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006738 } catch (ImsException e) {
6739 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006740 } finally {
6741 Binder.restoreCallingIdentity(token);
6742 }
6743 }
6744
Daniel Brightbb5840b2021-01-12 15:48:18 -08006745 /**
6746 * Sets the ims registration state on all valid {@link Phone}s.
6747 */
6748 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006749 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006750
6751 final long identity = Binder.clearCallingIdentity();
6752 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006753 // NOTE: Before S, this method only set the default phone.
6754 for (final Phone phone : PhoneFactory.getPhones()) {
6755 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6756 phone.setImsRegistrationState(registered);
6757 }
6758 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006759 } finally {
6760 Binder.restoreCallingIdentity(identity);
6761 }
Wink Saville36469e72014-06-11 15:17:00 -07006762 }
6763
6764 /**
Stuart Scott54788802015-03-30 13:18:01 -07006765 * Set the network selection mode to automatic.
6766 *
6767 */
6768 @Override
6769 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006770 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6771 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006772
joonhunshin4ac60942023-11-15 15:23:39 +00006773 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6774 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic");
6775
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006776 final long identity = Binder.clearCallingIdentity();
6777 try {
shilufc958392020-01-20 11:36:01 -08006778 if (!isActiveSubscription(subId)) {
6779 return;
6780 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006781 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006782 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6783 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006784 } finally {
6785 Binder.restoreCallingIdentity(identity);
6786 }
Stuart Scott54788802015-03-30 13:18:01 -07006787 }
6788
Jack Yud10cdd42020-09-28 20:28:01 -07006789 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006790 * Ask the radio to connect to the input network and change selection mode to manual.
6791 *
6792 * @param subId the id of the subscription.
6793 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6794 * the operator to attach to.
6795 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6796 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6797 * normal network selection next time.
6798 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006799 */
6800 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006801 public boolean setNetworkSelectionModeManual(
6802 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006803 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6804 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006805
joonhunshin4ac60942023-11-15 15:23:39 +00006806 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6807 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual");
6808
Jack Yu285100e2022-12-02 22:48:35 -08006809 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006810 if (!isActiveSubscription(subId)) {
6811 return false;
6812 }
6813
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006814 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006815 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006816 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006817 if (DBG) {
6818 log("setNetworkSelectionModeManual: subId: " + subId
6819 + " operator: " + operatorInfo);
6820 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006821 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6822 } finally {
6823 Binder.restoreCallingIdentity(identity);
6824 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006825 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006826 /**
shilu84f6e8b2019-12-19 13:58:01 -08006827 * Get the manual network selection
6828 *
6829 * @param subId the id of the subscription.
6830 *
6831 * @return the previously saved user selected PLMN
6832 */
6833 @Override
6834 public String getManualNetworkSelectionPlmn(int subId) {
6835 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006836 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6837 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006838
joonhunshin4ac60942023-11-15 15:23:39 +00006839 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6840 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn");
6841
shilu84f6e8b2019-12-19 13:58:01 -08006842 final long identity = Binder.clearCallingIdentity();
6843 try {
6844 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006845 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006846 }
6847
6848 final Phone phone = getPhone(subId);
6849 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006850 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006851 }
6852 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6853 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006854 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006855 } finally {
6856 Binder.restoreCallingIdentity(identity);
6857 }
6858 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006859
6860 /**
6861 * Scans for available networks.
6862 */
6863 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006864 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6865 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006866 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6867 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006868 LocationAccessPolicy.LocationPermissionResult locationResult =
6869 LocationAccessPolicy.checkLocationPermission(mApp,
6870 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6871 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006872 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006873 .setCallingPid(Binder.getCallingPid())
6874 .setCallingUid(Binder.getCallingUid())
6875 .setMethod("getCellNetworkScanResults")
6876 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006877 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6878 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006879 .build());
6880 switch (locationResult) {
6881 case DENIED_HARD:
6882 throw new SecurityException("Not allowed to access scan results -- location");
6883 case DENIED_SOFT:
6884 return null;
6885 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006886
Pengquan Menga1bb6272018-09-06 09:59:22 -07006887 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006888 try {
6889 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006890 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006891 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006892 } finally {
6893 Binder.restoreCallingIdentity(identity);
6894 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006895 }
6896
6897 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006898 * Get the call forwarding info, given the call forwarding reason.
6899 */
6900 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006901 public void getCallForwarding(int subId, int callForwardingReason,
6902 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006903 enforceReadPrivilegedPermission("getCallForwarding");
joonhunshin4ac60942023-11-15 15:23:39 +00006904
6905 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6906 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding");
6907
Shuo Qian4a594052020-01-23 11:59:30 -08006908 long identity = Binder.clearCallingIdentity();
6909 try {
6910 if (DBG) {
6911 log("getCallForwarding: subId " + subId
6912 + " callForwardingReason" + callForwardingReason);
6913 }
Hall Liu27d24262020-09-18 19:04:59 -07006914
6915 Phone phone = getPhone(subId);
6916 if (phone == null) {
6917 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006918 callback.onError(
6919 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006920 } catch (RemoteException e) {
6921 // ignore
6922 }
6923 return;
6924 }
6925
6926 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6927 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6928 @Override
6929 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6930 try {
6931 callback.onCallForwardingInfoAvailable(info);
6932 } catch (RemoteException e) {
6933 // ignore
6934 }
6935 }
6936
6937 @Override
6938 public void onError(int error) {
6939 try {
6940 callback.onError(error);
6941 } catch (RemoteException e) {
6942 // ignore
6943 }
6944 }
6945 });
6946 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006947 } finally {
6948 Binder.restoreCallingIdentity(identity);
6949 }
6950 }
6951
6952 /**
6953 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6954 * reason, the number to forward, and the timeout before the forwarding is attempted.
6955 */
6956 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006957 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6958 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006959 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006960
6961 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6962 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding");
6963
Shuo Qian4a594052020-01-23 11:59:30 -08006964 long identity = Binder.clearCallingIdentity();
6965 try {
6966 if (DBG) {
6967 log("setCallForwarding: subId " + subId
6968 + " callForwardingInfo" + callForwardingInfo);
6969 }
Hall Liu27d24262020-09-18 19:04:59 -07006970
6971 Phone phone = getPhone(subId);
6972 if (phone == null) {
6973 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006974 callback.accept(
6975 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006976 } catch (RemoteException e) {
6977 // ignore
6978 }
6979 return;
6980 }
6981
6982 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6983 FunctionalUtils.ignoreRemoteException(callback::accept));
6984
6985 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006986 } finally {
6987 Binder.restoreCallingIdentity(identity);
6988 }
6989 }
6990
6991 /**
Hall Liu27d24262020-09-18 19:04:59 -07006992 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006993 */
6994 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006995 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006996 enforceReadPrivilegedPermission("getCallWaitingStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00006997
6998 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6999 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus");
7000
Shuo Qian4a594052020-01-23 11:59:30 -08007001 long identity = Binder.clearCallingIdentity();
7002 try {
Hall Liu27d24262020-09-18 19:04:59 -07007003 Phone phone = getPhone(subId);
7004 if (phone == null) {
7005 try {
7006 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7007 } catch (RemoteException e) {
7008 // ignore
7009 }
7010 return;
7011 }
SongFerngWang0e767992021-03-31 22:08:45 +08007012 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7013 PersistableBundle c = configManager.getConfigForSubId(subId);
7014 boolean requireUssd = c.getBoolean(
7015 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007016
Shuo Qian4a594052020-01-23 11:59:30 -08007017 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08007018 if (requireUssd) {
7019 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7020 getSubscriptionCarrierId(subId));
7021 String newUssdCommand = "";
7022 try {
7023 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007024 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007025 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
7026 } catch (NullPointerException e) {
7027 loge("Failed to generate USSD number" + e);
7028 }
7029 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7030 mMainThreadHandler, callback, carrierXmlParser,
7031 CarrierXmlParser.SsEntry.SSAction.QUERY);
7032 final String ussdCommand = newUssdCommand;
7033 Executors.newSingleThreadExecutor().execute(() -> {
7034 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7035 });
7036 } else {
7037 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
7038 callback::accept);
7039 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
7040 }
Shuo Qian4a594052020-01-23 11:59:30 -08007041 } finally {
7042 Binder.restoreCallingIdentity(identity);
7043 }
7044 }
7045
7046 /**
Hall Liu27d24262020-09-18 19:04:59 -07007047 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007048 */
7049 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007050 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007051 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007052
7053 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7054 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus");
7055
Shuo Qian4a594052020-01-23 11:59:30 -08007056 long identity = Binder.clearCallingIdentity();
7057 try {
Hall Liu27d24262020-09-18 19:04:59 -07007058 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
7059
7060 Phone phone = getPhone(subId);
7061 if (phone == null) {
7062 try {
7063 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7064 } catch (RemoteException e) {
7065 // ignore
7066 }
7067 return;
7068 }
7069
SongFerngWang0e767992021-03-31 22:08:45 +08007070 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7071 PersistableBundle c = configManager.getConfigForSubId(subId);
7072 boolean requireUssd = c.getBoolean(
7073 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007074
SongFerngWang0e767992021-03-31 22:08:45 +08007075 if (DBG) log("getCallWaitingStatus: subId " + subId);
7076 if (requireUssd) {
7077 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7078 getSubscriptionCarrierId(subId));
7079 CarrierXmlParser.SsEntry.SSAction ssAction =
7080 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
7081 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
7082 String newUssdCommand = "";
7083 try {
7084 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007085 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007086 .makeCommand(ssAction, null);
7087 } catch (NullPointerException e) {
7088 loge("Failed to generate USSD number" + e);
7089 }
7090 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7091 mMainThreadHandler, callback, carrierXmlParser, ssAction);
7092 final String ussdCommand = newUssdCommand;
7093 Executors.newSingleThreadExecutor().execute(() -> {
7094 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7095 });
7096 } else {
7097 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
7098 FunctionalUtils.ignoreRemoteException(callback::accept));
7099
7100 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
7101 }
Shuo Qian4a594052020-01-23 11:59:30 -08007102 } finally {
7103 Binder.restoreCallingIdentity(identity);
7104 }
7105 }
7106
7107 /**
yinxub1bed742017-04-17 11:45:04 -07007108 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07007109 *
yinxub1bed742017-04-17 11:45:04 -07007110 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007111 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
7112 * location related information which will be sent if the caller already possess
7113 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07007114 * @param request contains the radio access networks with bands/channels to scan
7115 * @param messenger callback messenger for scan results or errors
7116 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07007117 * @return the id of the requested scan which can be used to stop the scan.
7118 */
7119 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007120 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
7121 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007122 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007123 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7124 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08007125 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007126 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
7127 if (!renounceFineLocationAccess) {
7128 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007129 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7130 .setCallingPackage(callingPackage)
7131 .setCallingFeatureId(callingFeatureId)
7132 .setCallingPid(Binder.getCallingPid())
7133 .setCallingUid(Binder.getCallingUid())
7134 .setMethod("requestNetworkScan")
7135 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7136 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7137 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7138 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007139 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08007140 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07007141 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
7142 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08007143 if (e != null) {
7144 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
7145 throw e;
7146 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07007147 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08007148 return TelephonyScanManager.INVALID_SCAN_ID;
7149 }
7150 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007151 }
joonhunshin4ac60942023-11-15 15:23:39 +00007152
7153 enforceTelephonyFeatureWithException(callingPackage,
7154 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan");
7155
Hall Liu912dfd32019-04-25 14:02:26 -07007156 int callingUid = Binder.getCallingUid();
7157 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07007158 final long identity = Binder.clearCallingIdentity();
7159 try {
7160 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07007161 renounceFineLocationAccess, request, messenger, binder,
7162 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07007163 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07007164 } finally {
7165 Binder.restoreCallingIdentity(identity);
7166 }
yinxu504e1392017-04-12 16:03:22 -07007167 }
7168
Hall Liub2ac8ef2019-02-28 15:56:23 -08007169 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07007170 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00007171 boolean hasCarrierPriv;
7172 final long identity = Binder.clearCallingIdentity();
7173 try {
7174 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
7175 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
7176 } finally {
7177 Binder.restoreCallingIdentity(identity);
7178 }
Hall Liu558027f2019-05-15 19:14:05 -07007179 boolean hasNetworkScanPermission =
7180 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007181 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07007182
7183 if (!hasCarrierPriv && !hasNetworkScanPermission) {
7184 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
7185 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08007186 }
7187
7188 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
7189 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08007190 if (ras.getChannels() != null && ras.getChannels().length > 0) {
7191 return new SecurityException("Specific channels must not be"
7192 + " scanned without location access.");
7193 }
7194 }
7195 }
7196
Hall Liub2ac8ef2019-02-28 15:56:23 -08007197 return null;
7198 }
7199
yinxu504e1392017-04-12 16:03:22 -07007200 /**
7201 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07007202 *
7203 * @param subId id of the subscription
7204 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07007205 */
7206 @Override
7207 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007208 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7209 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007210
Hall Liu912dfd32019-04-25 14:02:26 -07007211 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007212 final long identity = Binder.clearCallingIdentity();
7213 try {
Hall Liu912dfd32019-04-25 14:02:26 -07007214 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007215 } finally {
7216 Binder.restoreCallingIdentity(identity);
7217 }
yinxu504e1392017-04-12 16:03:22 -07007218 }
7219
7220 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08007221 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07007222 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08007223 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07007224 */
7225 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08007226 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08007227 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007228 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08007229 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007230
joonhunshin4ac60942023-11-15 15:23:39 +00007231 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7232 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask");
7233
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007234 final long identity = Binder.clearCallingIdentity();
7235 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007236 if (DBG) log("getAllowedNetworkTypesBitmask");
7237 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
7238 int networkTypesBitmask = (result != null ? result[0] : -1);
7239 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
7240 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007241 } finally {
7242 Binder.restoreCallingIdentity(identity);
7243 }
Jake Hamby7c27be32014-03-03 13:25:59 -08007244 }
7245
7246 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007247 * Get the allowed network types for certain reason.
7248 *
7249 * @param subId the id of the subscription.
7250 * @param reason the reason the allowed network type change is taking place
7251 * @return the allowed network types.
7252 */
7253 @Override
7254 public long getAllowedNetworkTypesForReason(int subId,
7255 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07007256 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007257 mApp, subId, "getAllowedNetworkTypesForReason");
joonhunshin4ac60942023-11-15 15:23:39 +00007258
7259 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7260 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesForReason");
7261
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007262 final long identity = Binder.clearCallingIdentity();
7263 try {
Jack Yu7247ac82023-03-02 23:52:10 -08007264 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007265 } finally {
7266 Binder.restoreCallingIdentity(identity);
7267 }
7268 }
7269
7270 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07007271 * Enable/Disable E-UTRA-NR Dual Connectivity
7272 * @param subId subscription id of the sim card
7273 * @param nrDualConnectivityState expected NR dual connectivity state
7274 * This can be passed following states
7275 * <ol>
7276 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
7277 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
7278 * <li>Disable NR dual connectivity and force secondary cell to be released
7279 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
7280 * </ol>
7281 * @return operation result.
7282 */
7283 @Override
7284 public int setNrDualConnectivityState(int subId,
7285 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
7286 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7287 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007288 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007289 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7290 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
7291 }
7292
Sooraj Sasindran37444802020-08-11 10:40:43 -07007293 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7294 final long identity = Binder.clearCallingIdentity();
7295 try {
7296 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
7297 nrDualConnectivityState, subId,
7298 workSource);
7299 if (DBG) log("enableNRDualConnectivity result: " + result);
7300 return result;
7301 } finally {
7302 Binder.restoreCallingIdentity(identity);
7303 }
7304 }
7305
7306 /**
7307 * Is E-UTRA-NR Dual Connectivity enabled
7308 * @return true if dual connectivity is enabled else false
7309 */
7310 @Override
7311 public boolean isNrDualConnectivityEnabled(int subId) {
7312 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007313 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07007314 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007315 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007316 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7317 return false;
7318 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07007319 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7320 final long identity = Binder.clearCallingIdentity();
7321 try {
7322 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
7323 null, subId, workSource);
7324 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
7325 return isEnabled;
7326 } finally {
7327 Binder.restoreCallingIdentity(identity);
7328 }
7329 }
7330
7331 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007332 * Set the allowed network types of the device and
7333 * provide the reason triggering the allowed network change.
7334 *
7335 * @param subId the id of the subscription.
7336 * @param reason the reason the allowed network type change is taking place
7337 * @param allowedNetworkTypes the allowed network types.
7338 * @return true on success; false on any failure.
7339 */
7340 @Override
7341 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08007342 @TelephonyManager.AllowedNetworkTypesReason int reason,
7343 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007344 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7345 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007346 // If the caller only has carrier privileges, then they should not be able to override
7347 // any network types which were set for security reasons.
7348 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
7349 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007350 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007351 throw new SecurityException(
7352 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007353 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007354 }
joonhunshin4ac60942023-11-15 15:23:39 +00007355
7356 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7357 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason");
7358
SongFerngWang3ef3e072020-12-21 16:41:52 +08007359 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007360 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08007361 return false;
7362 }
7363 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
7364 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007365 return false;
7366 }
7367
Jack Yu5b494332023-01-23 18:18:04 +00007368 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
7369 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007370
Jack Yue37dd262022-12-16 11:53:37 -08007371 Phone phone = getPhone(subId);
7372 if (phone == null) {
7373 return false;
7374 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007375
Jack Yue37dd262022-12-16 11:53:37 -08007376 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007377 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007378 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08007379 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007380
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007381 final long identity = Binder.clearCallingIdentity();
7382 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007383 Boolean success = (Boolean) sendRequest(
7384 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
7385 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
7386
7387 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
7388 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007389 } finally {
7390 Binder.restoreCallingIdentity(identity);
7391 }
7392 }
7393
7394 /**
Miaoa84611c2019-03-15 09:21:10 +08007395 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08007396 *
Miaoa84611c2019-03-15 09:21:10 +08007397 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07007398 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08007399 * @hide
7400 */
7401 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08007402 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007403 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007404
7405 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7406 PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber");
7407
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007408 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08007409 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007410 try {
Miaoa84611c2019-03-15 09:21:10 +08007411 if (phone != null) {
7412 return phone.hasMatchedTetherApnSetting();
7413 } else {
7414 return false;
7415 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007416 } finally {
7417 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007418 }
Junda Liu475951f2014-11-07 16:45:03 -08007419 }
7420
7421 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007422 * Get the user enabled state of Mobile Data.
7423 *
7424 * TODO: remove and use isUserDataEnabled.
7425 * This can't be removed now because some vendor codes
7426 * calls through ITelephony directly while they should
7427 * use TelephonyManager.
7428 *
7429 * @return true on enabled
7430 */
7431 @Override
7432 public boolean getDataEnabled(int subId) {
7433 return isUserDataEnabled(subId);
7434 }
7435
7436 /**
7437 * Get whether mobile data is enabled per user setting.
7438 *
7439 * There are other factors deciding whether mobile data is actually enabled, but they are
7440 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007441 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007442 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7443 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007444 *
7445 * @return {@code true} if data is enabled else {@code false}
7446 */
7447 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007448 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007449 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007450 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007451 try {
7452 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7453 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007454 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007455 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7456 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007457 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007458 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007459 mApp, subId, functionName);
7460
Robert Greenwalt646120a2014-05-23 11:54:03 -07007461 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007462
7463 final long identity = Binder.clearCallingIdentity();
7464 try {
Jack Yu285100e2022-12-02 22:48:35 -08007465 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007466 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7467 Phone phone = PhoneFactory.getPhone(phoneId);
7468 if (phone != null) {
7469 boolean retVal = phone.isUserDataEnabled();
7470 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7471 return retVal;
7472 } else {
7473 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7474 return false;
7475 }
7476 } finally {
7477 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007478 }
7479 }
7480
7481 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007482 * Checks if the device is capable of mobile data by considering whether whether the
7483 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7484 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007485 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007486 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007487 */
7488 @Override
7489 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007490 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007491 try {
7492 try {
7493 mApp.enforceCallingOrSelfPermission(
7494 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007495 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007496 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007497 try {
7498 mApp.enforceCallingOrSelfPermission(
7499 android.Manifest.permission.READ_PHONE_STATE,
7500 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007501 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007502 mApp.enforceCallingOrSelfPermission(
7503 permission.READ_BASIC_PHONE_STATE, functionName);
7504 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007505 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007506 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007507 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007508 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007509
joonhunshin4ac60942023-11-15 15:23:39 +00007510 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7511 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled");
7512
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007513 final long identity = Binder.clearCallingIdentity();
7514 try {
Jack Yu285100e2022-12-02 22:48:35 -08007515 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007516 Phone phone = PhoneFactory.getPhone(phoneId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007517 if (phone != null && phone.getDataSettingsManager() != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007518 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007519 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007520 return retVal;
7521 } else {
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007522 if (DBG) {
7523 loge("isDataEnabled: no phone or no DataSettingsManager subId="
7524 + subId + " retVal=false");
7525 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007526 return false;
7527 }
7528 } finally {
7529 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007530 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007531 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007532
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007533 /**
7534 * Check if data is enabled for a specific reason
7535 * @param subId Subscription index
7536 * @param reason the reason the data enable change is taking place
7537 * @return {@code true} if the overall data is enabled; {@code false} if not.
7538 */
7539 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007540 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007541 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007542 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007543 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007544 try {
7545 mApp.enforceCallingOrSelfPermission(
7546 android.Manifest.permission.ACCESS_NETWORK_STATE,
7547 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007548 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007549 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7550 functionName);
7551 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007552 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007553 try {
7554 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007555 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007556 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007557 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007558 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007559 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007560 }
7561
joonhunshin4ac60942023-11-15 15:23:39 +00007562 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7563 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007564
7565 final long identity = Binder.clearCallingIdentity();
7566 try {
Jack Yu285100e2022-12-02 22:48:35 -08007567 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007568 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007569 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007570 + " reason=" + reason);
7571 }
7572 Phone phone = PhoneFactory.getPhone(phoneId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007573 if (phone != null && phone.getDataSettingsManager() != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007574 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007575 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007576 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007577 return retVal;
7578 } else {
7579 if (DBG) {
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007580 loge("isDataEnabledForReason: no phone or no DataSettingsManager subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007581 + subId + " retVal=false");
7582 }
7583 return false;
7584 }
7585 } finally {
7586 Binder.restoreCallingIdentity(identity);
7587 }
7588 }
7589
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007590 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007591 public int getCarrierPrivilegeStatus(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00007592 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7593 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus");
7594
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007595 // No permission needed; this only lets the caller inspect their own status.
7596 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007597 }
Junda Liu29340342014-07-10 15:23:27 -07007598
7599 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007600 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007601 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
joonhunshin4ac60942023-11-15 15:23:39 +00007602
7603 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7604 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatusForUid");
7605
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007606 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7607 }
7608
7609 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7610 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007611 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007612 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007613 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7614 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007615 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7616 if (cpt == null) {
7617 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007618 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7619 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007620 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007621 }
7622
7623 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007624 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007625 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
joonhunshin4ac60942023-11-15 15:23:39 +00007626
7627 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7628 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage");
7629
chen xuf7e9fe82019-05-09 19:31:02 -07007630 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007631 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007632 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007633 Phone phone = getPhone(subId);
7634 if (phone == null) {
7635 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7636 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7637 }
7638 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7639 if (cpt == null) {
7640 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007641 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7642 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007643 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007644 }
7645
7646 @Override
7647 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007648 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007649
7650 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7651 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7652 "checkCarrierPrivilegesForPackageAnyPhone");
7653
Rambo Wange7209ce2022-02-23 13:41:02 -08007654 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7655 }
7656
7657 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007658 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007659 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007660 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007661 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007662 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7663 Phone phone = PhoneFactory.getPhone(phoneId);
7664 if (phone == null) {
7665 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007666 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007667 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7668 if (cpt == null) {
7669 continue;
7670 }
7671 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007672 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7673 break;
7674 }
7675 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007676 return result;
Junda Liu29340342014-07-10 15:23:27 -07007677 }
Derek Tan89e89d42014-07-08 17:00:10 -07007678
7679 @Override
Junda Liue64de782015-04-16 17:19:16 -07007680 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007681 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007682
7683 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7684 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7685 "getCarrierPackageNamesForIntentAndPhone");
7686
Rambo Wang8a247eb2022-02-08 21:11:18 +00007687 Phone phone = PhoneFactory.getPhone(phoneId);
7688 if (phone == null) {
7689 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007690 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007691 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7692 if (cpt == null) {
7693 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007694 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007695 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007696 }
7697
Amith Yamasani6e118872016-02-19 12:53:51 -08007698 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007699 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007700 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007701 Phone phone = PhoneFactory.getPhone(phoneId);
7702 if (phone == null) {
7703 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007704 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007705 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7706 if (cpt == null) {
7707 return Collections.emptyList();
7708 }
7709 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007710 }
7711
chen xuf7e9fe82019-05-09 19:31:02 -07007712 @Override
7713 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007714 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
joonhunshin4ac60942023-11-15 15:23:39 +00007715
7716 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7717 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7718 "getPackagesWithCarrierPrivilegesForAllPhones");
7719
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007720 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007721 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007722 try {
7723 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7724 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7725 }
7726 } finally {
7727 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007728 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007729 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007730 }
7731
Rambo Wang6812ffb2022-03-15 16:54:17 -07007732 @Override
7733 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7734 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7735
joonhunshin4ac60942023-11-15 15:23:39 +00007736 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7737 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7738 "getCarrierServicePackageNameForLogicalSlot");
7739
Rambo Wang6812ffb2022-03-15 16:54:17 -07007740 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7741 if (phone == null) {
7742 return null;
7743 }
7744 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7745 if (cpt == null) {
7746 return null;
7747 }
7748 return cpt.getCarrierServicePackageName();
7749 }
7750
Wink Savilleb564aae2014-10-23 10:18:09 -07007751 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007752 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007753 UiccPort port = phone == null ? null : phone.getUiccPort();
7754 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007755 return null;
7756 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007757 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007758 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007759 return null;
7760 }
7761 return iccId;
7762 }
7763
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007764 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007765 public void setCallComposerStatus(int subId, int status) {
7766 enforceModifyPermission();
7767
joonhunshin4ac60942023-11-15 15:23:39 +00007768 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7769 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus");
7770
Shuo Qiane4e11672020-12-15 22:15:33 -08007771 final long identity = Binder.clearCallingIdentity();
7772 try {
7773 Phone phone = getPhone(subId);
7774 if (phone != null) {
7775 Phone defaultPhone = phone.getImsPhone();
7776 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7777 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7778 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007779 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7780 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007781 }
7782 }
Shuo Qian284ae752020-12-22 19:10:14 -08007783 } catch (ImsException e) {
7784 throw new ServiceSpecificException(e.getCode());
7785 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007786 Binder.restoreCallingIdentity(identity);
7787 }
7788 }
7789
7790 @Override
7791 public int getCallComposerStatus(int subId) {
7792 enforceReadPrivilegedPermission("getCallComposerStatus");
7793
joonhunshin4ac60942023-11-15 15:23:39 +00007794 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7795 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus");
7796
Shuo Qiane4e11672020-12-15 22:15:33 -08007797 final long identity = Binder.clearCallingIdentity();
7798 try {
7799 Phone phone = getPhone(subId);
7800 if (phone != null) {
7801 Phone defaultPhone = phone.getImsPhone();
7802 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7803 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7804 return imsPhone.getCallComposerStatus();
7805 }
7806 }
7807 } finally {
7808 Binder.restoreCallingIdentity(identity);
7809 }
7810 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7811 }
7812
7813 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007814 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7815 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007816 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007817 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007818
joonhunshin4ac60942023-11-15 15:23:39 +00007819 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7820 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7821 "setLine1NumberForDisplayForSubscriber");
7822
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007823 final long identity = Binder.clearCallingIdentity();
7824 try {
7825 final String iccId = getIccId(subId);
7826 final Phone phone = getPhone(subId);
7827 if (phone == null) {
7828 return false;
7829 }
7830 final String subscriberId = phone.getSubscriberId();
7831
7832 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007833 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007834 + subscriberId + " to " + number);
7835 }
7836
7837 if (TextUtils.isEmpty(iccId)) {
7838 return false;
7839 }
7840
7841 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7842
7843 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7844 if (alphaTag == null) {
7845 editor.remove(alphaTagPrefKey);
7846 } else {
7847 editor.putString(alphaTagPrefKey, alphaTag);
7848 }
7849
7850 // Record both the line number and IMSI for this ICCID, since we need to
7851 // track all merged IMSIs based on line number
7852 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7853 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7854 if (number == null) {
7855 editor.remove(numberPrefKey);
7856 editor.remove(subscriberPrefKey);
7857 } else {
7858 editor.putString(numberPrefKey, number);
7859 editor.putString(subscriberPrefKey, subscriberId);
7860 }
7861
7862 editor.commit();
7863 return true;
7864 } finally {
7865 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007866 }
Derek Tan7226c842014-07-02 17:42:23 -07007867 }
7868
7869 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007870 public String getLine1NumberForDisplay(int subId, String callingPackage,
7871 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007872 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007873 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007874 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007875 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007876 return null;
7877 }
Derek Tan97ebb422014-09-05 16:55:38 -07007878
joonhunshin4ac60942023-11-15 15:23:39 +00007879 enforceTelephonyFeatureWithException(callingPackage,
7880 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay");
7881
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007882 final long identity = Binder.clearCallingIdentity();
7883 try {
7884 String iccId = getIccId(subId);
7885 if (iccId != null) {
7886 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7887 if (DBG_MERGE) {
7888 log("getLine1NumberForDisplay returning "
7889 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7890 }
7891 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007892 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007893 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7894 return null;
7895 } finally {
7896 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007897 }
Derek Tan7226c842014-07-02 17:42:23 -07007898 }
7899
7900 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007901 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7902 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007903 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007904 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007905 return null;
7906 }
Derek Tan97ebb422014-09-05 16:55:38 -07007907
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007908 final long identity = Binder.clearCallingIdentity();
7909 try {
7910 String iccId = getIccId(subId);
7911 if (iccId != null) {
7912 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7913 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7914 }
7915 return null;
7916 } finally {
7917 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007918 }
Derek Tan7226c842014-07-02 17:42:23 -07007919 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007920
7921 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007922 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7923 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007924 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7925 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007926 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007927 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007928 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007929 return null;
7930 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007931
Jordan Liub49b04b2019-05-06 14:45:15 -07007932 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7933 // the process, where TelephonyManager was instantiated.
7934 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007935 final long identity = Binder.clearCallingIdentity();
7936 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007937 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007938 final TelephonyManager tele = TelephonyManager.from(context);
7939 final SubscriptionManager sub = SubscriptionManager.from(context);
7940
7941 // Figure out what subscribers are currently active
7942 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007943
Jordan Liub49b04b2019-05-06 14:45:15 -07007944 // Only consider subs which match the current subId
7945 // This logic can be simplified. See b/131189269 for progress.
7946 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007947 activeSubscriberIds.add(tele.getSubscriberId(subId));
7948 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007949
7950 // First pass, find a number override for an active subscriber
7951 String mergeNumber = null;
7952 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7953 for (String key : prefs.keySet()) {
7954 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7955 final String subscriberId = (String) prefs.get(key);
7956 if (activeSubscriberIds.contains(subscriberId)) {
7957 final String iccId = key.substring(
7958 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7959 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7960 mergeNumber = (String) prefs.get(numberKey);
7961 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007962 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007963 + " for active subscriber " + subscriberId);
7964 }
7965 if (!TextUtils.isEmpty(mergeNumber)) {
7966 break;
7967 }
7968 }
7969 }
7970 }
7971
7972 // Shortcut when no active merged subscribers
7973 if (TextUtils.isEmpty(mergeNumber)) {
7974 return null;
7975 }
7976
7977 // Second pass, find all subscribers under that line override
7978 final ArraySet<String> result = new ArraySet<>();
7979 for (String key : prefs.keySet()) {
7980 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7981 final String number = (String) prefs.get(key);
7982 if (mergeNumber.equals(number)) {
7983 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7984 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7985 final String subscriberId = (String) prefs.get(subscriberKey);
7986 if (!TextUtils.isEmpty(subscriberId)) {
7987 result.add(subscriberId);
7988 }
7989 }
7990 }
7991 }
7992
7993 final String[] resultArray = result.toArray(new String[result.size()]);
7994 Arrays.sort(resultArray);
7995 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007996 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007997 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7998 }
7999 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07008000 } finally {
8001 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08008002 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08008003 }
8004
8005 @Override
zoey chen38003472019-12-13 17:16:31 +08008006 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
8007 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07008008
joonhunshin4ac60942023-11-15 15:23:39 +00008009 enforceTelephonyFeatureWithException(callingPackage,
8010 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup");
8011
Malcolm Chen6ca97372019-07-01 16:28:21 -07008012 final long identity = Binder.clearCallingIdentity();
8013 try {
8014 final TelephonyManager telephonyManager = mApp.getSystemService(
8015 TelephonyManager.class);
8016 String subscriberId = telephonyManager.getSubscriberId(subId);
8017 if (subscriberId == null) {
8018 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08008019 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07008020 + subId);
8021 }
8022 return null;
8023 }
8024
Jack Yu3beaf9d2023-04-14 09:17:27 -07008025 final SubscriptionInfo info = getSubscriptionManagerService()
8026 .getSubscriptionInfo(subId);
8027 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07008028 // If it doesn't belong to any group, return just subscriberId of itself.
8029 if (groupUuid == null) {
8030 return new String[]{subscriberId};
8031 }
8032
8033 // Get all subscriberIds from the group.
8034 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07008035 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
8036 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
8037 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07008038 for (SubscriptionInfo subInfo : groupInfos) {
8039 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
8040 if (subscriberId != null) {
8041 mergedSubscriberIds.add(subscriberId);
8042 }
8043 }
8044
8045 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
8046 } finally {
8047 Binder.restoreCallingIdentity(identity);
8048
8049 }
8050 }
8051
8052 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008053 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008054 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08008055 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008056
joonhunshin4ac60942023-11-15 15:23:39 +00008057 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8058 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride");
8059
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008060 final long identity = Binder.clearCallingIdentity();
8061 try {
8062 final Phone phone = getPhone(subId);
8063 return phone == null ? false : phone.setOperatorBrandOverride(brand);
8064 } finally {
8065 Binder.restoreCallingIdentity(identity);
8066 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07008067 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05008068
8069 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008070 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008071 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
8072 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008073 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
8074 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008075
8076 final long identity = Binder.clearCallingIdentity();
8077 try {
8078 final Phone phone = getPhone(subId);
8079 if (phone == null) {
8080 return false;
8081 }
8082 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
8083 cdmaNonRoamingList);
8084 } finally {
8085 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008086 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008087 }
8088
8089 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07008090 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008091 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08008092 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008093 if (phone == null) {
8094 return raf;
8095 }
8096
Shuo Qiandee53402020-05-29 14:08:15 -07008097 try {
8098 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008099 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07008100 mApp, phone.getSubId(), "getRadioAccessFamily");
8101 } catch (SecurityException e) {
8102 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
8103 throw e;
8104 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008105
joonhunshin4ac60942023-11-15 15:23:39 +00008106 enforceTelephonyFeatureWithException(callingPackage,
8107 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily");
8108
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008109 final long identity = Binder.clearCallingIdentity();
8110 try {
chen xub97461a2018-10-26 14:17:57 -07008111 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008112 } finally {
8113 Binder.restoreCallingIdentity(identity);
8114 }
chen xub97461a2018-10-26 14:17:57 -07008115 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07008116 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008117
8118 @Override
Hall Liu82694d52020-12-11 18:22:04 -08008119 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08008120 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08008121 try {
8122 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
8123 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008124 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008125 }
8126 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008127 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008128 }
joonhunshin4ac60942023-11-15 15:23:39 +00008129
8130 enforceTelephonyFeatureWithException(callingPackage,
8131 PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture");
8132
Hall Liu82694d52020-12-11 18:22:04 -08008133 RoleManager rm = mApp.getSystemService(RoleManager.class);
8134 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
8135 if (!dialerRoleHolders.contains(callingPackage)) {
8136 throw new SecurityException("App must be the dialer role holder to"
8137 + " upload a call composer pic");
8138 }
8139
8140 Executors.newSingleThreadExecutor().execute(() -> {
8141 ByteArrayOutputStream output = new ByteArrayOutputStream(
8142 (int) TelephonyManager.getMaximumCallComposerPictureSize());
8143 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
8144 boolean readUntilEnd = false;
8145 int totalBytesRead = 0;
8146 byte[] buffer = new byte[16 * 1024];
8147 while (true) {
8148 int numRead;
8149 try {
8150 numRead = input.read(buffer);
8151 } catch (IOException e) {
8152 try {
8153 fd.checkError();
8154 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
8155 null);
8156 } catch (IOException e1) {
8157 // This means that the other side closed explicitly with an error. If this
8158 // happens, log and ignore.
8159 loge("Remote end of call composer picture pipe closed: " + e1);
8160 }
8161 break;
8162 }
8163 if (numRead == -1) {
8164 readUntilEnd = true;
8165 break;
8166 }
8167 totalBytesRead += numRead;
8168 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
8169 loge("Too many bytes read for call composer picture: " + totalBytesRead);
8170 try {
8171 input.close();
8172 } catch (IOException e) {
8173 // ignore
8174 }
8175 break;
8176 }
8177 output.write(buffer, 0, numRead);
8178 }
8179 // Generally, the remote end will close the file descriptors. The only case where we
8180 // close is above, where the picture size is too big.
8181
8182 try {
8183 fd.checkError();
8184 } catch (IOException e) {
8185 loge("Remote end for call composer closed with an error: " + e);
8186 return;
8187 }
8188
Hall Liuaa4211e2021-01-20 15:43:39 -08008189 if (!readUntilEnd) {
8190 loge("Did not finish reading entire image; aborting");
8191 return;
8192 }
Hall Liu82694d52020-12-11 18:22:04 -08008193
Hall Liuaa4211e2021-01-20 15:43:39 -08008194 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
8195 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
8196 new CallComposerPictureTransfer.Factory() {},
8197 imageData,
8198 (result) -> {
8199 if (result.first != null) {
8200 ParcelUuid parcelUuid = new ParcelUuid(result.first);
8201 Bundle outputResult = new Bundle();
8202 outputResult.putParcelable(
8203 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
8204 callback.send(TelephonyManager.CallComposerException.SUCCESS,
8205 outputResult);
8206 } else {
8207 callback.send(result.second, null);
8208 }
8209 }
8210 );
Hall Liu82694d52020-12-11 18:22:04 -08008211 });
8212 }
8213
8214 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07008215 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008216 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07008217 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008218
joonhunshin4ac60942023-11-15 15:23:39 +00008219 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8220 PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling");
8221
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008222 final long identity = Binder.clearCallingIdentity();
8223 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008224 ImsManager.getInstance(defaultPhone.getContext(),
8225 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008226 } finally {
8227 Binder.restoreCallingIdentity(identity);
8228 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008229 }
8230
8231 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008232 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008233 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008234 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
8235 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00008236 return false;
8237 }
Svet Ganovb320e182015-04-16 12:30:10 -07008238
joonhunshin4ac60942023-11-15 15:23:39 +00008239 enforceTelephonyFeatureWithException(callingPackage,
8240 PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled");
8241
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008242 final long identity = Binder.clearCallingIdentity();
8243 try {
8244 // Check the user preference and the system-level IMS setting. Even if the user has
8245 // enabled video calling, if IMS is disabled we aren't able to support video calling.
8246 // In the long run, we may instead need to check if there exists a connection service
8247 // which can support video calling.
8248 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008249 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008250 return imsManager.isVtEnabledByPlatform()
8251 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
8252 && imsManager.isVtEnabledByUser();
8253 } finally {
8254 Binder.restoreCallingIdentity(identity);
8255 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008256 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06008257
Andrew Leea1239f22015-03-02 17:44:07 -08008258 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008259 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
8260 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008261 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008262 mApp, subId, callingPackage, callingFeatureId,
8263 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008264 return false;
8265 }
8266
joonhunshin4ac60942023-11-15 15:23:39 +00008267 enforceTelephonyFeatureWithException(callingPackage,
8268 PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength");
8269
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008270 final long identity = Binder.clearCallingIdentity();
8271 try {
8272 CarrierConfigManager configManager =
8273 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008274 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008275 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
8276 } finally {
8277 Binder.restoreCallingIdentity(identity);
8278 }
Andrew Leea1239f22015-03-02 17:44:07 -08008279 }
8280
8281 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008282 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008283 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008284 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008285 return false;
8286 }
8287
joonhunshin4ac60942023-11-15 15:23:39 +00008288 enforceTelephonyFeatureWithException(callingPackage,
8289 PackageManager.FEATURE_TELEPHONY, "isWorldPhone");
8290
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008291 final long identity = Binder.clearCallingIdentity();
8292 try {
8293 CarrierConfigManager configManager =
8294 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008295 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008296 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
8297 } finally {
8298 Binder.restoreCallingIdentity(identity);
8299 }
Andrew Leea1239f22015-03-02 17:44:07 -08008300 }
8301
Andrew Lee9431b832015-03-09 18:46:45 -07008302 @Override
8303 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008304 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08008305 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07008306 }
8307
8308 @Override
8309 public boolean isHearingAidCompatibilitySupported() {
joonhunshin4ac60942023-11-15 15:23:39 +00008310 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8311 PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported");
8312
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008313 final long identity = Binder.clearCallingIdentity();
8314 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008315 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008316 } finally {
8317 Binder.restoreCallingIdentity(identity);
8318 }
Andrew Lee9431b832015-03-09 18:46:45 -07008319 }
8320
Hall Liuf6668912018-10-31 17:05:23 -07008321 /**
8322 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
8323 * support for the feature and device firmware support.
8324 *
8325 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
8326 */
8327 @Override
8328 public boolean isRttSupported(int subscriptionId) {
joonhunshin4ac60942023-11-15 15:23:39 +00008329 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8330 PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported");
8331
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008332 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008333 final Phone phone = getPhone(subscriptionId);
8334 if (phone == null) {
8335 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
8336 return false;
8337 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008338 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008339 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008340 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
joonhunshin4ac60942023-11-15 15:23:39 +00008341 boolean isDeviceSupported = (phone.getContext().getResources() != null)
8342 ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt)
8343 : false;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008344 return isCarrierSupported && isDeviceSupported;
8345 } finally {
8346 Binder.restoreCallingIdentity(identity);
8347 }
Hall Liu98187582018-01-22 19:15:32 -08008348 }
8349
Hall Liuf6668912018-10-31 17:05:23 -07008350 /**
Hall Liuf2daa022019-07-23 18:39:00 -07008351 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
8352 * RTT setting, will return true if the device and carrier both support RTT.
8353 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07008354 */
8355 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008356 final long identity = Binder.clearCallingIdentity();
8357 try {
joonhunshin4ac60942023-11-15 15:23:39 +00008358 if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) {
8359 if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
8360 return false;
8361 }
8362 }
8363
Hall Liu5bab75c2019-12-11 23:58:20 +00008364 boolean isRttSupported = isRttSupported(subscriptionId);
8365 boolean isUserRttSettingOn = Settings.Secure.getInt(
8366 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
8367 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
8368 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
8369 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008370 } finally {
8371 Binder.restoreCallingIdentity(identity);
8372 }
Hall Liu3ad5f012018-04-06 16:23:39 -07008373 }
8374
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008375 @Deprecated
8376 @Override
8377 public String getDeviceId(String callingPackage) {
8378 return getDeviceIdWithFeature(callingPackage, null);
8379 }
8380
Sanket Padawe7310cc72015-01-14 09:53:20 -08008381 /**
8382 * Returns the unique device ID of phone, for example, the IMEI for
8383 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
8384 *
8385 * <p>Requires Permission:
8386 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
8387 */
8388 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008389 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07008390 try {
8391 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
8392 } catch (SecurityException se) {
8393 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
8394 throw new SecurityException("Package " + callingPackage + " does not belong to "
8395 + Binder.getCallingUid());
8396 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008397 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008398 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008399 return null;
8400 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008401 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008402 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008403 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008404 return null;
8405 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008406
8407 final long identity = Binder.clearCallingIdentity();
8408 try {
8409 return phone.getDeviceId();
8410 } finally {
8411 Binder.restoreCallingIdentity(identity);
8412 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008413 }
8414
Ping Sunc67b7c22016-03-02 19:16:45 +08008415 /**
8416 * {@hide}
8417 * Returns the IMS Registration Status on a particular subid
8418 *
8419 * @param subId
8420 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008421 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008422 Phone phone = getPhone(subId);
8423 if (phone != null) {
8424 return phone.isImsRegistered();
8425 } else {
8426 return false;
8427 }
8428 }
8429
Santos Cordon7a1885b2015-02-03 11:15:19 -08008430 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008431 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008432 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008433 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008434 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008435 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8436 }
8437 final long identity = Binder.clearCallingIdentity();
8438 try {
8439 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8440 } finally {
8441 Binder.restoreCallingIdentity(identity);
8442 }
8443 }
8444
8445 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008446 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008447 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008448 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008449 mApp,
8450 subscriptionId,
8451 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
8452 + subscriptionId);
joonhunshin4ac60942023-11-15 15:23:39 +00008453
8454 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8455 PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId");
8456
Tyler Gunnf70ed162019-04-03 15:28:53 -07008457 final long identity = Binder.clearCallingIdentity();
8458 try {
8459 Phone phone = getPhone(subscriptionId);
8460 if (phone == null) {
8461 return null;
8462 }
8463 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8464 } finally {
8465 Binder.restoreCallingIdentity(identity);
8466 }
8467 }
8468
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008469 /**
8470 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008471 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008472 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008473 final long identity = Binder.clearCallingIdentity();
8474 try {
8475 Phone phone = getPhone(subId);
8476 if (phone != null) {
8477 return phone.isWifiCallingEnabled();
8478 } else {
8479 return false;
8480 }
8481 } finally {
8482 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008483 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008484 }
8485
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008486 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008487 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008488 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008489 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008490 final long identity = Binder.clearCallingIdentity();
8491 try {
8492 Phone phone = getPhone(subId);
8493 if (phone != null) {
8494 return phone.isVideoEnabled();
8495 } else {
8496 return false;
8497 }
8498 } finally {
8499 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008500 }
8501 }
8502
8503 /**
8504 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8505 * defined in {@link ImsRegistrationImplBase}.
8506 */
8507 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008508 final long identity = Binder.clearCallingIdentity();
8509 try {
8510 Phone phone = getPhone(subId);
8511 if (phone != null) {
8512 return phone.getImsRegistrationTech();
8513 } else {
8514 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8515 }
8516 } finally {
8517 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008518 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008519 }
8520
Stuart Scott8eef64f2015-04-08 15:13:54 -07008521 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008522 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008523 enforceSettingsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008524
8525 enforceTelephonyFeatureWithException(callingPackage,
8526 PackageManager.FEATURE_TELEPHONY, "factoryReset");
8527
Stuart Scott981d8582015-04-21 14:09:50 -07008528 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8529 return;
8530 }
Kai Shif70f46f2021-03-03 13:59:46 -08008531 Phone defaultPhone = getDefaultPhone();
8532 if (defaultPhone != null) {
8533 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8534 mApp, getDefaultPhone().getSubId(), "factoryReset");
8535 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008536 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008537
Svet Ganovcc087f82015-05-12 20:35:54 -07008538 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008539 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8540 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008541 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008542 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008543 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008544 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008545 cleanUpAllowedNetworkTypes(phone, subId);
Rambo Wang71f6aa62024-02-23 20:16:22 +00008546 setDataRoamingEnabled(subId, phone == null ? false
8547 : phone.getDataSettingsManager().isDefaultDataRoamingEnabled());
Jordan Liu857e73a2021-03-05 16:24:04 -08008548 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008549 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008550 // There has been issues when Sms raw table somehow stores orphan
8551 // fragments. They lead to garbled message when new fragments come
8552 // in and combined with those stale ones. In case this happens again,
8553 // user can reset all network settings which will clean up this table.
8554 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008555 // Clean up IMS settings as well here.
8556 int slotId = getSlotIndex(subId);
8557 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
8558 ImsManager.getInstance(mApp, slotId).factoryReset();
8559 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008560
Kai Shif70f46f2021-03-03 13:59:46 -08008561 if (defaultPhone == null) {
8562 return;
8563 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008564 // Erase modem config if erase modem on network setting is enabled.
8565 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8566 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8567 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008568 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008569 }
Kai Shif70f46f2021-03-03 13:59:46 -08008570
8571 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008572 } finally {
8573 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008574 }
8575 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008576
SongFerngWangfd89b102021-05-27 22:44:54 +08008577 @VisibleForTesting
8578 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8579 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8580 return;
8581 }
8582 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8583 RILConstants.PREFERRED_NETWORK_MODE);
8584 SubscriptionManager.setSubscriptionProperty(subId,
8585 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8586 "user=" + defaultNetworkType);
8587 phone.loadAllowedNetworksFromSubscriptionDatabase();
8588 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8589 defaultNetworkType, null);
8590 }
8591
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008592 private void cleanUpSmsRawTable(Context context) {
8593 ContentResolver resolver = context.getContentResolver();
8594 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8595 resolver.delete(uri, null, null);
8596 }
8597
Narayan Kamath1c496c22015-04-16 14:40:19 +01008598 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008599 public String getSimLocaleForSubscriber(int subId) {
8600 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
joonhunshin4ac60942023-11-15 15:23:39 +00008601
8602 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8603 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber");
8604
chen xu5d3637b2019-01-21 23:31:38 -08008605 final Phone phone = getPhone(subId);
8606 if (phone == null) {
8607 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008608 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008609 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008610 final long identity = Binder.clearCallingIdentity();
8611 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008612 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
8613 phone.getContext().getOpPackageName(),
8614 phone.getContext().getAttributionTag());
8615 if (info == null) {
8616 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8617 return null;
chen xu6291c472019-02-04 12:55:53 -08008618 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008619 // Try and fetch the locale from the carrier properties or from the SIM language
8620 // preferences (EF-PL and EF-LI)...
8621 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008622 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008623 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8624 if (localeFromDefaultSim != null) {
8625 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8626 if (DBG) log("Using locale from subId: " + subId + " locale: "
8627 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008628 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008629 } else {
8630 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008631 }
8632 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008633
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008634 // The SIM language preferences only store a language (e.g. fr = French), not an
8635 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8636 // the SIM and carrier preferences does not include a country we add the country
8637 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008638 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008639 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008640 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008641 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008642 }
8643
8644 if (DBG) log("No locale found - returning null");
8645 return null;
8646 } finally {
8647 Binder.restoreCallingIdentity(identity);
8648 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008649 }
8650
tom hsu0b59d292022-09-29 23:49:21 +08008651 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008652 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008653 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008654 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008655 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008656 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8657 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008658 Locale.forLanguageTag(localeTag).getCountry())) {
8659 return localeTag;
8660 }
8661 }
8662 return inputLocale.toLanguageTag();
8663 }
8664
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008665 /**
8666 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8667 */
8668 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008669 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Ling Ma9fa67412023-11-13 14:13:19 -08008670 mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/);
Narayan Kamath1c496c22015-04-16 14:40:19 +01008671 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008672
Gary Jian3aa9a762022-01-24 16:41:19 +08008673 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8674 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008675
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008676 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008677 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8678 * representing the state of the modem.
8679 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008680 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8681 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008682 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008683 */
8684 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008685 public void requestModemActivityInfo(ResultReceiver result) {
8686 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008687
8688 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8689 PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo");
8690
vagdeviaf9a5b92018-08-15 16:01:53 -07008691 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008692
8693 final long identity = Binder.clearCallingIdentity();
8694 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008695 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008696 } finally {
8697 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008698 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008699 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008700
Gary Jian76280a42022-12-07 16:18:33 +08008701 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008702 // less than total activity duration.
8703 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8704 if (info == null) {
8705 return false;
8706 }
8707 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008708 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008709 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8710
Hall Liu49656c02020-10-09 19:00:11 -07008711 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8712
Siddharth Rayb8114062018-06-17 15:02:38 -07008713 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008714 && (info.getSleepTimeMillis() <= activityDurationMs)
8715 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008716 }
8717
Gary Jian3aa9a762022-01-24 16:41:19 +08008718 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8719 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8720 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8721 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8722
8723 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8724 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8725 }
8726
8727 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8728 mLastModemActivityInfo.setReceiveTimeMillis(
8729 rat,
8730 freq,
8731 info.getReceiveTimeMillis(rat, freq)
8732 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8733 }
8734
8735 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8736 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8737 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8738 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8739
8740 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8741 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8742 }
8743 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8744 mLastModemActivityInfo.setReceiveTimeMillis(
8745 rat,
8746 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8747 }
8748
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008749 /**
8750 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8751 * @param info recent ModemActivityInfo
8752 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008753 private void mergeModemActivityInfo(ModemActivityInfo info) {
8754 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008755 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008756 boolean matched;
8757 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8758 matched = false;
8759 int rat = info.getSpecificInfoRat(i);
8760 int freq = info.getSpecificInfoFrequencyRange(i);
8761 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8762 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8763 //if it already exists
8764 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8765 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8766 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8767 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8768 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8769 updateLastModemActivityInfo(info, rat, freq);
8770 matched = true;
8771 }
8772 } else {
8773 updateLastModemActivityInfo(info, rat);
8774 matched = true;
8775 }
8776 }
8777 }
8778
8779 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008780 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008781 new ActivityStatsTechSpecificInfo(
8782 rat,
8783 freq,
8784 info.getTransmitTimeMillis(rat, freq),
8785 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008786 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008787 }
8788 }
8789 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8790 mLastModemActivitySpecificInfo =
8791 new ActivityStatsTechSpecificInfo[merged.size()];
8792 merged.toArray(mLastModemActivitySpecificInfo);
8793
8794 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8795 mLastModemActivityInfo.setSleepTimeMillis(
8796 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008797 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008798 mLastModemActivityInfo.setIdleTimeMillis(
8799 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008800 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008801
8802 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008803 new ModemActivityInfo(
8804 mLastModemActivityInfo.getTimestampMillis(),
8805 mLastModemActivityInfo.getSleepTimeMillis(),
8806 mLastModemActivityInfo.getIdleTimeMillis(),
8807 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008808 }
8809
8810 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8811 ActivityStatsTechSpecificInfo[] info) {
8812 int infoSize = info.length;
8813 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8814 for (int i = 0; i < infoSize; i++) {
8815 ret[i] = new ActivityStatsTechSpecificInfo(
8816 info[i].getRat(), info[i].getFrequencyRange(),
8817 info[i].getTransmitTimeMillis(),
8818 (int) info[i].getReceiveTimeMillis());
8819 }
8820 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008821 }
8822
Jack Yu85bd38a2015-11-09 11:34:32 -08008823 /**
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008824 * Returns the service state information on specified SIM slot.
Jack Yu85bd38a2015-11-09 11:34:32 -08008825 */
8826 @Override
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008827 public ServiceState getServiceStateForSlot(int slotIndex, boolean renounceFineLocationAccess,
8828 boolean renounceCoarseLocationAccess, String callingPackage, String callingFeatureId) {
8829 Phone phone = PhoneFactory.getPhone(slotIndex);
8830 if (phone == null) {
8831 loge("getServiceStateForSlot retuning null for invalid slotIndex=" + slotIndex);
8832 return null;
8833 }
8834
8835 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08008836 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008837 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008838 return null;
8839 }
8840
joonhunshin4ac60942023-11-15 15:23:39 +00008841 enforceTelephonyFeatureWithException(callingPackage,
8842 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber");
8843
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008844 boolean hasFinePermission = false;
8845 boolean hasCoarsePermission = false;
8846 if (!renounceFineLocationAccess) {
8847 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8848 LocationAccessPolicy.checkLocationPermission(mApp,
8849 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8850 .setCallingPackage(callingPackage)
8851 .setCallingFeatureId(callingFeatureId)
8852 .setCallingPid(Binder.getCallingPid())
8853 .setCallingUid(Binder.getCallingUid())
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008854 .setMethod("getServiceStateForSlot")
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008855 .setLogAsInfo(true)
8856 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8857 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8858 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8859 .build());
8860 hasFinePermission =
8861 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8862 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008863
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008864 if (!renounceCoarseLocationAccess) {
8865 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8866 LocationAccessPolicy.checkLocationPermission(mApp,
8867 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8868 .setCallingPackage(callingPackage)
8869 .setCallingFeatureId(callingFeatureId)
8870 .setCallingPid(Binder.getCallingPid())
8871 .setCallingUid(Binder.getCallingUid())
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008872 .setMethod("getServiceStateForSlot")
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008873 .setLogAsInfo(true)
8874 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8875 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8876 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8877 .build());
8878 hasCoarsePermission =
8879 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8880 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008881
Jordan Liu0f2bc442020-11-18 16:47:37 -08008882 final long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008883 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008884 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8885 .getSubscriptionInfoInternal(subId);
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008886 if (subInfo != null && !subInfo.isActive()) {
8887 log("getServiceStateForSlot returning null for inactive subId=" + subId);
Jack Yu3beaf9d2023-04-14 09:17:27 -07008888 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008889 }
8890
Hall Liuf19c44f2018-11-27 14:38:17 -08008891 ServiceState ss = phone.getServiceState();
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008892 boolean isCallingPackageDataService = phone.getDataServicePackages()
8893 .contains(callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08008894
8895 // Scrub out the location info in ServiceState depending on what level of access
8896 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008897 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008898 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8899 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008900 } finally {
8901 Binder.restoreCallingIdentity(identity);
8902 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008903 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008904
8905 /**
8906 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8907 *
8908 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8909 * voicemail ringtone.
8910 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8911 * PhoneAccount.
8912 */
8913 @Override
8914 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008915 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8916 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri");
8917
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008918 final long identity = Binder.clearCallingIdentity();
8919 try {
8920 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8921 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008922 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008923 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008924
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008925 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8926 } finally {
8927 Binder.restoreCallingIdentity(identity);
8928 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008929 }
8930
8931 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008932 * Sets the per-account voicemail ringtone.
8933 *
8934 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8935 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8936 *
8937 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8938 * voicemail ringtone.
8939 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8940 * PhoneAccount.
8941 */
8942 @Override
8943 public void setVoicemailRingtoneUri(String callingPackage,
8944 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008945 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008946 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008947 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8948 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008949 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8950 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8951 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008952 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008953
joonhunshin4ac60942023-11-15 15:23:39 +00008954 enforceTelephonyFeatureWithException(callingPackage,
8955 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri");
8956
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008957 final long identity = Binder.clearCallingIdentity();
8958 try {
8959 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8960 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008961 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008962 }
8963 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8964 } finally {
8965 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008966 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008967 }
8968
8969 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008970 * Returns whether vibration is set for voicemail notification in Phone settings.
8971 *
8972 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8973 * voicemail vibration setting.
8974 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8975 */
8976 @Override
8977 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008978 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8979 PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled");
8980
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008981 final long identity = Binder.clearCallingIdentity();
8982 try {
8983 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8984 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008985 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008986 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008987
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008988 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8989 } finally {
8990 Binder.restoreCallingIdentity(identity);
8991 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008992 }
8993
Youhan Wange64578a2016-05-02 15:32:42 -07008994 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008995 * Sets the per-account voicemail vibration.
8996 *
8997 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8998 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8999 *
9000 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
9001 * voicemail vibration setting.
9002 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
9003 * specific PhoneAccount.
9004 */
9005 @Override
9006 public void setVoicemailVibrationEnabled(String callingPackage,
9007 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009008 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009009 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07009010 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
9011 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009012 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9013 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
9014 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009015 }
9016
joonhunshin4ac60942023-11-15 15:23:39 +00009017 enforceTelephonyFeatureWithException(callingPackage,
9018 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled");
9019
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009020 final long identity = Binder.clearCallingIdentity();
9021 try {
9022 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
9023 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009024 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009025 }
9026 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
9027 } finally {
9028 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009029 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009030 }
9031
9032 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009033 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
9034 *
9035 * @throws SecurityException if the caller does not have the required permission
9036 */
arunvoddud7401012022-12-15 16:08:12 +00009037 @VisibleForTesting
9038 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07009039 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07009040 message);
Youhan Wange64578a2016-05-02 15:32:42 -07009041 }
9042
9043 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009044 * Make sure either called from same process as self (phone) or IPC caller has send SMS
9045 * permission.
9046 *
9047 * @throws SecurityException if the caller does not have the required permission
9048 */
9049 private void enforceSendSmsPermission() {
9050 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
9051 }
9052
9053 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00009054 * Make sure either called from same process as self (phone) or IPC caller has interact across
9055 * users permission.
9056 *
9057 * @throws SecurityException if the caller does not have the required permission
9058 */
9059 private void enforceInteractAcrossUsersPermission(String message) {
9060 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
9061 }
9062
9063 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009064 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009065 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009066 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009067 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009068 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009069 final long identity = Binder.clearCallingIdentity();
9070 try {
9071 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009072 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009073 if (componentName == null) {
9074 throw new SecurityException(
9075 "Caller not current active visual voicemail package[null]");
9076 }
9077 String vvmPackage = componentName.getPackageName();
9078 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00009079 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009080 }
9081 } finally {
9082 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009083 }
9084 }
9085
9086 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009087 * Return the application ID for the app type.
9088 *
9089 * @param subId the subscription ID that this request applies to.
9090 * @param appType the uicc app type.
9091 * @return Application ID for specificied app type, or null if no uicc.
9092 */
9093 @Override
9094 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009095 enforceReadPrivilegedPermission("getAidForAppType");
joonhunshin4ac60942023-11-15 15:23:39 +00009096
9097 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9098 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType");
9099
Youhan Wange64578a2016-05-02 15:32:42 -07009100 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009101
9102 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07009103 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009104 if (phone == null) {
9105 return null;
9106 }
9107 String aid = null;
9108 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009109 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009110 .getApplicationByType(appType).getAid();
9111 } catch (Exception e) {
9112 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
9113 }
9114 return aid;
9115 } finally {
9116 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07009117 }
Youhan Wange64578a2016-05-02 15:32:42 -07009118 }
9119
Youhan Wang4001d252016-05-11 10:29:41 -07009120 /**
9121 * Return the Electronic Serial Number.
9122 *
9123 * @param subId the subscription ID that this request applies to.
9124 * @return ESN or null if error.
9125 */
9126 @Override
9127 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009128 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07009129 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009130
9131 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07009132 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009133 if (phone == null) {
9134 return null;
9135 }
9136 String esn = null;
9137 try {
9138 esn = phone.getEsn();
9139 } catch (Exception e) {
9140 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
9141 }
9142 return esn;
9143 } finally {
9144 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07009145 }
Youhan Wang4001d252016-05-11 10:29:41 -07009146 }
9147
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009148 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009149 * Return the Preferred Roaming List Version.
9150 *
9151 * @param subId the subscription ID that this request applies to.
9152 * @return PRLVersion or null if error.
9153 */
9154 @Override
9155 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009156 enforceReadPrivilegedPermission("getCdmaPrlVersion");
joonhunshin4ac60942023-11-15 15:23:39 +00009157
9158 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9159 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion");
9160
Youhan Wang66ad5d72016-07-18 17:56:58 -07009161 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009162
9163 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009164 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009165 if (phone == null) {
9166 return null;
9167 }
9168 String cdmaPrlVersion = null;
9169 try {
9170 cdmaPrlVersion = phone.getCdmaPrlVersion();
9171 } catch (Exception e) {
9172 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9173 }
9174 return cdmaPrlVersion;
9175 } finally {
9176 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009177 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009178 }
9179
9180 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009181 * Get snapshot of Telephony histograms
9182 * @return List of Telephony histograms
9183 * @hide
9184 */
9185 @Override
9186 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009187 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9188 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009189
9190 final long identity = Binder.clearCallingIdentity();
9191 try {
9192 return RIL.getTelephonyRILTimingHistograms();
9193 } finally {
9194 Binder.restoreCallingIdentity(identity);
9195 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009196 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009197
9198 /**
9199 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009200 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9201 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009202 * Require system privileges. In the future we may add this to carrier APIs.
9203 *
Michele Berionne482f8202018-11-27 18:57:59 -08009204 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009205 */
9206 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009207 @TelephonyManager.SetCarrierRestrictionResult
9208 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009209 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009210
9211 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9212 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers");
9213
vagdeviaf9a5b92018-08-15 16:01:53 -07009214 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009215
Michele Berionne482f8202018-11-27 18:57:59 -08009216 if (carrierRestrictionRules == null) {
9217 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009218 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009219
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009220 final long identity = Binder.clearCallingIdentity();
9221 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009222 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009223 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009224 } finally {
9225 Binder.restoreCallingIdentity(identity);
9226 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009227 }
9228
9229 /**
9230 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009231 * Get the allowed carrier list and the excluded carrier list, including the priority between
9232 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009233 * Require system privileges. In the future we may add this to carrier APIs.
9234 *
Michele Berionne482f8202018-11-27 18:57:59 -08009235 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009236 */
9237 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009238 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009239 enforceReadPrivilegedPermission("getAllowedCarriers");
joonhunshin4ac60942023-11-15 15:23:39 +00009240
9241 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9242 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers");
9243
vagdeviaf9a5b92018-08-15 16:01:53 -07009244 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009245
9246 final long identity = Binder.clearCallingIdentity();
9247 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009248 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9249 if (response instanceof CarrierRestrictionRules) {
9250 return (CarrierRestrictionRules) response;
9251 }
9252 // Response is an Exception of some kind,
9253 // which is signalled to the user as a NULL retval
9254 return null;
9255 } catch (Exception e) {
9256 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9257 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009258 } finally {
9259 Binder.restoreCallingIdentity(identity);
9260 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009261 }
9262
fionaxu59545b42016-05-25 15:53:37 -07009263 /**
arunvoddud7401012022-12-15 16:08:12 +00009264 * Fetches the carrier restriction status of the device and sends the status to the caller
9265 * through the callback.
9266 *
9267 * @param callback The callback that will be used to send the result.
9268 * @throws SecurityException if the caller does not have the required permission/privileges or
9269 * the caller is not allowlisted.
9270 */
9271 @Override
9272 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
9273 enforceReadPermission("getCarrierRestrictionStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00009274
9275 enforceTelephonyFeatureWithException(packageName,
9276 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierRestrictionStatus");
9277
Steve Statia28b7cb32024-03-11 23:58:50 +00009278 Set<Integer> carrierIds = validateCallerAndGetCarrierIds(packageName);
9279 if (carrierIds.contains(CarrierAllowListInfo.INVALID_CARRIER_ID)) {
arunvoddud7401012022-12-15 16:08:12 +00009280 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9281 throw new SecurityException("Not an authorized caller");
9282 }
9283 final long identity = Binder.clearCallingIdentity();
9284 try {
9285 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
Steve Statia28b7cb32024-03-11 23:58:50 +00009286 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierIds);
arunvoddud7401012022-12-15 16:08:12 +00009287 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9288 } finally {
9289 Binder.restoreCallingIdentity(identity);
9290 }
9291 }
9292
arunvoddu567f2b42023-04-25 17:22:00 +00009293 @Override
9294 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
9295 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
9296 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9297 return allowListInfo.getShaIdList(pkgName, carrierId);
9298 }
9299
arunvoddud7401012022-12-15 16:08:12 +00009300 @VisibleForTesting
Steve Statia28b7cb32024-03-11 23:58:50 +00009301 public Set<Integer> validateCallerAndGetCarrierIds(String packageName) {
arunvoddud7401012022-12-15 16:08:12 +00009302 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
Steve Statia28b7cb32024-03-11 23:58:50 +00009303 return allowListInfo.validateCallerAndGetCarrierIds(packageName);
arunvoddud7401012022-12-15 16:08:12 +00009304 }
9305
9306 /**
fionaxu59545b42016-05-25 15:53:37 -07009307 * Action set from carrier signalling broadcast receivers to enable/disable radio
9308 * @param subId the subscription ID that this action applies to.
9309 * @param enabled control enable or disable radio.
9310 * {@hide}
9311 */
9312 @Override
9313 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9314 enforceModifyPermission();
9315 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009316
9317 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009318 if (phone == null) {
9319 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9320 return;
9321 }
9322 try {
9323 phone.carrierActionSetRadioEnabled(enabled);
9324 } catch (Exception e) {
9325 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009326 } finally {
9327 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009328 }
9329 }
9330
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009331 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009332 * Enable or disable Voice over NR (VoNR)
9333 * @param subId the subscription ID that this action applies to.
9334 * @param enabled enable or disable VoNR.
9335 * @return operation result.
9336 */
9337 @Override
9338 public int setVoNrEnabled(int subId, boolean enabled) {
9339 enforceModifyPermission();
9340 final Phone phone = getPhone(subId);
9341
9342 final long identity = Binder.clearCallingIdentity();
9343 if (phone == null) {
9344 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9345 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9346 }
9347
9348 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9349 try {
9350 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9351 workSource);
9352 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009353
9354 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9355 if (DBG) {
9356 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9357 }
9358 SubscriptionManager.setSubscriptionProperty(
9359 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9360 (enabled ? "1" : "0"));
9361 }
9362
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009363 return result;
9364 } finally {
9365 Binder.restoreCallingIdentity(identity);
9366 }
9367 }
9368
9369 /**
9370 * Is voice over NR enabled
9371 * @return true if VoNR is enabled else false
9372 */
9373 @Override
9374 public boolean isVoNrEnabled(int subId) {
9375 enforceReadPrivilegedPermission("isVoNrEnabled");
9376 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9377 final long identity = Binder.clearCallingIdentity();
9378 try {
9379 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9380 null, subId, workSource);
9381 if (DBG) log("isVoNrEnabled: " + isEnabled);
9382 return isEnabled;
9383 } finally {
9384 Binder.restoreCallingIdentity(identity);
9385 }
9386 }
9387
9388 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009389 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9390 * network status based on which carrier apps could apply actions accordingly,
9391 * enable/disable default url handler for example.
9392 *
9393 * @param subId the subscription ID that this action applies to.
9394 * @param report control start/stop reporting the default network status.
9395 * {@hide}
9396 */
9397 @Override
9398 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9399 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009400
9401 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9402 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
9403 "carrierActionReportDefaultNetworkStatus");
9404
fionaxu8da9cb12017-05-23 15:02:46 -07009405 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009406
9407 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009408 if (phone == null) {
9409 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9410 return;
9411 }
9412 try {
9413 phone.carrierActionReportDefaultNetworkStatus(report);
9414 } catch (Exception e) {
9415 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009416 } finally {
9417 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009418 }
9419 }
9420
9421 /**
fionaxud9622282017-07-17 17:51:30 -07009422 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9423 * @param subId the subscription ID that this action applies to.
9424 * {@hide}
9425 */
9426 @Override
9427 public void carrierActionResetAll(int subId) {
9428 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009429
9430 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9431 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll");
9432
fionaxud9622282017-07-17 17:51:30 -07009433 final Phone phone = getPhone(subId);
9434 if (phone == null) {
9435 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9436 return;
9437 }
9438 try {
9439 phone.carrierActionResetAll();
9440 } catch (Exception e) {
9441 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9442 }
9443 }
9444
9445 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009446 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9447 * bug report is being generated.
9448 */
9449 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009450 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009451 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9452 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009453 writer.println("Permission Denial: can't dump Phone from pid="
9454 + Binder.getCallingPid()
9455 + ", uid=" + Binder.getCallingUid()
9456 + "without permission "
9457 + android.Manifest.permission.DUMP);
9458 return;
9459 }
Allen Xu4574a1a2024-05-13 23:10:02 +00009460 try {
9461 DumpsysHandler.dump(mApp, fd, writer, args);
9462 } catch (Exception e) {
9463 writer.println("Failed to dump phone information: " + e);
9464 }
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009465 }
Jack Yueb89b242016-06-22 13:27:47 -07009466
Brad Ebingerdac2f002018-04-03 15:17:52 -07009467 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009468 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9469 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9470 @NonNull String[] args) {
9471 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9472 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009473 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009474 }
9475
Jack Yueb89b242016-06-22 13:27:47 -07009476 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009477 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009478 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009479 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009480 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009481 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009482 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009483 */
9484 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009485 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009486 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009487 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9488 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9489 try {
9490 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009491 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009492 } catch (SecurityException se) {
9493 enforceModifyPermission();
9494 }
9495 } else {
9496 enforceModifyPermission();
9497 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009498
joonhunshin4ac60942023-11-15 15:23:39 +00009499 enforceTelephonyFeatureWithException(callingPackage,
9500 PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason");
9501
Nate Myren116695d2024-02-09 09:36:01 -08009502 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009503 final long identity = Binder.clearCallingIdentity();
9504 try {
Nate Myren116695d2024-02-09 09:36:01 -08009505 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
9506 && null != callingPackage && opEnableMobileDataByUser()) {
Nate Myren453c3472024-03-13 11:28:11 -07009507 mAppOps.noteOpNoThrow(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER,
Nate Myren116695d2024-02-09 09:36:01 -08009508 callingUid, callingPackage, null, null);
9509 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009510 Phone phone = getPhone(subId);
9511 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009512 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9513 phone.carrierActionSetMeteredApnsEnabled(enabled);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00009514 } else if (phone.getDataSettingsManager() != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07009515 phone.getDataSettingsManager().setDataEnabled(
9516 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009517 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009518 }
9519 } finally {
9520 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009521 }
9522 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009523
9524 /**
9525 * Get Client request stats
9526 * @return List of Client Request Stats
9527 * @hide
9528 */
9529 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009530 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9531 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009532 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009533 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009534 return null;
9535 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009536 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009537
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009538 final long identity = Binder.clearCallingIdentity();
9539 try {
9540 if (phone != null) {
9541 return phone.getClientRequestStats();
9542 }
9543
9544 return null;
9545 } finally {
9546 Binder.restoreCallingIdentity(identity);
9547 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009548 }
9549
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009550 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009551 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009552 if (uid == Process.ROOT_UID && packageName == null) {
9553 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9554 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9555 // exception. ROOT_UID seems not to have a valid package name returned by
9556 // PackageManager, so just fake it here to avoid issues when running telephony shell
9557 // commands that plumb through the RIL as root, like so:
9558 // $ adb root
9559 // $ adb shell cmd phone ...
9560 packageName = "root";
9561 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009562 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009563 }
Jack Yueb4124c2017-02-16 15:32:43 -08009564
9565 /**
Grace Chen70990072017-03-24 17:21:30 -07009566 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009567 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009568 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009569 * @param state State of SIM (power down, power up, pass through)
9570 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9571 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9572 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009573 *
9574 **/
9575 @Override
Grace Chen70990072017-03-24 17:21:30 -07009576 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009577 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009578
9579 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9580 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot");
9581
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009582 Phone phone = PhoneFactory.getPhone(slotIndex);
9583
vagdeviaf9a5b92018-08-15 16:01:53 -07009584 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9585
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009586 final long identity = Binder.clearCallingIdentity();
9587 try {
9588 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009589 phone.setSimPowerState(state, null, workSource);
9590 }
9591 } finally {
9592 Binder.restoreCallingIdentity(identity);
9593 }
9594 }
9595
9596 /**
9597 * Set SIM card power state.
9598 *
9599 * @param slotIndex SIM slot id.
9600 * @param state State of SIM (power down, power up, pass through)
9601 * @param callback callback to trigger after success or failure
9602 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9603 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9604 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9605 *
9606 **/
9607 @Override
9608 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9609 IIntegerConsumer callback) {
9610 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009611
9612 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9613 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
9614 "setSimPowerStateForSlotWithCallback");
9615
Jordan Liu109698e2020-11-24 14:50:34 -08009616 Phone phone = PhoneFactory.getPhone(slotIndex);
9617
9618 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9619
9620 final long identity = Binder.clearCallingIdentity();
9621 try {
9622 if (phone != null) {
9623 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9624 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009625 }
9626 } finally {
9627 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009628 }
9629 }
Shuo Qiandd210312017-04-12 22:11:33 +00009630
Tyler Gunn65d45c22017-06-05 11:22:26 -07009631 private boolean isUssdApiAllowed(int subId) {
9632 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009633 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009634 if (configManager == null) {
9635 return false;
9636 }
9637 PersistableBundle pb = configManager.getConfigForSubId(subId);
9638 if (pb == null) {
9639 return false;
9640 }
9641 return pb.getBoolean(
9642 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9643 }
9644
Shuo Qiandd210312017-04-12 22:11:33 +00009645 /**
Ling Mac28f0212023-03-24 16:07:15 -07009646 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00009647 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07009648 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00009649 */
goneil9c5f4872017-12-05 14:07:56 -08009650 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009651 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009652 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
joonhunshin4ac60942023-11-15 15:23:39 +00009653
9654 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9655 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode");
9656
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009657 final long identity = Binder.clearCallingIdentity();
9658 try {
Ling Mac28f0212023-03-24 16:07:15 -07009659 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009660 } finally {
9661 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009662 }
9663 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009664
9665 /**
9666 * Get the current signal strength information for the given subscription.
9667 * Because this information is not updated when the device is in a low power state
9668 * it should not be relied-upon to be current.
9669 * @param subId Subscription index
9670 * @return the most recent cached signal strength info from the modem
9671 */
9672 @Override
9673 public SignalStrength getSignalStrength(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00009674 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9675 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength");
9676
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009677 final long identity = Binder.clearCallingIdentity();
9678 try {
9679 Phone p = getPhone(subId);
9680 if (p == null) {
9681 return null;
9682 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009683
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009684 return p.getSignalStrength();
9685 } finally {
9686 Binder.restoreCallingIdentity(identity);
9687 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009688 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009689
Pengquan Meng77b7f132018-08-22 14:49:57 -07009690 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009691 * Get the current modem radio state for the given slot.
9692 * @param slotIndex slot index.
9693 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009694 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009695 * @return the current radio power state from the modem
9696 */
9697 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009698 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009699 Phone phone = PhoneFactory.getPhone(slotIndex);
9700 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009701 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9702 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009703 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9704 }
9705
joonhunshin4ac60942023-11-15 15:23:39 +00009706 enforceTelephonyFeatureWithException(callingPackage,
9707 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState");
9708
Chen Xuf792fd62018-10-17 17:54:36 +00009709 final long identity = Binder.clearCallingIdentity();
9710 try {
9711 return phone.getRadioPowerState();
9712 } finally {
9713 Binder.restoreCallingIdentity(identity);
9714 }
9715 }
9716 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9717 }
9718
9719 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009720 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9721 *
9722 * <p>Requires one of the following permissions:
9723 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009724 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009725 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9726 * privileges.
9727 *
9728 * @param subId subscription id
9729 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9730 * {@code false}.
9731 */
9732 @Override
9733 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009734 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009735 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009736 try {
9737 mApp.enforceCallingOrSelfPermission(
9738 android.Manifest.permission.ACCESS_NETWORK_STATE,
9739 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009740 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009741 mApp.enforceCallingOrSelfPermission(
9742 permission.READ_BASIC_PHONE_STATE, functionName);
9743 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009744 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009745 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009746 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009747 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009748
joonhunshin4ac60942023-11-15 15:23:39 +00009749 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9750 PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled");
9751
Pengquan Menga1bb6272018-09-06 09:59:22 -07009752 boolean isEnabled = false;
9753 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009754 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009755 Phone phone = getPhone(subId);
9756 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009757 } finally {
9758 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009759 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009760 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009761 }
9762
9763
9764 /**
9765 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9766 *
9767 * <p> Requires permission:
9768 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9769 * privileges.
9770 *
9771 * @param subId subscription id
9772 * @param isEnabled {@code true} means enable, {@code false} means disable.
9773 */
9774 @Override
9775 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009776 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9777 mApp, subId, "setDataRoamingEnabled");
9778
joonhunshin4ac60942023-11-15 15:23:39 +00009779 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9780 PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled");
9781
Pengquan Menga1bb6272018-09-06 09:59:22 -07009782 final long identity = Binder.clearCallingIdentity();
9783 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009784 Phone phone = getPhone(subId);
9785 if (phone != null) {
9786 phone.setDataRoamingEnabled(isEnabled);
9787 }
9788 } finally {
9789 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009790 }
9791 }
9792
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009793 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009794 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009795 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009796 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009797 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009798
joonhunshin4ac60942023-11-15 15:23:39 +00009799 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9800 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed");
9801
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009802 boolean isAllowed = true;
9803 final long identity = Binder.clearCallingIdentity();
9804 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009805 Phone phone = getPhone(subId);
9806 if (phone != null) {
9807 isAllowed = phone.isCspPlmnEnabled();
9808 }
9809 } finally {
9810 Binder.restoreCallingIdentity(identity);
9811 }
9812 return isAllowed;
9813 }
9814
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009815 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9816 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009817 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009818 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009819 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009820 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9821 if (phone == null) {
9822 return false;
9823 }
9824 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9825 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9826 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009827 }
9828
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009829 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009830 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009831 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009832 mApp.getSystemService(AppOpsManager.class)
9833 .checkPackage(Binder.getCallingUid(), callingPackage);
9834
Jordan Liu1e142fc2019-04-22 15:10:43 -07009835 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009836 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009837 try {
9838 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009839 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009840 } catch (SecurityException e) {
9841 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9842 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009843 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009844 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009845 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009846 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009847 }
joonhunshin4ac60942023-11-15 15:23:39 +00009848
9849 enforceTelephonyFeatureWithException(callingPackage,
9850 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo");
9851
sandeepjsb6c87872021-09-27 15:34:44 +00009852 // checking compatibility, if calling app's target SDK is T and beyond.
9853 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9854 Binder.getCallingUid())) {
9855 isIccIdAccessRestricted = true;
9856 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009857 final long identity = Binder.clearCallingIdentity();
9858 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009859 UiccController uiccController = UiccController.getInstance();
9860 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009861 if (hasReadPermission) {
9862 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009863 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009864
9865 // Remove private info if the caller doesn't have access
9866 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9867 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009868 //setting the value after compatibility check
9869 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009870 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9871 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009872 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009873 if (card == null) {
9874 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009875 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009876 continue;
9877 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009878 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9879 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009880 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009881 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009882 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009883 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9884 for (UiccPortInfo portInfo : portInfos) {
9885 UiccPort port = uiccController.getUiccPortForSlot(
9886 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9887 if (port == null) {
9888 // assume no access if port is null
9889 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9890 continue;
9891 }
9892 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9893 uiccPortInfos.add(portInfo);
9894 } else {
9895 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9896 }
9897 }
9898 filteredInfos.add(new UiccCardInfo(
9899 cardInfo.isEuicc(),
9900 cardInfo.getCardId(),
9901 null,
9902 cardInfo.getPhysicalSlotIndex(),
9903 cardInfo.isRemovable(),
9904 cardInfo.isMultipleEnabledProfilesSupported(),
9905 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009906 }
9907 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009908 } finally {
9909 Binder.restoreCallingIdentity(identity);
9910 }
9911 }
9912
sandeepjsb6c87872021-09-27 15:34:44 +00009913 /**
9914 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9915 * generally private and require carrier privileges to view.
9916 *
9917 * @hide
9918 */
9919 @NonNull
9920 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9921 List<UiccPortInfo> portinfo = new ArrayList<>();
9922 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9923 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9924 }
9925 return new UiccCardInfo(
9926 cardInfo.isEuicc(),
9927 cardInfo.getCardId(),
9928 null,
9929 cardInfo.getPhysicalSlotIndex(),
9930 cardInfo.isRemovable(),
9931 cardInfo.isMultipleEnabledProfilesSupported(),
9932 portinfo
9933 );
9934 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009935
sandeepjsb6c87872021-09-27 15:34:44 +00009936 /**
9937 * @hide
9938 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9939 * These values are generally private and require carrier privileges to view.
9940 */
9941 @NonNull
9942 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9943 return new UiccPortInfo(
9944 UiccPortInfo.ICCID_REDACTED,
9945 portInfo.getPortIndex(),
9946 portInfo.getLogicalSlotIndex(),
9947 portInfo.isActive()
9948 );
9949 }
9950 @Override
9951 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009952 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009953 mApp.getSystemService(AppOpsManager.class)
9954 .checkPackage(Binder.getCallingUid(), callingPackage);
9955
sandeepjsb6c87872021-09-27 15:34:44 +00009956 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009957
Aman Guptaf3c90b32022-03-17 04:54:16 +00009958 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9959 // we are reading iccId which is PII data.
9960 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009961
joonhunshin4ac60942023-11-15 15:23:39 +00009962 enforceTelephonyFeatureWithException(callingPackage,
9963 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo");
9964
sandeepjsb6c87872021-09-27 15:34:44 +00009965 // checking compatibility, if calling app's target SDK is T and beyond.
9966 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9967 Binder.getCallingUid())) {
9968 isLogicalSlotAccessRestricted = true;
9969 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009970 final long identity = Binder.clearCallingIdentity();
9971 try {
9972 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009973 if (slots == null || slots.length == 0) {
9974 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009975 return null;
9976 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009977 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9978 for (int i = 0; i < slots.length; i++) {
9979 UiccSlot slot = slots[i];
9980 if (slot == null) {
9981 continue;
9982 }
9983
Jordan Liu7be7e652019-05-06 18:55:02 +00009984 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009985 UiccCard card = slot.getUiccCard();
9986 if (card != null) {
9987 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009988 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009989 cardId = slot.getEid();
9990 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009991 // If cardId is null, use iccId of default port as cardId.
9992 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009993 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009994 }
9995
Jordan Liu857451f2019-05-09 16:35:35 -07009996 if (cardId != null) {
9997 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9998 // if cardId is an EID, it's all digits so this is fine
9999 cardId = IccUtils.stripTrailingFs(cardId);
10000 }
10001
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010002 int cardState = 0;
10003 switch (slot.getCardState()) {
10004 case CARDSTATE_ABSENT:
10005 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
10006 break;
10007 case CARDSTATE_PRESENT:
10008 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
10009 break;
10010 case CARDSTATE_ERROR:
10011 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
10012 break;
10013 case CARDSTATE_RESTRICTED:
10014 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
10015 break;
10016 default:
10017 break;
10018
10019 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010020 List<UiccPortInfo> portInfos = new ArrayList<>();
10021 int[] portIndexes = slot.getPortList();
10022 for (int portIdx : portIndexes) {
10023 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +000010024 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +000010025 portInfos.add(new UiccPortInfo(iccId, portIdx,
10026 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010027 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010028 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010029 slot.isEuicc(),
10030 cardId,
10031 cardState,
Jordan Liua2619582019-02-14 12:56:40 -080010032 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010033 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +000010034 //setting the value after compatibility check
10035 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010036 }
10037 return infos;
10038 } finally {
10039 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -070010040 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010041 }
10042
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010043 /* Returns null if doesn't have read permission or carrier privilege access. */
10044 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
10045 boolean hasReadPermission) {
10046 String iccId = slot.getIccId(portIndex);
10047 if (hasReadPermission) { // if has read permission
10048 return iccId;
10049 } else {
10050 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
10051 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
10052 // if no read permission, checking carrier privilege access
10053 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
10054 return iccId;
10055 }
10056 }
10057 }
10058 // No read permission or carrier privilege access.
10059 return UiccPortInfo.ICCID_REDACTED;
10060 }
10061
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010062 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010063 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010064 public boolean switchSlots(int[] physicalSlots) {
10065 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010066
joonhunshin4ac60942023-11-15 15:23:39 +000010067 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10068 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots");
10069
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010070 final long identity = Binder.clearCallingIdentity();
10071 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010072 List<UiccSlotMapping> slotMappings = new ArrayList<>();
10073 for (int i = 0; i < physicalSlots.length; i++) {
10074 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
10075 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
10076 physicalSlots[i], i));
10077 }
10078 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010079 } finally {
10080 Binder.restoreCallingIdentity(identity);
10081 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010082 }
Jack Yu4c988042018-02-27 15:30:01 -080010083
10084 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010085 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
10086 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
10087 enforceModifyPermission();
10088
joonhunshin4ac60942023-11-15 15:23:39 +000010089 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10090 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping");
10091
sandeepjsb6c87872021-09-27 15:34:44 +000010092 final long identity = Binder.clearCallingIdentity();
10093 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010094 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +000010095 } finally {
10096 Binder.restoreCallingIdentity(identity);
10097 }
10098 }
10099
10100 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -080010101 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
joonhunshin4ac60942023-11-15 15:23:39 +000010102 enforceTelephonyFeatureWithException(callingPackage,
10103 PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc");
10104
Jordan Liu7de49fa2018-12-06 14:48:49 -080010105 final long identity = Binder.clearCallingIdentity();
10106 try {
10107 return UiccController.getInstance().getCardIdForDefaultEuicc();
10108 } finally {
10109 Binder.restoreCallingIdentity(identity);
10110 }
10111 }
10112
Pengquan Meng85728fb2018-03-12 16:31:21 -070010113 /**
goneil47ffb6e2018-04-06 15:40:58 -070010114 * A test API to reload the UICC profile.
10115 *
10116 * <p>Requires that the calling app has permission
10117 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
10118 * @hide
10119 */
10120 @Override
10121 public void refreshUiccProfile(int subId) {
10122 enforceModifyPermission();
10123
10124 final long identity = Binder.clearCallingIdentity();
10125 try {
10126 Phone phone = getPhone(subId);
10127 if (phone == null) {
10128 return;
10129 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010130 UiccPort uiccPort = phone.getUiccPort();
10131 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -070010132 return;
10133 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010134 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -070010135 if (uiccProfile == null) {
10136 return;
10137 }
10138 uiccProfile.refresh();
10139 } finally {
10140 Binder.restoreCallingIdentity(identity);
10141 }
10142 }
10143
10144 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010145 * Returns false if the mobile data is disabled by default, otherwise return true.
10146 */
10147 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010148 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010149 }
10150
10151 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010152 * Returns the default network type for the given {@code subId}, if the default network type is
10153 * not set, return {@link Phone#PREFERRED_NT_MODE}.
10154 */
10155 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010156 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -080010157 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +090010158 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
10159 return list.get(phoneId);
10160 }
10161 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -070010162 }
fionaxua13278b2018-03-21 00:08:13 -070010163
10164 @Override
10165 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -070010166 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -070010167 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010168
10169 final long identity = Binder.clearCallingIdentity();
10170 try {
10171 final Phone phone = getPhone(subId);
10172 if (phone == null) {
10173 loge("setCarrierTestOverride fails with invalid subId: " + subId);
10174 return;
10175 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -080010176 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10177 if (cpt != null) {
10178 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
10179 }
10180 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -070010181 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
10182 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -070010183 if (carrierPrivilegeRules == null) {
10184 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
10185 } else {
10186 mCarrierPrivilegeTestOverrideSubIds.add(subId);
10187 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010188 } finally {
10189 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010190 }
fionaxua13278b2018-03-21 00:08:13 -070010191 }
10192
10193 @Override
Benedict Wong66477622023-02-03 23:30:57 +000010194 public void setCarrierServicePackageOverride(
10195 int subId, String carrierServicePackage, String callingPackage) {
10196 TelephonyPermissions.enforceShellOnly(
10197 Binder.getCallingUid(), "setCarrierServicePackageOverride");
10198
Benedict Wong66477622023-02-03 23:30:57 +000010199 final long identity = Binder.clearCallingIdentity();
10200 try {
10201 final Phone phone = getPhone(subId);
10202 if (phone == null || phone.getSubId() != subId) {
10203 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
10204 throw new IllegalArgumentException("No phone for subid");
10205 }
10206 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10207 if (cpt == null) {
10208 loge("setCarrierServicePackageOverride failed with no CPT for phone");
10209 throw new IllegalStateException("No CPT for phone");
10210 }
10211 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
10212 } finally {
10213 Binder.restoreCallingIdentity(identity);
10214 }
10215 }
10216
10217 @Override
fionaxua13278b2018-03-21 00:08:13 -070010218 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -070010219 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010220
10221 final long identity = Binder.clearCallingIdentity();
10222 try {
10223 final Phone phone = getPhone(subId);
10224 if (phone == null) {
10225 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
10226 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
10227 }
10228 return phone.getCarrierIdListVersion();
10229 } finally {
10230 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010231 }
fionaxua13278b2018-03-21 00:08:13 -070010232 }
Malcolm Chen2c63d402018-08-14 16:00:53 -070010233
10234 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010235 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
10236 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010237 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010238 mApp, subId, callingPackage, callingFeatureId,
10239 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010240 return -1;
10241 }
10242
10243 final long identity = Binder.clearCallingIdentity();
10244 try {
10245 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10246 } finally {
10247 Binder.restoreCallingIdentity(identity);
10248 }
10249 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010250
10251 @Override
10252 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +080010253 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010254 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010255 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010256
joonhunshin4ac60942023-11-15 15:23:39 +000010257 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10258 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode");
10259
Pengquan Menga1bb6272018-09-06 09:59:22 -070010260 final long identity = Binder.clearCallingIdentity();
10261 try {
10262 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10263 } finally {
10264 Binder.restoreCallingIdentity(identity);
10265 }
10266 }
10267
10268 @Override
10269 public boolean setCdmaRoamingMode(int subId, int mode) {
10270 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10271 mApp, subId, "setCdmaRoamingMode");
10272
joonhunshin4ac60942023-11-15 15:23:39 +000010273 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10274 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode");
10275
Pengquan Menga1bb6272018-09-06 09:59:22 -070010276 final long identity = Binder.clearCallingIdentity();
10277 try {
10278 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10279 } finally {
10280 Binder.restoreCallingIdentity(identity);
10281 }
10282 }
10283
10284 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010285 public int getCdmaSubscriptionMode(int subId) {
10286 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010287 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010288 mApp, subId, "getCdmaSubscriptionMode");
10289
joonhunshin4ac60942023-11-15 15:23:39 +000010290 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10291 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode");
10292
Sarah Chinbaab1432020-10-28 13:46:24 -070010293 final long identity = Binder.clearCallingIdentity();
10294 try {
10295 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10296 } finally {
10297 Binder.restoreCallingIdentity(identity);
10298 }
10299 }
10300
10301 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010302 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10303 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10304 mApp, subId, "setCdmaSubscriptionMode");
10305
joonhunshin4ac60942023-11-15 15:23:39 +000010306 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10307 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode");
10308
Pengquan Menga1bb6272018-09-06 09:59:22 -070010309 final long identity = Binder.clearCallingIdentity();
10310 try {
10311 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10312 } finally {
10313 Binder.restoreCallingIdentity(identity);
10314 }
10315 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010316
sqianc5eccab2018-10-19 18:46:41 -070010317 @Override
sqian8c685422019-02-22 15:55:18 -080010318 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010319 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010320 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010321 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10322 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010323 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10324 }
joonhunshin4ac60942023-11-15 15:23:39 +000010325
10326 enforceTelephonyFeatureWithException(callingPackage,
10327 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList");
10328
sqian11b7a0e2018-12-05 18:48:28 -080010329 final long identity = Binder.clearCallingIdentity();
10330 try {
sqian854d44b2018-12-12 16:48:18 -080010331 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10332 for (Phone phone: PhoneFactory.getPhones()) {
10333 if (phone.getEmergencyNumberTracker() != null
10334 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10335 emergencyNumberListInternal.put(
10336 phone.getSubId(),
10337 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10338 }
sqian11b7a0e2018-12-05 18:48:28 -080010339 }
sqian854d44b2018-12-12 16:48:18 -080010340 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010341 } finally {
10342 Binder.restoreCallingIdentity(identity);
10343 }
sqianc5eccab2018-10-19 18:46:41 -070010344 }
10345
10346 @Override
sqian8c685422019-02-22 15:55:18 -080010347 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010348 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010349 if (!exactMatch) {
10350 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010351 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010352 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010353 }
joonhunshin4ac60942023-11-15 15:23:39 +000010354
10355 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10356 PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber");
10357
sqian11b7a0e2018-12-05 18:48:28 -080010358 final long identity = Binder.clearCallingIdentity();
10359 try {
sqian854d44b2018-12-12 16:48:18 -080010360 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010361 //Note: we ignore passed in param exactMatch. We can remove it once
10362 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010363 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010364 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010365 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010366 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010367 }
sqian11b7a0e2018-12-05 18:48:28 -080010368 }
10369 return false;
10370 } finally {
10371 Binder.restoreCallingIdentity(identity);
10372 }
10373 }
10374
sqianf4ca7ed2019-01-15 18:32:07 -080010375 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010376 * Start emergency callback mode for GsmCdmaPhone for testing.
10377 */
10378 @Override
10379 public void startEmergencyCallbackMode() {
10380 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10381 "startEmergencyCallbackMode");
10382 enforceModifyPermission();
10383 final long identity = Binder.clearCallingIdentity();
10384 try {
10385 for (Phone phone : PhoneFactory.getPhones()) {
10386 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10387 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10388 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10389 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10390 gsmCdmaPhone.obtainMessage(
10391 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10392 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10393 }
10394 }
10395 } finally {
10396 Binder.restoreCallingIdentity(identity);
10397 }
10398 }
10399
10400 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010401 * Update emergency number list for test mode.
10402 */
10403 @Override
10404 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10405 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10406 "updateEmergencyNumberListTestMode");
10407
10408 final long identity = Binder.clearCallingIdentity();
10409 try {
10410 for (Phone phone: PhoneFactory.getPhones()) {
10411 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10412 if (tracker != null) {
10413 tracker.executeEmergencyNumberTestModeCommand(action, num);
10414 }
10415 }
10416 } finally {
10417 Binder.restoreCallingIdentity(identity);
10418 }
10419 }
10420
10421 /**
10422 * Get the full emergency number list for test mode.
10423 */
10424 @Override
10425 public List<String> getEmergencyNumberListTestMode() {
10426 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10427 "getEmergencyNumberListTestMode");
10428
10429 final long identity = Binder.clearCallingIdentity();
10430 try {
10431 Set<String> emergencyNumbers = new HashSet<>();
10432 for (Phone phone: PhoneFactory.getPhones()) {
10433 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10434 if (tracker != null) {
10435 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10436 emergencyNumbers.add(num.getNumber());
10437 }
10438 }
10439 }
10440 return new ArrayList<>(emergencyNumbers);
10441 } finally {
10442 Binder.restoreCallingIdentity(identity);
10443 }
10444 }
10445
chen xud6b45bd2018-10-30 22:27:10 -070010446 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010447 public int getEmergencyNumberDbVersion(int subId) {
10448 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10449
joonhunshin4ac60942023-11-15 15:23:39 +000010450 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10451 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion");
10452
Shuo Qian3b6ee772019-11-13 17:43:31 -080010453 final long identity = Binder.clearCallingIdentity();
10454 try {
10455 final Phone phone = getPhone(subId);
10456 if (phone == null) {
10457 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10458 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10459 }
10460 return phone.getEmergencyNumberDbVersion();
10461 } finally {
10462 Binder.restoreCallingIdentity(identity);
10463 }
10464 }
10465
10466 @Override
10467 public void notifyOtaEmergencyNumberDbInstalled() {
10468 enforceModifyPermission();
10469
joonhunshin4ac60942023-11-15 15:23:39 +000010470 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10471 PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled");
10472
Shuo Qian3b6ee772019-11-13 17:43:31 -080010473 final long identity = Binder.clearCallingIdentity();
10474 try {
10475 for (Phone phone: PhoneFactory.getPhones()) {
10476 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10477 if (tracker != null) {
10478 tracker.updateOtaEmergencyNumberDatabase();
10479 }
10480 }
10481 } finally {
10482 Binder.restoreCallingIdentity(identity);
10483 }
10484 }
10485
10486 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010487 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010488 enforceActiveEmergencySessionPermission();
10489
joonhunshin4ac60942023-11-15 15:23:39 +000010490 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10491 PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath");
10492
Shuo Qian3b6ee772019-11-13 17:43:31 -080010493 final long identity = Binder.clearCallingIdentity();
10494 try {
10495 for (Phone phone: PhoneFactory.getPhones()) {
10496 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10497 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010498 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10499 }
10500 }
10501 } finally {
10502 Binder.restoreCallingIdentity(identity);
10503 }
10504 }
10505
10506 @Override
10507 public void resetOtaEmergencyNumberDbFilePath() {
10508 enforceActiveEmergencySessionPermission();
10509
joonhunshin4ac60942023-11-15 15:23:39 +000010510 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10511 PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath");
10512
Shuo Qianc373f112020-03-05 17:55:34 -080010513 final long identity = Binder.clearCallingIdentity();
10514 try {
10515 for (Phone phone: PhoneFactory.getPhones()) {
10516 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10517 if (tracker != null) {
10518 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010519 }
10520 }
10521 } finally {
10522 Binder.restoreCallingIdentity(identity);
10523 }
10524 }
10525
10526 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010527 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10528 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10529 Phone phone = getPhone(subId);
10530 if (phone == null) {
10531 return null;
10532 }
10533 final long identity = Binder.clearCallingIdentity();
10534 try {
10535 UiccProfile profile = UiccController.getInstance()
10536 .getUiccProfileForPhone(phone.getPhoneId());
10537 if (profile != null) {
10538 return profile.getCertsFromCarrierPrivilegeAccessRules();
10539 }
10540 } finally {
10541 Binder.restoreCallingIdentity(identity);
10542 }
10543 return null;
10544 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010545
10546 /**
10547 * Enable or disable a modem stack.
10548 */
10549 @Override
10550 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10551 enforceModifyPermission();
10552
joonhunshin4ac60942023-11-15 15:23:39 +000010553 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10554 PackageManager.FEATURE_TELEPHONY, "enableModemForSlot");
10555
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010556 final long identity = Binder.clearCallingIdentity();
10557 try {
10558 Phone phone = PhoneFactory.getPhone(slotIndex);
10559 if (phone == null) {
10560 return false;
10561 } else {
10562 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10563 }
10564 } finally {
10565 Binder.restoreCallingIdentity(identity);
10566 }
10567 }
Michelecea4cf22018-12-21 15:00:11 -080010568
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010569 /**
10570 * Whether a modem stack is enabled or not.
10571 */
10572 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010573 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10574 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010575 Phone phone = PhoneFactory.getPhone(slotIndex);
10576 if (phone == null) return false;
10577
10578 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010579 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10580 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010581 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10582 }
10583
joonhunshin4ac60942023-11-15 15:23:39 +000010584 enforceTelephonyFeatureWithException(callingPackage,
10585 PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot");
10586
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010587 final long identity = Binder.clearCallingIdentity();
10588 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010589 try {
10590 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10591 } catch (NoSuchElementException ex) {
10592 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10593 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010594 } finally {
10595 Binder.restoreCallingIdentity(identity);
10596 }
10597 }
10598
Michelecea4cf22018-12-21 15:00:11 -080010599 @Override
Michele0ea7d782019-03-19 14:58:42 -070010600 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010601 enforceModifyPermission();
10602
joonhunshin4ac60942023-11-15 15:23:39 +000010603 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10604 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction");
10605
Michelecea4cf22018-12-21 15:00:11 -080010606 final long identity = Binder.clearCallingIdentity();
10607 try {
10608 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010609 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010610 .commit();
10611 } finally {
10612 Binder.restoreCallingIdentity(identity);
10613 }
10614 }
10615
10616 @Override
Michele0ea7d782019-03-19 14:58:42 -070010617 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010618 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010619 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010620 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10621 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010622 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010623 }
Michelecea4cf22018-12-21 15:00:11 -080010624
joonhunshin4ac60942023-11-15 15:23:39 +000010625 enforceTelephonyFeatureWithException(callingPackage,
10626 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported");
10627
Michelecea4cf22018-12-21 15:00:11 -080010628 final long identity = Binder.clearCallingIdentity();
10629 try {
Michele0ea7d782019-03-19 14:58:42 -070010630 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010631 } finally {
10632 Binder.restoreCallingIdentity(identity);
10633 }
10634 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010635
Michele0ea7d782019-03-19 14:58:42 -070010636 @TelephonyManager.IsMultiSimSupportedResult
10637 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010638 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10639 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10640 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010641 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10642 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010643 }
10644 // Check if the hardware supports multisim functionality. If usage of multisim is not
10645 // supported by the modem, indicate that it is restricted.
10646 PhoneCapability staticCapability =
10647 mPhoneConfigurationManager.getStaticPhoneCapability();
10648 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010649 loge("isMultiSimSupportedInternal: no static configuration available");
10650 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010651 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010652 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010653 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10654 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010655 }
10656 // Check if support of multiple SIMs is restricted by carrier
10657 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010658 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010659 }
10660
Michele0ea7d782019-03-19 14:58:42 -070010661 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010662 }
10663
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010664 /**
10665 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010666 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10667 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10668 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010669 * @param numOfSims number of active sims we want to switch to
10670 */
10671 @Override
10672 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010673 if (numOfSims == 1) {
10674 enforceModifyPermission();
10675 } else {
10676 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10677 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10678 }
joonhunshin4ac60942023-11-15 15:23:39 +000010679
10680 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10681 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig");
10682
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010683 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010684
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010685 try {
Michele30b57b22019-03-01 12:01:14 -080010686 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010687 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010688 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10689 return;
10690 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010691 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10692 } finally {
10693 Binder.restoreCallingIdentity(identity);
10694 }
10695 }
10696
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010697 @Override
10698 public boolean isApplicationOnUicc(int subId, int appType) {
10699 enforceReadPrivilegedPermission("isApplicationOnUicc");
joonhunshin4ac60942023-11-15 15:23:39 +000010700
10701 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10702 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc");
10703
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010704 Phone phone = getPhone(subId);
10705 if (phone == null) {
10706 return false;
10707 }
10708 final long identity = Binder.clearCallingIdentity();
10709 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010710 UiccPort uiccPort = phone.getUiccPort();
10711 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010712 return false;
10713 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010714 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010715 if (uiccProfile == null) {
10716 return false;
10717 }
10718 if (TelephonyManager.APPTYPE_SIM <= appType
10719 && appType <= TelephonyManager.APPTYPE_ISIM) {
10720 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10721 }
10722 return false;
10723 } finally {
10724 Binder.restoreCallingIdentity(identity);
10725 }
10726 }
10727
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010728 /**
chen xub4baa772019-04-03 10:23:41 -070010729 * Get whether making changes to modem configurations will trigger reboot.
10730 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010731 */
10732 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010733 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10734 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010735 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010736 mApp, subId, callingPackage, callingFeatureId,
10737 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010738 return false;
10739 }
joonhunshin4ac60942023-11-15 15:23:39 +000010740
10741 enforceTelephonyFeatureWithException(callingPackage,
10742 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
10743 "doesSwitchMultiSimConfigTriggerReboot");
10744
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010745 final long identity = Binder.clearCallingIdentity();
10746 try {
10747 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10748 } finally {
10749 Binder.restoreCallingIdentity(identity);
10750 }
10751 }
10752
Nathan Harold29f5f052019-02-15 13:41:57 -080010753 private void updateModemStateMetrics() {
10754 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10755 // TODO: check the state for each modem if the api is ready.
10756 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10757 }
10758
Pengquan Meng3889a572019-01-23 11:16:29 -080010759 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010760 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010761 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010762 // Verify that the callingPackage belongs to the calling UID
10763 mApp.getSystemService(AppOpsManager.class)
10764 .checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000010765
10766 enforceTelephonyFeatureWithException(callingPackage,
10767 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping");
10768
Pengquan Meng3889a572019-01-23 11:16:29 -080010769 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010770 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010771 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010772 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10773 if (slotInfos != null) {
10774 for (int i = 0; i < slotInfos.length; i++) {
10775 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10776 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10777 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10778 portInfo.getLogicalSlotIndex()));
10779 }
10780 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010781 }
10782 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010783 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010784 } finally {
10785 Binder.restoreCallingIdentity(identity);
10786 }
10787 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010788
10789 /**
10790 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010791 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010792 */
jimsunf9ec1622022-09-13 21:18:43 +080010793 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010794 @Override
10795 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010796 return getHalVersion(HAL_SERVICE_RADIO);
10797 }
10798
10799 /**
10800 * Get the HAL Version of a specific service
10801 */
10802 @Override
10803 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010804 Phone phone = getDefaultPhone();
10805 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010806 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010807 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10808 return hv.major * 100 + hv.minor;
10809 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010810
10811 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010812 * Get the current calling package name.
sangyun097dcf72024-01-04 10:35:49 +090010813 *
10814 * @return the current calling package name, or null if there is no known package.
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010815 */
10816 @Override
sangyun097dcf72024-01-04 10:35:49 +090010817 public @Nullable String getCurrentPackageName() {
10818 PackageManager pm = mApp.getPackageManager();
10819 String[] packageNames = pm == null ? null : pm.getPackagesForUid(Binder.getCallingUid());
10820 return packageNames == null ? null : packageNames[0];
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010821 }
10822
10823 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010824 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10825 * corresponding network requests on a subId.
10826 *
10827 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010828 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010829 * 2) APN is un-metered for this subscription, or
10830 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010831 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010832 *
10833 * @return whether data is allowed for a apn type.
10834 *
10835 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010836 */
10837 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010838 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010839 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10840 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010841
joonhunshin4ac60942023-11-15 15:23:39 +000010842 enforceTelephonyFeatureWithException(callingPackage,
10843 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn");
10844
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010845 // Now that all security checks passes, perform the operation as ourselves.
10846 final long identity = Binder.clearCallingIdentity();
10847 try {
10848 Phone phone = getPhone(subId);
10849 if (phone == null) return false;
10850
Jack Yu27422a52022-03-21 10:38:05 -070010851 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010852 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010853 isMetered = phone.getDataNetworkController().getDataConfigManager()
10854 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10855 phone.getServiceState().getDataRoaming());
Hunsuk Choibf761bf2024-06-18 08:34:32 +000010856 isDataEnabled = (phone.getDataSettingsManager() != null)
10857 ? phone.getDataSettingsManager().isDataEnabled(apnType) : false;
Jack Yu99e87332021-12-17 23:14:15 -080010858 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010859 } finally {
10860 Binder.restoreCallingIdentity(identity);
10861 }
10862 }
10863
10864 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010865 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010866 enforceReadPrivilegedPermission("isApnMetered");
10867
joonhunshin4ac60942023-11-15 15:23:39 +000010868 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10869 PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered");
10870
Malcolm Chene5ad5792019-04-18 13:51:02 -070010871 // Now that all security checks passes, perform the operation as ourselves.
10872 final long identity = Binder.clearCallingIdentity();
10873 try {
10874 Phone phone = getPhone(subId);
10875 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010876 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10877 DataUtils.apnTypeToNetworkCapability(apnType),
10878 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010879 } finally {
10880 Binder.restoreCallingIdentity(identity);
10881 }
10882 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010883
10884 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010885 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10886 int subscriptionId, IBooleanConsumer resultCallback) {
10887 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +000010888
10889 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10890 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels");
10891
Hall Liu73f5d362020-01-20 13:42:00 -080010892 long token = Binder.clearCallingIdentity();
10893 try {
10894 Phone phone = getPhone(subscriptionId);
10895 if (phone == null) {
10896 try {
10897 if (resultCallback != null) {
10898 resultCallback.accept(false);
10899 }
10900 } catch (RemoteException e) {
10901 // ignore
10902 }
10903 return;
10904 }
10905 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10906 Pair.create(specifiers, (x) -> {
10907 try {
10908 if (resultCallback != null) {
10909 resultCallback.accept(x);
10910 }
10911 } catch (RemoteException e) {
10912 // ignore
10913 }
10914 });
10915 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10916 } finally {
10917 Binder.restoreCallingIdentity(token);
10918 }
10919 }
10920
10921 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010922 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10923 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010924 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010925 mApp, subId, "getSystemSelectionChannels");
joonhunshin4ac60942023-11-15 15:23:39 +000010926
10927 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10928 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels");
10929
Sarah Chin679c08a2020-11-18 13:39:35 -080010930 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10931 final long identity = Binder.clearCallingIdentity();
10932 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010933 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10934 if (result instanceof IllegalStateException) {
10935 throw (IllegalStateException) result;
10936 }
10937 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010938 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10939 return specifiers;
10940 } finally {
10941 Binder.restoreCallingIdentity(identity);
10942 }
10943 }
10944
10945 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010946 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010947 enforceReadPrivilegedPermission("isMvnoMatched");
joonhunshin4ac60942023-11-15 15:23:39 +000010948
10949 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10950 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched");
10951
Jack Yu8b766fc2022-03-21 09:42:33 -070010952 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010953 }
10954
10955 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010956 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10957 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010958 if (callingPackage == null) {
10959 callingPackage = getCurrentPackageName();
10960 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010961 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10962 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010963 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10964 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010965 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10966 }
10967 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10968 Intent intent = new Intent();
10969 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10970 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10971 // Bring up choose default SMS subscription dialog right now
10972 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10973 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10974 mApp.startActivity(intent);
10975 }
chen xud5ca2d52019-05-28 15:20:57 -070010976
10977 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010978 public void showSwitchToManagedProfileDialog() {
10979 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000010980 try {
10981 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
10982 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
10983 // for work telephony.
10984 Intent intent = new Intent(Intent.ACTION_SENDTO);
10985 intent.setData(Uri.parse("smsto:"));
10986 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10987 mApp.startActivity(intent);
10988 } catch (ActivityNotFoundException e) {
10989 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
10990 Intent intent = new Intent();
10991 intent.setClass(mApp, ErrorDialogActivity.class);
10992 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10993 mApp.startActivity(intent);
10994 }
Ayush Sharma787854b2022-12-12 14:55:02 +000010995 }
10996
10997 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010998 public String getMmsUAProfUrl(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000010999 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11000 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl");
11001
chen xud5ca2d52019-05-28 15:20:57 -070011002 //TODO investigate if this API should require proper permission check in R b/133791609
11003 final long identity = Binder.clearCallingIdentity();
11004 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011005 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
11006 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
11007 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
11008 return carrierUAProfUrl;
11009 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011010 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11011 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070011012 } finally {
11013 Binder.restoreCallingIdentity(identity);
11014 }
11015 }
11016
11017 @Override
11018 public String getMmsUserAgent(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000011019 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11020 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent");
11021
chen xud5ca2d52019-05-28 15:20:57 -070011022 //TODO investigate if this API should require proper permission check in R b/133791609
11023 final long identity = Binder.clearCallingIdentity();
11024 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011025 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
11026 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
11027 if (!TextUtils.isEmpty(carrierUserAgent)) {
11028 return carrierUserAgent;
11029 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011030 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11031 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070011032 } finally {
11033 Binder.restoreCallingIdentity(identity);
11034 }
11035 }
Jack Yub07d4972019-05-28 16:12:25 -070011036
11037 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070011038 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
11039 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070011040
joonhunshin4ac60942023-11-15 15:23:39 +000011041 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11042 PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled");
11043
Jack Yub07d4972019-05-28 16:12:25 -070011044 final long identity = Binder.clearCallingIdentity();
11045 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011046 Phone phone = getPhone(subscriptionId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +000011047 if (phone == null || phone.getDataSettingsManager() == null) return false;
Jack Yub07d4972019-05-28 16:12:25 -070011048
Ling Maf188d502022-09-16 15:22:36 -070011049 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070011050 } finally {
11051 Binder.restoreCallingIdentity(identity);
11052 }
11053 }
11054
11055 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080011056 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070011057 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080011058 enforceModifyPermission();
11059
joonhunshin4ac60942023-11-15 15:23:39 +000011060 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11061 PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled");
11062
changbettyd5c246e2019-12-24 15:40:37 +080011063 final long identity = Binder.clearCallingIdentity();
11064 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011065 Phone phone = getPhone(subscriptionId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +000011066 if (phone == null || phone.getDataSettingsManager() == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080011067
Ling Maf188d502022-09-16 15:22:36 -070011068 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080011069 } finally {
11070 Binder.restoreCallingIdentity(identity);
11071 }
11072 }
11073
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011074 /**
Hall Liu746e03c2020-09-25 11:13:49 -070011075 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011076 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
11077 * otherwise.
11078 */
11079 @Override
11080 public void setCepEnabled(boolean isCepEnabled) {
11081 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
11082
11083 final long identity = Binder.clearCallingIdentity();
11084 try {
11085 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
11086 for (Phone phone : PhoneFactory.getPhones()) {
11087 Phone defaultPhone = phone.getImsPhone();
11088 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
11089 ImsPhone imsPhone = (ImsPhone) defaultPhone;
11090 ImsPhoneCallTracker imsPhoneCallTracker =
11091 (ImsPhoneCallTracker) imsPhone.getCallTracker();
11092 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
11093 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
11094 + imsPhone.getMsisdn());
11095 }
11096 }
11097 } finally {
11098 Binder.restoreCallingIdentity(identity);
11099 }
11100 }
allenwtsu46dcc572020-01-08 18:24:03 +080011101
11102 /**
11103 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
11104 *
11105 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
11106 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
11107 * before being read.
11108 */
11109 @Override
11110 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
11111 isCompressed) {
11112 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11113 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011114 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11115 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11116 }
joonhunshin4ac60942023-11-15 15:23:39 +000011117
11118 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11119 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11120 Binder.getCallingUserHandle())) {
11121 if (!isImsAvailableOnDevice()) {
11122 // ProvisioningManager can not handle ServiceSpecificException.
11123 // Throw the IllegalStateException and annotate ProvisioningManager.
11124 throw new IllegalStateException("IMS not available on device.");
11125 }
11126 } else {
11127 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11128 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11129 "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011130 }
11131
11132 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080011133 try {
Hui Wang761a6682020-10-31 05:12:53 +000011134 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
11135 } finally {
11136 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080011137 }
11138 }
zoey chene02881a2019-12-30 16:11:23 +080011139
11140 @Override
11141 public boolean isIccLockEnabled(int subId) {
11142 enforceReadPrivilegedPermission("isIccLockEnabled");
11143
joonhunshin4ac60942023-11-15 15:23:39 +000011144 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11145 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled");
11146
zoey chene02881a2019-12-30 16:11:23 +080011147 // Now that all security checks passes, perform the operation as ourselves.
11148 final long identity = Binder.clearCallingIdentity();
11149 try {
11150 Phone phone = getPhone(subId);
11151 if (phone != null && phone.getIccCard() != null) {
11152 return phone.getIccCard().getIccLockEnabled();
11153 } else {
11154 return false;
11155 }
11156 } finally {
11157 Binder.restoreCallingIdentity(identity);
11158 }
11159 }
11160
11161 /**
11162 * Set the ICC pin lock enabled or disabled.
11163 *
11164 * @return an integer representing the status of IccLock enabled or disabled in the following
11165 * three cases:
11166 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
11167 * successfully.
11168 * - Positive number and zero for remaining password attempts.
11169 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11170 *
11171 */
11172 @Override
11173 public int setIccLockEnabled(int subId, boolean enabled, String password) {
11174 enforceModifyPermission();
11175
joonhunshin4ac60942023-11-15 15:23:39 +000011176 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11177 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled");
11178
zoey chene02881a2019-12-30 16:11:23 +080011179 Phone phone = getPhone(subId);
11180 if (phone == null) {
11181 return 0;
11182 }
11183 // Now that all security checks passes, perform the operation as ourselves.
11184 final long identity = Binder.clearCallingIdentity();
11185 try {
11186 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
11187 new Pair<Boolean, String>(enabled, password), phone, null);
11188 return attemptsRemaining;
11189
11190 } catch (Exception e) {
11191 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
11192 } finally {
11193 Binder.restoreCallingIdentity(identity);
11194 }
11195 return 0;
11196 }
11197
11198 /**
11199 * Change the ICC password used in ICC pin lock.
11200 *
11201 * @return an integer representing the status of IccLock changed in the following three cases:
11202 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
11203 * - Positive number and zero for remaining password attempts.
11204 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11205 *
11206 */
11207 @Override
11208 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
11209 enforceModifyPermission();
11210
joonhunshin4ac60942023-11-15 15:23:39 +000011211 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11212 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword");
11213
zoey chene02881a2019-12-30 16:11:23 +080011214 Phone phone = getPhone(subId);
11215 if (phone == null) {
11216 return 0;
11217 }
11218 // Now that all security checks passes, perform the operation as ourselves.
11219 final long identity = Binder.clearCallingIdentity();
11220 try {
11221 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
11222 new Pair<String, String>(oldPassword, newPassword), phone, null);
11223 return attemptsRemaining;
11224
11225 } catch (Exception e) {
11226 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
11227 } finally {
11228 Binder.restoreCallingIdentity(identity);
11229 }
11230 return 0;
11231 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080011232
11233 /**
11234 * Request for receiving user activity notification
11235 */
11236 @Override
11237 public void requestUserActivityNotification() {
11238 if (!mNotifyUserActivity.get()
11239 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
11240 mNotifyUserActivity.set(true);
11241 }
11242 }
11243
11244 /**
11245 * Called when userActivity is signalled in the power manager.
11246 * This is safe to call from any thread, with any window manager locks held or not.
11247 */
11248 @Override
11249 public void userActivity() {
11250 // ***************************************
11251 // * Inherited from PhoneWindowManager *
11252 // ***************************************
11253 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
11254 // WITH ITS LOCKS HELD.
11255 //
11256 // This code must be VERY careful about the locks
11257 // it acquires.
11258 // In fact, the current code acquires way too many,
11259 // and probably has lurking deadlocks.
11260
11261 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
11262 throw new SecurityException("Only the OS may call notifyUserActivity()");
11263 }
11264
11265 if (mNotifyUserActivity.getAndSet(false)) {
11266 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
11267 USER_ACTIVITY_NOTIFICATION_DELAY);
11268 }
11269 }
Malcolm Chen4639c562020-04-13 11:59:40 -070011270
11271 @Override
11272 public boolean canConnectTo5GInDsdsMode() {
11273 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
11274 }
Jack Yud10cdd42020-09-28 20:28:01 -070011275
11276 @Override
11277 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
11278 String callingFeatureId) {
11279 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
11280 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
11281 throw new SecurityException("Requires READ_PHONE_STATE permission.");
11282 }
11283
joonhunshin4ac60942023-11-15 15:23:39 +000011284 enforceTelephonyFeatureWithException(callingPackage,
11285 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns");
11286
Jack Yud10cdd42020-09-28 20:28:01 -070011287 Phone phone = getPhone(subId);
11288 if (phone == null) {
11289 throw new RuntimeException("phone is not available");
11290 }
11291 // Now that all security checks passes, perform the operation as ourselves.
11292 final long identity = Binder.clearCallingIdentity();
11293 try {
11294 return phone.getEquivalentHomePlmns();
11295 } finally {
11296 Binder.restoreCallingIdentity(identity);
11297 }
11298 }
Daniel Bright59e67312020-11-13 11:49:37 -080011299
11300 @Override
11301 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011302 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
joonhunshin4ac60942023-11-15 15:23:39 +000011303 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11304 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
11305 "isRadioInterfaceCapabilitySupported");
11306
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011307 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080011308 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080011309 if (radioInterfaceCapabilities == null) {
11310 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080011311 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011312 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080011313 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011314
Hui Wang641e81c2020-10-12 12:14:23 -070011315 @Override
11316 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
11317 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000011318 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
11319 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11320 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
11321 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11322 Manifest.permission.MODIFY_PHONE_STATE);
joonhunshin4ac60942023-11-15 15:23:39 +000011323
11324 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11325 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest");
11326
Hui Wang641e81c2020-10-12 12:14:23 -070011327 if (DBG) {
11328 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
11329 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
11330 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
11331 }
11332
11333 if (!SubscriptionManager.isValidSubscriptionId(subId)
11334 || appType < TelephonyManager.APPTYPE_UNKNOWN
11335 || appType > TelephonyManager.APPTYPE_ISIM
11336 || nafUrl == null || securityProtocol == null || callback == null) {
11337 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
11338 if (callback != null) {
11339 try {
11340 callback.onAuthenticationFailure(
11341 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
11342 } catch (RemoteException exception) {
11343 log("Fail to notify onAuthenticationFailure due to " + exception);
11344 }
11345 return;
11346 }
11347 }
11348
11349 final long token = Binder.clearCallingIdentity();
11350 try {
11351 getGbaManager(subId).bootstrapAuthenticationRequest(
11352 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011353 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070011354 } finally {
11355 Binder.restoreCallingIdentity(token);
11356 }
11357 }
11358
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011359 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011360 * Attempts to set the radio power state for all phones for thermal reason.
11361 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011362 * requested radio power state will actually be set. See {@link
11363 * PhoneInternalInterface#setRadioPowerForReason} for more details.
11364 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011365 * @param enable {@code true} if trying to turn radio on.
11366 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
11367 * false}.
11368 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011369 private boolean setRadioPowerForThermal(boolean enable) {
11370 boolean isPhoneAvailable = false;
11371 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
11372 Phone phone = PhoneFactory.getPhone(i);
11373 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011374 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011375 isPhoneAvailable = true;
11376 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011377 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011378
11379 // return true if successfully informed the phone object about the thermal radio power
11380 // request.
11381 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011382 }
11383
11384 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011385 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011386 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11387 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11388 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11389 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11390 throw new IllegalArgumentException("modem does not support data throttling");
11391 }
11392
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011393 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11394 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011395 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011396 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11397 }
11398
Sarah Chinecc78c42022-03-31 21:16:48 -070011399 setDataEnabledForReason(
11400 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011401
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011402 if (isDataThrottlingSupported) {
11403 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011404 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011405 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11406 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11407 } else if (thermalMitigationResult
11408 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011409 log("Modem likely does not support data throttling on secondary carrier. Data " +
11410 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11411 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011412 }
11413 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011414 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011415
11416 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011417 }
11418
Jack Nudelman644b91a2021-03-12 14:09:48 -080011419 private static List<String> getThermalMitigationAllowlist(Context context) {
11420 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11421 for (String pckg : context.getResources()
11422 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11423 sThermalMitigationAllowlistedPackages.add(pckg);
11424 }
11425 }
11426
11427 return sThermalMitigationAllowlistedPackages;
11428 }
11429
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011430 private boolean isAnyPhoneInEmergencyState() {
11431 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11432 if (tm.isInEmergencyCall()) {
11433 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11434 return true;
11435 }
11436 for (Phone phone : PhoneFactory.getPhones()) {
11437 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11438 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011439 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11440 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011441 return true;
11442 }
11443 }
11444
11445 return false;
11446 }
11447
Jack Nudelman644b91a2021-03-12 14:09:48 -080011448 /**
11449 * Used by shell commands to add an authorized package name for thermal mitigation.
11450 * @param packageName name of package to be allowlisted
11451 * @param context
11452 */
11453 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11454 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11455 sThermalMitigationAllowlistedPackages.add(packageName);
11456 }
11457
11458 /**
11459 * Used by shell commands to remove an authorized package name for thermal mitigation.
11460 * @param packageName name of package to remove from allowlist
11461 * @param context
11462 */
11463 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11464 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11465 sThermalMitigationAllowlistedPackages.remove(packageName);
11466 }
11467
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011468 /**
11469 * Thermal mitigation request to control functionalities at modem.
11470 *
11471 * @param subId the id of the subscription.
11472 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011473 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011474 *
11475 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11476 */
11477 @Override
11478 @ThermalMitigationResult
11479 public int sendThermalMitigationRequest(
11480 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011481 ThermalMitigationRequest thermalMitigationRequest,
11482 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011483 enforceModifyPermission();
11484
Jack Nudelman644b91a2021-03-12 14:09:48 -080011485 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000011486
11487 enforceTelephonyFeatureWithException(callingPackage,
11488 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest");
11489
Jack Nudelman644b91a2021-03-12 14:09:48 -080011490 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11491 .contains(callingPackage)) {
11492 throw new SecurityException("Calling package must be configured in the device config. "
11493 + "calling package: " + callingPackage);
11494 }
11495
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011496 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11497 final long identity = Binder.clearCallingIdentity();
11498
11499 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11500 try {
11501 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11502 switch (thermalMitigationAction) {
11503 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11504 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011505 handleDataThrottlingRequest(subId,
11506 thermalMitigationRequest.getDataThrottlingRequest(),
11507 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011508 break;
11509 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11510 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11511 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11512 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11513 }
11514
11515 // Ensure that radio is on. If not able to power on due to phone being
11516 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011517 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011518 thermalMitigationResult =
11519 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11520 break;
11521 }
11522
11523 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011524 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011525 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11526 break;
11527 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11528 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11529 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11530 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11531 }
11532
11533 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11534 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011535 Phone phone = getPhone(subId);
11536 if (phone == null) {
11537 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011538 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011539 break;
11540 }
11541
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011542 TelephonyConnectionService service =
11543 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011544 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011545 Log.e(LOG_TAG, "An emergency call is pending");
11546 thermalMitigationResult =
11547 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11548 break;
11549 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011550 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011551 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011552 break;
11553 }
11554 } else {
11555 thermalMitigationResult =
11556 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11557 break;
11558 }
11559
11560 // Turn radio off. If not able to power off due to phone being unavailable,
11561 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011562 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011563 thermalMitigationResult =
11564 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11565 break;
11566 }
11567 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011568 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011569 break;
11570 default:
11571 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11572 + "not exist. Requested action: " + thermalMitigationAction);
11573 }
11574 } catch (IllegalArgumentException e) {
11575 throw e;
11576 } catch (Exception e) {
11577 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11578 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11579 } finally {
11580 Binder.restoreCallingIdentity(identity);
11581 }
11582
11583 if (DBG) {
11584 log("thermalMitigationRequest returning with thermalMitigationResult: "
11585 + thermalMitigationResult);
11586 }
11587
11588 return thermalMitigationResult;
11589 }
Hui Wang641e81c2020-10-12 12:14:23 -070011590
11591 /**
11592 * Set the GbaService Package Name that Telephony will bind to.
11593 *
11594 * @param subId The sim that the GbaService is associated with.
11595 * @param packageName The name of the package to be replaced with.
11596 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11597 */
11598 @Override
11599 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11600 enforceModifyPermission();
11601
11602 final long identity = Binder.clearCallingIdentity();
11603 try {
11604 return getGbaManager(subId).overrideServicePackage(packageName);
11605 } finally {
11606 Binder.restoreCallingIdentity(identity);
11607 }
11608 }
11609
11610 /**
11611 * Return the package name of the currently bound GbaService.
11612 *
11613 * @param subId The sim that the GbaService is associated with.
11614 * @return the package name of the GbaService configuration, null if GBA is not supported.
11615 */
11616 @Override
11617 public String getBoundGbaService(int subId) {
11618 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11619
11620 final long identity = Binder.clearCallingIdentity();
11621 try {
11622 return getGbaManager(subId).getServicePackage();
11623 } finally {
11624 Binder.restoreCallingIdentity(identity);
11625 }
11626 }
11627
11628 /**
11629 * Set the release time for telephony to unbind GbaService.
11630 *
11631 * @param subId The sim that the GbaService is associated with.
11632 * @param interval The release time to unbind GbaService by millisecond.
11633 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11634 */
11635 @Override
11636 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11637 enforceModifyPermission();
11638
11639 final long identity = Binder.clearCallingIdentity();
11640 try {
11641 return getGbaManager(subId).overrideReleaseTime(interval);
11642 } finally {
11643 Binder.restoreCallingIdentity(identity);
11644 }
11645 }
11646
11647 /**
11648 * Return the release time for telephony to unbind GbaService.
11649 *
11650 * @param subId The sim that the GbaService is associated with.
11651 * @return The release time to unbind GbaService by millisecond.
11652 */
11653 @Override
11654 public int getGbaReleaseTime(int subId) {
11655 enforceReadPrivilegedPermission("getGbaReleaseTime");
11656
11657 final long identity = Binder.clearCallingIdentity();
11658 try {
11659 return getGbaManager(subId).getReleaseTime();
11660 } finally {
11661 Binder.restoreCallingIdentity(identity);
11662 }
11663 }
11664
11665 private GbaManager getGbaManager(int subId) {
11666 GbaManager instance = GbaManager.getInstance(subId);
11667 if (instance == null) {
11668 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11669 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11670 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11671 }
11672 return instance;
11673 }
Hui Wang761a6682020-10-31 05:12:53 +000011674
11675 /**
11676 * indicate whether the device and the carrier can support
11677 * RCS VoLTE single registration.
11678 */
11679 @Override
11680 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011681 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11682 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11683 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11684 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011685
11686 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11687 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11688 }
11689
11690 final long identity = Binder.clearCallingIdentity();
11691 try {
11692 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11693 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011694 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11695 if (isCapable != null) {
11696 return isCapable;
11697 }
Hui Wang761a6682020-10-31 05:12:53 +000011698 }
Hui Wang67af90e2021-06-04 16:57:15 -070011699 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11700 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011701 } finally {
11702 Binder.restoreCallingIdentity(identity);
11703 }
11704 }
11705
11706 /**
11707 * Register RCS provisioning callback.
11708 */
11709 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011710 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011711 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011712 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011713 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011714 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11715 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011716
11717 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11718 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11719 }
joonhunshin4ac60942023-11-15 15:23:39 +000011720 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11721 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11722 Binder.getCallingUserHandle())) {
11723 if (!isImsAvailableOnDevice()) {
11724 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11725 "IMS not available on device.");
11726 }
11727 } else {
11728 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11729 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011730 }
11731
11732 final long identity = Binder.clearCallingIdentity();
11733 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011734 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011735 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011736 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11737 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011738 }
Hui Wang761a6682020-10-31 05:12:53 +000011739 } finally {
11740 Binder.restoreCallingIdentity(identity);
11741 }
11742 }
11743
11744 /**
11745 * Unregister RCS provisioning callback.
11746 */
11747 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011748 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011749 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011750 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011751 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011752 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11753 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011754
11755 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11756 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11757 }
joonhunshin4ac60942023-11-15 15:23:39 +000011758
11759 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11760 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11761 Binder.getCallingUserHandle())) {
11762 if (!isImsAvailableOnDevice()) {
11763 // operation failed silently
11764 Rlog.w(LOG_TAG, "IMS not available on device.");
11765 return;
11766 }
11767 } else {
11768 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11769 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11770 "unregisterRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011771 }
11772
11773 final long identity = Binder.clearCallingIdentity();
11774 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011775 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011776 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011777 } finally {
11778 Binder.restoreCallingIdentity(identity);
11779 }
11780 }
11781
11782 /**
11783 * trigger RCS reconfiguration.
11784 */
11785 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011786 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11787 "triggerRcsReconfiguration",
11788 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011789
11790 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11791 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11792 }
joonhunshin4ac60942023-11-15 15:23:39 +000011793 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11794 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11795 Binder.getCallingUserHandle())) {
11796 if (!isImsAvailableOnDevice()) {
11797 // ProvisioningManager can not handle ServiceSpecificException.
11798 // Throw the IllegalStateException and annotate ProvisioningManager.
11799 throw new IllegalStateException("IMS not available on device.");
11800 }
11801 } else {
11802 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11803 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011804 }
11805
11806 final long identity = Binder.clearCallingIdentity();
11807 try {
11808 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11809 } finally {
11810 Binder.restoreCallingIdentity(identity);
11811 }
11812 }
11813
11814 /**
11815 * Provide the client configuration parameters of the RCS application.
11816 */
11817 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011818 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11819 "setRcsClientConfiguration",
11820 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011821
11822 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11823 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11824 }
joonhunshin4ac60942023-11-15 15:23:39 +000011825 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11826 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11827 Binder.getCallingUserHandle())) {
11828 if (!isImsAvailableOnDevice()) {
11829 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11830 "IMS not available on device.");
11831 }
11832 } else {
11833 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11834 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011835 }
11836
11837 final long identity = Binder.clearCallingIdentity();
11838
11839 try {
11840 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11841 if (configBinder == null) {
11842 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011843 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11844 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011845 } else {
11846 configBinder.setRcsClientConfiguration(rcc);
11847 }
joonhunshin3e154242021-09-17 06:33:39 +000011848
11849 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11850 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011851 } catch (RemoteException e) {
11852 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011853 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11854 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011855 } finally {
11856 Binder.restoreCallingIdentity(identity);
11857 }
11858 }
11859
11860 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011861 * Enables or disables the test mode for RCS VoLTE single registration.
11862 */
11863 @Override
11864 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11865 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11866 "setRcsSingleRegistrationTestModeEnabled");
11867
11868 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11869 }
11870
11871 /**
11872 * Gets the test mode for RCS VoLTE single registration.
11873 */
11874 @Override
11875 public boolean getRcsSingleRegistrationTestModeEnabled() {
11876 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11877 "getRcsSingleRegistrationTestModeEnabled");
11878
11879 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11880 }
11881
11882 /**
Hui Wang761a6682020-10-31 05:12:53 +000011883 * Overrides the config of RCS VoLTE single registration enabled for the device.
11884 */
11885 @Override
11886 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11887 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11888 "setDeviceSingleRegistrationEnabledOverride");
11889 enforceModifyPermission();
11890
11891 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11892 : Boolean.parseBoolean(enabledStr);
11893 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011894 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011895 }
11896
11897 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011898 * Sends a device to device communication message. Only usable via shell.
11899 * @param message message to send.
11900 * @param value message value.
11901 */
11902 @Override
11903 public void sendDeviceToDeviceMessage(int message, int value) {
11904 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011905 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011906 enforceModifyPermission();
11907
11908 final long identity = Binder.clearCallingIdentity();
11909 try {
11910 TelephonyConnectionService service =
11911 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11912 if (service == null) {
11913 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11914 return;
11915 }
11916 service.sendTestDeviceToDeviceMessage(message, value);
11917 } finally {
11918 Binder.restoreCallingIdentity(identity);
11919 }
11920 }
11921
Tyler Gunnbabbda02021-02-10 11:05:02 -080011922 /**
11923 * Sets the specified device to device transport active.
11924 * @param transport The transport to set active.
11925 */
11926 @Override
11927 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11928 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11929 "setActiveDeviceToDeviceTransport");
11930 enforceModifyPermission();
11931
11932 final long identity = Binder.clearCallingIdentity();
11933 try {
11934 TelephonyConnectionService service =
11935 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11936 if (service == null) {
11937 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11938 return;
11939 }
11940 service.setActiveDeviceToDeviceTransport(transport);
11941 } finally {
11942 Binder.restoreCallingIdentity(identity);
11943 }
11944 }
Tyler Gunn92479152021-01-20 16:30:10 -080011945
Tyler Gunnd4339262021-05-03 14:46:49 -070011946 @Override
11947 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11948 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11949 "setDeviceToDeviceForceEnabled");
11950
11951 final long identity = Binder.clearCallingIdentity();
11952 try {
11953 Arrays.stream(PhoneFactory.getPhones()).forEach(
11954 p -> {
11955 Phone thePhone = p.getImsPhone();
11956 if (thePhone != null && thePhone instanceof ImsPhone) {
11957 ImsPhone imsPhone = (ImsPhone) thePhone;
11958 CallTracker tracker = imsPhone.getCallTracker();
11959 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11960 ImsPhoneCallTracker imsPhoneCallTracker =
11961 (ImsPhoneCallTracker) tracker;
11962 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11963 }
11964 }
11965 }
11966 );
11967 } finally {
11968 Binder.restoreCallingIdentity(identity);
11969 }
11970 }
11971
Tyler Gunn92479152021-01-20 16:30:10 -080011972 /**
Hui Wang761a6682020-10-31 05:12:53 +000011973 * Gets the config of RCS VoLTE single registration enabled for the device.
11974 */
11975 @Override
11976 public boolean getDeviceSingleRegistrationEnabled() {
11977 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11978 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11979 }
11980
11981 /**
11982 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11983 */
11984 @Override
11985 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11986 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11987 "setCarrierSingleRegistrationEnabledOverride");
11988 enforceModifyPermission();
11989
11990 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11991 : Boolean.parseBoolean(enabledStr);
11992 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11993 subId, enabled);
11994 }
11995
11996 /**
11997 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11998 */
11999 @Override
12000 public boolean getCarrierSingleRegistrationEnabled(int subId) {
12001 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
12002 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
12003 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080012004
12005 /**
Hui Wangb647abe2021-02-26 09:33:38 -080012006 * Overrides the ims feature validation result
12007 */
12008 @Override
12009 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
12010 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12011 "setImsFeatureValidationOverride");
12012
12013 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
12014 : Boolean.parseBoolean(enabledStr);
12015 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
12016 subId, enabled);
12017 }
12018
12019 /**
12020 * Gets the ims feature validation override value
12021 */
12022 @Override
12023 public boolean getImsFeatureValidationOverride(int subId) {
12024 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12025 "getImsFeatureValidationOverride");
12026 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
12027 }
12028
12029 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080012030 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
12031 * their mobile plan.
12032 */
12033 @Override
12034 public String getMobileProvisioningUrl() {
12035 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
12036 final long identity = Binder.clearCallingIdentity();
12037 try {
12038 return getDefaultPhone().getMobileProvisioningUrl();
12039 } finally {
12040 Binder.restoreCallingIdentity(identity);
12041 }
12042 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012043
James.cf Linbcdf8b32021-01-14 16:44:13 +080012044 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080012045 * Get the EAB contact from the EAB database.
12046 */
12047 @Override
12048 public String getContactFromEab(String contact) {
12049 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
12050 enforceModifyPermission();
12051 final long identity = Binder.clearCallingIdentity();
12052 try {
12053 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
12054 } finally {
12055 Binder.restoreCallingIdentity(identity);
12056 }
12057 }
12058
12059 /**
Calvin Pana1434322021-07-01 19:27:01 +080012060 * Get the EAB capability from the EAB database.
12061 */
12062 @Override
12063 public String getCapabilityFromEab(String contact) {
12064 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
12065 enforceModifyPermission();
12066 final long identity = Binder.clearCallingIdentity();
12067 try {
12068 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
12069 } finally {
12070 Binder.restoreCallingIdentity(identity);
12071 }
12072 }
12073
12074 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080012075 * Remove the EAB contacts from the EAB database.
12076 */
12077 @Override
12078 public int removeContactFromEab(int subId, String contacts) {
12079 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
12080 enforceModifyPermission();
12081 final long identity = Binder.clearCallingIdentity();
12082 try {
12083 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
12084 } finally {
12085 Binder.restoreCallingIdentity(identity);
12086 }
12087 }
12088
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012089 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080012090 public boolean getDeviceUceEnabled() {
12091 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
12092 final long identity = Binder.clearCallingIdentity();
12093 try {
12094 return mApp.getDeviceUceEnabled();
12095 } finally {
12096 Binder.restoreCallingIdentity(identity);
12097 }
12098 }
12099
12100 @Override
12101 public void setDeviceUceEnabled(boolean isEnabled) {
12102 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
12103 final long identity = Binder.clearCallingIdentity();
12104 try {
12105 mApp.setDeviceUceEnabled(isEnabled);
12106 } finally {
12107 Binder.restoreCallingIdentity(identity);
12108 }
12109 }
12110
Brad Ebinger14d467f2021-02-12 06:18:28 +000012111 /**
12112 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
12113 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12114 */
12115 // Used for SHELL command only right now.
12116 @Override
12117 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
12118 List<String> featureTags) {
12119 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12120 "addUceRegistrationOverrideShell");
12121 final long identity = Binder.clearCallingIdentity();
12122 try {
12123 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
12124 new ArraySet<>(featureTags));
12125 } catch (ImsException e) {
12126 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12127 } finally {
12128 Binder.restoreCallingIdentity(identity);
12129 }
12130 }
12131
12132 /**
12133 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
12134 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12135 */
12136 // Used for SHELL command only right now.
12137 @Override
12138 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
12139 List<String> featureTags) {
12140 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12141 "removeUceRegistrationOverrideShell");
12142 final long identity = Binder.clearCallingIdentity();
12143 try {
12144 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
12145 new ArraySet<>(featureTags));
12146 } catch (ImsException e) {
12147 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12148 } finally {
12149 Binder.restoreCallingIdentity(identity);
12150 }
12151 }
12152
12153 /**
12154 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
12155 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12156 */
12157 // Used for SHELL command only right now.
12158 @Override
12159 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
12160 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12161 "clearUceRegistrationOverrideShell");
12162 final long identity = Binder.clearCallingIdentity();
12163 try {
12164 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
12165 } catch (ImsException e) {
12166 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12167 } finally {
12168 Binder.restoreCallingIdentity(identity);
12169 }
12170 }
12171
12172 /**
12173 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12174 */
12175 // Used for SHELL command only right now.
12176 @Override
12177 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
12178 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12179 "getLatestRcsContactUceCapabilityShell");
12180 final long identity = Binder.clearCallingIdentity();
12181 try {
12182 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
12183 } catch (ImsException e) {
12184 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12185 } finally {
12186 Binder.restoreCallingIdentity(identity);
12187 }
12188 }
12189
12190 /**
12191 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
12192 * device does not have an active PUBLISH.
12193 */
12194 // Used for SHELL command only right now.
12195 @Override
12196 public String getLastUcePidfXmlShell(int subId) {
12197 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
12198 final long identity = Binder.clearCallingIdentity();
12199 try {
12200 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
12201 } catch (ImsException e) {
12202 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12203 } finally {
12204 Binder.restoreCallingIdentity(identity);
12205 }
12206 }
12207
James.cf Line8713a42021-04-29 16:04:26 +080012208 /**
12209 * Remove UCE requests cannot be sent to the network status.
12210 */
12211 // Used for SHELL command only right now.
12212 @Override
12213 public boolean removeUceRequestDisallowedStatus(int subId) {
12214 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
12215 final long identity = Binder.clearCallingIdentity();
12216 try {
12217 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
12218 } catch (ImsException e) {
12219 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12220 } finally {
12221 Binder.restoreCallingIdentity(identity);
12222 }
12223 }
12224
James.cf Lin18bb9002021-05-25 01:37:38 +080012225 /**
12226 * Remove UCE requests cannot be sent to the network status.
12227 */
12228 // Used for SHELL command only.
12229 @Override
12230 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
12231 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
12232 final long identity = Binder.clearCallingIdentity();
12233 try {
12234 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
12235 } catch (ImsException e) {
12236 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12237 } finally {
12238 Binder.restoreCallingIdentity(identity);
12239 }
12240 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000012241
James.cf Lin4b784aa2021-01-31 03:25:15 +080012242 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012243 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12244 String callingPackage) {
12245 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12246 mApp, subId, "setSignalStrengthUpdateRequest");
12247
joonhunshin4ac60942023-11-15 15:23:39 +000012248 enforceTelephonyFeatureWithException(callingPackage,
12249 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest");
12250
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012251 final int callingUid = Binder.getCallingUid();
12252 // Verify that tha callingPackage belongs to the calling UID
12253 mApp.getSystemService(AppOpsManager.class)
12254 .checkPackage(callingUid, callingPackage);
12255
Rambo Wang3607f502021-02-01 21:51:40 -080012256 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012257
12258 final long identity = Binder.clearCallingIdentity();
12259 try {
12260 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
12261 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12262
12263 if (result instanceof IllegalStateException) {
12264 throw (IllegalStateException) result;
12265 }
12266 } finally {
12267 Binder.restoreCallingIdentity(identity);
12268 }
12269 }
12270
12271 @Override
12272 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12273 String callingPackage) {
12274 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12275 mApp, subId, "clearSignalStrengthUpdateRequest");
12276
joonhunshin4ac60942023-11-15 15:23:39 +000012277 enforceTelephonyFeatureWithException(callingPackage,
12278 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest");
12279
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012280 final int callingUid = Binder.getCallingUid();
12281 // Verify that tha callingPackage belongs to the calling UID
12282 mApp.getSystemService(AppOpsManager.class)
12283 .checkPackage(callingUid, callingPackage);
12284
12285 final long identity = Binder.clearCallingIdentity();
12286 try {
12287 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
12288 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12289
12290 if (result instanceof IllegalStateException) {
12291 throw (IllegalStateException) result;
12292 }
12293 } finally {
12294 Binder.restoreCallingIdentity(identity);
12295 }
12296 }
12297
Rambo Wang3607f502021-02-01 21:51:40 -080012298 private static void validateSignalStrengthUpdateRequest(Context context,
12299 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012300 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
12301 // phone/system process do not have further restriction on request
12302 return;
12303 }
12304
12305 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080012306 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012307 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080012308 context.enforceCallingOrSelfPermission(
12309 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
12310 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012311 }
12312
12313 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000012314 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012315 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012316 || info.isEnabled()) {
12317 throw new IllegalArgumentException(
12318 "Only system can set hide fields in SignalThresholdInfo");
12319 }
12320
12321 // Thresholds length for each RAN need in range. This has been validated in
12322 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
12323 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
12324 final int[] thresholds = info.getThresholds();
12325 Objects.requireNonNull(thresholds);
12326 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
12327 || thresholds.length
12328 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
12329 throw new IllegalArgumentException(
12330 "thresholds length is out of range: " + thresholds.length);
12331 }
12332 }
12333 }
SongFerngWang8236caa2021-01-17 21:51:44 +080012334
12335 /**
12336 * Gets the current phone capability.
12337 *
12338 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
12339 * @return the PhoneCapability which describes the data connection capability of modem.
12340 * It's used to evaluate possible phone config change, for example from single
12341 * SIM device to multi-SIM device.
12342 */
12343 @Override
12344 public PhoneCapability getPhoneCapability() {
12345 enforceReadPrivilegedPermission("getPhoneCapability");
joonhunshin4ac60942023-11-15 15:23:39 +000012346
12347 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12348 PackageManager.FEATURE_TELEPHONY, "getPhoneCapability");
12349
SongFerngWang8236caa2021-01-17 21:51:44 +080012350 final long identity = Binder.clearCallingIdentity();
12351 try {
12352 return mPhoneConfigurationManager.getCurrentPhoneCapability();
12353 } finally {
12354 Binder.restoreCallingIdentity(identity);
12355 }
12356 }
Michele Berionne5e411512020-11-13 02:36:59 +000012357
12358 /**
12359 * Prepare TelephonyManager for an unattended reboot. The reboot is
12360 * required to be done shortly after the API is invoked.
12361 */
12362 @Override
12363 @TelephonyManager.PrepareUnattendedRebootResult
12364 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012365 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000012366 enforceRebootPermission();
12367
joonhunshin4ac60942023-11-15 15:23:39 +000012368 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12369 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot");
12370
Michele Berionne5e411512020-11-13 02:36:59 +000012371 final long identity = Binder.clearCallingIdentity();
12372 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012373 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000012374 } finally {
12375 Binder.restoreCallingIdentity(identity);
12376 }
12377 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012378
12379 /**
12380 * Request to get the current slicing configuration including URSP rules and
12381 * NSSAIs (configured, allowed and rejected).
12382 *
12383 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
12384 */
12385 @Override
12386 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000012387 TelephonyPermissions
12388 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
12389 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012390
joonhunshin4ac60942023-11-15 15:23:39 +000012391 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12392 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
12393 "getSlicingConfig");
12394
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012395 final long identity = Binder.clearCallingIdentity();
12396 try {
12397 Phone phone = getDefaultPhone();
12398 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
12399 } finally {
12400 Binder.restoreCallingIdentity(identity);
12401 }
12402 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012403
12404 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070012405 * Check whether the given premium capability is available for purchase from the carrier.
12406 *
12407 * @param capability The premium capability to check.
12408 * @param subId The subId to check the premium capability for.
12409 *
12410 * @return Whether the given premium capability is available to purchase.
12411 */
12412 @Override
12413 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
12414 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12415 mApp, "isPremiumCapabilityAvailableForPurchase")) {
12416 log("Premium capability "
12417 + TelephonyManager.convertPremiumCapabilityToString(capability)
12418 + " is not available for purchase due to missing permissions.");
12419 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
12420 + "permission READ_BASIC_PHONE_STATE.");
12421 }
12422
joonhunshin4ac60942023-11-15 15:23:39 +000012423 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12424 PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase");
12425
Sarah Chin2ec39f62022-08-31 17:03:26 -070012426 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080012427 if (phone == null) {
12428 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12429 return false;
12430 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012431 final long identity = Binder.clearCallingIdentity();
12432 try {
Sarah Chincc5446f2023-10-23 17:57:19 -070012433 return SlicePurchaseController.getInstance(phone, mFeatureFlags)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012434 .isPremiumCapabilityAvailableForPurchase(capability);
12435 } finally {
12436 Binder.restoreCallingIdentity(identity);
12437 }
12438 }
12439
12440 /**
12441 * Purchase the given premium capability from the carrier.
12442 *
12443 * @param capability The premium capability to purchase.
12444 * @param callback The result of the purchase request.
12445 * @param subId The subId to purchase the premium capability for.
12446 */
12447 @Override
12448 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12449 log("purchasePremiumCapability: capability="
12450 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12451 + getCurrentPackageName());
12452
12453 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12454 mApp, "purchasePremiumCapability")) {
12455 log("purchasePremiumCapability "
12456 + TelephonyManager.convertPremiumCapabilityToString(capability)
12457 + " failed due to missing permissions.");
12458 throw new SecurityException("purchasePremiumCapability requires permission "
12459 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012460 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12461 mApp, "purchasePremiumCapability")) {
12462 log("purchasePremiumCapability "
12463 + TelephonyManager.convertPremiumCapabilityToString(capability)
12464 + " failed due to missing permissions.");
12465 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012466 }
12467
joonhunshin4ac60942023-11-15 15:23:39 +000012468 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12469 PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability");
12470
Sarah Chin2ec39f62022-08-31 17:03:26 -070012471 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012472 if (phone == null) {
12473 try {
12474 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12475 callback.accept(result);
12476 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12477 } catch (RemoteException e) {
12478 String logStr = "Purchase premium capability "
12479 + TelephonyManager.convertPremiumCapabilityToString(capability)
12480 + " failed due to RemoteException handling null phone: " + e;
12481 if (DBG) log(logStr);
12482 AnomalyReporter.reportAnomaly(
12483 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12484 }
12485 return;
12486 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012487
12488 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012489 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012490 callingProcess = mApp.getPackageManager().getApplicationInfo(
12491 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070012492 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012493 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012494 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012495
12496 boolean isVisible = false;
12497 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12498 if (am != null) {
12499 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12500 if (processes != null) {
12501 for (ActivityManager.RunningAppProcessInfo process : processes) {
12502 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070012503 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080012504 if (process.processName.equals(callingProcess) && process.importance
12505 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12506 isVisible = true;
12507 break;
12508 }
12509 }
12510 }
12511 }
12512
12513 if (!isVisible) {
12514 try {
12515 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12516 callback.accept(result);
12517 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12518 } catch (RemoteException e) {
12519 String logStr = "Purchase premium capability "
12520 + TelephonyManager.convertPremiumCapabilityToString(capability)
12521 + " failed due to RemoteException handling background application: " + e;
12522 if (DBG) log(logStr);
12523 AnomalyReporter.reportAnomaly(
12524 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12525 }
12526 return;
12527 }
12528
Sarah Chin71b3a852022-09-28 15:54:19 -070012529 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012530 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012531 }
12532
12533 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012534 * Register an IMS connection state callback
12535 */
12536 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012537 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12538 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012539 if (feature == ImsFeature.FEATURE_MMTEL) {
12540 // ImsMmTelManager
12541 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12542 TelephonyPermissions
12543 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12544 mApp, subId, "registerImsStateCallback");
12545 } else if (feature == ImsFeature.FEATURE_RCS) {
12546 // ImsRcsManager or SipDelegateManager
12547 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12548 Binder.getCallingUid(), "registerImsStateCallback",
12549 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12550 Manifest.permission.READ_PRECISE_PHONE_STATE,
12551 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12552 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12553 }
12554
12555 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12556 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12557 "IMS not available on device.");
12558 }
12559
12560 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12561 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12562 }
12563
12564 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12565 if (controller == null) {
12566 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12567 "IMS not available on device.");
12568 }
12569
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012570 if (callingPackage == null) {
12571 callingPackage = getCurrentPackageName();
12572 }
12573
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012574 final long token = Binder.clearCallingIdentity();
12575 try {
12576 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012577 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012578 } catch (ImsException e) {
12579 throw new ServiceSpecificException(e.getCode());
12580 } finally {
12581 Binder.restoreCallingIdentity(token);
12582 }
12583 }
12584
12585 /**
12586 * Unregister an IMS connection state callback
12587 */
12588 @Override
12589 public void unregisterImsStateCallback(IImsStateCallback cb) {
12590 final long token = Binder.clearCallingIdentity();
12591 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12592 if (controller == null) {
12593 return;
12594 }
12595 try {
12596 controller.unregisterImsStateCallback(cb);
12597 } finally {
12598 Binder.restoreCallingIdentity(token);
12599 }
12600 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012601
12602 /**
12603 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12604 *
12605 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012606 * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012607 * SecurityException.
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012608 *
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012609 * If there is current registered network this value will be same as the registered cell
12610 * identity. If the device goes out of service the previous cell identity is cached and
12611 * will be returned. If the cache age of the Cell identity is more than 24 hours
12612 * it will be cleared and null will be returned.
12613 *
12614 */
12615 @Override
12616 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12617 String callingFeatureId) {
12618 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12619 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12620 LocationAccessPolicy.checkLocationPermission(mApp,
12621 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12622 .setCallingPackage(callingPackage)
12623 .setCallingFeatureId(callingFeatureId)
12624 .setCallingPid(Binder.getCallingPid())
12625 .setCallingUid(Binder.getCallingUid())
12626 .setMethod("getLastKnownCellIdentity")
12627 .setLogAsInfo(true)
12628 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12629 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12630 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12631 .build());
12632
12633 boolean hasFinePermission =
12634 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12635 if (!hasFinePermission
12636 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12637 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012638 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012639 }
12640
12641 final long identity = Binder.clearCallingIdentity();
12642 try {
Ling Mac28f0212023-03-24 16:07:15 -070012643 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012644 if (sst == null) return null;
12645 return sst.getLastKnownCellIdentity();
12646 } finally {
12647 Binder.restoreCallingIdentity(identity);
12648 }
12649 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012650
jimsun3b9ccac2021-10-26 15:01:23 +080012651 /**
12652 * Sets the modem service class Name that Telephony will bind to.
12653 *
12654 * @param serviceName The class name of the modem service.
12655 * @return true if the operation is succeed, otherwise false.
12656 */
12657 public boolean setModemService(String serviceName) {
12658 Log.d(LOG_TAG, "setModemService - " + serviceName);
12659 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12660 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012661 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12662 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012663 return mPhoneConfigurationManager.setModemService(serviceName);
12664 }
12665
12666 /**
12667 * Return the class name of the currently bounded modem service.
12668 *
12669 * @return the class name of the modem service.
12670 */
12671 public String getModemService() {
12672 String result;
12673 Log.d(LOG_TAG, "getModemService");
12674 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12675 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012676 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012677 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12678 "getModemService");
12679 result = mPhoneConfigurationManager.getModemService();
12680 Log.d(LOG_TAG, "result = " + result);
12681 return result;
12682 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012683
Hakjun Choi3ee81112023-12-19 15:40:58 +000012684 /**
12685 * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources,
12686 * including carrier config, entitlement server, and config update.
12687 *
12688 * @param subId subId The subscription ID of the carrier.
12689 *
12690 * @return List of plmns for carrier satellite service. If no plmn is available, empty list will
12691 * be returned.
12692 *
12693 * @throws SecurityException if the caller doesn't have the required permission.
12694 */
Hakjun Choi74c16be2024-01-19 08:18:09 +000012695 @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) {
12696 enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier");
Hakjun Choi3ee81112023-12-19 15:40:58 +000012697 final long identity = Binder.clearCallingIdentity();
12698 try {
Hakjun Choi74c16be2024-01-19 08:18:09 +000012699 return mSatelliteController.getSatellitePlmnsForCarrier(subId);
Hakjun Choi3ee81112023-12-19 15:40:58 +000012700 } finally {
12701 Binder.restoreCallingIdentity(identity);
12702 }
12703 }
12704
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012705 @Override
12706 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12707 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12708 mApp.enforceCallingOrSelfPermission(
12709 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12710 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12711
12712 final long identity = Binder.clearCallingIdentity();
12713 try {
12714 Phone phone = getPhone(subId);
12715 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012716 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12717 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012718 phone.setVoiceServiceStateOverride(hasService);
12719 } finally {
12720 Binder.restoreCallingIdentity(identity);
12721 }
12722 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012723
12724 /**
12725 * set removable eSIM as default eUICC.
12726 *
12727 * @hide
12728 */
12729 @Override
12730 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12731 enforceModifyPermission();
12732 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12733
12734 final long identity = Binder.clearCallingIdentity();
12735 try {
12736 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12737 } finally {
12738 Binder.restoreCallingIdentity(identity);
12739 }
12740 }
12741
12742 /**
12743 * Returns whether the removable eSIM is default eUICC or not.
12744 *
12745 * @hide
12746 */
12747 @Override
12748 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12749 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12750 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12751
12752 final long identity = Binder.clearCallingIdentity();
12753 try {
12754 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12755 } finally {
12756 Binder.restoreCallingIdentity(identity);
12757 }
12758 }
12759
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012760 /**
12761 * Get the component name of the default app to direct respond-via-message intent for the
12762 * user associated with this subscription, update the cache if there is no respond-via-message
12763 * application currently configured for this user.
12764 * @return component name of the app and class to direct Respond Via Message intent to, or
12765 * {@code null} if the functionality is not supported.
12766 * @hide
12767 */
12768 @Override
12769 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12770 boolean updateIfNeeded) {
12771 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012772
joonhunshin4ac60942023-11-15 15:23:39 +000012773 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12774 PackageManager.FEATURE_TELEPHONY_MESSAGING,
12775 "getDefaultRespondViaMessageApplication");
12776
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012777 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12778
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012779 UserHandle userHandle = null;
12780 final long identity = Binder.clearCallingIdentity();
12781 try {
12782 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12783 } finally {
12784 Binder.restoreCallingIdentity(identity);
12785 }
12786 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12787 updateIfNeeded, userHandle);
12788 }
Jack Yuf5badd92022-12-08 00:50:53 -080012789
12790 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012791 * Set whether the device is able to connect with null ciphering or integrity
12792 * algorithms. This is a global setting and will apply to all active subscriptions
12793 * and all new subscriptions after this.
12794 *
12795 * @param enabled when true, null cipher and integrity algorithms are allowed.
12796 * @hide
12797 */
12798 @Override
12799 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12800 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12801 enforceModifyPermission();
12802 checkForNullCipherAndIntegritySupport();
12803
12804 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12805 // for listening to these preference changes and applying them immediately.
12806 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12807 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12808 editor.apply();
12809
12810 for (Phone phone: PhoneFactory.getPhones()) {
12811 phone.handleNullCipherEnabledChange();
12812 }
12813 }
12814
12815
12816 /**
12817 * Get whether the device is able to connect with null ciphering or integrity
12818 * algorithms. Note that this retrieves the phone-global preference and not
12819 * the state of the radio.
12820 *
12821 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12822 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12823 * version for this feature.
12824 * @hide
12825 */
12826 @Override
12827 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12828 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12829 enforceReadPermission();
12830 checkForNullCipherAndIntegritySupport();
12831 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12832 }
12833
12834 private void checkForNullCipherAndIntegritySupport() {
12835 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12836 throw new UnsupportedOperationException(
12837 "Null cipher and integrity operations require HAL 2.1 or above");
12838 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012839 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12840 throw new UnsupportedOperationException(
12841 "Null cipher and integrity operations unsupported by modem");
12842 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012843 }
12844
Gil Cukierman06403e12023-11-29 16:33:03 +000012845 private void checkForIdentifierDisclosureNotificationSupport() {
12846 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) {
12847 throw new UnsupportedOperationException(
12848 "Cellular identifier disclosure transparency operations require HAL 2.2 or "
12849 + "above");
12850 }
12851 if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) {
12852 throw new UnsupportedOperationException(
12853 "Cellular identifier disclosure transparency operations unsupported by modem");
12854 }
12855 }
12856
Michael Groover826b71d2023-12-21 22:08:06 -060012857 private void checkForNullCipherNotificationSupport() {
12858 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) {
12859 throw new UnsupportedOperationException(
12860 "Null cipher notification operations require HAL 2.2 or above");
12861 }
12862 if (!getDefaultPhone().isNullCipherNotificationSupported()) {
12863 throw new UnsupportedOperationException(
12864 "Null cipher notification operations unsupported by modem");
12865 }
12866 }
12867
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012868 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012869 * Get the SIM state for the slot index.
12870 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12871 *
12872 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12873 */
12874 @Override
12875 @SimState
12876 public int getSimStateForSlotIndex(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +000012877 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12878 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex");
12879
Jack Yuf5badd92022-12-08 00:50:53 -080012880 IccCardConstants.State simState;
12881 if (slotIndex < 0) {
12882 simState = IccCardConstants.State.UNKNOWN;
12883 } else {
12884 Phone phone = null;
12885 try {
12886 phone = PhoneFactory.getPhone(slotIndex);
12887 } catch (IllegalStateException e) {
12888 // ignore
12889 }
12890 if (phone == null) {
12891 simState = IccCardConstants.State.UNKNOWN;
12892 } else {
12893 IccCard icc = phone.getIccCard();
12894 if (icc == null) {
12895 simState = IccCardConstants.State.UNKNOWN;
12896 } else {
12897 simState = icc.getState();
12898 }
12899 }
12900 }
12901 return simState.ordinal();
12902 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012903
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012904 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
12905 boolean enableLogcat,
12906 long logcatStartTimestampMillis, boolean enableTelecomDump,
12907 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012908 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012909 TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder =
12910 new TelephonyManager.EmergencyCallDiagnosticData.Builder();
12911 ecdDataBuilder
12912 .setTelecomDumpsysCollectionEnabled(enableTelecomDump)
12913 .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012914 if (enableLogcat) {
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012915 ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012916 }
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012917 TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build();
12918 Log.d(LOG_TAG, "persisting with Params " + ecdData.toString());
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012919 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
12920 Executors.newCachedThreadPool(), db,
12921 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012922 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012923 }
12924
12925 /**
12926 * Request telephony to persist state for debugging emergency call failures.
12927 *
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012928 * @param dropboxTag Tag to use when persisting data to dropbox service.
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012929 * @param enableLogcat whether to collect logcat output
12930 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
12931 * @param enableTelecomDump whether to collect telecom dumpsys
12932 * @param enableTelephonyDump whether to collect telephony dumpsys
12933 */
12934 @Override
12935 @RequiresPermission(android.Manifest.permission.DUMP)
12936 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
12937 long logcatStartTimestampMillis, boolean enableTelecomDump,
12938 boolean enableTelephonyDump) {
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -080012939 // Verify that the caller has READ_DROPBOX_DATA permission.
12940 if (mTelecomFeatureFlags.telecomResolveHiddenDependencies()
12941 && Flags.enableReadDropboxPermission()) {
12942 mApp.enforceCallingPermission(permission.READ_DROPBOX_DATA,
12943 "persistEmergencyCallDiagnosticData");
12944 } else {
12945 // Otherwise, enforce legacy permission.
12946 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
12947 "persistEmergencyCallDiagnosticData");
12948 }
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012949 final long identity = Binder.clearCallingIdentity();
12950 try {
12951 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
12952 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
12953
12954 } finally {
12955 Binder.restoreCallingIdentity(identity);
12956 }
12957 }
12958
Hui Wang9b5793a2022-12-05 14:38:06 -060012959 /**
12960 * Get current cell broadcast ranges.
12961 */
12962 @Override
12963 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12964 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12965 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12966 "getCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012967
12968 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12969 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges");
12970
Hui Wang9b5793a2022-12-05 14:38:06 -060012971 final long identity = Binder.clearCallingIdentity();
12972 try {
12973 return getPhone(subId).getCellBroadcastIdRanges();
12974 } finally {
12975 Binder.restoreCallingIdentity(identity);
12976 }
12977 }
12978
12979 /**
12980 * Set reception of cell broadcast messages with the list of the given ranges
12981 *
12982 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12983 */
12984 @Override
12985 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12986 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12987 @Nullable IIntegerConsumer callback) {
12988 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12989 "setCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012990
12991 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12992 PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges");
12993
Hui Wang9b5793a2022-12-05 14:38:06 -060012994 final long identity = Binder.clearCallingIdentity();
12995 try {
12996 Phone phone = getPhoneFromSubId(subId);
12997 if (DBG) {
12998 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12999 }
13000 phone.setCellBroadcastIdRanges(ranges, result -> {
13001 if (callback != null) {
13002 try {
13003 callback.accept(result);
13004 } catch (RemoteException e) {
13005 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
13006 }
13007 }
13008 });
13009 } finally {
13010 Binder.restoreCallingIdentity(identity);
13011 }
13012 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000013013
13014 /**
13015 * Returns whether the device supports the domain selection service.
13016 *
13017 * @return {@code true} if the device supports the domain selection service.
13018 */
13019 @Override
13020 public boolean isDomainSelectionSupported() {
13021 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
13022 "isDomainSelectionSupported");
13023
13024 final long identity = Binder.clearCallingIdentity();
13025 try {
13026 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
13027 } finally {
13028 Binder.restoreCallingIdentity(identity);
13029 }
13030 }
arunvoddud5c6ce02022-12-11 06:03:12 +000013031
13032 /**
Hunsuk Choi9c69a802024-04-11 20:39:23 +000013033 * Returns whether the AOSP domain selection service is supported.
13034 *
13035 * @return {@code true} if the AOSP domain selection service is supported,
13036 * {@code false} otherwise.
13037 */
13038 @Override
13039 public boolean isAospDomainSelectionService() {
13040 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
13041 "isAospDomainSelectionService");
13042
13043 final long identity = Binder.clearCallingIdentity();
13044 try {
13045 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13046 String dssComponentName = mApp.getResources().getString(
13047 R.string.config_domain_selection_service_component_name);
13048 ComponentName componentName = ComponentName.createRelative(mApp.getPackageName(),
13049 TelephonyDomainSelectionService.class.getName());
13050 Log.i(LOG_TAG, "isAospDomainSelectionService dss=" + dssComponentName
13051 + ", aosp=" + componentName.flattenToString());
13052 return TextUtils.equals(componentName.flattenToString(), dssComponentName);
13053 }
13054 } finally {
13055 Binder.restoreCallingIdentity(identity);
13056 }
13057 return false;
13058 }
13059
13060 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013061 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
13062 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
13063 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080013064 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013065 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chinabf081b2023-03-09 23:00:57 -080013066 * @param enableSatellite {@code true} to enable the satellite modem and
13067 * {@code false} to disable.
13068 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
Thomas Nguyena8062672024-02-05 14:18:19 -080013069 * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise.
Sarah Chinabf081b2023-03-09 23:00:57 -080013070 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080013071 *
13072 * @throws SecurityException if the caller doesn't have the required permission.
13073 */
13074 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013075 public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode,
Thomas Nguyena8062672024-02-05 14:18:19 -080013076 boolean isEmergency, @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013077 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013078 if (enableSatellite) {
13079 ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) {
13080 @Override
13081 protected void onReceiveResult(int resultCode, Bundle resultData) {
13082 Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode
13083 + ", resultData=" + resultData);
13084 boolean isAllowed = false;
13085 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(
13086 callback::accept);
13087 if (resultCode == SATELLITE_RESULT_SUCCESS) {
13088 if (resultData != null
13089 && resultData.containsKey(KEY_SATELLITE_COMMUNICATION_ALLOWED)) {
13090 isAllowed = resultData.getBoolean(KEY_SATELLITE_COMMUNICATION_ALLOWED);
13091 } else {
13092 loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist.");
13093 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013094 } else {
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013095 result.accept(resultCode);
13096 return;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013097 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013098 if (isAllowed) {
13099 mSatelliteController.requestSatelliteEnabled(
Hyosun Kimab304792024-03-29 09:18:03 +000013100 subId, enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013101 } else {
13102 result.accept(SATELLITE_RESULT_ACCESS_BARRED);
13103 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013104 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013105 };
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013106 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013107 subId, resultReceiver);
13108 } else {
13109 // No need to check if satellite is allowed at current location when disabling satellite
13110 mSatelliteController.requestSatelliteEnabled(
Hyosun Kimab304792024-03-29 09:18:03 +000013111 subId, enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013112 }
Sarah Chin503828c2023-02-01 23:54:20 -080013113 }
13114
13115 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013116 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080013117 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013118 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013119 * @param result The result receiver that returns whether the satellite modem is enabled
13120 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013121 *
13122 * @throws SecurityException if the caller doesn't have the required permission.
13123 */
13124 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013125 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
13126 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013127 mSatelliteController.requestIsSatelliteEnabled(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013128 }
13129
13130 /**
Sarah Chin43457982023-02-15 17:50:38 -080013131 * Request to get whether the satellite service demo mode is enabled.
13132 *
13133 * @param subId The subId of the subscription to check whether the satellite demo mode
13134 * is enabled for.
13135 * @param result The result receiver that returns whether the satellite demo mode is enabled
13136 * if the request is successful or an error code if the request failed.
13137 *
13138 * @throws SecurityException if the caller doesn't have the required permission.
13139 */
13140 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013141 public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
13142 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
13143 mSatelliteController.requestIsDemoModeEnabled(subId, result);
Sarah Chin43457982023-02-15 17:50:38 -080013144 }
13145
13146 /**
Thomas Nguyena8062672024-02-05 14:18:19 -080013147 * Request to get whether the satellite service is enabled with emergency mode.
13148 *
13149 * @param subId The subId of the subscription to check whether the satellite demo mode
13150 * is enabled for.
13151 * @param result The result receiver that returns whether the satellite emergency mode is
13152 * enabled if the request is successful or an error code if the request failed.
13153 *
13154 * @throws SecurityException if the caller doesn't have the required permission.
13155 */
13156 @Override
13157 public void requestIsEmergencyModeEnabled(int subId, @NonNull ResultReceiver result) {
13158 enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled");
13159 result.send(SATELLITE_RESULT_REQUEST_NOT_SUPPORTED, null);
13160 }
13161
13162 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013163 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080013164 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013165 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013166 * @param result The result receiver that returns whether the satellite service is supported on
13167 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013168 */
13169 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013170 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013171 mSatelliteController.requestIsSatelliteSupported(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013172 }
13173
13174 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013175 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080013176 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013177 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013178 * @param result The result receiver that returns the {@link SatelliteCapabilities}
13179 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013180 *
13181 * @throws SecurityException if the caller doesn't have required permission.
13182 */
13183 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013184 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
13185 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013186 mSatelliteController.requestSatelliteCapabilities(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013187 }
13188
13189 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013190 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013191 * This can be called by the pointing UI when the user starts pointing to the satellite.
13192 * Modem should continue to report the pointing input as the device or satellite moves.
13193 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013194 * @param subId The subId of the subscription to start satellite transmission updates for.
13195 * @param resultCallback The callback to get the result of the request.
13196 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080013197 *
13198 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013199 */
13200 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013201 public void startSatelliteTransmissionUpdates(int subId,
13202 @NonNull IIntegerConsumer resultCallback,
13203 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13204 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
13205 mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080013206 }
13207
13208 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013209 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013210 * This can be called by the pointing UI when the user stops pointing to the satellite.
13211 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013212 * @param subId The subId of the subscription to stop satellite transmission updates for.
13213 * @param resultCallback The callback to get the result of the request.
13214 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
13215 * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080013216 *
13217 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013218 */
13219 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013220 public void stopSatelliteTransmissionUpdates(int subId,
13221 @NonNull IIntegerConsumer resultCallback,
13222 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13223 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
13224 mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013225 }
13226
13227 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013228 * Register the subscription with a satellite provider.
13229 * This is needed to register the subscription if the provider allows dynamic registration.
13230 *
13231 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013232 * @param token The token to be used as a unique identifier for provisioning with satellite
13233 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013234 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080013235 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013236 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013237 * @return The signal transport used by the caller to cancel the provision request,
13238 * or {@code null} if the request failed.
13239 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013240 * @throws SecurityException if the caller doesn't have the required permission.
13241 */
13242 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013243 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013244 @NonNull String token, @NonNull byte[] provisionData,
13245 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013246 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013247 return mSatelliteController.provisionSatelliteService(subId, token, provisionData,
13248 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013249 }
13250
13251 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013252 * Unregister the device/subscription with the satellite provider.
13253 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013254 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013255 * should report as deprovisioned.
13256 *
13257 * @param subId The subId of the subscription to be deprovisioned.
13258 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080013259 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013260 *
13261 * @throws SecurityException if the caller doesn't have the required permission.
13262 */
13263 @Override
13264 public void deprovisionSatelliteService(int subId,
13265 @NonNull String token, @NonNull IIntegerConsumer callback) {
13266 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013267 mSatelliteController.deprovisionSatelliteService(subId, token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013268 }
13269
13270 /**
Sarah Chin43457982023-02-15 17:50:38 -080013271 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013272 *
Sarah Chin43457982023-02-15 17:50:38 -080013273 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013274 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013275 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013276 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013277 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013278 * @throws SecurityException if the caller doesn't have the required permission.
13279 */
13280 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013281 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
13282 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013283 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013284 return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013285 }
13286
13287 /**
Sarah Chin43457982023-02-15 17:50:38 -080013288 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013289 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013290 *
Sarah Chin43457982023-02-15 17:50:38 -080013291 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013292 * @param callback The callback that was passed to
13293 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013294 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013295 * @throws SecurityException if the caller doesn't have the required permission.
13296 */
13297 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013298 public void unregisterForSatelliteProvisionStateChanged(
13299 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013300 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013301 mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013302 }
13303
13304 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013305 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013306 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013307 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013308 * @param result The result receiver that returns whether the device is provisioned with a
13309 * satellite provider if the request is successful or an error code if the
13310 * request failed.
13311 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013312 * @throws SecurityException if the caller doesn't have the required permission.
13313 */
13314 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013315 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
13316 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013317 mSatelliteController.requestIsSatelliteProvisioned(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013318 }
13319
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013320 /**
Sarah Chin43457982023-02-15 17:50:38 -080013321 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013322 *
Sarah Chin43457982023-02-15 17:50:38 -080013323 * @param subId The subId of the subscription to register for satellite modem state changed.
13324 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080013325 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013326 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013327 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013328 * @throws SecurityException if the caller doesn't have the required permission.
13329 */
13330 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013331 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013332 @NonNull ISatelliteModemStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080013333 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013334 return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013335 }
13336
13337 /**
Sarah Chin43457982023-02-15 17:50:38 -080013338 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013339 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013340 *
Sarah Chin43457982023-02-15 17:50:38 -080013341 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080013342 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013343 * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013344 *
13345 * @throws SecurityException if the caller doesn't have the required permission.
13346 */
13347 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013348 public void unregisterForModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013349 @NonNull ISatelliteModemStateCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013350 enforceSatelliteCommunicationPermission("unregisterForModemStateChanged");
13351 mSatelliteController.unregisterForModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013352 }
13353
13354 /**
13355 * Register to receive incoming datagrams over satellite.
13356 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013357 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Sarah Chindf715ec2023-02-13 13:46:24 -080013358 * @param callback The callback to handle incoming datagrams over satellite.
13359 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013360 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013361 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013362 * @throws SecurityException if the caller doesn't have the required permission.
13363 */
13364 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013365 @SatelliteManager.SatelliteResult public int registerForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013366 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013367 enforceSatelliteCommunicationPermission("registerForIncomingDatagram");
13368 return mSatelliteController.registerForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013369 }
13370
13371 /**
13372 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013373 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013374 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013375 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
13376 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013377 * {@link #registerForIncomingDatagram(int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013378 *
13379 * @throws SecurityException if the caller doesn't have the required permission.
13380 */
13381 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013382 public void unregisterForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013383 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013384 enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram");
13385 mSatelliteController.unregisterForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013386 }
13387
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013388 /**
13389 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013390 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013391 * This method requests modem to check if there are any pending datagrams to be received over
13392 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000013393 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080013394 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013395 * @param subId The subId of the subscription used for receiving datagrams.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013396 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013397 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013398 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013399 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013400 public void pollPendingDatagrams(int subId, IIntegerConsumer callback) {
13401 enforceSatelliteCommunicationPermission("pollPendingDatagrams");
13402 mSatelliteController.pollPendingDatagrams(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013403 }
13404
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013405 /**
13406 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013407 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013408 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
13409 * input to this method. Datagram received here will be passed down to modem without any
13410 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080013411 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013412 * @param subId The subId of the subscription to send satellite datagrams for.
13413 * @param datagramType datagram type indicating whether the datagram is of type
13414 * SOS_SMS or LOCATION_SHARING.
13415 * @param datagram encoded gateway datagram which is encrypted by the caller.
13416 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000013417 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
13418 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013419 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013420 *
13421 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013422 */
13423 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013424 public void sendDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000013425 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
13426 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013427 enforceSatelliteCommunicationPermission("sendDatagram");
13428 mSatelliteController.sendDatagram(subId, datagramType, datagram, needFullScreenPointingUI,
13429 callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013430 }
13431
Sarah Chindf715ec2023-02-13 13:46:24 -080013432 /**
13433 * Request to get whether satellite communication is allowed for the current location.
13434 *
13435 * @param subId The subId of the subscription to check whether satellite communication is
13436 * allowed for the current location for.
13437 * @param result The result receiver that returns whether satellite communication is allowed
13438 * for the current location if the request is successful or an error code
13439 * if the request failed.
13440 *
13441 * @throws SecurityException if the caller doesn't have the required permission.
13442 */
13443 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013444 public void requestIsCommunicationAllowedForCurrentLocation(int subId,
Sarah Chindf715ec2023-02-13 13:46:24 -080013445 @NonNull ResultReceiver result) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013446 enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation");
13447 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(subId,
13448 result);
Sarah Chindf715ec2023-02-13 13:46:24 -080013449 }
13450
13451 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013452 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080013453 *
Sarah Chin5f57c582023-02-14 04:16:10 -080013454 * @param subId The subId to get the time after which the satellite will be visible for.
13455 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080013456 * be visible if the request is successful or an error code if the request failed.
13457 *
13458 * @throws SecurityException if the caller doesn't have the required permission.
13459 */
13460 @Override
13461 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
13462 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013463 mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013464 }
13465
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013466 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013467 * Inform that Device is aligned to satellite for demo mode.
13468 *
13469 * @param subId The subId to get the time after which the satellite will be visible for.
13470 * @param isAligned {@code true} Device is aligned with the satellite for demo mode
13471 * {@code false} Device fails to align with the satellite for demo mode.
13472 *
13473 * @throws SecurityException if the caller doesn't have required permission.
13474 */
13475 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
13476
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013477 public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) {
Hakjun Choiae365972023-04-25 11:00:31 +000013478 enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite");
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013479 mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned);
Hakjun Choiae365972023-04-25 11:00:31 +000013480 }
13481
13482 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000013483 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
13484 * by modem.
13485 *
13486 * @param subId The subId of the subscription to request for.
13487 * @param reason Reason for disallowing satellite communication for carrier.
Hakjun Choif92ac752024-03-18 19:34:29 +000013488 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013489 * operation.
13490 *
13491 * @throws SecurityException if the caller doesn't have required permission.
13492 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013493 public void addAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013494 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13495 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013496 enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013497 final long identity = Binder.clearCallingIdentity();
13498 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013499 mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013500 } finally {
13501 Binder.restoreCallingIdentity(identity);
13502 }
13503 }
13504
13505 /**
13506 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
13507 * by modem.
13508 *
13509 * @param subId The subId of the subscription to request for.
13510 * @param reason Reason for disallowing satellite communication.
Hakjun Choif92ac752024-03-18 19:34:29 +000013511 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013512 * operation.
13513 *
13514 * @throws SecurityException if the caller doesn't have required permission.
13515 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013516 public void removeAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013517 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13518 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013519 enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013520 final long identity = Binder.clearCallingIdentity();
13521 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013522 mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013523 } finally {
13524 Binder.restoreCallingIdentity(identity);
13525 }
13526 }
13527
13528 /**
13529 * Get reasons for disallowing satellite communication, as requested by
Hakjun Choif92ac752024-03-18 19:34:29 +000013530 * {@link #addAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
Hakjun Choicb39db92023-07-14 15:51:12 +000013531 *
13532 * @param subId The subId of the subscription to request for.
13533 *
13534 * @return Integer array of reasons for disallowing satellite communication.
13535 *
13536 * @throws SecurityException if the caller doesn't have the required permission.
13537 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013538 public @NonNull int[] getAttachRestrictionReasonsForCarrier(
Hakjun Choicb39db92023-07-14 15:51:12 +000013539 int subId) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013540 enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013541 final long identity = Binder.clearCallingIdentity();
13542 try {
13543 Set<Integer> reasonSet =
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013544 mSatelliteController.getAttachRestrictionReasonsForCarrier(subId);
Hakjun Choicb39db92023-07-14 15:51:12 +000013545 return reasonSet.stream().mapToInt(i->i).toArray();
13546 } finally {
13547 Binder.restoreCallingIdentity(identity);
13548 }
13549 }
13550
13551 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000013552 * Request to get the signal strength of the satellite connection.
13553 *
13554 * @param subId The subId of the subscription to request for.
13555 * @param result Result receiver to get the error code of the request and the current signal
13556 * strength of the satellite connection.
13557 *
13558 * @throws SecurityException if the caller doesn't have required permission.
13559 */
13560 @Override
13561 public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) {
13562 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
13563 final long identity = Binder.clearCallingIdentity();
13564 try {
13565 mSatelliteController.requestNtnSignalStrength(subId, result);
13566 } finally {
13567 Binder.restoreCallingIdentity(identity);
13568 }
13569 }
13570
13571 /**
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013572 * Registers for NTN signal strength changed from satellite modem. If the registration operation
13573 * is not successful, a {@link ServiceSpecificException} that contains
13574 * {@link SatelliteManager.SatelliteResult} will be thrown.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013575 *
13576 * @param subId The subId of the subscription to request for.
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013577 * @param callback The callback to handle the NTN signal strength changed event. If the
13578 * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged(
13579 * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of
13580 * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial
13581 * network has changed.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013582 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013583 * @throws SecurityException If the caller doesn't have the required permission.
13584 * @throws ServiceSpecificException If the callback registration operation fails.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013585 */
13586 @Override
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013587 public void registerForNtnSignalStrengthChanged(int subId,
13588 @NonNull INtnSignalStrengthCallback callback) throws RemoteException {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013589 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
13590 final long identity = Binder.clearCallingIdentity();
13591 try {
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013592 mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013593 } finally {
13594 Binder.restoreCallingIdentity(identity);
13595 }
13596 }
13597
13598 /**
13599 * Unregisters for NTN signal strength changed from satellite modem.
13600 * If callback was not registered before, the request will be ignored.
13601 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013602 * @param subId The subId of the subscription to unregister for listening NTN signal strength
13603 * changed event.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013604 * @param callback The callback that was passed to
13605 * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)}
13606 *
13607 * @throws SecurityException if the caller doesn't have the required permission.
13608 */
13609 @Override
13610 public void unregisterForNtnSignalStrengthChanged(
13611 int subId, @NonNull INtnSignalStrengthCallback callback) {
13612 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
13613 final long identity = Binder.clearCallingIdentity();
13614 try {
13615 mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback);
13616 } finally {
13617 Binder.restoreCallingIdentity(identity);
13618 }
13619 }
13620
13621 /**
Hakjun Choi8d96a562023-10-26 15:01:40 +000013622 * Registers for satellite capabilities change event from the satellite service.
13623 *
13624 * @param subId The subId of the subscription to request for.
13625 * @param callback The callback to handle the satellite capabilities changed event.
13626 *
13627 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13628 *
13629 * @throws SecurityException if the caller doesn't have required permission.
13630 */
13631 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013632 @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged(
Hakjun Choi8d96a562023-10-26 15:01:40 +000013633 int subId, @NonNull ISatelliteCapabilitiesCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013634 enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013635 final long identity = Binder.clearCallingIdentity();
13636 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013637 return mSatelliteController.registerForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013638 } finally {
13639 Binder.restoreCallingIdentity(identity);
13640 }
13641 }
13642
13643 /**
13644 * Unregisters for satellite capabilities change event from the satellite service.
13645 * If callback was not registered before, the request will be ignored.
13646 *
13647 * @param subId The subId of the subscription to unregister for satellite capabilities change.
13648 * @param callback The callback that was passed to.
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013649 * {@link #registerForCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}.
Hakjun Choi8d96a562023-10-26 15:01:40 +000013650 *
13651 * @throws SecurityException if the caller doesn't have required permission.
13652 */
13653 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013654 public void unregisterForCapabilitiesChanged(int subId,
13655 @NonNull ISatelliteCapabilitiesCallback callback) {
13656 enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013657 final long identity = Binder.clearCallingIdentity();
13658 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013659 mSatelliteController.unregisterForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013660 } finally {
13661 Binder.restoreCallingIdentity(identity);
13662 }
13663 }
13664
13665 /**
Hakjun Choif92ac752024-03-18 19:34:29 +000013666 * Registers for the satellite supported state changed.
13667 *
13668 * @param subId The subId of the subscription to register for supported state changed.
13669 * @param callback The callback to handle the satellite supported state changed event.
13670 *
13671 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13672 *
13673 * @throws SecurityException if the caller doesn't have the required permission.
13674 */
13675 @Override
13676 @SatelliteManager.SatelliteResult public int registerForSatelliteSupportedStateChanged(
13677 int subId, @NonNull ISatelliteSupportedStateCallback callback) {
13678 enforceSatelliteCommunicationPermission("registerForSatelliteSupportedStateChanged");
13679 return mSatelliteController.registerForSatelliteSupportedStateChanged(subId, callback);
13680 }
13681
13682 /**
13683 * Unregisters for the satellite supported state changed.
13684 * If callback was not registered before, the request will be ignored.
13685 *
13686 * @param subId The subId of the subscription to unregister for supported state changed.
13687 * @param callback The callback that was passed to
13688 * {@link #registerForSatelliteSupportedStateChanged(int, ISatelliteSupportedStateCallback)}.
13689 *
13690 * @throws SecurityException if the caller doesn't have the required permission.
13691 */
13692 @Override
13693 public void unregisterForSatelliteSupportedStateChanged(
13694 int subId, @NonNull ISatelliteSupportedStateCallback callback) {
13695 enforceSatelliteCommunicationPermission("unregisterForSatelliteSupportedStateChanged");
13696 mSatelliteController.unregisterForSatelliteSupportedStateChanged(subId, callback);
13697 }
13698
13699 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013700 * This API can be used by only CTS to update satellite vendor service package name.
13701 *
13702 * @param servicePackageName The package name of the satellite vendor service.
13703 * @return {@code true} if the satellite vendor service is set successfully,
13704 * {@code false} otherwise.
13705 */
13706 public boolean setSatelliteServicePackageName(String servicePackageName) {
13707 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName);
13708 TelephonyPermissions.enforceShellOnly(
13709 Binder.getCallingUid(), "setSatelliteServicePackageName");
13710 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13711 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13712 "setSatelliteServicePackageName");
13713 return mSatelliteController.setSatelliteServicePackageName(servicePackageName);
13714 }
13715
13716 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070013717 * This API can be used by only CTS to update satellite gateway service package name.
13718 *
13719 * @param servicePackageName The package name of the satellite gateway service.
13720 * @return {@code true} if the satellite gateway service is set successfully,
13721 * {@code false} otherwise.
13722 */
13723 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
13724 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
13725 TelephonyPermissions.enforceShellOnly(
13726 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
13727 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13728 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13729 "setSatelliteGatewayServicePackageName");
13730 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
13731 }
13732
13733 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070013734 * This API can be used by only CTS to update satellite pointing UI app package and class names.
13735 *
13736 * @param packageName The package name of the satellite pointing UI app.
13737 * @param className The class name of the satellite pointing UI app.
13738 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
13739 * {@code false} otherwise.
13740 */
13741 public boolean setSatellitePointingUiClassName(
13742 @Nullable String packageName, @Nullable String className) {
13743 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
13744 + ", className=" + className);
13745 TelephonyPermissions.enforceShellOnly(
13746 Binder.getCallingUid(), "setSatellitePointingUiClassName");
13747 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13748 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13749 "setSatelliteGatewayServicePackageName");
13750 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
13751 }
13752
13753 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070013754 * This API can be used by only CTS to update the timeout duration in milliseconds that
13755 * satellite should stay at listening mode to wait for the next incoming page before disabling
13756 * listening mode.
13757 *
13758 * @param timeoutMillis The timeout duration in millisecond.
13759 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13760 */
13761 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
13762 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
13763 TelephonyPermissions.enforceShellOnly(
13764 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
13765 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13766 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13767 "setSatelliteListeningTimeoutDuration");
13768 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
13769 }
13770
13771 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013772 * This API can be used by only CTS to override the timeout durations used by the
13773 * DatagramController module.
Hakjun Choiae365972023-04-25 11:00:31 +000013774 *
13775 * @param timeoutMillis The timeout duration in millisecond.
13776 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13777 */
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013778 public boolean setDatagramControllerTimeoutDuration(
13779 boolean reset, int timeoutType, long timeoutMillis) {
13780 Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset="
13781 + reset + ", timeoutMillis=" + timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013782 TelephonyPermissions.enforceShellOnly(
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013783 Binder.getCallingUid(), "setDatagramControllerTimeoutDuration");
Hakjun Choiae365972023-04-25 11:00:31 +000013784 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13785 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013786 "setDatagramControllerTimeoutDuration");
13787 return mSatelliteController.setDatagramControllerTimeoutDuration(
13788 reset, timeoutType, timeoutMillis);
13789 }
13790
13791 /**
Aishwarya Mallampati3f0ef9b2024-05-17 22:47:04 +000013792 * This API can be used by only CTS to override the boolean configs used by the
13793 * DatagramController module.
13794 *
13795 * @param enable Whether to enable or disable boolean config.
13796 * @return {@code true} if the boolean config is set successfully, {@code false} otherwise.
13797 */
13798 public boolean setDatagramControllerBooleanConfig(
13799 boolean reset, int booleanType, boolean enable) {
13800 Log.d(LOG_TAG, "setDatagramControllerBooleanConfig: booleanType=" + booleanType
13801 + ", reset=" + reset + ", enable=" + enable);
13802 TelephonyPermissions.enforceShellOnly(
13803 Binder.getCallingUid(), "setDatagramControllerBooleanConfig");
13804 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13805 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13806 "ssetDatagramControllerBooleanConfig");
13807 return mSatelliteController.setDatagramControllerBooleanConfig(reset, booleanType, enable);
13808 }
13809
13810
13811 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013812 * This API can be used by only CTS to override the timeout durations used by the
13813 * SatelliteController module.
13814 *
13815 * @param timeoutMillis The timeout duration in millisecond.
13816 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13817 */
13818 public boolean setSatelliteControllerTimeoutDuration(
13819 boolean reset, int timeoutType, long timeoutMillis) {
13820 Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset="
13821 + reset + ", timeoutMillis=" + timeoutMillis);
13822 TelephonyPermissions.enforceShellOnly(
13823 Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration");
13824 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13825 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13826 "setSatelliteControllerTimeoutDuration");
13827 return mSatelliteController.setSatelliteControllerTimeoutDuration(
13828 reset, timeoutType, timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013829 }
13830
13831 /**
Thomas Nguyen11a051f2023-10-25 10:14:55 -070013832 * This API can be used in only testing to override connectivity status in monitoring emergency
13833 * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.
13834 *
13835 * @param handoverType The type of handover from emergency call to satellite messaging. Use one
13836 * of the following values to enable the override:
13837 * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS
13838 * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911
13839 * To disable the override, use -1 for handoverType.
13840 * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer
13841 * delaySeconds after the emergency call starts.
13842 * @return {@code true} if the handover type is set successfully, {@code false} otherwise.
13843 */
13844 public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) {
13845 Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType);
13846 TelephonyPermissions.enforceShellOnly(
13847 Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType");
13848 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13849 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13850 "setEmergencyCallToSatelliteHandoverType");
13851 return mSatelliteController.setEmergencyCallToSatelliteHandoverType(
13852 handoverType, delaySeconds);
13853 }
13854
13855 /**
Thomas Nguyen3d602742024-01-19 11:29:35 -080013856 * This API can be used in only testing to override oem-enabled satellite provision status.
13857 *
13858 * @param reset {@code true} mean the overriding status should not be used, {@code false}
13859 * otherwise.
13860 * @param isProvisioned The overriding provision status.
13861 * @return {@code true} if the provision status is set successfully, {@code false} otherwise.
13862 */
13863 public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) {
13864 Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset
13865 + ", isProvisioned=" + isProvisioned);
13866 TelephonyPermissions.enforceShellOnly(
13867 Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus");
13868 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13869 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13870 "setOemEnabledSatelliteProvisionStatus");
13871 return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned);
13872 }
13873
13874 /**
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013875 * This API should be used by only CTS tests to forcefully set telephony country codes.
13876 *
13877 * @return {@code true} if the country code is set successfully, {@code false} otherwise.
13878 */
13879 public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes,
13880 Map cachedNetworkCountryCodes, String locationCountryCode,
13881 long locationCountryCodeTimestampNanos) {
13882 Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes="
13883 + String.join(", ", currentNetworkCountryCodes)
13884 + ", locationCountryCode=" + locationCountryCode
13885 + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos
13886 + ", reset=" + reset + ", cachedNetworkCountryCodes="
13887 + String.join(", ", cachedNetworkCountryCodes.keySet()));
13888 TelephonyPermissions.enforceShellOnly(
13889 Binder.getCallingUid(), "setCachedLocationCountryCode");
13890 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13891 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13892 "setCachedLocationCountryCode");
13893 return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext()).setCountryCodes(
13894 reset, currentNetworkCountryCodes, cachedNetworkCountryCodes, locationCountryCode,
13895 locationCountryCodeTimestampNanos);
13896 }
13897
13898 /**
13899 * This API should be used by only CTS tests to override the overlay configs of satellite
13900 * access controller.
13901 *
13902 * @param reset {@code true} mean the overridden configs should not be used, {@code false}
13903 * otherwise.
13904 * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise.
13905 */
13906 public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed,
13907 String s2CellFile, long locationFreshDurationNanos,
13908 List<String> satelliteCountryCodes) {
13909 Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset
13910 + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile
13911 + ", locationFreshDurationNanos=" + locationFreshDurationNanos
13912 + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null)
13913 ? String.join(", ", satelliteCountryCodes) : null));
13914 TelephonyPermissions.enforceShellOnly(
13915 Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs");
13916 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13917 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13918 "setSatelliteAccessControlOverlayConfigs");
13919 return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset, isAllowed,
13920 s2CellFile, locationFreshDurationNanos, satelliteCountryCodes);
13921 }
13922
13923 /**
Hakjun Choibc6ce992023-11-07 16:04:33 +000013924 * This API can be used by only CTS to override the cached value for the device overlay config
13925 * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether
13926 * outgoing satellite datagrams should be sent to modem in demo mode.
13927 *
13928 * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to
13929 * satellite modem or not.
13930 *
13931 * @return {@code true} if the operation is successful, {@code false} otherwise.
13932 */
13933 public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) {
13934 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
13935 Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is "
13936 + "disabled");
13937 return false;
13938 }
13939 Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode");
13940 TelephonyPermissions.enforceShellOnly(
13941 Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode");
13942 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13943 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13944 "setShouldSendDatagramToModemInDemoMode");
13945 return mSatelliteController.setShouldSendDatagramToModemInDemoMode(
13946 shouldSendToModemInDemoMode);
13947 }
13948
13949 /**
Hakjun Choi4a832d12024-05-28 22:23:55 +000013950 * This API can be used by only CTS to set the cache whether satellite communication is allowed.
13951 *
13952 * @param state a state indicates whether satellite access allowed state should be cached and
13953 * the allowed state.
13954 * @return {@code true} if the setting is successful, {@code false} otherwise.
13955 */
13956 public boolean setIsSatelliteCommunicationAllowedForCurrentLocationCache(String state) {
13957 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
13958 Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: "
13959 + "oemEnabledSatelliteFlag is disabled");
13960 return false;
13961 }
13962
13963 Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: "
13964 + "state=" + state);
13965 TelephonyPermissions.enforceShellOnly(
13966 Binder.getCallingUid(),
13967 "setIsSatelliteCommunicationAllowedForCurrentLocationCache");
13968 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13969 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13970 "setIsSatelliteCommunicationAllowedForCurrentLocationCache");
13971 return mSatelliteAccessController.setIsSatelliteCommunicationAllowedForCurrentLocationCache(
13972 state);
13973 }
13974
13975 /**
Hunsuk Choi13078be2023-09-13 10:55:21 +000013976 * Sets the service defined in ComponentName to be bound.
13977 *
13978 * This should only be used for testing.
13979 * @return {@code true} if the DomainSelectionService to bind to was set,
13980 * {@code false} otherwise.
13981 */
13982 @Override
13983 public boolean setDomainSelectionServiceOverride(ComponentName componentName) {
13984 Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName);
13985
13986 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
13987 "setDomainSelectionServiceOverride");
13988 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13989 getDefaultSubscription(), "setDomainSelectionServiceOverride");
13990
13991 final long identity = Binder.clearCallingIdentity();
13992 try {
13993 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13994 return DomainSelectionResolver.getInstance()
13995 .setDomainSelectionServiceOverride(componentName);
13996 }
13997 } finally {
13998 Binder.restoreCallingIdentity(identity);
13999 }
14000 return false;
14001 }
14002
14003 /**
14004 * Clears the DomainSelectionService override.
14005 *
14006 * This should only be used for testing.
14007 * @return {@code true} if the DomainSelectionService override was cleared,
14008 * {@code false} otherwise.
14009 */
14010 @Override
14011 public boolean clearDomainSelectionServiceOverride() {
14012 Log.i(LOG_TAG, "clearDomainSelectionServiceOverride");
14013
14014 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
14015 "clearDomainSelectionServiceOverride");
14016 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14017 getDefaultSubscription(), "clearDomainSelectionServiceOverride");
14018
14019 final long identity = Binder.clearCallingIdentity();
14020 try {
14021 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
14022 return DomainSelectionResolver.getInstance()
14023 .clearDomainSelectionServiceOverride();
14024 }
14025 } finally {
14026 Binder.restoreCallingIdentity(identity);
14027 }
14028 return false;
14029 }
14030
14031 /**
Gil Cukierman06403e12023-11-29 16:33:03 +000014032 * Enable or disable notifications sent for cellular identifier disclosure events.
14033 *
14034 * Disclosure events are defined as instances where a device has sent a cellular identifier
14035 * on the Non-access stratum (NAS) before a security context is established. As a result the
14036 * identifier is sent in the clear, which has privacy implications for the user.
14037 *
14038 * @param enable if notifications about disclosure events should be enabled
14039 * @throws SecurityException if the caller does not have the required privileges
14040 * @throws UnsupportedOperationException if the modem does not support this feature.
14041 */
14042 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000014043 public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) {
Gil Cukierman06403e12023-11-29 16:33:03 +000014044 enforceModifyPermission();
14045 checkForIdentifierDisclosureNotificationSupport();
14046
14047 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
14048 editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable);
14049 editor.apply();
14050
14051 // Each phone instance is responsible for updating its respective modem immediately
14052 // after we've made a preference change.
14053 for (Phone phone : PhoneFactory.getPhones()) {
14054 phone.handleIdentifierDisclosureNotificationPreferenceChange();
14055 }
14056 }
14057
14058 /**
14059 * Get whether or not cellular identifier disclosure notifications are enabled.
14060 *
14061 * @throws SecurityException if the caller does not have the required privileges
14062 * @throws UnsupportedOperationException if the modem does not support this feature.
14063 */
14064 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000014065 public boolean isCellularIdentifierDisclosureNotificationsEnabled() {
Gil Cukierman06403e12023-11-29 16:33:03 +000014066 enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled");
14067 checkForIdentifierDisclosureNotificationSupport();
14068 return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled();
14069 }
14070
14071 /**
Michael Groover826b71d2023-12-21 22:08:06 -060014072 * Enables or disables notifications sent when cellular null cipher or integrity algorithms
14073 * are in use by the cellular modem.
14074 *
14075 * @throws IllegalStateException if the Telephony process is not currently available
14076 * @throws SecurityException if the caller does not have the required privileges
14077 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14078 * and integrity algorithms in use
14079 * @hide
14080 */
14081 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Michael Grooverae447b22024-01-24 22:35:46 -060014082 public void setNullCipherNotificationsEnabled(boolean enable) {
Michael Groover826b71d2023-12-21 22:08:06 -060014083 enforceModifyPermission();
14084 checkForNullCipherNotificationSupport();
14085
14086 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
14087 editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable);
14088 editor.apply();
14089
14090 // Each phone instance is responsible for updating its respective modem immediately
14091 // after a preference change.
14092 for (Phone phone : PhoneFactory.getPhones()) {
14093 phone.handleNullCipherNotificationPreferenceChanged();
14094 }
14095 }
14096
14097 /**
14098 * Get whether notifications are enabled for null cipher or integrity algorithms in use by the
14099 * cellular modem.
14100 *
14101 * @throws IllegalStateException if the Telephony process is not currently available
14102 * @throws SecurityException if the caller does not have the required privileges
14103 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14104 * and integrity algorithms in use
14105 * @hide
14106 */
14107 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
14108 public boolean isNullCipherNotificationsEnabled() {
14109 enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled");
14110 checkForNullCipherNotificationSupport();
14111 return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled();
14112 }
14113
14114 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000014115 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
14116 *
14117 * <p>This method behaves in one of the following ways:
14118 * <ul>
14119 * <li>return true : if the calling package has the appop permission {@link
14120 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
14121 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
14122 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
14123 * Owner device identifier access check, or the calling package has carrier privileges</>
14124 * <li>throw SecurityException: if the caller does not meet any of the requirements.
14125 * </ul>
14126 */
14127 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
14128 String callingPackage, @Nullable String callingFeatureId, String message) {
14129 for (Phone phone : PhoneFactory.getPhones()) {
14130 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
14131 phone.getSubId(), callingPackage, callingFeatureId, message)) {
14132 return true;
14133 }
14134 }
14135 return false;
14136 }
arunvoddud7401012022-12-15 16:08:12 +000014137
14138 /**
Jack Yufa8ed012023-02-11 15:42:28 -080014139 * @return The subscription manager service instance.
14140 */
14141 public SubscriptionManagerService getSubscriptionManagerService() {
14142 return SubscriptionManagerService.getInstance();
14143 }
14144
14145 /**
arunvoddud7401012022-12-15 16:08:12 +000014146 * Class binds the consumer[callback] and carrierId.
14147 */
14148 private static class CallerCallbackInfo {
14149 private final Consumer<Integer> mConsumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014150 private final Set<Integer> mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014151
Steve Statia28b7cb32024-03-11 23:58:50 +000014152 public CallerCallbackInfo(Consumer<Integer> consumer, Set<Integer> carrierIds) {
arunvoddud7401012022-12-15 16:08:12 +000014153 mConsumer = consumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014154 mCarrierIds = carrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014155 }
14156
14157 public Consumer<Integer> getConsumer() {
14158 return mConsumer;
14159 }
14160
Steve Statia28b7cb32024-03-11 23:58:50 +000014161 public Set<Integer> getCarrierIds() {
14162 return mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014163 }
14164 }
joonhunshin4ac60942023-11-15 15:23:39 +000014165
14166 /*
14167 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14168 * But the context that is passed in is unused if the phone app is already alive.
14169 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14170 */
14171 @VisibleForTesting
14172 public void setPackageManager(PackageManager packageManager) {
14173 mPackageManager = packageManager;
14174 }
14175
14176 /*
Nate Myren453c3472024-03-13 11:28:11 -070014177 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14178 * But the context that is passed in is unused if the phone app is already alive.
14179 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14180 */
14181 @VisibleForTesting
14182 public void setAppOpsManager(AppOpsManager appOps) {
14183 mAppOps = appOps;
14184 }
14185
14186 /*
joonhunshin4ac60942023-11-15 15:23:39 +000014187 * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags.
14188 * But the FeatureFlags that is passed in is unused if the phone app is already alive.
14189 * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test.
14190 */
14191 @VisibleForTesting
14192 public void setFeatureFlags(FeatureFlags featureFlags) {
14193 mFeatureFlags = featureFlags;
14194 }
14195
14196 /**
14197 * Make sure the device has required telephony feature
14198 *
14199 * @throws UnsupportedOperationException if the device does not have required telephony feature
14200 */
14201 private void enforceTelephonyFeatureWithException(@Nullable String callingPackage,
14202 @NonNull String telephonyFeature, @NonNull String methodName) {
14203 if (callingPackage == null || mPackageManager == null) {
14204 return;
14205 }
14206
14207 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
14208 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage,
joonhunshinf624b2a2024-04-18 04:42:12 +000014209 Binder.getCallingUserHandle())
14210 || mVendorApiLevel < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
14211 // Skip to check associated telephony feature,
14212 // if compatibility change is not enabled for the current process or
14213 // the SDK version of vendor partition is less than Android V.
joonhunshin4ac60942023-11-15 15:23:39 +000014214 return;
14215 }
14216
14217 if (!mPackageManager.hasSystemFeature(telephonyFeature)) {
14218 throw new UnsupportedOperationException(
14219 methodName + " is unsupported without " + telephonyFeature);
14220 }
14221 }
youngtaecha5d483d52024-04-29 17:05:45 +000014222
14223 /**
14224 * Registers for the satellite communication allowed state changed.
14225 *
14226 * @param subId The subId of the subscription to register for the satellite communication
14227 * allowed state changed.
14228 * @param callback The callback to handle the satellite communication allowed
14229 * state changed event.
14230 *
14231 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
14232 *
14233 * @throws SecurityException if the caller doesn't have the required permission.
14234 */
14235 @Override
14236 @SatelliteManager.SatelliteResult public int registerForCommunicationAllowedStateChanged(
14237 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14238 enforceSatelliteCommunicationPermission("registerForCommunicationAllowedStateChanged");
14239 return mSatelliteAccessController.registerForCommunicationAllowedStateChanged(
14240 subId, callback);
14241 }
14242
14243 /**
14244 * Unregisters for the satellite communication allowed state changed.
14245 * If callback was not registered before, the request will be ignored.
14246 *
14247 * @param subId The subId of the subscription to unregister for the satellite communication
14248 * allowed state changed.
14249 * @param callback The callback that was passed to
14250 * {@link #registerForCommunicationAllowedStateChanged(int,
14251 * ISatelliteCommunicationAllowedStateCallback)}. *
14252 * @throws SecurityException if the caller doesn't have the required permission.
14253 */
14254 @Override
14255 public void unregisterForCommunicationAllowedStateChanged(
14256 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14257 enforceSatelliteCommunicationPermission("unregisterForCommunicationAllowedStateChanged");
14258 mSatelliteAccessController.unregisterForCommunicationAllowedStateChanged(subId, callback);
14259 }
Aishwarya Mallampatif265cea2024-06-04 19:55:41 +000014260
14261 /**
14262 * Request to get the {@link SatelliteSessionStats} of the satellite service.
14263 *
14264 * @param subId The subId of the subscription to the satellite session stats for.
14265 * @param result The result receiver that returns the {@link SatelliteSessionStats}
14266 * if the request is successful or an error code if the request failed.
14267 *
14268 * @throws SecurityException if the caller doesn't have required permission.
14269 */
14270 @Override
14271 public void requestSatelliteSessionStats(int subId, @NonNull ResultReceiver result) {
14272 enforceModifyPermission();
14273 enforcePackageUsageStatsPermission("requestSatelliteSessionStats");
14274 mSatelliteController.requestSatelliteSessionStats(subId, result);
14275 }
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014276
14277 /**
14278 * Request to get list of prioritized satellite subscriber ids to be used for provision.
14279 *
14280 * @param result The result receiver, which returns the list of prioritized satellite tokens
14281 * to be used for provision if the request is successful or an error code if the request failed.
14282 *
14283 * @throws SecurityException if the caller doesn't have the required permission.
14284 */
14285 @Override
14286 public void requestProvisionSubscriberIds(@NonNull ResultReceiver result) {
14287 enforceSatelliteCommunicationPermission("requestProvisionSubscriberIds");
14288 mSatelliteController.requestProvisionSubscriberIds(result);
14289 }
14290
14291 /**
14292 * Request to get provisioned status for given a satellite subscriber id.
14293 *
14294 * @param satelliteSubscriberId Satellite subscriber id requiring provisioned status check.
14295 * @param result The result receiver, which returns the provisioned status of the token if the
14296 * request is successful or an error code if the request failed.
14297 *
14298 * @throws SecurityException if the caller doesn't have the required permission.
14299 */
14300 @Override
14301 public void requestIsProvisioned(String satelliteSubscriberId, @NonNull ResultReceiver result) {
14302 enforceSatelliteCommunicationPermission("requestIsProvisioned");
14303 mSatelliteController.requestIsProvisioned(satelliteSubscriberId, result);
14304 }
14305
14306 /**
14307 * Deliver the list of provisioned satellite subscriber ids.
14308 *
14309 * @param list List of provisioned satellite subscriber ids.
14310 * @param result The result receiver that returns whether deliver success or fail.
14311 *
14312 * @throws SecurityException if the caller doesn't have the required permission.
14313 */
14314 @Override
14315 public void provisionSatellite(List<ProvisionSubscriberId> list,
14316 @NonNull ResultReceiver result) {
14317 enforceSatelliteCommunicationPermission("provisionSatellite");
14318 mSatelliteController.provisionSatellite(list, result);
14319 }
Jack Yufa8ed012023-02-11 15:42:28 -080014320}