blob: f410fadf2cd5d911ea7e4f5e622286976c4af5a9 [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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070079import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070080import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070081import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070082import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070083import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080084import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070085import android.provider.Telephony;
arunvoddud7401012022-12-15 16:08:12 +000086import android.service.carrier.CarrierIdentifier;
Inseob Kim14bb3d02018-12-13 17:11:34 +090087import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080088import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080089import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070090import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080091import android.telephony.AccessNetworkConstants;
92import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070093import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070094import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080095import android.telephony.Annotation.ThermalMitigationResult;
Sarah Chin2ec39f62022-08-31 17:03:26 -070096import android.telephony.AnomalyReporter;
Shuo Qian4a594052020-01-23 11:59:30 -080097import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070098import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080099import android.telephony.CarrierRestrictionRules;
Hui Wang9b5793a2022-12-05 14:38:06 -0600100import android.telephony.CellBroadcastIdRange;
yincheng zhao2737e882019-09-06 17:06:54 -0700101import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -0800102import android.telephony.CellIdentityCdma;
103import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700104import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -0700105import android.telephony.CellInfoGsm;
106import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700107import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800108import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -0700109import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700110import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700111import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -0800112import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700113import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -0800114import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -0700115import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -0800116import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800117import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700118import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800119import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700120import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800121import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800122import android.telephony.SignalStrengthUpdateRequest;
123import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800124import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800125import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800126import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700127import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700128import android.telephony.TelephonyManager;
Jack Yuf5badd92022-12-08 00:50:53 -0800129import android.telephony.TelephonyManager.SimState;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800130import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800131import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800132import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000133import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000134import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000135import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700136import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700137import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800138import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800139import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700140import android.telephony.gba.GbaAuthRequest;
141import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700142import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800143import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000144import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000145import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700146import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000147import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700148import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800149import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700150import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800151import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700152import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000153import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700154import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800155import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800156import android.telephony.ims.stub.ImsRegistrationImplBase;
Hakjun Choifa3e6172023-09-22 03:56:34 +0000157import android.telephony.satellite.INtnSignalStrengthCallback;
Hakjun Choi8d96a562023-10-26 15:01:40 +0000158import android.telephony.satellite.ISatelliteCapabilitiesCallback;
youngtaecha5d483d52024-04-29 17:05:45 +0000159import android.telephony.satellite.ISatelliteCommunicationAllowedStateCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800160import android.telephony.satellite.ISatelliteDatagramCallback;
Hakjun Choid4a52a22023-12-13 09:48:24 +0000161import android.telephony.satellite.ISatelliteModemStateCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800162import android.telephony.satellite.ISatelliteProvisionStateCallback;
Hakjun Choif92ac752024-03-18 19:34:29 +0000163import android.telephony.satellite.ISatelliteSupportedStateCallback;
Sarah Chinabf081b2023-03-09 23:00:57 -0800164import android.telephony.satellite.ISatelliteTransmissionUpdateCallback;
Hakjun Choi4c3668a2023-12-05 11:55:36 +0000165import android.telephony.satellite.NtnSignalStrength;
166import android.telephony.satellite.NtnSignalStrengthCallback;
Sarah Chin503828c2023-02-01 23:54:20 -0800167import android.telephony.satellite.SatelliteCapabilities;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000168import android.telephony.satellite.SatelliteDatagram;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800169import android.telephony.satellite.SatelliteDatagramCallback;
Sarah Chineccfbd12023-01-20 19:00:35 -0800170import android.telephony.satellite.SatelliteManager;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800171import android.telephony.satellite.SatelliteProvisionStateCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700172import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800173import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700174import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700175import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800176import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800177
Andrew Lee312e8172014-10-23 17:01:36 -0700178import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800179import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800180import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800181import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800182import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700183import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700184import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700185import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800186import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800187import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700188import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700189import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800190import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700191import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800192import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800193import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800194import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700195import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000196import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700197import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800198import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700199import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800200import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800201import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800202import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700203import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700204import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700205import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700206import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700207import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800208import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700209import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700210import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700211import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700212import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800213import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800214import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700215import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000216import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700217import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700218import com.android.internal.telephony.SmsPermissions;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800219import com.android.internal.telephony.TelephonyCountryDetector;
Peter Wang59571be2020-01-27 12:35:15 +0800220import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800221import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700222import com.android.internal.telephony.data.DataUtils;
Hunsuk Choi42cc62a2022-10-16 06:03:40 +0000223import com.android.internal.telephony.domainselection.DomainSelectionResolver;
sqianf4ca7ed2019-01-15 18:32:07 -0800224import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700225import com.android.internal.telephony.euicc.EuiccConnector;
Sarah Chincc5446f2023-10-23 17:57:19 -0700226import com.android.internal.telephony.flags.FeatureFlags;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800227import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700228import com.android.internal.telephony.imsphone.ImsPhone;
229import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000230import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800231import com.android.internal.telephony.metrics.TelephonyMetrics;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000232import com.android.internal.telephony.satellite.SatelliteController;
Jack Yu285100e2022-12-02 22:48:35 -0800233import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
234import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700235import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700236import com.android.internal.telephony.uicc.IccIoResult;
237import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800238import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700239import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800240import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700241import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000242import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800243import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000244import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800245import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000246import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700247import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700248import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800249import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800250import com.android.phone.callcomposer.CallComposerPictureManager;
251import com.android.phone.callcomposer.CallComposerPictureTransfer;
252import com.android.phone.callcomposer.ImageData;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800253import com.android.phone.satellite.accesscontrol.SatelliteAccessController;
Hyosun Kim240214a2023-11-02 13:30:15 +0000254import com.android.phone.satellite.entitlement.SatelliteEntitlementController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700255import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700256import com.android.phone.slice.SlicePurchaseController;
arunvoddud7401012022-12-15 16:08:12 +0000257import com.android.phone.utils.CarrierAllowListInfo;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700258import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800259import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700260import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700261import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800262import com.android.services.telephony.TelecomAccountRegistry;
263import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800264import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800265
Hall Liu82694d52020-12-11 18:22:04 -0800266import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700267import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800268import java.io.IOException;
269import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700270import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700271import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800272import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000273import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800274import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800275import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800276import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800277import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100278import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800279import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700280import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800281import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800282import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700283import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800284import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800285import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800286import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700287
288/**
289 * Implementation of the ITelephony interface.
290 */
Santos Cordon117fee72014-05-16 17:56:12 -0700291public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700292 private static final String LOG_TAG = "PhoneInterfaceManager";
293 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
294 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800295 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700296
297 // Message codes used with mMainThreadHandler
298 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700299 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
300 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700301 private static final int CMD_OPEN_CHANNEL = 9;
302 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
303 private static final int CMD_CLOSE_CHANNEL = 11;
304 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800305 private static final int CMD_NV_READ_ITEM = 13;
306 private static final int EVENT_NV_READ_ITEM_DONE = 14;
307 private static final int CMD_NV_WRITE_ITEM = 15;
308 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
309 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
310 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700311 private static final int CMD_RESET_MODEM_CONFIG = 19;
312 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800313 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
314 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800315 private static final int CMD_SEND_ENVELOPE = 25;
316 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700317 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
318 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
319 private static final int CMD_EXCHANGE_SIM_IO = 31;
320 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800321 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
322 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700323 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
324 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700325 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
326 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700327 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
328 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
329 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
330 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700331 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
332 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
333 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
334 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700335 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800336 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
337 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000338 private static final int CMD_SWITCH_SLOTS = 50;
339 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700340 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
341 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
342 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
343 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
344 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
345 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
346 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
347 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700348 private static final int CMD_GET_ALL_CELL_INFO = 60;
349 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
350 private static final int CMD_GET_CELL_LOCATION = 62;
351 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700352 private static final int CMD_MODEM_REBOOT = 64;
353 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700354 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
355 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800356 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
357 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700358 private static final int CMD_GET_MODEM_STATUS = 70;
359 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700360 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
361 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700362 private static final int CMD_ERASE_MODEM_CONFIG = 74;
363 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800364 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
365 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
366 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
367 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800368 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
369 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800370 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800371 private static final int CMD_GET_CALL_FORWARDING = 83;
372 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
373 private static final int CMD_SET_CALL_FORWARDING = 85;
374 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
375 private static final int CMD_GET_CALL_WAITING = 87;
376 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
377 private static final int CMD_SET_CALL_WAITING = 89;
378 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700379 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
380 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
381 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
382 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700383 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
384 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800385 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
386 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800387 private static final int CMD_SET_DATA_THROTTLING = 99;
388 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800389 private static final int CMD_SET_SIM_POWER = 101;
390 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800391 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
392 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
393 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
394 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800395 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
396 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000397 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800398 private static final int CMD_GET_SLICING_CONFIG = 110;
399 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800400 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700401 private static final int CMD_ENABLE_VONR = 113;
402 private static final int EVENT_ENABLE_VONR_DONE = 114;
403 private static final int CMD_IS_VONR_ENABLED = 115;
404 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700405 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
406 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000407
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800408 // Parameters of select command.
409 private static final int SELECT_COMMAND = 0xA4;
410 private static final int SELECT_P1 = 0x04;
411 private static final int SELECT_P2 = 0;
412 private static final int SELECT_P3 = 0x10;
413
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000414 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
415 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
Gil Cukierman06403e12023-11-29 16:33:03 +0000416 // Cellular identifier disclosure transparency was added in IRadioNetwork 2.2
417 private static final int MIN_IDENTIFIER_DISCLOSURE_VERSION = 202;
Michael Groover826b71d2023-12-21 22:08:06 -0600418 // Null cipher notification support was added in IRadioNetwork 2.2
419 private static final int MIN_NULL_CIPHER_NOTIFICATION_VERSION = 202;
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000420
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700421 /** The singleton instance. */
422 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800423 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700424
Sarah Chin4beb2b72023-02-14 14:47:54 -0800425 private final PhoneGlobals mApp;
joonhunshin4ac60942023-11-15 15:23:39 +0000426 private FeatureFlags mFeatureFlags;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800427 private final CallManager mCM;
428 private final ImsResolver mImsResolver;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000429
430 private final SatelliteController mSatelliteController;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800431 private final SatelliteAccessController mSatelliteAccessController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800432 private final UserManager mUserManager;
433 private final AppOpsManager mAppOps;
434 private final MainThreadHandler mMainThreadHandler;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800435 private final SharedPreferences mTelephonySharedPreferences;
436 private final PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800437 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
joonhunshin4ac60942023-11-15 15:23:39 +0000438 private PackageManager mPackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700439
Peter Wangdafb9ac2020-01-15 14:13:38 -0800440 /** User Activity */
Sarah Chin4beb2b72023-02-14 14:47:54 -0800441 private final AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800442 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800443 private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800444
Derek Tan97ebb422014-09-05 16:55:38 -0700445 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
446 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800447 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800448 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700449
Michelecea4cf22018-12-21 15:00:11 -0800450 // String to store multi SIM allowed
451 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
452
Derek Tan740e1672017-06-27 14:56:27 -0700453 // The AID of ISD-R.
454 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
455
yinxub1bed742017-04-17 11:45:04 -0700456 private NetworkScanRequestTracker mNetworkScanRequestTracker;
457
David Kelly5e06a7f2018-03-12 14:10:59 +0000458 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
459 private static final int MANUFACTURER_CODE_LENGTH = 8;
460
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800461 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800462 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800463
Sarah Chin2ec39f62022-08-31 17:03:26 -0700464 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
465 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
466
Derek Tan89e89d42014-07-08 17:00:10 -0700467 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700468 * Experiment flag to enable erase modem config on reset network, default value is false
469 */
470 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
471 "reset_network_erase_modem_config_enabled";
472
Rambo Wang0f050d82021-02-12 11:43:36 -0800473 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800474
Gary Jian76280a42022-12-07 16:18:33 +0800475 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
476
sandeepjsb6c87872021-09-27 15:34:44 +0000477 /**
478 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
479 * one ICCID active at the same time.
480 * Apps should use below API signatures if targeting SDK is T and beyond.
481 *
482 * @hide
483 */
484 @ChangeId
485 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
486 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800487
Naina Nallurid63128d2019-09-17 14:10:30 -0700488 /**
Chen Xu540470b2021-12-14 17:15:47 -0800489 * Apps targeting on Android T and beyond will get exception whenever icc close channel
490 * operation fails.
491 */
492 @ChangeId
493 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
494 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
495
496 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700497 * A request object to use for transmitting data to an ICC.
498 */
499 private static final class IccAPDUArgument {
500 public int channel, cla, command, p1, p2, p3;
501 public String data;
502
503 public IccAPDUArgument(int channel, int cla, int command,
504 int p1, int p2, int p3, String data) {
505 this.channel = channel;
506 this.cla = cla;
507 this.command = command;
508 this.p1 = p1;
509 this.p2 = p2;
510 this.p3 = p3;
511 this.data = data;
512 }
513 }
514
515 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700516 * A request object to use for transmitting data to an ICC.
517 */
518 private static final class ManualNetworkSelectionArgument {
519 public OperatorInfo operatorInfo;
520 public boolean persistSelection;
521
522 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
523 this.operatorInfo = operatorInfo;
524 this.persistSelection = persistSelection;
525 }
526 }
527
Sarah Chin71b3a852022-09-28 15:54:19 -0700528 private static final class PurchasePremiumCapabilityArgument {
529 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700530 public @NonNull IIntegerConsumer callback;
531
532 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800533 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700534 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700535 this.callback = callback;
536 }
537 }
538
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700539 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700540 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
541 * request after sending. The main thread will notify the request when it is complete.
542 */
543 private static final class MainThreadRequest {
544 /** The argument to use for the request */
545 public Object argument;
546 /** The result of the request that is run on the main thread */
547 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800548 // The subscriber id that this request applies to. Defaults to
549 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
550 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700551
Nathan Harold92bed182018-10-12 18:16:49 -0700552 // In cases where subId is unavailable, the caller needs to specify the phone.
553 public Phone phone;
554
vagdeviaf9a5b92018-08-15 16:01:53 -0700555 public WorkSource workSource;
556
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700557 public MainThreadRequest(Object argument) {
558 this.argument = argument;
559 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800560
Nathan Harold92bed182018-10-12 18:16:49 -0700561 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
562 this.argument = argument;
563 if (phone != null) {
564 this.phone = phone;
565 }
566 this.workSource = workSource;
567 }
568
vagdeviaf9a5b92018-08-15 16:01:53 -0700569 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800570 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800571 if (subId != null) {
572 this.subId = subId;
573 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700574 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800575 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700576 }
577
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800578 private static final class IncomingThirdPartyCallArgs {
579 public final ComponentName component;
580 public final String callId;
581 public final String callerDisplayName;
582
583 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
584 String callerDisplayName) {
585 this.component = component;
586 this.callId = callId;
587 this.callerDisplayName = callerDisplayName;
588 }
589 }
590
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700591 /**
592 * A handler that processes messages on the main thread in the phone process. Since many
593 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
594 * inbound binder threads to the main thread in the phone process. The Binder thread
595 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
596 * on, which will be notified when the operation completes and will contain the result of the
597 * request.
598 *
599 * <p>If a MainThreadRequest object is provided in the msg.obj field,
600 * note that request.result must be set to something non-null for the calling thread to
601 * unblock.
602 */
603 private final class MainThreadHandler extends Handler {
604 @Override
605 public void handleMessage(Message msg) {
606 MainThreadRequest request;
607 Message onCompleted;
608 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000609 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700610 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800611 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700612
613 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700614 case CMD_HANDLE_USSD_REQUEST: {
615 request = (MainThreadRequest) msg.obj;
616 final Phone phone = getPhoneFromRequest(request);
617 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800618 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700619 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700620
Pengquan Menga1bb6272018-09-06 09:59:22 -0700621 if (!isUssdApiAllowed(request.subId)) {
622 // Carrier does not support use of this API, return failure.
623 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
624 UssdResponse response = new UssdResponse(ussdRequest, null);
625 Bundle returnData = new Bundle();
626 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
627 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700628
Pengquan Menga1bb6272018-09-06 09:59:22 -0700629 request.result = true;
630 notifyRequester(request);
631 return;
632 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700633
Pengquan Menga1bb6272018-09-06 09:59:22 -0700634 try {
635 request.result = phone != null
636 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
637 } catch (CallStateException cse) {
638 request.result = false;
639 }
640 // Wake up the requesting thread
641 notifyRequester(request);
642 break;
pkanwar32d516d2016-10-14 19:37:38 -0700643 }
644
Yorke Lee716f67e2015-06-17 15:39:16 -0700645 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700646 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700647 final Phone phone = getPhoneFromRequest(request);
648 request.result = phone != null ?
649 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
650 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700651 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700652 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700653 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700654 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700655
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700656 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700657 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700658 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000659 uiccPort = getUiccPortFromRequest(request);
660 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700661 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800662 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700663 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700664 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700665 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800666 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000667 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800668 iccArgument.channel, iccArgument.cla, iccArgument.command,
669 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
670 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700671 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700672 break;
673
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700674 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700675 ar = (AsyncResult) msg.obj;
676 request = (MainThreadRequest) ar.userObj;
677 if (ar.exception == null && ar.result != null) {
678 request.result = ar.result;
679 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800680 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700681 if (ar.result == null) {
682 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800683 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700684 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800685 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700686 } else {
687 loge("iccTransmitApduLogicalChannel: Unknown exception");
688 }
689 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700690 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700691 break;
692
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700693 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
694 request = (MainThreadRequest) msg.obj;
695 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000696 uiccPort = getUiccPortFromRequest(request);
697 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700698 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800699 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700700 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700701 } else {
702 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800703 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000704 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800705 iccArgument.cla, iccArgument.command, iccArgument.p1,
706 iccArgument.p2,
707 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700708 }
709 break;
710
711 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
712 ar = (AsyncResult) msg.obj;
713 request = (MainThreadRequest) ar.userObj;
714 if (ar.exception == null && ar.result != null) {
715 request.result = ar.result;
716 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800717 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700718 if (ar.result == null) {
719 loge("iccTransmitApduBasicChannel: Empty response");
720 } else if (ar.exception instanceof CommandException) {
721 loge("iccTransmitApduBasicChannel: CommandException: " +
722 ar.exception);
723 } else {
724 loge("iccTransmitApduBasicChannel: Unknown exception");
725 }
726 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700727 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700728 break;
729
730 case CMD_EXCHANGE_SIM_IO:
731 request = (MainThreadRequest) msg.obj;
732 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000733 uiccPort = getUiccPortFromRequest(request);
734 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700735 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800736 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700737 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700738 } else {
739 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
740 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000741 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700742 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
743 iccArgument.data, onCompleted);
744 }
745 break;
746
747 case EVENT_EXCHANGE_SIM_IO_DONE:
748 ar = (AsyncResult) msg.obj;
749 request = (MainThreadRequest) ar.userObj;
750 if (ar.exception == null && ar.result != null) {
751 request.result = ar.result;
752 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800753 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700754 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700755 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700756 break;
757
Derek Tan4d5e5c12014-02-04 11:54:58 -0800758 case CMD_SEND_ENVELOPE:
759 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000760 uiccPort = getUiccPortFromRequest(request);
761 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700762 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800763 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700764 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700765 } else {
766 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800767 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700768 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800769 break;
770
771 case EVENT_SEND_ENVELOPE_DONE:
772 ar = (AsyncResult) msg.obj;
773 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700774 if (ar.exception == null && ar.result != null) {
775 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800776 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800777 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700778 if (ar.result == null) {
779 loge("sendEnvelopeWithStatus: Empty response");
780 } else if (ar.exception instanceof CommandException) {
781 loge("sendEnvelopeWithStatus: CommandException: " +
782 ar.exception);
783 } else {
784 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
785 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800786 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700787 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800788 break;
789
Shishir Agrawal566b7612013-10-28 14:41:00 -0700790 case CMD_OPEN_CHANNEL:
791 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000792 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800793 IccLogicalChannelRequest openChannelRequest =
794 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000795 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700796 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800797 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800798 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700799 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700800 } else {
801 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800802 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
803 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700804 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700805 break;
806
807 case EVENT_OPEN_CHANNEL_DONE:
808 ar = (AsyncResult) msg.obj;
809 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700810 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700811 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700812 int[] result = (int[]) ar.result;
813 int channelId = result[0];
814 byte[] selectResponse = null;
815 if (result.length > 1) {
816 selectResponse = new byte[result.length - 1];
817 for (int i = 1; i < result.length; ++i) {
818 selectResponse[i - 1] = (byte) result[i];
819 }
820 }
821 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800822 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800823
824 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700825 if (uiccPort == null) {
826 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
827 } else {
828 IccLogicalChannelRequest channelRequest =
829 (IccLogicalChannelRequest) request.argument;
830 channelRequest.channel = channelId;
831 uiccPort.onLogicalChannelOpened(channelRequest);
832 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700833 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700834 if (ar.result == null) {
835 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700836 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700837 if (ar.exception != null) {
838 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
839 }
840
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700841 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700842 if (ar.exception instanceof CommandException) {
843 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800844 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700845 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700846 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700847 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700848 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700849 }
850 }
851 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800852 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700853 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700854 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700855 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700856 break;
857
858 case CMD_CLOSE_CHANNEL:
859 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000860 uiccPort = getUiccPortFromRequest(request);
861 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700862 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800863 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800864 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800865 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700866 } else {
867 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000868 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700869 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700870 break;
871
872 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800873 ar = (AsyncResult) msg.obj;
874 request = (MainThreadRequest) ar.userObj;
875 if (ar.exception == null) {
876 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800877 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700878 if (uiccPort == null) {
879 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
880 } else {
881 final int channelId = (Integer) request.argument;
882 uiccPort.onLogicalChannelClosed(channelId);
883 }
Chen Xu540470b2021-12-14 17:15:47 -0800884 } else {
885 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800886 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800887 if (ar.exception instanceof CommandException) {
888 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
889 CommandException.Error error =
890 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800891 if (error == CommandException.Error.INVALID_ARGUMENTS) {
892 // should only throw exceptions from the binder threads.
893 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800894 "iccCloseLogicalChannel: invalid argument ");
895 }
896 } else {
897 loge("iccCloseLogicalChannel: Unknown exception");
898 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800899 request.result = (exception != null) ? exception :
900 new IllegalStateException(
901 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800902 }
903 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800904 break;
905
906 case CMD_NV_READ_ITEM:
907 request = (MainThreadRequest) msg.obj;
908 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800909 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
910 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800911 break;
912
913 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700914 ar = (AsyncResult) msg.obj;
915 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800916 if (ar.exception == null && ar.result != null) {
917 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700918 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800919 request.result = "";
920 if (ar.result == null) {
921 loge("nvReadItem: Empty response");
922 } else if (ar.exception instanceof CommandException) {
923 loge("nvReadItem: CommandException: " +
924 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700925 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800926 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700927 }
928 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700929 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700930 break;
931
Jake Hambye994d462014-02-03 13:10:13 -0800932 case CMD_NV_WRITE_ITEM:
933 request = (MainThreadRequest) msg.obj;
934 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
935 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800936 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700937 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800938 break;
939
940 case EVENT_NV_WRITE_ITEM_DONE:
941 handleNullReturnEvent(msg, "nvWriteItem");
942 break;
943
944 case CMD_NV_WRITE_CDMA_PRL:
945 request = (MainThreadRequest) msg.obj;
946 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800947 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800948 break;
949
950 case EVENT_NV_WRITE_CDMA_PRL_DONE:
951 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
952 break;
953
chen xu6dac5ab2018-10-26 17:39:23 -0700954 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800955 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700956 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800957 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800958 break;
959
chen xu6dac5ab2018-10-26 17:39:23 -0700960 case EVENT_RESET_MODEM_CONFIG_DONE:
961 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800962 break;
963
Sooraj Sasindran37444802020-08-11 10:40:43 -0700964 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
965 request = (MainThreadRequest) msg.obj;
966 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
967 request);
968 Phone phone = getPhoneFromRequest(request);
969 if (phone != null) {
970 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
971 } else {
972 loge("isNRDualConnectivityEnabled: No phone object");
973 request.result = false;
974 notifyRequester(request);
975 }
976 break;
977 }
978
979 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
980 ar = (AsyncResult) msg.obj;
981 request = (MainThreadRequest) ar.userObj;
982 if (ar.exception == null && ar.result != null) {
983 request.result = ar.result;
984 } else {
985 // request.result must be set to something non-null
986 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700987 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700988 request.result = ar.result;
989 } else {
990 request.result = false;
991 }
992 if (ar.result == null) {
993 loge("isNRDualConnectivityEnabled: Empty response");
994 } else if (ar.exception instanceof CommandException) {
995 loge("isNRDualConnectivityEnabled: CommandException: "
996 + ar.exception);
997 } else {
998 loge("isNRDualConnectivityEnabled: Unknown exception");
999 }
1000 }
1001 notifyRequester(request);
1002 break;
1003
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001004 case CMD_IS_VONR_ENABLED: {
1005 request = (MainThreadRequest) msg.obj;
1006 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
1007 request);
1008 Phone phone = getPhoneFromRequest(request);
1009 if (phone != null) {
1010 phone.isVoNrEnabled(onCompleted, request.workSource);
1011 } else {
1012 loge("isVoNrEnabled: No phone object");
1013 request.result = false;
1014 notifyRequester(request);
1015 }
1016 break;
1017 }
1018
1019 case EVENT_IS_VONR_ENABLED_DONE:
1020 ar = (AsyncResult) msg.obj;
1021 request = (MainThreadRequest) ar.userObj;
1022 if (ar.exception == null && ar.result != null) {
1023 request.result = ar.result;
1024 } else {
1025 // request.result must be set to something non-null
1026 // for the calling thread to unblock
1027 if (ar.result != null) {
1028 request.result = ar.result;
1029 } else {
1030 request.result = false;
1031 }
1032 if (ar.result == null) {
1033 loge("isVoNrEnabled: Empty response");
1034 } else if (ar.exception instanceof CommandException) {
1035 loge("isVoNrEnabled: CommandException: "
1036 + ar.exception);
1037 } else {
1038 loge("isVoNrEnabled: Unknown exception");
1039 }
1040 }
1041 notifyRequester(request);
1042 break;
1043
Sooraj Sasindran37444802020-08-11 10:40:43 -07001044 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1045 request = (MainThreadRequest) msg.obj;
1046 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1047 Phone phone = getPhoneFromRequest(request);
1048 if (phone != null) {
1049 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1050 request.workSource);
1051 } else {
1052 loge("enableNrDualConnectivity: No phone object");
1053 request.result =
1054 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1055 notifyRequester(request);
1056 }
1057 break;
1058 }
1059
1060 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1061 ar = (AsyncResult) msg.obj;
1062 request = (MainThreadRequest) ar.userObj;
1063 if (ar.exception == null) {
1064 request.result =
1065 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1066 } else {
1067 request.result =
1068 TelephonyManager
1069 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1070 if (ar.exception instanceof CommandException) {
1071 CommandException.Error error =
1072 ((CommandException) (ar.exception)).getCommandError();
1073 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1074 request.result =
1075 TelephonyManager
1076 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001077 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1078 request.result =
1079 TelephonyManager
1080 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001081 }
1082 loge("enableNrDualConnectivity" + ": CommandException: "
1083 + ar.exception);
1084 } else {
1085 loge("enableNrDualConnectivity" + ": Unknown exception");
1086 }
1087 }
1088 notifyRequester(request);
1089 break;
1090 }
1091
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001092 case CMD_ENABLE_VONR: {
1093 request = (MainThreadRequest) msg.obj;
1094 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1095 Phone phone = getPhoneFromRequest(request);
1096 if (phone != null) {
1097 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1098 request.workSource);
1099 } else {
1100 loge("setVoNrEnabled: No phone object");
1101 request.result =
1102 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1103 notifyRequester(request);
1104 }
1105 break;
1106 }
1107
1108 case EVENT_ENABLE_VONR_DONE: {
1109 ar = (AsyncResult) msg.obj;
1110 request = (MainThreadRequest) ar.userObj;
1111 if (ar.exception == null) {
1112 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1113 } else {
1114 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1115 if (ar.exception instanceof CommandException) {
1116 CommandException.Error error =
1117 ((CommandException) (ar.exception)).getCommandError();
1118 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1119 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1120 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1121 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1122 } else {
1123 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1124 }
1125 loge("setVoNrEnabled" + ": CommandException: "
1126 + ar.exception);
1127 } else {
1128 loge("setVoNrEnabled" + ": Unknown exception");
1129 }
1130 }
1131 notifyRequester(request);
1132 break;
1133 }
1134
SongFerngWang3ef3e072020-12-21 16:41:52 +08001135 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001136 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001137 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1138 request);
1139 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001140 break;
1141
SongFerngWang3ef3e072020-12-21 16:41:52 +08001142 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001143 ar = (AsyncResult) msg.obj;
1144 request = (MainThreadRequest) ar.userObj;
1145 if (ar.exception == null && ar.result != null) {
1146 request.result = ar.result; // Integer
1147 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301148 // request.result must be set to something non-null
1149 // for the calling thread to unblock
1150 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001151 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001152 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001153 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001154 loge("getAllowedNetworkTypesBitmask: CommandException: "
1155 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001156 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001157 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001158 }
1159 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001160 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001161 break;
1162
SongFerngWang3ef3e072020-12-21 16:41:52 +08001163 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001164 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001165 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1166 request);
1167 Pair<Integer, Long> reasonWithNetworkTypes =
1168 (Pair<Integer, Long>) request.argument;
1169 getPhoneFromRequest(request).setAllowedNetworkTypes(
1170 reasonWithNetworkTypes.first,
1171 reasonWithNetworkTypes.second,
1172 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001173 break;
1174
SongFerngWang3ef3e072020-12-21 16:41:52 +08001175 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1176 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001177 break;
1178
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001179 case CMD_SET_VOICEMAIL_NUMBER:
1180 request = (MainThreadRequest) msg.obj;
1181 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1182 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001183 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1184 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001185 break;
1186
1187 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1188 handleNullReturnEvent(msg, "setVoicemailNumber");
1189 break;
1190
Stuart Scott54788802015-03-30 13:18:01 -07001191 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1192 request = (MainThreadRequest) msg.obj;
1193 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1194 request);
1195 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1196 break;
1197
1198 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1199 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1200 break;
1201
Shishir Agrawal302c8692015-06-19 13:49:39 -07001202 case CMD_PERFORM_NETWORK_SCAN:
1203 request = (MainThreadRequest) msg.obj;
1204 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1205 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1206 break;
1207
Hall Liu27d24262020-09-18 19:04:59 -07001208 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001209 request = (MainThreadRequest) msg.obj;
1210 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001211 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1212 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1213 request.argument;
1214 int callForwardingReason = args.first;
1215 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001216 break;
Hall Liu27d24262020-09-18 19:04:59 -07001217 }
1218 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001219 ar = (AsyncResult) msg.obj;
1220 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001221 TelephonyManager.CallForwardingInfoCallback callback =
1222 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1223 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001224 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001225 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001226 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1227 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1228 // Service Class is a bit mask per 3gpp 27.007. Search for
1229 // any service for voice call.
1230 if ((callForwardInfo.serviceClass
1231 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001232 callForwardingInfo = new CallForwardingInfo(
1233 callForwardInfo.status
1234 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001235 callForwardInfo.reason,
1236 callForwardInfo.number,
1237 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001238 break;
1239 }
1240 }
1241 // Didn't find a call forward info for voice call.
1242 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001243 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1244 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001245 }
Hall Liu27d24262020-09-18 19:04:59 -07001246 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001247 } else {
1248 if (ar.result == null) {
1249 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1250 }
1251 if (ar.exception != null) {
1252 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1253 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001254 int errorCode = TelephonyManager
1255 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001256 if (ar.exception instanceof CommandException) {
1257 CommandException.Error error =
1258 ((CommandException) (ar.exception)).getCommandError();
1259 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001260 errorCode = TelephonyManager
1261 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001262 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001263 errorCode = TelephonyManager
1264 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001265 }
1266 }
Hall Liu27d24262020-09-18 19:04:59 -07001267 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001268 }
Shuo Qian4a594052020-01-23 11:59:30 -08001269 break;
Hall Liu27d24262020-09-18 19:04:59 -07001270 }
Shuo Qian4a594052020-01-23 11:59:30 -08001271
Hall Liu27d24262020-09-18 19:04:59 -07001272 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001273 request = (MainThreadRequest) msg.obj;
1274 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001275 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001276 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001277 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1278 request.argument).first;
1279 request.phone.setCallForwardingOption(
1280 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001281 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001282 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001283 callForwardingInfoToSet.getReason(),
1284 callForwardingInfoToSet.getNumber(),
1285 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1286 break;
Hall Liu27d24262020-09-18 19:04:59 -07001287 }
Shuo Qian4a594052020-01-23 11:59:30 -08001288
Hall Liu27d24262020-09-18 19:04:59 -07001289 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001290 ar = (AsyncResult) msg.obj;
1291 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001292 Consumer<Integer> callback =
1293 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1294 request.argument).second;
1295 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001296 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001297 int errorCode = TelephonyManager.CallForwardingInfoCallback
1298 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001299 if (ar.exception instanceof CommandException) {
1300 CommandException.Error error =
1301 ((CommandException) (ar.exception)).getCommandError();
1302 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001303 errorCode = TelephonyManager.CallForwardingInfoCallback
1304 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001305 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001306 errorCode = TelephonyManager.CallForwardingInfoCallback
1307 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001308 }
1309 }
1310 callback.accept(errorCode);
1311 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001312 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001313 }
Shuo Qian4a594052020-01-23 11:59:30 -08001314 break;
Hall Liu27d24262020-09-18 19:04:59 -07001315 }
Shuo Qian4a594052020-01-23 11:59:30 -08001316
Hall Liu27d24262020-09-18 19:04:59 -07001317 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001318 request = (MainThreadRequest) msg.obj;
1319 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1320 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1321 break;
Hall Liu27d24262020-09-18 19:04:59 -07001322 }
Shuo Qian4a594052020-01-23 11:59:30 -08001323
Hall Liu27d24262020-09-18 19:04:59 -07001324 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001325 ar = (AsyncResult) msg.obj;
1326 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001327 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001328 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001329 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001330 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001331 // Service Class is a bit mask per 3gpp 27.007.
1332 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001333 if (callForwardResults.length > 1
1334 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001335 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001336 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001337 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1338 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001339 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001340 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001341 }
1342 } else {
1343 if (ar.result == null) {
1344 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1345 }
1346 if (ar.exception != null) {
1347 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1348 }
1349 if (ar.exception instanceof CommandException) {
1350 CommandException.Error error =
1351 ((CommandException) (ar.exception)).getCommandError();
1352 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001353 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001354 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001355 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1356 callWaitingStatus =
1357 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001358 }
1359 }
1360 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001361 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001362 break;
Hall Liu27d24262020-09-18 19:04:59 -07001363 }
Shuo Qian4a594052020-01-23 11:59:30 -08001364
Hall Liu27d24262020-09-18 19:04:59 -07001365 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001366 request = (MainThreadRequest) msg.obj;
1367 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001368 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1369 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001370 break;
Hall Liu27d24262020-09-18 19:04:59 -07001371 }
Shuo Qian4a594052020-01-23 11:59:30 -08001372
Hall Liu27d24262020-09-18 19:04:59 -07001373 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001374 ar = (AsyncResult) msg.obj;
1375 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001376 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1377 Consumer<Integer> callback =
1378 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1379 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001380 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001381 if (ar.exception instanceof CommandException) {
1382 CommandException.Error error =
1383 ((CommandException) (ar.exception)).getCommandError();
1384 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1385 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001386 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1387 callback.accept(
1388 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001389 } else {
1390 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1391 }
1392 } else {
1393 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1394 }
1395 } else {
1396 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1397 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001398 }
Shuo Qian4a594052020-01-23 11:59:30 -08001399 break;
Hall Liu27d24262020-09-18 19:04:59 -07001400 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001401 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1402 ar = (AsyncResult) msg.obj;
1403 request = (MainThreadRequest) ar.userObj;
1404 CellNetworkScanResult cellScanResult;
1405 if (ar.exception == null && ar.result != null) {
1406 cellScanResult = new CellNetworkScanResult(
1407 CellNetworkScanResult.STATUS_SUCCESS,
1408 (List<OperatorInfo>) ar.result);
1409 } else {
1410 if (ar.result == null) {
1411 loge("getCellNetworkScanResults: Empty response");
1412 }
1413 if (ar.exception != null) {
1414 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1415 }
1416 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1417 if (ar.exception instanceof CommandException) {
1418 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001419 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001420 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1421 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1422 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1423 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1424 }
1425 }
1426 cellScanResult = new CellNetworkScanResult(errorCode, null);
1427 }
1428 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001429 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001430 break;
1431
1432 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1433 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001434 ManualNetworkSelectionArgument selArg =
1435 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001436 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1437 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001438 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1439 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001440 break;
1441
1442 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001443 ar = (AsyncResult) msg.obj;
1444 request = (MainThreadRequest) ar.userObj;
1445 if (ar.exception == null) {
1446 request.result = true;
1447 } else {
1448 request.result = false;
1449 loge("setNetworkSelectionModeManual " + ar.exception);
1450 }
1451 notifyRequester(request);
1452 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001453 break;
1454
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001455 case CMD_GET_MODEM_ACTIVITY_INFO:
1456 request = (MainThreadRequest) msg.obj;
1457 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001458 if (defaultPhone != null) {
1459 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001460 } else {
1461 ResultReceiver result = (ResultReceiver) request.argument;
1462 Bundle bundle = new Bundle();
1463 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001464 new ModemActivityInfo(0, 0, 0,
1465 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001466 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001467 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001468 break;
1469
Hall Liud0f208c2020-10-14 16:54:44 -07001470 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001471 ar = (AsyncResult) msg.obj;
1472 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001473 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001474 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001475 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001476 if (mLastModemActivityInfo == null) {
1477 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1478 mLastModemActivitySpecificInfo[0] =
1479 new ActivityStatsTechSpecificInfo(
1480 0,
1481 0,
1482 new int[ModemActivityInfo.getNumTxPowerLevels()],
1483 0);
1484 mLastModemActivityInfo =
1485 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1486 }
1487
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001488 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001489 // Update the last modem activity info and the result of the request.
1490 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1491 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001492 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001493 } else {
1494 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001495 }
Kai Shi917fdc62022-11-28 14:01:02 -08001496 // This is needed to decouple ret from mLastModemActivityInfo
1497 // We don't want to return mLastModemActivityInfo which is updated
1498 // inside mergeModemActivityInfo()
1499 ret = new ModemActivityInfo(
1500 mLastModemActivityInfo.getTimestampMillis(),
1501 mLastModemActivityInfo.getSleepTimeMillis(),
1502 mLastModemActivityInfo.getIdleTimeMillis(),
1503 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001504
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001505 } else {
1506 if (ar.result == null) {
1507 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001508 error = TelephonyManager.ModemActivityInfoException
1509 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001510 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001511 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001512 error = TelephonyManager.ModemActivityInfoException
1513 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001514 } else {
1515 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001516 error = TelephonyManager.ModemActivityInfoException
1517 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001518 }
1519 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001520 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001521 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001522 bundle.putParcelable(
1523 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001524 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001525 } else {
1526 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1527 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001528 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001529 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001530 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001531 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001532
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001533 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001534 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001535 CarrierRestrictionRules argument =
1536 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001537 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001538 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001539 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001540 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001541
1542 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1543 ar = (AsyncResult) msg.obj;
1544 request = (MainThreadRequest) ar.userObj;
1545 if (ar.exception == null && ar.result != null) {
1546 request.result = ar.result;
1547 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001548 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1549 if (ar.exception instanceof CommandException) {
1550 loge("setAllowedCarriers: CommandException: " + ar.exception);
1551 CommandException.Error error =
1552 ((CommandException) (ar.exception)).getCommandError();
1553 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1554 request.result =
1555 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1556 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001557 } else {
1558 loge("setAllowedCarriers: Unknown exception");
1559 }
1560 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001561 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001562 break;
1563
1564 case CMD_GET_ALLOWED_CARRIERS:
1565 request = (MainThreadRequest) msg.obj;
1566 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001567 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001568 break;
1569
1570 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1571 ar = (AsyncResult) msg.obj;
1572 request = (MainThreadRequest) ar.userObj;
1573 if (ar.exception == null && ar.result != null) {
1574 request.result = ar.result;
1575 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001576 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001577 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001578 if (ar.result == null) {
1579 loge("getAllowedCarriers: Empty response");
1580 } else if (ar.exception instanceof CommandException) {
1581 loge("getAllowedCarriers: CommandException: " +
1582 ar.exception);
1583 } else {
1584 loge("getAllowedCarriers: Unknown exception");
1585 }
1586 }
arunvoddud7401012022-12-15 16:08:12 +00001587 if (request.argument != null) {
1588 // This is for the implementation of carrierRestrictionStatus.
1589 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1590 Consumer<Integer> callback = callbackInfo.getConsumer();
1591 int callerCarrierId = callbackInfo.getCarrierId();
1592 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1593 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1594 CarrierRestrictionRules carrierRestrictionRules =
1595 (CarrierRestrictionRules) ar.result;
1596 int carrierId = -1;
1597 try {
1598 CarrierIdentifier carrierIdentifier =
1599 carrierRestrictionRules.getAllowedCarriers().get(0);
1600 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1601 carrierIdentifier);
1602 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1603 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1604 }
1605 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
1606 if (carrierId != -1 && callerCarrierId == carrierId && lockStatus
1607 == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001608 lockStatus = TelephonyManager
1609 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001610 }
1611 } else {
1612 Rlog.e(LOG_TAG,
1613 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1614 }
1615 callback.accept(lockStatus);
1616 } else {
1617 // This is for the implementation of getAllowedCarriers.
1618 notifyRequester(request);
1619 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001620 break;
1621
Nathan Haroldb3014052017-01-25 15:57:32 -08001622 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1623 ar = (AsyncResult) msg.obj;
1624 request = (MainThreadRequest) ar.userObj;
1625 if (ar.exception == null && ar.result != null) {
1626 request.result = ar.result;
1627 } else {
1628 request.result = new IllegalArgumentException(
1629 "Failed to retrieve Forbidden Plmns");
1630 if (ar.result == null) {
1631 loge("getForbiddenPlmns: Empty response");
1632 } else {
1633 loge("getForbiddenPlmns: Unknown exception");
1634 }
1635 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001636 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001637 break;
1638
1639 case CMD_GET_FORBIDDEN_PLMNS:
1640 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001641 uiccPort = getUiccPortFromRequest(request);
1642 if (uiccPort == null) {
1643 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001644 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001645 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001646 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001647 break;
1648 }
1649 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001650 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001651 if (uiccApp == null) {
1652 loge("getForbiddenPlmns() no app with specified type -- "
1653 + appType);
1654 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001655 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001656 break;
1657 } else {
1658 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1659 + " specified type -- " + appType);
1660 }
1661 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1662 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001663 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001664 break;
1665
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001666 case CMD_SWITCH_SLOTS:
1667 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001668 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001669 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001670 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001671 break;
1672
1673 case EVENT_SWITCH_SLOTS_DONE:
1674 ar = (AsyncResult) msg.obj;
1675 request = (MainThreadRequest) ar.userObj;
1676 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001677 notifyRequester(request);
1678 break;
1679 case CMD_GET_NETWORK_SELECTION_MODE:
1680 request = (MainThreadRequest) msg.obj;
1681 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1682 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1683 break;
1684
1685 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1686 ar = (AsyncResult) msg.obj;
1687 request = (MainThreadRequest) ar.userObj;
1688 if (ar.exception != null) {
1689 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1690 } else {
1691 int mode = ((int[]) ar.result)[0];
1692 if (mode == 0) {
1693 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1694 } else {
1695 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1696 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001697 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001698 notifyRequester(request);
1699 break;
1700 case CMD_GET_CDMA_ROAMING_MODE:
1701 request = (MainThreadRequest) msg.obj;
1702 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1703 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1704 break;
1705 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1706 ar = (AsyncResult) msg.obj;
1707 request = (MainThreadRequest) ar.userObj;
1708 if (ar.exception != null) {
1709 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1710 } else {
1711 request.result = ((int[]) ar.result)[0];
1712 }
1713 notifyRequester(request);
1714 break;
1715 case CMD_SET_CDMA_ROAMING_MODE:
1716 request = (MainThreadRequest) msg.obj;
1717 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1718 int mode = (int) request.argument;
1719 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1720 break;
1721 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1722 ar = (AsyncResult) msg.obj;
1723 request = (MainThreadRequest) ar.userObj;
1724 request.result = ar.exception == null;
1725 notifyRequester(request);
1726 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001727 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1728 request = (MainThreadRequest) msg.obj;
1729 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1730 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1731 break;
1732 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1733 ar = (AsyncResult) msg.obj;
1734 request = (MainThreadRequest) ar.userObj;
1735 if (ar.exception != null) {
1736 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1737 } else {
1738 request.result = ((int[]) ar.result)[0];
1739 }
1740 notifyRequester(request);
1741 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001742 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1743 request = (MainThreadRequest) msg.obj;
1744 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1745 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001746 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1747 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001748 break;
1749 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1750 ar = (AsyncResult) msg.obj;
1751 request = (MainThreadRequest) ar.userObj;
1752 request.result = ar.exception == null;
1753 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001754 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001755 case CMD_GET_ALL_CELL_INFO:
1756 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001757 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001758 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001759 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001760 case EVENT_GET_ALL_CELL_INFO_DONE:
1761 ar = (AsyncResult) msg.obj;
1762 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001763 // If a timeout occurs, the response will be null
1764 request.result = (ar.exception == null && ar.result != null)
1765 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001766 synchronized (request) {
1767 request.notifyAll();
1768 }
1769 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001770 case CMD_REQUEST_CELL_INFO_UPDATE:
1771 request = (MainThreadRequest) msg.obj;
1772 request.phone.requestCellInfoUpdate(request.workSource,
1773 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1774 break;
1775 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1776 ar = (AsyncResult) msg.obj;
1777 request = (MainThreadRequest) ar.userObj;
1778 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1779 try {
1780 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001781 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001782 cb.onError(
1783 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1784 ar.exception.getClass().getName(),
1785 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001786 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001787 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001788 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001789 } else {
1790 // use the result as returned
1791 cb.onCellInfo((List<CellInfo>) ar.result);
1792 }
1793 } catch (RemoteException re) {
1794 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1795 }
1796 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001797 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001798 request = (MainThreadRequest) msg.obj;
1799 WorkSource ws = (WorkSource) request.argument;
1800 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001801 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001802 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001803 }
1804 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001805 ar = (AsyncResult) msg.obj;
1806 request = (MainThreadRequest) ar.userObj;
1807 if (ar.exception == null) {
1808 request.result = ar.result;
1809 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001810 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001811 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001812 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001813 }
1814
1815 synchronized (request) {
1816 request.notifyAll();
1817 }
1818 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001819 }
chen xu6dac5ab2018-10-26 17:39:23 -07001820 case CMD_MODEM_REBOOT:
1821 request = (MainThreadRequest) msg.obj;
1822 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001823 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001824 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001825 case EVENT_CMD_MODEM_REBOOT_DONE:
1826 handleNullReturnEvent(msg, "rebootModem");
1827 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001828 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001829 request = (MainThreadRequest) msg.obj;
1830 boolean enable = (boolean) request.argument;
1831 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001832 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001833 PhoneConfigurationManager.getInstance()
1834 .enablePhone(request.phone, enable, onCompleted);
1835 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001836 }
Michele Berionne5e411512020-11-13 02:36:59 +00001837 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001838 ar = (AsyncResult) msg.obj;
1839 request = (MainThreadRequest) ar.userObj;
1840 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001841 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001842 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001843 if ((boolean) request.result) {
1844 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1845 updateModemStateMetrics();
1846 } else {
1847 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1848 + ar.exception);
1849 }
1850 notifyRequester(request);
1851 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001852 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001853 case CMD_GET_MODEM_STATUS:
1854 request = (MainThreadRequest) msg.obj;
1855 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1856 PhoneConfigurationManager.getInstance()
1857 .getPhoneStatusFromModem(request.phone, onCompleted);
1858 break;
1859 case EVENT_GET_MODEM_STATUS_DONE:
1860 ar = (AsyncResult) msg.obj;
1861 request = (MainThreadRequest) ar.userObj;
1862 int id = request.phone.getPhoneId();
1863 if (ar.exception == null && ar.result != null) {
1864 request.result = ar.result;
1865 //update the cache as modem status has changed
1866 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1867 (boolean) request.result);
1868 } else {
1869 // Return true if modem status cannot be retrieved. For most cases,
1870 // modem status is on. And for older version modems, GET_MODEM_STATUS
1871 // and disable modem are not supported. Modem is always on.
1872 // TODO: this should be fixed in R to support a third
1873 // status UNKNOWN b/131631629
1874 request.result = true;
1875 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1876 + ar.exception);
1877 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001878 notifyRequester(request);
1879 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001880 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1881 request = (MainThreadRequest) msg.obj;
1882 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1883 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1884 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1885 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1886 break;
1887 }
1888 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1889 ar = (AsyncResult) msg.obj;
1890 request = (MainThreadRequest) ar.userObj;
1891 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1892 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1893 args.second.accept(ar.exception == null);
1894 notifyRequester(request);
1895 break;
1896 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001897 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1898 request = (MainThreadRequest) msg.obj;
1899 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1900 Phone phone = getPhoneFromRequest(request);
1901 if (phone != null) {
1902 phone.getSystemSelectionChannels(onCompleted);
1903 } else {
1904 loge("getSystemSelectionChannels: No phone object");
1905 request.result = new ArrayList<RadioAccessSpecifier>();
1906 notifyRequester(request);
1907 }
1908 break;
1909 }
1910 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1911 ar = (AsyncResult) msg.obj;
1912 request = (MainThreadRequest) ar.userObj;
1913 if (ar.exception == null && ar.result != null) {
1914 request.result = ar.result;
1915 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001916 request.result = new IllegalStateException(
1917 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001918 if (ar.result == null) {
1919 loge("getSystemSelectionChannels: Empty response");
1920 } else {
1921 loge("getSystemSelectionChannels: Unknown exception");
1922 }
1923 }
1924 notifyRequester(request);
1925 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001926 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1927 ar = (AsyncResult) msg.obj;
1928 request = (MainThreadRequest) ar.userObj;
1929 if (ar.exception == null && ar.result != null) {
1930 request.result = ar.result;
1931 } else {
1932 request.result = -1;
1933 loge("Failed to set Forbidden Plmns");
1934 if (ar.result == null) {
1935 loge("setForbidenPlmns: Empty response");
1936 } else if (ar.exception != null) {
1937 loge("setForbiddenPlmns: Exception: " + ar.exception);
1938 request.result = -1;
1939 } else {
1940 loge("setForbiddenPlmns: Unknown exception");
1941 }
1942 }
1943 notifyRequester(request);
1944 break;
1945 case CMD_SET_FORBIDDEN_PLMNS:
1946 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001947 uiccPort = getUiccPortFromRequest(request);
1948 if (uiccPort == null) {
1949 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001950 request.result = -1;
1951 notifyRequester(request);
1952 break;
1953 }
1954 Pair<Integer, List<String>> setFplmnsArgs =
1955 (Pair<Integer, List<String>>) request.argument;
1956 appType = setFplmnsArgs.first;
1957 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001958 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001959 if (uiccApp == null) {
1960 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1961 request.result = -1;
1962 loge("Failed to get UICC App");
1963 notifyRequester(request);
1964 } else {
1965 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1966 ((SIMRecords) uiccApp.getIccRecords())
1967 .setForbiddenPlmns(onCompleted, fplmns);
1968 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001969 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001970 case CMD_ERASE_MODEM_CONFIG:
1971 request = (MainThreadRequest) msg.obj;
1972 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1973 defaultPhone.eraseModemConfig(onCompleted);
1974 break;
1975 case EVENT_ERASE_MODEM_CONFIG_DONE:
1976 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001977 break;
zoey chene02881a2019-12-30 16:11:23 +08001978
Kai Shif70f46f2021-03-03 13:59:46 -08001979 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1980 request = (MainThreadRequest) msg.obj;
1981 request.result = defaultPhone.eraseDataInSharedPreferences();
1982 notifyRequester(request);
1983 break;
1984
zoey chene02881a2019-12-30 16:11:23 +08001985 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1986 request = (MainThreadRequest) msg.obj;
1987 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1988 Pair<String, String> changed = (Pair<String, String>) request.argument;
1989 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1990 changed.first, changed.second, onCompleted);
1991 break;
1992 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1993 ar = (AsyncResult) msg.obj;
1994 request = (MainThreadRequest) ar.userObj;
1995 if (ar.exception == null) {
1996 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001997 // If the operation is successful, update the PIN storage
1998 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1999 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00002000 UiccController.getInstance().getPinStorage()
2001 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08002002 } else {
2003 request.result = msg.arg1;
2004 }
2005 notifyRequester(request);
2006 break;
2007
Michele Berionne5e411512020-11-13 02:36:59 +00002008 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08002009 request = (MainThreadRequest) msg.obj;
2010 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
2011 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2012 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2013 enabled.first, enabled.second, onCompleted);
2014 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002015 }
zoey chene02881a2019-12-30 16:11:23 +08002016 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2017 ar = (AsyncResult) msg.obj;
2018 request = (MainThreadRequest) ar.userObj;
2019 if (ar.exception == null) {
2020 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002021 // If the operation is successful, update the PIN storage
2022 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2023 int phoneId = getPhoneFromRequest(request).getPhoneId();
2024 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002025 UiccController.getInstance().getPinStorage()
2026 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002027 } else {
2028 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2029 }
zoey chene02881a2019-12-30 16:11:23 +08002030 } else {
2031 request.result = msg.arg1;
2032 }
Michele Berionne5e411512020-11-13 02:36:59 +00002033
2034
zoey chene02881a2019-12-30 16:11:23 +08002035 notifyRequester(request);
2036 break;
2037
Peter Wangdafb9ac2020-01-15 14:13:38 -08002038 case MSG_NOTIFY_USER_ACTIVITY:
2039 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002040 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002041 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2042 getDefaultPhone().getContext().sendBroadcastAsUser(
2043 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2044 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002045
2046 case CMD_SET_DATA_THROTTLING: {
2047 request = (MainThreadRequest) msg.obj;
2048 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2049 DataThrottlingRequest dataThrottlingRequest =
2050 (DataThrottlingRequest) request.argument;
2051 Phone phone = getPhoneFromRequest(request);
2052 if (phone != null) {
2053 phone.setDataThrottling(onCompleted,
2054 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2055 dataThrottlingRequest.getCompletionDurationMillis());
2056 } else {
2057 loge("setDataThrottling: No phone object");
2058 request.result =
2059 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2060 notifyRequester(request);
2061 }
2062
2063 break;
2064 }
2065 case EVENT_SET_DATA_THROTTLING_DONE:
2066 ar = (AsyncResult) msg.obj;
2067 request = (MainThreadRequest) ar.userObj;
2068
2069 if (ar.exception == null) {
2070 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2071 } else if (ar.exception instanceof CommandException) {
2072 loge("setDataThrottling: CommandException: " + ar.exception);
2073 CommandException.Error error =
2074 ((CommandException) (ar.exception)).getCommandError();
2075
2076 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2077 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002078 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002079 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2080 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002081 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2082 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002083 } else {
2084 request.result =
2085 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2086 }
2087 } else {
2088 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2089 }
2090 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2091 notifyRequester(request);
2092 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002093
2094 case CMD_SET_SIM_POWER: {
2095 request = (MainThreadRequest) msg.obj;
2096 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2097 request = (MainThreadRequest) msg.obj;
2098 int stateToSet =
2099 ((Pair<Integer, IIntegerConsumer>)
2100 request.argument).first;
2101 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2102 break;
2103 }
2104 case EVENT_SET_SIM_POWER_DONE: {
2105 ar = (AsyncResult) msg.obj;
2106 request = (MainThreadRequest) ar.userObj;
2107 IIntegerConsumer callback =
2108 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2109 if (ar.exception != null) {
2110 loge("setSimPower exception: " + ar.exception);
2111 int errorCode = TelephonyManager.CallForwardingInfoCallback
2112 .RESULT_ERROR_UNKNOWN;
2113 if (ar.exception instanceof CommandException) {
2114 CommandException.Error error =
2115 ((CommandException) (ar.exception)).getCommandError();
2116 if (error == CommandException.Error.SIM_ERR) {
2117 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2118 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2119 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2120 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2121 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2122 } else {
2123 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2124 }
2125 }
2126 try {
2127 callback.accept(errorCode);
2128 } catch (RemoteException e) {
2129 // Ignore if the remote process is no longer available to call back.
2130 Log.w(LOG_TAG, "setSimPower: callback not available.");
2131 }
2132 } else {
2133 try {
2134 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2135 } catch (RemoteException e) {
2136 // Ignore if the remote process is no longer available to call back.
2137 Log.w(LOG_TAG, "setSimPower: callback not available.");
2138 }
2139 }
2140 break;
2141 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002142 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2143 request = (MainThreadRequest) msg.obj;
2144
2145 final Phone phone = getPhoneFromRequest(request);
2146 if (phone == null || phone.getServiceStateTracker() == null) {
2147 request.result = new IllegalStateException("Phone or SST is null");
2148 notifyRequester(request);
2149 break;
2150 }
2151
2152 Pair<Integer, SignalStrengthUpdateRequest> pair =
2153 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2154 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2155 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002156 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002157 request.subId, pair.first /*callingUid*/,
2158 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002159 break;
2160 }
2161 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2162 ar = (AsyncResult) msg.obj;
2163 request = (MainThreadRequest) ar.userObj;
2164 // request.result will be the exception of ar if present, true otherwise.
2165 // Be cautious not to leave result null which will wait() forever
2166 request.result = ar.exception != null ? ar.exception : true;
2167 notifyRequester(request);
2168 break;
2169 }
2170 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2171 request = (MainThreadRequest) msg.obj;
2172
2173 Phone phone = getPhoneFromRequest(request);
2174 if (phone == null || phone.getServiceStateTracker() == null) {
2175 request.result = new IllegalStateException("Phone or SST is null");
2176 notifyRequester(request);
2177 break;
2178 }
2179
2180 Pair<Integer, SignalStrengthUpdateRequest> pair =
2181 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2182 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2183 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002184 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002185 request.subId, pair.first /*callingUid*/,
2186 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002187 break;
2188 }
2189 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2190 ar = (AsyncResult) msg.obj;
2191 request = (MainThreadRequest) ar.userObj;
2192 request.result = ar.exception != null ? ar.exception : true;
2193 notifyRequester(request);
2194 break;
2195 }
Jordan Liu109698e2020-11-24 14:50:34 -08002196
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002197 case CMD_GET_SLICING_CONFIG: {
2198 request = (MainThreadRequest) msg.obj;
2199 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2200 request.phone.getSlicingConfig(onCompleted);
2201 break;
2202 }
2203 case EVENT_GET_SLICING_CONFIG_DONE: {
2204 ar = (AsyncResult) msg.obj;
2205 request = (MainThreadRequest) ar.userObj;
2206 ResultReceiver result = (ResultReceiver) request.argument;
2207
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002208 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002209 Bundle bundle = new Bundle();
2210 int resultCode = 0;
2211 if (ar.exception != null) {
2212 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2213 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002214 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002215 } else if (ar.result == null) {
2216 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002217 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002218 } else {
2219 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002220 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2221 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002222 }
2223
2224 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002225 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002226 }
2227 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2228 result.send(resultCode, bundle);
2229 notifyRequester(request);
2230 break;
2231 }
2232
Sarah Chin71b3a852022-09-28 15:54:19 -07002233 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002234 request = (MainThreadRequest) msg.obj;
2235 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002236 PurchasePremiumCapabilityArgument arg =
2237 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chincc5446f2023-10-23 17:57:19 -07002238 SlicePurchaseController.getInstance(request.phone, mFeatureFlags)
2239 .purchasePremiumCapability(arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002240 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002241 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002242
Sarah Chin71b3a852022-09-28 15:54:19 -07002243 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002244 ar = (AsyncResult) msg.obj;
2245 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002246 PurchasePremiumCapabilityArgument arg =
2247 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002248 try {
2249 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002250 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002251 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002252 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chinff8b1802023-04-11 14:22:14 -07002253 + ", result="
Sarah Chin2ec39f62022-08-31 17:03:26 -07002254 + TelephonyManager.convertPurchaseResultToString(result));
2255 } catch (RemoteException e) {
2256 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002257 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002258 + " failed: " + e;
2259 if (DBG) log(logStr);
2260 AnomalyReporter.reportAnomaly(
2261 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2262 }
2263 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002264 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002265
Michele Berionne5e411512020-11-13 02:36:59 +00002266 case CMD_PREPARE_UNATTENDED_REBOOT:
2267 request = (MainThreadRequest) msg.obj;
2268 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002269 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002270 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002271 notifyRequester(request);
2272 break;
2273
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002274 default:
2275 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2276 break;
2277 }
2278 }
Jake Hambye994d462014-02-03 13:10:13 -08002279
Pengquan Menga1bb6272018-09-06 09:59:22 -07002280 private void notifyRequester(MainThreadRequest request) {
2281 synchronized (request) {
2282 request.notifyAll();
2283 }
2284 }
2285
Jake Hambye994d462014-02-03 13:10:13 -08002286 private void handleNullReturnEvent(Message msg, String command) {
2287 AsyncResult ar = (AsyncResult) msg.obj;
2288 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2289 if (ar.exception == null) {
2290 request.result = true;
2291 } else {
2292 request.result = false;
2293 if (ar.exception instanceof CommandException) {
2294 loge(command + ": CommandException: " + ar.exception);
2295 } else {
2296 loge(command + ": Unknown exception");
2297 }
2298 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002299 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002300 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002301 }
2302
2303 /**
2304 * Posts the specified command to be executed on the main thread,
2305 * waits for the request to complete, and returns the result.
2306 * @see #sendRequestAsync
2307 */
2308 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002309 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2310 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002311 }
2312
2313 /**
2314 * Posts the specified command to be executed on the main thread,
2315 * waits for the request to complete, and returns the result.
2316 * @see #sendRequestAsync
2317 */
2318 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2319 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002320 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002321 }
2322
2323 /**
2324 * Posts the specified command to be executed on the main thread,
2325 * waits for the request to complete, and returns the result.
2326 * @see #sendRequestAsync
2327 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002328 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002329 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2330 }
2331
2332 /**
2333 * Posts the specified command to be executed on the main thread,
2334 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2335 * if not timeout or null otherwise.
2336 * @see #sendRequestAsync
2337 */
2338 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2339 long timeoutInMs) {
2340 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002341 }
2342
2343 /**
2344 * Posts the specified command to be executed on the main thread,
2345 * waits for the request to complete, and returns the result.
2346 * @see #sendRequestAsync
2347 */
Nathan Harold92bed182018-10-12 18:16:49 -07002348 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002349 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002350 }
2351
2352 /**
2353 * Posts the specified command to be executed on the main thread,
2354 * waits for the request to complete, and returns the result.
2355 * @see #sendRequestAsync
2356 */
2357 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002358 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2359 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002360 }
2361
2362 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002363 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2364 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2365 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002366 * @see #sendRequestAsync
2367 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002368 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2369 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002370 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2371 throw new RuntimeException("This method will deadlock if called from the main thread.");
2372 }
2373
Nathan Harold92bed182018-10-12 18:16:49 -07002374 MainThreadRequest request = null;
2375 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2376 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2377 } else if (phone != null) {
2378 request = new MainThreadRequest(argument, phone, workSource);
2379 } else {
2380 request = new MainThreadRequest(argument, subId, workSource);
2381 }
2382
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002383 Message msg = mMainThreadHandler.obtainMessage(command, request);
2384 msg.sendToTarget();
2385
Rambo Wang0f050d82021-02-12 11:43:36 -08002386
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002387 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002388 if (timeoutInMs >= 0) {
2389 // Wait for at least timeoutInMs before returning null request result
2390 long now = SystemClock.elapsedRealtime();
2391 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002392 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002393 try {
2394 request.wait(deadline - now);
2395 } catch (InterruptedException e) {
2396 // Do nothing, go back and check if request is completed or timeout
2397 } finally {
2398 now = SystemClock.elapsedRealtime();
2399 }
2400 }
2401 } else {
2402 // Wait for the request to complete
2403 while (request.result == null) {
2404 try {
2405 request.wait();
2406 } catch (InterruptedException e) {
2407 // Do nothing, go back and wait until the request is complete
2408 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002409 }
2410 }
2411 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002412 if (request.result == null) {
2413 Log.wtf(LOG_TAG,
2414 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2415 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002416 return request.result;
2417 }
2418
2419 /**
2420 * Asynchronous ("fire and forget") version of sendRequest():
2421 * Posts the specified command to be executed on the main thread, and
2422 * returns immediately.
2423 * @see #sendRequest
2424 */
2425 private void sendRequestAsync(int command) {
2426 mMainThreadHandler.sendEmptyMessage(command);
2427 }
2428
2429 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002430 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002431 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002432 */
2433 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002434 sendRequestAsync(command, argument, null, null);
2435 }
2436
2437 /**
2438 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2439 * @see {@link #sendRequest(int,Object)}
2440 */
2441 private void sendRequestAsync(
2442 int command, Object argument, Phone phone, WorkSource workSource) {
2443 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002444 Message msg = mMainThreadHandler.obtainMessage(command, request);
2445 msg.sendToTarget();
2446 }
2447
2448 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002449 * Initialize the singleton PhoneInterfaceManager instance.
2450 * This is only done once, at startup, from PhoneApp.onCreate().
2451 */
Sarah Chincc5446f2023-10-23 17:57:19 -07002452 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002453 synchronized (PhoneInterfaceManager.class) {
2454 if (sInstance == null) {
Sarah Chincc5446f2023-10-23 17:57:19 -07002455 sInstance = new PhoneInterfaceManager(app, featureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002456 } else {
2457 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2458 }
2459 return sInstance;
2460 }
2461 }
2462
2463 /** Private constructor; @see init() */
Sarah Chincc5446f2023-10-23 17:57:19 -07002464 private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002465 mApp = app;
Sarah Chincc5446f2023-10-23 17:57:19 -07002466 mFeatureFlags = featureFlags;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002467 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002468 mImsResolver = ImsResolver.getInstance();
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +00002469 mSatelliteController = SatelliteController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002470 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002471 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2472 mMainThreadHandler = new MainThreadHandler();
Sarah Chin4beb2b72023-02-14 14:47:54 -08002473 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002474 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002475 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002476 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002477 mNotifyUserActivity = new AtomicBoolean(false);
joonhunshin4ac60942023-11-15 15:23:39 +00002478 mPackageManager = app.getPackageManager();
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -08002479 mSatelliteAccessController = SatelliteAccessController.getOrCreateInstance(
2480 getDefaultPhone().getContext(), featureFlags);
Tyler Gunn64144d92022-03-17 14:16:41 -07002481 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002482 publish();
arunvoddud7401012022-12-15 16:08:12 +00002483 CarrierAllowListInfo.loadInstance(mApp);
Hyosun Kim240214a2023-11-02 13:30:15 +00002484
2485 // Create the SatelliteEntitlementController singleton, for using the get the
2486 // entitlementStatus for satellite service.
2487 SatelliteEntitlementController.make(mApp, mFeatureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002488 }
2489
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002490 @VisibleForTesting
2491 public SharedPreferences getSharedPreferences() {
2492 return mTelephonySharedPreferences;
2493 }
2494
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002495 /**
2496 * Get the default phone for this device.
2497 */
2498 @VisibleForTesting
2499 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002500 Phone thePhone = getPhone(getDefaultSubscription());
2501 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2502 }
2503
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002504 private void publish() {
2505 if (DBG) log("publish: " + this);
2506
Peter Wangc035ce42020-01-08 21:00:22 -08002507 TelephonyFrameworkInitializer
2508 .getTelephonyServiceManager()
2509 .getTelephonyServiceRegisterer()
2510 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002511 }
2512
Stuart Scott584921c2015-01-15 17:10:34 -08002513 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002514 if (request.phone != null) {
2515 return request.phone;
2516 } else {
2517 return getPhoneFromSubId(request.subId);
2518 }
2519 }
2520
2521 private Phone getPhoneFromSubId(int subId) {
2522 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2523 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002524 }
2525
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002526 /**
2527 * Get phone object associated with a subscription.
2528 * Return default phone if phone object associated with subscription is null
2529 * @param subId - subscriptionId
2530 * @return phone object associated with a subscription or default phone if null.
2531 */
Ling Mac28f0212023-03-24 16:07:15 -07002532 private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) {
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002533 Phone phone = getPhoneFromSubId(subId);
2534 if (phone == null) {
Ling Mac28f0212023-03-24 16:07:15 -07002535 loge("Called with invalid subId: " + subId + ". Retrying with default phone.");
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002536 phone = getDefaultPhone();
2537 }
2538 return phone;
2539 }
2540
Rambo Wange53e07d2022-05-10 13:01:13 -07002541 @Nullable
2542 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002543 Phone phone = getPhoneFromRequest(request);
2544 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002545 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002546 }
2547
Ling Mac28f0212023-03-24 16:07:15 -07002548 /**
2549 * @param subId The sub Id that associates the phone. If the device has no active SIM, passing
2550 * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <=
2551 * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}.
2552 * @return The Phone associated the sub Id
2553 */
2554 private @Nullable Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002555 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002556 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002557
Kai Shif70f46f2021-03-03 13:59:46 -08002558 private void sendEraseModemConfig(@NonNull Phone phone) {
2559 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2560 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2561 }
2562
2563 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2564 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2565 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002566 }
2567
Peter Wang44b186e2020-01-13 23:33:09 -08002568 private boolean isImsAvailableOnDevice() {
2569 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2570 if (pm == null) {
2571 // For some reason package manger is not available.. This will fail internally anyway,
2572 // so do not throw error and allow.
2573 return true;
2574 }
2575 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2576 }
2577
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002578 public void dial(String number) {
joonhunshin4ac60942023-11-15 15:23:39 +00002579 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2580 PackageManager.FEATURE_TELEPHONY_CALLING, "dial");
2581
Wink Savilleadd7cc52014-09-08 14:23:09 -07002582 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002583 }
2584
Wink Savilleb564aae2014-10-23 10:18:09 -07002585 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002586 if (DBG) log("dial: " + number);
2587 // No permission check needed here: This is just a wrapper around the
2588 // ACTION_DIAL intent, which is available to any app since it puts up
2589 // the UI before it does anything.
2590
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002591 final long identity = Binder.clearCallingIdentity();
2592 try {
2593 String url = createTelUrl(number);
2594 if (url == null) {
2595 return;
2596 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002597
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002598 // PENDING: should we just silently fail if phone is offhook or ringing?
2599 PhoneConstants.State state = mCM.getState(subId);
2600 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2601 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2602 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2603 mApp.startActivity(intent);
2604 }
2605 } finally {
2606 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002607 }
2608 }
2609
2610 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002611 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002612 }
2613
Wink Savilleb564aae2014-10-23 10:18:09 -07002614 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002615 if (DBG) log("call: " + number);
2616
2617 // This is just a wrapper around the ACTION_CALL intent, but we still
2618 // need to do a permission check since we're calling startActivity()
2619 // from the context of the phone app.
2620 enforceCallPermission();
2621
Jordan Liu1617b712019-07-10 15:06:26 -07002622 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002623 != AppOpsManager.MODE_ALLOWED) {
2624 return;
2625 }
2626
joonhunshin4ac60942023-11-15 15:23:39 +00002627 enforceTelephonyFeatureWithException(callingPackage,
2628 PackageManager.FEATURE_TELEPHONY_CALLING, "call");
2629
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002630 final long identity = Binder.clearCallingIdentity();
2631 try {
2632 String url = createTelUrl(number);
2633 if (url == null) {
2634 return;
2635 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002636
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002637 boolean isValid = false;
2638 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2639 if (slist != null) {
2640 for (SubscriptionInfo subInfoRecord : slist) {
2641 if (subInfoRecord.getSubscriptionId() == subId) {
2642 isValid = true;
2643 break;
2644 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002645 }
Wink Saville08874612014-08-31 19:19:58 -07002646 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002647 if (!isValid) {
2648 return;
2649 }
Wink Saville08874612014-08-31 19:19:58 -07002650
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002651 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2652 intent.putExtra(SUBSCRIPTION_KEY, subId);
2653 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2654 mApp.startActivity(intent);
2655 } finally {
2656 Binder.restoreCallingIdentity(identity);
2657 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002658 }
2659
Wink Savilleb564aae2014-10-23 10:18:09 -07002660 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002661 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002662 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2663 }
2664
Wink Savilleb564aae2014-10-23 10:18:09 -07002665 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002666 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002667 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2668 }
2669
Wink Savilleb564aae2014-10-23 10:18:09 -07002670 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002671 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002672
joonhunshin4ac60942023-11-15 15:23:39 +00002673 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2674 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
2675 "supplyPinReportResultForSubscriber");
2676
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002677 final long identity = Binder.clearCallingIdentity();
2678 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002679 Phone phone = getPhone(subId);
2680 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002681 checkSimPin.start();
2682 return checkSimPin.unlockSim(null, pin);
2683 } finally {
2684 Binder.restoreCallingIdentity(identity);
2685 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002686 }
2687
Wink Savilleb564aae2014-10-23 10:18:09 -07002688 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002689 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002690
joonhunshin4ac60942023-11-15 15:23:39 +00002691 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2692 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "supplyPukForSubscriber");
2693
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002694 final long identity = Binder.clearCallingIdentity();
2695 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002696 Phone phone = getPhone(subId);
2697 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002698 checkSimPuk.start();
2699 return checkSimPuk.unlockSim(puk, pin);
2700 } finally {
2701 Binder.restoreCallingIdentity(identity);
2702 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002703 }
2704
2705 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002706 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002707 * a synchronous one.
2708 */
2709 private static class UnlockSim extends Thread {
2710
2711 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002712 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002713
2714 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002715 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2716 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002717
2718 // For replies from SimCard interface
2719 private Handler mHandler;
2720
2721 // For async handler to identify request type
2722 private static final int SUPPLY_PIN_COMPLETE = 100;
2723
Michele Berionne5e411512020-11-13 02:36:59 +00002724 UnlockSim(int phoneId, IccCard simCard) {
2725 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002726 mSimCard = simCard;
2727 }
2728
2729 @Override
2730 public void run() {
2731 Looper.prepare();
2732 synchronized (UnlockSim.this) {
2733 mHandler = new Handler() {
2734 @Override
2735 public void handleMessage(Message msg) {
2736 AsyncResult ar = (AsyncResult) msg.obj;
2737 switch (msg.what) {
2738 case SUPPLY_PIN_COMPLETE:
2739 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2740 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002741 mRetryCount = msg.arg1;
2742 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002743 CommandException.Error error = null;
2744 if (ar.exception instanceof CommandException) {
2745 error = ((CommandException) (ar.exception))
2746 .getCommandError();
2747 }
2748 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07002749 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002750 } else if (error == CommandException.Error.ABORTED) {
2751 /* When UiccCardApp dispose, handle message and return
2752 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08002753 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002754 } else {
2755 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2756 }
2757 } else {
2758 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2759 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002760 mDone = true;
2761 UnlockSim.this.notifyAll();
2762 }
2763 break;
2764 }
2765 }
2766 };
2767 UnlockSim.this.notifyAll();
2768 }
2769 Looper.loop();
2770 }
2771
2772 /*
2773 * Use PIN or PUK to unlock SIM card
2774 *
2775 * If PUK is null, unlock SIM card with PIN
2776 *
2777 * If PUK is not null, unlock SIM card with PUK and set PIN code
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302778 *
2779 * Besides, since it is reused in class level, the thread's looper will be stopped to avoid
2780 * its thread leak.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002781 */
Wink Saville9de0f752013-10-22 19:04:03 -07002782 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002783
2784 while (mHandler == null) {
2785 try {
2786 wait();
2787 } catch (InterruptedException e) {
2788 Thread.currentThread().interrupt();
2789 }
2790 }
2791 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2792
2793 if (puk == null) {
2794 mSimCard.supplyPin(pin, callback);
2795 } else {
2796 mSimCard.supplyPuk(puk, pin, callback);
2797 }
2798
2799 while (!mDone) {
2800 try {
2801 Log.d(LOG_TAG, "wait for done");
2802 wait();
2803 } catch (InterruptedException e) {
2804 // Restore the interrupted status
2805 Thread.currentThread().interrupt();
2806 }
2807 }
2808 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002809 int[] resultArray = new int[2];
2810 resultArray[0] = mResult;
2811 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002812
2813 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002814 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002815 }
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302816 // This instance is no longer reused, so quit its thread's looper.
2817 mHandler.getLooper().quitSafely();
Michele Berionne5e411512020-11-13 02:36:59 +00002818
Wink Saville9de0f752013-10-22 19:04:03 -07002819 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002820 }
2821 }
2822
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002823 /**
2824 * This method has been removed due to privacy and stability concerns.
2825 */
2826 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002827 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002828 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2829 return;
Wink Saville36469e72014-06-11 15:17:00 -07002830 }
2831
Nathan Harold1f889d82020-06-04 17:05:26 -07002832 @Override
2833 public void updateServiceLocationWithPackageName(String callingPackage) {
2834 mApp.getSystemService(AppOpsManager.class)
2835 .checkPackage(Binder.getCallingUid(), callingPackage);
2836
Nathan Haroldf096d982020-11-18 17:18:06 -08002837 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002838 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2839 // Callers targeting S have no business invoking this method.
2840 return;
2841 }
2842
2843 LocationAccessPolicy.LocationPermissionResult locationResult =
2844 LocationAccessPolicy.checkLocationPermission(mApp,
2845 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2846 .setCallingPackage(callingPackage)
2847 .setCallingFeatureId(null)
2848 .setCallingPid(Binder.getCallingPid())
2849 .setCallingUid(Binder.getCallingUid())
2850 .setMethod("updateServiceLocation")
2851 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2852 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2853 .build());
2854 // Apps that lack location permission have no business calling this method;
2855 // however, because no permission was declared in the public API, denials must
2856 // all be "soft".
2857 switch (locationResult) {
2858 case DENIED_HARD: /* fall through */
2859 case DENIED_SOFT:
2860 return;
2861 }
2862
2863 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002864 final long identity = Binder.clearCallingIdentity();
2865 try {
Ling Mac28f0212023-03-24 16:07:15 -07002866 getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002867 } finally {
2868 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002869 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002870 }
2871
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002872 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002873 @Override
2874 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002875 return isRadioOnWithFeature(callingPackage, null);
2876 }
2877
2878
2879 @Override
2880 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2881 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2882 callingFeatureId);
2883 }
2884
2885 @Deprecated
2886 @Override
2887 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2888 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002889 }
2890
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002891 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002892 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2893 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002894 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002895 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002896 return false;
2897 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002898
joonhunshin4ac60942023-11-15 15:23:39 +00002899 enforceTelephonyFeatureWithException(callingPackage,
2900 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isRadioOnWithFeature");
2901
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002902 final long identity = Binder.clearCallingIdentity();
2903 try {
2904 return isRadioOnForSubscriber(subId);
2905 } finally {
2906 Binder.restoreCallingIdentity(identity);
2907 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002908 }
2909
2910 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002911 final long identity = Binder.clearCallingIdentity();
2912 try {
2913 final Phone phone = getPhone(subId);
2914 if (phone != null) {
2915 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2916 } else {
2917 return false;
2918 }
2919 } finally {
2920 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002921 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002922 }
2923
2924 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002925 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002926 }
Wink Saville36469e72014-06-11 15:17:00 -07002927
Wink Savilleb564aae2014-10-23 10:18:09 -07002928 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002929 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002930
joonhunshin4ac60942023-11-15 15:23:39 +00002931 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2932 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "toggleRadioOnOffForSubscriber");
2933
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002934 final long identity = Binder.clearCallingIdentity();
2935 try {
2936 final Phone phone = getPhone(subId);
2937 if (phone != null) {
2938 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2939 }
2940 } finally {
2941 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002942 }
Wink Saville36469e72014-06-11 15:17:00 -07002943 }
2944
2945 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002946 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002947 }
2948
Wink Savilleb564aae2014-10-23 10:18:09 -07002949 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002950 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002951
2952 final long identity = Binder.clearCallingIdentity();
2953 try {
2954 final Phone phone = getPhone(subId);
2955 if (phone == null) {
2956 return false;
2957 }
2958 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2959 toggleRadioOnOffForSubscriber(subId);
2960 }
2961 return true;
2962 } finally {
2963 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002964 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002965 }
Wink Saville36469e72014-06-11 15:17:00 -07002966
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002967 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002968 enforceReadPrivilegedPermission("needMobileRadioShutdown");
joonhunshin4ac60942023-11-15 15:23:39 +00002969
2970 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2971 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needMobileRadioShutdown");
2972
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002973 /*
2974 * If any of the Radios are available, it will need to be
2975 * shutdown. So return true if any Radio is available.
2976 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002977 final long identity = Binder.clearCallingIdentity();
2978 try {
2979 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2980 Phone phone = PhoneFactory.getPhone(i);
2981 if (phone != null && phone.isRadioAvailable()) return true;
2982 }
2983 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2984 return false;
2985 } finally {
2986 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002987 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002988 }
2989
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002990 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002991 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002992 enforceModifyPermission();
2993
joonhunshin4ac60942023-11-15 15:23:39 +00002994 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2995 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "shutdownMobileRadios");
2996
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002997 final long identity = Binder.clearCallingIdentity();
2998 try {
2999 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3000 logv("Shutting down Phone " + i);
3001 shutdownRadioUsingPhoneId(i);
3002 }
3003 } finally {
3004 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003005 }
3006 }
3007
3008 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003009 Phone phone = PhoneFactory.getPhone(phoneId);
3010 if (phone != null && phone.isRadioAvailable()) {
3011 phone.shutdownRadio();
3012 }
3013 }
3014
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003015 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07003016 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003017
Ling Ma83dc5ea2023-01-12 15:06:04 -08003018 if (!turnOn) {
3019 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
3020 }
3021
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003022 final long identity = Binder.clearCallingIdentity();
3023 try {
3024 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
3025 if (defaultPhone != null) {
3026 defaultPhone.setRadioPower(turnOn);
3027 return true;
3028 } else {
3029 loge("There's no default phone.");
3030 return false;
3031 }
3032 } finally {
3033 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07003034 }
Wink Saville36469e72014-06-11 15:17:00 -07003035 }
3036
Wink Savilleb564aae2014-10-23 10:18:09 -07003037 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003038 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003039
Ling Ma83dc5ea2023-01-12 15:06:04 -08003040 if (!turnOn) {
3041 log("setRadioPowerForSubscriber off: subId=" + subId
3042 + ",callingPackage=" + getCurrentPackageName());
3043 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003044 final long identity = Binder.clearCallingIdentity();
3045 try {
3046 final Phone phone = getPhone(subId);
3047 if (phone != null) {
3048 phone.setRadioPower(turnOn);
3049 return true;
3050 } else {
3051 return false;
3052 }
3053 } finally {
3054 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003055 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003056 }
3057
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003058 /**
3059 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3060 * no reason to power it off. When any of the voters want to power it off, it will be turned
3061 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3062 * powering it off, and these radio off votes will be cleared.
3063 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3064 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3065 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3066 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3067 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3068 * check its vote.
3069 *
3070 * @param subId The subscription ID.
3071 * @param reason The reason for powering off radio.
3072 * @return true on success and false on failure.
3073 */
3074 public boolean requestRadioPowerOffForReason(int subId,
3075 @TelephonyManager.RadioPowerReason int reason) {
3076 enforceModifyPermission();
3077
joonhunshin4ac60942023-11-15 15:23:39 +00003078 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3079 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestRadioPowerOffForReason");
3080
Ling Ma83dc5ea2023-01-12 15:06:04 -08003081 log("requestRadioPowerOffForReason: subId=" + subId
3082 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003083 final long identity = Binder.clearCallingIdentity();
3084 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003085 boolean result = false;
3086 for (Phone phone : PhoneFactory.getPhones()) {
3087 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003088 phone.setRadioPowerForReason(false, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003089 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003090 if (!result) {
3091 loge("requestRadioPowerOffForReason: no phone exists");
3092 }
3093 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003094 } finally {
3095 Binder.restoreCallingIdentity(identity);
3096 }
3097 }
3098
3099 /**
3100 * Remove the vote on powering off the radio for a reason, as requested by
3101 * {@link requestRadioPowerOffForReason}.
3102 *
3103 * @param subId The subscription ID.
3104 * @param reason The reason for powering off radio.
3105 * @return true on success and false on failure.
3106 */
3107 public boolean clearRadioPowerOffForReason(int subId,
3108 @TelephonyManager.RadioPowerReason int reason) {
3109 enforceModifyPermission();
3110
joonhunshin4ac60942023-11-15 15:23:39 +00003111 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3112 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearRadioPowerOffForReason");
3113
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003114 final long identity = Binder.clearCallingIdentity();
3115 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003116 boolean result = false;
3117 for (Phone phone : PhoneFactory.getPhones()) {
3118 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003119 phone.setRadioPowerForReason(true, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003120 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003121 if (!result) {
3122 loge("clearRadioPowerOffForReason: no phone exists");
3123 }
3124 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003125 } finally {
3126 Binder.restoreCallingIdentity(identity);
3127 }
3128 }
3129
3130 /**
3131 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3132 *
3133 * @param subId The subscription ID.
3134 * @param callingPackage The package making the call.
3135 * @param callingFeatureId The feature in the package.
3136 * @return List of reasons for powering off radio.
3137 */
3138 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3139 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3140
joonhunshin4ac60942023-11-15 15:23:39 +00003141 enforceTelephonyFeatureWithException(callingPackage,
3142 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerOffReasons");
3143
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003144 final long identity = Binder.clearCallingIdentity();
3145 List result = new ArrayList();
3146 try {
3147 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3148 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3149 return result;
3150 }
3151
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003152 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003153 if (phone != null) {
3154 result.addAll(phone.getRadioPowerOffReasons());
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003155 } else {
3156 loge("getRadioPowerOffReasons: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003157 }
3158 } finally {
3159 Binder.restoreCallingIdentity(identity);
3160 }
3161 return result;
3162 }
3163
Wink Saville36469e72014-06-11 15:17:00 -07003164 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003165 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003166 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003167 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003168
joonhunshin4ac60942023-11-15 15:23:39 +00003169 enforceTelephonyFeatureWithException(callingPackage,
3170 PackageManager.FEATURE_TELEPHONY_DATA, "enableDataConnectivity");
3171
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003172 final long identity = Binder.clearCallingIdentity();
3173 try {
Jack Yu285100e2022-12-02 22:48:35 -08003174 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003175 final Phone phone = getPhone(subId);
3176 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003177 phone.getDataSettingsManager().setDataEnabled(
3178 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003179 return true;
3180 } else {
3181 return false;
3182 }
3183 } finally {
3184 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003185 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003186 }
3187
Wink Saville36469e72014-06-11 15:17:00 -07003188 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003189 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003190 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003191 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003192
joonhunshin4ac60942023-11-15 15:23:39 +00003193 enforceTelephonyFeatureWithException(callingPackage,
3194 PackageManager.FEATURE_TELEPHONY_DATA, "disableDataConnectivity");
3195
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003196 final long identity = Binder.clearCallingIdentity();
3197 try {
Jack Yu285100e2022-12-02 22:48:35 -08003198 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003199 final Phone phone = getPhone(subId);
3200 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003201 phone.getDataSettingsManager().setDataEnabled(
3202 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003203 return true;
3204 } else {
3205 return false;
3206 }
3207 } finally {
3208 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003209 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003210 }
3211
Sanket Padawe356d7632015-06-22 14:03:32 -07003212 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003213 public boolean isDataConnectivityPossible(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003214 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3215 PackageManager.FEATURE_TELEPHONY_DATA, "isDataConnectivityPossible");
3216
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003217 final long identity = Binder.clearCallingIdentity();
3218 try {
3219 final Phone phone = getPhone(subId);
3220 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003221 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003222 } else {
3223 return false;
3224 }
3225 } finally {
3226 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003227 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003228 }
3229
3230 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003231 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003232 }
3233
pkanwarae03a6b2016-11-06 20:37:09 -08003234 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003235 enforceCallPermission();
3236
joonhunshin4ac60942023-11-15 15:23:39 +00003237 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3238 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "handleUssdRequest");
3239
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003240 final long identity = Binder.clearCallingIdentity();
3241 try {
3242 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3243 return;
3244 }
3245 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3246 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3247 } finally {
3248 Binder.restoreCallingIdentity(identity);
3249 }
pkanwar32d516d2016-10-14 19:37:38 -07003250 };
3251
Wink Savilleb564aae2014-10-23 10:18:09 -07003252 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003253 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003254
joonhunshin4ac60942023-11-15 15:23:39 +00003255 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3256 PackageManager.FEATURE_TELEPHONY_CALLING, "handlePinMmiForSubscriber");
3257
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003258 final long identity = Binder.clearCallingIdentity();
3259 try {
3260 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3261 return false;
3262 }
3263 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3264 } finally {
3265 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003266 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003267 }
3268
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003269 /**
3270 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3271 * tag on getCallState Binder call.
3272 */
3273 @Deprecated
3274 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003275 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003276 if (CompatChanges.isChangeEnabled(
3277 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3278 Binder.getCallingUid())) {
3279 // Do not allow this API to be called on API version 31+, it should only be
3280 // called on old apps using this Binder call directly.
3281 throw new SecurityException("This method can only be used for applications "
3282 + "targeting API version 30 or less.");
3283 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003284 final long identity = Binder.clearCallingIdentity();
3285 try {
Ling Mac28f0212023-03-24 16:07:15 -07003286 Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription());
3287 return PhoneConstantConversions.convertCallState(phone.getState());
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003288 } finally {
3289 Binder.restoreCallingIdentity(identity);
3290 }
3291 }
3292
3293 @Override
3294 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3295 if (CompatChanges.isChangeEnabled(
3296 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3297 Binder.getCallingUid())) {
3298 // Check READ_PHONE_STATE for API version 31+
3299 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3300 featureId, "getCallStateForSubscription")) {
3301 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3302 + "targeting API level 31+.");
3303 }
3304 }
joonhunshin4ac60942023-11-15 15:23:39 +00003305
3306 enforceTelephonyFeatureWithException(callingPackage,
3307 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallStateForSubscription");
3308
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003309 final long identity = Binder.clearCallingIdentity();
3310 try {
3311 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003312 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3313 PhoneConstantConversions.convertCallState(phone.getState());
3314 } finally {
3315 Binder.restoreCallingIdentity(identity);
3316 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003317 }
3318
Sanket Padawe356d7632015-06-22 14:03:32 -07003319 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003320 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003321 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003322 }
3323
3324 @Override
3325 public int getDataStateForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003326 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3327 PackageManager.FEATURE_TELEPHONY_DATA, "getDataStateForSubId");
3328
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003329 final long identity = Binder.clearCallingIdentity();
3330 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003331 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003332 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003333 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003334 } else {
3335 return PhoneConstantConversions.convertDataState(
3336 PhoneConstants.DataState.DISCONNECTED);
3337 }
3338 } finally {
3339 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003340 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003341 }
3342
Sanket Padawe356d7632015-06-22 14:03:32 -07003343 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003344 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003345 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003346 }
3347
3348 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003349 public @DataActivityType int getDataActivityForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003350 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3351 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivityForSubId");
3352
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003353 final long identity = Binder.clearCallingIdentity();
3354 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003355 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003356 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003357 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003358 } else {
3359 return TelephonyManager.DATA_ACTIVITY_NONE;
3360 }
3361 } finally {
3362 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003363 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003364 }
3365
3366 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003367 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003368 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003369 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003370
3371 LocationAccessPolicy.LocationPermissionResult locationResult =
3372 LocationAccessPolicy.checkLocationPermission(mApp,
3373 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3374 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003375 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003376 .setCallingPid(Binder.getCallingPid())
3377 .setCallingUid(Binder.getCallingUid())
3378 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003379 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003380 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3381 .build());
3382 switch (locationResult) {
3383 case DENIED_HARD:
3384 throw new SecurityException("Not allowed to access cell location");
3385 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003386 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3387 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003388 }
3389
joonhunshin4ac60942023-11-15 15:23:39 +00003390 enforceTelephonyFeatureWithException(callingPackage,
3391 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getCellLocation");
3392
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003393 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003394 final long identity = Binder.clearCallingIdentity();
3395 try {
3396 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003397 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003398 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003399 } finally {
3400 Binder.restoreCallingIdentity(identity);
3401 }
Svetoslav64fad262015-04-14 14:35:21 -07003402 }
3403
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003404 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003405 public String getNetworkCountryIsoForPhone(int phoneId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003406 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3407 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkCountryIsoForPhone");
3408
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003409 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3410 // registered cell info, so return a NULL country instead.
3411 final long identity = Binder.clearCallingIdentity();
3412 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003413 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3414 // Get default phone in this case.
3415 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3416 }
Jack Yu285100e2022-12-02 22:48:35 -08003417 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003418 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003419 if (phone == null) return "";
3420 ServiceStateTracker sst = phone.getServiceStateTracker();
3421 if (sst == null) return "";
3422 LocaleTracker lt = sst.getLocaleTracker();
3423 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003424 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003425 } finally {
3426 Binder.restoreCallingIdentity(identity);
3427 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003428 }
3429
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003430 /**
3431 * This method was removed due to potential issues caused by performing partial
3432 * updates of service state, and lack of a credible use case.
3433 *
3434 * This has the ability to break the telephony implementation by disabling notification of
3435 * changes in device connectivity. DO NOT USE THIS!
3436 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003437 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003438 public void enableLocationUpdates() {
3439 mApp.enforceCallingOrSelfPermission(
3440 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003441 }
3442
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003443 /**
3444 * This method was removed due to potential issues caused by performing partial
3445 * updates of service state, and lack of a credible use case.
3446 *
3447 * This has the ability to break the telephony implementation by disabling notification of
3448 * changes in device connectivity. DO NOT USE THIS!
3449 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003450 @Override
3451 public void disableLocationUpdates() {
3452 mApp.enforceCallingOrSelfPermission(
3453 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003454 }
3455
3456 @Override
3457 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003458 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3459 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003460 try {
3461 mApp.getSystemService(AppOpsManager.class)
3462 .checkPackage(Binder.getCallingUid(), callingPackage);
3463 } catch (SecurityException e) {
3464 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3465 throw e;
3466 }
3467
Nathan Haroldf096d982020-11-18 17:18:06 -08003468 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003469 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3470 throw new SecurityException(
3471 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3472 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003473
Jordan Liu1617b712019-07-10 15:06:26 -07003474 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003475 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3476 return null;
3477 }
Svetoslav64fad262015-04-14 14:35:21 -07003478
joonhunshin4ac60942023-11-15 15:23:39 +00003479 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3480 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNeighboringCellInfo");
3481
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003482 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003483
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003484 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003485 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003486
Nathan Haroldf180aac2018-06-01 18:43:55 -07003487 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3488 for (CellInfo ci : info) {
3489 if (ci instanceof CellInfoGsm) {
3490 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3491 } else if (ci instanceof CellInfoWcdma) {
3492 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3493 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003494 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003495 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003496 }
3497
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003498 private List<CellInfo> getCachedCellInfo() {
3499 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3500 for (Phone phone : PhoneFactory.getPhones()) {
3501 List<CellInfo> info = phone.getAllCellInfo();
3502 if (info != null) cellInfos.addAll(info);
3503 }
3504 return cellInfos;
3505 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003506
3507 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003508 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003509 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003510 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003511
3512 LocationAccessPolicy.LocationPermissionResult locationResult =
3513 LocationAccessPolicy.checkLocationPermission(mApp,
3514 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3515 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003516 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003517 .setCallingPid(Binder.getCallingPid())
3518 .setCallingUid(Binder.getCallingUid())
3519 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003520 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003521 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3522 .build());
3523 switch (locationResult) {
3524 case DENIED_HARD:
3525 throw new SecurityException("Not allowed to access cell info");
3526 case DENIED_SOFT:
3527 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003528 }
3529
Nathan Haroldf096d982020-11-18 17:18:06 -08003530 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003531 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3532 return getCachedCellInfo();
3533 }
3534
joonhunshin4ac60942023-11-15 15:23:39 +00003535 enforceTelephonyFeatureWithException(callingPackage,
3536 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllCellInfo");
3537
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003538 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003539 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003540 final long identity = Binder.clearCallingIdentity();
3541 try {
3542 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3543 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003544 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003545 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003546 if (info != null) cellInfos.addAll(info);
3547 }
3548 return cellInfos;
3549 } finally {
3550 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003551 }
3552 }
3553
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003554 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003555 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3556 String callingFeatureId) {
3557 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3558 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003559 }
3560
3561 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003562 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3563 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003564 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003565 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003566 }
3567
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003568 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3569 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003570 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003571 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003572
3573 LocationAccessPolicy.LocationPermissionResult locationResult =
3574 LocationAccessPolicy.checkLocationPermission(mApp,
3575 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3576 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003577 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003578 .setCallingPid(Binder.getCallingPid())
3579 .setCallingUid(Binder.getCallingUid())
3580 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003581 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3582 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003583 .build());
3584 switch (locationResult) {
3585 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003586 if (TelephonyPermissions
3587 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003588 // Safetynet logging for b/154934934
3589 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3590 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003591 throw new SecurityException("Not allowed to access cell info");
3592 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003593 if (TelephonyPermissions
3594 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003595 // Safetynet logging for b/154934934
3596 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3597 }
Nathan Harold5320c422019-05-09 10:26:08 -07003598 try {
3599 cb.onCellInfo(new ArrayList<CellInfo>());
3600 } catch (RemoteException re) {
3601 // Drop without consequences
3602 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003603 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003604 }
3605
joonhunshin4ac60942023-11-15 15:23:39 +00003606 enforceTelephonyFeatureWithException(callingPackage,
3607 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestCellInfoUpdateInternal");
Nathan Harolda939a962019-05-09 10:13:47 -07003608
3609 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003610 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3611
3612 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3613 }
3614
3615 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003616 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003617 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003618 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003619
3620 final long identity = Binder.clearCallingIdentity();
3621 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003622 Phone phone = getPhone(subId);
3623 if (phone == null) {
3624 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3625 } else {
3626 phone.setCellInfoListRate(rateInMillis, workSource);
3627 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003628 } finally {
3629 Binder.restoreCallingIdentity(identity);
3630 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003631 }
3632
Shishir Agrawala9f32182016-04-12 12:00:16 -07003633 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003634 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003635 Phone phone = PhoneFactory.getPhone(slotIndex);
3636 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003637 return null;
3638 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003639 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003640 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003641 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003642 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003643 return null;
3644 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003645
joonhunshin4ac60942023-11-15 15:23:39 +00003646 enforceTelephonyFeatureWithException(callingPackage,
3647 PackageManager.FEATURE_TELEPHONY_GSM, "getImeiForSlot");
3648
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003649 final long identity = Binder.clearCallingIdentity();
3650 try {
3651 return phone.getImei();
3652 } finally {
3653 Binder.restoreCallingIdentity(identity);
3654 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003655 }
3656
3657 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003658 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3659 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3660 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3661 callingFeatureId, "getPrimaryImei")) {
3662 throw new SecurityException("Caller does not have permission");
3663 }
joonhunshin4ac60942023-11-15 15:23:39 +00003664
3665 enforceTelephonyFeatureWithException(callingPackage,
3666 PackageManager.FEATURE_TELEPHONY_GSM, "getPrimaryImei");
3667
arunvoddud5c6ce02022-12-11 06:03:12 +00003668 final long identity = Binder.clearCallingIdentity();
3669 try {
3670 for (Phone phone : PhoneFactory.getPhones()) {
3671 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3672 return phone.getImei();
3673 }
3674 }
3675 throw new UnsupportedOperationException("Operation not supported");
3676 } finally {
3677 Binder.restoreCallingIdentity(identity);
3678 }
3679 }
3680
3681 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003682 public String getTypeAllocationCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003683 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3684 PackageManager.FEATURE_TELEPHONY_GSM, "getTypeAllocationCodeForSlot");
3685
David Kelly5e06a7f2018-03-12 14:10:59 +00003686 Phone phone = PhoneFactory.getPhone(slotIndex);
3687 String tac = null;
3688 if (phone != null) {
3689 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003690 try {
3691 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3692 } catch (IndexOutOfBoundsException e) {
3693 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3694 return null;
3695 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003696 }
3697 return tac;
3698 }
3699
3700 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003701 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003702 try {
3703 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3704 } catch (SecurityException se) {
3705 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3706 throw new SecurityException("Package " + callingPackage + " does not belong to "
3707 + Binder.getCallingUid());
3708 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003709 Phone phone = PhoneFactory.getPhone(slotIndex);
3710 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003711 return null;
3712 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003713
Jeff Davidson913390f2018-02-23 17:11:49 -08003714 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003715 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003716 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003717 return null;
3718 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003719
joonhunshin4ac60942023-11-15 15:23:39 +00003720 enforceTelephonyFeatureWithException(callingPackage,
3721 PackageManager.FEATURE_TELEPHONY_CDMA, "getMeidForSlot");
3722
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003723 final long identity = Binder.clearCallingIdentity();
3724 try {
3725 return phone.getMeid();
3726 } finally {
3727 Binder.restoreCallingIdentity(identity);
3728 }
Jack Yu2af8d712017-03-15 17:14:14 -07003729 }
3730
3731 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003732 public String getManufacturerCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003733 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3734 PackageManager.FEATURE_TELEPHONY_CDMA, "getManufacturerCodeForSlot");
3735
David Kelly5e06a7f2018-03-12 14:10:59 +00003736 Phone phone = PhoneFactory.getPhone(slotIndex);
3737 String manufacturerCode = null;
3738 if (phone != null) {
3739 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003740 try {
3741 manufacturerCode =
3742 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3743 } catch (IndexOutOfBoundsException e) {
3744 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3745 return null;
3746 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003747 }
3748 return manufacturerCode;
3749 }
3750
3751 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003752 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3753 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003754 Phone phone = PhoneFactory.getPhone(slotIndex);
3755 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003756 return null;
3757 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003758 int subId = phone.getSubId();
3759 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003760 mApp, subId, callingPackage, callingFeatureId,
3761 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003762 return null;
3763 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003764
joonhunshin4ac60942023-11-15 15:23:39 +00003765 enforceTelephonyFeatureWithException(callingPackage,
3766 PackageManager.FEATURE_TELEPHONY, "getDeviceSoftwareVersionForSlot");
3767
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003768 final long identity = Binder.clearCallingIdentity();
3769 try {
3770 return phone.getDeviceSvn();
3771 } finally {
3772 Binder.restoreCallingIdentity(identity);
3773 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003774 }
3775
fionaxu43304da2017-11-27 22:51:16 -08003776 @Override
3777 public int getSubscriptionCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003778 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3779 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierId");
3780
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003781 final long identity = Binder.clearCallingIdentity();
3782 try {
3783 final Phone phone = getPhone(subId);
3784 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3785 } finally {
3786 Binder.restoreCallingIdentity(identity);
3787 }
fionaxu43304da2017-11-27 22:51:16 -08003788 }
3789
3790 @Override
3791 public String getSubscriptionCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003792 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3793 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierName");
3794
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003795 final long identity = Binder.clearCallingIdentity();
3796 try {
3797 final Phone phone = getPhone(subId);
3798 return phone == null ? null : phone.getCarrierName();
3799 } finally {
3800 Binder.restoreCallingIdentity(identity);
3801 }
fionaxu43304da2017-11-27 22:51:16 -08003802 }
3803
calvinpanffe225e2018-11-01 19:43:06 +08003804 @Override
chen xu0026ca62019-03-06 15:28:50 -08003805 public int getSubscriptionSpecificCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003806 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3807 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionSpecificCarrierId");
3808
chen xu25637222018-11-04 17:17:00 -08003809 final long identity = Binder.clearCallingIdentity();
3810 try {
3811 final Phone phone = getPhone(subId);
3812 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003813 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003814 } finally {
3815 Binder.restoreCallingIdentity(identity);
3816 }
3817 }
3818
3819 @Override
chen xu0026ca62019-03-06 15:28:50 -08003820 public String getSubscriptionSpecificCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003821 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3822 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
3823 "getSubscriptionSpecificCarrierName");
3824
chen xu25637222018-11-04 17:17:00 -08003825 final long identity = Binder.clearCallingIdentity();
3826 try {
3827 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003828 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003829 } finally {
3830 Binder.restoreCallingIdentity(identity);
3831 }
3832 }
3833
chen xu651eec72018-11-11 19:03:44 -08003834 @Override
chen xu864e11c2018-12-06 22:10:03 -08003835 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3836 if (!isSubscriptionMccMnc) {
3837 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3838 }
chen xu651eec72018-11-11 19:03:44 -08003839 final Phone phone = PhoneFactory.getPhone(slotIndex);
3840 if (phone == null) {
3841 return TelephonyManager.UNKNOWN_CARRIER_ID;
3842 }
joonhunshin4ac60942023-11-15 15:23:39 +00003843
3844 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3845 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromMccMnc");
3846
chen xu651eec72018-11-11 19:03:44 -08003847 final long identity = Binder.clearCallingIdentity();
3848 try {
3849 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3850 } finally {
3851 Binder.restoreCallingIdentity(identity);
3852 }
3853 }
3854
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003855 //
3856 // Internal helper methods.
3857 //
3858
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003859 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003860 * Make sure the caller is the calling package itself
3861 *
3862 * @throws SecurityException if the caller is not the calling package
3863 */
3864 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3865 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003866 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3867 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003868 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003869 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003870 } catch (PackageManager.NameNotFoundException e) {
3871 // packageUid is -1
3872 }
3873 if (packageUid != callingUid) {
3874 throw new SecurityException(message + ": Package " + callingPackage
3875 + " does not belong to " + callingUid);
3876 }
3877 }
3878
3879 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003880 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3881 *
3882 * @throws SecurityException if the caller does not have the required permission
3883 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003884 @VisibleForTesting
3885 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003886 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3887 }
3888
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003889 /**
arunvoddud7401012022-12-15 16:08:12 +00003890 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003891 *
3892 * @throws SecurityException if the caller does not have the required permission
3893 */
3894 @VisibleForTesting
3895 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003896 enforceReadPermission(null);
3897 }
3898
3899 /**
3900 * Make sure the caller has the READ_PHONE_STATE permissions.
3901 *
3902 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3903 */
3904 @VisibleForTesting
3905 public void enforceReadPermission(String msg) {
3906 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003907 }
3908
Shuo Qian3b6ee772019-11-13 17:43:31 -08003909 private void enforceActiveEmergencySessionPermission() {
3910 mApp.enforceCallingOrSelfPermission(
3911 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3912 }
3913
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003914 /**
3915 * Make sure the caller has the CALL_PHONE permission.
3916 *
3917 * @throws SecurityException if the caller does not have the required permission
3918 */
3919 private void enforceCallPermission() {
3920 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3921 }
3922
paulhu5a773602019-08-23 19:17:33 +08003923 private void enforceSettingsPermission() {
3924 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003925 }
3926
Michele Berionne5e411512020-11-13 02:36:59 +00003927 private void enforceRebootPermission() {
3928 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3929 }
3930
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003931 /**
3932 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3933 * @param message - log message to print.
3934 * @throws SecurityException if the caller does not have the required permission
3935 */
3936 private void enforceSatelliteCommunicationPermission(String message) {
3937 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3938 }
3939
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003940 private String createTelUrl(String number) {
3941 if (TextUtils.isEmpty(number)) {
3942 return null;
3943 }
3944
Jake Hambye994d462014-02-03 13:10:13 -08003945 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003946 }
3947
Ihab Awadf9e92732013-12-05 18:02:52 -08003948 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003949 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003950 }
3951
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003952 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003953 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003954 }
3955
Ihab Awadf9e92732013-12-05 18:02:52 -08003956 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003957 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003958 }
3959
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003960 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003961 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003962 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003963 }
3964
Sanket Padawe356d7632015-06-22 14:03:32 -07003965 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003966 public int getActivePhoneTypeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003967 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3968 PackageManager.FEATURE_TELEPHONY, "getActivePhoneTypeForSlot");
3969
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003970 final long identity = Binder.clearCallingIdentity();
3971 try {
3972 final Phone phone = PhoneFactory.getPhone(slotIndex);
3973 if (phone == null) {
3974 return PhoneConstants.PHONE_TYPE_NONE;
3975 } else {
3976 return phone.getPhoneType();
3977 }
3978 } finally {
3979 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003980 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003981 }
3982
3983 /**
3984 * Returns the CDMA ERI icon index to display
3985 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003986 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003987 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3988 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3989 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003990 }
3991
Sanket Padawe356d7632015-06-22 14:03:32 -07003992 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003993 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3994 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003995 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003996 mApp, subId, callingPackage, callingFeatureId,
3997 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003998 return -1;
3999 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004000
joonhunshin4ac60942023-11-15 15:23:39 +00004001 enforceTelephonyFeatureWithException(callingPackage,
4002 PackageManager.FEATURE_TELEPHONY_CDMA,
4003 "getCdmaEriIconIndexForSubscriber");
4004
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004005 final long identity = Binder.clearCallingIdentity();
4006 try {
4007 final Phone phone = getPhone(subId);
4008 if (phone != null) {
4009 return phone.getCdmaEriIconIndex();
4010 } else {
4011 return -1;
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 mode,
4020 * 0 - ON
4021 * 1 - FLASHING
4022 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004023 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004024 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
4025 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
4026 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004027 }
4028
Sanket Padawe356d7632015-06-22 14:03:32 -07004029 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004030 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
4031 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004032 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004033 mApp, subId, callingPackage, callingFeatureId,
4034 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004035 return -1;
4036 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004037
4038 final long identity = Binder.clearCallingIdentity();
4039 try {
4040 final Phone phone = getPhone(subId);
4041 if (phone != null) {
4042 return phone.getCdmaEriIconMode();
4043 } else {
4044 return -1;
4045 }
4046 } finally {
4047 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004048 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004049 }
4050
4051 /**
4052 * Returns the CDMA ERI text,
4053 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004054 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004055 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
4056 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
4057 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004058 }
4059
Sanket Padawe356d7632015-06-22 14:03:32 -07004060 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004061 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
4062 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004063 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004064 mApp, subId, callingPackage, callingFeatureId,
4065 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004066 return null;
4067 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004068
4069 final long identity = Binder.clearCallingIdentity();
4070 try {
4071 final Phone phone = getPhone(subId);
4072 if (phone != null) {
4073 return phone.getCdmaEriText();
4074 } else {
4075 return null;
4076 }
4077 } finally {
4078 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004079 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004080 }
4081
4082 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07004083 * Returns the CDMA MDN.
4084 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004085 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004086 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004087 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4088 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004089
joonhunshin4ac60942023-11-15 15:23:39 +00004090 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4091 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMdn");
4092
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004093 final long identity = Binder.clearCallingIdentity();
4094 try {
4095 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004096 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004097 return phone.getLine1Number();
4098 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004099 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004100 return null;
4101 }
4102 } finally {
4103 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004104 }
4105 }
4106
4107 /**
4108 * Returns the CDMA MIN.
4109 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004110 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004111 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004112 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4113 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004114
joonhunshin4ac60942023-11-15 15:23:39 +00004115 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4116 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMin");
4117
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004118 final long identity = Binder.clearCallingIdentity();
4119 try {
4120 final Phone phone = getPhone(subId);
4121 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
4122 return phone.getCdmaMin();
4123 } else {
4124 return null;
4125 }
4126 } finally {
4127 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004128 }
4129 }
4130
Hall Liud892bec2018-11-30 14:51:45 -08004131 @Override
4132 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
4133 INumberVerificationCallback callback, String callingPackage) {
4134 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
4135 != PERMISSION_GRANTED) {
4136 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
4137 }
4138 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4139
4140 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
4141 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08004142 throw new SecurityException("Calling package must be configured in the device config: "
4143 + "calling package: " + callingPackage
4144 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004145 }
4146
joonhunshin4ac60942023-11-15 15:23:39 +00004147 enforceTelephonyFeatureWithException(callingPackage,
4148 PackageManager.FEATURE_TELEPHONY_CALLING, "requestNumberVerification");
4149
Hall Liud892bec2018-11-30 14:51:45 -08004150 if (range == null) {
4151 throw new NullPointerException("Range must be non-null");
4152 }
4153
4154 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004155 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004156
4157 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4158 }
4159
Junda Liuca05d5d2014-08-14 22:36:34 -07004160 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004161 * Returns true if CDMA provisioning needs to run.
4162 */
4163 public boolean needsOtaServiceProvisioning() {
joonhunshin4ac60942023-11-15 15:23:39 +00004164 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4165 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needsOtaServiceProvisioning");
4166
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004167 final long identity = Binder.clearCallingIdentity();
4168 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004169 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004170 } finally {
4171 Binder.restoreCallingIdentity(identity);
4172 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004173 }
4174
4175 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004176 * Sets the voice mail number of a given subId.
4177 */
4178 @Override
4179 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004180 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4181 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004182
joonhunshin4ac60942023-11-15 15:23:39 +00004183 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4184 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceMailNumber");
4185
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004186 final long identity = Binder.clearCallingIdentity();
4187 try {
4188 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4189 new Pair<String, String>(alphaTag, number), new Integer(subId));
4190 return success;
4191 } finally {
4192 Binder.restoreCallingIdentity(identity);
4193 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004194 }
4195
Ta-wei Yen87c49842016-05-13 21:19:52 -07004196 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004197 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4198 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004199 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4200 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004201 if (!TextUtils.equals(callingPackage, systemDialer)) {
4202 throw new SecurityException("caller must be system dialer");
4203 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004204
joonhunshin4ac60942023-11-15 15:23:39 +00004205 enforceTelephonyFeatureWithException(callingPackage,
4206 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailSettings");
4207
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004208 final long identity = Binder.clearCallingIdentity();
4209 try {
4210 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4211 if (phoneAccountHandle == null) {
4212 return null;
4213 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004214 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004215 } finally {
4216 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004217 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004218 }
4219
4220 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004221 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4222 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004223 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004224 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004225 mApp, subId, callingPackage, callingFeatureId,
4226 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004227 return null;
4228 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004229
joonhunshin4ac60942023-11-15 15:23:39 +00004230 enforceTelephonyFeatureWithException(callingPackage,
4231 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailPackageName");
4232
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004233 final long identity = Binder.clearCallingIdentity();
4234 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004235 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004236 } finally {
4237 Binder.restoreCallingIdentity(identity);
4238 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004239 }
4240
4241 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004242 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4243 VisualVoicemailSmsFilterSettings settings) {
4244 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004245
joonhunshin4ac60942023-11-15 15:23:39 +00004246 enforceTelephonyFeatureWithException(callingPackage,
4247 PackageManager.FEATURE_TELEPHONY_CALLING, "enableVisualVoicemailSmsFilter");
4248
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004249 final long identity = Binder.clearCallingIdentity();
4250 try {
4251 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004252 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004253 } finally {
4254 Binder.restoreCallingIdentity(identity);
4255 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004256 }
4257
4258 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004259 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4260 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004261
joonhunshin4ac60942023-11-15 15:23:39 +00004262 enforceTelephonyFeatureWithException(callingPackage,
4263 PackageManager.FEATURE_TELEPHONY_CALLING, "disableVisualVoicemailSmsFilter");
4264
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004265 final long identity = Binder.clearCallingIdentity();
4266 try {
4267 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004268 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004269 } finally {
4270 Binder.restoreCallingIdentity(identity);
4271 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004272 }
4273
4274 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004275 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4276 String callingPackage, int subId) {
4277 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004278
4279 final long identity = Binder.clearCallingIdentity();
4280 try {
4281 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004282 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004283 } finally {
4284 Binder.restoreCallingIdentity(identity);
4285 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004286 }
4287
4288 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004289 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004290 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004291
4292 final long identity = Binder.clearCallingIdentity();
4293 try {
4294 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004295 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004296 } finally {
4297 Binder.restoreCallingIdentity(identity);
4298 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004299 }
4300
4301 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004302 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4303 String callingAttributionTag, int subId, String number, int port, String text,
4304 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004305 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004306 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004307 enforceSendSmsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00004308
4309 enforceTelephonyFeatureWithException(callingPackage,
4310 PackageManager.FEATURE_TELEPHONY_CALLING, "sendVisualVoicemailSmsForSubscriber");
4311
Amit Mahajandccb3f12019-05-13 13:48:32 -07004312 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004313 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4314 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004315 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004316
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004317 /**
fionaxu0152e512016-11-14 13:36:14 -08004318 * Sets the voice activation state of a given subId.
4319 */
4320 @Override
4321 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004322 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4323 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004324
joonhunshin4ac60942023-11-15 15:23:39 +00004325 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4326 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState");
4327
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004328 final long identity = Binder.clearCallingIdentity();
4329 try {
4330 final Phone phone = getPhone(subId);
4331 if (phone != null) {
4332 phone.setVoiceActivationState(activationState);
4333 } else {
4334 loge("setVoiceActivationState fails with invalid subId: " + subId);
4335 }
4336 } finally {
4337 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004338 }
4339 }
4340
4341 /**
4342 * Sets the data activation state of a given subId.
4343 */
4344 @Override
4345 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004346 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4347 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004348
joonhunshin4ac60942023-11-15 15:23:39 +00004349 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4350 PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState");
4351
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004352 final long identity = Binder.clearCallingIdentity();
4353 try {
4354 final Phone phone = getPhone(subId);
4355 if (phone != null) {
4356 phone.setDataActivationState(activationState);
4357 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004358 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004359 }
4360 } finally {
4361 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004362 }
4363 }
4364
4365 /**
4366 * Returns the voice activation state of a given subId.
4367 */
4368 @Override
4369 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004370 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004371
joonhunshin4ac60942023-11-15 15:23:39 +00004372 enforceTelephonyFeatureWithException(callingPackage,
4373 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState");
4374
fionaxu0152e512016-11-14 13:36:14 -08004375 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004376 final long identity = Binder.clearCallingIdentity();
4377 try {
4378 if (phone != null) {
4379 return phone.getVoiceActivationState();
4380 } else {
4381 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4382 }
4383 } finally {
4384 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004385 }
4386 }
4387
4388 /**
4389 * Returns the data activation state of a given subId.
4390 */
4391 @Override
4392 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004393 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004394
joonhunshin4ac60942023-11-15 15:23:39 +00004395 enforceTelephonyFeatureWithException(callingPackage,
4396 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState");
4397
fionaxu0152e512016-11-14 13:36:14 -08004398 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004399 final long identity = Binder.clearCallingIdentity();
4400 try {
4401 if (phone != null) {
4402 return phone.getDataActivationState();
4403 } else {
4404 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4405 }
4406 } finally {
4407 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004408 }
4409 }
4410
4411 /**
Wink Saville36469e72014-06-11 15:17:00 -07004412 * Returns the unread count of voicemails for a subId
4413 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004414 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004415 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4416 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004417 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004418 mApp, subId, callingPackage, callingFeatureId,
4419 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004420 return 0;
4421 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004422 final long identity = Binder.clearCallingIdentity();
4423 try {
4424 final Phone phone = getPhone(subId);
4425 if (phone != null) {
4426 return phone.getVoiceMessageCount();
4427 } else {
4428 return 0;
4429 }
4430 } finally {
4431 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004432 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004433 }
4434
4435 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004436 * returns true, if the device is in a state where both voice and data
4437 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004438 */
4439 @Override
4440 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00004441 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4442 PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed");
4443
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004444 final long identity = Binder.clearCallingIdentity();
4445 try {
Ling Mac28f0212023-03-24 16:07:15 -07004446 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004447 } finally {
4448 Binder.restoreCallingIdentity(identity);
4449 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004450 }
4451
4452 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004453 * Send the dialer code if called from the current default dialer or the caller has
4454 * carrier privilege.
4455 * @param inputCode The dialer code to send
4456 */
4457 @Override
4458 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004459 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004460 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004461 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4462 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004463 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004464 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004465 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004466 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004467
joonhunshin4ac60942023-11-15 15:23:39 +00004468 enforceTelephonyFeatureWithException(callingPackage,
4469 PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode");
4470
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004471 final long identity = Binder.clearCallingIdentity();
4472 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004473 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004474 } finally {
4475 Binder.restoreCallingIdentity(identity);
4476 }
fionaxu235cc5e2017-03-06 22:25:57 -08004477 }
4478
Pengquan Menga1bb6272018-09-06 09:59:22 -07004479 @Override
4480 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004481 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004482 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4483 mApp, subId, "getNetworkSelectionMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004484
4485 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4486 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode");
4487
shilufc958392020-01-20 11:36:01 -08004488 final long identity = Binder.clearCallingIdentity();
4489 try {
4490 if (!isActiveSubscription(subId)) {
4491 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4492 }
4493 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4494 } finally {
4495 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004496 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004497 }
4498
Brad Ebinger35c841c2018-10-01 10:40:55 -07004499 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004500 public boolean isInEmergencySmsMode() {
4501 enforceReadPrivilegedPermission("isInEmergencySmsMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004502
4503 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4504 PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode");
4505
Brad Ebingerb2b65522019-03-15 13:48:47 -07004506 final long identity = Binder.clearCallingIdentity();
4507 try {
4508 for (Phone phone : PhoneFactory.getPhones()) {
4509 if (phone.isInEmergencySmsMode()) {
4510 return true;
4511 }
4512 }
4513 } finally {
4514 Binder.restoreCallingIdentity(identity);
4515 }
4516 return false;
4517 }
4518
shilu366312e2019-12-17 09:28:10 -08004519 /**
4520 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4521 * @param subId The subscription to use to check the configuration.
4522 * @param c The callback that will be used to send the result.
4523 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004524 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004525 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4526 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004527 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004528 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004529
4530 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4531 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4532 "IMS not available on device.");
4533 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004534 final long token = Binder.clearCallingIdentity();
4535 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004536 int slotId = getSlotIndexOrException(subId);
4537 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004538
4539 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4540 if (controller != null) {
4541 ImsManager imsManager = controller.getImsManager(subId);
4542 if (imsManager != null) {
4543 imsManager.addRegistrationCallbackForSubscription(c, subId);
4544 } else {
4545 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4546 }
4547 } else {
4548 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4549 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004550 } catch (ImsException e) {
4551 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004552 } finally {
4553 Binder.restoreCallingIdentity(token);
4554 }
4555 }
4556
shilu366312e2019-12-17 09:28:10 -08004557 /**
4558 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4559 * @param subId The subscription to use to check the configuration.
4560 * @param c The callback that will be used to send the result.
4561 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004562 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004563 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004564 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004565 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004566 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4567 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4568 }
Meng Wangafbc5852019-09-19 17:37:13 -07004569 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004570
Meng Wangafbc5852019-09-19 17:37:13 -07004571 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004572 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4573 if (controller != null) {
4574 ImsManager imsManager = controller.getImsManager(subId);
4575 if (imsManager != null) {
4576 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4577 } else {
4578 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4579 + "is inactive, ignoring unregister.");
4580 // If the ImsManager is not valid, just return, since the callback
4581 // will already have been removed internally.
4582 }
4583 }
Meng Wangafbc5852019-09-19 17:37:13 -07004584 } finally {
4585 Binder.restoreCallingIdentity(token);
4586 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004587 }
4588
Brad Ebingera34a6c22019-10-22 17:36:18 -07004589 /**
Hidayat Khan99ea48f2023-12-11 04:37:45 +00004590 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4591 * @param subId The subscription to use to check the configuration.
4592 * @param c The callback that will be used to send the result.
4593 */
4594 @Override
4595 public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c)
4596 throws RemoteException {
4597 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4598 mApp, subId, "registerImsEmergencyRegistrationCallback");
4599
4600 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4601 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4602 "IMS not available on device.");
4603 }
4604 final long token = Binder.clearCallingIdentity();
4605 try {
4606 int slotId = getSlotIndexOrException(subId);
4607 verifyImsMmTelConfiguredOrThrow(slotId);
4608
4609 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4610 if (controller != null) {
4611 ImsManager imsManager = controller.getImsManager(subId);
4612 if (imsManager != null) {
4613 imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId);
4614 } else {
4615 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4616 }
4617 } else {
4618 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4619 }
4620 } catch (ImsException e) {
4621 throw new ServiceSpecificException(e.getCode());
4622 } finally {
4623 Binder.restoreCallingIdentity(token);
4624 }
4625 }
4626
4627 /**
4628 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4629 * @param subId The subscription to use to check the configuration.
4630 * @param c The callback that will be used to send the result.
4631 */
4632 @Override
4633 public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) {
4634 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4635 mApp, subId, "unregisterImsEmergencyRegistrationCallback");
4636 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4637 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4638 }
4639 final long token = Binder.clearCallingIdentity();
4640
4641 try {
4642 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4643 if (controller != null) {
4644 ImsManager imsManager = controller.getImsManager(subId);
4645 if (imsManager != null) {
4646 imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId);
4647 } else {
4648 Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId
4649 + "is inactive, ignoring unregister.");
4650 // If the ImsManager is not valid, just return, since the callback
4651 // will already have been removed internally.
4652 }
4653 }
4654 } finally {
4655 Binder.restoreCallingIdentity(token);
4656 }
4657 }
4658
4659 /**
Brad Ebingera34a6c22019-10-22 17:36:18 -07004660 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4661 */
4662 @Override
4663 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4664 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4665 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4666 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4667 "IMS not available on device.");
4668 }
4669 final long token = Binder.clearCallingIdentity();
4670 try {
4671 Phone phone = getPhone(subId);
4672 if (phone == null) {
4673 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4674 + subId + "'");
4675 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4676 }
4677 phone.getImsRegistrationState(regState -> {
4678 try {
4679 consumer.accept((regState == null)
4680 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4681 } catch (RemoteException e) {
4682 // Ignore if the remote process is no longer available to call back.
4683 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4684 }
4685 });
4686 } finally {
4687 Binder.restoreCallingIdentity(token);
4688 }
4689 }
4690
4691 /**
4692 * Get the transport type for the IMS service registration state.
4693 */
4694 @Override
4695 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004696 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004697 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004698 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4699 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4700 "IMS not available on device.");
4701 }
4702 final long token = Binder.clearCallingIdentity();
4703 try {
4704 Phone phone = getPhone(subId);
4705 if (phone == null) {
4706 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4707 + subId + "'");
4708 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4709 }
4710 phone.getImsRegistrationTech(regTech -> {
4711 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4712 int regTechConverted = (regTech == null)
4713 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4714 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4715 regTechConverted);
4716 try {
4717 consumer.accept(regTechConverted);
4718 } catch (RemoteException e) {
4719 // Ignore if the remote process is no longer available to call back.
4720 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4721 }
4722 });
4723 } finally {
4724 Binder.restoreCallingIdentity(token);
4725 }
4726 }
4727
shilu366312e2019-12-17 09:28:10 -08004728 /**
4729 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4730 * @param subId The subscription to use to check the configuration.
4731 * @param c The callback that will be used to send the result.
4732 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004733 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004734 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4735 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004736 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004737 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004738 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4739 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4740 "IMS not available on device.");
4741 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004742 final long token = Binder.clearCallingIdentity();
4743 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004744 int slotId = getSlotIndexOrException(subId);
4745 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004746
4747 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4748 if (controller != null) {
4749 ImsManager imsManager = controller.getImsManager(subId);
4750 if (imsManager != null) {
4751 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4752 } else {
4753 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4754 }
4755 } else {
4756 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4757 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004758 } catch (ImsException e) {
4759 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004760 } finally {
4761 Binder.restoreCallingIdentity(token);
4762 }
4763 }
4764
shilu366312e2019-12-17 09:28:10 -08004765 /**
4766 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4767 * @param subId The subscription to use to check the configuration.
4768 * @param c The callback that will be used to send the result.
4769 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004770 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004771 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004772 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004773 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004774 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4775 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4776 }
Meng Wangafbc5852019-09-19 17:37:13 -07004777
4778 final long token = Binder.clearCallingIdentity();
4779 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004780 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4781 if (controller != null) {
4782 ImsManager imsManager = controller.getImsManager(subId);
4783 if (imsManager != null) {
4784 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4785 } else {
4786 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4787 + " is inactive, ignoring unregister.");
4788 // If the ImsManager is not valid, just return, since the callback
4789 // will already have been removed internally.
4790 }
4791 }
Meng Wangafbc5852019-09-19 17:37:13 -07004792 } finally {
4793 Binder.restoreCallingIdentity(token);
4794 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004795 }
4796
4797 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004798 public boolean isCapable(int subId, int capability, int regTech) {
4799 enforceReadPrivilegedPermission("isCapable");
joonhunshin4ac60942023-11-15 15:23:39 +00004800
4801 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4802 FEATURE_TELEPHONY_IMS, "isCapable");
4803
Brad Ebinger35c841c2018-10-01 10:40:55 -07004804 final long token = Binder.clearCallingIdentity();
4805 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004806 int slotId = getSlotIndexOrException(subId);
4807 verifyImsMmTelConfiguredOrThrow(slotId);
4808 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4809 } catch (com.android.ims.ImsException e) {
4810 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4811 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004812 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004813 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4814 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004815 } finally {
4816 Binder.restoreCallingIdentity(token);
4817 }
4818 }
4819
4820 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004821 public boolean isAvailable(int subId, int capability, int regTech) {
4822 enforceReadPrivilegedPermission("isAvailable");
joonhunshin4ac60942023-11-15 15:23:39 +00004823
4824 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4825 FEATURE_TELEPHONY_IMS, "isAvailable");
4826
Brad Ebinger35c841c2018-10-01 10:40:55 -07004827 final long token = Binder.clearCallingIdentity();
4828 try {
4829 Phone phone = getPhone(subId);
4830 if (phone == null) return false;
4831 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004832 } catch (com.android.ims.ImsException e) {
4833 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4834 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004835 } finally {
4836 Binder.restoreCallingIdentity(token);
4837 }
4838 }
4839
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004840 /**
4841 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4842 * subscription.
4843 * @param subId The subscription to use to check the configuration.
4844 * @param callback The callback that will be used to send the result.
4845 * @param capability The MmTelFeature capability that will be used to send the result.
4846 * @param transportType The transport type of the MmTelFeature capability.
4847 */
4848 @Override
4849 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4850 int transportType) {
4851 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004852 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4853 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4854 "IMS not available on device.");
4855 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004856 final long token = Binder.clearCallingIdentity();
4857 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004858 int slotId = getSlotIndex(subId);
4859 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4860 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4861 + subId + "'");
4862 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4863 }
4864 verifyImsMmTelConfiguredOrThrow(slotId);
4865 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4866 transportType, aBoolean -> {
4867 try {
4868 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4869 } catch (RemoteException e) {
4870 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4871 + "running. Ignore");
4872 }
4873 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004874 } catch (ImsException e) {
4875 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004876 } finally {
4877 Binder.restoreCallingIdentity(token);
4878 }
4879 }
4880
shilu366312e2019-12-17 09:28:10 -08004881 /**
4882 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4883 * @param subId The subscription to use to check the configuration.
4884 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004885 @Override
4886 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004887 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004888 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004889
joonhunshin4ac60942023-11-15 15:23:39 +00004890 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4891 FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled");
4892
Brad Ebinger35c841c2018-10-01 10:40:55 -07004893 final long token = Binder.clearCallingIdentity();
4894 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004895 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004896 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004897 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004898 } catch (ImsException e) {
4899 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004900 } finally {
4901 Binder.restoreCallingIdentity(token);
4902 }
4903 }
4904
4905 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004906 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004907 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004908 "setAdvancedCallingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004909
4910 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4911 FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled");
4912
Brad Ebinger35c841c2018-10-01 10:40:55 -07004913 final long identity = Binder.clearCallingIdentity();
4914 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004915 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004916 // This setting doesn't require an active ImsService connection, so do not verify. The
4917 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004918 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004919 } catch (ImsException e) {
4920 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004921 } finally {
4922 Binder.restoreCallingIdentity(identity);
4923 }
4924 }
4925
shilu366312e2019-12-17 09:28:10 -08004926 /**
4927 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4928 * @param subId The subscription to use to check the configuration.
4929 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004930 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004931 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004932 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004933 mApp, subId, "isVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004934
4935 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4936 FEATURE_TELEPHONY_IMS, "isVtSettingEnabled");
4937
Brad Ebinger35c841c2018-10-01 10:40:55 -07004938 final long identity = Binder.clearCallingIdentity();
4939 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004940 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004941 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004942 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004943 } catch (ImsException e) {
4944 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004945 } finally {
4946 Binder.restoreCallingIdentity(identity);
4947 }
4948 }
4949
4950 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004951 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004952 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004953 "setVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004954
4955 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4956 FEATURE_TELEPHONY_IMS, "setVtSettingEnabled");
4957
Brad Ebinger35c841c2018-10-01 10:40:55 -07004958 final long identity = Binder.clearCallingIdentity();
4959 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004960 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004961 // This setting doesn't require an active ImsService connection, so do not verify. The
4962 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004963 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004964 } catch (ImsException e) {
4965 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004966 } finally {
4967 Binder.restoreCallingIdentity(identity);
4968 }
4969 }
4970
shilu366312e2019-12-17 09:28:10 -08004971 /**
4972 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4973 * @param subId The subscription to use to check the configuration.
4974 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004975 @Override
4976 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004977 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004978 mApp, subId, "isVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004979
4980 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4981 FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled");
4982
Brad Ebinger35c841c2018-10-01 10:40:55 -07004983 final long identity = Binder.clearCallingIdentity();
4984 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004985 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004986 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004987 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004988 } catch (ImsException e) {
4989 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004990 } finally {
4991 Binder.restoreCallingIdentity(identity);
4992 }
4993 }
4994
4995 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004996 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004997 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004998 "setVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004999
5000 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5001 FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled");
5002
Brad Ebinger35c841c2018-10-01 10:40:55 -07005003 final long identity = Binder.clearCallingIdentity();
5004 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005005 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005006 // This setting doesn't require an active ImsService connection, so do not verify. The
5007 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005008 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005009 } catch (ImsException e) {
5010 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005011 } finally {
5012 Binder.restoreCallingIdentity(identity);
5013 }
5014 }
5015
shilu366312e2019-12-17 09:28:10 -08005016 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005017 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
5018 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5019 * @param subId The subscription to use to check the configuration.
5020 */
5021 @Override
5022 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005023 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005024 mApp, subId, "isCrossSimCallingEnabledByUser");
joonhunshin4ac60942023-11-15 15:23:39 +00005025
5026 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5027 FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser");
5028
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005029 final long identity = Binder.clearCallingIdentity();
5030 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005031 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005032 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005033 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005034 } catch (ImsException e) {
5035 throw new ServiceSpecificException(e.getCode());
5036 } finally {
5037 Binder.restoreCallingIdentity(identity);
5038 }
5039 }
5040
5041 /**
5042 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
5043 * Requires MODIFY_PHONE_STATE permission.
5044 * @param subId The subscription to use to check the configuration.
5045 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
5046 * false otherwise
5047 */
5048 @Override
5049 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
5050 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5051 "setCrossSimCallingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005052
5053 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5054 FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled");
5055
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005056 final long identity = Binder.clearCallingIdentity();
5057 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005058 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005059 // This setting doesn't require an active ImsService connection, so do not verify. The
5060 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005061 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005062 } catch (ImsException e) {
5063 throw new ServiceSpecificException(e.getCode());
5064 } finally {
5065 Binder.restoreCallingIdentity(identity);
5066 }
5067 }
5068
5069 /**
shilu366312e2019-12-17 09:28:10 -08005070 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5071 * @param subId The subscription to use to check the configuration.
5072 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005073 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07005074
Brad Ebinger35c841c2018-10-01 10:40:55 -07005075 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005076 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005077 mApp, subId, "isVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005078
5079 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5080 FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled");
5081
Brad Ebinger35c841c2018-10-01 10:40:55 -07005082 final long identity = Binder.clearCallingIdentity();
5083 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005084 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005085 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005086 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005087 } catch (ImsException e) {
5088 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005089 } finally {
5090 Binder.restoreCallingIdentity(identity);
5091 }
5092 }
5093
5094 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005095 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005096 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005097 "setVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005098
5099 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5100 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled");
5101
Brad Ebinger35c841c2018-10-01 10:40:55 -07005102 final long identity = Binder.clearCallingIdentity();
5103 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005104 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005105 // This setting doesn't require an active ImsService connection, so do not verify. The
5106 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005107 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005108 } catch (ImsException e) {
5109 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005110 } finally {
5111 Binder.restoreCallingIdentity(identity);
5112 }
5113 }
5114
5115 @Override
5116 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
5117 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5118 "setVoWiFiNonPersistent");
joonhunshin4ac60942023-11-15 15:23:39 +00005119
5120 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5121 FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent");
5122
Brad Ebinger35c841c2018-10-01 10:40:55 -07005123 final long identity = Binder.clearCallingIdentity();
5124 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005125 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005126 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005127 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005128 } catch (ImsException e) {
5129 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005130 } finally {
5131 Binder.restoreCallingIdentity(identity);
5132 }
5133 }
5134
shilu366312e2019-12-17 09:28:10 -08005135 /**
5136 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5137 * @param subId The subscription to use to check the configuration.
5138 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005139 @Override
5140 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005141 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005142 mApp, subId, "getVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005143
5144 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5145 FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting");
5146
Brad Ebinger35c841c2018-10-01 10:40:55 -07005147 final long identity = Binder.clearCallingIdentity();
5148 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005149 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005150 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005151 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005152 } catch (ImsException e) {
5153 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005154 } finally {
5155 Binder.restoreCallingIdentity(identity);
5156 }
5157 }
5158
5159 @Override
5160 public void setVoWiFiModeSetting(int subId, int mode) {
5161 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5162 "setVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005163
5164 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5165 FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting");
5166
Brad Ebinger35c841c2018-10-01 10:40:55 -07005167 final long identity = Binder.clearCallingIdentity();
5168 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005169 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005170 // This setting doesn't require an active ImsService connection, so do not verify. The
5171 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005172 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005173 } catch (ImsException e) {
5174 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005175 } finally {
5176 Binder.restoreCallingIdentity(identity);
5177 }
5178 }
5179
5180 @Override
5181 public int getVoWiFiRoamingModeSetting(int subId) {
5182 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005183
5184 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5185 FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting");
5186
Brad Ebinger35c841c2018-10-01 10:40:55 -07005187 final long identity = Binder.clearCallingIdentity();
5188 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005189 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005190 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005191 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005192 } catch (ImsException e) {
5193 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005194 } finally {
5195 Binder.restoreCallingIdentity(identity);
5196 }
5197 }
5198
5199 @Override
5200 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
5201 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5202 "setVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005203
5204 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5205 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting");
5206
Brad Ebinger35c841c2018-10-01 10:40:55 -07005207 final long identity = Binder.clearCallingIdentity();
5208 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005209 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005210 // This setting doesn't require an active ImsService connection, so do not verify. The
5211 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005212 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005213 } catch (ImsException e) {
5214 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005215 } finally {
5216 Binder.restoreCallingIdentity(identity);
5217 }
5218 }
5219
5220 @Override
5221 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
5222 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5223 "setRttCapabilityEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005224
5225 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5226 FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting");
5227
Brad Ebinger35c841c2018-10-01 10:40:55 -07005228 final long identity = Binder.clearCallingIdentity();
5229 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005230 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005231 // This setting doesn't require an active ImsService connection, so do not verify. The
5232 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005233 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005234 } catch (ImsException e) {
5235 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005236 } finally {
5237 Binder.restoreCallingIdentity(identity);
5238 }
5239 }
5240
shilu366312e2019-12-17 09:28:10 -08005241 /**
5242 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5243 * @param subId The subscription to use to check the configuration.
5244 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005245 @Override
5246 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005247 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005248 mApp, subId, "isTtyOverVolteEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005249
5250 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5251 FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled");
5252
Brad Ebinger35c841c2018-10-01 10:40:55 -07005253 final long identity = Binder.clearCallingIdentity();
5254 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005255 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005256 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005257 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005258 } catch (ImsException e) {
5259 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005260 } finally {
5261 Binder.restoreCallingIdentity(identity);
5262 }
5263 }
5264
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005265 @Override
5266 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5267 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005268
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005269 final long identity = Binder.clearCallingIdentity();
5270 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005271 if (!isImsAvailableOnDevice()) {
5272 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5273 "IMS not available on device.");
5274 }
5275 int slotId = getSlotIndexOrException(subId);
5276 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005277
5278 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5279 if (controller != null) {
5280 ImsManager imsManager = controller.getImsManager(subId);
5281 if (imsManager != null) {
5282 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5283 } else {
5284 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5285 }
5286 } else {
5287 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5288 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005289 } catch (ImsException e) {
5290 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005291 } finally {
5292 Binder.restoreCallingIdentity(identity);
5293 }
5294 }
5295
5296 @Override
5297 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5298 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005299
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005300 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005301 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5302 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5303 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005304 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005305 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5306 if (controller != null) {
5307 ImsManager imsManager = controller.getImsManager(subId);
5308 if (imsManager != null) {
5309 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5310 } else {
5311 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5312 + " is inactive, ignoring unregister.");
5313 // If the ImsManager is not valid, just return, since the callback will already
5314 // have been removed internally.
5315 }
5316 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005317 } finally {
5318 Binder.restoreCallingIdentity(identity);
5319 }
5320 }
5321
joonhunshincffb7fc2021-11-28 07:32:01 +00005322 @Override
5323 public void registerFeatureProvisioningChangedCallback(int subId,
5324 IFeatureProvisioningCallback callback) {
5325 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5326 mApp, subId, "registerFeatureProvisioningChangedCallback");
5327
5328 final long identity = Binder.clearCallingIdentity();
5329 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5330 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5331 }
5332
joonhunshin91bc1952022-04-29 08:47:15 +00005333 try {
5334 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5335 if (controller == null) {
5336 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5337 "Device does not support IMS");
5338 }
5339 controller.addFeatureProvisioningChangedCallback(subId, callback);
5340 } finally {
5341 Binder.restoreCallingIdentity(identity);
5342 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005343 }
5344
5345 @Override
5346 public void unregisterFeatureProvisioningChangedCallback(int subId,
5347 IFeatureProvisioningCallback callback) {
5348 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5349 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5350
5351 final long identity = Binder.clearCallingIdentity();
5352 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5353 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5354 }
5355
joonhunshin91bc1952022-04-29 08:47:15 +00005356 try {
5357 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5358 if (controller == null) {
5359 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5360 return;
5361 }
5362 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5363 } finally {
5364 Binder.restoreCallingIdentity(identity);
5365 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005366 }
allenwtsu99c623b2020-01-03 18:24:23 +08005367
5368 private void checkModifyPhoneStatePermission(int subId, String message) {
5369 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5370 message);
5371 }
5372
allenwtsu99c623b2020-01-03 18:24:23 +08005373 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005374 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005375 boolean isProvisioned) {
5376 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5377
joonhunshin4ac60942023-11-15 15:23:39 +00005378 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5379 FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability");
5380
allenwtsu99c623b2020-01-03 18:24:23 +08005381 final long identity = Binder.clearCallingIdentity();
5382 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005383 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5384 if (controller == null) {
5385 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5386 return;
5387 }
5388 controller.setRcsProvisioningStatusForCapability(
5389 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005390 } finally {
5391 Binder.restoreCallingIdentity(identity);
5392 }
allenwtsu99c623b2020-01-03 18:24:23 +08005393 }
5394
5395
5396 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005397 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5398 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5399 mApp, subId, "getRcsProvisioningStatusForCapability");
5400
joonhunshin4ac60942023-11-15 15:23:39 +00005401 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5402 FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability");
5403
allenwtsu99c623b2020-01-03 18:24:23 +08005404 final long identity = Binder.clearCallingIdentity();
5405 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005406 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5407 if (controller == null) {
5408 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5409
5410 // device does not support IMS, this method will return true always.
5411 return true;
5412 }
5413 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005414 } finally {
5415 Binder.restoreCallingIdentity(identity);
5416 }
5417 }
5418
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005419 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005420 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5421 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005422 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005423
joonhunshin4ac60942023-11-15 15:23:39 +00005424 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5425 FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability");
5426
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005427 final long identity = Binder.clearCallingIdentity();
5428 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005429 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5430 if (controller == null) {
5431 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5432 return;
5433 }
5434 controller.setImsProvisioningStatusForCapability(
5435 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005436 } finally {
5437 Binder.restoreCallingIdentity(identity);
5438 }
5439 }
5440
5441 @Override
5442 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005443 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5444 mApp, subId, "getProvisioningStatusForCapability");
5445
joonhunshin4ac60942023-11-15 15:23:39 +00005446 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5447 FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability");
5448
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005449 final long identity = Binder.clearCallingIdentity();
5450 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005451 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5452 if (controller == null) {
5453 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005454
joonhunshin91bc1952022-04-29 08:47:15 +00005455 // device does not support IMS, this method will return true always.
5456 return true;
5457 }
5458 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005459 } finally {
5460 Binder.restoreCallingIdentity(identity);
5461 }
5462 }
5463
5464 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005465 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5466 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5467 mApp, subId, "isProvisioningRequiredForCapability");
5468
joonhunshin4ac60942023-11-15 15:23:39 +00005469 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5470 FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability");
5471
joonhunshincffb7fc2021-11-28 07:32:01 +00005472 final long identity = Binder.clearCallingIdentity();
5473 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005474 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5475 if (controller == null) {
5476 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5477
5478 // device does not support IMS, this method will return false
5479 return false;
5480 }
5481 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005482 } finally {
5483 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005484 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005485 }
5486
5487 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005488 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5489 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5490 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005491
joonhunshin4ac60942023-11-15 15:23:39 +00005492 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5493 FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability");
5494
joonhunshincffb7fc2021-11-28 07:32:01 +00005495 final long identity = Binder.clearCallingIdentity();
5496 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005497 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5498 if (controller == null) {
5499 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5500
5501 // device does not support IMS, this method will return false
5502 return false;
5503 }
5504 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005505 } finally {
5506 Binder.restoreCallingIdentity(identity);
5507 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005508 }
5509
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005510 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005511 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005512 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5513 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5514 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005515 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5516 mApp, subId, "getImsProvisioningInt");
5517
joonhunshin4ac60942023-11-15 15:23:39 +00005518 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5519 FEATURE_TELEPHONY_IMS, "getImsProvisioningInt");
5520
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005521 final long identity = Binder.clearCallingIdentity();
5522 try {
5523 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005524 int slotId = getSlotIndex(subId);
5525 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5526 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5527 + subId + "' for key:" + key);
5528 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5529 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005530
joonhunshin91bc1952022-04-29 08:47:15 +00005531 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5532 if (controller == null) {
5533 loge("getImsProvisioningInt: Device does not support IMS");
5534
5535 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5536 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5537 }
5538 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005539 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5540 return retVal;
5541 }
5542
calvinpanb5a34062021-02-08 19:59:36 +08005543 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005544 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005545 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5546 + subId + "' for key:" + key);
5547 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005548 } finally {
5549 Binder.restoreCallingIdentity(identity);
5550 }
5551 }
5552
5553 @Override
5554 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005555 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5556 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5557 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005558 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5559 mApp, subId, "getImsProvisioningString");
5560
joonhunshin4ac60942023-11-15 15:23:39 +00005561 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5562 FEATURE_TELEPHONY_IMS, "getImsProvisioningString");
5563
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005564 final long identity = Binder.clearCallingIdentity();
5565 try {
5566 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005567 int slotId = getSlotIndex(subId);
5568 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5569 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5570 + subId + "' for key:" + key);
5571 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5572 }
calvinpanb5a34062021-02-08 19:59:36 +08005573 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005574 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005575 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5576 + subId + "' for key:" + key);
5577 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005578 } finally {
5579 Binder.restoreCallingIdentity(identity);
5580 }
5581 }
5582
5583 @Override
5584 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005585 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5586 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5587 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005588 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5589 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005590
joonhunshin4ac60942023-11-15 15:23:39 +00005591 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5592 FEATURE_TELEPHONY_IMS, "setImsProvisioningInt");
5593
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005594 final long identity = Binder.clearCallingIdentity();
5595 try {
5596 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005597 int slotId = getSlotIndex(subId);
5598 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5599 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5600 + subId + "' for key:" + key);
5601 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5602 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005603
joonhunshin91bc1952022-04-29 08:47:15 +00005604 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5605 if (controller == null) {
5606 loge("setImsProvisioningInt: Device does not support IMS");
5607
5608 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5609 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5610 }
5611 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005612 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5613 return retVal;
5614 }
5615
calvinpanb5a34062021-02-08 19:59:36 +08005616 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5617 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005618 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005619 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005620 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005621 } finally {
5622 Binder.restoreCallingIdentity(identity);
5623 }
5624 }
5625
5626 @Override
5627 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005628 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5629 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5630 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005631 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5632 "setImsProvisioningString");
joonhunshin4ac60942023-11-15 15:23:39 +00005633
5634 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5635 FEATURE_TELEPHONY_IMS, "setImsProvisioningString");
5636
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005637 final long identity = Binder.clearCallingIdentity();
5638 try {
5639 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005640 int slotId = getSlotIndex(subId);
5641 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5642 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5643 + subId + "' for key:" + key);
5644 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5645 }
calvinpanb5a34062021-02-08 19:59:36 +08005646 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5647 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005648 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005649 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005650 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005651 } finally {
5652 Binder.restoreCallingIdentity(identity);
5653 }
5654 }
5655
Brad Ebinger919631e2021-06-02 17:46:35 -07005656 /**
5657 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5658 * for the given slot ID or no ImsResolver instance has been created.
5659 * @param slotId The slot ID that the IMS service is created for.
5660 * @throws ImsException If there is no ImsService configured for this slot.
5661 */
5662 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5663 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5664 ImsFeature.FEATURE_MMTEL)) {
5665 throw new ImsException("This subscription does not support MMTEL over IMS",
5666 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5667 }
5668 }
5669
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005670 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005671 int slotId = SubscriptionManager.getSlotIndex(subId);
5672 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005673 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5674 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005675 }
5676 return slotId;
5677 }
5678
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005679 private int getSlotIndex(int subId) {
5680 int slotId = SubscriptionManager.getSlotIndex(subId);
5681 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5682 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5683 }
5684 return slotId;
5685 }
5686
Wink Saville36469e72014-06-11 15:17:00 -07005687 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005688 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005689 */
5690 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005691 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5692 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005693 try {
5694 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5695 } catch (SecurityException se) {
5696 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5697 throw new SecurityException("Package " + callingPackage + " does not belong to "
5698 + Binder.getCallingUid());
5699 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005700 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005701 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005702 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005703 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005704 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005705 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005706 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005707 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5708 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005709
joonhunshin4ac60942023-11-15 15:23:39 +00005710 enforceTelephonyFeatureWithException(callingPackage,
5711 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber");
5712
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005713 final long identity = Binder.clearCallingIdentity();
5714 try {
5715 final Phone phone = getPhone(subId);
5716 if (phone != null) {
5717 return phone.getServiceState().getDataNetworkType();
5718 } else {
5719 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5720 }
5721 } finally {
5722 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005723 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005724 }
5725
5726 /**
5727 * Returns the data network type
5728 */
5729 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005730 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005731 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005732 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005733 }
5734
5735 /**
5736 * Returns the data network type for a subId
5737 */
5738 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005739 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5740 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005741 String functionName = "getDataNetworkTypeForSubscriber";
5742 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5743 mApp, functionName)) {
5744 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5745 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5746 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5747 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005748 }
5749
joonhunshin4ac60942023-11-15 15:23:39 +00005750 enforceTelephonyFeatureWithException(callingPackage,
5751 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber");
5752
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005753 final long identity = Binder.clearCallingIdentity();
5754 try {
5755 final Phone phone = getPhone(subId);
5756 if (phone != null) {
5757 return phone.getServiceState().getDataNetworkType();
5758 } else {
5759 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5760 }
5761 } finally {
5762 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005763 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005764 }
5765
5766 /**
Wink Saville36469e72014-06-11 15:17:00 -07005767 * Returns the Voice network type for a subId
5768 */
5769 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005770 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5771 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005772 String functionName = "getVoiceNetworkTypeForSubscriber";
5773 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5774 mApp, functionName)) {
5775 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5776 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5777 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5778 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005779 }
5780
joonhunshin4ac60942023-11-15 15:23:39 +00005781 enforceTelephonyFeatureWithException(callingPackage,
5782 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber");
5783
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005784 final long identity = Binder.clearCallingIdentity();
5785 try {
5786 final Phone phone = getPhone(subId);
5787 if (phone != null) {
5788 return phone.getServiceState().getVoiceNetworkType();
5789 } else {
5790 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5791 }
5792 } finally {
5793 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005794 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005795 }
5796
5797 /**
5798 * @return true if a ICC card is present
5799 */
5800 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005801 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005802 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005803 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005804 }
5805
5806 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005807 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005808 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005809 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005810 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00005811 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5812 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex");
5813
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005814 final long identity = Binder.clearCallingIdentity();
5815 try {
5816 final Phone phone = PhoneFactory.getPhone(slotIndex);
5817 if (phone != null) {
5818 return phone.getIccCard().hasIccCard();
5819 } else {
5820 return false;
5821 }
5822 } finally {
5823 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005824 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005825 }
5826
5827 /**
5828 * Return if the current radio is LTE on CDMA. This
5829 * is a tri-state return value as for a period of time
5830 * the mode may be unknown.
5831 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005832 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005833 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005834 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005835 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005836 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005837 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5838 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5839 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005840 }
5841
Sanket Padawe356d7632015-06-22 14:03:32 -07005842 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005843 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5844 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005845 try {
5846 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5847 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005848 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5849 }
5850
joonhunshin4ac60942023-11-15 15:23:39 +00005851 enforceTelephonyFeatureWithException(callingPackage,
5852 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber");
5853
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005854 final long identity = Binder.clearCallingIdentity();
5855 try {
5856 final Phone phone = getPhone(subId);
5857 if (phone == null) {
5858 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5859 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005860 return TelephonyProperties.lte_on_cdma_device()
5861 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005862 }
5863 } finally {
5864 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005865 }
Wink Saville36469e72014-06-11 15:17:00 -07005866 }
5867
Wink Saville36469e72014-06-11 15:17:00 -07005868 /**
5869 * {@hide}
5870 * Returns Default subId, 0 in the case of single standby.
5871 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005872 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005873 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005874 }
5875
Shishir Agrawala9f32182016-04-12 12:00:16 -07005876 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005877 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005878 }
5879
Wink Savilleb564aae2014-10-23 10:18:09 -07005880 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005881 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005882 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005883
Pengquan Menge92a50d2018-09-21 15:54:48 -07005884 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005885 return getSubscriptionManagerService().isActiveSubId(subId,
5886 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005887 }
5888
Ihab Awadf2177b72013-11-25 13:33:23 -08005889 /**
5890 * @see android.telephony.TelephonyManager.WifiCallingChoices
5891 */
5892 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005893 final long identity = Binder.clearCallingIdentity();
5894 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005895 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005896 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5897 getWhenToMakeWifiCallsDefaultPreference());
5898 } finally {
5899 Binder.restoreCallingIdentity(identity);
5900 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005901 }
5902
5903 /**
5904 * @see android.telephony.TelephonyManager.WifiCallingChoices
5905 */
5906 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005907 final long identity = Binder.clearCallingIdentity();
5908 try {
5909 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005910 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005911 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5912 } finally {
5913 Binder.restoreCallingIdentity(identity);
5914 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005915 }
5916
Sailesh Nepald1e68152013-12-12 19:08:02 -08005917 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005918 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005919 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005920 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005921
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005922 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5923 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5924 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005925 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005926 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005927 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005928 }
5929 return PhoneFactory.getPhone(phoneId);
5930 }
5931
Shishir Agrawal566b7612013-10-28 14:41:00 -07005932 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005933 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005934 @NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00005935
Rambo Wanga1782702021-11-10 20:15:19 -08005936 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5937 /*message=*/ "iccOpenLogicalChannel");
5938
5939 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5940 // Verify that the callingPackage in the request belongs to the calling UID
5941 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5942
joonhunshin4ac60942023-11-15 15:23:39 +00005943 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5944 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel");
5945
Rambo Wanga1782702021-11-10 20:15:19 -08005946 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005947 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005948
Rambo Wanga1782702021-11-10 20:15:19 -08005949 private Phone getPhoneFromValidIccLogicalChannelRequest(
5950 @NonNull IccLogicalChannelRequest request, String message) {
5951 Phone phone;
5952 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5953 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5954 mApp, request.subId, message);
5955 phone = getPhoneFromSubId(request.subId);
5956 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5957 enforceModifyPermission();
5958 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5959 } else {
5960 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005961 }
Rambo Wanga1782702021-11-10 20:15:19 -08005962 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005963 }
5964
5965 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005966 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005967 final long identity = Binder.clearCallingIdentity();
5968 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005969 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005970 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005971 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5972 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005973 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5974 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005975 loge("The calling package is not allowed to access ISD-R.");
5976 throw new SecurityException(
5977 "The calling package is not allowed to access ISD-R.");
5978 }
Derek Tan740e1672017-06-27 14:56:27 -07005979 }
Derek Tan740e1672017-06-27 14:56:27 -07005980
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005981 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005982 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5983 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005984 return response;
5985 } finally {
5986 Binder.restoreCallingIdentity(identity);
5987 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005988 }
5989
5990 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005991 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00005992 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5993 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel");
5994
Rambo Wanga1782702021-11-10 20:15:19 -08005995 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5996 /*message=*/"iccCloseLogicalChannel");
5997
5998 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5999
6000 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006001 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006002
Rambo Wanga1782702021-11-10 20:15:19 -08006003 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
6004 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08006005 // before this feature is enabled, this API should only return false if
6006 // the operation fails instead of throwing runtime exception for
6007 // backward-compatibility.
6008 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
6009 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006010 final long identity = Binder.clearCallingIdentity();
6011 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006012 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08006013 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006014 }
Chen Xue9d737e2022-01-01 23:41:31 -08006015 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08006016 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08006017 Boolean success = false;
6018 if (result instanceof RuntimeException) {
6019 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08006020 if (shouldThrowExceptionOnFailure) {
6021 throw (RuntimeException) result;
6022 } else {
6023 return false;
6024 }
Chen Xue9d737e2022-01-01 23:41:31 -08006025 } else if (result instanceof Boolean) {
6026 success = (Boolean) result;
6027 } else {
6028 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
6029 }
Rambo Wanga1782702021-11-10 20:15:19 -08006030 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006031 return success;
6032 } finally {
6033 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006034 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006035 }
6036
6037 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006038 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07006039 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006040 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6041 mApp, subId, "iccTransmitApduLogicalChannel");
joonhunshin4ac60942023-11-15 15:23:39 +00006042
6043 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6044 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel");
6045
Jordan Liu4c733742019-02-28 12:03:40 -08006046 if (DBG) {
6047 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
6048 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
6049 + p3 + " data=" + data);
6050 }
6051 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
6052 command, p1, p2, p3, data);
6053 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006054
Jordan Liu4c733742019-02-28 12:03:40 -08006055 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006056 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006057 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006058 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006059
6060 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6061 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
6062 "iccTransmitApduLogicalChannelBySlot");
6063
Jordan Liu4c733742019-02-28 12:03:40 -08006064 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006065 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006066 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
6067 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006068 }
6069 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006070 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
6071 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006072 }
6073
6074 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
6075 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006076 final long identity = Binder.clearCallingIdentity();
6077 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07006078 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006079 return "";
6080 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006081
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006082 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006083 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
6084 null /* workSource */);
6085 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006086
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006087 // Append the returned status code to the end of the response payload.
6088 String s = Integer.toHexString(
6089 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6090 if (response.payload != null) {
6091 s = IccUtils.bytesToHexString(response.payload) + s;
6092 }
6093 return s;
6094 } finally {
6095 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006096 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006097 }
Jake Hambye994d462014-02-03 13:10:13 -08006098
Evan Charltonc66da362014-05-16 14:06:40 -07006099 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006100 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
6101 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006102 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6103 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006104 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006105
6106 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6107 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel");
6108
Jordan Liu4c733742019-02-28 12:03:40 -08006109 if (DBG) {
6110 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
6111 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
6112 }
6113 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
6114 cla, command, p1, p2, p3, data);
6115 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006116
Jordan Liu4c733742019-02-28 12:03:40 -08006117 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006118 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006119 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006120 enforceModifyPermission();
6121 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006122
6123 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6124 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot");
6125
Jordan Liu4c733742019-02-28 12:03:40 -08006126 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006127 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006128 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
6129 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006130 }
6131
6132 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006133 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
6134 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006135 }
6136
6137 // open APDU basic channel assuming the caller has sufficient permissions
6138 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
6139 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006140 final long identity = Binder.clearCallingIdentity();
6141 try {
6142 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
6143 && TextUtils.equals(ISDR_AID, data)) {
6144 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006145 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6146 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006147 if (bestComponent == null
6148 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
6149 loge("The calling package is not allowed to select ISD-R.");
6150 throw new SecurityException(
6151 "The calling package is not allowed to select ISD-R.");
6152 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006153 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006154
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006155 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006156 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
6157 null /* workSource */);
6158 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006159
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006160 // Append the returned status code to the end of the response payload.
6161 String s = Integer.toHexString(
6162 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6163 if (response.payload != null) {
6164 s = IccUtils.bytesToHexString(response.payload) + s;
6165 }
6166 return s;
6167 } finally {
6168 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006169 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006170 }
6171
6172 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006173 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006174 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006175 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6176 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006177
joonhunshin4ac60942023-11-15 15:23:39 +00006178 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6179 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO");
6180
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006181 final long identity = Binder.clearCallingIdentity();
6182 try {
6183 if (DBG) {
6184 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
6185 + p1 + " " + p2 + " " + p3 + ":" + filePath);
6186 }
6187
6188 IccIoResult response =
6189 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
6190 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
6191 subId);
6192
6193 if (DBG) {
6194 log("Exchange SIM_IO [R]" + response);
6195 }
6196
6197 byte[] result = null;
6198 int length = 2;
6199 if (response.payload != null) {
6200 length = 2 + response.payload.length;
6201 result = new byte[length];
6202 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
6203 } else {
6204 result = new byte[length];
6205 }
6206
6207 result[length - 1] = (byte) response.sw2;
6208 result[length - 2] = (byte) response.sw1;
6209 return result;
6210 } finally {
6211 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006212 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006213 }
6214
Nathan Haroldb3014052017-01-25 15:57:32 -08006215 /**
6216 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
6217 * on a particular subscription
6218 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006219 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
6220 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07006221 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006222 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07006223 return null;
6224 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006225
joonhunshin4ac60942023-11-15 15:23:39 +00006226 enforceTelephonyFeatureWithException(callingPackage,
6227 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns");
6228
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006229 final long identity = Binder.clearCallingIdentity();
6230 try {
6231 if (appType != TelephonyManager.APPTYPE_USIM
6232 && appType != TelephonyManager.APPTYPE_SIM) {
6233 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
6234 return null;
6235 }
6236 Object response = sendRequest(
6237 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
6238 if (response instanceof String[]) {
6239 return (String[]) response;
6240 }
yincheng zhao2737e882019-09-06 17:06:54 -07006241 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006242 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08006243 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006244 } finally {
6245 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08006246 }
Nathan Haroldb3014052017-01-25 15:57:32 -08006247 }
6248
yincheng zhao2737e882019-09-06 17:06:54 -07006249 /**
6250 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
6251 * subscription.
6252 *
6253 * @param subId the id of the subscription.
6254 * @param appType the uicc app type, must be USIM or SIM.
6255 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
6256 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006257 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07006258 * @return number of fplmns that is successfully written to the SIM.
6259 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006260 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
6261 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07006262 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6263 mApp, subId, "setForbiddenPlmns");
6264
joonhunshin4ac60942023-11-15 15:23:39 +00006265 enforceTelephonyFeatureWithException(callingPackage,
6266 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns");
6267
yincheng zhao2737e882019-09-06 17:06:54 -07006268 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
6269 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
6270 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
6271 }
6272 if (fplmns == null) {
6273 throw new IllegalArgumentException("Fplmn List provided is null");
6274 }
6275 for (String fplmn : fplmns) {
6276 if (!CellIdentity.isValidPlmn(fplmn)) {
6277 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
6278 }
6279 }
6280 final long identity = Binder.clearCallingIdentity();
6281 try {
6282 Object response = sendRequest(
6283 CMD_SET_FORBIDDEN_PLMNS,
6284 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
6285 subId);
6286 return (int) response;
6287 } finally {
6288 Binder.restoreCallingIdentity(identity);
6289 }
6290 }
6291
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006292 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006293 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006294 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6295 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07006296
joonhunshin4ac60942023-11-15 15:23:39 +00006297 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6298 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus");
6299
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006300 final long identity = Binder.clearCallingIdentity();
6301 try {
6302 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
6303 if (response.payload == null) {
6304 return "";
6305 }
Evan Charltonc66da362014-05-16 14:06:40 -07006306
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006307 // Append the returned status code to the end of the response payload.
6308 String s = Integer.toHexString(
6309 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6310 s = IccUtils.bytesToHexString(response.payload) + s;
6311 return s;
6312 } finally {
6313 Binder.restoreCallingIdentity(identity);
6314 }
Evan Charltonc66da362014-05-16 14:06:40 -07006315 }
6316
Jake Hambye994d462014-02-03 13:10:13 -08006317 /**
6318 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6319 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6320 *
6321 * @param itemID the ID of the item to read
6322 * @return the NV item as a String, or null on error.
6323 */
6324 @Override
6325 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006326 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006327 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6328 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006329
6330 final long identity = Binder.clearCallingIdentity();
6331 try {
6332 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07006333 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006334 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
6335 return value;
6336 } finally {
6337 Binder.restoreCallingIdentity(identity);
6338 }
Jake Hambye994d462014-02-03 13:10:13 -08006339 }
6340
6341 /**
6342 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6343 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6344 *
6345 * @param itemID the ID of the item to read
6346 * @param itemValue the value to write, as a String
6347 * @return true on success; false on any failure
6348 */
6349 @Override
6350 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006351 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006352 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6353 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006354
6355 final long identity = Binder.clearCallingIdentity();
6356 try {
6357 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6358 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006359 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006360 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6361 return success;
6362 } finally {
6363 Binder.restoreCallingIdentity(identity);
6364 }
Jake Hambye994d462014-02-03 13:10:13 -08006365 }
6366
6367 /**
6368 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6369 * Used for device configuration by some CDMA operators.
6370 *
6371 * @param preferredRoamingList byte array containing the new PRL
6372 * @return true on success; false on any failure
6373 */
6374 @Override
6375 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006376 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6377 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006378
6379 final long identity = Binder.clearCallingIdentity();
6380 try {
6381 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6382 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6383 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6384 return success;
6385 } finally {
6386 Binder.restoreCallingIdentity(identity);
6387 }
Jake Hambye994d462014-02-03 13:10:13 -08006388 }
6389
6390 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006391 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006392 * Used for device configuration by some CDMA operators.
6393 *
chen xu6dac5ab2018-10-26 17:39:23 -07006394 * @param slotIndex - device slot.
6395 *
Jake Hambye994d462014-02-03 13:10:13 -08006396 * @return true on success; false on any failure
6397 */
6398 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006399 public boolean resetModemConfig(int slotIndex) {
6400 Phone phone = PhoneFactory.getPhone(slotIndex);
6401 if (phone != null) {
6402 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6403 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006404
joonhunshin4ac60942023-11-15 15:23:39 +00006405 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6406 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig");
6407
chen xu6dac5ab2018-10-26 17:39:23 -07006408 final long identity = Binder.clearCallingIdentity();
6409 try {
6410 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6411 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6412 return success;
6413 } finally {
6414 Binder.restoreCallingIdentity(identity);
6415 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006416 }
chen xu6dac5ab2018-10-26 17:39:23 -07006417 return false;
6418 }
6419
6420 /**
6421 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6422 *
6423 * @param slotIndex - device slot.
6424 *
6425 * @return true on success; false on any failure
6426 */
6427 @Override
6428 public boolean rebootModem(int slotIndex) {
6429 Phone phone = PhoneFactory.getPhone(slotIndex);
6430 if (phone != null) {
6431 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6432 mApp, phone.getSubId(), "rebootModem");
6433
joonhunshin4ac60942023-11-15 15:23:39 +00006434 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6435 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem");
6436
chen xu6dac5ab2018-10-26 17:39:23 -07006437 final long identity = Binder.clearCallingIdentity();
6438 try {
6439 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6440 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6441 return success;
6442 } finally {
6443 Binder.restoreCallingIdentity(identity);
6444 }
6445 }
6446 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006447 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006448
Brad Ebinger51f743a2017-01-23 13:50:20 -08006449 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006450 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6451 * {@link #disableIms(int)}.
6452 * @param slotIndex device slot.
6453 */
6454 public void resetIms(int slotIndex) {
6455 enforceModifyPermission();
6456
joonhunshin4ac60942023-11-15 15:23:39 +00006457 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6458 PackageManager.FEATURE_TELEPHONY_IMS, "resetIms");
6459
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006460 final long identity = Binder.clearCallingIdentity();
6461 try {
6462 if (mImsResolver == null) {
6463 // may happen if the does not support IMS.
6464 return;
6465 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006466 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006467 } finally {
6468 Binder.restoreCallingIdentity(identity);
6469 }
6470 }
6471
6472 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006473 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6474 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006475 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006476 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006477 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006478
6479 final long identity = Binder.clearCallingIdentity();
6480 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006481 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006482 // may happen if the device does not support IMS.
6483 return;
6484 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006485 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006486 } finally {
6487 Binder.restoreCallingIdentity(identity);
6488 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006489 }
6490
6491 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006492 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6493 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006494 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006495 public void disableIms(int slotId) {
6496 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006497
6498 final long identity = Binder.clearCallingIdentity();
6499 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006500 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006501 // may happen if the device does not support IMS.
6502 return;
6503 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006504 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006505 } finally {
6506 Binder.restoreCallingIdentity(identity);
6507 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006508 }
6509
6510 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006511 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6512 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006513 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006514 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006515 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006516 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006517
6518 final long identity = Binder.clearCallingIdentity();
6519 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006520 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006521 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6522 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006523 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006524 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006525 } finally {
6526 Binder.restoreCallingIdentity(identity);
6527 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006528 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006529 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006530 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6531 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006532 @Override
6533 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006534 enforceModifyPermission();
6535
6536 final long identity = Binder.clearCallingIdentity();
6537 try {
6538 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006539 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006540 } finally {
6541 Binder.restoreCallingIdentity(identity);
6542 }
6543 }
6544
6545 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006546 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006547 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006548 */
6549 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6550 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 Ebinger9c0eb502019-01-23 15:06:19 -08006555 // may happen if the device does not support IMS.
6556 return null;
6557 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006558 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006559 } finally {
6560 Binder.restoreCallingIdentity(identity);
6561 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006562 }
6563
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006564 /**
6565 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006566 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006567 */
6568 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6569 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006570
6571 final long identity = Binder.clearCallingIdentity();
6572 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006573 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006574 // may happen if the device does not support IMS.
6575 return null;
6576 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006577 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006578 } finally {
6579 Binder.restoreCallingIdentity(identity);
6580 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006581 }
6582
Brad Ebinger884c07b2018-02-15 16:17:40 -08006583 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006584 * Sets the ImsService Package Name that Telephony will bind to.
6585 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006586 * @param slotIndex the slot ID that the ImsService should bind for.
6587 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006588 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006589 * @param featureTypes An integer array of feature types associated with a packageName.
6590 * @param packageName The name of the package that the current configuration will be replaced
6591 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006592 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006593 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006594 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6595 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006596 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006597 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006598 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006599
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006600 final long identity = Binder.clearCallingIdentity();
6601 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006602 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006603 // may happen if the device does not support IMS.
6604 return false;
6605 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006606 Map<Integer, String> featureConfig = new HashMap<>();
6607 for (int featureType : featureTypes) {
6608 featureConfig.put(featureType, packageName);
6609 }
6610 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6611 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006612 } finally {
6613 Binder.restoreCallingIdentity(identity);
6614 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006615 }
6616
6617 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006618 * Clears any carrier ImsService overrides for the slot index specified that were previously
6619 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6620 *
6621 * This should only be used for testing.
6622 *
6623 * @param slotIndex the slot ID that the ImsService should bind for.
6624 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6625 */
6626 @Override
6627 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006628 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6629 "clearCarrierImsServiceOverride");
6630 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006631 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006632
6633 final long identity = Binder.clearCallingIdentity();
6634 try {
6635 if (mImsResolver == null) {
6636 // may happen if the device does not support IMS.
6637 return false;
6638 }
6639 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6640 } finally {
6641 Binder.restoreCallingIdentity(identity);
6642 }
6643 }
6644
6645 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006646 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006647 *
6648 * @param slotId The slot that the ImsService is associated with.
6649 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6650 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006651 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006652 * @return the package name of the ImsService configuration.
6653 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006654 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6655 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006656 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006657 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6658 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006659
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006660 final long identity = Binder.clearCallingIdentity();
6661 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006662 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006663 // may happen if the device does not support IMS.
6664 return "";
6665 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006666 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006667 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6668 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006669 } finally {
6670 Binder.restoreCallingIdentity(identity);
6671 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006672 }
6673
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006674 /**
6675 * Get the MmTelFeature state associated with the requested subscription id.
6676 * @param subId The subscription that the MmTelFeature is associated with.
6677 * @param callback A callback with an integer containing the
6678 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6679 */
6680 @Override
6681 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6682 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006683 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6684 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6685 "IMS not available on device.");
6686 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006687 final long token = Binder.clearCallingIdentity();
6688 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006689 int slotId = getSlotIndex(subId);
6690 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6691 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6692 + subId + "'");
6693 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6694 }
6695 verifyImsMmTelConfiguredOrThrow(slotId);
6696 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6697 try {
6698 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6699 } catch (RemoteException e) {
6700 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6701 + "Ignore");
6702 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006703 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006704 } catch (ImsException e) {
6705 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006706 } finally {
6707 Binder.restoreCallingIdentity(token);
6708 }
6709 }
6710
Daniel Brightbb5840b2021-01-12 15:48:18 -08006711 /**
6712 * Sets the ims registration state on all valid {@link Phone}s.
6713 */
6714 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006715 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006716
6717 final long identity = Binder.clearCallingIdentity();
6718 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006719 // NOTE: Before S, this method only set the default phone.
6720 for (final Phone phone : PhoneFactory.getPhones()) {
6721 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6722 phone.setImsRegistrationState(registered);
6723 }
6724 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006725 } finally {
6726 Binder.restoreCallingIdentity(identity);
6727 }
Wink Saville36469e72014-06-11 15:17:00 -07006728 }
6729
6730 /**
Stuart Scott54788802015-03-30 13:18:01 -07006731 * Set the network selection mode to automatic.
6732 *
6733 */
6734 @Override
6735 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006736 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6737 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006738
joonhunshin4ac60942023-11-15 15:23:39 +00006739 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6740 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic");
6741
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006742 final long identity = Binder.clearCallingIdentity();
6743 try {
shilufc958392020-01-20 11:36:01 -08006744 if (!isActiveSubscription(subId)) {
6745 return;
6746 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006747 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006748 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6749 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006750 } finally {
6751 Binder.restoreCallingIdentity(identity);
6752 }
Stuart Scott54788802015-03-30 13:18:01 -07006753 }
6754
Jack Yud10cdd42020-09-28 20:28:01 -07006755 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006756 * Ask the radio to connect to the input network and change selection mode to manual.
6757 *
6758 * @param subId the id of the subscription.
6759 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6760 * the operator to attach to.
6761 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6762 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6763 * normal network selection next time.
6764 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006765 */
6766 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006767 public boolean setNetworkSelectionModeManual(
6768 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006769 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6770 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006771
joonhunshin4ac60942023-11-15 15:23:39 +00006772 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6773 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual");
6774
Jack Yu285100e2022-12-02 22:48:35 -08006775 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006776 if (!isActiveSubscription(subId)) {
6777 return false;
6778 }
6779
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006780 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006781 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006782 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006783 if (DBG) {
6784 log("setNetworkSelectionModeManual: subId: " + subId
6785 + " operator: " + operatorInfo);
6786 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006787 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6788 } finally {
6789 Binder.restoreCallingIdentity(identity);
6790 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006791 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006792 /**
shilu84f6e8b2019-12-19 13:58:01 -08006793 * Get the manual network selection
6794 *
6795 * @param subId the id of the subscription.
6796 *
6797 * @return the previously saved user selected PLMN
6798 */
6799 @Override
6800 public String getManualNetworkSelectionPlmn(int subId) {
6801 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006802 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6803 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006804
joonhunshin4ac60942023-11-15 15:23:39 +00006805 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6806 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn");
6807
shilu84f6e8b2019-12-19 13:58:01 -08006808 final long identity = Binder.clearCallingIdentity();
6809 try {
6810 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006811 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006812 }
6813
6814 final Phone phone = getPhone(subId);
6815 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006816 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006817 }
6818 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6819 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006820 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006821 } finally {
6822 Binder.restoreCallingIdentity(identity);
6823 }
6824 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006825
6826 /**
6827 * Scans for available networks.
6828 */
6829 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006830 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6831 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006832 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6833 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006834 LocationAccessPolicy.LocationPermissionResult locationResult =
6835 LocationAccessPolicy.checkLocationPermission(mApp,
6836 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6837 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006838 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006839 .setCallingPid(Binder.getCallingPid())
6840 .setCallingUid(Binder.getCallingUid())
6841 .setMethod("getCellNetworkScanResults")
6842 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006843 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6844 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006845 .build());
6846 switch (locationResult) {
6847 case DENIED_HARD:
6848 throw new SecurityException("Not allowed to access scan results -- location");
6849 case DENIED_SOFT:
6850 return null;
6851 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006852
Pengquan Menga1bb6272018-09-06 09:59:22 -07006853 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006854 try {
6855 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006856 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006857 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006858 } finally {
6859 Binder.restoreCallingIdentity(identity);
6860 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006861 }
6862
6863 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006864 * Get the call forwarding info, given the call forwarding reason.
6865 */
6866 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006867 public void getCallForwarding(int subId, int callForwardingReason,
6868 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006869 enforceReadPrivilegedPermission("getCallForwarding");
joonhunshin4ac60942023-11-15 15:23:39 +00006870
6871 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6872 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding");
6873
Shuo Qian4a594052020-01-23 11:59:30 -08006874 long identity = Binder.clearCallingIdentity();
6875 try {
6876 if (DBG) {
6877 log("getCallForwarding: subId " + subId
6878 + " callForwardingReason" + callForwardingReason);
6879 }
Hall Liu27d24262020-09-18 19:04:59 -07006880
6881 Phone phone = getPhone(subId);
6882 if (phone == null) {
6883 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006884 callback.onError(
6885 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006886 } catch (RemoteException e) {
6887 // ignore
6888 }
6889 return;
6890 }
6891
6892 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6893 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6894 @Override
6895 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6896 try {
6897 callback.onCallForwardingInfoAvailable(info);
6898 } catch (RemoteException e) {
6899 // ignore
6900 }
6901 }
6902
6903 @Override
6904 public void onError(int error) {
6905 try {
6906 callback.onError(error);
6907 } catch (RemoteException e) {
6908 // ignore
6909 }
6910 }
6911 });
6912 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006913 } finally {
6914 Binder.restoreCallingIdentity(identity);
6915 }
6916 }
6917
6918 /**
6919 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6920 * reason, the number to forward, and the timeout before the forwarding is attempted.
6921 */
6922 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006923 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6924 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006925 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006926
6927 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6928 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding");
6929
Shuo Qian4a594052020-01-23 11:59:30 -08006930 long identity = Binder.clearCallingIdentity();
6931 try {
6932 if (DBG) {
6933 log("setCallForwarding: subId " + subId
6934 + " callForwardingInfo" + callForwardingInfo);
6935 }
Hall Liu27d24262020-09-18 19:04:59 -07006936
6937 Phone phone = getPhone(subId);
6938 if (phone == null) {
6939 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006940 callback.accept(
6941 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006942 } catch (RemoteException e) {
6943 // ignore
6944 }
6945 return;
6946 }
6947
6948 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6949 FunctionalUtils.ignoreRemoteException(callback::accept));
6950
6951 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006952 } finally {
6953 Binder.restoreCallingIdentity(identity);
6954 }
6955 }
6956
6957 /**
Hall Liu27d24262020-09-18 19:04:59 -07006958 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006959 */
6960 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006961 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006962 enforceReadPrivilegedPermission("getCallWaitingStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00006963
6964 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6965 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus");
6966
Shuo Qian4a594052020-01-23 11:59:30 -08006967 long identity = Binder.clearCallingIdentity();
6968 try {
Hall Liu27d24262020-09-18 19:04:59 -07006969 Phone phone = getPhone(subId);
6970 if (phone == null) {
6971 try {
6972 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6973 } catch (RemoteException e) {
6974 // ignore
6975 }
6976 return;
6977 }
SongFerngWang0e767992021-03-31 22:08:45 +08006978 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6979 PersistableBundle c = configManager.getConfigForSubId(subId);
6980 boolean requireUssd = c.getBoolean(
6981 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006982
Shuo Qian4a594052020-01-23 11:59:30 -08006983 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006984 if (requireUssd) {
6985 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6986 getSubscriptionCarrierId(subId));
6987 String newUssdCommand = "";
6988 try {
6989 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006990 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006991 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6992 } catch (NullPointerException e) {
6993 loge("Failed to generate USSD number" + e);
6994 }
6995 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6996 mMainThreadHandler, callback, carrierXmlParser,
6997 CarrierXmlParser.SsEntry.SSAction.QUERY);
6998 final String ussdCommand = newUssdCommand;
6999 Executors.newSingleThreadExecutor().execute(() -> {
7000 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7001 });
7002 } else {
7003 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
7004 callback::accept);
7005 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
7006 }
Shuo Qian4a594052020-01-23 11:59:30 -08007007 } finally {
7008 Binder.restoreCallingIdentity(identity);
7009 }
7010 }
7011
7012 /**
Hall Liu27d24262020-09-18 19:04:59 -07007013 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007014 */
7015 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007016 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007017 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007018
7019 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7020 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus");
7021
Shuo Qian4a594052020-01-23 11:59:30 -08007022 long identity = Binder.clearCallingIdentity();
7023 try {
Hall Liu27d24262020-09-18 19:04:59 -07007024 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
7025
7026 Phone phone = getPhone(subId);
7027 if (phone == null) {
7028 try {
7029 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7030 } catch (RemoteException e) {
7031 // ignore
7032 }
7033 return;
7034 }
7035
SongFerngWang0e767992021-03-31 22:08:45 +08007036 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7037 PersistableBundle c = configManager.getConfigForSubId(subId);
7038 boolean requireUssd = c.getBoolean(
7039 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007040
SongFerngWang0e767992021-03-31 22:08:45 +08007041 if (DBG) log("getCallWaitingStatus: subId " + subId);
7042 if (requireUssd) {
7043 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7044 getSubscriptionCarrierId(subId));
7045 CarrierXmlParser.SsEntry.SSAction ssAction =
7046 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
7047 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
7048 String newUssdCommand = "";
7049 try {
7050 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007051 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007052 .makeCommand(ssAction, null);
7053 } catch (NullPointerException e) {
7054 loge("Failed to generate USSD number" + e);
7055 }
7056 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7057 mMainThreadHandler, callback, carrierXmlParser, ssAction);
7058 final String ussdCommand = newUssdCommand;
7059 Executors.newSingleThreadExecutor().execute(() -> {
7060 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7061 });
7062 } else {
7063 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
7064 FunctionalUtils.ignoreRemoteException(callback::accept));
7065
7066 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
7067 }
Shuo Qian4a594052020-01-23 11:59:30 -08007068 } finally {
7069 Binder.restoreCallingIdentity(identity);
7070 }
7071 }
7072
7073 /**
yinxub1bed742017-04-17 11:45:04 -07007074 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07007075 *
yinxub1bed742017-04-17 11:45:04 -07007076 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007077 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
7078 * location related information which will be sent if the caller already possess
7079 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07007080 * @param request contains the radio access networks with bands/channels to scan
7081 * @param messenger callback messenger for scan results or errors
7082 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07007083 * @return the id of the requested scan which can be used to stop the scan.
7084 */
7085 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007086 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
7087 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007088 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007089 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7090 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08007091 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007092 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
7093 if (!renounceFineLocationAccess) {
7094 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007095 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7096 .setCallingPackage(callingPackage)
7097 .setCallingFeatureId(callingFeatureId)
7098 .setCallingPid(Binder.getCallingPid())
7099 .setCallingUid(Binder.getCallingUid())
7100 .setMethod("requestNetworkScan")
7101 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7102 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7103 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7104 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007105 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08007106 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07007107 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
7108 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08007109 if (e != null) {
7110 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
7111 throw e;
7112 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07007113 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08007114 return TelephonyScanManager.INVALID_SCAN_ID;
7115 }
7116 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007117 }
joonhunshin4ac60942023-11-15 15:23:39 +00007118
7119 enforceTelephonyFeatureWithException(callingPackage,
7120 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan");
7121
Hall Liu912dfd32019-04-25 14:02:26 -07007122 int callingUid = Binder.getCallingUid();
7123 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07007124 final long identity = Binder.clearCallingIdentity();
7125 try {
7126 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07007127 renounceFineLocationAccess, request, messenger, binder,
7128 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07007129 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07007130 } finally {
7131 Binder.restoreCallingIdentity(identity);
7132 }
yinxu504e1392017-04-12 16:03:22 -07007133 }
7134
Hall Liub2ac8ef2019-02-28 15:56:23 -08007135 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07007136 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00007137 boolean hasCarrierPriv;
7138 final long identity = Binder.clearCallingIdentity();
7139 try {
7140 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
7141 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
7142 } finally {
7143 Binder.restoreCallingIdentity(identity);
7144 }
Hall Liu558027f2019-05-15 19:14:05 -07007145 boolean hasNetworkScanPermission =
7146 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007147 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07007148
7149 if (!hasCarrierPriv && !hasNetworkScanPermission) {
7150 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
7151 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08007152 }
7153
7154 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
7155 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08007156 if (ras.getChannels() != null && ras.getChannels().length > 0) {
7157 return new SecurityException("Specific channels must not be"
7158 + " scanned without location access.");
7159 }
7160 }
7161 }
7162
Hall Liub2ac8ef2019-02-28 15:56:23 -08007163 return null;
7164 }
7165
yinxu504e1392017-04-12 16:03:22 -07007166 /**
7167 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07007168 *
7169 * @param subId id of the subscription
7170 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07007171 */
7172 @Override
7173 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007174 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7175 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007176
Hall Liu912dfd32019-04-25 14:02:26 -07007177 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007178 final long identity = Binder.clearCallingIdentity();
7179 try {
Hall Liu912dfd32019-04-25 14:02:26 -07007180 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007181 } finally {
7182 Binder.restoreCallingIdentity(identity);
7183 }
yinxu504e1392017-04-12 16:03:22 -07007184 }
7185
7186 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08007187 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07007188 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08007189 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07007190 */
7191 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08007192 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08007193 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007194 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08007195 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007196
joonhunshin4ac60942023-11-15 15:23:39 +00007197 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7198 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask");
7199
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007200 final long identity = Binder.clearCallingIdentity();
7201 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007202 if (DBG) log("getAllowedNetworkTypesBitmask");
7203 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
7204 int networkTypesBitmask = (result != null ? result[0] : -1);
7205 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
7206 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007207 } finally {
7208 Binder.restoreCallingIdentity(identity);
7209 }
Jake Hamby7c27be32014-03-03 13:25:59 -08007210 }
7211
7212 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007213 * Get the allowed network types for certain reason.
7214 *
7215 * @param subId the id of the subscription.
7216 * @param reason the reason the allowed network type change is taking place
7217 * @return the allowed network types.
7218 */
7219 @Override
7220 public long getAllowedNetworkTypesForReason(int subId,
7221 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07007222 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007223 mApp, subId, "getAllowedNetworkTypesForReason");
joonhunshin4ac60942023-11-15 15:23:39 +00007224
7225 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7226 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesForReason");
7227
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007228 final long identity = Binder.clearCallingIdentity();
7229 try {
Jack Yu7247ac82023-03-02 23:52:10 -08007230 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007231 } finally {
7232 Binder.restoreCallingIdentity(identity);
7233 }
7234 }
7235
7236 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07007237 * Enable/Disable E-UTRA-NR Dual Connectivity
7238 * @param subId subscription id of the sim card
7239 * @param nrDualConnectivityState expected NR dual connectivity state
7240 * This can be passed following states
7241 * <ol>
7242 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
7243 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
7244 * <li>Disable NR dual connectivity and force secondary cell to be released
7245 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
7246 * </ol>
7247 * @return operation result.
7248 */
7249 @Override
7250 public int setNrDualConnectivityState(int subId,
7251 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
7252 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7253 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007254 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007255 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7256 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
7257 }
7258
Sooraj Sasindran37444802020-08-11 10:40:43 -07007259 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7260 final long identity = Binder.clearCallingIdentity();
7261 try {
7262 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
7263 nrDualConnectivityState, subId,
7264 workSource);
7265 if (DBG) log("enableNRDualConnectivity result: " + result);
7266 return result;
7267 } finally {
7268 Binder.restoreCallingIdentity(identity);
7269 }
7270 }
7271
7272 /**
7273 * Is E-UTRA-NR Dual Connectivity enabled
7274 * @return true if dual connectivity is enabled else false
7275 */
7276 @Override
7277 public boolean isNrDualConnectivityEnabled(int subId) {
7278 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007279 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07007280 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007281 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007282 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7283 return false;
7284 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07007285 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7286 final long identity = Binder.clearCallingIdentity();
7287 try {
7288 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
7289 null, subId, workSource);
7290 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
7291 return isEnabled;
7292 } finally {
7293 Binder.restoreCallingIdentity(identity);
7294 }
7295 }
7296
7297 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007298 * Set the allowed network types of the device and
7299 * provide the reason triggering the allowed network change.
7300 *
7301 * @param subId the id of the subscription.
7302 * @param reason the reason the allowed network type change is taking place
7303 * @param allowedNetworkTypes the allowed network types.
7304 * @return true on success; false on any failure.
7305 */
7306 @Override
7307 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08007308 @TelephonyManager.AllowedNetworkTypesReason int reason,
7309 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007310 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7311 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007312 // If the caller only has carrier privileges, then they should not be able to override
7313 // any network types which were set for security reasons.
7314 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
7315 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007316 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007317 throw new SecurityException(
7318 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007319 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007320 }
joonhunshin4ac60942023-11-15 15:23:39 +00007321
7322 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7323 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason");
7324
SongFerngWang3ef3e072020-12-21 16:41:52 +08007325 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007326 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08007327 return false;
7328 }
7329 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
7330 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007331 return false;
7332 }
7333
Jack Yu5b494332023-01-23 18:18:04 +00007334 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
7335 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007336
Jack Yue37dd262022-12-16 11:53:37 -08007337 Phone phone = getPhone(subId);
7338 if (phone == null) {
7339 return false;
7340 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007341
Jack Yue37dd262022-12-16 11:53:37 -08007342 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007343 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007344 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08007345 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007346
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007347 final long identity = Binder.clearCallingIdentity();
7348 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007349 Boolean success = (Boolean) sendRequest(
7350 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
7351 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
7352
7353 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
7354 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007355 } finally {
7356 Binder.restoreCallingIdentity(identity);
7357 }
7358 }
7359
7360 /**
Miaoa84611c2019-03-15 09:21:10 +08007361 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08007362 *
Miaoa84611c2019-03-15 09:21:10 +08007363 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07007364 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08007365 * @hide
7366 */
7367 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08007368 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007369 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007370
7371 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7372 PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber");
7373
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007374 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08007375 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007376 try {
Miaoa84611c2019-03-15 09:21:10 +08007377 if (phone != null) {
7378 return phone.hasMatchedTetherApnSetting();
7379 } else {
7380 return false;
7381 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007382 } finally {
7383 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007384 }
Junda Liu475951f2014-11-07 16:45:03 -08007385 }
7386
7387 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007388 * Get the user enabled state of Mobile Data.
7389 *
7390 * TODO: remove and use isUserDataEnabled.
7391 * This can't be removed now because some vendor codes
7392 * calls through ITelephony directly while they should
7393 * use TelephonyManager.
7394 *
7395 * @return true on enabled
7396 */
7397 @Override
7398 public boolean getDataEnabled(int subId) {
7399 return isUserDataEnabled(subId);
7400 }
7401
7402 /**
7403 * Get whether mobile data is enabled per user setting.
7404 *
7405 * There are other factors deciding whether mobile data is actually enabled, but they are
7406 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007407 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007408 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7409 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007410 *
7411 * @return {@code true} if data is enabled else {@code false}
7412 */
7413 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007414 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007415 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007416 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007417 try {
7418 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7419 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007420 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007421 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7422 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007423 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007424 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007425 mApp, subId, functionName);
7426
Robert Greenwalt646120a2014-05-23 11:54:03 -07007427 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007428
7429 final long identity = Binder.clearCallingIdentity();
7430 try {
Jack Yu285100e2022-12-02 22:48:35 -08007431 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007432 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7433 Phone phone = PhoneFactory.getPhone(phoneId);
7434 if (phone != null) {
7435 boolean retVal = phone.isUserDataEnabled();
7436 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7437 return retVal;
7438 } else {
7439 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7440 return false;
7441 }
7442 } finally {
7443 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007444 }
7445 }
7446
7447 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007448 * Checks if the device is capable of mobile data by considering whether whether the
7449 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7450 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007451 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007452 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007453 */
7454 @Override
7455 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007456 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007457 try {
7458 try {
7459 mApp.enforceCallingOrSelfPermission(
7460 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007461 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007462 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007463 try {
7464 mApp.enforceCallingOrSelfPermission(
7465 android.Manifest.permission.READ_PHONE_STATE,
7466 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007467 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007468 mApp.enforceCallingOrSelfPermission(
7469 permission.READ_BASIC_PHONE_STATE, functionName);
7470 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007471 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007472 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007473 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007474 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007475
joonhunshin4ac60942023-11-15 15:23:39 +00007476 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7477 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled");
7478
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007479 final long identity = Binder.clearCallingIdentity();
7480 try {
Jack Yu285100e2022-12-02 22:48:35 -08007481 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007482 Phone phone = PhoneFactory.getPhone(phoneId);
7483 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007484 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007485 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007486 return retVal;
7487 } else {
7488 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7489 return false;
7490 }
7491 } finally {
7492 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007493 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007494 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007495
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007496 /**
7497 * Check if data is enabled for a specific reason
7498 * @param subId Subscription index
7499 * @param reason the reason the data enable change is taking place
7500 * @return {@code true} if the overall data is enabled; {@code false} if not.
7501 */
7502 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007503 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007504 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007505 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007506 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007507 try {
7508 mApp.enforceCallingOrSelfPermission(
7509 android.Manifest.permission.ACCESS_NETWORK_STATE,
7510 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007511 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007512 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7513 functionName);
7514 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007515 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007516 try {
7517 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007518 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007519 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007520 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007521 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007522 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007523 }
7524
joonhunshin4ac60942023-11-15 15:23:39 +00007525 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7526 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007527
7528 final long identity = Binder.clearCallingIdentity();
7529 try {
Jack Yu285100e2022-12-02 22:48:35 -08007530 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007531 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007532 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007533 + " reason=" + reason);
7534 }
7535 Phone phone = PhoneFactory.getPhone(phoneId);
7536 if (phone != null) {
7537 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007538 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007539 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007540 return retVal;
7541 } else {
7542 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007543 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007544 + subId + " retVal=false");
7545 }
7546 return false;
7547 }
7548 } finally {
7549 Binder.restoreCallingIdentity(identity);
7550 }
7551 }
7552
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007553 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007554 public int getCarrierPrivilegeStatus(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00007555 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7556 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus");
7557
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007558 // No permission needed; this only lets the caller inspect their own status.
7559 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007560 }
Junda Liu29340342014-07-10 15:23:27 -07007561
7562 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007563 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007564 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
joonhunshin4ac60942023-11-15 15:23:39 +00007565
7566 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7567 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatusForUid");
7568
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007569 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7570 }
7571
7572 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7573 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007574 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007575 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007576 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7577 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007578 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7579 if (cpt == null) {
7580 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007581 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7582 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007583 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007584 }
7585
7586 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007587 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007588 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
joonhunshin4ac60942023-11-15 15:23:39 +00007589
7590 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7591 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage");
7592
chen xuf7e9fe82019-05-09 19:31:02 -07007593 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007594 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007595 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007596 Phone phone = getPhone(subId);
7597 if (phone == null) {
7598 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7599 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7600 }
7601 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7602 if (cpt == null) {
7603 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007604 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7605 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007606 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007607 }
7608
7609 @Override
7610 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007611 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007612
7613 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7614 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7615 "checkCarrierPrivilegesForPackageAnyPhone");
7616
Rambo Wange7209ce2022-02-23 13:41:02 -08007617 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7618 }
7619
7620 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007621 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007622 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007623 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007624 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007625 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7626 Phone phone = PhoneFactory.getPhone(phoneId);
7627 if (phone == null) {
7628 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007629 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007630 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7631 if (cpt == null) {
7632 continue;
7633 }
7634 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007635 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7636 break;
7637 }
7638 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007639 return result;
Junda Liu29340342014-07-10 15:23:27 -07007640 }
Derek Tan89e89d42014-07-08 17:00:10 -07007641
7642 @Override
Junda Liue64de782015-04-16 17:19:16 -07007643 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007644 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007645
7646 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7647 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7648 "getCarrierPackageNamesForIntentAndPhone");
7649
Rambo Wang8a247eb2022-02-08 21:11:18 +00007650 Phone phone = PhoneFactory.getPhone(phoneId);
7651 if (phone == null) {
7652 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007653 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007654 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7655 if (cpt == null) {
7656 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007657 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007658 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007659 }
7660
Amith Yamasani6e118872016-02-19 12:53:51 -08007661 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007662 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007663 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007664 Phone phone = PhoneFactory.getPhone(phoneId);
7665 if (phone == null) {
7666 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007667 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007668 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7669 if (cpt == null) {
7670 return Collections.emptyList();
7671 }
7672 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007673 }
7674
chen xuf7e9fe82019-05-09 19:31:02 -07007675 @Override
7676 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007677 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
joonhunshin4ac60942023-11-15 15:23:39 +00007678
7679 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7680 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7681 "getPackagesWithCarrierPrivilegesForAllPhones");
7682
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007683 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007684 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007685 try {
7686 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7687 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7688 }
7689 } finally {
7690 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007691 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007692 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007693 }
7694
Rambo Wang6812ffb2022-03-15 16:54:17 -07007695 @Override
7696 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7697 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7698
joonhunshin4ac60942023-11-15 15:23:39 +00007699 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7700 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7701 "getCarrierServicePackageNameForLogicalSlot");
7702
Rambo Wang6812ffb2022-03-15 16:54:17 -07007703 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7704 if (phone == null) {
7705 return null;
7706 }
7707 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7708 if (cpt == null) {
7709 return null;
7710 }
7711 return cpt.getCarrierServicePackageName();
7712 }
7713
Wink Savilleb564aae2014-10-23 10:18:09 -07007714 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007715 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007716 UiccPort port = phone == null ? null : phone.getUiccPort();
7717 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007718 return null;
7719 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007720 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007721 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007722 return null;
7723 }
7724 return iccId;
7725 }
7726
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007727 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007728 public void setCallComposerStatus(int subId, int status) {
7729 enforceModifyPermission();
7730
joonhunshin4ac60942023-11-15 15:23:39 +00007731 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7732 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus");
7733
Shuo Qiane4e11672020-12-15 22:15:33 -08007734 final long identity = Binder.clearCallingIdentity();
7735 try {
7736 Phone phone = getPhone(subId);
7737 if (phone != null) {
7738 Phone defaultPhone = phone.getImsPhone();
7739 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7740 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7741 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007742 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7743 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007744 }
7745 }
Shuo Qian284ae752020-12-22 19:10:14 -08007746 } catch (ImsException e) {
7747 throw new ServiceSpecificException(e.getCode());
7748 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007749 Binder.restoreCallingIdentity(identity);
7750 }
7751 }
7752
7753 @Override
7754 public int getCallComposerStatus(int subId) {
7755 enforceReadPrivilegedPermission("getCallComposerStatus");
7756
joonhunshin4ac60942023-11-15 15:23:39 +00007757 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7758 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus");
7759
Shuo Qiane4e11672020-12-15 22:15:33 -08007760 final long identity = Binder.clearCallingIdentity();
7761 try {
7762 Phone phone = getPhone(subId);
7763 if (phone != null) {
7764 Phone defaultPhone = phone.getImsPhone();
7765 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7766 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7767 return imsPhone.getCallComposerStatus();
7768 }
7769 }
7770 } finally {
7771 Binder.restoreCallingIdentity(identity);
7772 }
7773 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7774 }
7775
7776 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007777 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7778 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007779 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007780 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007781
joonhunshin4ac60942023-11-15 15:23:39 +00007782 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7783 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7784 "setLine1NumberForDisplayForSubscriber");
7785
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007786 final long identity = Binder.clearCallingIdentity();
7787 try {
7788 final String iccId = getIccId(subId);
7789 final Phone phone = getPhone(subId);
7790 if (phone == null) {
7791 return false;
7792 }
7793 final String subscriberId = phone.getSubscriberId();
7794
7795 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007796 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007797 + subscriberId + " to " + number);
7798 }
7799
7800 if (TextUtils.isEmpty(iccId)) {
7801 return false;
7802 }
7803
7804 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7805
7806 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7807 if (alphaTag == null) {
7808 editor.remove(alphaTagPrefKey);
7809 } else {
7810 editor.putString(alphaTagPrefKey, alphaTag);
7811 }
7812
7813 // Record both the line number and IMSI for this ICCID, since we need to
7814 // track all merged IMSIs based on line number
7815 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7816 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7817 if (number == null) {
7818 editor.remove(numberPrefKey);
7819 editor.remove(subscriberPrefKey);
7820 } else {
7821 editor.putString(numberPrefKey, number);
7822 editor.putString(subscriberPrefKey, subscriberId);
7823 }
7824
7825 editor.commit();
7826 return true;
7827 } finally {
7828 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007829 }
Derek Tan7226c842014-07-02 17:42:23 -07007830 }
7831
7832 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007833 public String getLine1NumberForDisplay(int subId, String callingPackage,
7834 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007835 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007836 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007837 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007838 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007839 return null;
7840 }
Derek Tan97ebb422014-09-05 16:55:38 -07007841
joonhunshin4ac60942023-11-15 15:23:39 +00007842 enforceTelephonyFeatureWithException(callingPackage,
7843 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay");
7844
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007845 final long identity = Binder.clearCallingIdentity();
7846 try {
7847 String iccId = getIccId(subId);
7848 if (iccId != null) {
7849 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7850 if (DBG_MERGE) {
7851 log("getLine1NumberForDisplay returning "
7852 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7853 }
7854 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007855 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007856 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7857 return null;
7858 } finally {
7859 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007860 }
Derek Tan7226c842014-07-02 17:42:23 -07007861 }
7862
7863 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007864 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7865 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007866 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007867 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007868 return null;
7869 }
Derek Tan97ebb422014-09-05 16:55:38 -07007870
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007871 final long identity = Binder.clearCallingIdentity();
7872 try {
7873 String iccId = getIccId(subId);
7874 if (iccId != null) {
7875 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7876 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7877 }
7878 return null;
7879 } finally {
7880 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007881 }
Derek Tan7226c842014-07-02 17:42:23 -07007882 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007883
7884 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007885 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7886 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007887 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7888 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007889 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007890 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007891 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007892 return null;
7893 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007894
Jordan Liub49b04b2019-05-06 14:45:15 -07007895 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7896 // the process, where TelephonyManager was instantiated.
7897 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007898 final long identity = Binder.clearCallingIdentity();
7899 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007900 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007901 final TelephonyManager tele = TelephonyManager.from(context);
7902 final SubscriptionManager sub = SubscriptionManager.from(context);
7903
7904 // Figure out what subscribers are currently active
7905 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007906
Jordan Liub49b04b2019-05-06 14:45:15 -07007907 // Only consider subs which match the current subId
7908 // This logic can be simplified. See b/131189269 for progress.
7909 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007910 activeSubscriberIds.add(tele.getSubscriberId(subId));
7911 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007912
7913 // First pass, find a number override for an active subscriber
7914 String mergeNumber = null;
7915 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7916 for (String key : prefs.keySet()) {
7917 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7918 final String subscriberId = (String) prefs.get(key);
7919 if (activeSubscriberIds.contains(subscriberId)) {
7920 final String iccId = key.substring(
7921 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7922 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7923 mergeNumber = (String) prefs.get(numberKey);
7924 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007925 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007926 + " for active subscriber " + subscriberId);
7927 }
7928 if (!TextUtils.isEmpty(mergeNumber)) {
7929 break;
7930 }
7931 }
7932 }
7933 }
7934
7935 // Shortcut when no active merged subscribers
7936 if (TextUtils.isEmpty(mergeNumber)) {
7937 return null;
7938 }
7939
7940 // Second pass, find all subscribers under that line override
7941 final ArraySet<String> result = new ArraySet<>();
7942 for (String key : prefs.keySet()) {
7943 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7944 final String number = (String) prefs.get(key);
7945 if (mergeNumber.equals(number)) {
7946 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7947 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7948 final String subscriberId = (String) prefs.get(subscriberKey);
7949 if (!TextUtils.isEmpty(subscriberId)) {
7950 result.add(subscriberId);
7951 }
7952 }
7953 }
7954 }
7955
7956 final String[] resultArray = result.toArray(new String[result.size()]);
7957 Arrays.sort(resultArray);
7958 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007959 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007960 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7961 }
7962 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007963 } finally {
7964 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007965 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007966 }
7967
7968 @Override
zoey chen38003472019-12-13 17:16:31 +08007969 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7970 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007971
joonhunshin4ac60942023-11-15 15:23:39 +00007972 enforceTelephonyFeatureWithException(callingPackage,
7973 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup");
7974
Malcolm Chen6ca97372019-07-01 16:28:21 -07007975 final long identity = Binder.clearCallingIdentity();
7976 try {
7977 final TelephonyManager telephonyManager = mApp.getSystemService(
7978 TelephonyManager.class);
7979 String subscriberId = telephonyManager.getSubscriberId(subId);
7980 if (subscriberId == null) {
7981 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007982 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007983 + subId);
7984 }
7985 return null;
7986 }
7987
Jack Yu3beaf9d2023-04-14 09:17:27 -07007988 final SubscriptionInfo info = getSubscriptionManagerService()
7989 .getSubscriptionInfo(subId);
7990 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07007991 // If it doesn't belong to any group, return just subscriberId of itself.
7992 if (groupUuid == null) {
7993 return new String[]{subscriberId};
7994 }
7995
7996 // Get all subscriberIds from the group.
7997 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07007998 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
7999 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
8000 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07008001 for (SubscriptionInfo subInfo : groupInfos) {
8002 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
8003 if (subscriberId != null) {
8004 mergedSubscriberIds.add(subscriberId);
8005 }
8006 }
8007
8008 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
8009 } finally {
8010 Binder.restoreCallingIdentity(identity);
8011
8012 }
8013 }
8014
8015 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008016 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008017 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08008018 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008019
joonhunshin4ac60942023-11-15 15:23:39 +00008020 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8021 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride");
8022
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008023 final long identity = Binder.clearCallingIdentity();
8024 try {
8025 final Phone phone = getPhone(subId);
8026 return phone == null ? false : phone.setOperatorBrandOverride(brand);
8027 } finally {
8028 Binder.restoreCallingIdentity(identity);
8029 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07008030 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05008031
8032 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008033 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008034 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
8035 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008036 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
8037 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008038
8039 final long identity = Binder.clearCallingIdentity();
8040 try {
8041 final Phone phone = getPhone(subId);
8042 if (phone == null) {
8043 return false;
8044 }
8045 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
8046 cdmaNonRoamingList);
8047 } finally {
8048 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008049 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008050 }
8051
8052 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07008053 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008054 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08008055 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008056 if (phone == null) {
8057 return raf;
8058 }
8059
Shuo Qiandee53402020-05-29 14:08:15 -07008060 try {
8061 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008062 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07008063 mApp, phone.getSubId(), "getRadioAccessFamily");
8064 } catch (SecurityException e) {
8065 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
8066 throw e;
8067 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008068
joonhunshin4ac60942023-11-15 15:23:39 +00008069 enforceTelephonyFeatureWithException(callingPackage,
8070 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily");
8071
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008072 final long identity = Binder.clearCallingIdentity();
8073 try {
chen xub97461a2018-10-26 14:17:57 -07008074 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008075 } finally {
8076 Binder.restoreCallingIdentity(identity);
8077 }
chen xub97461a2018-10-26 14:17:57 -07008078 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07008079 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008080
8081 @Override
Hall Liu82694d52020-12-11 18:22:04 -08008082 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08008083 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08008084 try {
8085 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
8086 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008087 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008088 }
8089 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008090 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008091 }
joonhunshin4ac60942023-11-15 15:23:39 +00008092
8093 enforceTelephonyFeatureWithException(callingPackage,
8094 PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture");
8095
Hall Liu82694d52020-12-11 18:22:04 -08008096 RoleManager rm = mApp.getSystemService(RoleManager.class);
8097 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
8098 if (!dialerRoleHolders.contains(callingPackage)) {
8099 throw new SecurityException("App must be the dialer role holder to"
8100 + " upload a call composer pic");
8101 }
8102
8103 Executors.newSingleThreadExecutor().execute(() -> {
8104 ByteArrayOutputStream output = new ByteArrayOutputStream(
8105 (int) TelephonyManager.getMaximumCallComposerPictureSize());
8106 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
8107 boolean readUntilEnd = false;
8108 int totalBytesRead = 0;
8109 byte[] buffer = new byte[16 * 1024];
8110 while (true) {
8111 int numRead;
8112 try {
8113 numRead = input.read(buffer);
8114 } catch (IOException e) {
8115 try {
8116 fd.checkError();
8117 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
8118 null);
8119 } catch (IOException e1) {
8120 // This means that the other side closed explicitly with an error. If this
8121 // happens, log and ignore.
8122 loge("Remote end of call composer picture pipe closed: " + e1);
8123 }
8124 break;
8125 }
8126 if (numRead == -1) {
8127 readUntilEnd = true;
8128 break;
8129 }
8130 totalBytesRead += numRead;
8131 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
8132 loge("Too many bytes read for call composer picture: " + totalBytesRead);
8133 try {
8134 input.close();
8135 } catch (IOException e) {
8136 // ignore
8137 }
8138 break;
8139 }
8140 output.write(buffer, 0, numRead);
8141 }
8142 // Generally, the remote end will close the file descriptors. The only case where we
8143 // close is above, where the picture size is too big.
8144
8145 try {
8146 fd.checkError();
8147 } catch (IOException e) {
8148 loge("Remote end for call composer closed with an error: " + e);
8149 return;
8150 }
8151
Hall Liuaa4211e2021-01-20 15:43:39 -08008152 if (!readUntilEnd) {
8153 loge("Did not finish reading entire image; aborting");
8154 return;
8155 }
Hall Liu82694d52020-12-11 18:22:04 -08008156
Hall Liuaa4211e2021-01-20 15:43:39 -08008157 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
8158 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
8159 new CallComposerPictureTransfer.Factory() {},
8160 imageData,
8161 (result) -> {
8162 if (result.first != null) {
8163 ParcelUuid parcelUuid = new ParcelUuid(result.first);
8164 Bundle outputResult = new Bundle();
8165 outputResult.putParcelable(
8166 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
8167 callback.send(TelephonyManager.CallComposerException.SUCCESS,
8168 outputResult);
8169 } else {
8170 callback.send(result.second, null);
8171 }
8172 }
8173 );
Hall Liu82694d52020-12-11 18:22:04 -08008174 });
8175 }
8176
8177 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07008178 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008179 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07008180 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008181
joonhunshin4ac60942023-11-15 15:23:39 +00008182 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8183 PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling");
8184
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008185 final long identity = Binder.clearCallingIdentity();
8186 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008187 ImsManager.getInstance(defaultPhone.getContext(),
8188 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008189 } finally {
8190 Binder.restoreCallingIdentity(identity);
8191 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008192 }
8193
8194 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008195 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008196 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008197 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
8198 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00008199 return false;
8200 }
Svet Ganovb320e182015-04-16 12:30:10 -07008201
joonhunshin4ac60942023-11-15 15:23:39 +00008202 enforceTelephonyFeatureWithException(callingPackage,
8203 PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled");
8204
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008205 final long identity = Binder.clearCallingIdentity();
8206 try {
8207 // Check the user preference and the system-level IMS setting. Even if the user has
8208 // enabled video calling, if IMS is disabled we aren't able to support video calling.
8209 // In the long run, we may instead need to check if there exists a connection service
8210 // which can support video calling.
8211 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008212 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008213 return imsManager.isVtEnabledByPlatform()
8214 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
8215 && imsManager.isVtEnabledByUser();
8216 } finally {
8217 Binder.restoreCallingIdentity(identity);
8218 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008219 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06008220
Andrew Leea1239f22015-03-02 17:44:07 -08008221 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008222 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
8223 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008224 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008225 mApp, subId, callingPackage, callingFeatureId,
8226 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008227 return false;
8228 }
8229
joonhunshin4ac60942023-11-15 15:23:39 +00008230 enforceTelephonyFeatureWithException(callingPackage,
8231 PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength");
8232
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008233 final long identity = Binder.clearCallingIdentity();
8234 try {
8235 CarrierConfigManager configManager =
8236 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008237 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008238 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
8239 } finally {
8240 Binder.restoreCallingIdentity(identity);
8241 }
Andrew Leea1239f22015-03-02 17:44:07 -08008242 }
8243
8244 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008245 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008246 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008247 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008248 return false;
8249 }
8250
joonhunshin4ac60942023-11-15 15:23:39 +00008251 enforceTelephonyFeatureWithException(callingPackage,
8252 PackageManager.FEATURE_TELEPHONY, "isWorldPhone");
8253
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008254 final long identity = Binder.clearCallingIdentity();
8255 try {
8256 CarrierConfigManager configManager =
8257 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008258 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008259 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
8260 } finally {
8261 Binder.restoreCallingIdentity(identity);
8262 }
Andrew Leea1239f22015-03-02 17:44:07 -08008263 }
8264
Andrew Lee9431b832015-03-09 18:46:45 -07008265 @Override
8266 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008267 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08008268 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07008269 }
8270
8271 @Override
8272 public boolean isHearingAidCompatibilitySupported() {
joonhunshin4ac60942023-11-15 15:23:39 +00008273 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8274 PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported");
8275
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008276 final long identity = Binder.clearCallingIdentity();
8277 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008278 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008279 } finally {
8280 Binder.restoreCallingIdentity(identity);
8281 }
Andrew Lee9431b832015-03-09 18:46:45 -07008282 }
8283
Hall Liuf6668912018-10-31 17:05:23 -07008284 /**
8285 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
8286 * support for the feature and device firmware support.
8287 *
8288 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
8289 */
8290 @Override
8291 public boolean isRttSupported(int subscriptionId) {
joonhunshin4ac60942023-11-15 15:23:39 +00008292 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8293 PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported");
8294
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008295 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008296 final Phone phone = getPhone(subscriptionId);
8297 if (phone == null) {
8298 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
8299 return false;
8300 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008301 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008302 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008303 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
joonhunshin4ac60942023-11-15 15:23:39 +00008304 boolean isDeviceSupported = (phone.getContext().getResources() != null)
8305 ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt)
8306 : false;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008307 return isCarrierSupported && isDeviceSupported;
8308 } finally {
8309 Binder.restoreCallingIdentity(identity);
8310 }
Hall Liu98187582018-01-22 19:15:32 -08008311 }
8312
Hall Liuf6668912018-10-31 17:05:23 -07008313 /**
Hall Liuf2daa022019-07-23 18:39:00 -07008314 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
8315 * RTT setting, will return true if the device and carrier both support RTT.
8316 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07008317 */
8318 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008319 final long identity = Binder.clearCallingIdentity();
8320 try {
joonhunshin4ac60942023-11-15 15:23:39 +00008321 if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) {
8322 if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
8323 return false;
8324 }
8325 }
8326
Hall Liu5bab75c2019-12-11 23:58:20 +00008327 boolean isRttSupported = isRttSupported(subscriptionId);
8328 boolean isUserRttSettingOn = Settings.Secure.getInt(
8329 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
8330 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
8331 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
8332 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008333 } finally {
8334 Binder.restoreCallingIdentity(identity);
8335 }
Hall Liu3ad5f012018-04-06 16:23:39 -07008336 }
8337
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008338 @Deprecated
8339 @Override
8340 public String getDeviceId(String callingPackage) {
8341 return getDeviceIdWithFeature(callingPackage, null);
8342 }
8343
Sanket Padawe7310cc72015-01-14 09:53:20 -08008344 /**
8345 * Returns the unique device ID of phone, for example, the IMEI for
8346 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
8347 *
8348 * <p>Requires Permission:
8349 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
8350 */
8351 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008352 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07008353 try {
8354 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
8355 } catch (SecurityException se) {
8356 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
8357 throw new SecurityException("Package " + callingPackage + " does not belong to "
8358 + Binder.getCallingUid());
8359 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008360 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008361 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008362 return null;
8363 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008364 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008365 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008366 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008367 return null;
8368 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008369
8370 final long identity = Binder.clearCallingIdentity();
8371 try {
8372 return phone.getDeviceId();
8373 } finally {
8374 Binder.restoreCallingIdentity(identity);
8375 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008376 }
8377
Ping Sunc67b7c22016-03-02 19:16:45 +08008378 /**
8379 * {@hide}
8380 * Returns the IMS Registration Status on a particular subid
8381 *
8382 * @param subId
8383 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008384 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008385 Phone phone = getPhone(subId);
8386 if (phone != null) {
8387 return phone.isImsRegistered();
8388 } else {
8389 return false;
8390 }
8391 }
8392
Santos Cordon7a1885b2015-02-03 11:15:19 -08008393 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008394 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008395 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008396 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008397 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008398 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8399 }
8400 final long identity = Binder.clearCallingIdentity();
8401 try {
8402 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8403 } finally {
8404 Binder.restoreCallingIdentity(identity);
8405 }
8406 }
8407
8408 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008409 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008410 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008411 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008412 mApp,
8413 subscriptionId,
8414 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
8415 + subscriptionId);
joonhunshin4ac60942023-11-15 15:23:39 +00008416
8417 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8418 PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId");
8419
Tyler Gunnf70ed162019-04-03 15:28:53 -07008420 final long identity = Binder.clearCallingIdentity();
8421 try {
8422 Phone phone = getPhone(subscriptionId);
8423 if (phone == null) {
8424 return null;
8425 }
8426 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8427 } finally {
8428 Binder.restoreCallingIdentity(identity);
8429 }
8430 }
8431
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008432 /**
8433 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008434 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008435 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008436 final long identity = Binder.clearCallingIdentity();
8437 try {
8438 Phone phone = getPhone(subId);
8439 if (phone != null) {
8440 return phone.isWifiCallingEnabled();
8441 } else {
8442 return false;
8443 }
8444 } finally {
8445 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008446 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008447 }
8448
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008449 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008450 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008451 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008452 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008453 final long identity = Binder.clearCallingIdentity();
8454 try {
8455 Phone phone = getPhone(subId);
8456 if (phone != null) {
8457 return phone.isVideoEnabled();
8458 } else {
8459 return false;
8460 }
8461 } finally {
8462 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008463 }
8464 }
8465
8466 /**
8467 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8468 * defined in {@link ImsRegistrationImplBase}.
8469 */
8470 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008471 final long identity = Binder.clearCallingIdentity();
8472 try {
8473 Phone phone = getPhone(subId);
8474 if (phone != null) {
8475 return phone.getImsRegistrationTech();
8476 } else {
8477 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8478 }
8479 } finally {
8480 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008481 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008482 }
8483
Stuart Scott8eef64f2015-04-08 15:13:54 -07008484 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008485 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008486 enforceSettingsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008487
8488 enforceTelephonyFeatureWithException(callingPackage,
8489 PackageManager.FEATURE_TELEPHONY, "factoryReset");
8490
Stuart Scott981d8582015-04-21 14:09:50 -07008491 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8492 return;
8493 }
Kai Shif70f46f2021-03-03 13:59:46 -08008494 Phone defaultPhone = getDefaultPhone();
8495 if (defaultPhone != null) {
8496 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8497 mApp, getDefaultPhone().getSubId(), "factoryReset");
8498 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008499 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008500
Svet Ganovcc087f82015-05-12 20:35:54 -07008501 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008502 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8503 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008504 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008505 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008506 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008507 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008508 cleanUpAllowedNetworkTypes(phone, subId);
Rambo Wang71f6aa62024-02-23 20:16:22 +00008509 setDataRoamingEnabled(subId, phone == null ? false
8510 : phone.getDataSettingsManager().isDefaultDataRoamingEnabled());
Jordan Liu857e73a2021-03-05 16:24:04 -08008511 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008512 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008513 // There has been issues when Sms raw table somehow stores orphan
8514 // fragments. They lead to garbled message when new fragments come
8515 // in and combined with those stale ones. In case this happens again,
8516 // user can reset all network settings which will clean up this table.
8517 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008518 // Clean up IMS settings as well here.
8519 int slotId = getSlotIndex(subId);
8520 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
8521 ImsManager.getInstance(mApp, slotId).factoryReset();
8522 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008523
Kai Shif70f46f2021-03-03 13:59:46 -08008524 if (defaultPhone == null) {
8525 return;
8526 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008527 // Erase modem config if erase modem on network setting is enabled.
8528 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8529 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8530 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008531 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008532 }
Kai Shif70f46f2021-03-03 13:59:46 -08008533
8534 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008535 } finally {
8536 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008537 }
8538 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008539
SongFerngWangfd89b102021-05-27 22:44:54 +08008540 @VisibleForTesting
8541 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8542 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8543 return;
8544 }
8545 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8546 RILConstants.PREFERRED_NETWORK_MODE);
8547 SubscriptionManager.setSubscriptionProperty(subId,
8548 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8549 "user=" + defaultNetworkType);
8550 phone.loadAllowedNetworksFromSubscriptionDatabase();
8551 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8552 defaultNetworkType, null);
8553 }
8554
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008555 private void cleanUpSmsRawTable(Context context) {
8556 ContentResolver resolver = context.getContentResolver();
8557 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8558 resolver.delete(uri, null, null);
8559 }
8560
Narayan Kamath1c496c22015-04-16 14:40:19 +01008561 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008562 public String getSimLocaleForSubscriber(int subId) {
8563 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
joonhunshin4ac60942023-11-15 15:23:39 +00008564
8565 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8566 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber");
8567
chen xu5d3637b2019-01-21 23:31:38 -08008568 final Phone phone = getPhone(subId);
8569 if (phone == null) {
8570 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008571 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008572 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008573 final long identity = Binder.clearCallingIdentity();
8574 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008575 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
8576 phone.getContext().getOpPackageName(),
8577 phone.getContext().getAttributionTag());
8578 if (info == null) {
8579 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8580 return null;
chen xu6291c472019-02-04 12:55:53 -08008581 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008582 // Try and fetch the locale from the carrier properties or from the SIM language
8583 // preferences (EF-PL and EF-LI)...
8584 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008585 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008586 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8587 if (localeFromDefaultSim != null) {
8588 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8589 if (DBG) log("Using locale from subId: " + subId + " locale: "
8590 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008591 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008592 } else {
8593 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008594 }
8595 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008596
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008597 // The SIM language preferences only store a language (e.g. fr = French), not an
8598 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8599 // the SIM and carrier preferences does not include a country we add the country
8600 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008601 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008602 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008603 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008604 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008605 }
8606
8607 if (DBG) log("No locale found - returning null");
8608 return null;
8609 } finally {
8610 Binder.restoreCallingIdentity(identity);
8611 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008612 }
8613
tom hsu0b59d292022-09-29 23:49:21 +08008614 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008615 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008616 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008617 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008618 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008619 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8620 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008621 Locale.forLanguageTag(localeTag).getCountry())) {
8622 return localeTag;
8623 }
8624 }
8625 return inputLocale.toLanguageTag();
8626 }
8627
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008628 /**
8629 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8630 */
8631 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008632 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Ling Ma9fa67412023-11-13 14:13:19 -08008633 mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/);
Narayan Kamath1c496c22015-04-16 14:40:19 +01008634 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008635
Gary Jian3aa9a762022-01-24 16:41:19 +08008636 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8637 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008638
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008639 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008640 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8641 * representing the state of the modem.
8642 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008643 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8644 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008645 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008646 */
8647 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008648 public void requestModemActivityInfo(ResultReceiver result) {
8649 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008650
8651 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8652 PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo");
8653
vagdeviaf9a5b92018-08-15 16:01:53 -07008654 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008655
8656 final long identity = Binder.clearCallingIdentity();
8657 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008658 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008659 } finally {
8660 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008661 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008662 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008663
Gary Jian76280a42022-12-07 16:18:33 +08008664 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008665 // less than total activity duration.
8666 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8667 if (info == null) {
8668 return false;
8669 }
8670 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008671 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008672 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8673
Hall Liu49656c02020-10-09 19:00:11 -07008674 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8675
Siddharth Rayb8114062018-06-17 15:02:38 -07008676 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008677 && (info.getSleepTimeMillis() <= activityDurationMs)
8678 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008679 }
8680
Gary Jian3aa9a762022-01-24 16:41:19 +08008681 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8682 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8683 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8684 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8685
8686 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8687 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8688 }
8689
8690 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8691 mLastModemActivityInfo.setReceiveTimeMillis(
8692 rat,
8693 freq,
8694 info.getReceiveTimeMillis(rat, freq)
8695 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8696 }
8697
8698 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8699 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8700 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8701 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8702
8703 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8704 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8705 }
8706 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8707 mLastModemActivityInfo.setReceiveTimeMillis(
8708 rat,
8709 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8710 }
8711
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008712 /**
8713 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8714 * @param info recent ModemActivityInfo
8715 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008716 private void mergeModemActivityInfo(ModemActivityInfo info) {
8717 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008718 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008719 boolean matched;
8720 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8721 matched = false;
8722 int rat = info.getSpecificInfoRat(i);
8723 int freq = info.getSpecificInfoFrequencyRange(i);
8724 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8725 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8726 //if it already exists
8727 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8728 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8729 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8730 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8731 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8732 updateLastModemActivityInfo(info, rat, freq);
8733 matched = true;
8734 }
8735 } else {
8736 updateLastModemActivityInfo(info, rat);
8737 matched = true;
8738 }
8739 }
8740 }
8741
8742 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008743 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008744 new ActivityStatsTechSpecificInfo(
8745 rat,
8746 freq,
8747 info.getTransmitTimeMillis(rat, freq),
8748 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008749 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008750 }
8751 }
8752 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8753 mLastModemActivitySpecificInfo =
8754 new ActivityStatsTechSpecificInfo[merged.size()];
8755 merged.toArray(mLastModemActivitySpecificInfo);
8756
8757 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8758 mLastModemActivityInfo.setSleepTimeMillis(
8759 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008760 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008761 mLastModemActivityInfo.setIdleTimeMillis(
8762 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008763 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008764
8765 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008766 new ModemActivityInfo(
8767 mLastModemActivityInfo.getTimestampMillis(),
8768 mLastModemActivityInfo.getSleepTimeMillis(),
8769 mLastModemActivityInfo.getIdleTimeMillis(),
8770 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008771 }
8772
8773 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8774 ActivityStatsTechSpecificInfo[] info) {
8775 int infoSize = info.length;
8776 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8777 for (int i = 0; i < infoSize; i++) {
8778 ret[i] = new ActivityStatsTechSpecificInfo(
8779 info[i].getRat(), info[i].getFrequencyRange(),
8780 info[i].getTransmitTimeMillis(),
8781 (int) info[i].getReceiveTimeMillis());
8782 }
8783 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008784 }
8785
Jack Yu85bd38a2015-11-09 11:34:32 -08008786 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008787 * Returns the service state information on specified subscription.
8788 */
8789 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008790 public ServiceState getServiceStateForSubscriber(int subId,
8791 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8792 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008793 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008794 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008795 return null;
8796 }
8797
joonhunshin4ac60942023-11-15 15:23:39 +00008798 enforceTelephonyFeatureWithException(callingPackage,
8799 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber");
8800
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008801 boolean hasFinePermission = false;
8802 boolean hasCoarsePermission = false;
8803 if (!renounceFineLocationAccess) {
8804 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8805 LocationAccessPolicy.checkLocationPermission(mApp,
8806 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8807 .setCallingPackage(callingPackage)
8808 .setCallingFeatureId(callingFeatureId)
8809 .setCallingPid(Binder.getCallingPid())
8810 .setCallingUid(Binder.getCallingUid())
8811 .setMethod("getServiceStateForSubscriber")
8812 .setLogAsInfo(true)
8813 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8814 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8815 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8816 .build());
8817 hasFinePermission =
8818 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8819 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008820
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008821 if (!renounceCoarseLocationAccess) {
8822 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8823 LocationAccessPolicy.checkLocationPermission(mApp,
8824 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8825 .setCallingPackage(callingPackage)
8826 .setCallingFeatureId(callingFeatureId)
8827 .setCallingPid(Binder.getCallingPid())
8828 .setCallingUid(Binder.getCallingUid())
8829 .setMethod("getServiceStateForSubscriber")
8830 .setLogAsInfo(true)
8831 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8832 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8833 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8834 .build());
8835 hasCoarsePermission =
8836 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8837 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008838
Jack Yu479f40e2020-10-27 21:29:25 -07008839 final Phone phone = getPhone(subId);
8840 if (phone == null) {
8841 return null;
8842 }
8843
Jordan Liu0f2bc442020-11-18 16:47:37 -08008844 final long identity = Binder.clearCallingIdentity();
8845
Jack Yu479f40e2020-10-27 21:29:25 -07008846 boolean isCallingPackageDataService = phone.getDataServicePackages()
8847 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008848 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008849 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu3beaf9d2023-04-14 09:17:27 -07008850 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8851 .getSubscriptionInfoInternal(subId);
8852 if (subInfo == null || !subInfo.isActive()) {
8853 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8854 + "subId=" + subId);
8855 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008856 }
8857
Hall Liuf19c44f2018-11-27 14:38:17 -08008858 ServiceState ss = phone.getServiceState();
8859
8860 // Scrub out the location info in ServiceState depending on what level of access
8861 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008862 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008863 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8864 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008865 } finally {
8866 Binder.restoreCallingIdentity(identity);
8867 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008868 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008869
8870 /**
8871 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8872 *
8873 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8874 * voicemail ringtone.
8875 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8876 * PhoneAccount.
8877 */
8878 @Override
8879 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008880 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8881 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri");
8882
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008883 final long identity = Binder.clearCallingIdentity();
8884 try {
8885 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8886 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008887 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008888 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008889
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008890 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8891 } finally {
8892 Binder.restoreCallingIdentity(identity);
8893 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008894 }
8895
8896 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008897 * Sets the per-account voicemail ringtone.
8898 *
8899 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8900 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8901 *
8902 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8903 * voicemail ringtone.
8904 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8905 * PhoneAccount.
8906 */
8907 @Override
8908 public void setVoicemailRingtoneUri(String callingPackage,
8909 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008910 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008911 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008912 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8913 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008914 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8915 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8916 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008917 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008918
joonhunshin4ac60942023-11-15 15:23:39 +00008919 enforceTelephonyFeatureWithException(callingPackage,
8920 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri");
8921
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008922 final long identity = Binder.clearCallingIdentity();
8923 try {
8924 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8925 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008926 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008927 }
8928 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8929 } finally {
8930 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008931 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008932 }
8933
8934 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008935 * Returns whether vibration is set for voicemail notification in Phone settings.
8936 *
8937 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8938 * voicemail vibration setting.
8939 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8940 */
8941 @Override
8942 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008943 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8944 PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled");
8945
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008946 final long identity = Binder.clearCallingIdentity();
8947 try {
8948 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8949 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008950 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008951 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008952
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008953 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8954 } finally {
8955 Binder.restoreCallingIdentity(identity);
8956 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008957 }
8958
Youhan Wange64578a2016-05-02 15:32:42 -07008959 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008960 * Sets the per-account voicemail vibration.
8961 *
8962 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8963 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8964 *
8965 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8966 * voicemail vibration setting.
8967 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8968 * specific PhoneAccount.
8969 */
8970 @Override
8971 public void setVoicemailVibrationEnabled(String callingPackage,
8972 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008973 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008974 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008975 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8976 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008977 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8978 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8979 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008980 }
8981
joonhunshin4ac60942023-11-15 15:23:39 +00008982 enforceTelephonyFeatureWithException(callingPackage,
8983 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled");
8984
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008985 final long identity = Binder.clearCallingIdentity();
8986 try {
8987 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8988 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008989 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008990 }
8991 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8992 } finally {
8993 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008994 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008995 }
8996
8997 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008998 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8999 *
9000 * @throws SecurityException if the caller does not have the required permission
9001 */
arunvoddud7401012022-12-15 16:08:12 +00009002 @VisibleForTesting
9003 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07009004 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07009005 message);
Youhan Wange64578a2016-05-02 15:32:42 -07009006 }
9007
9008 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009009 * Make sure either called from same process as self (phone) or IPC caller has send SMS
9010 * permission.
9011 *
9012 * @throws SecurityException if the caller does not have the required permission
9013 */
9014 private void enforceSendSmsPermission() {
9015 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
9016 }
9017
9018 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00009019 * Make sure either called from same process as self (phone) or IPC caller has interact across
9020 * users permission.
9021 *
9022 * @throws SecurityException if the caller does not have the required permission
9023 */
9024 private void enforceInteractAcrossUsersPermission(String message) {
9025 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
9026 }
9027
9028 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009029 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009030 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009031 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009032 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009033 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009034 final long identity = Binder.clearCallingIdentity();
9035 try {
9036 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009037 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009038 if (componentName == null) {
9039 throw new SecurityException(
9040 "Caller not current active visual voicemail package[null]");
9041 }
9042 String vvmPackage = componentName.getPackageName();
9043 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00009044 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009045 }
9046 } finally {
9047 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009048 }
9049 }
9050
9051 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009052 * Return the application ID for the app type.
9053 *
9054 * @param subId the subscription ID that this request applies to.
9055 * @param appType the uicc app type.
9056 * @return Application ID for specificied app type, or null if no uicc.
9057 */
9058 @Override
9059 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009060 enforceReadPrivilegedPermission("getAidForAppType");
joonhunshin4ac60942023-11-15 15:23:39 +00009061
9062 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9063 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType");
9064
Youhan Wange64578a2016-05-02 15:32:42 -07009065 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009066
9067 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07009068 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009069 if (phone == null) {
9070 return null;
9071 }
9072 String aid = null;
9073 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009074 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009075 .getApplicationByType(appType).getAid();
9076 } catch (Exception e) {
9077 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
9078 }
9079 return aid;
9080 } finally {
9081 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07009082 }
Youhan Wange64578a2016-05-02 15:32:42 -07009083 }
9084
Youhan Wang4001d252016-05-11 10:29:41 -07009085 /**
9086 * Return the Electronic Serial Number.
9087 *
9088 * @param subId the subscription ID that this request applies to.
9089 * @return ESN or null if error.
9090 */
9091 @Override
9092 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009093 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07009094 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009095
9096 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07009097 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009098 if (phone == null) {
9099 return null;
9100 }
9101 String esn = null;
9102 try {
9103 esn = phone.getEsn();
9104 } catch (Exception e) {
9105 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
9106 }
9107 return esn;
9108 } finally {
9109 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07009110 }
Youhan Wang4001d252016-05-11 10:29:41 -07009111 }
9112
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009113 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009114 * Return the Preferred Roaming List Version.
9115 *
9116 * @param subId the subscription ID that this request applies to.
9117 * @return PRLVersion or null if error.
9118 */
9119 @Override
9120 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009121 enforceReadPrivilegedPermission("getCdmaPrlVersion");
joonhunshin4ac60942023-11-15 15:23:39 +00009122
9123 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9124 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion");
9125
Youhan Wang66ad5d72016-07-18 17:56:58 -07009126 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009127
9128 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009129 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009130 if (phone == null) {
9131 return null;
9132 }
9133 String cdmaPrlVersion = null;
9134 try {
9135 cdmaPrlVersion = phone.getCdmaPrlVersion();
9136 } catch (Exception e) {
9137 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9138 }
9139 return cdmaPrlVersion;
9140 } finally {
9141 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009142 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009143 }
9144
9145 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009146 * Get snapshot of Telephony histograms
9147 * @return List of Telephony histograms
9148 * @hide
9149 */
9150 @Override
9151 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009152 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9153 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009154
9155 final long identity = Binder.clearCallingIdentity();
9156 try {
9157 return RIL.getTelephonyRILTimingHistograms();
9158 } finally {
9159 Binder.restoreCallingIdentity(identity);
9160 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009161 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009162
9163 /**
9164 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009165 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9166 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009167 * Require system privileges. In the future we may add this to carrier APIs.
9168 *
Michele Berionne482f8202018-11-27 18:57:59 -08009169 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009170 */
9171 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009172 @TelephonyManager.SetCarrierRestrictionResult
9173 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009174 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009175
9176 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9177 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers");
9178
vagdeviaf9a5b92018-08-15 16:01:53 -07009179 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009180
Michele Berionne482f8202018-11-27 18:57:59 -08009181 if (carrierRestrictionRules == null) {
9182 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009183 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009184
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009185 final long identity = Binder.clearCallingIdentity();
9186 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009187 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009188 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009189 } finally {
9190 Binder.restoreCallingIdentity(identity);
9191 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009192 }
9193
9194 /**
9195 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009196 * Get the allowed carrier list and the excluded carrier list, including the priority between
9197 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009198 * Require system privileges. In the future we may add this to carrier APIs.
9199 *
Michele Berionne482f8202018-11-27 18:57:59 -08009200 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009201 */
9202 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009203 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009204 enforceReadPrivilegedPermission("getAllowedCarriers");
joonhunshin4ac60942023-11-15 15:23:39 +00009205
9206 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9207 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers");
9208
vagdeviaf9a5b92018-08-15 16:01:53 -07009209 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009210
9211 final long identity = Binder.clearCallingIdentity();
9212 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009213 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9214 if (response instanceof CarrierRestrictionRules) {
9215 return (CarrierRestrictionRules) response;
9216 }
9217 // Response is an Exception of some kind,
9218 // which is signalled to the user as a NULL retval
9219 return null;
9220 } catch (Exception e) {
9221 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9222 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009223 } finally {
9224 Binder.restoreCallingIdentity(identity);
9225 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009226 }
9227
fionaxu59545b42016-05-25 15:53:37 -07009228 /**
arunvoddud7401012022-12-15 16:08:12 +00009229 * Fetches the carrier restriction status of the device and sends the status to the caller
9230 * through the callback.
9231 *
9232 * @param callback The callback that will be used to send the result.
9233 * @throws SecurityException if the caller does not have the required permission/privileges or
9234 * the caller is not allowlisted.
9235 */
9236 @Override
9237 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
9238 enforceReadPermission("getCarrierRestrictionStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00009239
9240 enforceTelephonyFeatureWithException(packageName,
9241 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierRestrictionStatus");
9242
arunvoddud7401012022-12-15 16:08:12 +00009243 int carrierId = validateCallerAndGetCarrierId(packageName);
9244 if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) {
9245 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9246 throw new SecurityException("Not an authorized caller");
9247 }
9248 final long identity = Binder.clearCallingIdentity();
9249 try {
9250 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
9251 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId);
9252 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9253 } finally {
9254 Binder.restoreCallingIdentity(identity);
9255 }
9256 }
9257
arunvoddu567f2b42023-04-25 17:22:00 +00009258 @Override
9259 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
9260 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
9261 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9262 return allowListInfo.getShaIdList(pkgName, carrierId);
9263 }
9264
arunvoddud7401012022-12-15 16:08:12 +00009265 @VisibleForTesting
9266 public int validateCallerAndGetCarrierId(String packageName) {
9267 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9268 return allowListInfo.validateCallerAndGetCarrierId(packageName);
9269 }
9270
9271 /**
fionaxu59545b42016-05-25 15:53:37 -07009272 * Action set from carrier signalling broadcast receivers to enable/disable radio
9273 * @param subId the subscription ID that this action applies to.
9274 * @param enabled control enable or disable radio.
9275 * {@hide}
9276 */
9277 @Override
9278 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9279 enforceModifyPermission();
9280 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009281
9282 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009283 if (phone == null) {
9284 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9285 return;
9286 }
9287 try {
9288 phone.carrierActionSetRadioEnabled(enabled);
9289 } catch (Exception e) {
9290 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009291 } finally {
9292 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009293 }
9294 }
9295
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009296 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009297 * Enable or disable Voice over NR (VoNR)
9298 * @param subId the subscription ID that this action applies to.
9299 * @param enabled enable or disable VoNR.
9300 * @return operation result.
9301 */
9302 @Override
9303 public int setVoNrEnabled(int subId, boolean enabled) {
9304 enforceModifyPermission();
9305 final Phone phone = getPhone(subId);
9306
9307 final long identity = Binder.clearCallingIdentity();
9308 if (phone == null) {
9309 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9310 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9311 }
9312
9313 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9314 try {
9315 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9316 workSource);
9317 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009318
9319 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9320 if (DBG) {
9321 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9322 }
9323 SubscriptionManager.setSubscriptionProperty(
9324 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9325 (enabled ? "1" : "0"));
9326 }
9327
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009328 return result;
9329 } finally {
9330 Binder.restoreCallingIdentity(identity);
9331 }
9332 }
9333
9334 /**
9335 * Is voice over NR enabled
9336 * @return true if VoNR is enabled else false
9337 */
9338 @Override
9339 public boolean isVoNrEnabled(int subId) {
9340 enforceReadPrivilegedPermission("isVoNrEnabled");
9341 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9342 final long identity = Binder.clearCallingIdentity();
9343 try {
9344 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9345 null, subId, workSource);
9346 if (DBG) log("isVoNrEnabled: " + isEnabled);
9347 return isEnabled;
9348 } finally {
9349 Binder.restoreCallingIdentity(identity);
9350 }
9351 }
9352
9353 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009354 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9355 * network status based on which carrier apps could apply actions accordingly,
9356 * enable/disable default url handler for example.
9357 *
9358 * @param subId the subscription ID that this action applies to.
9359 * @param report control start/stop reporting the default network status.
9360 * {@hide}
9361 */
9362 @Override
9363 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9364 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009365
9366 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9367 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
9368 "carrierActionReportDefaultNetworkStatus");
9369
fionaxu8da9cb12017-05-23 15:02:46 -07009370 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009371
9372 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009373 if (phone == null) {
9374 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9375 return;
9376 }
9377 try {
9378 phone.carrierActionReportDefaultNetworkStatus(report);
9379 } catch (Exception e) {
9380 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009381 } finally {
9382 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009383 }
9384 }
9385
9386 /**
fionaxud9622282017-07-17 17:51:30 -07009387 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9388 * @param subId the subscription ID that this action applies to.
9389 * {@hide}
9390 */
9391 @Override
9392 public void carrierActionResetAll(int subId) {
9393 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009394
9395 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9396 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll");
9397
fionaxud9622282017-07-17 17:51:30 -07009398 final Phone phone = getPhone(subId);
9399 if (phone == null) {
9400 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9401 return;
9402 }
9403 try {
9404 phone.carrierActionResetAll();
9405 } catch (Exception e) {
9406 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9407 }
9408 }
9409
9410 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009411 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9412 * bug report is being generated.
9413 */
9414 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009415 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009416 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9417 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009418 writer.println("Permission Denial: can't dump Phone from pid="
9419 + Binder.getCallingPid()
9420 + ", uid=" + Binder.getCallingUid()
9421 + "without permission "
9422 + android.Manifest.permission.DUMP);
9423 return;
9424 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009425 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009426 }
Jack Yueb89b242016-06-22 13:27:47 -07009427
Brad Ebingerdac2f002018-04-03 15:17:52 -07009428 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009429 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9430 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9431 @NonNull String[] args) {
9432 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9433 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009434 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009435 }
9436
Jack Yueb89b242016-06-22 13:27:47 -07009437 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009438 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009439 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009440 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009441 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009442 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009443 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009444 */
9445 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009446 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009447 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009448 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9449 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9450 try {
9451 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009452 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009453 } catch (SecurityException se) {
9454 enforceModifyPermission();
9455 }
9456 } else {
9457 enforceModifyPermission();
9458 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009459
joonhunshin4ac60942023-11-15 15:23:39 +00009460 enforceTelephonyFeatureWithException(callingPackage,
9461 PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason");
9462
Nate Myren116695d2024-02-09 09:36:01 -08009463 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009464 final long identity = Binder.clearCallingIdentity();
9465 try {
Nate Myren116695d2024-02-09 09:36:01 -08009466 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
9467 && null != callingPackage && opEnableMobileDataByUser()) {
9468 mAppOps.noteOp(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER,
9469 callingUid, callingPackage, null, null);
9470 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009471 Phone phone = getPhone(subId);
9472 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009473 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9474 phone.carrierActionSetMeteredApnsEnabled(enabled);
9475 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07009476 phone.getDataSettingsManager().setDataEnabled(
9477 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009478 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009479 }
9480 } finally {
9481 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009482 }
9483 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009484
9485 /**
9486 * Get Client request stats
9487 * @return List of Client Request Stats
9488 * @hide
9489 */
9490 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009491 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9492 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009493 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009494 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009495 return null;
9496 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009497 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009498
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009499 final long identity = Binder.clearCallingIdentity();
9500 try {
9501 if (phone != null) {
9502 return phone.getClientRequestStats();
9503 }
9504
9505 return null;
9506 } finally {
9507 Binder.restoreCallingIdentity(identity);
9508 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009509 }
9510
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009511 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009512 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009513 if (uid == Process.ROOT_UID && packageName == null) {
9514 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9515 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9516 // exception. ROOT_UID seems not to have a valid package name returned by
9517 // PackageManager, so just fake it here to avoid issues when running telephony shell
9518 // commands that plumb through the RIL as root, like so:
9519 // $ adb root
9520 // $ adb shell cmd phone ...
9521 packageName = "root";
9522 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009523 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009524 }
Jack Yueb4124c2017-02-16 15:32:43 -08009525
9526 /**
Grace Chen70990072017-03-24 17:21:30 -07009527 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009528 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009529 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009530 * @param state State of SIM (power down, power up, pass through)
9531 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9532 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9533 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009534 *
9535 **/
9536 @Override
Grace Chen70990072017-03-24 17:21:30 -07009537 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009538 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009539
9540 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9541 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot");
9542
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009543 Phone phone = PhoneFactory.getPhone(slotIndex);
9544
vagdeviaf9a5b92018-08-15 16:01:53 -07009545 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9546
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009547 final long identity = Binder.clearCallingIdentity();
9548 try {
9549 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009550 phone.setSimPowerState(state, null, workSource);
9551 }
9552 } finally {
9553 Binder.restoreCallingIdentity(identity);
9554 }
9555 }
9556
9557 /**
9558 * Set SIM card power state.
9559 *
9560 * @param slotIndex SIM slot id.
9561 * @param state State of SIM (power down, power up, pass through)
9562 * @param callback callback to trigger after success or failure
9563 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9564 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9565 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9566 *
9567 **/
9568 @Override
9569 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9570 IIntegerConsumer callback) {
9571 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009572
9573 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9574 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
9575 "setSimPowerStateForSlotWithCallback");
9576
Jordan Liu109698e2020-11-24 14:50:34 -08009577 Phone phone = PhoneFactory.getPhone(slotIndex);
9578
9579 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9580
9581 final long identity = Binder.clearCallingIdentity();
9582 try {
9583 if (phone != null) {
9584 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9585 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009586 }
9587 } finally {
9588 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009589 }
9590 }
Shuo Qiandd210312017-04-12 22:11:33 +00009591
Tyler Gunn65d45c22017-06-05 11:22:26 -07009592 private boolean isUssdApiAllowed(int subId) {
9593 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009594 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009595 if (configManager == null) {
9596 return false;
9597 }
9598 PersistableBundle pb = configManager.getConfigForSubId(subId);
9599 if (pb == null) {
9600 return false;
9601 }
9602 return pb.getBoolean(
9603 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9604 }
9605
Shuo Qiandd210312017-04-12 22:11:33 +00009606 /**
Ling Mac28f0212023-03-24 16:07:15 -07009607 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00009608 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07009609 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00009610 */
goneil9c5f4872017-12-05 14:07:56 -08009611 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009612 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009613 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
joonhunshin4ac60942023-11-15 15:23:39 +00009614
9615 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9616 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode");
9617
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009618 final long identity = Binder.clearCallingIdentity();
9619 try {
Ling Mac28f0212023-03-24 16:07:15 -07009620 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009621 } finally {
9622 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009623 }
9624 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009625
9626 /**
9627 * Get the current signal strength information for the given subscription.
9628 * Because this information is not updated when the device is in a low power state
9629 * it should not be relied-upon to be current.
9630 * @param subId Subscription index
9631 * @return the most recent cached signal strength info from the modem
9632 */
9633 @Override
9634 public SignalStrength getSignalStrength(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00009635 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9636 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength");
9637
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009638 final long identity = Binder.clearCallingIdentity();
9639 try {
9640 Phone p = getPhone(subId);
9641 if (p == null) {
9642 return null;
9643 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009644
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009645 return p.getSignalStrength();
9646 } finally {
9647 Binder.restoreCallingIdentity(identity);
9648 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009649 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009650
Pengquan Meng77b7f132018-08-22 14:49:57 -07009651 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009652 * Get the current modem radio state for the given slot.
9653 * @param slotIndex slot index.
9654 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009655 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009656 * @return the current radio power state from the modem
9657 */
9658 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009659 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009660 Phone phone = PhoneFactory.getPhone(slotIndex);
9661 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009662 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9663 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009664 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9665 }
9666
joonhunshin4ac60942023-11-15 15:23:39 +00009667 enforceTelephonyFeatureWithException(callingPackage,
9668 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState");
9669
Chen Xuf792fd62018-10-17 17:54:36 +00009670 final long identity = Binder.clearCallingIdentity();
9671 try {
9672 return phone.getRadioPowerState();
9673 } finally {
9674 Binder.restoreCallingIdentity(identity);
9675 }
9676 }
9677 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9678 }
9679
9680 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009681 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9682 *
9683 * <p>Requires one of the following permissions:
9684 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009685 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009686 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9687 * privileges.
9688 *
9689 * @param subId subscription id
9690 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9691 * {@code false}.
9692 */
9693 @Override
9694 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009695 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009696 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009697 try {
9698 mApp.enforceCallingOrSelfPermission(
9699 android.Manifest.permission.ACCESS_NETWORK_STATE,
9700 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009701 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009702 mApp.enforceCallingOrSelfPermission(
9703 permission.READ_BASIC_PHONE_STATE, functionName);
9704 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009705 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009706 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009707 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009708 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009709
joonhunshin4ac60942023-11-15 15:23:39 +00009710 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9711 PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled");
9712
Pengquan Menga1bb6272018-09-06 09:59:22 -07009713 boolean isEnabled = false;
9714 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009715 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009716 Phone phone = getPhone(subId);
9717 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009718 } finally {
9719 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009720 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009721 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009722 }
9723
9724
9725 /**
9726 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9727 *
9728 * <p> Requires permission:
9729 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9730 * privileges.
9731 *
9732 * @param subId subscription id
9733 * @param isEnabled {@code true} means enable, {@code false} means disable.
9734 */
9735 @Override
9736 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009737 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9738 mApp, subId, "setDataRoamingEnabled");
9739
joonhunshin4ac60942023-11-15 15:23:39 +00009740 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9741 PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled");
9742
Pengquan Menga1bb6272018-09-06 09:59:22 -07009743 final long identity = Binder.clearCallingIdentity();
9744 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009745 Phone phone = getPhone(subId);
9746 if (phone != null) {
9747 phone.setDataRoamingEnabled(isEnabled);
9748 }
9749 } finally {
9750 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009751 }
9752 }
9753
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009754 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009755 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009756 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009757 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009758 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009759
joonhunshin4ac60942023-11-15 15:23:39 +00009760 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9761 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed");
9762
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009763 boolean isAllowed = true;
9764 final long identity = Binder.clearCallingIdentity();
9765 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009766 Phone phone = getPhone(subId);
9767 if (phone != null) {
9768 isAllowed = phone.isCspPlmnEnabled();
9769 }
9770 } finally {
9771 Binder.restoreCallingIdentity(identity);
9772 }
9773 return isAllowed;
9774 }
9775
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009776 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9777 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009778 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009779 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009780 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009781 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9782 if (phone == null) {
9783 return false;
9784 }
9785 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9786 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9787 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009788 }
9789
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009790 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009791 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009792 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009793 mApp.getSystemService(AppOpsManager.class)
9794 .checkPackage(Binder.getCallingUid(), callingPackage);
9795
Jordan Liu1e142fc2019-04-22 15:10:43 -07009796 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009797 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009798 try {
9799 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009800 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009801 } catch (SecurityException e) {
9802 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9803 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009804 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009805 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009806 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009807 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009808 }
joonhunshin4ac60942023-11-15 15:23:39 +00009809
9810 enforceTelephonyFeatureWithException(callingPackage,
9811 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo");
9812
sandeepjsb6c87872021-09-27 15:34:44 +00009813 // checking compatibility, if calling app's target SDK is T and beyond.
9814 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9815 Binder.getCallingUid())) {
9816 isIccIdAccessRestricted = true;
9817 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009818 final long identity = Binder.clearCallingIdentity();
9819 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009820 UiccController uiccController = UiccController.getInstance();
9821 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009822 if (hasReadPermission) {
9823 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009824 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009825
9826 // Remove private info if the caller doesn't have access
9827 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9828 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009829 //setting the value after compatibility check
9830 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009831 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9832 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009833 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009834 if (card == null) {
9835 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009836 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009837 continue;
9838 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009839 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9840 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009841 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009842 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009843 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009844 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9845 for (UiccPortInfo portInfo : portInfos) {
9846 UiccPort port = uiccController.getUiccPortForSlot(
9847 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9848 if (port == null) {
9849 // assume no access if port is null
9850 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9851 continue;
9852 }
9853 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9854 uiccPortInfos.add(portInfo);
9855 } else {
9856 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9857 }
9858 }
9859 filteredInfos.add(new UiccCardInfo(
9860 cardInfo.isEuicc(),
9861 cardInfo.getCardId(),
9862 null,
9863 cardInfo.getPhysicalSlotIndex(),
9864 cardInfo.isRemovable(),
9865 cardInfo.isMultipleEnabledProfilesSupported(),
9866 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009867 }
9868 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009869 } finally {
9870 Binder.restoreCallingIdentity(identity);
9871 }
9872 }
9873
sandeepjsb6c87872021-09-27 15:34:44 +00009874 /**
9875 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9876 * generally private and require carrier privileges to view.
9877 *
9878 * @hide
9879 */
9880 @NonNull
9881 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9882 List<UiccPortInfo> portinfo = new ArrayList<>();
9883 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9884 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9885 }
9886 return new UiccCardInfo(
9887 cardInfo.isEuicc(),
9888 cardInfo.getCardId(),
9889 null,
9890 cardInfo.getPhysicalSlotIndex(),
9891 cardInfo.isRemovable(),
9892 cardInfo.isMultipleEnabledProfilesSupported(),
9893 portinfo
9894 );
9895 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009896
sandeepjsb6c87872021-09-27 15:34:44 +00009897 /**
9898 * @hide
9899 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9900 * These values are generally private and require carrier privileges to view.
9901 */
9902 @NonNull
9903 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9904 return new UiccPortInfo(
9905 UiccPortInfo.ICCID_REDACTED,
9906 portInfo.getPortIndex(),
9907 portInfo.getLogicalSlotIndex(),
9908 portInfo.isActive()
9909 );
9910 }
9911 @Override
9912 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009913 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009914 mApp.getSystemService(AppOpsManager.class)
9915 .checkPackage(Binder.getCallingUid(), callingPackage);
9916
sandeepjsb6c87872021-09-27 15:34:44 +00009917 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009918
Aman Guptaf3c90b32022-03-17 04:54:16 +00009919 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9920 // we are reading iccId which is PII data.
9921 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009922
joonhunshin4ac60942023-11-15 15:23:39 +00009923 enforceTelephonyFeatureWithException(callingPackage,
9924 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo");
9925
sandeepjsb6c87872021-09-27 15:34:44 +00009926 // checking compatibility, if calling app's target SDK is T and beyond.
9927 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9928 Binder.getCallingUid())) {
9929 isLogicalSlotAccessRestricted = true;
9930 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009931 final long identity = Binder.clearCallingIdentity();
9932 try {
9933 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009934 if (slots == null || slots.length == 0) {
9935 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009936 return null;
9937 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009938 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9939 for (int i = 0; i < slots.length; i++) {
9940 UiccSlot slot = slots[i];
9941 if (slot == null) {
9942 continue;
9943 }
9944
Jordan Liu7be7e652019-05-06 18:55:02 +00009945 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009946 UiccCard card = slot.getUiccCard();
9947 if (card != null) {
9948 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009949 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009950 cardId = slot.getEid();
9951 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009952 // If cardId is null, use iccId of default port as cardId.
9953 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009954 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009955 }
9956
Jordan Liu857451f2019-05-09 16:35:35 -07009957 if (cardId != null) {
9958 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9959 // if cardId is an EID, it's all digits so this is fine
9960 cardId = IccUtils.stripTrailingFs(cardId);
9961 }
9962
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009963 int cardState = 0;
9964 switch (slot.getCardState()) {
9965 case CARDSTATE_ABSENT:
9966 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9967 break;
9968 case CARDSTATE_PRESENT:
9969 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9970 break;
9971 case CARDSTATE_ERROR:
9972 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9973 break;
9974 case CARDSTATE_RESTRICTED:
9975 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9976 break;
9977 default:
9978 break;
9979
9980 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009981 List<UiccPortInfo> portInfos = new ArrayList<>();
9982 int[] portIndexes = slot.getPortList();
9983 for (int portIdx : portIndexes) {
9984 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009985 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009986 portInfos.add(new UiccPortInfo(iccId, portIdx,
9987 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009988 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009989 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009990 slot.isEuicc(),
9991 cardId,
9992 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009993 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009994 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009995 //setting the value after compatibility check
9996 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009997 }
9998 return infos;
9999 } finally {
10000 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -070010001 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010002 }
10003
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010004 /* Returns null if doesn't have read permission or carrier privilege access. */
10005 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
10006 boolean hasReadPermission) {
10007 String iccId = slot.getIccId(portIndex);
10008 if (hasReadPermission) { // if has read permission
10009 return iccId;
10010 } else {
10011 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
10012 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
10013 // if no read permission, checking carrier privilege access
10014 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
10015 return iccId;
10016 }
10017 }
10018 }
10019 // No read permission or carrier privilege access.
10020 return UiccPortInfo.ICCID_REDACTED;
10021 }
10022
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010023 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010024 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010025 public boolean switchSlots(int[] physicalSlots) {
10026 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010027
joonhunshin4ac60942023-11-15 15:23:39 +000010028 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10029 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots");
10030
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010031 final long identity = Binder.clearCallingIdentity();
10032 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010033 List<UiccSlotMapping> slotMappings = new ArrayList<>();
10034 for (int i = 0; i < physicalSlots.length; i++) {
10035 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
10036 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
10037 physicalSlots[i], i));
10038 }
10039 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010040 } finally {
10041 Binder.restoreCallingIdentity(identity);
10042 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010043 }
Jack Yu4c988042018-02-27 15:30:01 -080010044
10045 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010046 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
10047 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
10048 enforceModifyPermission();
10049
joonhunshin4ac60942023-11-15 15:23:39 +000010050 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10051 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping");
10052
sandeepjsb6c87872021-09-27 15:34:44 +000010053 final long identity = Binder.clearCallingIdentity();
10054 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010055 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +000010056 } finally {
10057 Binder.restoreCallingIdentity(identity);
10058 }
10059 }
10060
10061 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -080010062 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
joonhunshin4ac60942023-11-15 15:23:39 +000010063 enforceTelephonyFeatureWithException(callingPackage,
10064 PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc");
10065
Jordan Liu7de49fa2018-12-06 14:48:49 -080010066 final long identity = Binder.clearCallingIdentity();
10067 try {
10068 return UiccController.getInstance().getCardIdForDefaultEuicc();
10069 } finally {
10070 Binder.restoreCallingIdentity(identity);
10071 }
10072 }
10073
Pengquan Meng85728fb2018-03-12 16:31:21 -070010074 /**
goneil47ffb6e2018-04-06 15:40:58 -070010075 * A test API to reload the UICC profile.
10076 *
10077 * <p>Requires that the calling app has permission
10078 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
10079 * @hide
10080 */
10081 @Override
10082 public void refreshUiccProfile(int subId) {
10083 enforceModifyPermission();
10084
10085 final long identity = Binder.clearCallingIdentity();
10086 try {
10087 Phone phone = getPhone(subId);
10088 if (phone == null) {
10089 return;
10090 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010091 UiccPort uiccPort = phone.getUiccPort();
10092 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -070010093 return;
10094 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010095 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -070010096 if (uiccProfile == null) {
10097 return;
10098 }
10099 uiccProfile.refresh();
10100 } finally {
10101 Binder.restoreCallingIdentity(identity);
10102 }
10103 }
10104
10105 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010106 * Returns false if the mobile data is disabled by default, otherwise return true.
10107 */
10108 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010109 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010110 }
10111
10112 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010113 * Returns the default network type for the given {@code subId}, if the default network type is
10114 * not set, return {@link Phone#PREFERRED_NT_MODE}.
10115 */
10116 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010117 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -080010118 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +090010119 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
10120 return list.get(phoneId);
10121 }
10122 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -070010123 }
fionaxua13278b2018-03-21 00:08:13 -070010124
10125 @Override
10126 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -070010127 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -070010128 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010129
10130 final long identity = Binder.clearCallingIdentity();
10131 try {
10132 final Phone phone = getPhone(subId);
10133 if (phone == null) {
10134 loge("setCarrierTestOverride fails with invalid subId: " + subId);
10135 return;
10136 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -080010137 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10138 if (cpt != null) {
10139 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
10140 }
10141 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -070010142 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
10143 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -070010144 if (carrierPrivilegeRules == null) {
10145 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
10146 } else {
10147 mCarrierPrivilegeTestOverrideSubIds.add(subId);
10148 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010149 } finally {
10150 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010151 }
fionaxua13278b2018-03-21 00:08:13 -070010152 }
10153
10154 @Override
Benedict Wong66477622023-02-03 23:30:57 +000010155 public void setCarrierServicePackageOverride(
10156 int subId, String carrierServicePackage, String callingPackage) {
10157 TelephonyPermissions.enforceShellOnly(
10158 Binder.getCallingUid(), "setCarrierServicePackageOverride");
10159
Benedict Wong66477622023-02-03 23:30:57 +000010160 final long identity = Binder.clearCallingIdentity();
10161 try {
10162 final Phone phone = getPhone(subId);
10163 if (phone == null || phone.getSubId() != subId) {
10164 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
10165 throw new IllegalArgumentException("No phone for subid");
10166 }
10167 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10168 if (cpt == null) {
10169 loge("setCarrierServicePackageOverride failed with no CPT for phone");
10170 throw new IllegalStateException("No CPT for phone");
10171 }
10172 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
10173 } finally {
10174 Binder.restoreCallingIdentity(identity);
10175 }
10176 }
10177
10178 @Override
fionaxua13278b2018-03-21 00:08:13 -070010179 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -070010180 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010181
10182 final long identity = Binder.clearCallingIdentity();
10183 try {
10184 final Phone phone = getPhone(subId);
10185 if (phone == null) {
10186 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
10187 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
10188 }
10189 return phone.getCarrierIdListVersion();
10190 } finally {
10191 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010192 }
fionaxua13278b2018-03-21 00:08:13 -070010193 }
Malcolm Chen2c63d402018-08-14 16:00:53 -070010194
10195 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010196 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
10197 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010198 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010199 mApp, subId, callingPackage, callingFeatureId,
10200 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010201 return -1;
10202 }
10203
10204 final long identity = Binder.clearCallingIdentity();
10205 try {
10206 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10207 } finally {
10208 Binder.restoreCallingIdentity(identity);
10209 }
10210 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010211
10212 @Override
10213 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +080010214 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010215 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010216 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010217
joonhunshin4ac60942023-11-15 15:23:39 +000010218 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10219 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode");
10220
Pengquan Menga1bb6272018-09-06 09:59:22 -070010221 final long identity = Binder.clearCallingIdentity();
10222 try {
10223 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10224 } finally {
10225 Binder.restoreCallingIdentity(identity);
10226 }
10227 }
10228
10229 @Override
10230 public boolean setCdmaRoamingMode(int subId, int mode) {
10231 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10232 mApp, subId, "setCdmaRoamingMode");
10233
joonhunshin4ac60942023-11-15 15:23:39 +000010234 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10235 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode");
10236
Pengquan Menga1bb6272018-09-06 09:59:22 -070010237 final long identity = Binder.clearCallingIdentity();
10238 try {
10239 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10240 } finally {
10241 Binder.restoreCallingIdentity(identity);
10242 }
10243 }
10244
10245 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010246 public int getCdmaSubscriptionMode(int subId) {
10247 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010248 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010249 mApp, subId, "getCdmaSubscriptionMode");
10250
joonhunshin4ac60942023-11-15 15:23:39 +000010251 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10252 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode");
10253
Sarah Chinbaab1432020-10-28 13:46:24 -070010254 final long identity = Binder.clearCallingIdentity();
10255 try {
10256 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10257 } finally {
10258 Binder.restoreCallingIdentity(identity);
10259 }
10260 }
10261
10262 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010263 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10264 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10265 mApp, subId, "setCdmaSubscriptionMode");
10266
joonhunshin4ac60942023-11-15 15:23:39 +000010267 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10268 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode");
10269
Pengquan Menga1bb6272018-09-06 09:59:22 -070010270 final long identity = Binder.clearCallingIdentity();
10271 try {
10272 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10273 } finally {
10274 Binder.restoreCallingIdentity(identity);
10275 }
10276 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010277
sqianc5eccab2018-10-19 18:46:41 -070010278 @Override
sqian8c685422019-02-22 15:55:18 -080010279 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010280 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010281 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010282 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10283 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010284 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10285 }
joonhunshin4ac60942023-11-15 15:23:39 +000010286
10287 enforceTelephonyFeatureWithException(callingPackage,
10288 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList");
10289
sqian11b7a0e2018-12-05 18:48:28 -080010290 final long identity = Binder.clearCallingIdentity();
10291 try {
sqian854d44b2018-12-12 16:48:18 -080010292 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10293 for (Phone phone: PhoneFactory.getPhones()) {
10294 if (phone.getEmergencyNumberTracker() != null
10295 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10296 emergencyNumberListInternal.put(
10297 phone.getSubId(),
10298 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10299 }
sqian11b7a0e2018-12-05 18:48:28 -080010300 }
sqian854d44b2018-12-12 16:48:18 -080010301 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010302 } finally {
10303 Binder.restoreCallingIdentity(identity);
10304 }
sqianc5eccab2018-10-19 18:46:41 -070010305 }
10306
10307 @Override
sqian8c685422019-02-22 15:55:18 -080010308 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010309 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010310 if (!exactMatch) {
10311 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010312 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010313 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010314 }
joonhunshin4ac60942023-11-15 15:23:39 +000010315
10316 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10317 PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber");
10318
sqian11b7a0e2018-12-05 18:48:28 -080010319 final long identity = Binder.clearCallingIdentity();
10320 try {
sqian854d44b2018-12-12 16:48:18 -080010321 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010322 //Note: we ignore passed in param exactMatch. We can remove it once
10323 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010324 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010325 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010326 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010327 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010328 }
sqian11b7a0e2018-12-05 18:48:28 -080010329 }
10330 return false;
10331 } finally {
10332 Binder.restoreCallingIdentity(identity);
10333 }
10334 }
10335
sqianf4ca7ed2019-01-15 18:32:07 -080010336 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010337 * Start emergency callback mode for GsmCdmaPhone for testing.
10338 */
10339 @Override
10340 public void startEmergencyCallbackMode() {
10341 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10342 "startEmergencyCallbackMode");
10343 enforceModifyPermission();
10344 final long identity = Binder.clearCallingIdentity();
10345 try {
10346 for (Phone phone : PhoneFactory.getPhones()) {
10347 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10348 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10349 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10350 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10351 gsmCdmaPhone.obtainMessage(
10352 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10353 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10354 }
10355 }
10356 } finally {
10357 Binder.restoreCallingIdentity(identity);
10358 }
10359 }
10360
10361 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010362 * Update emergency number list for test mode.
10363 */
10364 @Override
10365 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10366 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10367 "updateEmergencyNumberListTestMode");
10368
10369 final long identity = Binder.clearCallingIdentity();
10370 try {
10371 for (Phone phone: PhoneFactory.getPhones()) {
10372 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10373 if (tracker != null) {
10374 tracker.executeEmergencyNumberTestModeCommand(action, num);
10375 }
10376 }
10377 } finally {
10378 Binder.restoreCallingIdentity(identity);
10379 }
10380 }
10381
10382 /**
10383 * Get the full emergency number list for test mode.
10384 */
10385 @Override
10386 public List<String> getEmergencyNumberListTestMode() {
10387 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10388 "getEmergencyNumberListTestMode");
10389
10390 final long identity = Binder.clearCallingIdentity();
10391 try {
10392 Set<String> emergencyNumbers = new HashSet<>();
10393 for (Phone phone: PhoneFactory.getPhones()) {
10394 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10395 if (tracker != null) {
10396 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10397 emergencyNumbers.add(num.getNumber());
10398 }
10399 }
10400 }
10401 return new ArrayList<>(emergencyNumbers);
10402 } finally {
10403 Binder.restoreCallingIdentity(identity);
10404 }
10405 }
10406
chen xud6b45bd2018-10-30 22:27:10 -070010407 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010408 public int getEmergencyNumberDbVersion(int subId) {
10409 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10410
joonhunshin4ac60942023-11-15 15:23:39 +000010411 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10412 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion");
10413
Shuo Qian3b6ee772019-11-13 17:43:31 -080010414 final long identity = Binder.clearCallingIdentity();
10415 try {
10416 final Phone phone = getPhone(subId);
10417 if (phone == null) {
10418 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10419 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10420 }
10421 return phone.getEmergencyNumberDbVersion();
10422 } finally {
10423 Binder.restoreCallingIdentity(identity);
10424 }
10425 }
10426
10427 @Override
10428 public void notifyOtaEmergencyNumberDbInstalled() {
10429 enforceModifyPermission();
10430
joonhunshin4ac60942023-11-15 15:23:39 +000010431 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10432 PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled");
10433
Shuo Qian3b6ee772019-11-13 17:43:31 -080010434 final long identity = Binder.clearCallingIdentity();
10435 try {
10436 for (Phone phone: PhoneFactory.getPhones()) {
10437 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10438 if (tracker != null) {
10439 tracker.updateOtaEmergencyNumberDatabase();
10440 }
10441 }
10442 } finally {
10443 Binder.restoreCallingIdentity(identity);
10444 }
10445 }
10446
10447 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010448 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010449 enforceActiveEmergencySessionPermission();
10450
joonhunshin4ac60942023-11-15 15:23:39 +000010451 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10452 PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath");
10453
Shuo Qian3b6ee772019-11-13 17:43:31 -080010454 final long identity = Binder.clearCallingIdentity();
10455 try {
10456 for (Phone phone: PhoneFactory.getPhones()) {
10457 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10458 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010459 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10460 }
10461 }
10462 } finally {
10463 Binder.restoreCallingIdentity(identity);
10464 }
10465 }
10466
10467 @Override
10468 public void resetOtaEmergencyNumberDbFilePath() {
10469 enforceActiveEmergencySessionPermission();
10470
joonhunshin4ac60942023-11-15 15:23:39 +000010471 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10472 PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath");
10473
Shuo Qianc373f112020-03-05 17:55:34 -080010474 final long identity = Binder.clearCallingIdentity();
10475 try {
10476 for (Phone phone: PhoneFactory.getPhones()) {
10477 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10478 if (tracker != null) {
10479 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010480 }
10481 }
10482 } finally {
10483 Binder.restoreCallingIdentity(identity);
10484 }
10485 }
10486
10487 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010488 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10489 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10490 Phone phone = getPhone(subId);
10491 if (phone == null) {
10492 return null;
10493 }
10494 final long identity = Binder.clearCallingIdentity();
10495 try {
10496 UiccProfile profile = UiccController.getInstance()
10497 .getUiccProfileForPhone(phone.getPhoneId());
10498 if (profile != null) {
10499 return profile.getCertsFromCarrierPrivilegeAccessRules();
10500 }
10501 } finally {
10502 Binder.restoreCallingIdentity(identity);
10503 }
10504 return null;
10505 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010506
10507 /**
10508 * Enable or disable a modem stack.
10509 */
10510 @Override
10511 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10512 enforceModifyPermission();
10513
joonhunshin4ac60942023-11-15 15:23:39 +000010514 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10515 PackageManager.FEATURE_TELEPHONY, "enableModemForSlot");
10516
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010517 final long identity = Binder.clearCallingIdentity();
10518 try {
10519 Phone phone = PhoneFactory.getPhone(slotIndex);
10520 if (phone == null) {
10521 return false;
10522 } else {
10523 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10524 }
10525 } finally {
10526 Binder.restoreCallingIdentity(identity);
10527 }
10528 }
Michelecea4cf22018-12-21 15:00:11 -080010529
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010530 /**
10531 * Whether a modem stack is enabled or not.
10532 */
10533 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010534 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10535 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010536 Phone phone = PhoneFactory.getPhone(slotIndex);
10537 if (phone == null) return false;
10538
10539 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010540 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10541 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010542 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10543 }
10544
joonhunshin4ac60942023-11-15 15:23:39 +000010545 enforceTelephonyFeatureWithException(callingPackage,
10546 PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot");
10547
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010548 final long identity = Binder.clearCallingIdentity();
10549 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010550 try {
10551 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10552 } catch (NoSuchElementException ex) {
10553 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10554 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010555 } finally {
10556 Binder.restoreCallingIdentity(identity);
10557 }
10558 }
10559
Michelecea4cf22018-12-21 15:00:11 -080010560 @Override
Michele0ea7d782019-03-19 14:58:42 -070010561 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010562 enforceModifyPermission();
10563
joonhunshin4ac60942023-11-15 15:23:39 +000010564 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10565 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction");
10566
Michelecea4cf22018-12-21 15:00:11 -080010567 final long identity = Binder.clearCallingIdentity();
10568 try {
10569 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010570 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010571 .commit();
10572 } finally {
10573 Binder.restoreCallingIdentity(identity);
10574 }
10575 }
10576
10577 @Override
Michele0ea7d782019-03-19 14:58:42 -070010578 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010579 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010580 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010581 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10582 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010583 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010584 }
Michelecea4cf22018-12-21 15:00:11 -080010585
joonhunshin4ac60942023-11-15 15:23:39 +000010586 enforceTelephonyFeatureWithException(callingPackage,
10587 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported");
10588
Michelecea4cf22018-12-21 15:00:11 -080010589 final long identity = Binder.clearCallingIdentity();
10590 try {
Michele0ea7d782019-03-19 14:58:42 -070010591 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010592 } finally {
10593 Binder.restoreCallingIdentity(identity);
10594 }
10595 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010596
Michele0ea7d782019-03-19 14:58:42 -070010597 @TelephonyManager.IsMultiSimSupportedResult
10598 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010599 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10600 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10601 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010602 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10603 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010604 }
10605 // Check if the hardware supports multisim functionality. If usage of multisim is not
10606 // supported by the modem, indicate that it is restricted.
10607 PhoneCapability staticCapability =
10608 mPhoneConfigurationManager.getStaticPhoneCapability();
10609 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010610 loge("isMultiSimSupportedInternal: no static configuration available");
10611 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010612 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010613 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010614 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10615 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010616 }
10617 // Check if support of multiple SIMs is restricted by carrier
10618 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010619 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010620 }
10621
Michele0ea7d782019-03-19 14:58:42 -070010622 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010623 }
10624
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010625 /**
10626 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010627 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10628 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10629 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010630 * @param numOfSims number of active sims we want to switch to
10631 */
10632 @Override
10633 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010634 if (numOfSims == 1) {
10635 enforceModifyPermission();
10636 } else {
10637 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10638 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10639 }
joonhunshin4ac60942023-11-15 15:23:39 +000010640
10641 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10642 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig");
10643
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010644 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010645
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010646 try {
Michele30b57b22019-03-01 12:01:14 -080010647 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010648 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010649 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10650 return;
10651 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010652 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10653 } finally {
10654 Binder.restoreCallingIdentity(identity);
10655 }
10656 }
10657
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010658 @Override
10659 public boolean isApplicationOnUicc(int subId, int appType) {
10660 enforceReadPrivilegedPermission("isApplicationOnUicc");
joonhunshin4ac60942023-11-15 15:23:39 +000010661
10662 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10663 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc");
10664
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010665 Phone phone = getPhone(subId);
10666 if (phone == null) {
10667 return false;
10668 }
10669 final long identity = Binder.clearCallingIdentity();
10670 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010671 UiccPort uiccPort = phone.getUiccPort();
10672 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010673 return false;
10674 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010675 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010676 if (uiccProfile == null) {
10677 return false;
10678 }
10679 if (TelephonyManager.APPTYPE_SIM <= appType
10680 && appType <= TelephonyManager.APPTYPE_ISIM) {
10681 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10682 }
10683 return false;
10684 } finally {
10685 Binder.restoreCallingIdentity(identity);
10686 }
10687 }
10688
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010689 /**
chen xub4baa772019-04-03 10:23:41 -070010690 * Get whether making changes to modem configurations will trigger reboot.
10691 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010692 */
10693 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010694 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10695 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010696 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010697 mApp, subId, callingPackage, callingFeatureId,
10698 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010699 return false;
10700 }
joonhunshin4ac60942023-11-15 15:23:39 +000010701
10702 enforceTelephonyFeatureWithException(callingPackage,
10703 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
10704 "doesSwitchMultiSimConfigTriggerReboot");
10705
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010706 final long identity = Binder.clearCallingIdentity();
10707 try {
10708 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10709 } finally {
10710 Binder.restoreCallingIdentity(identity);
10711 }
10712 }
10713
Nathan Harold29f5f052019-02-15 13:41:57 -080010714 private void updateModemStateMetrics() {
10715 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10716 // TODO: check the state for each modem if the api is ready.
10717 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10718 }
10719
Pengquan Meng3889a572019-01-23 11:16:29 -080010720 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010721 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010722 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010723 // Verify that the callingPackage belongs to the calling UID
10724 mApp.getSystemService(AppOpsManager.class)
10725 .checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000010726
10727 enforceTelephonyFeatureWithException(callingPackage,
10728 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping");
10729
Pengquan Meng3889a572019-01-23 11:16:29 -080010730 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010731 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010732 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010733 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10734 if (slotInfos != null) {
10735 for (int i = 0; i < slotInfos.length; i++) {
10736 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10737 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10738 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10739 portInfo.getLogicalSlotIndex()));
10740 }
10741 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010742 }
10743 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010744 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010745 } finally {
10746 Binder.restoreCallingIdentity(identity);
10747 }
10748 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010749
10750 /**
10751 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010752 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010753 */
jimsunf9ec1622022-09-13 21:18:43 +080010754 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010755 @Override
10756 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010757 return getHalVersion(HAL_SERVICE_RADIO);
10758 }
10759
10760 /**
10761 * Get the HAL Version of a specific service
10762 */
10763 @Override
10764 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010765 Phone phone = getDefaultPhone();
10766 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010767 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010768 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10769 return hv.major * 100 + hv.minor;
10770 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010771
10772 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010773 * Get the current calling package name.
sangyun097dcf72024-01-04 10:35:49 +090010774 *
10775 * @return the current calling package name, or null if there is no known package.
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010776 */
10777 @Override
sangyun097dcf72024-01-04 10:35:49 +090010778 public @Nullable String getCurrentPackageName() {
10779 PackageManager pm = mApp.getPackageManager();
10780 String[] packageNames = pm == null ? null : pm.getPackagesForUid(Binder.getCallingUid());
10781 return packageNames == null ? null : packageNames[0];
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010782 }
10783
10784 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010785 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10786 * corresponding network requests on a subId.
10787 *
10788 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010789 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010790 * 2) APN is un-metered for this subscription, or
10791 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010792 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010793 *
10794 * @return whether data is allowed for a apn type.
10795 *
10796 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010797 */
10798 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010799 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010800 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10801 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010802
joonhunshin4ac60942023-11-15 15:23:39 +000010803 enforceTelephonyFeatureWithException(callingPackage,
10804 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn");
10805
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010806 // Now that all security checks passes, perform the operation as ourselves.
10807 final long identity = Binder.clearCallingIdentity();
10808 try {
10809 Phone phone = getPhone(subId);
10810 if (phone == null) return false;
10811
Jack Yu27422a52022-03-21 10:38:05 -070010812 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010813 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010814 isMetered = phone.getDataNetworkController().getDataConfigManager()
10815 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10816 phone.getServiceState().getDataRoaming());
10817 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010818 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010819 } finally {
10820 Binder.restoreCallingIdentity(identity);
10821 }
10822 }
10823
10824 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010825 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010826 enforceReadPrivilegedPermission("isApnMetered");
10827
joonhunshin4ac60942023-11-15 15:23:39 +000010828 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10829 PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered");
10830
Malcolm Chene5ad5792019-04-18 13:51:02 -070010831 // Now that all security checks passes, perform the operation as ourselves.
10832 final long identity = Binder.clearCallingIdentity();
10833 try {
10834 Phone phone = getPhone(subId);
10835 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010836 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10837 DataUtils.apnTypeToNetworkCapability(apnType),
10838 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010839 } finally {
10840 Binder.restoreCallingIdentity(identity);
10841 }
10842 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010843
10844 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010845 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10846 int subscriptionId, IBooleanConsumer resultCallback) {
10847 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +000010848
10849 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10850 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels");
10851
Hall Liu73f5d362020-01-20 13:42:00 -080010852 long token = Binder.clearCallingIdentity();
10853 try {
10854 Phone phone = getPhone(subscriptionId);
10855 if (phone == null) {
10856 try {
10857 if (resultCallback != null) {
10858 resultCallback.accept(false);
10859 }
10860 } catch (RemoteException e) {
10861 // ignore
10862 }
10863 return;
10864 }
10865 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10866 Pair.create(specifiers, (x) -> {
10867 try {
10868 if (resultCallback != null) {
10869 resultCallback.accept(x);
10870 }
10871 } catch (RemoteException e) {
10872 // ignore
10873 }
10874 });
10875 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10876 } finally {
10877 Binder.restoreCallingIdentity(token);
10878 }
10879 }
10880
10881 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010882 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10883 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010884 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010885 mApp, subId, "getSystemSelectionChannels");
joonhunshin4ac60942023-11-15 15:23:39 +000010886
10887 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10888 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels");
10889
Sarah Chin679c08a2020-11-18 13:39:35 -080010890 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10891 final long identity = Binder.clearCallingIdentity();
10892 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010893 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10894 if (result instanceof IllegalStateException) {
10895 throw (IllegalStateException) result;
10896 }
10897 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010898 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10899 return specifiers;
10900 } finally {
10901 Binder.restoreCallingIdentity(identity);
10902 }
10903 }
10904
10905 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010906 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010907 enforceReadPrivilegedPermission("isMvnoMatched");
joonhunshin4ac60942023-11-15 15:23:39 +000010908
10909 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10910 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched");
10911
Jack Yu8b766fc2022-03-21 09:42:33 -070010912 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010913 }
10914
10915 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010916 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10917 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010918 if (callingPackage == null) {
10919 callingPackage = getCurrentPackageName();
10920 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010921 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10922 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010923 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10924 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010925 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10926 }
10927 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10928 Intent intent = new Intent();
10929 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10930 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10931 // Bring up choose default SMS subscription dialog right now
10932 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10933 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10934 mApp.startActivity(intent);
10935 }
chen xud5ca2d52019-05-28 15:20:57 -070010936
10937 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010938 public void showSwitchToManagedProfileDialog() {
10939 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000010940 try {
10941 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
10942 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
10943 // for work telephony.
10944 Intent intent = new Intent(Intent.ACTION_SENDTO);
10945 intent.setData(Uri.parse("smsto:"));
10946 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10947 mApp.startActivity(intent);
10948 } catch (ActivityNotFoundException e) {
10949 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
10950 Intent intent = new Intent();
10951 intent.setClass(mApp, ErrorDialogActivity.class);
10952 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10953 mApp.startActivity(intent);
10954 }
Ayush Sharma787854b2022-12-12 14:55:02 +000010955 }
10956
10957 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010958 public String getMmsUAProfUrl(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000010959 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10960 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl");
10961
chen xud5ca2d52019-05-28 15:20:57 -070010962 //TODO investigate if this API should require proper permission check in R b/133791609
10963 final long identity = Binder.clearCallingIdentity();
10964 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010965 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10966 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10967 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10968 return carrierUAProfUrl;
10969 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010970 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10971 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010972 } finally {
10973 Binder.restoreCallingIdentity(identity);
10974 }
10975 }
10976
10977 @Override
10978 public String getMmsUserAgent(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000010979 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10980 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent");
10981
chen xud5ca2d52019-05-28 15:20:57 -070010982 //TODO investigate if this API should require proper permission check in R b/133791609
10983 final long identity = Binder.clearCallingIdentity();
10984 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010985 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10986 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10987 if (!TextUtils.isEmpty(carrierUserAgent)) {
10988 return carrierUserAgent;
10989 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010990 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10991 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010992 } finally {
10993 Binder.restoreCallingIdentity(identity);
10994 }
10995 }
Jack Yub07d4972019-05-28 16:12:25 -070010996
10997 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010998 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10999 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070011000
joonhunshin4ac60942023-11-15 15:23:39 +000011001 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11002 PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled");
11003
Jack Yub07d4972019-05-28 16:12:25 -070011004 final long identity = Binder.clearCallingIdentity();
11005 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011006 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070011007 if (phone == null) return false;
11008
Ling Maf188d502022-09-16 15:22:36 -070011009 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070011010 } finally {
11011 Binder.restoreCallingIdentity(identity);
11012 }
11013 }
11014
11015 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080011016 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070011017 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080011018 enforceModifyPermission();
11019
joonhunshin4ac60942023-11-15 15:23:39 +000011020 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11021 PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled");
11022
changbettyd5c246e2019-12-24 15:40:37 +080011023 final long identity = Binder.clearCallingIdentity();
11024 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011025 Phone phone = getPhone(subscriptionId);
11026 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080011027
Ling Maf188d502022-09-16 15:22:36 -070011028 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080011029 } finally {
11030 Binder.restoreCallingIdentity(identity);
11031 }
11032 }
11033
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011034 /**
Hall Liu746e03c2020-09-25 11:13:49 -070011035 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011036 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
11037 * otherwise.
11038 */
11039 @Override
11040 public void setCepEnabled(boolean isCepEnabled) {
11041 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
11042
11043 final long identity = Binder.clearCallingIdentity();
11044 try {
11045 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
11046 for (Phone phone : PhoneFactory.getPhones()) {
11047 Phone defaultPhone = phone.getImsPhone();
11048 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
11049 ImsPhone imsPhone = (ImsPhone) defaultPhone;
11050 ImsPhoneCallTracker imsPhoneCallTracker =
11051 (ImsPhoneCallTracker) imsPhone.getCallTracker();
11052 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
11053 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
11054 + imsPhone.getMsisdn());
11055 }
11056 }
11057 } finally {
11058 Binder.restoreCallingIdentity(identity);
11059 }
11060 }
allenwtsu46dcc572020-01-08 18:24:03 +080011061
11062 /**
11063 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
11064 *
11065 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
11066 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
11067 * before being read.
11068 */
11069 @Override
11070 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
11071 isCompressed) {
11072 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11073 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011074 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11075 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11076 }
joonhunshin4ac60942023-11-15 15:23:39 +000011077
11078 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11079 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11080 Binder.getCallingUserHandle())) {
11081 if (!isImsAvailableOnDevice()) {
11082 // ProvisioningManager can not handle ServiceSpecificException.
11083 // Throw the IllegalStateException and annotate ProvisioningManager.
11084 throw new IllegalStateException("IMS not available on device.");
11085 }
11086 } else {
11087 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11088 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11089 "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011090 }
11091
11092 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080011093 try {
Hui Wang761a6682020-10-31 05:12:53 +000011094 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
11095 } finally {
11096 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080011097 }
11098 }
zoey chene02881a2019-12-30 16:11:23 +080011099
11100 @Override
11101 public boolean isIccLockEnabled(int subId) {
11102 enforceReadPrivilegedPermission("isIccLockEnabled");
11103
joonhunshin4ac60942023-11-15 15:23:39 +000011104 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11105 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled");
11106
zoey chene02881a2019-12-30 16:11:23 +080011107 // Now that all security checks passes, perform the operation as ourselves.
11108 final long identity = Binder.clearCallingIdentity();
11109 try {
11110 Phone phone = getPhone(subId);
11111 if (phone != null && phone.getIccCard() != null) {
11112 return phone.getIccCard().getIccLockEnabled();
11113 } else {
11114 return false;
11115 }
11116 } finally {
11117 Binder.restoreCallingIdentity(identity);
11118 }
11119 }
11120
11121 /**
11122 * Set the ICC pin lock enabled or disabled.
11123 *
11124 * @return an integer representing the status of IccLock enabled or disabled in the following
11125 * three cases:
11126 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
11127 * successfully.
11128 * - Positive number and zero for remaining password attempts.
11129 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11130 *
11131 */
11132 @Override
11133 public int setIccLockEnabled(int subId, boolean enabled, String password) {
11134 enforceModifyPermission();
11135
joonhunshin4ac60942023-11-15 15:23:39 +000011136 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11137 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled");
11138
zoey chene02881a2019-12-30 16:11:23 +080011139 Phone phone = getPhone(subId);
11140 if (phone == null) {
11141 return 0;
11142 }
11143 // Now that all security checks passes, perform the operation as ourselves.
11144 final long identity = Binder.clearCallingIdentity();
11145 try {
11146 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
11147 new Pair<Boolean, String>(enabled, password), phone, null);
11148 return attemptsRemaining;
11149
11150 } catch (Exception e) {
11151 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
11152 } finally {
11153 Binder.restoreCallingIdentity(identity);
11154 }
11155 return 0;
11156 }
11157
11158 /**
11159 * Change the ICC password used in ICC pin lock.
11160 *
11161 * @return an integer representing the status of IccLock changed in the following three cases:
11162 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
11163 * - Positive number and zero for remaining password attempts.
11164 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11165 *
11166 */
11167 @Override
11168 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
11169 enforceModifyPermission();
11170
joonhunshin4ac60942023-11-15 15:23:39 +000011171 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11172 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword");
11173
zoey chene02881a2019-12-30 16:11:23 +080011174 Phone phone = getPhone(subId);
11175 if (phone == null) {
11176 return 0;
11177 }
11178 // Now that all security checks passes, perform the operation as ourselves.
11179 final long identity = Binder.clearCallingIdentity();
11180 try {
11181 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
11182 new Pair<String, String>(oldPassword, newPassword), phone, null);
11183 return attemptsRemaining;
11184
11185 } catch (Exception e) {
11186 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
11187 } finally {
11188 Binder.restoreCallingIdentity(identity);
11189 }
11190 return 0;
11191 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080011192
11193 /**
11194 * Request for receiving user activity notification
11195 */
11196 @Override
11197 public void requestUserActivityNotification() {
11198 if (!mNotifyUserActivity.get()
11199 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
11200 mNotifyUserActivity.set(true);
11201 }
11202 }
11203
11204 /**
11205 * Called when userActivity is signalled in the power manager.
11206 * This is safe to call from any thread, with any window manager locks held or not.
11207 */
11208 @Override
11209 public void userActivity() {
11210 // ***************************************
11211 // * Inherited from PhoneWindowManager *
11212 // ***************************************
11213 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
11214 // WITH ITS LOCKS HELD.
11215 //
11216 // This code must be VERY careful about the locks
11217 // it acquires.
11218 // In fact, the current code acquires way too many,
11219 // and probably has lurking deadlocks.
11220
11221 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
11222 throw new SecurityException("Only the OS may call notifyUserActivity()");
11223 }
11224
11225 if (mNotifyUserActivity.getAndSet(false)) {
11226 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
11227 USER_ACTIVITY_NOTIFICATION_DELAY);
11228 }
11229 }
Malcolm Chen4639c562020-04-13 11:59:40 -070011230
11231 @Override
11232 public boolean canConnectTo5GInDsdsMode() {
11233 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
11234 }
Jack Yud10cdd42020-09-28 20:28:01 -070011235
11236 @Override
11237 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
11238 String callingFeatureId) {
11239 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
11240 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
11241 throw new SecurityException("Requires READ_PHONE_STATE permission.");
11242 }
11243
joonhunshin4ac60942023-11-15 15:23:39 +000011244 enforceTelephonyFeatureWithException(callingPackage,
11245 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns");
11246
Jack Yud10cdd42020-09-28 20:28:01 -070011247 Phone phone = getPhone(subId);
11248 if (phone == null) {
11249 throw new RuntimeException("phone is not available");
11250 }
11251 // Now that all security checks passes, perform the operation as ourselves.
11252 final long identity = Binder.clearCallingIdentity();
11253 try {
11254 return phone.getEquivalentHomePlmns();
11255 } finally {
11256 Binder.restoreCallingIdentity(identity);
11257 }
11258 }
Daniel Bright59e67312020-11-13 11:49:37 -080011259
11260 @Override
11261 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011262 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
joonhunshin4ac60942023-11-15 15:23:39 +000011263 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11264 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
11265 "isRadioInterfaceCapabilitySupported");
11266
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011267 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080011268 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080011269 if (radioInterfaceCapabilities == null) {
11270 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080011271 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011272 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080011273 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011274
Hui Wang641e81c2020-10-12 12:14:23 -070011275 @Override
11276 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
11277 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000011278 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
11279 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11280 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
11281 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11282 Manifest.permission.MODIFY_PHONE_STATE);
joonhunshin4ac60942023-11-15 15:23:39 +000011283
11284 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11285 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest");
11286
Hui Wang641e81c2020-10-12 12:14:23 -070011287 if (DBG) {
11288 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
11289 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
11290 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
11291 }
11292
11293 if (!SubscriptionManager.isValidSubscriptionId(subId)
11294 || appType < TelephonyManager.APPTYPE_UNKNOWN
11295 || appType > TelephonyManager.APPTYPE_ISIM
11296 || nafUrl == null || securityProtocol == null || callback == null) {
11297 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
11298 if (callback != null) {
11299 try {
11300 callback.onAuthenticationFailure(
11301 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
11302 } catch (RemoteException exception) {
11303 log("Fail to notify onAuthenticationFailure due to " + exception);
11304 }
11305 return;
11306 }
11307 }
11308
11309 final long token = Binder.clearCallingIdentity();
11310 try {
11311 getGbaManager(subId).bootstrapAuthenticationRequest(
11312 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011313 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070011314 } finally {
11315 Binder.restoreCallingIdentity(token);
11316 }
11317 }
11318
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011319 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011320 * Attempts to set the radio power state for all phones for thermal reason.
11321 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011322 * requested radio power state will actually be set. See {@link
11323 * PhoneInternalInterface#setRadioPowerForReason} for more details.
11324 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011325 * @param enable {@code true} if trying to turn radio on.
11326 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
11327 * false}.
11328 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011329 private boolean setRadioPowerForThermal(boolean enable) {
11330 boolean isPhoneAvailable = false;
11331 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
11332 Phone phone = PhoneFactory.getPhone(i);
11333 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011334 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011335 isPhoneAvailable = true;
11336 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011337 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011338
11339 // return true if successfully informed the phone object about the thermal radio power
11340 // request.
11341 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011342 }
11343
11344 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011345 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011346 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11347 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11348 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11349 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11350 throw new IllegalArgumentException("modem does not support data throttling");
11351 }
11352
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011353 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11354 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011355 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011356 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11357 }
11358
Sarah Chinecc78c42022-03-31 21:16:48 -070011359 setDataEnabledForReason(
11360 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011361
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011362 if (isDataThrottlingSupported) {
11363 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011364 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011365 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11366 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11367 } else if (thermalMitigationResult
11368 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011369 log("Modem likely does not support data throttling on secondary carrier. Data " +
11370 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11371 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011372 }
11373 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011374 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011375
11376 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011377 }
11378
Jack Nudelman644b91a2021-03-12 14:09:48 -080011379 private static List<String> getThermalMitigationAllowlist(Context context) {
11380 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11381 for (String pckg : context.getResources()
11382 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11383 sThermalMitigationAllowlistedPackages.add(pckg);
11384 }
11385 }
11386
11387 return sThermalMitigationAllowlistedPackages;
11388 }
11389
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011390 private boolean isAnyPhoneInEmergencyState() {
11391 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11392 if (tm.isInEmergencyCall()) {
11393 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11394 return true;
11395 }
11396 for (Phone phone : PhoneFactory.getPhones()) {
11397 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11398 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011399 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11400 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011401 return true;
11402 }
11403 }
11404
11405 return false;
11406 }
11407
Jack Nudelman644b91a2021-03-12 14:09:48 -080011408 /**
11409 * Used by shell commands to add an authorized package name for thermal mitigation.
11410 * @param packageName name of package to be allowlisted
11411 * @param context
11412 */
11413 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11414 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11415 sThermalMitigationAllowlistedPackages.add(packageName);
11416 }
11417
11418 /**
11419 * Used by shell commands to remove an authorized package name for thermal mitigation.
11420 * @param packageName name of package to remove from allowlist
11421 * @param context
11422 */
11423 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11424 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11425 sThermalMitigationAllowlistedPackages.remove(packageName);
11426 }
11427
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011428 /**
11429 * Thermal mitigation request to control functionalities at modem.
11430 *
11431 * @param subId the id of the subscription.
11432 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011433 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011434 *
11435 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11436 */
11437 @Override
11438 @ThermalMitigationResult
11439 public int sendThermalMitigationRequest(
11440 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011441 ThermalMitigationRequest thermalMitigationRequest,
11442 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011443 enforceModifyPermission();
11444
Jack Nudelman644b91a2021-03-12 14:09:48 -080011445 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000011446
11447 enforceTelephonyFeatureWithException(callingPackage,
11448 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest");
11449
Jack Nudelman644b91a2021-03-12 14:09:48 -080011450 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11451 .contains(callingPackage)) {
11452 throw new SecurityException("Calling package must be configured in the device config. "
11453 + "calling package: " + callingPackage);
11454 }
11455
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011456 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11457 final long identity = Binder.clearCallingIdentity();
11458
11459 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11460 try {
11461 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11462 switch (thermalMitigationAction) {
11463 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11464 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011465 handleDataThrottlingRequest(subId,
11466 thermalMitigationRequest.getDataThrottlingRequest(),
11467 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011468 break;
11469 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11470 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11471 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11472 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11473 }
11474
11475 // Ensure that radio is on. If not able to power on due to phone being
11476 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011477 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011478 thermalMitigationResult =
11479 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11480 break;
11481 }
11482
11483 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011484 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011485 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11486 break;
11487 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11488 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11489 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11490 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11491 }
11492
11493 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11494 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011495 Phone phone = getPhone(subId);
11496 if (phone == null) {
11497 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011498 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011499 break;
11500 }
11501
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011502 TelephonyConnectionService service =
11503 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011504 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011505 Log.e(LOG_TAG, "An emergency call is pending");
11506 thermalMitigationResult =
11507 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11508 break;
11509 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011510 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011511 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011512 break;
11513 }
11514 } else {
11515 thermalMitigationResult =
11516 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11517 break;
11518 }
11519
11520 // Turn radio off. If not able to power off due to phone being unavailable,
11521 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011522 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011523 thermalMitigationResult =
11524 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11525 break;
11526 }
11527 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011528 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011529 break;
11530 default:
11531 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11532 + "not exist. Requested action: " + thermalMitigationAction);
11533 }
11534 } catch (IllegalArgumentException e) {
11535 throw e;
11536 } catch (Exception e) {
11537 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11538 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11539 } finally {
11540 Binder.restoreCallingIdentity(identity);
11541 }
11542
11543 if (DBG) {
11544 log("thermalMitigationRequest returning with thermalMitigationResult: "
11545 + thermalMitigationResult);
11546 }
11547
11548 return thermalMitigationResult;
11549 }
Hui Wang641e81c2020-10-12 12:14:23 -070011550
11551 /**
11552 * Set the GbaService Package Name that Telephony will bind to.
11553 *
11554 * @param subId The sim that the GbaService is associated with.
11555 * @param packageName The name of the package to be replaced with.
11556 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11557 */
11558 @Override
11559 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11560 enforceModifyPermission();
11561
11562 final long identity = Binder.clearCallingIdentity();
11563 try {
11564 return getGbaManager(subId).overrideServicePackage(packageName);
11565 } finally {
11566 Binder.restoreCallingIdentity(identity);
11567 }
11568 }
11569
11570 /**
11571 * Return the package name of the currently bound GbaService.
11572 *
11573 * @param subId The sim that the GbaService is associated with.
11574 * @return the package name of the GbaService configuration, null if GBA is not supported.
11575 */
11576 @Override
11577 public String getBoundGbaService(int subId) {
11578 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11579
11580 final long identity = Binder.clearCallingIdentity();
11581 try {
11582 return getGbaManager(subId).getServicePackage();
11583 } finally {
11584 Binder.restoreCallingIdentity(identity);
11585 }
11586 }
11587
11588 /**
11589 * Set the release time for telephony to unbind GbaService.
11590 *
11591 * @param subId The sim that the GbaService is associated with.
11592 * @param interval The release time to unbind GbaService by millisecond.
11593 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11594 */
11595 @Override
11596 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11597 enforceModifyPermission();
11598
11599 final long identity = Binder.clearCallingIdentity();
11600 try {
11601 return getGbaManager(subId).overrideReleaseTime(interval);
11602 } finally {
11603 Binder.restoreCallingIdentity(identity);
11604 }
11605 }
11606
11607 /**
11608 * Return the release time for telephony to unbind GbaService.
11609 *
11610 * @param subId The sim that the GbaService is associated with.
11611 * @return The release time to unbind GbaService by millisecond.
11612 */
11613 @Override
11614 public int getGbaReleaseTime(int subId) {
11615 enforceReadPrivilegedPermission("getGbaReleaseTime");
11616
11617 final long identity = Binder.clearCallingIdentity();
11618 try {
11619 return getGbaManager(subId).getReleaseTime();
11620 } finally {
11621 Binder.restoreCallingIdentity(identity);
11622 }
11623 }
11624
11625 private GbaManager getGbaManager(int subId) {
11626 GbaManager instance = GbaManager.getInstance(subId);
11627 if (instance == null) {
11628 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11629 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11630 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11631 }
11632 return instance;
11633 }
Hui Wang761a6682020-10-31 05:12:53 +000011634
11635 /**
11636 * indicate whether the device and the carrier can support
11637 * RCS VoLTE single registration.
11638 */
11639 @Override
11640 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011641 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11642 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11643 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11644 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011645
11646 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11647 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11648 }
11649
11650 final long identity = Binder.clearCallingIdentity();
11651 try {
11652 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11653 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011654 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11655 if (isCapable != null) {
11656 return isCapable;
11657 }
Hui Wang761a6682020-10-31 05:12:53 +000011658 }
Hui Wang67af90e2021-06-04 16:57:15 -070011659 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11660 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011661 } finally {
11662 Binder.restoreCallingIdentity(identity);
11663 }
11664 }
11665
11666 /**
11667 * Register RCS provisioning callback.
11668 */
11669 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011670 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011671 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011672 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011673 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011674 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11675 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011676
11677 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11678 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11679 }
joonhunshin4ac60942023-11-15 15:23:39 +000011680 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11681 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11682 Binder.getCallingUserHandle())) {
11683 if (!isImsAvailableOnDevice()) {
11684 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11685 "IMS not available on device.");
11686 }
11687 } else {
11688 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11689 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011690 }
11691
11692 final long identity = Binder.clearCallingIdentity();
11693 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011694 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011695 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011696 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11697 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011698 }
Hui Wang761a6682020-10-31 05:12:53 +000011699 } finally {
11700 Binder.restoreCallingIdentity(identity);
11701 }
11702 }
11703
11704 /**
11705 * Unregister RCS provisioning callback.
11706 */
11707 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011708 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011709 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011710 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011711 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011712 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11713 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011714
11715 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11716 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11717 }
joonhunshin4ac60942023-11-15 15:23:39 +000011718
11719 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11720 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11721 Binder.getCallingUserHandle())) {
11722 if (!isImsAvailableOnDevice()) {
11723 // operation failed silently
11724 Rlog.w(LOG_TAG, "IMS not available on device.");
11725 return;
11726 }
11727 } else {
11728 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11729 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11730 "unregisterRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011731 }
11732
11733 final long identity = Binder.clearCallingIdentity();
11734 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011735 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011736 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011737 } finally {
11738 Binder.restoreCallingIdentity(identity);
11739 }
11740 }
11741
11742 /**
11743 * trigger RCS reconfiguration.
11744 */
11745 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011746 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11747 "triggerRcsReconfiguration",
11748 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011749
11750 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11751 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11752 }
joonhunshin4ac60942023-11-15 15:23:39 +000011753 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11754 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11755 Binder.getCallingUserHandle())) {
11756 if (!isImsAvailableOnDevice()) {
11757 // ProvisioningManager can not handle ServiceSpecificException.
11758 // Throw the IllegalStateException and annotate ProvisioningManager.
11759 throw new IllegalStateException("IMS not available on device.");
11760 }
11761 } else {
11762 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11763 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011764 }
11765
11766 final long identity = Binder.clearCallingIdentity();
11767 try {
11768 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11769 } finally {
11770 Binder.restoreCallingIdentity(identity);
11771 }
11772 }
11773
11774 /**
11775 * Provide the client configuration parameters of the RCS application.
11776 */
11777 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011778 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11779 "setRcsClientConfiguration",
11780 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011781
11782 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11783 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11784 }
joonhunshin4ac60942023-11-15 15:23:39 +000011785 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11786 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11787 Binder.getCallingUserHandle())) {
11788 if (!isImsAvailableOnDevice()) {
11789 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11790 "IMS not available on device.");
11791 }
11792 } else {
11793 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11794 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011795 }
11796
11797 final long identity = Binder.clearCallingIdentity();
11798
11799 try {
11800 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11801 if (configBinder == null) {
11802 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011803 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11804 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011805 } else {
11806 configBinder.setRcsClientConfiguration(rcc);
11807 }
joonhunshin3e154242021-09-17 06:33:39 +000011808
11809 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11810 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011811 } catch (RemoteException e) {
11812 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011813 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11814 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011815 } finally {
11816 Binder.restoreCallingIdentity(identity);
11817 }
11818 }
11819
11820 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011821 * Enables or disables the test mode for RCS VoLTE single registration.
11822 */
11823 @Override
11824 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11825 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11826 "setRcsSingleRegistrationTestModeEnabled");
11827
11828 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11829 }
11830
11831 /**
11832 * Gets the test mode for RCS VoLTE single registration.
11833 */
11834 @Override
11835 public boolean getRcsSingleRegistrationTestModeEnabled() {
11836 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11837 "getRcsSingleRegistrationTestModeEnabled");
11838
11839 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11840 }
11841
11842 /**
Hui Wang761a6682020-10-31 05:12:53 +000011843 * Overrides the config of RCS VoLTE single registration enabled for the device.
11844 */
11845 @Override
11846 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11847 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11848 "setDeviceSingleRegistrationEnabledOverride");
11849 enforceModifyPermission();
11850
11851 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11852 : Boolean.parseBoolean(enabledStr);
11853 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011854 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011855 }
11856
11857 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011858 * Sends a device to device communication message. Only usable via shell.
11859 * @param message message to send.
11860 * @param value message value.
11861 */
11862 @Override
11863 public void sendDeviceToDeviceMessage(int message, int value) {
11864 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011865 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011866 enforceModifyPermission();
11867
11868 final long identity = Binder.clearCallingIdentity();
11869 try {
11870 TelephonyConnectionService service =
11871 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11872 if (service == null) {
11873 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11874 return;
11875 }
11876 service.sendTestDeviceToDeviceMessage(message, value);
11877 } finally {
11878 Binder.restoreCallingIdentity(identity);
11879 }
11880 }
11881
Tyler Gunnbabbda02021-02-10 11:05:02 -080011882 /**
11883 * Sets the specified device to device transport active.
11884 * @param transport The transport to set active.
11885 */
11886 @Override
11887 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11888 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11889 "setActiveDeviceToDeviceTransport");
11890 enforceModifyPermission();
11891
11892 final long identity = Binder.clearCallingIdentity();
11893 try {
11894 TelephonyConnectionService service =
11895 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11896 if (service == null) {
11897 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11898 return;
11899 }
11900 service.setActiveDeviceToDeviceTransport(transport);
11901 } finally {
11902 Binder.restoreCallingIdentity(identity);
11903 }
11904 }
Tyler Gunn92479152021-01-20 16:30:10 -080011905
Tyler Gunnd4339262021-05-03 14:46:49 -070011906 @Override
11907 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11908 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11909 "setDeviceToDeviceForceEnabled");
11910
11911 final long identity = Binder.clearCallingIdentity();
11912 try {
11913 Arrays.stream(PhoneFactory.getPhones()).forEach(
11914 p -> {
11915 Phone thePhone = p.getImsPhone();
11916 if (thePhone != null && thePhone instanceof ImsPhone) {
11917 ImsPhone imsPhone = (ImsPhone) thePhone;
11918 CallTracker tracker = imsPhone.getCallTracker();
11919 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11920 ImsPhoneCallTracker imsPhoneCallTracker =
11921 (ImsPhoneCallTracker) tracker;
11922 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11923 }
11924 }
11925 }
11926 );
11927 } finally {
11928 Binder.restoreCallingIdentity(identity);
11929 }
11930 }
11931
Tyler Gunn92479152021-01-20 16:30:10 -080011932 /**
Hui Wang761a6682020-10-31 05:12:53 +000011933 * Gets the config of RCS VoLTE single registration enabled for the device.
11934 */
11935 @Override
11936 public boolean getDeviceSingleRegistrationEnabled() {
11937 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11938 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11939 }
11940
11941 /**
11942 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11943 */
11944 @Override
11945 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11946 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11947 "setCarrierSingleRegistrationEnabledOverride");
11948 enforceModifyPermission();
11949
11950 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11951 : Boolean.parseBoolean(enabledStr);
11952 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11953 subId, enabled);
11954 }
11955
11956 /**
11957 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11958 */
11959 @Override
11960 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11961 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11962 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11963 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011964
11965 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011966 * Overrides the ims feature validation result
11967 */
11968 @Override
11969 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11970 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11971 "setImsFeatureValidationOverride");
11972
11973 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11974 : Boolean.parseBoolean(enabledStr);
11975 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11976 subId, enabled);
11977 }
11978
11979 /**
11980 * Gets the ims feature validation override value
11981 */
11982 @Override
11983 public boolean getImsFeatureValidationOverride(int subId) {
11984 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11985 "getImsFeatureValidationOverride");
11986 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11987 }
11988
11989 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011990 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11991 * their mobile plan.
11992 */
11993 @Override
11994 public String getMobileProvisioningUrl() {
11995 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
11996 final long identity = Binder.clearCallingIdentity();
11997 try {
11998 return getDefaultPhone().getMobileProvisioningUrl();
11999 } finally {
12000 Binder.restoreCallingIdentity(identity);
12001 }
12002 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012003
James.cf Linbcdf8b32021-01-14 16:44:13 +080012004 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080012005 * Get the EAB contact from the EAB database.
12006 */
12007 @Override
12008 public String getContactFromEab(String contact) {
12009 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
12010 enforceModifyPermission();
12011 final long identity = Binder.clearCallingIdentity();
12012 try {
12013 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
12014 } finally {
12015 Binder.restoreCallingIdentity(identity);
12016 }
12017 }
12018
12019 /**
Calvin Pana1434322021-07-01 19:27:01 +080012020 * Get the EAB capability from the EAB database.
12021 */
12022 @Override
12023 public String getCapabilityFromEab(String contact) {
12024 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
12025 enforceModifyPermission();
12026 final long identity = Binder.clearCallingIdentity();
12027 try {
12028 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
12029 } finally {
12030 Binder.restoreCallingIdentity(identity);
12031 }
12032 }
12033
12034 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080012035 * Remove the EAB contacts from the EAB database.
12036 */
12037 @Override
12038 public int removeContactFromEab(int subId, String contacts) {
12039 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
12040 enforceModifyPermission();
12041 final long identity = Binder.clearCallingIdentity();
12042 try {
12043 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
12044 } finally {
12045 Binder.restoreCallingIdentity(identity);
12046 }
12047 }
12048
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012049 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080012050 public boolean getDeviceUceEnabled() {
12051 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
12052 final long identity = Binder.clearCallingIdentity();
12053 try {
12054 return mApp.getDeviceUceEnabled();
12055 } finally {
12056 Binder.restoreCallingIdentity(identity);
12057 }
12058 }
12059
12060 @Override
12061 public void setDeviceUceEnabled(boolean isEnabled) {
12062 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
12063 final long identity = Binder.clearCallingIdentity();
12064 try {
12065 mApp.setDeviceUceEnabled(isEnabled);
12066 } finally {
12067 Binder.restoreCallingIdentity(identity);
12068 }
12069 }
12070
Brad Ebinger14d467f2021-02-12 06:18:28 +000012071 /**
12072 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
12073 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12074 */
12075 // Used for SHELL command only right now.
12076 @Override
12077 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
12078 List<String> featureTags) {
12079 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12080 "addUceRegistrationOverrideShell");
12081 final long identity = Binder.clearCallingIdentity();
12082 try {
12083 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
12084 new ArraySet<>(featureTags));
12085 } catch (ImsException e) {
12086 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12087 } finally {
12088 Binder.restoreCallingIdentity(identity);
12089 }
12090 }
12091
12092 /**
12093 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
12094 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12095 */
12096 // Used for SHELL command only right now.
12097 @Override
12098 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
12099 List<String> featureTags) {
12100 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12101 "removeUceRegistrationOverrideShell");
12102 final long identity = Binder.clearCallingIdentity();
12103 try {
12104 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
12105 new ArraySet<>(featureTags));
12106 } catch (ImsException e) {
12107 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12108 } finally {
12109 Binder.restoreCallingIdentity(identity);
12110 }
12111 }
12112
12113 /**
12114 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
12115 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12116 */
12117 // Used for SHELL command only right now.
12118 @Override
12119 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
12120 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12121 "clearUceRegistrationOverrideShell");
12122 final long identity = Binder.clearCallingIdentity();
12123 try {
12124 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
12125 } catch (ImsException e) {
12126 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12127 } finally {
12128 Binder.restoreCallingIdentity(identity);
12129 }
12130 }
12131
12132 /**
12133 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12134 */
12135 // Used for SHELL command only right now.
12136 @Override
12137 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
12138 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12139 "getLatestRcsContactUceCapabilityShell");
12140 final long identity = Binder.clearCallingIdentity();
12141 try {
12142 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
12143 } catch (ImsException e) {
12144 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12145 } finally {
12146 Binder.restoreCallingIdentity(identity);
12147 }
12148 }
12149
12150 /**
12151 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
12152 * device does not have an active PUBLISH.
12153 */
12154 // Used for SHELL command only right now.
12155 @Override
12156 public String getLastUcePidfXmlShell(int subId) {
12157 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
12158 final long identity = Binder.clearCallingIdentity();
12159 try {
12160 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
12161 } catch (ImsException e) {
12162 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12163 } finally {
12164 Binder.restoreCallingIdentity(identity);
12165 }
12166 }
12167
James.cf Line8713a42021-04-29 16:04:26 +080012168 /**
12169 * Remove UCE requests cannot be sent to the network status.
12170 */
12171 // Used for SHELL command only right now.
12172 @Override
12173 public boolean removeUceRequestDisallowedStatus(int subId) {
12174 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
12175 final long identity = Binder.clearCallingIdentity();
12176 try {
12177 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
12178 } catch (ImsException e) {
12179 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12180 } finally {
12181 Binder.restoreCallingIdentity(identity);
12182 }
12183 }
12184
James.cf Lin18bb9002021-05-25 01:37:38 +080012185 /**
12186 * Remove UCE requests cannot be sent to the network status.
12187 */
12188 // Used for SHELL command only.
12189 @Override
12190 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
12191 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
12192 final long identity = Binder.clearCallingIdentity();
12193 try {
12194 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
12195 } catch (ImsException e) {
12196 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12197 } finally {
12198 Binder.restoreCallingIdentity(identity);
12199 }
12200 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000012201
James.cf Lin4b784aa2021-01-31 03:25:15 +080012202 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012203 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12204 String callingPackage) {
12205 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12206 mApp, subId, "setSignalStrengthUpdateRequest");
12207
joonhunshin4ac60942023-11-15 15:23:39 +000012208 enforceTelephonyFeatureWithException(callingPackage,
12209 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest");
12210
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012211 final int callingUid = Binder.getCallingUid();
12212 // Verify that tha callingPackage belongs to the calling UID
12213 mApp.getSystemService(AppOpsManager.class)
12214 .checkPackage(callingUid, callingPackage);
12215
Rambo Wang3607f502021-02-01 21:51:40 -080012216 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012217
12218 final long identity = Binder.clearCallingIdentity();
12219 try {
12220 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
12221 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12222
12223 if (result instanceof IllegalStateException) {
12224 throw (IllegalStateException) result;
12225 }
12226 } finally {
12227 Binder.restoreCallingIdentity(identity);
12228 }
12229 }
12230
12231 @Override
12232 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12233 String callingPackage) {
12234 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12235 mApp, subId, "clearSignalStrengthUpdateRequest");
12236
joonhunshin4ac60942023-11-15 15:23:39 +000012237 enforceTelephonyFeatureWithException(callingPackage,
12238 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest");
12239
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012240 final int callingUid = Binder.getCallingUid();
12241 // Verify that tha callingPackage belongs to the calling UID
12242 mApp.getSystemService(AppOpsManager.class)
12243 .checkPackage(callingUid, callingPackage);
12244
12245 final long identity = Binder.clearCallingIdentity();
12246 try {
12247 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
12248 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12249
12250 if (result instanceof IllegalStateException) {
12251 throw (IllegalStateException) result;
12252 }
12253 } finally {
12254 Binder.restoreCallingIdentity(identity);
12255 }
12256 }
12257
Rambo Wang3607f502021-02-01 21:51:40 -080012258 private static void validateSignalStrengthUpdateRequest(Context context,
12259 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012260 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
12261 // phone/system process do not have further restriction on request
12262 return;
12263 }
12264
12265 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080012266 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012267 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080012268 context.enforceCallingOrSelfPermission(
12269 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
12270 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012271 }
12272
12273 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000012274 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012275 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012276 || info.isEnabled()) {
12277 throw new IllegalArgumentException(
12278 "Only system can set hide fields in SignalThresholdInfo");
12279 }
12280
12281 // Thresholds length for each RAN need in range. This has been validated in
12282 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
12283 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
12284 final int[] thresholds = info.getThresholds();
12285 Objects.requireNonNull(thresholds);
12286 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
12287 || thresholds.length
12288 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
12289 throw new IllegalArgumentException(
12290 "thresholds length is out of range: " + thresholds.length);
12291 }
12292 }
12293 }
SongFerngWang8236caa2021-01-17 21:51:44 +080012294
12295 /**
12296 * Gets the current phone capability.
12297 *
12298 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
12299 * @return the PhoneCapability which describes the data connection capability of modem.
12300 * It's used to evaluate possible phone config change, for example from single
12301 * SIM device to multi-SIM device.
12302 */
12303 @Override
12304 public PhoneCapability getPhoneCapability() {
12305 enforceReadPrivilegedPermission("getPhoneCapability");
joonhunshin4ac60942023-11-15 15:23:39 +000012306
12307 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12308 PackageManager.FEATURE_TELEPHONY, "getPhoneCapability");
12309
SongFerngWang8236caa2021-01-17 21:51:44 +080012310 final long identity = Binder.clearCallingIdentity();
12311 try {
12312 return mPhoneConfigurationManager.getCurrentPhoneCapability();
12313 } finally {
12314 Binder.restoreCallingIdentity(identity);
12315 }
12316 }
Michele Berionne5e411512020-11-13 02:36:59 +000012317
12318 /**
12319 * Prepare TelephonyManager for an unattended reboot. The reboot is
12320 * required to be done shortly after the API is invoked.
12321 */
12322 @Override
12323 @TelephonyManager.PrepareUnattendedRebootResult
12324 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012325 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000012326 enforceRebootPermission();
12327
joonhunshin4ac60942023-11-15 15:23:39 +000012328 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12329 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot");
12330
Michele Berionne5e411512020-11-13 02:36:59 +000012331 final long identity = Binder.clearCallingIdentity();
12332 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012333 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000012334 } finally {
12335 Binder.restoreCallingIdentity(identity);
12336 }
12337 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012338
12339 /**
12340 * Request to get the current slicing configuration including URSP rules and
12341 * NSSAIs (configured, allowed and rejected).
12342 *
12343 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
12344 */
12345 @Override
12346 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000012347 TelephonyPermissions
12348 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
12349 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012350
joonhunshin4ac60942023-11-15 15:23:39 +000012351 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12352 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
12353 "getSlicingConfig");
12354
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012355 final long identity = Binder.clearCallingIdentity();
12356 try {
12357 Phone phone = getDefaultPhone();
12358 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
12359 } finally {
12360 Binder.restoreCallingIdentity(identity);
12361 }
12362 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012363
12364 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070012365 * Check whether the given premium capability is available for purchase from the carrier.
12366 *
12367 * @param capability The premium capability to check.
12368 * @param subId The subId to check the premium capability for.
12369 *
12370 * @return Whether the given premium capability is available to purchase.
12371 */
12372 @Override
12373 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
12374 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12375 mApp, "isPremiumCapabilityAvailableForPurchase")) {
12376 log("Premium capability "
12377 + TelephonyManager.convertPremiumCapabilityToString(capability)
12378 + " is not available for purchase due to missing permissions.");
12379 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
12380 + "permission READ_BASIC_PHONE_STATE.");
12381 }
12382
joonhunshin4ac60942023-11-15 15:23:39 +000012383 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12384 PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase");
12385
Sarah Chin2ec39f62022-08-31 17:03:26 -070012386 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080012387 if (phone == null) {
12388 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12389 return false;
12390 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012391 final long identity = Binder.clearCallingIdentity();
12392 try {
Sarah Chincc5446f2023-10-23 17:57:19 -070012393 return SlicePurchaseController.getInstance(phone, mFeatureFlags)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012394 .isPremiumCapabilityAvailableForPurchase(capability);
12395 } finally {
12396 Binder.restoreCallingIdentity(identity);
12397 }
12398 }
12399
12400 /**
12401 * Purchase the given premium capability from the carrier.
12402 *
12403 * @param capability The premium capability to purchase.
12404 * @param callback The result of the purchase request.
12405 * @param subId The subId to purchase the premium capability for.
12406 */
12407 @Override
12408 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12409 log("purchasePremiumCapability: capability="
12410 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12411 + getCurrentPackageName());
12412
12413 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12414 mApp, "purchasePremiumCapability")) {
12415 log("purchasePremiumCapability "
12416 + TelephonyManager.convertPremiumCapabilityToString(capability)
12417 + " failed due to missing permissions.");
12418 throw new SecurityException("purchasePremiumCapability requires permission "
12419 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012420 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12421 mApp, "purchasePremiumCapability")) {
12422 log("purchasePremiumCapability "
12423 + TelephonyManager.convertPremiumCapabilityToString(capability)
12424 + " failed due to missing permissions.");
12425 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012426 }
12427
joonhunshin4ac60942023-11-15 15:23:39 +000012428 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12429 PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability");
12430
Sarah Chin2ec39f62022-08-31 17:03:26 -070012431 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012432 if (phone == null) {
12433 try {
12434 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12435 callback.accept(result);
12436 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12437 } catch (RemoteException e) {
12438 String logStr = "Purchase premium capability "
12439 + TelephonyManager.convertPremiumCapabilityToString(capability)
12440 + " failed due to RemoteException handling null phone: " + e;
12441 if (DBG) log(logStr);
12442 AnomalyReporter.reportAnomaly(
12443 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12444 }
12445 return;
12446 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012447
12448 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012449 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012450 callingProcess = mApp.getPackageManager().getApplicationInfo(
12451 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070012452 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012453 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012454 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012455
12456 boolean isVisible = false;
12457 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12458 if (am != null) {
12459 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12460 if (processes != null) {
12461 for (ActivityManager.RunningAppProcessInfo process : processes) {
12462 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070012463 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080012464 if (process.processName.equals(callingProcess) && process.importance
12465 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12466 isVisible = true;
12467 break;
12468 }
12469 }
12470 }
12471 }
12472
12473 if (!isVisible) {
12474 try {
12475 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12476 callback.accept(result);
12477 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12478 } catch (RemoteException e) {
12479 String logStr = "Purchase premium capability "
12480 + TelephonyManager.convertPremiumCapabilityToString(capability)
12481 + " failed due to RemoteException handling background application: " + e;
12482 if (DBG) log(logStr);
12483 AnomalyReporter.reportAnomaly(
12484 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12485 }
12486 return;
12487 }
12488
Sarah Chin71b3a852022-09-28 15:54:19 -070012489 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012490 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012491 }
12492
12493 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012494 * Register an IMS connection state callback
12495 */
12496 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012497 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12498 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012499 if (feature == ImsFeature.FEATURE_MMTEL) {
12500 // ImsMmTelManager
12501 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12502 TelephonyPermissions
12503 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12504 mApp, subId, "registerImsStateCallback");
12505 } else if (feature == ImsFeature.FEATURE_RCS) {
12506 // ImsRcsManager or SipDelegateManager
12507 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12508 Binder.getCallingUid(), "registerImsStateCallback",
12509 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12510 Manifest.permission.READ_PRECISE_PHONE_STATE,
12511 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12512 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12513 }
12514
12515 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12516 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12517 "IMS not available on device.");
12518 }
12519
12520 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12521 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12522 }
12523
12524 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12525 if (controller == null) {
12526 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12527 "IMS not available on device.");
12528 }
12529
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012530 if (callingPackage == null) {
12531 callingPackage = getCurrentPackageName();
12532 }
12533
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012534 final long token = Binder.clearCallingIdentity();
12535 try {
12536 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012537 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012538 } catch (ImsException e) {
12539 throw new ServiceSpecificException(e.getCode());
12540 } finally {
12541 Binder.restoreCallingIdentity(token);
12542 }
12543 }
12544
12545 /**
12546 * Unregister an IMS connection state callback
12547 */
12548 @Override
12549 public void unregisterImsStateCallback(IImsStateCallback cb) {
12550 final long token = Binder.clearCallingIdentity();
12551 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12552 if (controller == null) {
12553 return;
12554 }
12555 try {
12556 controller.unregisterImsStateCallback(cb);
12557 } finally {
12558 Binder.restoreCallingIdentity(token);
12559 }
12560 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012561
12562 /**
12563 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12564 *
12565 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012566 * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012567 * SecurityException.
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012568 *
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012569 * If there is current registered network this value will be same as the registered cell
12570 * identity. If the device goes out of service the previous cell identity is cached and
12571 * will be returned. If the cache age of the Cell identity is more than 24 hours
12572 * it will be cleared and null will be returned.
12573 *
12574 */
12575 @Override
12576 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12577 String callingFeatureId) {
12578 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12579 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12580 LocationAccessPolicy.checkLocationPermission(mApp,
12581 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12582 .setCallingPackage(callingPackage)
12583 .setCallingFeatureId(callingFeatureId)
12584 .setCallingPid(Binder.getCallingPid())
12585 .setCallingUid(Binder.getCallingUid())
12586 .setMethod("getLastKnownCellIdentity")
12587 .setLogAsInfo(true)
12588 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12589 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12590 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12591 .build());
12592
12593 boolean hasFinePermission =
12594 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12595 if (!hasFinePermission
12596 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12597 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012598 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012599 }
12600
12601 final long identity = Binder.clearCallingIdentity();
12602 try {
Ling Mac28f0212023-03-24 16:07:15 -070012603 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012604 if (sst == null) return null;
12605 return sst.getLastKnownCellIdentity();
12606 } finally {
12607 Binder.restoreCallingIdentity(identity);
12608 }
12609 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012610
jimsun3b9ccac2021-10-26 15:01:23 +080012611 /**
12612 * Sets the modem service class Name that Telephony will bind to.
12613 *
12614 * @param serviceName The class name of the modem service.
12615 * @return true if the operation is succeed, otherwise false.
12616 */
12617 public boolean setModemService(String serviceName) {
12618 Log.d(LOG_TAG, "setModemService - " + serviceName);
12619 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12620 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012621 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12622 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012623 return mPhoneConfigurationManager.setModemService(serviceName);
12624 }
12625
12626 /**
12627 * Return the class name of the currently bounded modem service.
12628 *
12629 * @return the class name of the modem service.
12630 */
12631 public String getModemService() {
12632 String result;
12633 Log.d(LOG_TAG, "getModemService");
12634 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12635 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012636 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012637 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12638 "getModemService");
12639 result = mPhoneConfigurationManager.getModemService();
12640 Log.d(LOG_TAG, "result = " + result);
12641 return result;
12642 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012643
Hakjun Choi3ee81112023-12-19 15:40:58 +000012644 /**
12645 * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources,
12646 * including carrier config, entitlement server, and config update.
12647 *
12648 * @param subId subId The subscription ID of the carrier.
12649 *
12650 * @return List of plmns for carrier satellite service. If no plmn is available, empty list will
12651 * be returned.
12652 *
12653 * @throws SecurityException if the caller doesn't have the required permission.
12654 */
Hakjun Choi74c16be2024-01-19 08:18:09 +000012655 @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) {
12656 enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier");
Hakjun Choi3ee81112023-12-19 15:40:58 +000012657 final long identity = Binder.clearCallingIdentity();
12658 try {
Hakjun Choi74c16be2024-01-19 08:18:09 +000012659 return mSatelliteController.getSatellitePlmnsForCarrier(subId);
Hakjun Choi3ee81112023-12-19 15:40:58 +000012660 } finally {
12661 Binder.restoreCallingIdentity(identity);
12662 }
12663 }
12664
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012665 @Override
12666 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12667 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12668 mApp.enforceCallingOrSelfPermission(
12669 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12670 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12671
12672 final long identity = Binder.clearCallingIdentity();
12673 try {
12674 Phone phone = getPhone(subId);
12675 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012676 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12677 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012678 phone.setVoiceServiceStateOverride(hasService);
12679 } finally {
12680 Binder.restoreCallingIdentity(identity);
12681 }
12682 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012683
12684 /**
12685 * set removable eSIM as default eUICC.
12686 *
12687 * @hide
12688 */
12689 @Override
12690 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12691 enforceModifyPermission();
12692 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12693
12694 final long identity = Binder.clearCallingIdentity();
12695 try {
12696 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12697 } finally {
12698 Binder.restoreCallingIdentity(identity);
12699 }
12700 }
12701
12702 /**
12703 * Returns whether the removable eSIM is default eUICC or not.
12704 *
12705 * @hide
12706 */
12707 @Override
12708 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12709 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12710 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12711
12712 final long identity = Binder.clearCallingIdentity();
12713 try {
12714 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12715 } finally {
12716 Binder.restoreCallingIdentity(identity);
12717 }
12718 }
12719
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012720 /**
12721 * Get the component name of the default app to direct respond-via-message intent for the
12722 * user associated with this subscription, update the cache if there is no respond-via-message
12723 * application currently configured for this user.
12724 * @return component name of the app and class to direct Respond Via Message intent to, or
12725 * {@code null} if the functionality is not supported.
12726 * @hide
12727 */
12728 @Override
12729 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12730 boolean updateIfNeeded) {
12731 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012732
joonhunshin4ac60942023-11-15 15:23:39 +000012733 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12734 PackageManager.FEATURE_TELEPHONY_MESSAGING,
12735 "getDefaultRespondViaMessageApplication");
12736
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012737 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12738
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012739 UserHandle userHandle = null;
12740 final long identity = Binder.clearCallingIdentity();
12741 try {
12742 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12743 } finally {
12744 Binder.restoreCallingIdentity(identity);
12745 }
12746 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12747 updateIfNeeded, userHandle);
12748 }
Jack Yuf5badd92022-12-08 00:50:53 -080012749
12750 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012751 * Set whether the device is able to connect with null ciphering or integrity
12752 * algorithms. This is a global setting and will apply to all active subscriptions
12753 * and all new subscriptions after this.
12754 *
12755 * @param enabled when true, null cipher and integrity algorithms are allowed.
12756 * @hide
12757 */
12758 @Override
12759 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12760 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12761 enforceModifyPermission();
12762 checkForNullCipherAndIntegritySupport();
12763
12764 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12765 // for listening to these preference changes and applying them immediately.
12766 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12767 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12768 editor.apply();
12769
12770 for (Phone phone: PhoneFactory.getPhones()) {
12771 phone.handleNullCipherEnabledChange();
12772 }
12773 }
12774
12775
12776 /**
12777 * Get whether the device is able to connect with null ciphering or integrity
12778 * algorithms. Note that this retrieves the phone-global preference and not
12779 * the state of the radio.
12780 *
12781 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12782 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12783 * version for this feature.
12784 * @hide
12785 */
12786 @Override
12787 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12788 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12789 enforceReadPermission();
12790 checkForNullCipherAndIntegritySupport();
12791 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12792 }
12793
12794 private void checkForNullCipherAndIntegritySupport() {
12795 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12796 throw new UnsupportedOperationException(
12797 "Null cipher and integrity operations require HAL 2.1 or above");
12798 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012799 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12800 throw new UnsupportedOperationException(
12801 "Null cipher and integrity operations unsupported by modem");
12802 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012803 }
12804
Gil Cukierman06403e12023-11-29 16:33:03 +000012805 private void checkForIdentifierDisclosureNotificationSupport() {
12806 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) {
12807 throw new UnsupportedOperationException(
12808 "Cellular identifier disclosure transparency operations require HAL 2.2 or "
12809 + "above");
12810 }
12811 if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) {
12812 throw new UnsupportedOperationException(
12813 "Cellular identifier disclosure transparency operations unsupported by modem");
12814 }
12815 }
12816
Michael Groover826b71d2023-12-21 22:08:06 -060012817 private void checkForNullCipherNotificationSupport() {
12818 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) {
12819 throw new UnsupportedOperationException(
12820 "Null cipher notification operations require HAL 2.2 or above");
12821 }
12822 if (!getDefaultPhone().isNullCipherNotificationSupported()) {
12823 throw new UnsupportedOperationException(
12824 "Null cipher notification operations unsupported by modem");
12825 }
12826 }
12827
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012828 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012829 * Get the SIM state for the slot index.
12830 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12831 *
12832 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12833 */
12834 @Override
12835 @SimState
12836 public int getSimStateForSlotIndex(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +000012837 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12838 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex");
12839
Jack Yuf5badd92022-12-08 00:50:53 -080012840 IccCardConstants.State simState;
12841 if (slotIndex < 0) {
12842 simState = IccCardConstants.State.UNKNOWN;
12843 } else {
12844 Phone phone = null;
12845 try {
12846 phone = PhoneFactory.getPhone(slotIndex);
12847 } catch (IllegalStateException e) {
12848 // ignore
12849 }
12850 if (phone == null) {
12851 simState = IccCardConstants.State.UNKNOWN;
12852 } else {
12853 IccCard icc = phone.getIccCard();
12854 if (icc == null) {
12855 simState = IccCardConstants.State.UNKNOWN;
12856 } else {
12857 simState = icc.getState();
12858 }
12859 }
12860 }
12861 return simState.ordinal();
12862 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012863
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012864 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
12865 boolean enableLogcat,
12866 long logcatStartTimestampMillis, boolean enableTelecomDump,
12867 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012868 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012869 TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder =
12870 new TelephonyManager.EmergencyCallDiagnosticData.Builder();
12871 ecdDataBuilder
12872 .setTelecomDumpsysCollectionEnabled(enableTelecomDump)
12873 .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012874 if (enableLogcat) {
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012875 ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012876 }
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012877 TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build();
12878 Log.d(LOG_TAG, "persisting with Params " + ecdData.toString());
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012879 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
12880 Executors.newCachedThreadPool(), db,
12881 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012882 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012883 }
12884
12885 /**
12886 * Request telephony to persist state for debugging emergency call failures.
12887 *
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012888 * @param dropboxTag Tag to use when persisting data to dropbox service.
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012889 * @param enableLogcat whether to collect logcat output
12890 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
12891 * @param enableTelecomDump whether to collect telecom dumpsys
12892 * @param enableTelephonyDump whether to collect telephony dumpsys
12893 */
12894 @Override
12895 @RequiresPermission(android.Manifest.permission.DUMP)
12896 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
12897 long logcatStartTimestampMillis, boolean enableTelecomDump,
12898 boolean enableTelephonyDump) {
12899 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
12900 "persistEmergencyCallDiagnosticData");
12901 final long identity = Binder.clearCallingIdentity();
12902 try {
12903 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
12904 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
12905
12906 } finally {
12907 Binder.restoreCallingIdentity(identity);
12908 }
12909 }
12910
Hui Wang9b5793a2022-12-05 14:38:06 -060012911 /**
12912 * Get current cell broadcast ranges.
12913 */
12914 @Override
12915 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12916 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12917 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12918 "getCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012919
12920 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12921 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges");
12922
Hui Wang9b5793a2022-12-05 14:38:06 -060012923 final long identity = Binder.clearCallingIdentity();
12924 try {
12925 return getPhone(subId).getCellBroadcastIdRanges();
12926 } finally {
12927 Binder.restoreCallingIdentity(identity);
12928 }
12929 }
12930
12931 /**
12932 * Set reception of cell broadcast messages with the list of the given ranges
12933 *
12934 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12935 */
12936 @Override
12937 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12938 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12939 @Nullable IIntegerConsumer callback) {
12940 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12941 "setCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012942
12943 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12944 PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges");
12945
Hui Wang9b5793a2022-12-05 14:38:06 -060012946 final long identity = Binder.clearCallingIdentity();
12947 try {
12948 Phone phone = getPhoneFromSubId(subId);
12949 if (DBG) {
12950 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12951 }
12952 phone.setCellBroadcastIdRanges(ranges, result -> {
12953 if (callback != null) {
12954 try {
12955 callback.accept(result);
12956 } catch (RemoteException e) {
12957 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12958 }
12959 }
12960 });
12961 } finally {
12962 Binder.restoreCallingIdentity(identity);
12963 }
12964 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012965
12966 /**
12967 * Returns whether the device supports the domain selection service.
12968 *
12969 * @return {@code true} if the device supports the domain selection service.
12970 */
12971 @Override
12972 public boolean isDomainSelectionSupported() {
12973 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12974 "isDomainSelectionSupported");
12975
12976 final long identity = Binder.clearCallingIdentity();
12977 try {
12978 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12979 } finally {
12980 Binder.restoreCallingIdentity(identity);
12981 }
12982 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012983
12984 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012985 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
12986 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
12987 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080012988 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012989 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chinabf081b2023-03-09 23:00:57 -080012990 * @param enableSatellite {@code true} to enable the satellite modem and
12991 * {@code false} to disable.
12992 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
Thomas Nguyena8062672024-02-05 14:18:19 -080012993 * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise.
Sarah Chinabf081b2023-03-09 23:00:57 -080012994 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080012995 *
12996 * @throws SecurityException if the caller doesn't have the required permission.
12997 */
12998 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012999 public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode,
Thomas Nguyena8062672024-02-05 14:18:19 -080013000 boolean isEmergency, @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013001 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013002 if (enableSatellite) {
13003 ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) {
13004 @Override
13005 protected void onReceiveResult(int resultCode, Bundle resultData) {
13006 Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode
13007 + ", resultData=" + resultData);
13008 boolean isAllowed = false;
13009 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(
13010 callback::accept);
13011 if (resultCode == SATELLITE_RESULT_SUCCESS) {
13012 if (resultData != null
13013 && resultData.containsKey(KEY_SATELLITE_COMMUNICATION_ALLOWED)) {
13014 isAllowed = resultData.getBoolean(KEY_SATELLITE_COMMUNICATION_ALLOWED);
13015 } else {
13016 loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist.");
13017 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013018 } else {
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013019 result.accept(resultCode);
13020 return;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013021 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013022 if (isAllowed) {
13023 mSatelliteController.requestSatelliteEnabled(
Hyosun Kimab304792024-03-29 09:18:03 +000013024 subId, enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013025 } else {
13026 result.accept(SATELLITE_RESULT_ACCESS_BARRED);
13027 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013028 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013029 };
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013030 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013031 subId, resultReceiver);
13032 } else {
13033 // No need to check if satellite is allowed at current location when disabling satellite
13034 mSatelliteController.requestSatelliteEnabled(
Hyosun Kimab304792024-03-29 09:18:03 +000013035 subId, enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013036 }
Sarah Chin503828c2023-02-01 23:54:20 -080013037 }
13038
13039 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013040 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080013041 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013042 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013043 * @param result The result receiver that returns whether the satellite modem is enabled
13044 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013045 *
13046 * @throws SecurityException if the caller doesn't have the required permission.
13047 */
13048 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013049 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
13050 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013051 mSatelliteController.requestIsSatelliteEnabled(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013052 }
13053
13054 /**
Sarah Chin43457982023-02-15 17:50:38 -080013055 * Request to get whether the satellite service demo mode is enabled.
13056 *
13057 * @param subId The subId of the subscription to check whether the satellite demo mode
13058 * is enabled for.
13059 * @param result The result receiver that returns whether the satellite demo mode is enabled
13060 * if the request is successful or an error code if the request failed.
13061 *
13062 * @throws SecurityException if the caller doesn't have the required permission.
13063 */
13064 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013065 public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
13066 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
13067 mSatelliteController.requestIsDemoModeEnabled(subId, result);
Sarah Chin43457982023-02-15 17:50:38 -080013068 }
13069
13070 /**
Thomas Nguyena8062672024-02-05 14:18:19 -080013071 * Request to get whether the satellite service is enabled with emergency mode.
13072 *
13073 * @param subId The subId of the subscription to check whether the satellite demo mode
13074 * is enabled for.
13075 * @param result The result receiver that returns whether the satellite emergency mode is
13076 * enabled if the request is successful or an error code if the request failed.
13077 *
13078 * @throws SecurityException if the caller doesn't have the required permission.
13079 */
13080 @Override
13081 public void requestIsEmergencyModeEnabled(int subId, @NonNull ResultReceiver result) {
13082 enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled");
13083 result.send(SATELLITE_RESULT_REQUEST_NOT_SUPPORTED, null);
13084 }
13085
13086 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013087 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080013088 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013089 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013090 * @param result The result receiver that returns whether the satellite service is supported on
13091 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013092 */
13093 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013094 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013095 mSatelliteController.requestIsSatelliteSupported(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013096 }
13097
13098 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013099 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080013100 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013101 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013102 * @param result The result receiver that returns the {@link SatelliteCapabilities}
13103 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013104 *
13105 * @throws SecurityException if the caller doesn't have required permission.
13106 */
13107 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013108 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
13109 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013110 mSatelliteController.requestSatelliteCapabilities(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013111 }
13112
13113 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013114 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013115 * This can be called by the pointing UI when the user starts pointing to the satellite.
13116 * Modem should continue to report the pointing input as the device or satellite moves.
13117 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013118 * @param subId The subId of the subscription to start satellite transmission updates for.
13119 * @param resultCallback The callback to get the result of the request.
13120 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080013121 *
13122 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013123 */
13124 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013125 public void startSatelliteTransmissionUpdates(int subId,
13126 @NonNull IIntegerConsumer resultCallback,
13127 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13128 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
13129 mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080013130 }
13131
13132 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013133 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013134 * This can be called by the pointing UI when the user stops pointing to the satellite.
13135 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013136 * @param subId The subId of the subscription to stop satellite transmission updates for.
13137 * @param resultCallback The callback to get the result of the request.
13138 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
13139 * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080013140 *
13141 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013142 */
13143 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013144 public void stopSatelliteTransmissionUpdates(int subId,
13145 @NonNull IIntegerConsumer resultCallback,
13146 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13147 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
13148 mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013149 }
13150
13151 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013152 * Register the subscription with a satellite provider.
13153 * This is needed to register the subscription if the provider allows dynamic registration.
13154 *
13155 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013156 * @param token The token to be used as a unique identifier for provisioning with satellite
13157 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013158 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080013159 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013160 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013161 * @return The signal transport used by the caller to cancel the provision request,
13162 * or {@code null} if the request failed.
13163 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013164 * @throws SecurityException if the caller doesn't have the required permission.
13165 */
13166 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013167 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013168 @NonNull String token, @NonNull byte[] provisionData,
13169 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013170 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013171 return mSatelliteController.provisionSatelliteService(subId, token, provisionData,
13172 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013173 }
13174
13175 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013176 * Unregister the device/subscription with the satellite provider.
13177 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013178 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013179 * should report as deprovisioned.
13180 *
13181 * @param subId The subId of the subscription to be deprovisioned.
13182 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080013183 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013184 *
13185 * @throws SecurityException if the caller doesn't have the required permission.
13186 */
13187 @Override
13188 public void deprovisionSatelliteService(int subId,
13189 @NonNull String token, @NonNull IIntegerConsumer callback) {
13190 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013191 mSatelliteController.deprovisionSatelliteService(subId, token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013192 }
13193
13194 /**
Sarah Chin43457982023-02-15 17:50:38 -080013195 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013196 *
Sarah Chin43457982023-02-15 17:50:38 -080013197 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013198 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013199 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013200 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013201 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013202 * @throws SecurityException if the caller doesn't have the required permission.
13203 */
13204 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013205 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
13206 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013207 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013208 return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013209 }
13210
13211 /**
Sarah Chin43457982023-02-15 17:50:38 -080013212 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013213 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013214 *
Sarah Chin43457982023-02-15 17:50:38 -080013215 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013216 * @param callback The callback that was passed to
13217 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013218 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013219 * @throws SecurityException if the caller doesn't have the required permission.
13220 */
13221 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013222 public void unregisterForSatelliteProvisionStateChanged(
13223 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013224 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013225 mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013226 }
13227
13228 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013229 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013230 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013231 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013232 * @param result The result receiver that returns whether the device is provisioned with a
13233 * satellite provider if the request is successful or an error code if the
13234 * request failed.
13235 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013236 * @throws SecurityException if the caller doesn't have the required permission.
13237 */
13238 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013239 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
13240 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013241 mSatelliteController.requestIsSatelliteProvisioned(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013242 }
13243
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013244 /**
Sarah Chin43457982023-02-15 17:50:38 -080013245 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013246 *
Sarah Chin43457982023-02-15 17:50:38 -080013247 * @param subId The subId of the subscription to register for satellite modem state changed.
13248 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080013249 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013250 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013251 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013252 * @throws SecurityException if the caller doesn't have the required permission.
13253 */
13254 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013255 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013256 @NonNull ISatelliteModemStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080013257 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013258 return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013259 }
13260
13261 /**
Sarah Chin43457982023-02-15 17:50:38 -080013262 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013263 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013264 *
Sarah Chin43457982023-02-15 17:50:38 -080013265 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080013266 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013267 * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013268 *
13269 * @throws SecurityException if the caller doesn't have the required permission.
13270 */
13271 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013272 public void unregisterForModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013273 @NonNull ISatelliteModemStateCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013274 enforceSatelliteCommunicationPermission("unregisterForModemStateChanged");
13275 mSatelliteController.unregisterForModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013276 }
13277
13278 /**
13279 * Register to receive incoming datagrams over satellite.
13280 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013281 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Sarah Chindf715ec2023-02-13 13:46:24 -080013282 * @param callback The callback to handle incoming datagrams over satellite.
13283 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013284 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013285 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013286 * @throws SecurityException if the caller doesn't have the required permission.
13287 */
13288 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013289 @SatelliteManager.SatelliteResult public int registerForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013290 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013291 enforceSatelliteCommunicationPermission("registerForIncomingDatagram");
13292 return mSatelliteController.registerForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013293 }
13294
13295 /**
13296 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013297 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013298 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013299 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
13300 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013301 * {@link #registerForIncomingDatagram(int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013302 *
13303 * @throws SecurityException if the caller doesn't have the required permission.
13304 */
13305 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013306 public void unregisterForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013307 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013308 enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram");
13309 mSatelliteController.unregisterForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013310 }
13311
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013312 /**
13313 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013314 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013315 * This method requests modem to check if there are any pending datagrams to be received over
13316 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000013317 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080013318 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013319 * @param subId The subId of the subscription used for receiving datagrams.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013320 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013321 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013322 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013323 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013324 public void pollPendingDatagrams(int subId, IIntegerConsumer callback) {
13325 enforceSatelliteCommunicationPermission("pollPendingDatagrams");
13326 mSatelliteController.pollPendingDatagrams(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013327 }
13328
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013329 /**
13330 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013331 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013332 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
13333 * input to this method. Datagram received here will be passed down to modem without any
13334 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080013335 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013336 * @param subId The subId of the subscription to send satellite datagrams for.
13337 * @param datagramType datagram type indicating whether the datagram is of type
13338 * SOS_SMS or LOCATION_SHARING.
13339 * @param datagram encoded gateway datagram which is encrypted by the caller.
13340 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000013341 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
13342 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013343 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013344 *
13345 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013346 */
13347 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013348 public void sendDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000013349 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
13350 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013351 enforceSatelliteCommunicationPermission("sendDatagram");
13352 mSatelliteController.sendDatagram(subId, datagramType, datagram, needFullScreenPointingUI,
13353 callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013354 }
13355
Sarah Chindf715ec2023-02-13 13:46:24 -080013356 /**
13357 * Request to get whether satellite communication is allowed for the current location.
13358 *
13359 * @param subId The subId of the subscription to check whether satellite communication is
13360 * allowed for the current location for.
13361 * @param result The result receiver that returns whether satellite communication is allowed
13362 * for the current location if the request is successful or an error code
13363 * if the request failed.
13364 *
13365 * @throws SecurityException if the caller doesn't have the required permission.
13366 */
13367 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013368 public void requestIsCommunicationAllowedForCurrentLocation(int subId,
Sarah Chindf715ec2023-02-13 13:46:24 -080013369 @NonNull ResultReceiver result) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013370 enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation");
13371 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(subId,
13372 result);
Sarah Chindf715ec2023-02-13 13:46:24 -080013373 }
13374
13375 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013376 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080013377 *
Sarah Chin5f57c582023-02-14 04:16:10 -080013378 * @param subId The subId to get the time after which the satellite will be visible for.
13379 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080013380 * be visible if the request is successful or an error code if the request failed.
13381 *
13382 * @throws SecurityException if the caller doesn't have the required permission.
13383 */
13384 @Override
13385 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
13386 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013387 mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013388 }
13389
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013390 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013391 * Inform that Device is aligned to satellite for demo mode.
13392 *
13393 * @param subId The subId to get the time after which the satellite will be visible for.
13394 * @param isAligned {@code true} Device is aligned with the satellite for demo mode
13395 * {@code false} Device fails to align with the satellite for demo mode.
13396 *
13397 * @throws SecurityException if the caller doesn't have required permission.
13398 */
13399 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
13400
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013401 public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) {
Hakjun Choiae365972023-04-25 11:00:31 +000013402 enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite");
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013403 mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned);
Hakjun Choiae365972023-04-25 11:00:31 +000013404 }
13405
13406 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000013407 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
13408 * by modem.
13409 *
13410 * @param subId The subId of the subscription to request for.
13411 * @param reason Reason for disallowing satellite communication for carrier.
Hakjun Choif92ac752024-03-18 19:34:29 +000013412 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013413 * operation.
13414 *
13415 * @throws SecurityException if the caller doesn't have required permission.
13416 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013417 public void addAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013418 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13419 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013420 enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013421 final long identity = Binder.clearCallingIdentity();
13422 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013423 mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013424 } finally {
13425 Binder.restoreCallingIdentity(identity);
13426 }
13427 }
13428
13429 /**
13430 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
13431 * by modem.
13432 *
13433 * @param subId The subId of the subscription to request for.
13434 * @param reason Reason for disallowing satellite communication.
Hakjun Choif92ac752024-03-18 19:34:29 +000013435 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013436 * operation.
13437 *
13438 * @throws SecurityException if the caller doesn't have required permission.
13439 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013440 public void removeAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013441 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13442 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013443 enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013444 final long identity = Binder.clearCallingIdentity();
13445 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013446 mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013447 } finally {
13448 Binder.restoreCallingIdentity(identity);
13449 }
13450 }
13451
13452 /**
13453 * Get reasons for disallowing satellite communication, as requested by
Hakjun Choif92ac752024-03-18 19:34:29 +000013454 * {@link #addAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
Hakjun Choicb39db92023-07-14 15:51:12 +000013455 *
13456 * @param subId The subId of the subscription to request for.
13457 *
13458 * @return Integer array of reasons for disallowing satellite communication.
13459 *
13460 * @throws SecurityException if the caller doesn't have the required permission.
13461 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013462 public @NonNull int[] getAttachRestrictionReasonsForCarrier(
Hakjun Choicb39db92023-07-14 15:51:12 +000013463 int subId) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013464 enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013465 final long identity = Binder.clearCallingIdentity();
13466 try {
13467 Set<Integer> reasonSet =
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013468 mSatelliteController.getAttachRestrictionReasonsForCarrier(subId);
Hakjun Choicb39db92023-07-14 15:51:12 +000013469 return reasonSet.stream().mapToInt(i->i).toArray();
13470 } finally {
13471 Binder.restoreCallingIdentity(identity);
13472 }
13473 }
13474
13475 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000013476 * Request to get the signal strength of the satellite connection.
13477 *
13478 * @param subId The subId of the subscription to request for.
13479 * @param result Result receiver to get the error code of the request and the current signal
13480 * strength of the satellite connection.
13481 *
13482 * @throws SecurityException if the caller doesn't have required permission.
13483 */
13484 @Override
13485 public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) {
13486 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
13487 final long identity = Binder.clearCallingIdentity();
13488 try {
13489 mSatelliteController.requestNtnSignalStrength(subId, result);
13490 } finally {
13491 Binder.restoreCallingIdentity(identity);
13492 }
13493 }
13494
13495 /**
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013496 * Registers for NTN signal strength changed from satellite modem. If the registration operation
13497 * is not successful, a {@link ServiceSpecificException} that contains
13498 * {@link SatelliteManager.SatelliteResult} will be thrown.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013499 *
13500 * @param subId The subId of the subscription to request for.
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013501 * @param callback The callback to handle the NTN signal strength changed event. If the
13502 * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged(
13503 * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of
13504 * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial
13505 * network has changed.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013506 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013507 * @throws SecurityException If the caller doesn't have the required permission.
13508 * @throws ServiceSpecificException If the callback registration operation fails.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013509 */
13510 @Override
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013511 public void registerForNtnSignalStrengthChanged(int subId,
13512 @NonNull INtnSignalStrengthCallback callback) throws RemoteException {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013513 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
13514 final long identity = Binder.clearCallingIdentity();
13515 try {
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013516 mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013517 } finally {
13518 Binder.restoreCallingIdentity(identity);
13519 }
13520 }
13521
13522 /**
13523 * Unregisters for NTN signal strength changed from satellite modem.
13524 * If callback was not registered before, the request will be ignored.
13525 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013526 * @param subId The subId of the subscription to unregister for listening NTN signal strength
13527 * changed event.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013528 * @param callback The callback that was passed to
13529 * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)}
13530 *
13531 * @throws SecurityException if the caller doesn't have the required permission.
13532 */
13533 @Override
13534 public void unregisterForNtnSignalStrengthChanged(
13535 int subId, @NonNull INtnSignalStrengthCallback callback) {
13536 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
13537 final long identity = Binder.clearCallingIdentity();
13538 try {
13539 mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback);
13540 } finally {
13541 Binder.restoreCallingIdentity(identity);
13542 }
13543 }
13544
13545 /**
Hakjun Choi8d96a562023-10-26 15:01:40 +000013546 * Registers for satellite capabilities change event from the satellite service.
13547 *
13548 * @param subId The subId of the subscription to request for.
13549 * @param callback The callback to handle the satellite capabilities changed event.
13550 *
13551 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13552 *
13553 * @throws SecurityException if the caller doesn't have required permission.
13554 */
13555 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013556 @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged(
Hakjun Choi8d96a562023-10-26 15:01:40 +000013557 int subId, @NonNull ISatelliteCapabilitiesCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013558 enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013559 final long identity = Binder.clearCallingIdentity();
13560 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013561 return mSatelliteController.registerForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013562 } finally {
13563 Binder.restoreCallingIdentity(identity);
13564 }
13565 }
13566
13567 /**
13568 * Unregisters for satellite capabilities change event from the satellite service.
13569 * If callback was not registered before, the request will be ignored.
13570 *
13571 * @param subId The subId of the subscription to unregister for satellite capabilities change.
13572 * @param callback The callback that was passed to.
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013573 * {@link #registerForCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}.
Hakjun Choi8d96a562023-10-26 15:01:40 +000013574 *
13575 * @throws SecurityException if the caller doesn't have required permission.
13576 */
13577 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013578 public void unregisterForCapabilitiesChanged(int subId,
13579 @NonNull ISatelliteCapabilitiesCallback callback) {
13580 enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013581 final long identity = Binder.clearCallingIdentity();
13582 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013583 mSatelliteController.unregisterForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013584 } finally {
13585 Binder.restoreCallingIdentity(identity);
13586 }
13587 }
13588
13589 /**
Hakjun Choif92ac752024-03-18 19:34:29 +000013590 * Registers for the satellite supported state changed.
13591 *
13592 * @param subId The subId of the subscription to register for supported state changed.
13593 * @param callback The callback to handle the satellite supported state changed event.
13594 *
13595 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13596 *
13597 * @throws SecurityException if the caller doesn't have the required permission.
13598 */
13599 @Override
13600 @SatelliteManager.SatelliteResult public int registerForSatelliteSupportedStateChanged(
13601 int subId, @NonNull ISatelliteSupportedStateCallback callback) {
13602 enforceSatelliteCommunicationPermission("registerForSatelliteSupportedStateChanged");
13603 return mSatelliteController.registerForSatelliteSupportedStateChanged(subId, callback);
13604 }
13605
13606 /**
13607 * Unregisters for the satellite supported state changed.
13608 * If callback was not registered before, the request will be ignored.
13609 *
13610 * @param subId The subId of the subscription to unregister for supported state changed.
13611 * @param callback The callback that was passed to
13612 * {@link #registerForSatelliteSupportedStateChanged(int, ISatelliteSupportedStateCallback)}.
13613 *
13614 * @throws SecurityException if the caller doesn't have the required permission.
13615 */
13616 @Override
13617 public void unregisterForSatelliteSupportedStateChanged(
13618 int subId, @NonNull ISatelliteSupportedStateCallback callback) {
13619 enforceSatelliteCommunicationPermission("unregisterForSatelliteSupportedStateChanged");
13620 mSatelliteController.unregisterForSatelliteSupportedStateChanged(subId, callback);
13621 }
13622
13623 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013624 * This API can be used by only CTS to update satellite vendor service package name.
13625 *
13626 * @param servicePackageName The package name of the satellite vendor service.
13627 * @return {@code true} if the satellite vendor service is set successfully,
13628 * {@code false} otherwise.
13629 */
13630 public boolean setSatelliteServicePackageName(String servicePackageName) {
13631 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName);
13632 TelephonyPermissions.enforceShellOnly(
13633 Binder.getCallingUid(), "setSatelliteServicePackageName");
13634 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13635 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13636 "setSatelliteServicePackageName");
13637 return mSatelliteController.setSatelliteServicePackageName(servicePackageName);
13638 }
13639
13640 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070013641 * This API can be used by only CTS to update satellite gateway service package name.
13642 *
13643 * @param servicePackageName The package name of the satellite gateway service.
13644 * @return {@code true} if the satellite gateway service is set successfully,
13645 * {@code false} otherwise.
13646 */
13647 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
13648 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
13649 TelephonyPermissions.enforceShellOnly(
13650 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
13651 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13652 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13653 "setSatelliteGatewayServicePackageName");
13654 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
13655 }
13656
13657 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070013658 * This API can be used by only CTS to update satellite pointing UI app package and class names.
13659 *
13660 * @param packageName The package name of the satellite pointing UI app.
13661 * @param className The class name of the satellite pointing UI app.
13662 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
13663 * {@code false} otherwise.
13664 */
13665 public boolean setSatellitePointingUiClassName(
13666 @Nullable String packageName, @Nullable String className) {
13667 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
13668 + ", className=" + className);
13669 TelephonyPermissions.enforceShellOnly(
13670 Binder.getCallingUid(), "setSatellitePointingUiClassName");
13671 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13672 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13673 "setSatelliteGatewayServicePackageName");
13674 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
13675 }
13676
13677 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070013678 * This API can be used by only CTS to update the timeout duration in milliseconds that
13679 * satellite should stay at listening mode to wait for the next incoming page before disabling
13680 * listening mode.
13681 *
13682 * @param timeoutMillis The timeout duration in millisecond.
13683 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13684 */
13685 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
13686 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
13687 TelephonyPermissions.enforceShellOnly(
13688 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
13689 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13690 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13691 "setSatelliteListeningTimeoutDuration");
13692 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
13693 }
13694
13695 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013696 * This API can be used by only CTS to override the timeout durations used by the
13697 * DatagramController module.
Hakjun Choiae365972023-04-25 11:00:31 +000013698 *
13699 * @param timeoutMillis The timeout duration in millisecond.
13700 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13701 */
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013702 public boolean setDatagramControllerTimeoutDuration(
13703 boolean reset, int timeoutType, long timeoutMillis) {
13704 Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset="
13705 + reset + ", timeoutMillis=" + timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013706 TelephonyPermissions.enforceShellOnly(
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013707 Binder.getCallingUid(), "setDatagramControllerTimeoutDuration");
Hakjun Choiae365972023-04-25 11:00:31 +000013708 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13709 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013710 "setDatagramControllerTimeoutDuration");
13711 return mSatelliteController.setDatagramControllerTimeoutDuration(
13712 reset, timeoutType, timeoutMillis);
13713 }
13714
13715 /**
13716 * This API can be used by only CTS to override the timeout durations used by the
13717 * SatelliteController module.
13718 *
13719 * @param timeoutMillis The timeout duration in millisecond.
13720 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13721 */
13722 public boolean setSatelliteControllerTimeoutDuration(
13723 boolean reset, int timeoutType, long timeoutMillis) {
13724 Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset="
13725 + reset + ", timeoutMillis=" + timeoutMillis);
13726 TelephonyPermissions.enforceShellOnly(
13727 Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration");
13728 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13729 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13730 "setSatelliteControllerTimeoutDuration");
13731 return mSatelliteController.setSatelliteControllerTimeoutDuration(
13732 reset, timeoutType, timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013733 }
13734
13735 /**
Thomas Nguyen11a051f2023-10-25 10:14:55 -070013736 * This API can be used in only testing to override connectivity status in monitoring emergency
13737 * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.
13738 *
13739 * @param handoverType The type of handover from emergency call to satellite messaging. Use one
13740 * of the following values to enable the override:
13741 * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS
13742 * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911
13743 * To disable the override, use -1 for handoverType.
13744 * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer
13745 * delaySeconds after the emergency call starts.
13746 * @return {@code true} if the handover type is set successfully, {@code false} otherwise.
13747 */
13748 public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) {
13749 Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType);
13750 TelephonyPermissions.enforceShellOnly(
13751 Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType");
13752 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13753 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13754 "setEmergencyCallToSatelliteHandoverType");
13755 return mSatelliteController.setEmergencyCallToSatelliteHandoverType(
13756 handoverType, delaySeconds);
13757 }
13758
13759 /**
Thomas Nguyen3d602742024-01-19 11:29:35 -080013760 * This API can be used in only testing to override oem-enabled satellite provision status.
13761 *
13762 * @param reset {@code true} mean the overriding status should not be used, {@code false}
13763 * otherwise.
13764 * @param isProvisioned The overriding provision status.
13765 * @return {@code true} if the provision status is set successfully, {@code false} otherwise.
13766 */
13767 public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) {
13768 Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset
13769 + ", isProvisioned=" + isProvisioned);
13770 TelephonyPermissions.enforceShellOnly(
13771 Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus");
13772 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13773 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13774 "setOemEnabledSatelliteProvisionStatus");
13775 return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned);
13776 }
13777
13778 /**
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013779 * This API should be used by only CTS tests to forcefully set telephony country codes.
13780 *
13781 * @return {@code true} if the country code is set successfully, {@code false} otherwise.
13782 */
13783 public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes,
13784 Map cachedNetworkCountryCodes, String locationCountryCode,
13785 long locationCountryCodeTimestampNanos) {
13786 Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes="
13787 + String.join(", ", currentNetworkCountryCodes)
13788 + ", locationCountryCode=" + locationCountryCode
13789 + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos
13790 + ", reset=" + reset + ", cachedNetworkCountryCodes="
13791 + String.join(", ", cachedNetworkCountryCodes.keySet()));
13792 TelephonyPermissions.enforceShellOnly(
13793 Binder.getCallingUid(), "setCachedLocationCountryCode");
13794 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13795 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13796 "setCachedLocationCountryCode");
13797 return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext()).setCountryCodes(
13798 reset, currentNetworkCountryCodes, cachedNetworkCountryCodes, locationCountryCode,
13799 locationCountryCodeTimestampNanos);
13800 }
13801
13802 /**
13803 * This API should be used by only CTS tests to override the overlay configs of satellite
13804 * access controller.
13805 *
13806 * @param reset {@code true} mean the overridden configs should not be used, {@code false}
13807 * otherwise.
13808 * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise.
13809 */
13810 public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed,
13811 String s2CellFile, long locationFreshDurationNanos,
13812 List<String> satelliteCountryCodes) {
13813 Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset
13814 + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile
13815 + ", locationFreshDurationNanos=" + locationFreshDurationNanos
13816 + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null)
13817 ? String.join(", ", satelliteCountryCodes) : null));
13818 TelephonyPermissions.enforceShellOnly(
13819 Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs");
13820 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13821 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13822 "setSatelliteAccessControlOverlayConfigs");
13823 return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset, isAllowed,
13824 s2CellFile, locationFreshDurationNanos, satelliteCountryCodes);
13825 }
13826
13827 /**
Hakjun Choibc6ce992023-11-07 16:04:33 +000013828 * This API can be used by only CTS to override the cached value for the device overlay config
13829 * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether
13830 * outgoing satellite datagrams should be sent to modem in demo mode.
13831 *
13832 * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to
13833 * satellite modem or not.
13834 *
13835 * @return {@code true} if the operation is successful, {@code false} otherwise.
13836 */
13837 public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) {
13838 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
13839 Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is "
13840 + "disabled");
13841 return false;
13842 }
13843 Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode");
13844 TelephonyPermissions.enforceShellOnly(
13845 Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode");
13846 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13847 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13848 "setShouldSendDatagramToModemInDemoMode");
13849 return mSatelliteController.setShouldSendDatagramToModemInDemoMode(
13850 shouldSendToModemInDemoMode);
13851 }
13852
13853 /**
Hunsuk Choi13078be2023-09-13 10:55:21 +000013854 * Sets the service defined in ComponentName to be bound.
13855 *
13856 * This should only be used for testing.
13857 * @return {@code true} if the DomainSelectionService to bind to was set,
13858 * {@code false} otherwise.
13859 */
13860 @Override
13861 public boolean setDomainSelectionServiceOverride(ComponentName componentName) {
13862 Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName);
13863
13864 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
13865 "setDomainSelectionServiceOverride");
13866 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13867 getDefaultSubscription(), "setDomainSelectionServiceOverride");
13868
13869 final long identity = Binder.clearCallingIdentity();
13870 try {
13871 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13872 return DomainSelectionResolver.getInstance()
13873 .setDomainSelectionServiceOverride(componentName);
13874 }
13875 } finally {
13876 Binder.restoreCallingIdentity(identity);
13877 }
13878 return false;
13879 }
13880
13881 /**
13882 * Clears the DomainSelectionService override.
13883 *
13884 * This should only be used for testing.
13885 * @return {@code true} if the DomainSelectionService override was cleared,
13886 * {@code false} otherwise.
13887 */
13888 @Override
13889 public boolean clearDomainSelectionServiceOverride() {
13890 Log.i(LOG_TAG, "clearDomainSelectionServiceOverride");
13891
13892 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
13893 "clearDomainSelectionServiceOverride");
13894 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13895 getDefaultSubscription(), "clearDomainSelectionServiceOverride");
13896
13897 final long identity = Binder.clearCallingIdentity();
13898 try {
13899 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13900 return DomainSelectionResolver.getInstance()
13901 .clearDomainSelectionServiceOverride();
13902 }
13903 } finally {
13904 Binder.restoreCallingIdentity(identity);
13905 }
13906 return false;
13907 }
13908
13909 /**
Gil Cukierman06403e12023-11-29 16:33:03 +000013910 * Enable or disable notifications sent for cellular identifier disclosure events.
13911 *
13912 * Disclosure events are defined as instances where a device has sent a cellular identifier
13913 * on the Non-access stratum (NAS) before a security context is established. As a result the
13914 * identifier is sent in the clear, which has privacy implications for the user.
13915 *
13916 * @param enable if notifications about disclosure events should be enabled
13917 * @throws SecurityException if the caller does not have the required privileges
13918 * @throws UnsupportedOperationException if the modem does not support this feature.
13919 */
13920 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000013921 public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) {
Gil Cukierman06403e12023-11-29 16:33:03 +000013922 enforceModifyPermission();
13923 checkForIdentifierDisclosureNotificationSupport();
13924
13925 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
13926 editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable);
13927 editor.apply();
13928
13929 // Each phone instance is responsible for updating its respective modem immediately
13930 // after we've made a preference change.
13931 for (Phone phone : PhoneFactory.getPhones()) {
13932 phone.handleIdentifierDisclosureNotificationPreferenceChange();
13933 }
13934 }
13935
13936 /**
13937 * Get whether or not cellular identifier disclosure notifications are enabled.
13938 *
13939 * @throws SecurityException if the caller does not have the required privileges
13940 * @throws UnsupportedOperationException if the modem does not support this feature.
13941 */
13942 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000013943 public boolean isCellularIdentifierDisclosureNotificationsEnabled() {
Gil Cukierman06403e12023-11-29 16:33:03 +000013944 enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled");
13945 checkForIdentifierDisclosureNotificationSupport();
13946 return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled();
13947 }
13948
13949 /**
Michael Groover826b71d2023-12-21 22:08:06 -060013950 * Enables or disables notifications sent when cellular null cipher or integrity algorithms
13951 * are in use by the cellular modem.
13952 *
13953 * @throws IllegalStateException if the Telephony process is not currently available
13954 * @throws SecurityException if the caller does not have the required privileges
13955 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
13956 * and integrity algorithms in use
13957 * @hide
13958 */
13959 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Michael Grooverae447b22024-01-24 22:35:46 -060013960 public void setNullCipherNotificationsEnabled(boolean enable) {
Michael Groover826b71d2023-12-21 22:08:06 -060013961 enforceModifyPermission();
13962 checkForNullCipherNotificationSupport();
13963
13964 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
13965 editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable);
13966 editor.apply();
13967
13968 // Each phone instance is responsible for updating its respective modem immediately
13969 // after a preference change.
13970 for (Phone phone : PhoneFactory.getPhones()) {
13971 phone.handleNullCipherNotificationPreferenceChanged();
13972 }
13973 }
13974
13975 /**
13976 * Get whether notifications are enabled for null cipher or integrity algorithms in use by the
13977 * cellular modem.
13978 *
13979 * @throws IllegalStateException if the Telephony process is not currently available
13980 * @throws SecurityException if the caller does not have the required privileges
13981 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
13982 * and integrity algorithms in use
13983 * @hide
13984 */
13985 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
13986 public boolean isNullCipherNotificationsEnabled() {
13987 enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled");
13988 checkForNullCipherNotificationSupport();
13989 return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled();
13990 }
13991
13992 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000013993 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
13994 *
13995 * <p>This method behaves in one of the following ways:
13996 * <ul>
13997 * <li>return true : if the calling package has the appop permission {@link
13998 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
13999 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
14000 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
14001 * Owner device identifier access check, or the calling package has carrier privileges</>
14002 * <li>throw SecurityException: if the caller does not meet any of the requirements.
14003 * </ul>
14004 */
14005 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
14006 String callingPackage, @Nullable String callingFeatureId, String message) {
14007 for (Phone phone : PhoneFactory.getPhones()) {
14008 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
14009 phone.getSubId(), callingPackage, callingFeatureId, message)) {
14010 return true;
14011 }
14012 }
14013 return false;
14014 }
arunvoddud7401012022-12-15 16:08:12 +000014015
14016 /**
Jack Yufa8ed012023-02-11 15:42:28 -080014017 * @return The subscription manager service instance.
14018 */
14019 public SubscriptionManagerService getSubscriptionManagerService() {
14020 return SubscriptionManagerService.getInstance();
14021 }
14022
14023 /**
arunvoddud7401012022-12-15 16:08:12 +000014024 * Class binds the consumer[callback] and carrierId.
14025 */
14026 private static class CallerCallbackInfo {
14027 private final Consumer<Integer> mConsumer;
14028 private final int mCarrierId;
14029
14030 public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) {
14031 mConsumer = consumer;
14032 mCarrierId = carrierId;
14033 }
14034
14035 public Consumer<Integer> getConsumer() {
14036 return mConsumer;
14037 }
14038
14039 public int getCarrierId() {
14040 return mCarrierId;
14041 }
14042 }
joonhunshin4ac60942023-11-15 15:23:39 +000014043
14044 /*
14045 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14046 * But the context that is passed in is unused if the phone app is already alive.
14047 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14048 */
14049 @VisibleForTesting
14050 public void setPackageManager(PackageManager packageManager) {
14051 mPackageManager = packageManager;
14052 }
14053
14054 /*
14055 * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags.
14056 * But the FeatureFlags that is passed in is unused if the phone app is already alive.
14057 * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test.
14058 */
14059 @VisibleForTesting
14060 public void setFeatureFlags(FeatureFlags featureFlags) {
14061 mFeatureFlags = featureFlags;
14062 }
14063
14064 /**
14065 * Make sure the device has required telephony feature
14066 *
14067 * @throws UnsupportedOperationException if the device does not have required telephony feature
14068 */
14069 private void enforceTelephonyFeatureWithException(@Nullable String callingPackage,
14070 @NonNull String telephonyFeature, @NonNull String methodName) {
14071 if (callingPackage == null || mPackageManager == null) {
14072 return;
14073 }
14074
14075 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
14076 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage,
14077 Binder.getCallingUserHandle())) {
14078 return;
14079 }
14080
14081 if (!mPackageManager.hasSystemFeature(telephonyFeature)) {
14082 throw new UnsupportedOperationException(
14083 methodName + " is unsupported without " + telephonyFeature);
14084 }
14085 }
youngtaecha5d483d52024-04-29 17:05:45 +000014086
14087 /**
14088 * Registers for the satellite communication allowed state changed.
14089 *
14090 * @param subId The subId of the subscription to register for the satellite communication
14091 * allowed state changed.
14092 * @param callback The callback to handle the satellite communication allowed
14093 * state changed event.
14094 *
14095 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
14096 *
14097 * @throws SecurityException if the caller doesn't have the required permission.
14098 */
14099 @Override
14100 @SatelliteManager.SatelliteResult public int registerForCommunicationAllowedStateChanged(
14101 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14102 enforceSatelliteCommunicationPermission("registerForCommunicationAllowedStateChanged");
14103 return mSatelliteAccessController.registerForCommunicationAllowedStateChanged(
14104 subId, callback);
14105 }
14106
14107 /**
14108 * Unregisters for the satellite communication allowed state changed.
14109 * If callback was not registered before, the request will be ignored.
14110 *
14111 * @param subId The subId of the subscription to unregister for the satellite communication
14112 * allowed state changed.
14113 * @param callback The callback that was passed to
14114 * {@link #registerForCommunicationAllowedStateChanged(int,
14115 * ISatelliteCommunicationAllowedStateCallback)}. *
14116 * @throws SecurityException if the caller doesn't have the required permission.
14117 */
14118 @Override
14119 public void unregisterForCommunicationAllowedStateChanged(
14120 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14121 enforceSatelliteCommunicationPermission("unregisterForCommunicationAllowedStateChanged");
14122 mSatelliteAccessController.unregisterForCommunicationAllowedStateChanged(subId, callback);
14123 }
Jack Yufa8ed012023-02-11 15:42:28 -080014124}