blob: 2779bdbe1586d0a738f8e4e5972632e783350bb6 [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;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800159import android.telephony.satellite.ISatelliteDatagramCallback;
Hakjun Choid4a52a22023-12-13 09:48:24 +0000160import android.telephony.satellite.ISatelliteModemStateCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800161import android.telephony.satellite.ISatelliteProvisionStateCallback;
Hakjun Choif92ac752024-03-18 19:34:29 +0000162import android.telephony.satellite.ISatelliteSupportedStateCallback;
Sarah Chinabf081b2023-03-09 23:00:57 -0800163import android.telephony.satellite.ISatelliteTransmissionUpdateCallback;
Hakjun Choi4c3668a2023-12-05 11:55:36 +0000164import android.telephony.satellite.NtnSignalStrength;
165import android.telephony.satellite.NtnSignalStrengthCallback;
Sarah Chin503828c2023-02-01 23:54:20 -0800166import android.telephony.satellite.SatelliteCapabilities;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000167import android.telephony.satellite.SatelliteDatagram;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800168import android.telephony.satellite.SatelliteDatagramCallback;
Sarah Chineccfbd12023-01-20 19:00:35 -0800169import android.telephony.satellite.SatelliteManager;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800170import android.telephony.satellite.SatelliteProvisionStateCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700171import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800172import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700173import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700174import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800175import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800176
Andrew Lee312e8172014-10-23 17:01:36 -0700177import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800178import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800179import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800180import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800181import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700182import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700183import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700184import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800185import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800186import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700187import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700188import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800189import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700190import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800191import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800192import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800193import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700194import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000195import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700196import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800197import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700198import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800199import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800200import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800201import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700202import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700203import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700204import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700205import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700206import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800207import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700208import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700209import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700210import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700211import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800212import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800213import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700214import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000215import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700216import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700217import com.android.internal.telephony.SmsPermissions;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800218import com.android.internal.telephony.TelephonyCountryDetector;
Peter Wang59571be2020-01-27 12:35:15 +0800219import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800220import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700221import com.android.internal.telephony.data.DataUtils;
Hunsuk Choi42cc62a2022-10-16 06:03:40 +0000222import com.android.internal.telephony.domainselection.DomainSelectionResolver;
sqianf4ca7ed2019-01-15 18:32:07 -0800223import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700224import com.android.internal.telephony.euicc.EuiccConnector;
Sarah Chincc5446f2023-10-23 17:57:19 -0700225import com.android.internal.telephony.flags.FeatureFlags;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800226import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700227import com.android.internal.telephony.imsphone.ImsPhone;
228import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000229import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800230import com.android.internal.telephony.metrics.TelephonyMetrics;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000231import com.android.internal.telephony.satellite.SatelliteController;
Jack Yu285100e2022-12-02 22:48:35 -0800232import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
233import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700234import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700235import com.android.internal.telephony.uicc.IccIoResult;
236import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800237import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700238import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800239import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700240import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000241import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800242import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000243import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800244import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000245import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700246import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700247import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800248import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800249import com.android.phone.callcomposer.CallComposerPictureManager;
250import com.android.phone.callcomposer.CallComposerPictureTransfer;
251import com.android.phone.callcomposer.ImageData;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800252import com.android.phone.satellite.accesscontrol.SatelliteAccessController;
Hyosun Kim240214a2023-11-02 13:30:15 +0000253import com.android.phone.satellite.entitlement.SatelliteEntitlementController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700254import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700255import com.android.phone.slice.SlicePurchaseController;
arunvoddud7401012022-12-15 16:08:12 +0000256import com.android.phone.utils.CarrierAllowListInfo;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700257import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800258import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700259import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700260import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -0800261import com.android.server.feature.flags.Flags;
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;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -0800427 private com.android.server.telecom.flags.FeatureFlags mTelecomFeatureFlags;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800428 private final CallManager mCM;
429 private final ImsResolver mImsResolver;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000430
431 private final SatelliteController mSatelliteController;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800432 private final SatelliteAccessController mSatelliteAccessController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800433 private final UserManager mUserManager;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800434 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;
Nate Myren453c3472024-03-13 11:28:11 -0700438 private AppOpsManager mAppOps;
joonhunshin4ac60942023-11-15 15:23:39 +0000439 private PackageManager mPackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700440
Peter Wangdafb9ac2020-01-15 14:13:38 -0800441 /** User Activity */
Sarah Chin4beb2b72023-02-14 14:47:54 -0800442 private final AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800443 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800444 private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800445
Derek Tan97ebb422014-09-05 16:55:38 -0700446 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
447 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800448 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800449 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700450
Michelecea4cf22018-12-21 15:00:11 -0800451 // String to store multi SIM allowed
452 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
453
Derek Tan740e1672017-06-27 14:56:27 -0700454 // The AID of ISD-R.
455 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
456
yinxub1bed742017-04-17 11:45:04 -0700457 private NetworkScanRequestTracker mNetworkScanRequestTracker;
458
David Kelly5e06a7f2018-03-12 14:10:59 +0000459 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
460 private static final int MANUFACTURER_CODE_LENGTH = 8;
461
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800462 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800463 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800464
Sarah Chin2ec39f62022-08-31 17:03:26 -0700465 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
466 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
467
Derek Tan89e89d42014-07-08 17:00:10 -0700468 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700469 * Experiment flag to enable erase modem config on reset network, default value is false
470 */
471 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
472 "reset_network_erase_modem_config_enabled";
473
Rambo Wang0f050d82021-02-12 11:43:36 -0800474 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800475
Gary Jian76280a42022-12-07 16:18:33 +0800476 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
477
sandeepjsb6c87872021-09-27 15:34:44 +0000478 /**
479 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
480 * one ICCID active at the same time.
481 * Apps should use below API signatures if targeting SDK is T and beyond.
482 *
483 * @hide
484 */
485 @ChangeId
486 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
487 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800488
Naina Nallurid63128d2019-09-17 14:10:30 -0700489 /**
Chen Xu540470b2021-12-14 17:15:47 -0800490 * Apps targeting on Android T and beyond will get exception whenever icc close channel
491 * operation fails.
492 */
493 @ChangeId
494 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
495 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
496
497 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700498 * A request object to use for transmitting data to an ICC.
499 */
500 private static final class IccAPDUArgument {
501 public int channel, cla, command, p1, p2, p3;
502 public String data;
503
504 public IccAPDUArgument(int channel, int cla, int command,
505 int p1, int p2, int p3, String data) {
506 this.channel = channel;
507 this.cla = cla;
508 this.command = command;
509 this.p1 = p1;
510 this.p2 = p2;
511 this.p3 = p3;
512 this.data = data;
513 }
514 }
515
516 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700517 * A request object to use for transmitting data to an ICC.
518 */
519 private static final class ManualNetworkSelectionArgument {
520 public OperatorInfo operatorInfo;
521 public boolean persistSelection;
522
523 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
524 this.operatorInfo = operatorInfo;
525 this.persistSelection = persistSelection;
526 }
527 }
528
Sarah Chin71b3a852022-09-28 15:54:19 -0700529 private static final class PurchasePremiumCapabilityArgument {
530 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700531 public @NonNull IIntegerConsumer callback;
532
533 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800534 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700535 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700536 this.callback = callback;
537 }
538 }
539
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700540 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700541 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
542 * request after sending. The main thread will notify the request when it is complete.
543 */
544 private static final class MainThreadRequest {
545 /** The argument to use for the request */
546 public Object argument;
547 /** The result of the request that is run on the main thread */
548 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800549 // The subscriber id that this request applies to. Defaults to
550 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
551 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700552
Nathan Harold92bed182018-10-12 18:16:49 -0700553 // In cases where subId is unavailable, the caller needs to specify the phone.
554 public Phone phone;
555
vagdeviaf9a5b92018-08-15 16:01:53 -0700556 public WorkSource workSource;
557
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700558 public MainThreadRequest(Object argument) {
559 this.argument = argument;
560 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800561
Nathan Harold92bed182018-10-12 18:16:49 -0700562 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
563 this.argument = argument;
564 if (phone != null) {
565 this.phone = phone;
566 }
567 this.workSource = workSource;
568 }
569
vagdeviaf9a5b92018-08-15 16:01:53 -0700570 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800571 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800572 if (subId != null) {
573 this.subId = subId;
574 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700575 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800576 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700577 }
578
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800579 private static final class IncomingThirdPartyCallArgs {
580 public final ComponentName component;
581 public final String callId;
582 public final String callerDisplayName;
583
584 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
585 String callerDisplayName) {
586 this.component = component;
587 this.callId = callId;
588 this.callerDisplayName = callerDisplayName;
589 }
590 }
591
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700592 /**
593 * A handler that processes messages on the main thread in the phone process. Since many
594 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
595 * inbound binder threads to the main thread in the phone process. The Binder thread
596 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
597 * on, which will be notified when the operation completes and will contain the result of the
598 * request.
599 *
600 * <p>If a MainThreadRequest object is provided in the msg.obj field,
601 * note that request.result must be set to something non-null for the calling thread to
602 * unblock.
603 */
604 private final class MainThreadHandler extends Handler {
605 @Override
606 public void handleMessage(Message msg) {
607 MainThreadRequest request;
608 Message onCompleted;
609 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000610 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700611 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800612 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700613
614 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700615 case CMD_HANDLE_USSD_REQUEST: {
616 request = (MainThreadRequest) msg.obj;
617 final Phone phone = getPhoneFromRequest(request);
618 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800619 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700620 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700621
Pengquan Menga1bb6272018-09-06 09:59:22 -0700622 if (!isUssdApiAllowed(request.subId)) {
623 // Carrier does not support use of this API, return failure.
624 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
625 UssdResponse response = new UssdResponse(ussdRequest, null);
626 Bundle returnData = new Bundle();
627 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
628 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700629
Pengquan Menga1bb6272018-09-06 09:59:22 -0700630 request.result = true;
631 notifyRequester(request);
632 return;
633 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700634
Pengquan Menga1bb6272018-09-06 09:59:22 -0700635 try {
636 request.result = phone != null
637 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
638 } catch (CallStateException cse) {
639 request.result = false;
640 }
641 // Wake up the requesting thread
642 notifyRequester(request);
643 break;
pkanwar32d516d2016-10-14 19:37:38 -0700644 }
645
Yorke Lee716f67e2015-06-17 15:39:16 -0700646 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700647 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700648 final Phone phone = getPhoneFromRequest(request);
649 request.result = phone != null ?
650 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
651 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700652 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700653 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700654 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700655 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700656
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700657 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700658 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700659 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000660 uiccPort = getUiccPortFromRequest(request);
661 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700662 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800663 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700664 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700665 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700666 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800667 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000668 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800669 iccArgument.channel, iccArgument.cla, iccArgument.command,
670 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
671 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700672 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700673 break;
674
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700675 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700676 ar = (AsyncResult) msg.obj;
677 request = (MainThreadRequest) ar.userObj;
678 if (ar.exception == null && ar.result != null) {
679 request.result = ar.result;
680 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800681 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700682 if (ar.result == null) {
683 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800684 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700685 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800686 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700687 } else {
688 loge("iccTransmitApduLogicalChannel: Unknown exception");
689 }
690 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700691 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700692 break;
693
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700694 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
695 request = (MainThreadRequest) msg.obj;
696 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000697 uiccPort = getUiccPortFromRequest(request);
698 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700699 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800700 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700701 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700702 } else {
703 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800704 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000705 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800706 iccArgument.cla, iccArgument.command, iccArgument.p1,
707 iccArgument.p2,
708 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700709 }
710 break;
711
712 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
713 ar = (AsyncResult) msg.obj;
714 request = (MainThreadRequest) ar.userObj;
715 if (ar.exception == null && ar.result != null) {
716 request.result = ar.result;
717 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800718 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700719 if (ar.result == null) {
720 loge("iccTransmitApduBasicChannel: Empty response");
721 } else if (ar.exception instanceof CommandException) {
722 loge("iccTransmitApduBasicChannel: CommandException: " +
723 ar.exception);
724 } else {
725 loge("iccTransmitApduBasicChannel: Unknown exception");
726 }
727 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700728 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700729 break;
730
731 case CMD_EXCHANGE_SIM_IO:
732 request = (MainThreadRequest) msg.obj;
733 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000734 uiccPort = getUiccPortFromRequest(request);
735 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700736 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800737 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700738 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700739 } else {
740 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
741 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000742 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700743 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
744 iccArgument.data, onCompleted);
745 }
746 break;
747
748 case EVENT_EXCHANGE_SIM_IO_DONE:
749 ar = (AsyncResult) msg.obj;
750 request = (MainThreadRequest) ar.userObj;
751 if (ar.exception == null && ar.result != null) {
752 request.result = ar.result;
753 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800754 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700755 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700756 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700757 break;
758
Derek Tan4d5e5c12014-02-04 11:54:58 -0800759 case CMD_SEND_ENVELOPE:
760 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000761 uiccPort = getUiccPortFromRequest(request);
762 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700763 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800764 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700765 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700766 } else {
767 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800768 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700769 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800770 break;
771
772 case EVENT_SEND_ENVELOPE_DONE:
773 ar = (AsyncResult) msg.obj;
774 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700775 if (ar.exception == null && ar.result != null) {
776 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800777 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800778 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700779 if (ar.result == null) {
780 loge("sendEnvelopeWithStatus: Empty response");
781 } else if (ar.exception instanceof CommandException) {
782 loge("sendEnvelopeWithStatus: CommandException: " +
783 ar.exception);
784 } else {
785 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
786 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800787 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700788 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800789 break;
790
Shishir Agrawal566b7612013-10-28 14:41:00 -0700791 case CMD_OPEN_CHANNEL:
792 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000793 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800794 IccLogicalChannelRequest openChannelRequest =
795 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000796 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700797 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800798 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800799 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700800 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700801 } else {
802 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800803 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
804 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700805 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700806 break;
807
808 case EVENT_OPEN_CHANNEL_DONE:
809 ar = (AsyncResult) msg.obj;
810 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700811 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700812 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700813 int[] result = (int[]) ar.result;
814 int channelId = result[0];
815 byte[] selectResponse = null;
816 if (result.length > 1) {
817 selectResponse = new byte[result.length - 1];
818 for (int i = 1; i < result.length; ++i) {
819 selectResponse[i - 1] = (byte) result[i];
820 }
821 }
822 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800823 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800824
825 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700826 if (uiccPort == null) {
827 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
828 } else {
829 IccLogicalChannelRequest channelRequest =
830 (IccLogicalChannelRequest) request.argument;
831 channelRequest.channel = channelId;
832 uiccPort.onLogicalChannelOpened(channelRequest);
833 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700834 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700835 if (ar.result == null) {
836 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700837 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700838 if (ar.exception != null) {
839 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
840 }
841
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700842 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700843 if (ar.exception instanceof CommandException) {
844 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800845 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700846 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700847 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700848 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700849 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700850 }
851 }
852 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800853 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700854 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700855 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700856 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700857 break;
858
859 case CMD_CLOSE_CHANNEL:
860 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000861 uiccPort = getUiccPortFromRequest(request);
862 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700863 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800864 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800865 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800866 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700867 } else {
868 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000869 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700870 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700871 break;
872
873 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800874 ar = (AsyncResult) msg.obj;
875 request = (MainThreadRequest) ar.userObj;
876 if (ar.exception == null) {
877 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800878 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700879 if (uiccPort == null) {
880 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
881 } else {
882 final int channelId = (Integer) request.argument;
883 uiccPort.onLogicalChannelClosed(channelId);
884 }
Chen Xu540470b2021-12-14 17:15:47 -0800885 } else {
886 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800887 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800888 if (ar.exception instanceof CommandException) {
889 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
890 CommandException.Error error =
891 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800892 if (error == CommandException.Error.INVALID_ARGUMENTS) {
893 // should only throw exceptions from the binder threads.
894 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800895 "iccCloseLogicalChannel: invalid argument ");
896 }
897 } else {
898 loge("iccCloseLogicalChannel: Unknown exception");
899 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800900 request.result = (exception != null) ? exception :
901 new IllegalStateException(
902 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800903 }
904 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800905 break;
906
907 case CMD_NV_READ_ITEM:
908 request = (MainThreadRequest) msg.obj;
909 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800910 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
911 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800912 break;
913
914 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700915 ar = (AsyncResult) msg.obj;
916 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800917 if (ar.exception == null && ar.result != null) {
918 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700919 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800920 request.result = "";
921 if (ar.result == null) {
922 loge("nvReadItem: Empty response");
923 } else if (ar.exception instanceof CommandException) {
924 loge("nvReadItem: CommandException: " +
925 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700926 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800927 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700928 }
929 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700930 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700931 break;
932
Jake Hambye994d462014-02-03 13:10:13 -0800933 case CMD_NV_WRITE_ITEM:
934 request = (MainThreadRequest) msg.obj;
935 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
936 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800937 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700938 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800939 break;
940
941 case EVENT_NV_WRITE_ITEM_DONE:
942 handleNullReturnEvent(msg, "nvWriteItem");
943 break;
944
945 case CMD_NV_WRITE_CDMA_PRL:
946 request = (MainThreadRequest) msg.obj;
947 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800948 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800949 break;
950
951 case EVENT_NV_WRITE_CDMA_PRL_DONE:
952 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
953 break;
954
chen xu6dac5ab2018-10-26 17:39:23 -0700955 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800956 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700957 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800958 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800959 break;
960
chen xu6dac5ab2018-10-26 17:39:23 -0700961 case EVENT_RESET_MODEM_CONFIG_DONE:
962 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800963 break;
964
Sooraj Sasindran37444802020-08-11 10:40:43 -0700965 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
966 request = (MainThreadRequest) msg.obj;
967 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
968 request);
969 Phone phone = getPhoneFromRequest(request);
970 if (phone != null) {
971 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
972 } else {
973 loge("isNRDualConnectivityEnabled: No phone object");
974 request.result = false;
975 notifyRequester(request);
976 }
977 break;
978 }
979
980 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
981 ar = (AsyncResult) msg.obj;
982 request = (MainThreadRequest) ar.userObj;
983 if (ar.exception == null && ar.result != null) {
984 request.result = ar.result;
985 } else {
986 // request.result must be set to something non-null
987 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700988 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700989 request.result = ar.result;
990 } else {
991 request.result = false;
992 }
993 if (ar.result == null) {
994 loge("isNRDualConnectivityEnabled: Empty response");
995 } else if (ar.exception instanceof CommandException) {
996 loge("isNRDualConnectivityEnabled: CommandException: "
997 + ar.exception);
998 } else {
999 loge("isNRDualConnectivityEnabled: Unknown exception");
1000 }
1001 }
1002 notifyRequester(request);
1003 break;
1004
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001005 case CMD_IS_VONR_ENABLED: {
1006 request = (MainThreadRequest) msg.obj;
1007 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
1008 request);
1009 Phone phone = getPhoneFromRequest(request);
1010 if (phone != null) {
1011 phone.isVoNrEnabled(onCompleted, request.workSource);
1012 } else {
1013 loge("isVoNrEnabled: No phone object");
1014 request.result = false;
1015 notifyRequester(request);
1016 }
1017 break;
1018 }
1019
1020 case EVENT_IS_VONR_ENABLED_DONE:
1021 ar = (AsyncResult) msg.obj;
1022 request = (MainThreadRequest) ar.userObj;
1023 if (ar.exception == null && ar.result != null) {
1024 request.result = ar.result;
1025 } else {
1026 // request.result must be set to something non-null
1027 // for the calling thread to unblock
1028 if (ar.result != null) {
1029 request.result = ar.result;
1030 } else {
1031 request.result = false;
1032 }
1033 if (ar.result == null) {
1034 loge("isVoNrEnabled: Empty response");
1035 } else if (ar.exception instanceof CommandException) {
1036 loge("isVoNrEnabled: CommandException: "
1037 + ar.exception);
1038 } else {
1039 loge("isVoNrEnabled: Unknown exception");
1040 }
1041 }
1042 notifyRequester(request);
1043 break;
1044
Sooraj Sasindran37444802020-08-11 10:40:43 -07001045 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1046 request = (MainThreadRequest) msg.obj;
1047 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1048 Phone phone = getPhoneFromRequest(request);
1049 if (phone != null) {
1050 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1051 request.workSource);
1052 } else {
1053 loge("enableNrDualConnectivity: No phone object");
1054 request.result =
1055 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1056 notifyRequester(request);
1057 }
1058 break;
1059 }
1060
1061 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1062 ar = (AsyncResult) msg.obj;
1063 request = (MainThreadRequest) ar.userObj;
1064 if (ar.exception == null) {
1065 request.result =
1066 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1067 } else {
1068 request.result =
1069 TelephonyManager
1070 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1071 if (ar.exception instanceof CommandException) {
1072 CommandException.Error error =
1073 ((CommandException) (ar.exception)).getCommandError();
1074 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1075 request.result =
1076 TelephonyManager
1077 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001078 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1079 request.result =
1080 TelephonyManager
1081 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001082 }
1083 loge("enableNrDualConnectivity" + ": CommandException: "
1084 + ar.exception);
1085 } else {
1086 loge("enableNrDualConnectivity" + ": Unknown exception");
1087 }
1088 }
1089 notifyRequester(request);
1090 break;
1091 }
1092
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001093 case CMD_ENABLE_VONR: {
1094 request = (MainThreadRequest) msg.obj;
1095 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1096 Phone phone = getPhoneFromRequest(request);
1097 if (phone != null) {
1098 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1099 request.workSource);
1100 } else {
1101 loge("setVoNrEnabled: No phone object");
1102 request.result =
1103 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1104 notifyRequester(request);
1105 }
1106 break;
1107 }
1108
1109 case EVENT_ENABLE_VONR_DONE: {
1110 ar = (AsyncResult) msg.obj;
1111 request = (MainThreadRequest) ar.userObj;
1112 if (ar.exception == null) {
1113 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1114 } else {
1115 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1116 if (ar.exception instanceof CommandException) {
1117 CommandException.Error error =
1118 ((CommandException) (ar.exception)).getCommandError();
1119 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1120 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1121 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1122 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1123 } else {
1124 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1125 }
1126 loge("setVoNrEnabled" + ": CommandException: "
1127 + ar.exception);
1128 } else {
1129 loge("setVoNrEnabled" + ": Unknown exception");
1130 }
1131 }
1132 notifyRequester(request);
1133 break;
1134 }
1135
SongFerngWang3ef3e072020-12-21 16:41:52 +08001136 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001137 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001138 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1139 request);
1140 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001141 break;
1142
SongFerngWang3ef3e072020-12-21 16:41:52 +08001143 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001144 ar = (AsyncResult) msg.obj;
1145 request = (MainThreadRequest) ar.userObj;
1146 if (ar.exception == null && ar.result != null) {
1147 request.result = ar.result; // Integer
1148 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301149 // request.result must be set to something non-null
1150 // for the calling thread to unblock
1151 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001152 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001153 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001154 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001155 loge("getAllowedNetworkTypesBitmask: CommandException: "
1156 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001157 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001158 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001159 }
1160 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001161 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001162 break;
1163
SongFerngWang3ef3e072020-12-21 16:41:52 +08001164 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001165 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001166 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1167 request);
1168 Pair<Integer, Long> reasonWithNetworkTypes =
1169 (Pair<Integer, Long>) request.argument;
1170 getPhoneFromRequest(request).setAllowedNetworkTypes(
1171 reasonWithNetworkTypes.first,
1172 reasonWithNetworkTypes.second,
1173 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001174 break;
1175
SongFerngWang3ef3e072020-12-21 16:41:52 +08001176 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1177 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001178 break;
1179
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001180 case CMD_SET_VOICEMAIL_NUMBER:
1181 request = (MainThreadRequest) msg.obj;
1182 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1183 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001184 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1185 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001186 break;
1187
1188 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1189 handleNullReturnEvent(msg, "setVoicemailNumber");
1190 break;
1191
Stuart Scott54788802015-03-30 13:18:01 -07001192 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1193 request = (MainThreadRequest) msg.obj;
1194 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1195 request);
1196 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1197 break;
1198
1199 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1200 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1201 break;
1202
Shishir Agrawal302c8692015-06-19 13:49:39 -07001203 case CMD_PERFORM_NETWORK_SCAN:
1204 request = (MainThreadRequest) msg.obj;
1205 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1206 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1207 break;
1208
Hall Liu27d24262020-09-18 19:04:59 -07001209 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001210 request = (MainThreadRequest) msg.obj;
1211 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001212 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1213 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1214 request.argument;
1215 int callForwardingReason = args.first;
1216 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001217 break;
Hall Liu27d24262020-09-18 19:04:59 -07001218 }
1219 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001220 ar = (AsyncResult) msg.obj;
1221 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001222 TelephonyManager.CallForwardingInfoCallback callback =
1223 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1224 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001225 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001226 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001227 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1228 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1229 // Service Class is a bit mask per 3gpp 27.007. Search for
1230 // any service for voice call.
1231 if ((callForwardInfo.serviceClass
1232 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001233 callForwardingInfo = new CallForwardingInfo(
1234 callForwardInfo.status
1235 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001236 callForwardInfo.reason,
1237 callForwardInfo.number,
1238 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001239 break;
1240 }
1241 }
1242 // Didn't find a call forward info for voice call.
1243 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001244 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1245 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001246 }
Hall Liu27d24262020-09-18 19:04:59 -07001247 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001248 } else {
1249 if (ar.result == null) {
1250 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1251 }
1252 if (ar.exception != null) {
1253 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1254 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001255 int errorCode = TelephonyManager
1256 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001257 if (ar.exception instanceof CommandException) {
1258 CommandException.Error error =
1259 ((CommandException) (ar.exception)).getCommandError();
1260 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001261 errorCode = TelephonyManager
1262 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001263 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001264 errorCode = TelephonyManager
1265 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001266 }
1267 }
Hall Liu27d24262020-09-18 19:04:59 -07001268 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001269 }
Shuo Qian4a594052020-01-23 11:59:30 -08001270 break;
Hall Liu27d24262020-09-18 19:04:59 -07001271 }
Shuo Qian4a594052020-01-23 11:59:30 -08001272
Hall Liu27d24262020-09-18 19:04:59 -07001273 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001274 request = (MainThreadRequest) msg.obj;
1275 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001276 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001277 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001278 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1279 request.argument).first;
1280 request.phone.setCallForwardingOption(
1281 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001282 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001283 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001284 callForwardingInfoToSet.getReason(),
1285 callForwardingInfoToSet.getNumber(),
1286 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1287 break;
Hall Liu27d24262020-09-18 19:04:59 -07001288 }
Shuo Qian4a594052020-01-23 11:59:30 -08001289
Hall Liu27d24262020-09-18 19:04:59 -07001290 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001291 ar = (AsyncResult) msg.obj;
1292 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001293 Consumer<Integer> callback =
1294 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1295 request.argument).second;
1296 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001297 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001298 int errorCode = TelephonyManager.CallForwardingInfoCallback
1299 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001300 if (ar.exception instanceof CommandException) {
1301 CommandException.Error error =
1302 ((CommandException) (ar.exception)).getCommandError();
1303 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001304 errorCode = TelephonyManager.CallForwardingInfoCallback
1305 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001306 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001307 errorCode = TelephonyManager.CallForwardingInfoCallback
1308 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001309 }
1310 }
1311 callback.accept(errorCode);
1312 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001313 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001314 }
Shuo Qian4a594052020-01-23 11:59:30 -08001315 break;
Hall Liu27d24262020-09-18 19:04:59 -07001316 }
Shuo Qian4a594052020-01-23 11:59:30 -08001317
Hall Liu27d24262020-09-18 19:04:59 -07001318 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001319 request = (MainThreadRequest) msg.obj;
1320 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1321 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1322 break;
Hall Liu27d24262020-09-18 19:04:59 -07001323 }
Shuo Qian4a594052020-01-23 11:59:30 -08001324
Hall Liu27d24262020-09-18 19:04:59 -07001325 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001326 ar = (AsyncResult) msg.obj;
1327 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001328 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001329 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001330 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001331 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001332 // Service Class is a bit mask per 3gpp 27.007.
1333 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001334 if (callForwardResults.length > 1
1335 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001336 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001337 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001338 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1339 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001340 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001341 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001342 }
1343 } else {
1344 if (ar.result == null) {
1345 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1346 }
1347 if (ar.exception != null) {
1348 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1349 }
1350 if (ar.exception instanceof CommandException) {
1351 CommandException.Error error =
1352 ((CommandException) (ar.exception)).getCommandError();
1353 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001354 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001355 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001356 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1357 callWaitingStatus =
1358 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001359 }
1360 }
1361 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001362 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001363 break;
Hall Liu27d24262020-09-18 19:04:59 -07001364 }
Shuo Qian4a594052020-01-23 11:59:30 -08001365
Hall Liu27d24262020-09-18 19:04:59 -07001366 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001367 request = (MainThreadRequest) msg.obj;
1368 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001369 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1370 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001371 break;
Hall Liu27d24262020-09-18 19:04:59 -07001372 }
Shuo Qian4a594052020-01-23 11:59:30 -08001373
Hall Liu27d24262020-09-18 19:04:59 -07001374 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001375 ar = (AsyncResult) msg.obj;
1376 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001377 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1378 Consumer<Integer> callback =
1379 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1380 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001381 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001382 if (ar.exception instanceof CommandException) {
1383 CommandException.Error error =
1384 ((CommandException) (ar.exception)).getCommandError();
1385 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1386 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001387 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1388 callback.accept(
1389 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001390 } else {
1391 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1392 }
1393 } else {
1394 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1395 }
1396 } else {
1397 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1398 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001399 }
Shuo Qian4a594052020-01-23 11:59:30 -08001400 break;
Hall Liu27d24262020-09-18 19:04:59 -07001401 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001402 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1403 ar = (AsyncResult) msg.obj;
1404 request = (MainThreadRequest) ar.userObj;
1405 CellNetworkScanResult cellScanResult;
1406 if (ar.exception == null && ar.result != null) {
1407 cellScanResult = new CellNetworkScanResult(
1408 CellNetworkScanResult.STATUS_SUCCESS,
1409 (List<OperatorInfo>) ar.result);
1410 } else {
1411 if (ar.result == null) {
1412 loge("getCellNetworkScanResults: Empty response");
1413 }
1414 if (ar.exception != null) {
1415 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1416 }
1417 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1418 if (ar.exception instanceof CommandException) {
1419 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001420 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001421 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1422 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1423 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1424 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1425 }
1426 }
1427 cellScanResult = new CellNetworkScanResult(errorCode, null);
1428 }
1429 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001430 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001431 break;
1432
1433 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1434 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001435 ManualNetworkSelectionArgument selArg =
1436 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001437 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1438 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001439 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1440 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001441 break;
1442
1443 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001444 ar = (AsyncResult) msg.obj;
1445 request = (MainThreadRequest) ar.userObj;
1446 if (ar.exception == null) {
1447 request.result = true;
1448 } else {
1449 request.result = false;
1450 loge("setNetworkSelectionModeManual " + ar.exception);
1451 }
1452 notifyRequester(request);
1453 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001454 break;
1455
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001456 case CMD_GET_MODEM_ACTIVITY_INFO:
1457 request = (MainThreadRequest) msg.obj;
1458 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001459 if (defaultPhone != null) {
1460 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001461 } else {
1462 ResultReceiver result = (ResultReceiver) request.argument;
1463 Bundle bundle = new Bundle();
1464 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001465 new ModemActivityInfo(0, 0, 0,
1466 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001467 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001468 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001469 break;
1470
Hall Liud0f208c2020-10-14 16:54:44 -07001471 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001472 ar = (AsyncResult) msg.obj;
1473 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001474 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001475 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001476 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001477 if (mLastModemActivityInfo == null) {
1478 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1479 mLastModemActivitySpecificInfo[0] =
1480 new ActivityStatsTechSpecificInfo(
1481 0,
1482 0,
1483 new int[ModemActivityInfo.getNumTxPowerLevels()],
1484 0);
1485 mLastModemActivityInfo =
1486 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1487 }
1488
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001489 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001490 // Update the last modem activity info and the result of the request.
1491 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1492 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001493 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001494 } else {
1495 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001496 }
Kai Shi917fdc62022-11-28 14:01:02 -08001497 // This is needed to decouple ret from mLastModemActivityInfo
1498 // We don't want to return mLastModemActivityInfo which is updated
1499 // inside mergeModemActivityInfo()
1500 ret = new ModemActivityInfo(
1501 mLastModemActivityInfo.getTimestampMillis(),
1502 mLastModemActivityInfo.getSleepTimeMillis(),
1503 mLastModemActivityInfo.getIdleTimeMillis(),
1504 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001505
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001506 } else {
1507 if (ar.result == null) {
1508 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001509 error = TelephonyManager.ModemActivityInfoException
1510 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001511 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001512 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001513 error = TelephonyManager.ModemActivityInfoException
1514 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001515 } else {
1516 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001517 error = TelephonyManager.ModemActivityInfoException
1518 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001519 }
1520 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001521 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001522 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001523 bundle.putParcelable(
1524 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001525 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001526 } else {
1527 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1528 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001529 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001530 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001531 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001532 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001533
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001534 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001535 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001536 CarrierRestrictionRules argument =
1537 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001538 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001539 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001540 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001541 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001542
1543 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1544 ar = (AsyncResult) msg.obj;
1545 request = (MainThreadRequest) ar.userObj;
1546 if (ar.exception == null && ar.result != null) {
1547 request.result = ar.result;
1548 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001549 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1550 if (ar.exception instanceof CommandException) {
1551 loge("setAllowedCarriers: CommandException: " + ar.exception);
1552 CommandException.Error error =
1553 ((CommandException) (ar.exception)).getCommandError();
1554 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1555 request.result =
1556 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1557 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001558 } else {
1559 loge("setAllowedCarriers: Unknown exception");
1560 }
1561 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001562 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001563 break;
1564
1565 case CMD_GET_ALLOWED_CARRIERS:
1566 request = (MainThreadRequest) msg.obj;
1567 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001568 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001569 break;
1570
1571 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1572 ar = (AsyncResult) msg.obj;
1573 request = (MainThreadRequest) ar.userObj;
1574 if (ar.exception == null && ar.result != null) {
1575 request.result = ar.result;
1576 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001577 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001578 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001579 if (ar.result == null) {
1580 loge("getAllowedCarriers: Empty response");
1581 } else if (ar.exception instanceof CommandException) {
1582 loge("getAllowedCarriers: CommandException: " +
1583 ar.exception);
1584 } else {
1585 loge("getAllowedCarriers: Unknown exception");
1586 }
1587 }
arunvoddud7401012022-12-15 16:08:12 +00001588 if (request.argument != null) {
1589 // This is for the implementation of carrierRestrictionStatus.
1590 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1591 Consumer<Integer> callback = callbackInfo.getConsumer();
Steve Statia28b7cb32024-03-11 23:58:50 +00001592 Set<Integer> callerCarrierIds = callbackInfo.getCarrierIds();
arunvoddud7401012022-12-15 16:08:12 +00001593 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1594 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1595 CarrierRestrictionRules carrierRestrictionRules =
1596 (CarrierRestrictionRules) ar.result;
1597 int carrierId = -1;
1598 try {
1599 CarrierIdentifier carrierIdentifier =
1600 carrierRestrictionRules.getAllowedCarriers().get(0);
1601 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1602 carrierIdentifier);
1603 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1604 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1605 }
1606 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
Steve Statia28b7cb32024-03-11 23:58:50 +00001607 int restrictedStatus =
1608 TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED;
1609 if (carrierId != -1 && callerCarrierIds.contains(carrierId) &&
1610 lockStatus == restrictedStatus) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001611 lockStatus = TelephonyManager
1612 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001613 }
1614 } else {
1615 Rlog.e(LOG_TAG,
1616 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1617 }
1618 callback.accept(lockStatus);
1619 } else {
1620 // This is for the implementation of getAllowedCarriers.
1621 notifyRequester(request);
1622 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001623 break;
1624
Nathan Haroldb3014052017-01-25 15:57:32 -08001625 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1626 ar = (AsyncResult) msg.obj;
1627 request = (MainThreadRequest) ar.userObj;
1628 if (ar.exception == null && ar.result != null) {
1629 request.result = ar.result;
1630 } else {
1631 request.result = new IllegalArgumentException(
1632 "Failed to retrieve Forbidden Plmns");
1633 if (ar.result == null) {
1634 loge("getForbiddenPlmns: Empty response");
1635 } else {
1636 loge("getForbiddenPlmns: Unknown exception");
1637 }
1638 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001639 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001640 break;
1641
1642 case CMD_GET_FORBIDDEN_PLMNS:
1643 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001644 uiccPort = getUiccPortFromRequest(request);
1645 if (uiccPort == null) {
1646 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001647 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001648 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001649 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001650 break;
1651 }
1652 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001653 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001654 if (uiccApp == null) {
1655 loge("getForbiddenPlmns() no app with specified type -- "
1656 + appType);
1657 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001658 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001659 break;
1660 } else {
1661 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1662 + " specified type -- " + appType);
1663 }
1664 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1665 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001666 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001667 break;
1668
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001669 case CMD_SWITCH_SLOTS:
1670 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001671 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001672 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001673 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001674 break;
1675
1676 case EVENT_SWITCH_SLOTS_DONE:
1677 ar = (AsyncResult) msg.obj;
1678 request = (MainThreadRequest) ar.userObj;
1679 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001680 notifyRequester(request);
1681 break;
1682 case CMD_GET_NETWORK_SELECTION_MODE:
1683 request = (MainThreadRequest) msg.obj;
1684 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1685 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1686 break;
1687
1688 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1689 ar = (AsyncResult) msg.obj;
1690 request = (MainThreadRequest) ar.userObj;
1691 if (ar.exception != null) {
1692 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1693 } else {
1694 int mode = ((int[]) ar.result)[0];
1695 if (mode == 0) {
1696 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1697 } else {
1698 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1699 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001700 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001701 notifyRequester(request);
1702 break;
1703 case CMD_GET_CDMA_ROAMING_MODE:
1704 request = (MainThreadRequest) msg.obj;
1705 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1706 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1707 break;
1708 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1709 ar = (AsyncResult) msg.obj;
1710 request = (MainThreadRequest) ar.userObj;
1711 if (ar.exception != null) {
1712 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1713 } else {
1714 request.result = ((int[]) ar.result)[0];
1715 }
1716 notifyRequester(request);
1717 break;
1718 case CMD_SET_CDMA_ROAMING_MODE:
1719 request = (MainThreadRequest) msg.obj;
1720 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1721 int mode = (int) request.argument;
1722 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1723 break;
1724 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1725 ar = (AsyncResult) msg.obj;
1726 request = (MainThreadRequest) ar.userObj;
1727 request.result = ar.exception == null;
1728 notifyRequester(request);
1729 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001730 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1731 request = (MainThreadRequest) msg.obj;
1732 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1733 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1734 break;
1735 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1736 ar = (AsyncResult) msg.obj;
1737 request = (MainThreadRequest) ar.userObj;
1738 if (ar.exception != null) {
1739 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1740 } else {
1741 request.result = ((int[]) ar.result)[0];
1742 }
1743 notifyRequester(request);
1744 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001745 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1746 request = (MainThreadRequest) msg.obj;
1747 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1748 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001749 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1750 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001751 break;
1752 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1753 ar = (AsyncResult) msg.obj;
1754 request = (MainThreadRequest) ar.userObj;
1755 request.result = ar.exception == null;
1756 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001757 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001758 case CMD_GET_ALL_CELL_INFO:
1759 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001760 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001761 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001762 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001763 case EVENT_GET_ALL_CELL_INFO_DONE:
1764 ar = (AsyncResult) msg.obj;
1765 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001766 // If a timeout occurs, the response will be null
1767 request.result = (ar.exception == null && ar.result != null)
1768 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001769 synchronized (request) {
1770 request.notifyAll();
1771 }
1772 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001773 case CMD_REQUEST_CELL_INFO_UPDATE:
1774 request = (MainThreadRequest) msg.obj;
1775 request.phone.requestCellInfoUpdate(request.workSource,
1776 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1777 break;
1778 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1779 ar = (AsyncResult) msg.obj;
1780 request = (MainThreadRequest) ar.userObj;
1781 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1782 try {
1783 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001784 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001785 cb.onError(
1786 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1787 ar.exception.getClass().getName(),
1788 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001789 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001790 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001791 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001792 } else {
1793 // use the result as returned
1794 cb.onCellInfo((List<CellInfo>) ar.result);
1795 }
1796 } catch (RemoteException re) {
1797 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1798 }
1799 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001800 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001801 request = (MainThreadRequest) msg.obj;
1802 WorkSource ws = (WorkSource) request.argument;
1803 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001804 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001805 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001806 }
1807 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001808 ar = (AsyncResult) msg.obj;
1809 request = (MainThreadRequest) ar.userObj;
1810 if (ar.exception == null) {
1811 request.result = ar.result;
1812 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001813 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001814 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001815 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001816 }
1817
1818 synchronized (request) {
1819 request.notifyAll();
1820 }
1821 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001822 }
chen xu6dac5ab2018-10-26 17:39:23 -07001823 case CMD_MODEM_REBOOT:
1824 request = (MainThreadRequest) msg.obj;
1825 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001826 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001827 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001828 case EVENT_CMD_MODEM_REBOOT_DONE:
1829 handleNullReturnEvent(msg, "rebootModem");
1830 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001831 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001832 request = (MainThreadRequest) msg.obj;
1833 boolean enable = (boolean) request.argument;
1834 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001835 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001836 PhoneConfigurationManager.getInstance()
1837 .enablePhone(request.phone, enable, onCompleted);
1838 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001839 }
Michele Berionne5e411512020-11-13 02:36:59 +00001840 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001841 ar = (AsyncResult) msg.obj;
1842 request = (MainThreadRequest) ar.userObj;
1843 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001844 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001845 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001846 if ((boolean) request.result) {
1847 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1848 updateModemStateMetrics();
1849 } else {
1850 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1851 + ar.exception);
1852 }
1853 notifyRequester(request);
1854 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001855 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001856 case CMD_GET_MODEM_STATUS:
1857 request = (MainThreadRequest) msg.obj;
1858 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1859 PhoneConfigurationManager.getInstance()
1860 .getPhoneStatusFromModem(request.phone, onCompleted);
1861 break;
1862 case EVENT_GET_MODEM_STATUS_DONE:
1863 ar = (AsyncResult) msg.obj;
1864 request = (MainThreadRequest) ar.userObj;
1865 int id = request.phone.getPhoneId();
1866 if (ar.exception == null && ar.result != null) {
1867 request.result = ar.result;
1868 //update the cache as modem status has changed
1869 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1870 (boolean) request.result);
1871 } else {
1872 // Return true if modem status cannot be retrieved. For most cases,
1873 // modem status is on. And for older version modems, GET_MODEM_STATUS
1874 // and disable modem are not supported. Modem is always on.
1875 // TODO: this should be fixed in R to support a third
1876 // status UNKNOWN b/131631629
1877 request.result = true;
1878 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1879 + ar.exception);
1880 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001881 notifyRequester(request);
1882 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001883 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1884 request = (MainThreadRequest) msg.obj;
1885 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1886 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1887 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1888 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1889 break;
1890 }
1891 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1892 ar = (AsyncResult) msg.obj;
1893 request = (MainThreadRequest) ar.userObj;
1894 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1895 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1896 args.second.accept(ar.exception == null);
1897 notifyRequester(request);
1898 break;
1899 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001900 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1901 request = (MainThreadRequest) msg.obj;
1902 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1903 Phone phone = getPhoneFromRequest(request);
1904 if (phone != null) {
1905 phone.getSystemSelectionChannels(onCompleted);
1906 } else {
1907 loge("getSystemSelectionChannels: No phone object");
1908 request.result = new ArrayList<RadioAccessSpecifier>();
1909 notifyRequester(request);
1910 }
1911 break;
1912 }
1913 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1914 ar = (AsyncResult) msg.obj;
1915 request = (MainThreadRequest) ar.userObj;
1916 if (ar.exception == null && ar.result != null) {
1917 request.result = ar.result;
1918 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001919 request.result = new IllegalStateException(
1920 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001921 if (ar.result == null) {
1922 loge("getSystemSelectionChannels: Empty response");
1923 } else {
1924 loge("getSystemSelectionChannels: Unknown exception");
1925 }
1926 }
1927 notifyRequester(request);
1928 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001929 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1930 ar = (AsyncResult) msg.obj;
1931 request = (MainThreadRequest) ar.userObj;
1932 if (ar.exception == null && ar.result != null) {
1933 request.result = ar.result;
1934 } else {
1935 request.result = -1;
1936 loge("Failed to set Forbidden Plmns");
1937 if (ar.result == null) {
1938 loge("setForbidenPlmns: Empty response");
1939 } else if (ar.exception != null) {
1940 loge("setForbiddenPlmns: Exception: " + ar.exception);
1941 request.result = -1;
1942 } else {
1943 loge("setForbiddenPlmns: Unknown exception");
1944 }
1945 }
1946 notifyRequester(request);
1947 break;
1948 case CMD_SET_FORBIDDEN_PLMNS:
1949 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001950 uiccPort = getUiccPortFromRequest(request);
1951 if (uiccPort == null) {
1952 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001953 request.result = -1;
1954 notifyRequester(request);
1955 break;
1956 }
1957 Pair<Integer, List<String>> setFplmnsArgs =
1958 (Pair<Integer, List<String>>) request.argument;
1959 appType = setFplmnsArgs.first;
1960 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001961 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001962 if (uiccApp == null) {
1963 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1964 request.result = -1;
1965 loge("Failed to get UICC App");
1966 notifyRequester(request);
1967 } else {
1968 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1969 ((SIMRecords) uiccApp.getIccRecords())
1970 .setForbiddenPlmns(onCompleted, fplmns);
1971 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001972 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001973 case CMD_ERASE_MODEM_CONFIG:
1974 request = (MainThreadRequest) msg.obj;
1975 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1976 defaultPhone.eraseModemConfig(onCompleted);
1977 break;
1978 case EVENT_ERASE_MODEM_CONFIG_DONE:
1979 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001980 break;
zoey chene02881a2019-12-30 16:11:23 +08001981
Kai Shif70f46f2021-03-03 13:59:46 -08001982 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1983 request = (MainThreadRequest) msg.obj;
1984 request.result = defaultPhone.eraseDataInSharedPreferences();
1985 notifyRequester(request);
1986 break;
1987
zoey chene02881a2019-12-30 16:11:23 +08001988 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1989 request = (MainThreadRequest) msg.obj;
1990 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1991 Pair<String, String> changed = (Pair<String, String>) request.argument;
1992 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1993 changed.first, changed.second, onCompleted);
1994 break;
1995 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1996 ar = (AsyncResult) msg.obj;
1997 request = (MainThreadRequest) ar.userObj;
1998 if (ar.exception == null) {
1999 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002000 // If the operation is successful, update the PIN storage
2001 Pair<String, String> passwords = (Pair<String, String>) request.argument;
2002 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00002003 UiccController.getInstance().getPinStorage()
2004 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08002005 } else {
2006 request.result = msg.arg1;
2007 }
2008 notifyRequester(request);
2009 break;
2010
Michele Berionne5e411512020-11-13 02:36:59 +00002011 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08002012 request = (MainThreadRequest) msg.obj;
2013 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
2014 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2015 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2016 enabled.first, enabled.second, onCompleted);
2017 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002018 }
zoey chene02881a2019-12-30 16:11:23 +08002019 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2020 ar = (AsyncResult) msg.obj;
2021 request = (MainThreadRequest) ar.userObj;
2022 if (ar.exception == null) {
2023 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002024 // If the operation is successful, update the PIN storage
2025 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2026 int phoneId = getPhoneFromRequest(request).getPhoneId();
2027 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002028 UiccController.getInstance().getPinStorage()
2029 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002030 } else {
2031 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2032 }
zoey chene02881a2019-12-30 16:11:23 +08002033 } else {
2034 request.result = msg.arg1;
2035 }
Michele Berionne5e411512020-11-13 02:36:59 +00002036
2037
zoey chene02881a2019-12-30 16:11:23 +08002038 notifyRequester(request);
2039 break;
2040
Peter Wangdafb9ac2020-01-15 14:13:38 -08002041 case MSG_NOTIFY_USER_ACTIVITY:
2042 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002043 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002044 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2045 getDefaultPhone().getContext().sendBroadcastAsUser(
2046 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2047 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002048
2049 case CMD_SET_DATA_THROTTLING: {
2050 request = (MainThreadRequest) msg.obj;
2051 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2052 DataThrottlingRequest dataThrottlingRequest =
2053 (DataThrottlingRequest) request.argument;
2054 Phone phone = getPhoneFromRequest(request);
2055 if (phone != null) {
2056 phone.setDataThrottling(onCompleted,
2057 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2058 dataThrottlingRequest.getCompletionDurationMillis());
2059 } else {
2060 loge("setDataThrottling: No phone object");
2061 request.result =
2062 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2063 notifyRequester(request);
2064 }
2065
2066 break;
2067 }
2068 case EVENT_SET_DATA_THROTTLING_DONE:
2069 ar = (AsyncResult) msg.obj;
2070 request = (MainThreadRequest) ar.userObj;
2071
2072 if (ar.exception == null) {
2073 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2074 } else if (ar.exception instanceof CommandException) {
2075 loge("setDataThrottling: CommandException: " + ar.exception);
2076 CommandException.Error error =
2077 ((CommandException) (ar.exception)).getCommandError();
2078
2079 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2080 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002081 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002082 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2083 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002084 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2085 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002086 } else {
2087 request.result =
2088 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2089 }
2090 } else {
2091 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2092 }
2093 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2094 notifyRequester(request);
2095 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002096
2097 case CMD_SET_SIM_POWER: {
2098 request = (MainThreadRequest) msg.obj;
2099 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2100 request = (MainThreadRequest) msg.obj;
2101 int stateToSet =
2102 ((Pair<Integer, IIntegerConsumer>)
2103 request.argument).first;
2104 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2105 break;
2106 }
2107 case EVENT_SET_SIM_POWER_DONE: {
2108 ar = (AsyncResult) msg.obj;
2109 request = (MainThreadRequest) ar.userObj;
2110 IIntegerConsumer callback =
2111 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2112 if (ar.exception != null) {
2113 loge("setSimPower exception: " + ar.exception);
2114 int errorCode = TelephonyManager.CallForwardingInfoCallback
2115 .RESULT_ERROR_UNKNOWN;
2116 if (ar.exception instanceof CommandException) {
2117 CommandException.Error error =
2118 ((CommandException) (ar.exception)).getCommandError();
2119 if (error == CommandException.Error.SIM_ERR) {
2120 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2121 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2122 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2123 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2124 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2125 } else {
2126 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2127 }
2128 }
2129 try {
2130 callback.accept(errorCode);
2131 } catch (RemoteException e) {
2132 // Ignore if the remote process is no longer available to call back.
2133 Log.w(LOG_TAG, "setSimPower: callback not available.");
2134 }
2135 } else {
2136 try {
2137 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2138 } catch (RemoteException e) {
2139 // Ignore if the remote process is no longer available to call back.
2140 Log.w(LOG_TAG, "setSimPower: callback not available.");
2141 }
2142 }
2143 break;
2144 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002145 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2146 request = (MainThreadRequest) msg.obj;
2147
2148 final Phone phone = getPhoneFromRequest(request);
2149 if (phone == null || phone.getServiceStateTracker() == null) {
2150 request.result = new IllegalStateException("Phone or SST is null");
2151 notifyRequester(request);
2152 break;
2153 }
2154
2155 Pair<Integer, SignalStrengthUpdateRequest> pair =
2156 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2157 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2158 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002159 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002160 request.subId, pair.first /*callingUid*/,
2161 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002162 break;
2163 }
2164 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2165 ar = (AsyncResult) msg.obj;
2166 request = (MainThreadRequest) ar.userObj;
2167 // request.result will be the exception of ar if present, true otherwise.
2168 // Be cautious not to leave result null which will wait() forever
2169 request.result = ar.exception != null ? ar.exception : true;
2170 notifyRequester(request);
2171 break;
2172 }
2173 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2174 request = (MainThreadRequest) msg.obj;
2175
2176 Phone phone = getPhoneFromRequest(request);
2177 if (phone == null || phone.getServiceStateTracker() == null) {
2178 request.result = new IllegalStateException("Phone or SST is null");
2179 notifyRequester(request);
2180 break;
2181 }
2182
2183 Pair<Integer, SignalStrengthUpdateRequest> pair =
2184 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2185 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2186 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002187 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002188 request.subId, pair.first /*callingUid*/,
2189 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002190 break;
2191 }
2192 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2193 ar = (AsyncResult) msg.obj;
2194 request = (MainThreadRequest) ar.userObj;
2195 request.result = ar.exception != null ? ar.exception : true;
2196 notifyRequester(request);
2197 break;
2198 }
Jordan Liu109698e2020-11-24 14:50:34 -08002199
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002200 case CMD_GET_SLICING_CONFIG: {
2201 request = (MainThreadRequest) msg.obj;
2202 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2203 request.phone.getSlicingConfig(onCompleted);
2204 break;
2205 }
2206 case EVENT_GET_SLICING_CONFIG_DONE: {
2207 ar = (AsyncResult) msg.obj;
2208 request = (MainThreadRequest) ar.userObj;
2209 ResultReceiver result = (ResultReceiver) request.argument;
2210
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002211 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002212 Bundle bundle = new Bundle();
2213 int resultCode = 0;
2214 if (ar.exception != null) {
2215 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2216 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002217 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002218 } else if (ar.result == null) {
2219 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002220 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002221 } else {
2222 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002223 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2224 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002225 }
2226
2227 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002228 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002229 }
2230 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2231 result.send(resultCode, bundle);
2232 notifyRequester(request);
2233 break;
2234 }
2235
Sarah Chin71b3a852022-09-28 15:54:19 -07002236 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002237 request = (MainThreadRequest) msg.obj;
2238 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002239 PurchasePremiumCapabilityArgument arg =
2240 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chincc5446f2023-10-23 17:57:19 -07002241 SlicePurchaseController.getInstance(request.phone, mFeatureFlags)
2242 .purchasePremiumCapability(arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002243 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002244 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002245
Sarah Chin71b3a852022-09-28 15:54:19 -07002246 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002247 ar = (AsyncResult) msg.obj;
2248 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002249 PurchasePremiumCapabilityArgument arg =
2250 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002251 try {
2252 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002253 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002254 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002255 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chinff8b1802023-04-11 14:22:14 -07002256 + ", result="
Sarah Chin2ec39f62022-08-31 17:03:26 -07002257 + TelephonyManager.convertPurchaseResultToString(result));
2258 } catch (RemoteException e) {
2259 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002260 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002261 + " failed: " + e;
2262 if (DBG) log(logStr);
2263 AnomalyReporter.reportAnomaly(
2264 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2265 }
2266 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002267 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002268
Michele Berionne5e411512020-11-13 02:36:59 +00002269 case CMD_PREPARE_UNATTENDED_REBOOT:
2270 request = (MainThreadRequest) msg.obj;
2271 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002272 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002273 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002274 notifyRequester(request);
2275 break;
2276
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002277 default:
2278 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2279 break;
2280 }
2281 }
Jake Hambye994d462014-02-03 13:10:13 -08002282
Pengquan Menga1bb6272018-09-06 09:59:22 -07002283 private void notifyRequester(MainThreadRequest request) {
2284 synchronized (request) {
2285 request.notifyAll();
2286 }
2287 }
2288
Jake Hambye994d462014-02-03 13:10:13 -08002289 private void handleNullReturnEvent(Message msg, String command) {
2290 AsyncResult ar = (AsyncResult) msg.obj;
2291 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2292 if (ar.exception == null) {
2293 request.result = true;
2294 } else {
2295 request.result = false;
2296 if (ar.exception instanceof CommandException) {
2297 loge(command + ": CommandException: " + ar.exception);
2298 } else {
2299 loge(command + ": Unknown exception");
2300 }
2301 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002302 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002303 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002304 }
2305
2306 /**
2307 * Posts the specified command to be executed on the main thread,
2308 * waits for the request to complete, and returns the result.
2309 * @see #sendRequestAsync
2310 */
2311 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002312 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2313 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002314 }
2315
2316 /**
2317 * Posts the specified command to be executed on the main thread,
2318 * waits for the request to complete, and returns the result.
2319 * @see #sendRequestAsync
2320 */
2321 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2322 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002323 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002324 }
2325
2326 /**
2327 * Posts the specified command to be executed on the main thread,
2328 * waits for the request to complete, and returns the result.
2329 * @see #sendRequestAsync
2330 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002331 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002332 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2333 }
2334
2335 /**
2336 * Posts the specified command to be executed on the main thread,
2337 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2338 * if not timeout or null otherwise.
2339 * @see #sendRequestAsync
2340 */
2341 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2342 long timeoutInMs) {
2343 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002344 }
2345
2346 /**
2347 * Posts the specified command to be executed on the main thread,
2348 * waits for the request to complete, and returns the result.
2349 * @see #sendRequestAsync
2350 */
Nathan Harold92bed182018-10-12 18:16:49 -07002351 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002352 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002353 }
2354
2355 /**
2356 * Posts the specified command to be executed on the main thread,
2357 * waits for the request to complete, and returns the result.
2358 * @see #sendRequestAsync
2359 */
2360 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002361 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2362 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002363 }
2364
2365 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002366 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2367 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2368 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002369 * @see #sendRequestAsync
2370 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002371 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2372 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002373 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2374 throw new RuntimeException("This method will deadlock if called from the main thread.");
2375 }
2376
Nathan Harold92bed182018-10-12 18:16:49 -07002377 MainThreadRequest request = null;
2378 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2379 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2380 } else if (phone != null) {
2381 request = new MainThreadRequest(argument, phone, workSource);
2382 } else {
2383 request = new MainThreadRequest(argument, subId, workSource);
2384 }
2385
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002386 Message msg = mMainThreadHandler.obtainMessage(command, request);
2387 msg.sendToTarget();
2388
Rambo Wang0f050d82021-02-12 11:43:36 -08002389
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002390 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002391 if (timeoutInMs >= 0) {
2392 // Wait for at least timeoutInMs before returning null request result
2393 long now = SystemClock.elapsedRealtime();
2394 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002395 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002396 try {
2397 request.wait(deadline - now);
2398 } catch (InterruptedException e) {
2399 // Do nothing, go back and check if request is completed or timeout
2400 } finally {
2401 now = SystemClock.elapsedRealtime();
2402 }
2403 }
2404 } else {
2405 // Wait for the request to complete
2406 while (request.result == null) {
2407 try {
2408 request.wait();
2409 } catch (InterruptedException e) {
2410 // Do nothing, go back and wait until the request is complete
2411 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002412 }
2413 }
2414 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002415 if (request.result == null) {
2416 Log.wtf(LOG_TAG,
2417 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2418 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002419 return request.result;
2420 }
2421
2422 /**
2423 * Asynchronous ("fire and forget") version of sendRequest():
2424 * Posts the specified command to be executed on the main thread, and
2425 * returns immediately.
2426 * @see #sendRequest
2427 */
2428 private void sendRequestAsync(int command) {
2429 mMainThreadHandler.sendEmptyMessage(command);
2430 }
2431
2432 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002433 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002434 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002435 */
2436 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002437 sendRequestAsync(command, argument, null, null);
2438 }
2439
2440 /**
2441 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2442 * @see {@link #sendRequest(int,Object)}
2443 */
2444 private void sendRequestAsync(
2445 int command, Object argument, Phone phone, WorkSource workSource) {
2446 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002447 Message msg = mMainThreadHandler.obtainMessage(command, request);
2448 msg.sendToTarget();
2449 }
2450
2451 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002452 * Initialize the singleton PhoneInterfaceManager instance.
2453 * This is only done once, at startup, from PhoneApp.onCreate().
2454 */
Sarah Chincc5446f2023-10-23 17:57:19 -07002455 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002456 synchronized (PhoneInterfaceManager.class) {
2457 if (sInstance == null) {
Sarah Chincc5446f2023-10-23 17:57:19 -07002458 sInstance = new PhoneInterfaceManager(app, featureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002459 } else {
2460 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2461 }
2462 return sInstance;
2463 }
2464 }
2465
2466 /** Private constructor; @see init() */
Sarah Chincc5446f2023-10-23 17:57:19 -07002467 private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002468 mApp = app;
Sarah Chincc5446f2023-10-23 17:57:19 -07002469 mFeatureFlags = featureFlags;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -08002470 mTelecomFeatureFlags = new com.android.server.telecom.flags.FeatureFlagsImpl();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002471 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002472 mImsResolver = ImsResolver.getInstance();
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +00002473 mSatelliteController = SatelliteController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002474 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002475 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2476 mMainThreadHandler = new MainThreadHandler();
Sarah Chin4beb2b72023-02-14 14:47:54 -08002477 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002478 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002479 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002480 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002481 mNotifyUserActivity = new AtomicBoolean(false);
joonhunshin4ac60942023-11-15 15:23:39 +00002482 mPackageManager = app.getPackageManager();
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -08002483 mSatelliteAccessController = SatelliteAccessController.getOrCreateInstance(
2484 getDefaultPhone().getContext(), featureFlags);
Tyler Gunn64144d92022-03-17 14:16:41 -07002485 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002486 publish();
arunvoddud7401012022-12-15 16:08:12 +00002487 CarrierAllowListInfo.loadInstance(mApp);
Hyosun Kim240214a2023-11-02 13:30:15 +00002488
2489 // Create the SatelliteEntitlementController singleton, for using the get the
2490 // entitlementStatus for satellite service.
2491 SatelliteEntitlementController.make(mApp, mFeatureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002492 }
2493
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002494 @VisibleForTesting
2495 public SharedPreferences getSharedPreferences() {
2496 return mTelephonySharedPreferences;
2497 }
2498
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002499 /**
2500 * Get the default phone for this device.
2501 */
2502 @VisibleForTesting
2503 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002504 Phone thePhone = getPhone(getDefaultSubscription());
2505 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2506 }
2507
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002508 private void publish() {
2509 if (DBG) log("publish: " + this);
2510
Peter Wangc035ce42020-01-08 21:00:22 -08002511 TelephonyFrameworkInitializer
2512 .getTelephonyServiceManager()
2513 .getTelephonyServiceRegisterer()
2514 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002515 }
2516
Stuart Scott584921c2015-01-15 17:10:34 -08002517 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002518 if (request.phone != null) {
2519 return request.phone;
2520 } else {
2521 return getPhoneFromSubId(request.subId);
2522 }
2523 }
2524
2525 private Phone getPhoneFromSubId(int subId) {
2526 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2527 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002528 }
2529
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002530 /**
2531 * Get phone object associated with a subscription.
2532 * Return default phone if phone object associated with subscription is null
2533 * @param subId - subscriptionId
2534 * @return phone object associated with a subscription or default phone if null.
2535 */
Ling Mac28f0212023-03-24 16:07:15 -07002536 private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) {
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002537 Phone phone = getPhoneFromSubId(subId);
2538 if (phone == null) {
Ling Mac28f0212023-03-24 16:07:15 -07002539 loge("Called with invalid subId: " + subId + ". Retrying with default phone.");
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002540 phone = getDefaultPhone();
2541 }
2542 return phone;
2543 }
2544
Rambo Wange53e07d2022-05-10 13:01:13 -07002545 @Nullable
2546 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002547 Phone phone = getPhoneFromRequest(request);
2548 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002549 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002550 }
2551
Ling Mac28f0212023-03-24 16:07:15 -07002552 /**
2553 * @param subId The sub Id that associates the phone. If the device has no active SIM, passing
2554 * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <=
2555 * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}.
2556 * @return The Phone associated the sub Id
2557 */
2558 private @Nullable Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002559 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002560 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002561
Kai Shif70f46f2021-03-03 13:59:46 -08002562 private void sendEraseModemConfig(@NonNull Phone phone) {
2563 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2564 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2565 }
2566
2567 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2568 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2569 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002570 }
2571
Peter Wang44b186e2020-01-13 23:33:09 -08002572 private boolean isImsAvailableOnDevice() {
2573 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2574 if (pm == null) {
2575 // For some reason package manger is not available.. This will fail internally anyway,
2576 // so do not throw error and allow.
2577 return true;
2578 }
2579 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2580 }
2581
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002582 public void dial(String number) {
joonhunshin4ac60942023-11-15 15:23:39 +00002583 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2584 PackageManager.FEATURE_TELEPHONY_CALLING, "dial");
2585
Wink Savilleadd7cc52014-09-08 14:23:09 -07002586 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002587 }
2588
Wink Savilleb564aae2014-10-23 10:18:09 -07002589 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002590 if (DBG) log("dial: " + number);
2591 // No permission check needed here: This is just a wrapper around the
2592 // ACTION_DIAL intent, which is available to any app since it puts up
2593 // the UI before it does anything.
2594
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002595 final long identity = Binder.clearCallingIdentity();
2596 try {
2597 String url = createTelUrl(number);
2598 if (url == null) {
2599 return;
2600 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002601
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002602 // PENDING: should we just silently fail if phone is offhook or ringing?
2603 PhoneConstants.State state = mCM.getState(subId);
2604 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2605 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2606 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2607 mApp.startActivity(intent);
2608 }
2609 } finally {
2610 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002611 }
2612 }
2613
2614 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002615 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002616 }
2617
Wink Savilleb564aae2014-10-23 10:18:09 -07002618 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002619 if (DBG) log("call: " + number);
2620
2621 // This is just a wrapper around the ACTION_CALL intent, but we still
2622 // need to do a permission check since we're calling startActivity()
2623 // from the context of the phone app.
2624 enforceCallPermission();
2625
Jordan Liu1617b712019-07-10 15:06:26 -07002626 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002627 != AppOpsManager.MODE_ALLOWED) {
2628 return;
2629 }
2630
joonhunshin4ac60942023-11-15 15:23:39 +00002631 enforceTelephonyFeatureWithException(callingPackage,
2632 PackageManager.FEATURE_TELEPHONY_CALLING, "call");
2633
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002634 final long identity = Binder.clearCallingIdentity();
2635 try {
2636 String url = createTelUrl(number);
2637 if (url == null) {
2638 return;
2639 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002640
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002641 boolean isValid = false;
2642 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2643 if (slist != null) {
2644 for (SubscriptionInfo subInfoRecord : slist) {
2645 if (subInfoRecord.getSubscriptionId() == subId) {
2646 isValid = true;
2647 break;
2648 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002649 }
Wink Saville08874612014-08-31 19:19:58 -07002650 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002651 if (!isValid) {
2652 return;
2653 }
Wink Saville08874612014-08-31 19:19:58 -07002654
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002655 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2656 intent.putExtra(SUBSCRIPTION_KEY, subId);
2657 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2658 mApp.startActivity(intent);
2659 } finally {
2660 Binder.restoreCallingIdentity(identity);
2661 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002662 }
2663
Wink Savilleb564aae2014-10-23 10:18:09 -07002664 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002665 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002666 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2667 }
2668
Wink Savilleb564aae2014-10-23 10:18:09 -07002669 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002670 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002671 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2672 }
2673
Wink Savilleb564aae2014-10-23 10:18:09 -07002674 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002675 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002676
joonhunshin4ac60942023-11-15 15:23:39 +00002677 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2678 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
2679 "supplyPinReportResultForSubscriber");
2680
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002681 final long identity = Binder.clearCallingIdentity();
2682 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002683 Phone phone = getPhone(subId);
2684 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002685 checkSimPin.start();
2686 return checkSimPin.unlockSim(null, pin);
2687 } finally {
2688 Binder.restoreCallingIdentity(identity);
2689 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002690 }
2691
Wink Savilleb564aae2014-10-23 10:18:09 -07002692 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002693 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002694
joonhunshin4ac60942023-11-15 15:23:39 +00002695 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2696 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "supplyPukForSubscriber");
2697
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002698 final long identity = Binder.clearCallingIdentity();
2699 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002700 Phone phone = getPhone(subId);
2701 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002702 checkSimPuk.start();
2703 return checkSimPuk.unlockSim(puk, pin);
2704 } finally {
2705 Binder.restoreCallingIdentity(identity);
2706 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002707 }
2708
2709 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002710 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002711 * a synchronous one.
2712 */
2713 private static class UnlockSim extends Thread {
2714
2715 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002716 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002717
2718 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002719 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2720 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002721
2722 // For replies from SimCard interface
2723 private Handler mHandler;
2724
2725 // For async handler to identify request type
2726 private static final int SUPPLY_PIN_COMPLETE = 100;
2727
Michele Berionne5e411512020-11-13 02:36:59 +00002728 UnlockSim(int phoneId, IccCard simCard) {
2729 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002730 mSimCard = simCard;
2731 }
2732
2733 @Override
2734 public void run() {
2735 Looper.prepare();
2736 synchronized (UnlockSim.this) {
2737 mHandler = new Handler() {
2738 @Override
2739 public void handleMessage(Message msg) {
2740 AsyncResult ar = (AsyncResult) msg.obj;
2741 switch (msg.what) {
2742 case SUPPLY_PIN_COMPLETE:
2743 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2744 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002745 mRetryCount = msg.arg1;
2746 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002747 CommandException.Error error = null;
2748 if (ar.exception instanceof CommandException) {
2749 error = ((CommandException) (ar.exception))
2750 .getCommandError();
2751 }
2752 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07002753 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002754 } else if (error == CommandException.Error.ABORTED) {
2755 /* When UiccCardApp dispose, handle message and return
2756 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08002757 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002758 } else {
2759 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2760 }
2761 } else {
2762 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2763 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002764 mDone = true;
2765 UnlockSim.this.notifyAll();
2766 }
2767 break;
2768 }
2769 }
2770 };
2771 UnlockSim.this.notifyAll();
2772 }
2773 Looper.loop();
2774 }
2775
2776 /*
2777 * Use PIN or PUK to unlock SIM card
2778 *
2779 * If PUK is null, unlock SIM card with PIN
2780 *
2781 * If PUK is not null, unlock SIM card with PUK and set PIN code
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302782 *
2783 * Besides, since it is reused in class level, the thread's looper will be stopped to avoid
2784 * its thread leak.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002785 */
Wink Saville9de0f752013-10-22 19:04:03 -07002786 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002787
2788 while (mHandler == null) {
2789 try {
2790 wait();
2791 } catch (InterruptedException e) {
2792 Thread.currentThread().interrupt();
2793 }
2794 }
2795 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2796
2797 if (puk == null) {
2798 mSimCard.supplyPin(pin, callback);
2799 } else {
2800 mSimCard.supplyPuk(puk, pin, callback);
2801 }
2802
2803 while (!mDone) {
2804 try {
2805 Log.d(LOG_TAG, "wait for done");
2806 wait();
2807 } catch (InterruptedException e) {
2808 // Restore the interrupted status
2809 Thread.currentThread().interrupt();
2810 }
2811 }
2812 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002813 int[] resultArray = new int[2];
2814 resultArray[0] = mResult;
2815 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002816
2817 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002818 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002819 }
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302820 // This instance is no longer reused, so quit its thread's looper.
2821 mHandler.getLooper().quitSafely();
Michele Berionne5e411512020-11-13 02:36:59 +00002822
Wink Saville9de0f752013-10-22 19:04:03 -07002823 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002824 }
2825 }
2826
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002827 /**
2828 * This method has been removed due to privacy and stability concerns.
2829 */
2830 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002831 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002832 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2833 return;
Wink Saville36469e72014-06-11 15:17:00 -07002834 }
2835
Nathan Harold1f889d82020-06-04 17:05:26 -07002836 @Override
2837 public void updateServiceLocationWithPackageName(String callingPackage) {
2838 mApp.getSystemService(AppOpsManager.class)
2839 .checkPackage(Binder.getCallingUid(), callingPackage);
2840
Nathan Haroldf096d982020-11-18 17:18:06 -08002841 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002842 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2843 // Callers targeting S have no business invoking this method.
2844 return;
2845 }
2846
2847 LocationAccessPolicy.LocationPermissionResult locationResult =
2848 LocationAccessPolicy.checkLocationPermission(mApp,
2849 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2850 .setCallingPackage(callingPackage)
2851 .setCallingFeatureId(null)
2852 .setCallingPid(Binder.getCallingPid())
2853 .setCallingUid(Binder.getCallingUid())
2854 .setMethod("updateServiceLocation")
2855 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2856 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2857 .build());
2858 // Apps that lack location permission have no business calling this method;
2859 // however, because no permission was declared in the public API, denials must
2860 // all be "soft".
2861 switch (locationResult) {
2862 case DENIED_HARD: /* fall through */
2863 case DENIED_SOFT:
2864 return;
2865 }
2866
2867 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002868 final long identity = Binder.clearCallingIdentity();
2869 try {
Ling Mac28f0212023-03-24 16:07:15 -07002870 getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002871 } finally {
2872 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002873 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002874 }
2875
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002876 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002877 @Override
2878 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002879 return isRadioOnWithFeature(callingPackage, null);
2880 }
2881
2882
2883 @Override
2884 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2885 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2886 callingFeatureId);
2887 }
2888
2889 @Deprecated
2890 @Override
2891 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2892 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002893 }
2894
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002895 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002896 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2897 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002898 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002899 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002900 return false;
2901 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002902
joonhunshin4ac60942023-11-15 15:23:39 +00002903 enforceTelephonyFeatureWithException(callingPackage,
2904 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isRadioOnWithFeature");
2905
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002906 final long identity = Binder.clearCallingIdentity();
2907 try {
2908 return isRadioOnForSubscriber(subId);
2909 } finally {
2910 Binder.restoreCallingIdentity(identity);
2911 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002912 }
2913
2914 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002915 final long identity = Binder.clearCallingIdentity();
2916 try {
2917 final Phone phone = getPhone(subId);
2918 if (phone != null) {
2919 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2920 } else {
2921 return false;
2922 }
2923 } finally {
2924 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002925 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002926 }
2927
2928 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002929 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002930 }
Wink Saville36469e72014-06-11 15:17:00 -07002931
Wink Savilleb564aae2014-10-23 10:18:09 -07002932 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002933 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002934
joonhunshin4ac60942023-11-15 15:23:39 +00002935 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2936 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "toggleRadioOnOffForSubscriber");
2937
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002938 final long identity = Binder.clearCallingIdentity();
2939 try {
2940 final Phone phone = getPhone(subId);
2941 if (phone != null) {
2942 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2943 }
2944 } finally {
2945 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002946 }
Wink Saville36469e72014-06-11 15:17:00 -07002947 }
2948
2949 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002950 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002951 }
2952
Wink Savilleb564aae2014-10-23 10:18:09 -07002953 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002954 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002955
2956 final long identity = Binder.clearCallingIdentity();
2957 try {
2958 final Phone phone = getPhone(subId);
2959 if (phone == null) {
2960 return false;
2961 }
2962 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2963 toggleRadioOnOffForSubscriber(subId);
2964 }
2965 return true;
2966 } finally {
2967 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002968 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002969 }
Wink Saville36469e72014-06-11 15:17:00 -07002970
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002971 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002972 enforceReadPrivilegedPermission("needMobileRadioShutdown");
joonhunshin4ac60942023-11-15 15:23:39 +00002973
2974 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2975 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needMobileRadioShutdown");
2976
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002977 /*
2978 * If any of the Radios are available, it will need to be
2979 * shutdown. So return true if any Radio is available.
2980 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002981 final long identity = Binder.clearCallingIdentity();
2982 try {
2983 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2984 Phone phone = PhoneFactory.getPhone(i);
2985 if (phone != null && phone.isRadioAvailable()) return true;
2986 }
2987 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2988 return false;
2989 } finally {
2990 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002991 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002992 }
2993
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002994 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002995 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002996 enforceModifyPermission();
2997
joonhunshin4ac60942023-11-15 15:23:39 +00002998 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2999 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "shutdownMobileRadios");
3000
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003001 final long identity = Binder.clearCallingIdentity();
3002 try {
3003 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3004 logv("Shutting down Phone " + i);
3005 shutdownRadioUsingPhoneId(i);
3006 }
3007 } finally {
3008 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003009 }
3010 }
3011
3012 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003013 Phone phone = PhoneFactory.getPhone(phoneId);
3014 if (phone != null && phone.isRadioAvailable()) {
3015 phone.shutdownRadio();
3016 }
3017 }
3018
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003019 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07003020 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003021
Ling Ma83dc5ea2023-01-12 15:06:04 -08003022 if (!turnOn) {
3023 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
3024 }
3025
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003026 final long identity = Binder.clearCallingIdentity();
3027 try {
3028 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
3029 if (defaultPhone != null) {
3030 defaultPhone.setRadioPower(turnOn);
3031 return true;
3032 } else {
3033 loge("There's no default phone.");
3034 return false;
3035 }
3036 } finally {
3037 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07003038 }
Wink Saville36469e72014-06-11 15:17:00 -07003039 }
3040
Wink Savilleb564aae2014-10-23 10:18:09 -07003041 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003042 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003043
Ling Ma83dc5ea2023-01-12 15:06:04 -08003044 if (!turnOn) {
3045 log("setRadioPowerForSubscriber off: subId=" + subId
3046 + ",callingPackage=" + getCurrentPackageName());
3047 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003048 final long identity = Binder.clearCallingIdentity();
3049 try {
3050 final Phone phone = getPhone(subId);
3051 if (phone != null) {
3052 phone.setRadioPower(turnOn);
3053 return true;
3054 } else {
3055 return false;
3056 }
3057 } finally {
3058 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003059 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003060 }
3061
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003062 /**
3063 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3064 * no reason to power it off. When any of the voters want to power it off, it will be turned
3065 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3066 * powering it off, and these radio off votes will be cleared.
3067 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3068 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3069 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3070 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3071 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3072 * check its vote.
3073 *
3074 * @param subId The subscription ID.
3075 * @param reason The reason for powering off radio.
3076 * @return true on success and false on failure.
3077 */
3078 public boolean requestRadioPowerOffForReason(int subId,
3079 @TelephonyManager.RadioPowerReason int reason) {
3080 enforceModifyPermission();
3081
joonhunshin4ac60942023-11-15 15:23:39 +00003082 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3083 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestRadioPowerOffForReason");
3084
Ling Ma83dc5ea2023-01-12 15:06:04 -08003085 log("requestRadioPowerOffForReason: subId=" + subId
3086 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003087 final long identity = Binder.clearCallingIdentity();
3088 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003089 boolean result = false;
3090 for (Phone phone : PhoneFactory.getPhones()) {
3091 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003092 phone.setRadioPowerForReason(false, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003093 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003094 if (!result) {
3095 loge("requestRadioPowerOffForReason: no phone exists");
3096 }
3097 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003098 } finally {
3099 Binder.restoreCallingIdentity(identity);
3100 }
3101 }
3102
3103 /**
3104 * Remove the vote on powering off the radio for a reason, as requested by
3105 * {@link requestRadioPowerOffForReason}.
3106 *
3107 * @param subId The subscription ID.
3108 * @param reason The reason for powering off radio.
3109 * @return true on success and false on failure.
3110 */
3111 public boolean clearRadioPowerOffForReason(int subId,
3112 @TelephonyManager.RadioPowerReason int reason) {
3113 enforceModifyPermission();
3114
joonhunshin4ac60942023-11-15 15:23:39 +00003115 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3116 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearRadioPowerOffForReason");
3117
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003118 final long identity = Binder.clearCallingIdentity();
3119 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003120 boolean result = false;
3121 for (Phone phone : PhoneFactory.getPhones()) {
3122 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003123 phone.setRadioPowerForReason(true, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003124 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003125 if (!result) {
3126 loge("clearRadioPowerOffForReason: no phone exists");
3127 }
3128 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003129 } finally {
3130 Binder.restoreCallingIdentity(identity);
3131 }
3132 }
3133
3134 /**
3135 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3136 *
3137 * @param subId The subscription ID.
3138 * @param callingPackage The package making the call.
3139 * @param callingFeatureId The feature in the package.
3140 * @return List of reasons for powering off radio.
3141 */
3142 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3143 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3144
joonhunshin4ac60942023-11-15 15:23:39 +00003145 enforceTelephonyFeatureWithException(callingPackage,
3146 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerOffReasons");
3147
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003148 final long identity = Binder.clearCallingIdentity();
3149 List result = new ArrayList();
3150 try {
3151 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3152 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3153 return result;
3154 }
3155
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003156 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003157 if (phone != null) {
3158 result.addAll(phone.getRadioPowerOffReasons());
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003159 } else {
3160 loge("getRadioPowerOffReasons: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003161 }
3162 } finally {
3163 Binder.restoreCallingIdentity(identity);
3164 }
3165 return result;
3166 }
3167
Wink Saville36469e72014-06-11 15:17:00 -07003168 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003169 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003170 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003171 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003172
joonhunshin4ac60942023-11-15 15:23:39 +00003173 enforceTelephonyFeatureWithException(callingPackage,
3174 PackageManager.FEATURE_TELEPHONY_DATA, "enableDataConnectivity");
3175
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003176 final long identity = Binder.clearCallingIdentity();
3177 try {
Jack Yu285100e2022-12-02 22:48:35 -08003178 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003179 final Phone phone = getPhone(subId);
3180 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003181 phone.getDataSettingsManager().setDataEnabled(
3182 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003183 return true;
3184 } else {
3185 return false;
3186 }
3187 } finally {
3188 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003189 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003190 }
3191
Wink Saville36469e72014-06-11 15:17:00 -07003192 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003193 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003194 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003195 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003196
joonhunshin4ac60942023-11-15 15:23:39 +00003197 enforceTelephonyFeatureWithException(callingPackage,
3198 PackageManager.FEATURE_TELEPHONY_DATA, "disableDataConnectivity");
3199
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003200 final long identity = Binder.clearCallingIdentity();
3201 try {
Jack Yu285100e2022-12-02 22:48:35 -08003202 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003203 final Phone phone = getPhone(subId);
3204 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003205 phone.getDataSettingsManager().setDataEnabled(
3206 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003207 return true;
3208 } else {
3209 return false;
3210 }
3211 } finally {
3212 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003213 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003214 }
3215
Sanket Padawe356d7632015-06-22 14:03:32 -07003216 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003217 public boolean isDataConnectivityPossible(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003218 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3219 PackageManager.FEATURE_TELEPHONY_DATA, "isDataConnectivityPossible");
3220
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003221 final long identity = Binder.clearCallingIdentity();
3222 try {
3223 final Phone phone = getPhone(subId);
3224 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003225 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003226 } else {
3227 return false;
3228 }
3229 } finally {
3230 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003231 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003232 }
3233
3234 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003235 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003236 }
3237
pkanwarae03a6b2016-11-06 20:37:09 -08003238 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003239 enforceCallPermission();
3240
joonhunshin4ac60942023-11-15 15:23:39 +00003241 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3242 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "handleUssdRequest");
3243
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003244 final long identity = Binder.clearCallingIdentity();
3245 try {
3246 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3247 return;
3248 }
3249 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3250 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3251 } finally {
3252 Binder.restoreCallingIdentity(identity);
3253 }
pkanwar32d516d2016-10-14 19:37:38 -07003254 };
3255
Wink Savilleb564aae2014-10-23 10:18:09 -07003256 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003257 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003258
joonhunshin4ac60942023-11-15 15:23:39 +00003259 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3260 PackageManager.FEATURE_TELEPHONY_CALLING, "handlePinMmiForSubscriber");
3261
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003262 final long identity = Binder.clearCallingIdentity();
3263 try {
3264 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3265 return false;
3266 }
3267 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3268 } finally {
3269 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003270 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003271 }
3272
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003273 /**
3274 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3275 * tag on getCallState Binder call.
3276 */
3277 @Deprecated
3278 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003279 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003280 if (CompatChanges.isChangeEnabled(
3281 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3282 Binder.getCallingUid())) {
3283 // Do not allow this API to be called on API version 31+, it should only be
3284 // called on old apps using this Binder call directly.
3285 throw new SecurityException("This method can only be used for applications "
3286 + "targeting API version 30 or less.");
3287 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003288 final long identity = Binder.clearCallingIdentity();
3289 try {
Ling Mac28f0212023-03-24 16:07:15 -07003290 Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription());
3291 return PhoneConstantConversions.convertCallState(phone.getState());
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003292 } finally {
3293 Binder.restoreCallingIdentity(identity);
3294 }
3295 }
3296
3297 @Override
3298 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3299 if (CompatChanges.isChangeEnabled(
3300 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3301 Binder.getCallingUid())) {
3302 // Check READ_PHONE_STATE for API version 31+
3303 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3304 featureId, "getCallStateForSubscription")) {
3305 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3306 + "targeting API level 31+.");
3307 }
3308 }
joonhunshin4ac60942023-11-15 15:23:39 +00003309
3310 enforceTelephonyFeatureWithException(callingPackage,
3311 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallStateForSubscription");
3312
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003313 final long identity = Binder.clearCallingIdentity();
3314 try {
3315 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003316 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3317 PhoneConstantConversions.convertCallState(phone.getState());
3318 } finally {
3319 Binder.restoreCallingIdentity(identity);
3320 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003321 }
3322
Sanket Padawe356d7632015-06-22 14:03:32 -07003323 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003324 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003325 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003326 }
3327
3328 @Override
3329 public int getDataStateForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003330 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3331 PackageManager.FEATURE_TELEPHONY_DATA, "getDataStateForSubId");
3332
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003333 final long identity = Binder.clearCallingIdentity();
3334 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003335 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003336 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003337 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003338 } else {
3339 return PhoneConstantConversions.convertDataState(
3340 PhoneConstants.DataState.DISCONNECTED);
3341 }
3342 } finally {
3343 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003344 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003345 }
3346
Sanket Padawe356d7632015-06-22 14:03:32 -07003347 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003348 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003349 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003350 }
3351
3352 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003353 public @DataActivityType int getDataActivityForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003354 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3355 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivityForSubId");
3356
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003357 final long identity = Binder.clearCallingIdentity();
3358 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003359 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003360 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003361 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003362 } else {
3363 return TelephonyManager.DATA_ACTIVITY_NONE;
3364 }
3365 } finally {
3366 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003367 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003368 }
3369
3370 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003371 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003372 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003373 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003374
3375 LocationAccessPolicy.LocationPermissionResult locationResult =
3376 LocationAccessPolicy.checkLocationPermission(mApp,
3377 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3378 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003379 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003380 .setCallingPid(Binder.getCallingPid())
3381 .setCallingUid(Binder.getCallingUid())
3382 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003383 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003384 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3385 .build());
3386 switch (locationResult) {
3387 case DENIED_HARD:
3388 throw new SecurityException("Not allowed to access cell location");
3389 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003390 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3391 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003392 }
3393
joonhunshin4ac60942023-11-15 15:23:39 +00003394 enforceTelephonyFeatureWithException(callingPackage,
3395 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getCellLocation");
3396
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003397 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003398 final long identity = Binder.clearCallingIdentity();
3399 try {
3400 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003401 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003402 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003403 } finally {
3404 Binder.restoreCallingIdentity(identity);
3405 }
Svetoslav64fad262015-04-14 14:35:21 -07003406 }
3407
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003408 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003409 public String getNetworkCountryIsoForPhone(int phoneId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003410 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3411 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkCountryIsoForPhone");
3412
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003413 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3414 // registered cell info, so return a NULL country instead.
3415 final long identity = Binder.clearCallingIdentity();
3416 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003417 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3418 // Get default phone in this case.
3419 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3420 }
Jack Yu285100e2022-12-02 22:48:35 -08003421 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003422 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003423 if (phone == null) return "";
3424 ServiceStateTracker sst = phone.getServiceStateTracker();
3425 if (sst == null) return "";
3426 LocaleTracker lt = sst.getLocaleTracker();
3427 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003428 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003429 } finally {
3430 Binder.restoreCallingIdentity(identity);
3431 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003432 }
3433
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003434 /**
3435 * This method was removed due to potential issues caused by performing partial
3436 * updates of service state, and lack of a credible use case.
3437 *
3438 * This has the ability to break the telephony implementation by disabling notification of
3439 * changes in device connectivity. DO NOT USE THIS!
3440 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003441 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003442 public void enableLocationUpdates() {
3443 mApp.enforceCallingOrSelfPermission(
3444 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003445 }
3446
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003447 /**
3448 * This method was removed due to potential issues caused by performing partial
3449 * updates of service state, and lack of a credible use case.
3450 *
3451 * This has the ability to break the telephony implementation by disabling notification of
3452 * changes in device connectivity. DO NOT USE THIS!
3453 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003454 @Override
3455 public void disableLocationUpdates() {
3456 mApp.enforceCallingOrSelfPermission(
3457 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003458 }
3459
3460 @Override
3461 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003462 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3463 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003464 try {
3465 mApp.getSystemService(AppOpsManager.class)
3466 .checkPackage(Binder.getCallingUid(), callingPackage);
3467 } catch (SecurityException e) {
3468 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3469 throw e;
3470 }
3471
Nathan Haroldf096d982020-11-18 17:18:06 -08003472 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003473 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3474 throw new SecurityException(
3475 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3476 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003477
Jordan Liu1617b712019-07-10 15:06:26 -07003478 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003479 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3480 return null;
3481 }
Svetoslav64fad262015-04-14 14:35:21 -07003482
joonhunshin4ac60942023-11-15 15:23:39 +00003483 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3484 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNeighboringCellInfo");
3485
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003486 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003487
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003488 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003489 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003490
Nathan Haroldf180aac2018-06-01 18:43:55 -07003491 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3492 for (CellInfo ci : info) {
3493 if (ci instanceof CellInfoGsm) {
3494 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3495 } else if (ci instanceof CellInfoWcdma) {
3496 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3497 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003498 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003499 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003500 }
3501
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003502 private List<CellInfo> getCachedCellInfo() {
3503 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3504 for (Phone phone : PhoneFactory.getPhones()) {
3505 List<CellInfo> info = phone.getAllCellInfo();
3506 if (info != null) cellInfos.addAll(info);
3507 }
3508 return cellInfos;
3509 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003510
3511 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003512 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003513 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003514 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003515
3516 LocationAccessPolicy.LocationPermissionResult locationResult =
3517 LocationAccessPolicy.checkLocationPermission(mApp,
3518 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3519 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003520 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003521 .setCallingPid(Binder.getCallingPid())
3522 .setCallingUid(Binder.getCallingUid())
3523 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003524 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003525 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3526 .build());
3527 switch (locationResult) {
3528 case DENIED_HARD:
3529 throw new SecurityException("Not allowed to access cell info");
3530 case DENIED_SOFT:
3531 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003532 }
3533
Nathan Haroldf096d982020-11-18 17:18:06 -08003534 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003535 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3536 return getCachedCellInfo();
3537 }
3538
joonhunshin4ac60942023-11-15 15:23:39 +00003539 enforceTelephonyFeatureWithException(callingPackage,
3540 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllCellInfo");
3541
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003542 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003543 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003544 final long identity = Binder.clearCallingIdentity();
3545 try {
3546 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3547 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003548 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003549 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003550 if (info != null) cellInfos.addAll(info);
3551 }
3552 return cellInfos;
3553 } finally {
3554 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003555 }
3556 }
3557
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003558 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003559 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3560 String callingFeatureId) {
3561 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3562 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003563 }
3564
3565 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003566 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3567 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003568 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003569 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003570 }
3571
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003572 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3573 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003574 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003575 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003576
3577 LocationAccessPolicy.LocationPermissionResult locationResult =
3578 LocationAccessPolicy.checkLocationPermission(mApp,
3579 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3580 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003581 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003582 .setCallingPid(Binder.getCallingPid())
3583 .setCallingUid(Binder.getCallingUid())
3584 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003585 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3586 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003587 .build());
3588 switch (locationResult) {
3589 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003590 if (TelephonyPermissions
3591 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003592 // Safetynet logging for b/154934934
3593 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3594 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003595 throw new SecurityException("Not allowed to access cell info");
3596 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003597 if (TelephonyPermissions
3598 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003599 // Safetynet logging for b/154934934
3600 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3601 }
Nathan Harold5320c422019-05-09 10:26:08 -07003602 try {
3603 cb.onCellInfo(new ArrayList<CellInfo>());
3604 } catch (RemoteException re) {
3605 // Drop without consequences
3606 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003607 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003608 }
3609
joonhunshin4ac60942023-11-15 15:23:39 +00003610 enforceTelephonyFeatureWithException(callingPackage,
3611 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestCellInfoUpdateInternal");
Nathan Harolda939a962019-05-09 10:13:47 -07003612
3613 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003614 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3615
3616 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3617 }
3618
3619 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003620 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003621 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003622 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003623
3624 final long identity = Binder.clearCallingIdentity();
3625 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003626 Phone phone = getPhone(subId);
3627 if (phone == null) {
3628 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3629 } else {
3630 phone.setCellInfoListRate(rateInMillis, workSource);
3631 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003632 } finally {
3633 Binder.restoreCallingIdentity(identity);
3634 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003635 }
3636
Shishir Agrawala9f32182016-04-12 12:00:16 -07003637 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003638 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003639 Phone phone = PhoneFactory.getPhone(slotIndex);
3640 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003641 return null;
3642 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003643 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003644 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003645 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003646 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003647 return null;
3648 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003649
joonhunshin4ac60942023-11-15 15:23:39 +00003650 enforceTelephonyFeatureWithException(callingPackage,
3651 PackageManager.FEATURE_TELEPHONY_GSM, "getImeiForSlot");
3652
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003653 final long identity = Binder.clearCallingIdentity();
3654 try {
3655 return phone.getImei();
3656 } finally {
3657 Binder.restoreCallingIdentity(identity);
3658 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003659 }
3660
3661 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003662 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3663 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3664 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3665 callingFeatureId, "getPrimaryImei")) {
3666 throw new SecurityException("Caller does not have permission");
3667 }
joonhunshin4ac60942023-11-15 15:23:39 +00003668
3669 enforceTelephonyFeatureWithException(callingPackage,
3670 PackageManager.FEATURE_TELEPHONY_GSM, "getPrimaryImei");
3671
arunvoddud5c6ce02022-12-11 06:03:12 +00003672 final long identity = Binder.clearCallingIdentity();
3673 try {
3674 for (Phone phone : PhoneFactory.getPhones()) {
3675 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3676 return phone.getImei();
3677 }
3678 }
3679 throw new UnsupportedOperationException("Operation not supported");
3680 } finally {
3681 Binder.restoreCallingIdentity(identity);
3682 }
3683 }
3684
3685 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003686 public String getTypeAllocationCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003687 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3688 PackageManager.FEATURE_TELEPHONY_GSM, "getTypeAllocationCodeForSlot");
3689
David Kelly5e06a7f2018-03-12 14:10:59 +00003690 Phone phone = PhoneFactory.getPhone(slotIndex);
3691 String tac = null;
3692 if (phone != null) {
3693 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003694 try {
3695 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3696 } catch (IndexOutOfBoundsException e) {
3697 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3698 return null;
3699 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003700 }
3701 return tac;
3702 }
3703
3704 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003705 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003706 try {
3707 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3708 } catch (SecurityException se) {
3709 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3710 throw new SecurityException("Package " + callingPackage + " does not belong to "
3711 + Binder.getCallingUid());
3712 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003713 Phone phone = PhoneFactory.getPhone(slotIndex);
3714 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003715 return null;
3716 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003717
Jeff Davidson913390f2018-02-23 17:11:49 -08003718 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003719 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003720 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003721 return null;
3722 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003723
joonhunshin4ac60942023-11-15 15:23:39 +00003724 enforceTelephonyFeatureWithException(callingPackage,
3725 PackageManager.FEATURE_TELEPHONY_CDMA, "getMeidForSlot");
3726
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003727 final long identity = Binder.clearCallingIdentity();
3728 try {
3729 return phone.getMeid();
3730 } finally {
3731 Binder.restoreCallingIdentity(identity);
3732 }
Jack Yu2af8d712017-03-15 17:14:14 -07003733 }
3734
3735 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003736 public String getManufacturerCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003737 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3738 PackageManager.FEATURE_TELEPHONY_CDMA, "getManufacturerCodeForSlot");
3739
David Kelly5e06a7f2018-03-12 14:10:59 +00003740 Phone phone = PhoneFactory.getPhone(slotIndex);
3741 String manufacturerCode = null;
3742 if (phone != null) {
3743 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003744 try {
3745 manufacturerCode =
3746 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3747 } catch (IndexOutOfBoundsException e) {
3748 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3749 return null;
3750 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003751 }
3752 return manufacturerCode;
3753 }
3754
3755 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003756 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3757 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003758 Phone phone = PhoneFactory.getPhone(slotIndex);
3759 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003760 return null;
3761 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003762 int subId = phone.getSubId();
3763 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003764 mApp, subId, callingPackage, callingFeatureId,
3765 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003766 return null;
3767 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003768
joonhunshin4ac60942023-11-15 15:23:39 +00003769 enforceTelephonyFeatureWithException(callingPackage,
3770 PackageManager.FEATURE_TELEPHONY, "getDeviceSoftwareVersionForSlot");
3771
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003772 final long identity = Binder.clearCallingIdentity();
3773 try {
3774 return phone.getDeviceSvn();
3775 } finally {
3776 Binder.restoreCallingIdentity(identity);
3777 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003778 }
3779
fionaxu43304da2017-11-27 22:51:16 -08003780 @Override
3781 public int getSubscriptionCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003782 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3783 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierId");
3784
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003785 final long identity = Binder.clearCallingIdentity();
3786 try {
3787 final Phone phone = getPhone(subId);
3788 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3789 } finally {
3790 Binder.restoreCallingIdentity(identity);
3791 }
fionaxu43304da2017-11-27 22:51:16 -08003792 }
3793
3794 @Override
3795 public String getSubscriptionCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003796 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3797 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierName");
3798
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003799 final long identity = Binder.clearCallingIdentity();
3800 try {
3801 final Phone phone = getPhone(subId);
3802 return phone == null ? null : phone.getCarrierName();
3803 } finally {
3804 Binder.restoreCallingIdentity(identity);
3805 }
fionaxu43304da2017-11-27 22:51:16 -08003806 }
3807
calvinpanffe225e2018-11-01 19:43:06 +08003808 @Override
chen xu0026ca62019-03-06 15:28:50 -08003809 public int getSubscriptionSpecificCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003810 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3811 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionSpecificCarrierId");
3812
chen xu25637222018-11-04 17:17:00 -08003813 final long identity = Binder.clearCallingIdentity();
3814 try {
3815 final Phone phone = getPhone(subId);
3816 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003817 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003818 } finally {
3819 Binder.restoreCallingIdentity(identity);
3820 }
3821 }
3822
3823 @Override
chen xu0026ca62019-03-06 15:28:50 -08003824 public String getSubscriptionSpecificCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003825 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3826 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
3827 "getSubscriptionSpecificCarrierName");
3828
chen xu25637222018-11-04 17:17:00 -08003829 final long identity = Binder.clearCallingIdentity();
3830 try {
3831 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003832 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003833 } finally {
3834 Binder.restoreCallingIdentity(identity);
3835 }
3836 }
3837
chen xu651eec72018-11-11 19:03:44 -08003838 @Override
chen xu864e11c2018-12-06 22:10:03 -08003839 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3840 if (!isSubscriptionMccMnc) {
3841 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3842 }
chen xu651eec72018-11-11 19:03:44 -08003843 final Phone phone = PhoneFactory.getPhone(slotIndex);
3844 if (phone == null) {
3845 return TelephonyManager.UNKNOWN_CARRIER_ID;
3846 }
joonhunshin4ac60942023-11-15 15:23:39 +00003847
3848 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3849 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromMccMnc");
3850
chen xu651eec72018-11-11 19:03:44 -08003851 final long identity = Binder.clearCallingIdentity();
3852 try {
3853 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3854 } finally {
3855 Binder.restoreCallingIdentity(identity);
3856 }
3857 }
3858
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003859 //
3860 // Internal helper methods.
3861 //
3862
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003863 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003864 * Make sure the caller is the calling package itself
3865 *
3866 * @throws SecurityException if the caller is not the calling package
3867 */
3868 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3869 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003870 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3871 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003872 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003873 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003874 } catch (PackageManager.NameNotFoundException e) {
3875 // packageUid is -1
3876 }
3877 if (packageUid != callingUid) {
3878 throw new SecurityException(message + ": Package " + callingPackage
3879 + " does not belong to " + callingUid);
3880 }
3881 }
3882
3883 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003884 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3885 *
3886 * @throws SecurityException if the caller does not have the required permission
3887 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003888 @VisibleForTesting
3889 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003890 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3891 }
3892
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003893 /**
arunvoddud7401012022-12-15 16:08:12 +00003894 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003895 *
3896 * @throws SecurityException if the caller does not have the required permission
3897 */
3898 @VisibleForTesting
3899 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003900 enforceReadPermission(null);
3901 }
3902
3903 /**
3904 * Make sure the caller has the READ_PHONE_STATE permissions.
3905 *
3906 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3907 */
3908 @VisibleForTesting
3909 public void enforceReadPermission(String msg) {
3910 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003911 }
3912
Shuo Qian3b6ee772019-11-13 17:43:31 -08003913 private void enforceActiveEmergencySessionPermission() {
3914 mApp.enforceCallingOrSelfPermission(
3915 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3916 }
3917
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003918 /**
3919 * Make sure the caller has the CALL_PHONE permission.
3920 *
3921 * @throws SecurityException if the caller does not have the required permission
3922 */
3923 private void enforceCallPermission() {
3924 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3925 }
3926
paulhu5a773602019-08-23 19:17:33 +08003927 private void enforceSettingsPermission() {
3928 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003929 }
3930
Michele Berionne5e411512020-11-13 02:36:59 +00003931 private void enforceRebootPermission() {
3932 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3933 }
3934
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003935 /**
3936 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3937 * @param message - log message to print.
3938 * @throws SecurityException if the caller does not have the required permission
3939 */
3940 private void enforceSatelliteCommunicationPermission(String message) {
3941 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3942 }
3943
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003944 private String createTelUrl(String number) {
3945 if (TextUtils.isEmpty(number)) {
3946 return null;
3947 }
3948
Jake Hambye994d462014-02-03 13:10:13 -08003949 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003950 }
3951
Ihab Awadf9e92732013-12-05 18:02:52 -08003952 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003953 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003954 }
3955
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003956 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003957 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003958 }
3959
Ihab Awadf9e92732013-12-05 18:02:52 -08003960 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003961 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003962 }
3963
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003964 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003965 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003966 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003967 }
3968
Sanket Padawe356d7632015-06-22 14:03:32 -07003969 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003970 public int getActivePhoneTypeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003971 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3972 PackageManager.FEATURE_TELEPHONY, "getActivePhoneTypeForSlot");
3973
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003974 final long identity = Binder.clearCallingIdentity();
3975 try {
3976 final Phone phone = PhoneFactory.getPhone(slotIndex);
3977 if (phone == null) {
3978 return PhoneConstants.PHONE_TYPE_NONE;
3979 } else {
3980 return phone.getPhoneType();
3981 }
3982 } finally {
3983 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003984 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003985 }
3986
3987 /**
3988 * Returns the CDMA ERI icon index to display
3989 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003990 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003991 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3992 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3993 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003994 }
3995
Sanket Padawe356d7632015-06-22 14:03:32 -07003996 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003997 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3998 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003999 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004000 mApp, subId, callingPackage, callingFeatureId,
4001 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004002 return -1;
4003 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004004
joonhunshin4ac60942023-11-15 15:23:39 +00004005 enforceTelephonyFeatureWithException(callingPackage,
4006 PackageManager.FEATURE_TELEPHONY_CDMA,
4007 "getCdmaEriIconIndexForSubscriber");
4008
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004009 final long identity = Binder.clearCallingIdentity();
4010 try {
4011 final Phone phone = getPhone(subId);
4012 if (phone != null) {
4013 return phone.getCdmaEriIconIndex();
4014 } else {
4015 return -1;
4016 }
4017 } finally {
4018 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004019 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004020 }
4021
4022 /**
4023 * Returns the CDMA ERI icon mode,
4024 * 0 - ON
4025 * 1 - FLASHING
4026 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004027 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004028 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
4029 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
4030 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004031 }
4032
Sanket Padawe356d7632015-06-22 14:03:32 -07004033 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004034 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
4035 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004036 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004037 mApp, subId, callingPackage, callingFeatureId,
4038 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004039 return -1;
4040 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004041
4042 final long identity = Binder.clearCallingIdentity();
4043 try {
4044 final Phone phone = getPhone(subId);
4045 if (phone != null) {
4046 return phone.getCdmaEriIconMode();
4047 } else {
4048 return -1;
4049 }
4050 } finally {
4051 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004052 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004053 }
4054
4055 /**
4056 * Returns the CDMA ERI text,
4057 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004058 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004059 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
4060 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
4061 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004062 }
4063
Sanket Padawe356d7632015-06-22 14:03:32 -07004064 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004065 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
4066 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004067 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004068 mApp, subId, callingPackage, callingFeatureId,
4069 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004070 return null;
4071 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004072
4073 final long identity = Binder.clearCallingIdentity();
4074 try {
4075 final Phone phone = getPhone(subId);
4076 if (phone != null) {
4077 return phone.getCdmaEriText();
4078 } else {
4079 return null;
4080 }
4081 } finally {
4082 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004083 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004084 }
4085
4086 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07004087 * Returns the CDMA MDN.
4088 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004089 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004090 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004091 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4092 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004093
joonhunshin4ac60942023-11-15 15:23:39 +00004094 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4095 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMdn");
4096
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004097 final long identity = Binder.clearCallingIdentity();
4098 try {
4099 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004100 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004101 return phone.getLine1Number();
4102 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004103 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004104 return null;
4105 }
4106 } finally {
4107 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004108 }
4109 }
4110
4111 /**
4112 * Returns the CDMA MIN.
4113 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004114 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004115 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004116 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4117 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004118
joonhunshin4ac60942023-11-15 15:23:39 +00004119 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4120 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMin");
4121
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004122 final long identity = Binder.clearCallingIdentity();
4123 try {
4124 final Phone phone = getPhone(subId);
4125 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
4126 return phone.getCdmaMin();
4127 } else {
4128 return null;
4129 }
4130 } finally {
4131 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004132 }
4133 }
4134
Hall Liud892bec2018-11-30 14:51:45 -08004135 @Override
4136 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
4137 INumberVerificationCallback callback, String callingPackage) {
4138 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
4139 != PERMISSION_GRANTED) {
4140 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
4141 }
4142 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4143
4144 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
4145 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08004146 throw new SecurityException("Calling package must be configured in the device config: "
4147 + "calling package: " + callingPackage
4148 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004149 }
4150
joonhunshin4ac60942023-11-15 15:23:39 +00004151 enforceTelephonyFeatureWithException(callingPackage,
4152 PackageManager.FEATURE_TELEPHONY_CALLING, "requestNumberVerification");
4153
Hall Liud892bec2018-11-30 14:51:45 -08004154 if (range == null) {
4155 throw new NullPointerException("Range must be non-null");
4156 }
4157
4158 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004159 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004160
4161 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4162 }
4163
Junda Liuca05d5d2014-08-14 22:36:34 -07004164 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004165 * Returns true if CDMA provisioning needs to run.
4166 */
4167 public boolean needsOtaServiceProvisioning() {
joonhunshin4ac60942023-11-15 15:23:39 +00004168 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4169 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needsOtaServiceProvisioning");
4170
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004171 final long identity = Binder.clearCallingIdentity();
4172 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004173 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004174 } finally {
4175 Binder.restoreCallingIdentity(identity);
4176 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004177 }
4178
4179 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004180 * Sets the voice mail number of a given subId.
4181 */
4182 @Override
4183 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004184 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4185 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004186
joonhunshin4ac60942023-11-15 15:23:39 +00004187 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4188 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceMailNumber");
4189
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004190 final long identity = Binder.clearCallingIdentity();
4191 try {
4192 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4193 new Pair<String, String>(alphaTag, number), new Integer(subId));
4194 return success;
4195 } finally {
4196 Binder.restoreCallingIdentity(identity);
4197 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004198 }
4199
Ta-wei Yen87c49842016-05-13 21:19:52 -07004200 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004201 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4202 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004203 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4204 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004205 if (!TextUtils.equals(callingPackage, systemDialer)) {
4206 throw new SecurityException("caller must be system dialer");
4207 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004208
joonhunshin4ac60942023-11-15 15:23:39 +00004209 enforceTelephonyFeatureWithException(callingPackage,
4210 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailSettings");
4211
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004212 final long identity = Binder.clearCallingIdentity();
4213 try {
4214 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4215 if (phoneAccountHandle == null) {
4216 return null;
4217 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004218 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004219 } finally {
4220 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004221 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004222 }
4223
4224 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004225 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4226 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004227 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004228 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004229 mApp, subId, callingPackage, callingFeatureId,
4230 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004231 return null;
4232 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004233
joonhunshin4ac60942023-11-15 15:23:39 +00004234 enforceTelephonyFeatureWithException(callingPackage,
4235 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailPackageName");
4236
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004237 final long identity = Binder.clearCallingIdentity();
4238 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004239 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004240 } finally {
4241 Binder.restoreCallingIdentity(identity);
4242 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004243 }
4244
4245 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004246 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4247 VisualVoicemailSmsFilterSettings settings) {
4248 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004249
joonhunshin4ac60942023-11-15 15:23:39 +00004250 enforceTelephonyFeatureWithException(callingPackage,
4251 PackageManager.FEATURE_TELEPHONY_CALLING, "enableVisualVoicemailSmsFilter");
4252
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004253 final long identity = Binder.clearCallingIdentity();
4254 try {
4255 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004256 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004257 } finally {
4258 Binder.restoreCallingIdentity(identity);
4259 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004260 }
4261
4262 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004263 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4264 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004265
joonhunshin4ac60942023-11-15 15:23:39 +00004266 enforceTelephonyFeatureWithException(callingPackage,
4267 PackageManager.FEATURE_TELEPHONY_CALLING, "disableVisualVoicemailSmsFilter");
4268
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004269 final long identity = Binder.clearCallingIdentity();
4270 try {
4271 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004272 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004273 } finally {
4274 Binder.restoreCallingIdentity(identity);
4275 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004276 }
4277
4278 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004279 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4280 String callingPackage, int subId) {
4281 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004282
4283 final long identity = Binder.clearCallingIdentity();
4284 try {
4285 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004286 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004287 } finally {
4288 Binder.restoreCallingIdentity(identity);
4289 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004290 }
4291
4292 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004293 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004294 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004295
4296 final long identity = Binder.clearCallingIdentity();
4297 try {
4298 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004299 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004300 } finally {
4301 Binder.restoreCallingIdentity(identity);
4302 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004303 }
4304
4305 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004306 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4307 String callingAttributionTag, int subId, String number, int port, String text,
4308 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004309 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004310 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004311 enforceSendSmsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00004312
4313 enforceTelephonyFeatureWithException(callingPackage,
4314 PackageManager.FEATURE_TELEPHONY_CALLING, "sendVisualVoicemailSmsForSubscriber");
4315
Amit Mahajandccb3f12019-05-13 13:48:32 -07004316 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004317 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4318 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004319 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004320
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004321 /**
fionaxu0152e512016-11-14 13:36:14 -08004322 * Sets the voice activation state of a given subId.
4323 */
4324 @Override
4325 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004326 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4327 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004328
joonhunshin4ac60942023-11-15 15:23:39 +00004329 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4330 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState");
4331
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004332 final long identity = Binder.clearCallingIdentity();
4333 try {
4334 final Phone phone = getPhone(subId);
4335 if (phone != null) {
4336 phone.setVoiceActivationState(activationState);
4337 } else {
4338 loge("setVoiceActivationState fails with invalid subId: " + subId);
4339 }
4340 } finally {
4341 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004342 }
4343 }
4344
4345 /**
4346 * Sets the data activation state of a given subId.
4347 */
4348 @Override
4349 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004350 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4351 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004352
joonhunshin4ac60942023-11-15 15:23:39 +00004353 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4354 PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState");
4355
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004356 final long identity = Binder.clearCallingIdentity();
4357 try {
4358 final Phone phone = getPhone(subId);
4359 if (phone != null) {
4360 phone.setDataActivationState(activationState);
4361 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004362 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004363 }
4364 } finally {
4365 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004366 }
4367 }
4368
4369 /**
4370 * Returns the voice activation state of a given subId.
4371 */
4372 @Override
4373 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004374 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004375
joonhunshin4ac60942023-11-15 15:23:39 +00004376 enforceTelephonyFeatureWithException(callingPackage,
4377 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState");
4378
fionaxu0152e512016-11-14 13:36:14 -08004379 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004380 final long identity = Binder.clearCallingIdentity();
4381 try {
4382 if (phone != null) {
4383 return phone.getVoiceActivationState();
4384 } else {
4385 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4386 }
4387 } finally {
4388 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004389 }
4390 }
4391
4392 /**
4393 * Returns the data activation state of a given subId.
4394 */
4395 @Override
4396 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004397 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004398
joonhunshin4ac60942023-11-15 15:23:39 +00004399 enforceTelephonyFeatureWithException(callingPackage,
4400 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState");
4401
fionaxu0152e512016-11-14 13:36:14 -08004402 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004403 final long identity = Binder.clearCallingIdentity();
4404 try {
4405 if (phone != null) {
4406 return phone.getDataActivationState();
4407 } else {
4408 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4409 }
4410 } finally {
4411 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004412 }
4413 }
4414
4415 /**
Wink Saville36469e72014-06-11 15:17:00 -07004416 * Returns the unread count of voicemails for a subId
4417 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004418 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004419 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4420 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004421 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004422 mApp, subId, callingPackage, callingFeatureId,
4423 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004424 return 0;
4425 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004426 final long identity = Binder.clearCallingIdentity();
4427 try {
4428 final Phone phone = getPhone(subId);
4429 if (phone != null) {
4430 return phone.getVoiceMessageCount();
4431 } else {
4432 return 0;
4433 }
4434 } finally {
4435 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004436 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004437 }
4438
4439 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004440 * returns true, if the device is in a state where both voice and data
4441 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004442 */
4443 @Override
4444 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00004445 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4446 PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed");
4447
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004448 final long identity = Binder.clearCallingIdentity();
4449 try {
Ling Mac28f0212023-03-24 16:07:15 -07004450 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004451 } finally {
4452 Binder.restoreCallingIdentity(identity);
4453 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004454 }
4455
4456 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004457 * Send the dialer code if called from the current default dialer or the caller has
4458 * carrier privilege.
4459 * @param inputCode The dialer code to send
4460 */
4461 @Override
4462 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004463 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004464 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004465 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4466 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004467 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004468 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004469 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004470 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004471
joonhunshin4ac60942023-11-15 15:23:39 +00004472 enforceTelephonyFeatureWithException(callingPackage,
4473 PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode");
4474
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004475 final long identity = Binder.clearCallingIdentity();
4476 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004477 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004478 } finally {
4479 Binder.restoreCallingIdentity(identity);
4480 }
fionaxu235cc5e2017-03-06 22:25:57 -08004481 }
4482
Pengquan Menga1bb6272018-09-06 09:59:22 -07004483 @Override
4484 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004485 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004486 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4487 mApp, subId, "getNetworkSelectionMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004488
4489 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4490 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode");
4491
shilufc958392020-01-20 11:36:01 -08004492 final long identity = Binder.clearCallingIdentity();
4493 try {
4494 if (!isActiveSubscription(subId)) {
4495 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4496 }
4497 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4498 } finally {
4499 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004500 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004501 }
4502
Brad Ebinger35c841c2018-10-01 10:40:55 -07004503 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004504 public boolean isInEmergencySmsMode() {
4505 enforceReadPrivilegedPermission("isInEmergencySmsMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004506
4507 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4508 PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode");
4509
Brad Ebingerb2b65522019-03-15 13:48:47 -07004510 final long identity = Binder.clearCallingIdentity();
4511 try {
4512 for (Phone phone : PhoneFactory.getPhones()) {
4513 if (phone.isInEmergencySmsMode()) {
4514 return true;
4515 }
4516 }
4517 } finally {
4518 Binder.restoreCallingIdentity(identity);
4519 }
4520 return false;
4521 }
4522
shilu366312e2019-12-17 09:28:10 -08004523 /**
4524 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4525 * @param subId The subscription to use to check the configuration.
4526 * @param c The callback that will be used to send the result.
4527 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004528 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004529 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4530 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004531 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004532 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004533
4534 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4535 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4536 "IMS not available on device.");
4537 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004538 final long token = Binder.clearCallingIdentity();
4539 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004540 int slotId = getSlotIndexOrException(subId);
4541 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004542
4543 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4544 if (controller != null) {
4545 ImsManager imsManager = controller.getImsManager(subId);
4546 if (imsManager != null) {
4547 imsManager.addRegistrationCallbackForSubscription(c, subId);
4548 } else {
4549 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4550 }
4551 } else {
4552 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4553 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004554 } catch (ImsException e) {
4555 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004556 } finally {
4557 Binder.restoreCallingIdentity(token);
4558 }
4559 }
4560
shilu366312e2019-12-17 09:28:10 -08004561 /**
4562 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4563 * @param subId The subscription to use to check the configuration.
4564 * @param c The callback that will be used to send the result.
4565 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004566 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004567 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004568 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004569 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004570 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4571 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4572 }
Meng Wangafbc5852019-09-19 17:37:13 -07004573 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004574
Meng Wangafbc5852019-09-19 17:37:13 -07004575 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004576 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4577 if (controller != null) {
4578 ImsManager imsManager = controller.getImsManager(subId);
4579 if (imsManager != null) {
4580 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4581 } else {
4582 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4583 + "is inactive, ignoring unregister.");
4584 // If the ImsManager is not valid, just return, since the callback
4585 // will already have been removed internally.
4586 }
4587 }
Meng Wangafbc5852019-09-19 17:37:13 -07004588 } finally {
4589 Binder.restoreCallingIdentity(token);
4590 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004591 }
4592
Brad Ebingera34a6c22019-10-22 17:36:18 -07004593 /**
Hidayat Khan99ea48f2023-12-11 04:37:45 +00004594 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4595 * @param subId The subscription to use to check the configuration.
4596 * @param c The callback that will be used to send the result.
4597 */
4598 @Override
4599 public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c)
4600 throws RemoteException {
4601 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4602 mApp, subId, "registerImsEmergencyRegistrationCallback");
4603
4604 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4605 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4606 "IMS not available on device.");
4607 }
4608 final long token = Binder.clearCallingIdentity();
4609 try {
4610 int slotId = getSlotIndexOrException(subId);
4611 verifyImsMmTelConfiguredOrThrow(slotId);
4612
4613 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4614 if (controller != null) {
4615 ImsManager imsManager = controller.getImsManager(subId);
4616 if (imsManager != null) {
4617 imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId);
4618 } else {
4619 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4620 }
4621 } else {
4622 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4623 }
4624 } catch (ImsException e) {
4625 throw new ServiceSpecificException(e.getCode());
4626 } finally {
4627 Binder.restoreCallingIdentity(token);
4628 }
4629 }
4630
4631 /**
4632 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4633 * @param subId The subscription to use to check the configuration.
4634 * @param c The callback that will be used to send the result.
4635 */
4636 @Override
4637 public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) {
4638 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4639 mApp, subId, "unregisterImsEmergencyRegistrationCallback");
4640 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4641 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4642 }
4643 final long token = Binder.clearCallingIdentity();
4644
4645 try {
4646 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4647 if (controller != null) {
4648 ImsManager imsManager = controller.getImsManager(subId);
4649 if (imsManager != null) {
4650 imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId);
4651 } else {
4652 Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId
4653 + "is inactive, ignoring unregister.");
4654 // If the ImsManager is not valid, just return, since the callback
4655 // will already have been removed internally.
4656 }
4657 }
4658 } finally {
4659 Binder.restoreCallingIdentity(token);
4660 }
4661 }
4662
4663 /**
Brad Ebingera34a6c22019-10-22 17:36:18 -07004664 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4665 */
4666 @Override
4667 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4668 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4669 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4670 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4671 "IMS not available on device.");
4672 }
4673 final long token = Binder.clearCallingIdentity();
4674 try {
4675 Phone phone = getPhone(subId);
4676 if (phone == null) {
4677 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4678 + subId + "'");
4679 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4680 }
4681 phone.getImsRegistrationState(regState -> {
4682 try {
4683 consumer.accept((regState == null)
4684 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4685 } catch (RemoteException e) {
4686 // Ignore if the remote process is no longer available to call back.
4687 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4688 }
4689 });
4690 } finally {
4691 Binder.restoreCallingIdentity(token);
4692 }
4693 }
4694
4695 /**
4696 * Get the transport type for the IMS service registration state.
4697 */
4698 @Override
4699 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004700 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004701 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004702 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4703 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4704 "IMS not available on device.");
4705 }
4706 final long token = Binder.clearCallingIdentity();
4707 try {
4708 Phone phone = getPhone(subId);
4709 if (phone == null) {
4710 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4711 + subId + "'");
4712 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4713 }
4714 phone.getImsRegistrationTech(regTech -> {
4715 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4716 int regTechConverted = (regTech == null)
4717 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4718 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4719 regTechConverted);
4720 try {
4721 consumer.accept(regTechConverted);
4722 } catch (RemoteException e) {
4723 // Ignore if the remote process is no longer available to call back.
4724 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4725 }
4726 });
4727 } finally {
4728 Binder.restoreCallingIdentity(token);
4729 }
4730 }
4731
shilu366312e2019-12-17 09:28:10 -08004732 /**
4733 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4734 * @param subId The subscription to use to check the configuration.
4735 * @param c The callback that will be used to send the result.
4736 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004737 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004738 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4739 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004740 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004741 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004742 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4743 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4744 "IMS not available on device.");
4745 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004746 final long token = Binder.clearCallingIdentity();
4747 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004748 int slotId = getSlotIndexOrException(subId);
4749 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004750
4751 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4752 if (controller != null) {
4753 ImsManager imsManager = controller.getImsManager(subId);
4754 if (imsManager != null) {
4755 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4756 } else {
4757 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4758 }
4759 } else {
4760 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4761 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004762 } catch (ImsException e) {
4763 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004764 } finally {
4765 Binder.restoreCallingIdentity(token);
4766 }
4767 }
4768
shilu366312e2019-12-17 09:28:10 -08004769 /**
4770 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4771 * @param subId The subscription to use to check the configuration.
4772 * @param c The callback that will be used to send the result.
4773 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004774 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004775 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004776 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004777 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004778 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4779 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4780 }
Meng Wangafbc5852019-09-19 17:37:13 -07004781
4782 final long token = Binder.clearCallingIdentity();
4783 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004784 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4785 if (controller != null) {
4786 ImsManager imsManager = controller.getImsManager(subId);
4787 if (imsManager != null) {
4788 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4789 } else {
4790 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4791 + " is inactive, ignoring unregister.");
4792 // If the ImsManager is not valid, just return, since the callback
4793 // will already have been removed internally.
4794 }
4795 }
Meng Wangafbc5852019-09-19 17:37:13 -07004796 } finally {
4797 Binder.restoreCallingIdentity(token);
4798 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004799 }
4800
4801 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004802 public boolean isCapable(int subId, int capability, int regTech) {
4803 enforceReadPrivilegedPermission("isCapable");
joonhunshin4ac60942023-11-15 15:23:39 +00004804
4805 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4806 FEATURE_TELEPHONY_IMS, "isCapable");
4807
Brad Ebinger35c841c2018-10-01 10:40:55 -07004808 final long token = Binder.clearCallingIdentity();
4809 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004810 int slotId = getSlotIndexOrException(subId);
4811 verifyImsMmTelConfiguredOrThrow(slotId);
4812 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4813 } catch (com.android.ims.ImsException e) {
4814 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4815 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004816 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004817 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4818 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004819 } finally {
4820 Binder.restoreCallingIdentity(token);
4821 }
4822 }
4823
4824 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004825 public boolean isAvailable(int subId, int capability, int regTech) {
4826 enforceReadPrivilegedPermission("isAvailable");
joonhunshin4ac60942023-11-15 15:23:39 +00004827
4828 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4829 FEATURE_TELEPHONY_IMS, "isAvailable");
4830
Brad Ebinger35c841c2018-10-01 10:40:55 -07004831 final long token = Binder.clearCallingIdentity();
4832 try {
4833 Phone phone = getPhone(subId);
4834 if (phone == null) return false;
4835 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004836 } catch (com.android.ims.ImsException e) {
4837 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4838 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004839 } finally {
4840 Binder.restoreCallingIdentity(token);
4841 }
4842 }
4843
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004844 /**
4845 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4846 * subscription.
4847 * @param subId The subscription to use to check the configuration.
4848 * @param callback The callback that will be used to send the result.
4849 * @param capability The MmTelFeature capability that will be used to send the result.
4850 * @param transportType The transport type of the MmTelFeature capability.
4851 */
4852 @Override
4853 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4854 int transportType) {
4855 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004856 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4857 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4858 "IMS not available on device.");
4859 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004860 final long token = Binder.clearCallingIdentity();
4861 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004862 int slotId = getSlotIndex(subId);
4863 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4864 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4865 + subId + "'");
4866 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4867 }
4868 verifyImsMmTelConfiguredOrThrow(slotId);
4869 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4870 transportType, aBoolean -> {
4871 try {
4872 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4873 } catch (RemoteException e) {
4874 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4875 + "running. Ignore");
4876 }
4877 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004878 } catch (ImsException e) {
4879 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004880 } finally {
4881 Binder.restoreCallingIdentity(token);
4882 }
4883 }
4884
shilu366312e2019-12-17 09:28:10 -08004885 /**
4886 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4887 * @param subId The subscription to use to check the configuration.
4888 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004889 @Override
4890 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004891 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004892 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004893
joonhunshin4ac60942023-11-15 15:23:39 +00004894 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4895 FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled");
4896
Brad Ebinger35c841c2018-10-01 10:40:55 -07004897 final long token = Binder.clearCallingIdentity();
4898 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004899 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004900 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004901 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004902 } catch (ImsException e) {
4903 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004904 } finally {
4905 Binder.restoreCallingIdentity(token);
4906 }
4907 }
4908
4909 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004910 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004911 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004912 "setAdvancedCallingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004913
4914 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4915 FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled");
4916
Brad Ebinger35c841c2018-10-01 10:40:55 -07004917 final long identity = Binder.clearCallingIdentity();
4918 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004919 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004920 // This setting doesn't require an active ImsService connection, so do not verify. The
4921 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004922 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004923 } catch (ImsException e) {
4924 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004925 } finally {
4926 Binder.restoreCallingIdentity(identity);
4927 }
4928 }
4929
shilu366312e2019-12-17 09:28:10 -08004930 /**
4931 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4932 * @param subId The subscription to use to check the configuration.
4933 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004934 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004935 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004936 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004937 mApp, subId, "isVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004938
4939 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4940 FEATURE_TELEPHONY_IMS, "isVtSettingEnabled");
4941
Brad Ebinger35c841c2018-10-01 10:40:55 -07004942 final long identity = Binder.clearCallingIdentity();
4943 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004944 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004945 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004946 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004947 } catch (ImsException e) {
4948 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004949 } finally {
4950 Binder.restoreCallingIdentity(identity);
4951 }
4952 }
4953
4954 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004955 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004956 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004957 "setVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004958
4959 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4960 FEATURE_TELEPHONY_IMS, "setVtSettingEnabled");
4961
Brad Ebinger35c841c2018-10-01 10:40:55 -07004962 final long identity = Binder.clearCallingIdentity();
4963 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004964 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004965 // This setting doesn't require an active ImsService connection, so do not verify. The
4966 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004967 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004968 } catch (ImsException e) {
4969 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004970 } finally {
4971 Binder.restoreCallingIdentity(identity);
4972 }
4973 }
4974
shilu366312e2019-12-17 09:28:10 -08004975 /**
4976 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4977 * @param subId The subscription to use to check the configuration.
4978 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004979 @Override
4980 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004981 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004982 mApp, subId, "isVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004983
4984 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4985 FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled");
4986
Brad Ebinger35c841c2018-10-01 10:40:55 -07004987 final long identity = Binder.clearCallingIdentity();
4988 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004989 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004990 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004991 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004992 } catch (ImsException e) {
4993 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004994 } finally {
4995 Binder.restoreCallingIdentity(identity);
4996 }
4997 }
4998
4999 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005000 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005001 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005002 "setVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005003
5004 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5005 FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled");
5006
Brad Ebinger35c841c2018-10-01 10:40:55 -07005007 final long identity = Binder.clearCallingIdentity();
5008 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005009 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005010 // This setting doesn't require an active ImsService connection, so do not verify. The
5011 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005012 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005013 } catch (ImsException e) {
5014 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005015 } finally {
5016 Binder.restoreCallingIdentity(identity);
5017 }
5018 }
5019
shilu366312e2019-12-17 09:28:10 -08005020 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005021 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
5022 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5023 * @param subId The subscription to use to check the configuration.
5024 */
5025 @Override
5026 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005027 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005028 mApp, subId, "isCrossSimCallingEnabledByUser");
joonhunshin4ac60942023-11-15 15:23:39 +00005029
5030 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5031 FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser");
5032
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005033 final long identity = Binder.clearCallingIdentity();
5034 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005035 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005036 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005037 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005038 } catch (ImsException e) {
5039 throw new ServiceSpecificException(e.getCode());
5040 } finally {
5041 Binder.restoreCallingIdentity(identity);
5042 }
5043 }
5044
5045 /**
5046 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
5047 * Requires MODIFY_PHONE_STATE permission.
5048 * @param subId The subscription to use to check the configuration.
5049 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
5050 * false otherwise
5051 */
5052 @Override
5053 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
5054 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5055 "setCrossSimCallingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005056
5057 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5058 FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled");
5059
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005060 final long identity = Binder.clearCallingIdentity();
5061 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005062 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005063 // This setting doesn't require an active ImsService connection, so do not verify. The
5064 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005065 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005066 } catch (ImsException e) {
5067 throw new ServiceSpecificException(e.getCode());
5068 } finally {
5069 Binder.restoreCallingIdentity(identity);
5070 }
5071 }
5072
5073 /**
shilu366312e2019-12-17 09:28:10 -08005074 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5075 * @param subId The subscription to use to check the configuration.
5076 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005077 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07005078
Brad Ebinger35c841c2018-10-01 10:40:55 -07005079 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005080 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005081 mApp, subId, "isVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005082
5083 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5084 FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled");
5085
Brad Ebinger35c841c2018-10-01 10:40:55 -07005086 final long identity = Binder.clearCallingIdentity();
5087 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005088 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005089 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005090 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005091 } catch (ImsException e) {
5092 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005093 } finally {
5094 Binder.restoreCallingIdentity(identity);
5095 }
5096 }
5097
5098 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005099 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005100 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005101 "setVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005102
5103 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5104 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled");
5105
Brad Ebinger35c841c2018-10-01 10:40:55 -07005106 final long identity = Binder.clearCallingIdentity();
5107 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005108 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005109 // This setting doesn't require an active ImsService connection, so do not verify. The
5110 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005111 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005112 } catch (ImsException e) {
5113 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005114 } finally {
5115 Binder.restoreCallingIdentity(identity);
5116 }
5117 }
5118
5119 @Override
5120 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
5121 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5122 "setVoWiFiNonPersistent");
joonhunshin4ac60942023-11-15 15:23:39 +00005123
5124 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5125 FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent");
5126
Brad Ebinger35c841c2018-10-01 10:40:55 -07005127 final long identity = Binder.clearCallingIdentity();
5128 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005129 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005130 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005131 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005132 } catch (ImsException e) {
5133 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005134 } finally {
5135 Binder.restoreCallingIdentity(identity);
5136 }
5137 }
5138
shilu366312e2019-12-17 09:28:10 -08005139 /**
5140 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5141 * @param subId The subscription to use to check the configuration.
5142 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005143 @Override
5144 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005145 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005146 mApp, subId, "getVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005147
5148 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5149 FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting");
5150
Brad Ebinger35c841c2018-10-01 10:40:55 -07005151 final long identity = Binder.clearCallingIdentity();
5152 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005153 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005154 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005155 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005156 } catch (ImsException e) {
5157 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005158 } finally {
5159 Binder.restoreCallingIdentity(identity);
5160 }
5161 }
5162
5163 @Override
5164 public void setVoWiFiModeSetting(int subId, int mode) {
5165 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5166 "setVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005167
5168 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5169 FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting");
5170
Brad Ebinger35c841c2018-10-01 10:40:55 -07005171 final long identity = Binder.clearCallingIdentity();
5172 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005173 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005174 // This setting doesn't require an active ImsService connection, so do not verify. The
5175 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005176 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005177 } catch (ImsException e) {
5178 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005179 } finally {
5180 Binder.restoreCallingIdentity(identity);
5181 }
5182 }
5183
5184 @Override
5185 public int getVoWiFiRoamingModeSetting(int subId) {
5186 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005187
5188 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5189 FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting");
5190
Brad Ebinger35c841c2018-10-01 10:40:55 -07005191 final long identity = Binder.clearCallingIdentity();
5192 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005193 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005194 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005195 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005196 } catch (ImsException e) {
5197 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005198 } finally {
5199 Binder.restoreCallingIdentity(identity);
5200 }
5201 }
5202
5203 @Override
5204 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
5205 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5206 "setVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005207
5208 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5209 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting");
5210
Brad Ebinger35c841c2018-10-01 10:40:55 -07005211 final long identity = Binder.clearCallingIdentity();
5212 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005213 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005214 // This setting doesn't require an active ImsService connection, so do not verify. The
5215 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005216 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005217 } catch (ImsException e) {
5218 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005219 } finally {
5220 Binder.restoreCallingIdentity(identity);
5221 }
5222 }
5223
5224 @Override
5225 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
5226 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5227 "setRttCapabilityEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005228
5229 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5230 FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting");
5231
Brad Ebinger35c841c2018-10-01 10:40:55 -07005232 final long identity = Binder.clearCallingIdentity();
5233 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005234 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005235 // This setting doesn't require an active ImsService connection, so do not verify. The
5236 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005237 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005238 } catch (ImsException e) {
5239 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005240 } finally {
5241 Binder.restoreCallingIdentity(identity);
5242 }
5243 }
5244
shilu366312e2019-12-17 09:28:10 -08005245 /**
5246 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5247 * @param subId The subscription to use to check the configuration.
5248 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005249 @Override
5250 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005251 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005252 mApp, subId, "isTtyOverVolteEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005253
5254 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5255 FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled");
5256
Brad Ebinger35c841c2018-10-01 10:40:55 -07005257 final long identity = Binder.clearCallingIdentity();
5258 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005259 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005260 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005261 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005262 } catch (ImsException e) {
5263 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005264 } finally {
5265 Binder.restoreCallingIdentity(identity);
5266 }
5267 }
5268
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005269 @Override
5270 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5271 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005272
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005273 final long identity = Binder.clearCallingIdentity();
5274 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005275 if (!isImsAvailableOnDevice()) {
5276 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5277 "IMS not available on device.");
5278 }
5279 int slotId = getSlotIndexOrException(subId);
5280 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005281
5282 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5283 if (controller != null) {
5284 ImsManager imsManager = controller.getImsManager(subId);
5285 if (imsManager != null) {
5286 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5287 } else {
5288 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5289 }
5290 } else {
5291 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5292 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005293 } catch (ImsException e) {
5294 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005295 } finally {
5296 Binder.restoreCallingIdentity(identity);
5297 }
5298 }
5299
5300 @Override
5301 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5302 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005303
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005304 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005305 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5306 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5307 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005308 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005309 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5310 if (controller != null) {
5311 ImsManager imsManager = controller.getImsManager(subId);
5312 if (imsManager != null) {
5313 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5314 } else {
5315 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5316 + " is inactive, ignoring unregister.");
5317 // If the ImsManager is not valid, just return, since the callback will already
5318 // have been removed internally.
5319 }
5320 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005321 } finally {
5322 Binder.restoreCallingIdentity(identity);
5323 }
5324 }
5325
joonhunshincffb7fc2021-11-28 07:32:01 +00005326 @Override
5327 public void registerFeatureProvisioningChangedCallback(int subId,
5328 IFeatureProvisioningCallback callback) {
5329 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5330 mApp, subId, "registerFeatureProvisioningChangedCallback");
5331
5332 final long identity = Binder.clearCallingIdentity();
5333 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5334 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5335 }
5336
joonhunshin91bc1952022-04-29 08:47:15 +00005337 try {
5338 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5339 if (controller == null) {
5340 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5341 "Device does not support IMS");
5342 }
5343 controller.addFeatureProvisioningChangedCallback(subId, callback);
5344 } finally {
5345 Binder.restoreCallingIdentity(identity);
5346 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005347 }
5348
5349 @Override
5350 public void unregisterFeatureProvisioningChangedCallback(int subId,
5351 IFeatureProvisioningCallback callback) {
5352 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5353 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5354
5355 final long identity = Binder.clearCallingIdentity();
5356 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5357 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5358 }
5359
joonhunshin91bc1952022-04-29 08:47:15 +00005360 try {
5361 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5362 if (controller == null) {
5363 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5364 return;
5365 }
5366 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5367 } finally {
5368 Binder.restoreCallingIdentity(identity);
5369 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005370 }
allenwtsu99c623b2020-01-03 18:24:23 +08005371
5372 private void checkModifyPhoneStatePermission(int subId, String message) {
5373 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5374 message);
5375 }
5376
allenwtsu99c623b2020-01-03 18:24:23 +08005377 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005378 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005379 boolean isProvisioned) {
5380 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5381
joonhunshin4ac60942023-11-15 15:23:39 +00005382 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5383 FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability");
5384
allenwtsu99c623b2020-01-03 18:24:23 +08005385 final long identity = Binder.clearCallingIdentity();
5386 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005387 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5388 if (controller == null) {
5389 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5390 return;
5391 }
5392 controller.setRcsProvisioningStatusForCapability(
5393 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005394 } finally {
5395 Binder.restoreCallingIdentity(identity);
5396 }
allenwtsu99c623b2020-01-03 18:24:23 +08005397 }
5398
5399
5400 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005401 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5402 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5403 mApp, subId, "getRcsProvisioningStatusForCapability");
5404
joonhunshin4ac60942023-11-15 15:23:39 +00005405 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5406 FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability");
5407
allenwtsu99c623b2020-01-03 18:24:23 +08005408 final long identity = Binder.clearCallingIdentity();
5409 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005410 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5411 if (controller == null) {
5412 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5413
5414 // device does not support IMS, this method will return true always.
5415 return true;
5416 }
5417 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005418 } finally {
5419 Binder.restoreCallingIdentity(identity);
5420 }
5421 }
5422
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005423 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005424 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5425 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005426 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005427
joonhunshin4ac60942023-11-15 15:23:39 +00005428 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5429 FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability");
5430
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005431 final long identity = Binder.clearCallingIdentity();
5432 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005433 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5434 if (controller == null) {
5435 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5436 return;
5437 }
5438 controller.setImsProvisioningStatusForCapability(
5439 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005440 } finally {
5441 Binder.restoreCallingIdentity(identity);
5442 }
5443 }
5444
5445 @Override
5446 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005447 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5448 mApp, subId, "getProvisioningStatusForCapability");
5449
joonhunshin4ac60942023-11-15 15:23:39 +00005450 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5451 FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability");
5452
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005453 final long identity = Binder.clearCallingIdentity();
5454 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005455 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5456 if (controller == null) {
5457 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005458
joonhunshin91bc1952022-04-29 08:47:15 +00005459 // device does not support IMS, this method will return true always.
5460 return true;
5461 }
5462 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005463 } finally {
5464 Binder.restoreCallingIdentity(identity);
5465 }
5466 }
5467
5468 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005469 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5470 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5471 mApp, subId, "isProvisioningRequiredForCapability");
5472
joonhunshin4ac60942023-11-15 15:23:39 +00005473 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5474 FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability");
5475
joonhunshincffb7fc2021-11-28 07:32:01 +00005476 final long identity = Binder.clearCallingIdentity();
5477 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005478 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5479 if (controller == null) {
5480 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5481
5482 // device does not support IMS, this method will return false
5483 return false;
5484 }
5485 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005486 } finally {
5487 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005488 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005489 }
5490
5491 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005492 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5493 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5494 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005495
joonhunshin4ac60942023-11-15 15:23:39 +00005496 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5497 FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability");
5498
joonhunshincffb7fc2021-11-28 07:32:01 +00005499 final long identity = Binder.clearCallingIdentity();
5500 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005501 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5502 if (controller == null) {
5503 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5504
5505 // device does not support IMS, this method will return false
5506 return false;
5507 }
5508 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005509 } finally {
5510 Binder.restoreCallingIdentity(identity);
5511 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005512 }
5513
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005514 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005515 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005516 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5517 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5518 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005519 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5520 mApp, subId, "getImsProvisioningInt");
5521
joonhunshin4ac60942023-11-15 15:23:39 +00005522 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5523 FEATURE_TELEPHONY_IMS, "getImsProvisioningInt");
5524
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005525 final long identity = Binder.clearCallingIdentity();
5526 try {
5527 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005528 int slotId = getSlotIndex(subId);
5529 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5530 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5531 + subId + "' for key:" + key);
5532 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5533 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005534
joonhunshin91bc1952022-04-29 08:47:15 +00005535 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5536 if (controller == null) {
5537 loge("getImsProvisioningInt: Device does not support IMS");
5538
5539 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5540 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5541 }
5542 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005543 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5544 return retVal;
5545 }
5546
calvinpanb5a34062021-02-08 19:59:36 +08005547 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005548 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005549 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5550 + subId + "' for key:" + key);
5551 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005552 } finally {
5553 Binder.restoreCallingIdentity(identity);
5554 }
5555 }
5556
5557 @Override
5558 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005559 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5560 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5561 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005562 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5563 mApp, subId, "getImsProvisioningString");
5564
joonhunshin4ac60942023-11-15 15:23:39 +00005565 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5566 FEATURE_TELEPHONY_IMS, "getImsProvisioningString");
5567
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005568 final long identity = Binder.clearCallingIdentity();
5569 try {
5570 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005571 int slotId = getSlotIndex(subId);
5572 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5573 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5574 + subId + "' for key:" + key);
5575 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5576 }
calvinpanb5a34062021-02-08 19:59:36 +08005577 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005578 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005579 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5580 + subId + "' for key:" + key);
5581 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005582 } finally {
5583 Binder.restoreCallingIdentity(identity);
5584 }
5585 }
5586
5587 @Override
5588 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005589 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5590 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5591 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005592 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5593 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005594
joonhunshin4ac60942023-11-15 15:23:39 +00005595 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5596 FEATURE_TELEPHONY_IMS, "setImsProvisioningInt");
5597
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005598 final long identity = Binder.clearCallingIdentity();
5599 try {
5600 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005601 int slotId = getSlotIndex(subId);
5602 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5603 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5604 + subId + "' for key:" + key);
5605 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5606 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005607
joonhunshin91bc1952022-04-29 08:47:15 +00005608 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5609 if (controller == null) {
5610 loge("setImsProvisioningInt: Device does not support IMS");
5611
5612 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5613 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5614 }
5615 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005616 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5617 return retVal;
5618 }
5619
calvinpanb5a34062021-02-08 19:59:36 +08005620 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5621 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005622 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005623 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005624 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005625 } finally {
5626 Binder.restoreCallingIdentity(identity);
5627 }
5628 }
5629
5630 @Override
5631 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005632 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5633 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5634 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005635 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5636 "setImsProvisioningString");
joonhunshin4ac60942023-11-15 15:23:39 +00005637
5638 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5639 FEATURE_TELEPHONY_IMS, "setImsProvisioningString");
5640
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005641 final long identity = Binder.clearCallingIdentity();
5642 try {
5643 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005644 int slotId = getSlotIndex(subId);
5645 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5646 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5647 + subId + "' for key:" + key);
5648 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5649 }
calvinpanb5a34062021-02-08 19:59:36 +08005650 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5651 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005652 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005653 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005654 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005655 } finally {
5656 Binder.restoreCallingIdentity(identity);
5657 }
5658 }
5659
Brad Ebinger919631e2021-06-02 17:46:35 -07005660 /**
5661 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5662 * for the given slot ID or no ImsResolver instance has been created.
5663 * @param slotId The slot ID that the IMS service is created for.
5664 * @throws ImsException If there is no ImsService configured for this slot.
5665 */
5666 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5667 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5668 ImsFeature.FEATURE_MMTEL)) {
5669 throw new ImsException("This subscription does not support MMTEL over IMS",
5670 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5671 }
5672 }
5673
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005674 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005675 int slotId = SubscriptionManager.getSlotIndex(subId);
5676 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005677 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5678 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005679 }
5680 return slotId;
5681 }
5682
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005683 private int getSlotIndex(int subId) {
5684 int slotId = SubscriptionManager.getSlotIndex(subId);
5685 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5686 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5687 }
5688 return slotId;
5689 }
5690
Wink Saville36469e72014-06-11 15:17:00 -07005691 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005692 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005693 */
5694 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005695 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5696 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005697 try {
5698 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5699 } catch (SecurityException se) {
5700 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5701 throw new SecurityException("Package " + callingPackage + " does not belong to "
5702 + Binder.getCallingUid());
5703 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005704 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005705 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005706 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005707 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005708 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005709 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005710 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005711 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5712 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005713
joonhunshin4ac60942023-11-15 15:23:39 +00005714 enforceTelephonyFeatureWithException(callingPackage,
5715 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber");
5716
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005717 final long identity = Binder.clearCallingIdentity();
5718 try {
5719 final Phone phone = getPhone(subId);
5720 if (phone != null) {
5721 return phone.getServiceState().getDataNetworkType();
5722 } else {
5723 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5724 }
5725 } finally {
5726 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005727 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005728 }
5729
5730 /**
5731 * Returns the data network type
5732 */
5733 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005734 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005735 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005736 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005737 }
5738
5739 /**
5740 * Returns the data network type for a subId
5741 */
5742 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005743 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5744 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005745 String functionName = "getDataNetworkTypeForSubscriber";
5746 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5747 mApp, functionName)) {
5748 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5749 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5750 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5751 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005752 }
5753
joonhunshin4ac60942023-11-15 15:23:39 +00005754 enforceTelephonyFeatureWithException(callingPackage,
5755 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber");
5756
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005757 final long identity = Binder.clearCallingIdentity();
5758 try {
5759 final Phone phone = getPhone(subId);
5760 if (phone != null) {
5761 return phone.getServiceState().getDataNetworkType();
5762 } else {
5763 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5764 }
5765 } finally {
5766 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005767 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005768 }
5769
5770 /**
Wink Saville36469e72014-06-11 15:17:00 -07005771 * Returns the Voice network type for a subId
5772 */
5773 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005774 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5775 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005776 String functionName = "getVoiceNetworkTypeForSubscriber";
5777 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5778 mApp, functionName)) {
5779 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5780 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5781 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5782 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005783 }
5784
joonhunshin4ac60942023-11-15 15:23:39 +00005785 enforceTelephonyFeatureWithException(callingPackage,
5786 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber");
5787
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005788 final long identity = Binder.clearCallingIdentity();
5789 try {
5790 final Phone phone = getPhone(subId);
5791 if (phone != null) {
5792 return phone.getServiceState().getVoiceNetworkType();
5793 } else {
5794 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5795 }
5796 } finally {
5797 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005798 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005799 }
5800
5801 /**
5802 * @return true if a ICC card is present
5803 */
5804 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005805 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005806 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005807 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005808 }
5809
5810 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005811 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005812 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005813 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005814 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00005815 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5816 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex");
5817
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005818 final long identity = Binder.clearCallingIdentity();
5819 try {
5820 final Phone phone = PhoneFactory.getPhone(slotIndex);
5821 if (phone != null) {
5822 return phone.getIccCard().hasIccCard();
5823 } else {
5824 return false;
5825 }
5826 } finally {
5827 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005828 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005829 }
5830
5831 /**
5832 * Return if the current radio is LTE on CDMA. This
5833 * is a tri-state return value as for a period of time
5834 * the mode may be unknown.
5835 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005836 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005837 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005838 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005839 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005840 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005841 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5842 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5843 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005844 }
5845
Sanket Padawe356d7632015-06-22 14:03:32 -07005846 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005847 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5848 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005849 try {
5850 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5851 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005852 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5853 }
5854
joonhunshin4ac60942023-11-15 15:23:39 +00005855 enforceTelephonyFeatureWithException(callingPackage,
5856 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber");
5857
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005858 final long identity = Binder.clearCallingIdentity();
5859 try {
5860 final Phone phone = getPhone(subId);
5861 if (phone == null) {
5862 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5863 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005864 return TelephonyProperties.lte_on_cdma_device()
5865 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005866 }
5867 } finally {
5868 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005869 }
Wink Saville36469e72014-06-11 15:17:00 -07005870 }
5871
Wink Saville36469e72014-06-11 15:17:00 -07005872 /**
5873 * {@hide}
5874 * Returns Default subId, 0 in the case of single standby.
5875 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005876 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005877 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005878 }
5879
Shishir Agrawala9f32182016-04-12 12:00:16 -07005880 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005881 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005882 }
5883
Wink Savilleb564aae2014-10-23 10:18:09 -07005884 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005885 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005886 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005887
Pengquan Menge92a50d2018-09-21 15:54:48 -07005888 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005889 return getSubscriptionManagerService().isActiveSubId(subId,
5890 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005891 }
5892
Ihab Awadf2177b72013-11-25 13:33:23 -08005893 /**
5894 * @see android.telephony.TelephonyManager.WifiCallingChoices
5895 */
5896 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005897 final long identity = Binder.clearCallingIdentity();
5898 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005899 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005900 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5901 getWhenToMakeWifiCallsDefaultPreference());
5902 } finally {
5903 Binder.restoreCallingIdentity(identity);
5904 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005905 }
5906
5907 /**
5908 * @see android.telephony.TelephonyManager.WifiCallingChoices
5909 */
5910 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005911 final long identity = Binder.clearCallingIdentity();
5912 try {
5913 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005914 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005915 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5916 } finally {
5917 Binder.restoreCallingIdentity(identity);
5918 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005919 }
5920
Sailesh Nepald1e68152013-12-12 19:08:02 -08005921 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005922 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005923 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005924 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005925
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005926 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5927 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5928 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005929 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005930 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005931 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005932 }
5933 return PhoneFactory.getPhone(phoneId);
5934 }
5935
Shishir Agrawal566b7612013-10-28 14:41:00 -07005936 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005937 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005938 @NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00005939
Rambo Wanga1782702021-11-10 20:15:19 -08005940 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5941 /*message=*/ "iccOpenLogicalChannel");
5942
5943 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5944 // Verify that the callingPackage in the request belongs to the calling UID
5945 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5946
joonhunshin4ac60942023-11-15 15:23:39 +00005947 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5948 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel");
5949
Rambo Wanga1782702021-11-10 20:15:19 -08005950 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005951 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005952
Rambo Wanga1782702021-11-10 20:15:19 -08005953 private Phone getPhoneFromValidIccLogicalChannelRequest(
5954 @NonNull IccLogicalChannelRequest request, String message) {
5955 Phone phone;
5956 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5957 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5958 mApp, request.subId, message);
5959 phone = getPhoneFromSubId(request.subId);
5960 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5961 enforceModifyPermission();
5962 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5963 } else {
5964 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005965 }
Rambo Wanga1782702021-11-10 20:15:19 -08005966 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005967 }
5968
5969 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005970 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005971 final long identity = Binder.clearCallingIdentity();
5972 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005973 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005974 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005975 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5976 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005977 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5978 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005979 loge("The calling package is not allowed to access ISD-R.");
5980 throw new SecurityException(
5981 "The calling package is not allowed to access ISD-R.");
5982 }
Derek Tan740e1672017-06-27 14:56:27 -07005983 }
Derek Tan740e1672017-06-27 14:56:27 -07005984
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005985 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005986 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5987 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005988 return response;
5989 } finally {
5990 Binder.restoreCallingIdentity(identity);
5991 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005992 }
5993
5994 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005995 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00005996 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5997 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel");
5998
Rambo Wanga1782702021-11-10 20:15:19 -08005999 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
6000 /*message=*/"iccCloseLogicalChannel");
6001
6002 if (DBG) log("iccCloseLogicalChannel: request=" + request);
6003
6004 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006005 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006006
Rambo Wanga1782702021-11-10 20:15:19 -08006007 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
6008 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08006009 // before this feature is enabled, this API should only return false if
6010 // the operation fails instead of throwing runtime exception for
6011 // backward-compatibility.
6012 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
6013 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006014 final long identity = Binder.clearCallingIdentity();
6015 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006016 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08006017 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006018 }
Chen Xue9d737e2022-01-01 23:41:31 -08006019 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08006020 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08006021 Boolean success = false;
6022 if (result instanceof RuntimeException) {
6023 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08006024 if (shouldThrowExceptionOnFailure) {
6025 throw (RuntimeException) result;
6026 } else {
6027 return false;
6028 }
Chen Xue9d737e2022-01-01 23:41:31 -08006029 } else if (result instanceof Boolean) {
6030 success = (Boolean) result;
6031 } else {
6032 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
6033 }
Rambo Wanga1782702021-11-10 20:15:19 -08006034 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006035 return success;
6036 } finally {
6037 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006038 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006039 }
6040
6041 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006042 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07006043 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006044 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6045 mApp, subId, "iccTransmitApduLogicalChannel");
joonhunshin4ac60942023-11-15 15:23:39 +00006046
6047 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6048 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel");
6049
Jordan Liu4c733742019-02-28 12:03:40 -08006050 if (DBG) {
6051 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
6052 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
6053 + p3 + " data=" + data);
6054 }
6055 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
6056 command, p1, p2, p3, data);
6057 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006058
Jordan Liu4c733742019-02-28 12:03:40 -08006059 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006060 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006061 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006062 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006063
6064 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6065 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
6066 "iccTransmitApduLogicalChannelBySlot");
6067
Jordan Liu4c733742019-02-28 12:03:40 -08006068 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006069 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006070 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
6071 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006072 }
6073 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006074 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
6075 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006076 }
6077
6078 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
6079 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006080 final long identity = Binder.clearCallingIdentity();
6081 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07006082 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006083 return "";
6084 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006085
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006086 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006087 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
6088 null /* workSource */);
6089 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006090
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006091 // Append the returned status code to the end of the response payload.
6092 String s = Integer.toHexString(
6093 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6094 if (response.payload != null) {
6095 s = IccUtils.bytesToHexString(response.payload) + s;
6096 }
6097 return s;
6098 } finally {
6099 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006100 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006101 }
Jake Hambye994d462014-02-03 13:10:13 -08006102
Evan Charltonc66da362014-05-16 14:06:40 -07006103 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006104 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
6105 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006106 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6107 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006108 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006109
6110 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6111 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel");
6112
Jordan Liu4c733742019-02-28 12:03:40 -08006113 if (DBG) {
6114 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
6115 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
6116 }
6117 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
6118 cla, command, p1, p2, p3, data);
6119 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006120
Jordan Liu4c733742019-02-28 12:03:40 -08006121 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006122 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006123 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006124 enforceModifyPermission();
6125 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006126
6127 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6128 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot");
6129
Jordan Liu4c733742019-02-28 12:03:40 -08006130 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006131 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006132 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
6133 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006134 }
6135
6136 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006137 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
6138 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006139 }
6140
6141 // open APDU basic channel assuming the caller has sufficient permissions
6142 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
6143 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006144 final long identity = Binder.clearCallingIdentity();
6145 try {
6146 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
6147 && TextUtils.equals(ISDR_AID, data)) {
6148 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006149 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6150 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006151 if (bestComponent == null
6152 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
6153 loge("The calling package is not allowed to select ISD-R.");
6154 throw new SecurityException(
6155 "The calling package is not allowed to select ISD-R.");
6156 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006157 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006158
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006159 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006160 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
6161 null /* workSource */);
6162 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006163
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006164 // Append the returned status code to the end of the response payload.
6165 String s = Integer.toHexString(
6166 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6167 if (response.payload != null) {
6168 s = IccUtils.bytesToHexString(response.payload) + s;
6169 }
6170 return s;
6171 } finally {
6172 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006173 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006174 }
6175
6176 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006177 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006178 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006179 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6180 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006181
joonhunshin4ac60942023-11-15 15:23:39 +00006182 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6183 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO");
6184
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006185 final long identity = Binder.clearCallingIdentity();
6186 try {
6187 if (DBG) {
6188 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
6189 + p1 + " " + p2 + " " + p3 + ":" + filePath);
6190 }
6191
6192 IccIoResult response =
6193 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
6194 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
6195 subId);
6196
6197 if (DBG) {
6198 log("Exchange SIM_IO [R]" + response);
6199 }
6200
6201 byte[] result = null;
6202 int length = 2;
6203 if (response.payload != null) {
6204 length = 2 + response.payload.length;
6205 result = new byte[length];
6206 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
6207 } else {
6208 result = new byte[length];
6209 }
6210
6211 result[length - 1] = (byte) response.sw2;
6212 result[length - 2] = (byte) response.sw1;
6213 return result;
6214 } finally {
6215 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006216 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006217 }
6218
Nathan Haroldb3014052017-01-25 15:57:32 -08006219 /**
6220 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
6221 * on a particular subscription
6222 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006223 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
6224 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07006225 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006226 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07006227 return null;
6228 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006229
joonhunshin4ac60942023-11-15 15:23:39 +00006230 enforceTelephonyFeatureWithException(callingPackage,
6231 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns");
6232
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006233 final long identity = Binder.clearCallingIdentity();
6234 try {
6235 if (appType != TelephonyManager.APPTYPE_USIM
6236 && appType != TelephonyManager.APPTYPE_SIM) {
6237 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
6238 return null;
6239 }
6240 Object response = sendRequest(
6241 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
6242 if (response instanceof String[]) {
6243 return (String[]) response;
6244 }
yincheng zhao2737e882019-09-06 17:06:54 -07006245 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006246 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08006247 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006248 } finally {
6249 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08006250 }
Nathan Haroldb3014052017-01-25 15:57:32 -08006251 }
6252
yincheng zhao2737e882019-09-06 17:06:54 -07006253 /**
6254 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
6255 * subscription.
6256 *
6257 * @param subId the id of the subscription.
6258 * @param appType the uicc app type, must be USIM or SIM.
6259 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
6260 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006261 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07006262 * @return number of fplmns that is successfully written to the SIM.
6263 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006264 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
6265 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07006266 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6267 mApp, subId, "setForbiddenPlmns");
6268
joonhunshin4ac60942023-11-15 15:23:39 +00006269 enforceTelephonyFeatureWithException(callingPackage,
6270 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns");
6271
yincheng zhao2737e882019-09-06 17:06:54 -07006272 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
6273 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
6274 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
6275 }
6276 if (fplmns == null) {
6277 throw new IllegalArgumentException("Fplmn List provided is null");
6278 }
6279 for (String fplmn : fplmns) {
6280 if (!CellIdentity.isValidPlmn(fplmn)) {
6281 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
6282 }
6283 }
6284 final long identity = Binder.clearCallingIdentity();
6285 try {
6286 Object response = sendRequest(
6287 CMD_SET_FORBIDDEN_PLMNS,
6288 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
6289 subId);
6290 return (int) response;
6291 } finally {
6292 Binder.restoreCallingIdentity(identity);
6293 }
6294 }
6295
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006296 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006297 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006298 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6299 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07006300
joonhunshin4ac60942023-11-15 15:23:39 +00006301 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6302 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus");
6303
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006304 final long identity = Binder.clearCallingIdentity();
6305 try {
6306 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
6307 if (response.payload == null) {
6308 return "";
6309 }
Evan Charltonc66da362014-05-16 14:06:40 -07006310
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006311 // Append the returned status code to the end of the response payload.
6312 String s = Integer.toHexString(
6313 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6314 s = IccUtils.bytesToHexString(response.payload) + s;
6315 return s;
6316 } finally {
6317 Binder.restoreCallingIdentity(identity);
6318 }
Evan Charltonc66da362014-05-16 14:06:40 -07006319 }
6320
Jake Hambye994d462014-02-03 13:10:13 -08006321 /**
6322 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6323 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6324 *
6325 * @param itemID the ID of the item to read
6326 * @return the NV item as a String, or null on error.
6327 */
6328 @Override
6329 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006330 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006331 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6332 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006333
6334 final long identity = Binder.clearCallingIdentity();
6335 try {
6336 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07006337 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006338 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
6339 return value;
6340 } finally {
6341 Binder.restoreCallingIdentity(identity);
6342 }
Jake Hambye994d462014-02-03 13:10:13 -08006343 }
6344
6345 /**
6346 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6347 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6348 *
6349 * @param itemID the ID of the item to read
6350 * @param itemValue the value to write, as a String
6351 * @return true on success; false on any failure
6352 */
6353 @Override
6354 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006355 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006356 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6357 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006358
6359 final long identity = Binder.clearCallingIdentity();
6360 try {
6361 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6362 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006363 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006364 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6365 return success;
6366 } finally {
6367 Binder.restoreCallingIdentity(identity);
6368 }
Jake Hambye994d462014-02-03 13:10:13 -08006369 }
6370
6371 /**
6372 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6373 * Used for device configuration by some CDMA operators.
6374 *
6375 * @param preferredRoamingList byte array containing the new PRL
6376 * @return true on success; false on any failure
6377 */
6378 @Override
6379 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006380 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6381 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006382
6383 final long identity = Binder.clearCallingIdentity();
6384 try {
6385 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6386 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6387 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6388 return success;
6389 } finally {
6390 Binder.restoreCallingIdentity(identity);
6391 }
Jake Hambye994d462014-02-03 13:10:13 -08006392 }
6393
6394 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006395 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006396 * Used for device configuration by some CDMA operators.
6397 *
chen xu6dac5ab2018-10-26 17:39:23 -07006398 * @param slotIndex - device slot.
6399 *
Jake Hambye994d462014-02-03 13:10:13 -08006400 * @return true on success; false on any failure
6401 */
6402 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006403 public boolean resetModemConfig(int slotIndex) {
6404 Phone phone = PhoneFactory.getPhone(slotIndex);
6405 if (phone != null) {
6406 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6407 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006408
joonhunshin4ac60942023-11-15 15:23:39 +00006409 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6410 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig");
6411
chen xu6dac5ab2018-10-26 17:39:23 -07006412 final long identity = Binder.clearCallingIdentity();
6413 try {
6414 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6415 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6416 return success;
6417 } finally {
6418 Binder.restoreCallingIdentity(identity);
6419 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006420 }
chen xu6dac5ab2018-10-26 17:39:23 -07006421 return false;
6422 }
6423
6424 /**
6425 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6426 *
6427 * @param slotIndex - device slot.
6428 *
6429 * @return true on success; false on any failure
6430 */
6431 @Override
6432 public boolean rebootModem(int slotIndex) {
6433 Phone phone = PhoneFactory.getPhone(slotIndex);
6434 if (phone != null) {
6435 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6436 mApp, phone.getSubId(), "rebootModem");
6437
joonhunshin4ac60942023-11-15 15:23:39 +00006438 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6439 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem");
6440
chen xu6dac5ab2018-10-26 17:39:23 -07006441 final long identity = Binder.clearCallingIdentity();
6442 try {
6443 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6444 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6445 return success;
6446 } finally {
6447 Binder.restoreCallingIdentity(identity);
6448 }
6449 }
6450 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006451 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006452
Brad Ebinger51f743a2017-01-23 13:50:20 -08006453 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006454 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6455 * {@link #disableIms(int)}.
6456 * @param slotIndex device slot.
6457 */
6458 public void resetIms(int slotIndex) {
6459 enforceModifyPermission();
6460
joonhunshin4ac60942023-11-15 15:23:39 +00006461 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6462 PackageManager.FEATURE_TELEPHONY_IMS, "resetIms");
6463
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006464 final long identity = Binder.clearCallingIdentity();
6465 try {
6466 if (mImsResolver == null) {
6467 // may happen if the does not support IMS.
6468 return;
6469 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006470 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006471 } finally {
6472 Binder.restoreCallingIdentity(identity);
6473 }
6474 }
6475
6476 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006477 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6478 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006479 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006480 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006481 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006482
6483 final long identity = Binder.clearCallingIdentity();
6484 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006485 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006486 // may happen if the device does not support IMS.
6487 return;
6488 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006489 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006490 } finally {
6491 Binder.restoreCallingIdentity(identity);
6492 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006493 }
6494
6495 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006496 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6497 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006498 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006499 public void disableIms(int slotId) {
6500 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006501
6502 final long identity = Binder.clearCallingIdentity();
6503 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006504 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006505 // may happen if the device does not support IMS.
6506 return;
6507 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006508 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006509 } finally {
6510 Binder.restoreCallingIdentity(identity);
6511 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006512 }
6513
6514 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006515 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6516 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006517 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006518 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006519 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006520 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006521
6522 final long identity = Binder.clearCallingIdentity();
6523 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006524 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006525 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6526 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006527 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006528 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006529 } finally {
6530 Binder.restoreCallingIdentity(identity);
6531 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006532 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006533 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006534 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6535 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006536 @Override
6537 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006538 enforceModifyPermission();
6539
6540 final long identity = Binder.clearCallingIdentity();
6541 try {
6542 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006543 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006544 } finally {
6545 Binder.restoreCallingIdentity(identity);
6546 }
6547 }
6548
6549 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006550 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006551 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006552 */
6553 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6554 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006555
6556 final long identity = Binder.clearCallingIdentity();
6557 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006558 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006559 // may happen if the device does not support IMS.
6560 return null;
6561 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006562 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006563 } finally {
6564 Binder.restoreCallingIdentity(identity);
6565 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006566 }
6567
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006568 /**
6569 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006570 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006571 */
6572 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6573 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006574
6575 final long identity = Binder.clearCallingIdentity();
6576 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006577 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006578 // may happen if the device does not support IMS.
6579 return null;
6580 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006581 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006582 } finally {
6583 Binder.restoreCallingIdentity(identity);
6584 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006585 }
6586
Brad Ebinger884c07b2018-02-15 16:17:40 -08006587 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006588 * Sets the ImsService Package Name that Telephony will bind to.
6589 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006590 * @param slotIndex the slot ID that the ImsService should bind for.
6591 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006592 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006593 * @param featureTypes An integer array of feature types associated with a packageName.
6594 * @param packageName The name of the package that the current configuration will be replaced
6595 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006596 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006597 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006598 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6599 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006600 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006601 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006602 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006603
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006604 final long identity = Binder.clearCallingIdentity();
6605 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006606 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006607 // may happen if the device does not support IMS.
6608 return false;
6609 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006610 Map<Integer, String> featureConfig = new HashMap<>();
6611 for (int featureType : featureTypes) {
6612 featureConfig.put(featureType, packageName);
6613 }
6614 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6615 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006616 } finally {
6617 Binder.restoreCallingIdentity(identity);
6618 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006619 }
6620
6621 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006622 * Clears any carrier ImsService overrides for the slot index specified that were previously
6623 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6624 *
6625 * This should only be used for testing.
6626 *
6627 * @param slotIndex the slot ID that the ImsService should bind for.
6628 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6629 */
6630 @Override
6631 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006632 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6633 "clearCarrierImsServiceOverride");
6634 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006635 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006636
6637 final long identity = Binder.clearCallingIdentity();
6638 try {
6639 if (mImsResolver == null) {
6640 // may happen if the device does not support IMS.
6641 return false;
6642 }
6643 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6644 } finally {
6645 Binder.restoreCallingIdentity(identity);
6646 }
6647 }
6648
6649 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006650 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006651 *
6652 * @param slotId The slot that the ImsService is associated with.
6653 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6654 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006655 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006656 * @return the package name of the ImsService configuration.
6657 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006658 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6659 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006660 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006661 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6662 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006663
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006664 final long identity = Binder.clearCallingIdentity();
6665 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006666 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006667 // may happen if the device does not support IMS.
6668 return "";
6669 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006670 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006671 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6672 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006673 } finally {
6674 Binder.restoreCallingIdentity(identity);
6675 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006676 }
6677
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006678 /**
6679 * Get the MmTelFeature state associated with the requested subscription id.
6680 * @param subId The subscription that the MmTelFeature is associated with.
6681 * @param callback A callback with an integer containing the
6682 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6683 */
6684 @Override
6685 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6686 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006687 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6688 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6689 "IMS not available on device.");
6690 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006691 final long token = Binder.clearCallingIdentity();
6692 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006693 int slotId = getSlotIndex(subId);
6694 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6695 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6696 + subId + "'");
6697 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6698 }
6699 verifyImsMmTelConfiguredOrThrow(slotId);
6700 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6701 try {
6702 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6703 } catch (RemoteException e) {
6704 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6705 + "Ignore");
6706 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006707 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006708 } catch (ImsException e) {
6709 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006710 } finally {
6711 Binder.restoreCallingIdentity(token);
6712 }
6713 }
6714
Daniel Brightbb5840b2021-01-12 15:48:18 -08006715 /**
6716 * Sets the ims registration state on all valid {@link Phone}s.
6717 */
6718 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006719 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006720
6721 final long identity = Binder.clearCallingIdentity();
6722 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006723 // NOTE: Before S, this method only set the default phone.
6724 for (final Phone phone : PhoneFactory.getPhones()) {
6725 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6726 phone.setImsRegistrationState(registered);
6727 }
6728 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006729 } finally {
6730 Binder.restoreCallingIdentity(identity);
6731 }
Wink Saville36469e72014-06-11 15:17:00 -07006732 }
6733
6734 /**
Stuart Scott54788802015-03-30 13:18:01 -07006735 * Set the network selection mode to automatic.
6736 *
6737 */
6738 @Override
6739 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006740 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6741 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006742
joonhunshin4ac60942023-11-15 15:23:39 +00006743 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6744 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic");
6745
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006746 final long identity = Binder.clearCallingIdentity();
6747 try {
shilufc958392020-01-20 11:36:01 -08006748 if (!isActiveSubscription(subId)) {
6749 return;
6750 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006751 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006752 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6753 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006754 } finally {
6755 Binder.restoreCallingIdentity(identity);
6756 }
Stuart Scott54788802015-03-30 13:18:01 -07006757 }
6758
Jack Yud10cdd42020-09-28 20:28:01 -07006759 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006760 * Ask the radio to connect to the input network and change selection mode to manual.
6761 *
6762 * @param subId the id of the subscription.
6763 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6764 * the operator to attach to.
6765 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6766 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6767 * normal network selection next time.
6768 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006769 */
6770 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006771 public boolean setNetworkSelectionModeManual(
6772 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006773 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6774 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006775
joonhunshin4ac60942023-11-15 15:23:39 +00006776 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6777 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual");
6778
Jack Yu285100e2022-12-02 22:48:35 -08006779 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006780 if (!isActiveSubscription(subId)) {
6781 return false;
6782 }
6783
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006784 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006785 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006786 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006787 if (DBG) {
6788 log("setNetworkSelectionModeManual: subId: " + subId
6789 + " operator: " + operatorInfo);
6790 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006791 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6792 } finally {
6793 Binder.restoreCallingIdentity(identity);
6794 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006795 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006796 /**
shilu84f6e8b2019-12-19 13:58:01 -08006797 * Get the manual network selection
6798 *
6799 * @param subId the id of the subscription.
6800 *
6801 * @return the previously saved user selected PLMN
6802 */
6803 @Override
6804 public String getManualNetworkSelectionPlmn(int subId) {
6805 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006806 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6807 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006808
joonhunshin4ac60942023-11-15 15:23:39 +00006809 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6810 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn");
6811
shilu84f6e8b2019-12-19 13:58:01 -08006812 final long identity = Binder.clearCallingIdentity();
6813 try {
6814 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006815 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006816 }
6817
6818 final Phone phone = getPhone(subId);
6819 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006820 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006821 }
6822 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6823 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006824 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006825 } finally {
6826 Binder.restoreCallingIdentity(identity);
6827 }
6828 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006829
6830 /**
6831 * Scans for available networks.
6832 */
6833 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006834 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6835 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006836 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6837 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006838 LocationAccessPolicy.LocationPermissionResult locationResult =
6839 LocationAccessPolicy.checkLocationPermission(mApp,
6840 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6841 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006842 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006843 .setCallingPid(Binder.getCallingPid())
6844 .setCallingUid(Binder.getCallingUid())
6845 .setMethod("getCellNetworkScanResults")
6846 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006847 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6848 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006849 .build());
6850 switch (locationResult) {
6851 case DENIED_HARD:
6852 throw new SecurityException("Not allowed to access scan results -- location");
6853 case DENIED_SOFT:
6854 return null;
6855 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006856
Pengquan Menga1bb6272018-09-06 09:59:22 -07006857 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006858 try {
6859 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006860 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006861 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006862 } finally {
6863 Binder.restoreCallingIdentity(identity);
6864 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006865 }
6866
6867 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006868 * Get the call forwarding info, given the call forwarding reason.
6869 */
6870 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006871 public void getCallForwarding(int subId, int callForwardingReason,
6872 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006873 enforceReadPrivilegedPermission("getCallForwarding");
joonhunshin4ac60942023-11-15 15:23:39 +00006874
6875 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6876 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding");
6877
Shuo Qian4a594052020-01-23 11:59:30 -08006878 long identity = Binder.clearCallingIdentity();
6879 try {
6880 if (DBG) {
6881 log("getCallForwarding: subId " + subId
6882 + " callForwardingReason" + callForwardingReason);
6883 }
Hall Liu27d24262020-09-18 19:04:59 -07006884
6885 Phone phone = getPhone(subId);
6886 if (phone == null) {
6887 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006888 callback.onError(
6889 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006890 } catch (RemoteException e) {
6891 // ignore
6892 }
6893 return;
6894 }
6895
6896 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6897 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6898 @Override
6899 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6900 try {
6901 callback.onCallForwardingInfoAvailable(info);
6902 } catch (RemoteException e) {
6903 // ignore
6904 }
6905 }
6906
6907 @Override
6908 public void onError(int error) {
6909 try {
6910 callback.onError(error);
6911 } catch (RemoteException e) {
6912 // ignore
6913 }
6914 }
6915 });
6916 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006917 } finally {
6918 Binder.restoreCallingIdentity(identity);
6919 }
6920 }
6921
6922 /**
6923 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6924 * reason, the number to forward, and the timeout before the forwarding is attempted.
6925 */
6926 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006927 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6928 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006929 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006930
6931 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6932 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding");
6933
Shuo Qian4a594052020-01-23 11:59:30 -08006934 long identity = Binder.clearCallingIdentity();
6935 try {
6936 if (DBG) {
6937 log("setCallForwarding: subId " + subId
6938 + " callForwardingInfo" + callForwardingInfo);
6939 }
Hall Liu27d24262020-09-18 19:04:59 -07006940
6941 Phone phone = getPhone(subId);
6942 if (phone == null) {
6943 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006944 callback.accept(
6945 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006946 } catch (RemoteException e) {
6947 // ignore
6948 }
6949 return;
6950 }
6951
6952 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6953 FunctionalUtils.ignoreRemoteException(callback::accept));
6954
6955 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006956 } finally {
6957 Binder.restoreCallingIdentity(identity);
6958 }
6959 }
6960
6961 /**
Hall Liu27d24262020-09-18 19:04:59 -07006962 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006963 */
6964 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006965 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006966 enforceReadPrivilegedPermission("getCallWaitingStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00006967
6968 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6969 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus");
6970
Shuo Qian4a594052020-01-23 11:59:30 -08006971 long identity = Binder.clearCallingIdentity();
6972 try {
Hall Liu27d24262020-09-18 19:04:59 -07006973 Phone phone = getPhone(subId);
6974 if (phone == null) {
6975 try {
6976 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6977 } catch (RemoteException e) {
6978 // ignore
6979 }
6980 return;
6981 }
SongFerngWang0e767992021-03-31 22:08:45 +08006982 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6983 PersistableBundle c = configManager.getConfigForSubId(subId);
6984 boolean requireUssd = c.getBoolean(
6985 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006986
Shuo Qian4a594052020-01-23 11:59:30 -08006987 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006988 if (requireUssd) {
6989 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6990 getSubscriptionCarrierId(subId));
6991 String newUssdCommand = "";
6992 try {
6993 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006994 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006995 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6996 } catch (NullPointerException e) {
6997 loge("Failed to generate USSD number" + e);
6998 }
6999 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7000 mMainThreadHandler, callback, carrierXmlParser,
7001 CarrierXmlParser.SsEntry.SSAction.QUERY);
7002 final String ussdCommand = newUssdCommand;
7003 Executors.newSingleThreadExecutor().execute(() -> {
7004 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7005 });
7006 } else {
7007 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
7008 callback::accept);
7009 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
7010 }
Shuo Qian4a594052020-01-23 11:59:30 -08007011 } finally {
7012 Binder.restoreCallingIdentity(identity);
7013 }
7014 }
7015
7016 /**
Hall Liu27d24262020-09-18 19:04:59 -07007017 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007018 */
7019 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007020 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007021 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007022
7023 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7024 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus");
7025
Shuo Qian4a594052020-01-23 11:59:30 -08007026 long identity = Binder.clearCallingIdentity();
7027 try {
Hall Liu27d24262020-09-18 19:04:59 -07007028 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
7029
7030 Phone phone = getPhone(subId);
7031 if (phone == null) {
7032 try {
7033 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7034 } catch (RemoteException e) {
7035 // ignore
7036 }
7037 return;
7038 }
7039
SongFerngWang0e767992021-03-31 22:08:45 +08007040 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7041 PersistableBundle c = configManager.getConfigForSubId(subId);
7042 boolean requireUssd = c.getBoolean(
7043 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007044
SongFerngWang0e767992021-03-31 22:08:45 +08007045 if (DBG) log("getCallWaitingStatus: subId " + subId);
7046 if (requireUssd) {
7047 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7048 getSubscriptionCarrierId(subId));
7049 CarrierXmlParser.SsEntry.SSAction ssAction =
7050 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
7051 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
7052 String newUssdCommand = "";
7053 try {
7054 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007055 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007056 .makeCommand(ssAction, null);
7057 } catch (NullPointerException e) {
7058 loge("Failed to generate USSD number" + e);
7059 }
7060 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7061 mMainThreadHandler, callback, carrierXmlParser, ssAction);
7062 final String ussdCommand = newUssdCommand;
7063 Executors.newSingleThreadExecutor().execute(() -> {
7064 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7065 });
7066 } else {
7067 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
7068 FunctionalUtils.ignoreRemoteException(callback::accept));
7069
7070 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
7071 }
Shuo Qian4a594052020-01-23 11:59:30 -08007072 } finally {
7073 Binder.restoreCallingIdentity(identity);
7074 }
7075 }
7076
7077 /**
yinxub1bed742017-04-17 11:45:04 -07007078 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07007079 *
yinxub1bed742017-04-17 11:45:04 -07007080 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007081 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
7082 * location related information which will be sent if the caller already possess
7083 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07007084 * @param request contains the radio access networks with bands/channels to scan
7085 * @param messenger callback messenger for scan results or errors
7086 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07007087 * @return the id of the requested scan which can be used to stop the scan.
7088 */
7089 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007090 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
7091 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007092 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007093 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7094 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08007095 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007096 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
7097 if (!renounceFineLocationAccess) {
7098 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007099 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7100 .setCallingPackage(callingPackage)
7101 .setCallingFeatureId(callingFeatureId)
7102 .setCallingPid(Binder.getCallingPid())
7103 .setCallingUid(Binder.getCallingUid())
7104 .setMethod("requestNetworkScan")
7105 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7106 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7107 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7108 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007109 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08007110 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07007111 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
7112 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08007113 if (e != null) {
7114 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
7115 throw e;
7116 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07007117 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08007118 return TelephonyScanManager.INVALID_SCAN_ID;
7119 }
7120 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007121 }
joonhunshin4ac60942023-11-15 15:23:39 +00007122
7123 enforceTelephonyFeatureWithException(callingPackage,
7124 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan");
7125
Hall Liu912dfd32019-04-25 14:02:26 -07007126 int callingUid = Binder.getCallingUid();
7127 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07007128 final long identity = Binder.clearCallingIdentity();
7129 try {
7130 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07007131 renounceFineLocationAccess, request, messenger, binder,
7132 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07007133 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07007134 } finally {
7135 Binder.restoreCallingIdentity(identity);
7136 }
yinxu504e1392017-04-12 16:03:22 -07007137 }
7138
Hall Liub2ac8ef2019-02-28 15:56:23 -08007139 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07007140 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00007141 boolean hasCarrierPriv;
7142 final long identity = Binder.clearCallingIdentity();
7143 try {
7144 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
7145 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
7146 } finally {
7147 Binder.restoreCallingIdentity(identity);
7148 }
Hall Liu558027f2019-05-15 19:14:05 -07007149 boolean hasNetworkScanPermission =
7150 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007151 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07007152
7153 if (!hasCarrierPriv && !hasNetworkScanPermission) {
7154 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
7155 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08007156 }
7157
7158 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
7159 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08007160 if (ras.getChannels() != null && ras.getChannels().length > 0) {
7161 return new SecurityException("Specific channels must not be"
7162 + " scanned without location access.");
7163 }
7164 }
7165 }
7166
Hall Liub2ac8ef2019-02-28 15:56:23 -08007167 return null;
7168 }
7169
yinxu504e1392017-04-12 16:03:22 -07007170 /**
7171 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07007172 *
7173 * @param subId id of the subscription
7174 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07007175 */
7176 @Override
7177 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007178 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7179 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007180
Hall Liu912dfd32019-04-25 14:02:26 -07007181 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007182 final long identity = Binder.clearCallingIdentity();
7183 try {
Hall Liu912dfd32019-04-25 14:02:26 -07007184 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007185 } finally {
7186 Binder.restoreCallingIdentity(identity);
7187 }
yinxu504e1392017-04-12 16:03:22 -07007188 }
7189
7190 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08007191 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07007192 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08007193 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07007194 */
7195 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08007196 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08007197 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007198 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08007199 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007200
joonhunshin4ac60942023-11-15 15:23:39 +00007201 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7202 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask");
7203
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007204 final long identity = Binder.clearCallingIdentity();
7205 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007206 if (DBG) log("getAllowedNetworkTypesBitmask");
7207 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
7208 int networkTypesBitmask = (result != null ? result[0] : -1);
7209 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
7210 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007211 } finally {
7212 Binder.restoreCallingIdentity(identity);
7213 }
Jake Hamby7c27be32014-03-03 13:25:59 -08007214 }
7215
7216 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007217 * Get the allowed network types for certain reason.
7218 *
7219 * @param subId the id of the subscription.
7220 * @param reason the reason the allowed network type change is taking place
7221 * @return the allowed network types.
7222 */
7223 @Override
7224 public long getAllowedNetworkTypesForReason(int subId,
7225 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07007226 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007227 mApp, subId, "getAllowedNetworkTypesForReason");
joonhunshin4ac60942023-11-15 15:23:39 +00007228
7229 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7230 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesForReason");
7231
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007232 final long identity = Binder.clearCallingIdentity();
7233 try {
Jack Yu7247ac82023-03-02 23:52:10 -08007234 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007235 } finally {
7236 Binder.restoreCallingIdentity(identity);
7237 }
7238 }
7239
7240 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07007241 * Enable/Disable E-UTRA-NR Dual Connectivity
7242 * @param subId subscription id of the sim card
7243 * @param nrDualConnectivityState expected NR dual connectivity state
7244 * This can be passed following states
7245 * <ol>
7246 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
7247 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
7248 * <li>Disable NR dual connectivity and force secondary cell to be released
7249 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
7250 * </ol>
7251 * @return operation result.
7252 */
7253 @Override
7254 public int setNrDualConnectivityState(int subId,
7255 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
7256 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7257 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007258 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007259 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7260 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
7261 }
7262
Sooraj Sasindran37444802020-08-11 10:40:43 -07007263 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7264 final long identity = Binder.clearCallingIdentity();
7265 try {
7266 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
7267 nrDualConnectivityState, subId,
7268 workSource);
7269 if (DBG) log("enableNRDualConnectivity result: " + result);
7270 return result;
7271 } finally {
7272 Binder.restoreCallingIdentity(identity);
7273 }
7274 }
7275
7276 /**
7277 * Is E-UTRA-NR Dual Connectivity enabled
7278 * @return true if dual connectivity is enabled else false
7279 */
7280 @Override
7281 public boolean isNrDualConnectivityEnabled(int subId) {
7282 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007283 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07007284 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007285 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007286 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7287 return false;
7288 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07007289 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7290 final long identity = Binder.clearCallingIdentity();
7291 try {
7292 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
7293 null, subId, workSource);
7294 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
7295 return isEnabled;
7296 } finally {
7297 Binder.restoreCallingIdentity(identity);
7298 }
7299 }
7300
7301 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007302 * Set the allowed network types of the device and
7303 * provide the reason triggering the allowed network change.
7304 *
7305 * @param subId the id of the subscription.
7306 * @param reason the reason the allowed network type change is taking place
7307 * @param allowedNetworkTypes the allowed network types.
7308 * @return true on success; false on any failure.
7309 */
7310 @Override
7311 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08007312 @TelephonyManager.AllowedNetworkTypesReason int reason,
7313 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007314 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7315 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007316 // If the caller only has carrier privileges, then they should not be able to override
7317 // any network types which were set for security reasons.
7318 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
7319 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007320 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007321 throw new SecurityException(
7322 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007323 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007324 }
joonhunshin4ac60942023-11-15 15:23:39 +00007325
7326 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7327 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason");
7328
SongFerngWang3ef3e072020-12-21 16:41:52 +08007329 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007330 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08007331 return false;
7332 }
7333 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
7334 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007335 return false;
7336 }
7337
Jack Yu5b494332023-01-23 18:18:04 +00007338 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
7339 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007340
Jack Yue37dd262022-12-16 11:53:37 -08007341 Phone phone = getPhone(subId);
7342 if (phone == null) {
7343 return false;
7344 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007345
Jack Yue37dd262022-12-16 11:53:37 -08007346 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007347 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007348 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08007349 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007350
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007351 final long identity = Binder.clearCallingIdentity();
7352 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007353 Boolean success = (Boolean) sendRequest(
7354 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
7355 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
7356
7357 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
7358 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007359 } finally {
7360 Binder.restoreCallingIdentity(identity);
7361 }
7362 }
7363
7364 /**
Miaoa84611c2019-03-15 09:21:10 +08007365 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08007366 *
Miaoa84611c2019-03-15 09:21:10 +08007367 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07007368 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08007369 * @hide
7370 */
7371 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08007372 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007373 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007374
7375 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7376 PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber");
7377
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007378 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08007379 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007380 try {
Miaoa84611c2019-03-15 09:21:10 +08007381 if (phone != null) {
7382 return phone.hasMatchedTetherApnSetting();
7383 } else {
7384 return false;
7385 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007386 } finally {
7387 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007388 }
Junda Liu475951f2014-11-07 16:45:03 -08007389 }
7390
7391 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007392 * Get the user enabled state of Mobile Data.
7393 *
7394 * TODO: remove and use isUserDataEnabled.
7395 * This can't be removed now because some vendor codes
7396 * calls through ITelephony directly while they should
7397 * use TelephonyManager.
7398 *
7399 * @return true on enabled
7400 */
7401 @Override
7402 public boolean getDataEnabled(int subId) {
7403 return isUserDataEnabled(subId);
7404 }
7405
7406 /**
7407 * Get whether mobile data is enabled per user setting.
7408 *
7409 * There are other factors deciding whether mobile data is actually enabled, but they are
7410 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007411 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007412 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7413 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007414 *
7415 * @return {@code true} if data is enabled else {@code false}
7416 */
7417 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007418 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007419 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007420 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007421 try {
7422 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7423 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007424 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007425 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7426 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007427 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007428 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007429 mApp, subId, functionName);
7430
Robert Greenwalt646120a2014-05-23 11:54:03 -07007431 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007432
7433 final long identity = Binder.clearCallingIdentity();
7434 try {
Jack Yu285100e2022-12-02 22:48:35 -08007435 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007436 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7437 Phone phone = PhoneFactory.getPhone(phoneId);
7438 if (phone != null) {
7439 boolean retVal = phone.isUserDataEnabled();
7440 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7441 return retVal;
7442 } else {
7443 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7444 return false;
7445 }
7446 } finally {
7447 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007448 }
7449 }
7450
7451 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007452 * Checks if the device is capable of mobile data by considering whether whether the
7453 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7454 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007455 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007456 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007457 */
7458 @Override
7459 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007460 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007461 try {
7462 try {
7463 mApp.enforceCallingOrSelfPermission(
7464 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007465 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007466 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007467 try {
7468 mApp.enforceCallingOrSelfPermission(
7469 android.Manifest.permission.READ_PHONE_STATE,
7470 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007471 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007472 mApp.enforceCallingOrSelfPermission(
7473 permission.READ_BASIC_PHONE_STATE, functionName);
7474 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007475 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007476 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007477 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007478 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007479
joonhunshin4ac60942023-11-15 15:23:39 +00007480 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7481 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled");
7482
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007483 final long identity = Binder.clearCallingIdentity();
7484 try {
Jack Yu285100e2022-12-02 22:48:35 -08007485 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007486 Phone phone = PhoneFactory.getPhone(phoneId);
7487 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007488 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007489 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007490 return retVal;
7491 } else {
7492 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7493 return false;
7494 }
7495 } finally {
7496 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007497 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007498 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007499
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007500 /**
7501 * Check if data is enabled for a specific reason
7502 * @param subId Subscription index
7503 * @param reason the reason the data enable change is taking place
7504 * @return {@code true} if the overall data is enabled; {@code false} if not.
7505 */
7506 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007507 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007508 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007509 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007510 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007511 try {
7512 mApp.enforceCallingOrSelfPermission(
7513 android.Manifest.permission.ACCESS_NETWORK_STATE,
7514 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007515 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007516 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7517 functionName);
7518 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007519 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007520 try {
7521 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007522 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007523 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007524 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007525 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007526 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007527 }
7528
joonhunshin4ac60942023-11-15 15:23:39 +00007529 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7530 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007531
7532 final long identity = Binder.clearCallingIdentity();
7533 try {
Jack Yu285100e2022-12-02 22:48:35 -08007534 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007535 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007536 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007537 + " reason=" + reason);
7538 }
7539 Phone phone = PhoneFactory.getPhone(phoneId);
7540 if (phone != null) {
7541 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007542 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007543 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007544 return retVal;
7545 } else {
7546 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007547 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007548 + subId + " retVal=false");
7549 }
7550 return false;
7551 }
7552 } finally {
7553 Binder.restoreCallingIdentity(identity);
7554 }
7555 }
7556
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007557 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007558 public int getCarrierPrivilegeStatus(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00007559 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7560 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus");
7561
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007562 // No permission needed; this only lets the caller inspect their own status.
7563 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007564 }
Junda Liu29340342014-07-10 15:23:27 -07007565
7566 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007567 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007568 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
joonhunshin4ac60942023-11-15 15:23:39 +00007569
7570 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7571 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatusForUid");
7572
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007573 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7574 }
7575
7576 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7577 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007578 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007579 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007580 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7581 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007582 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7583 if (cpt == null) {
7584 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007585 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7586 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007587 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007588 }
7589
7590 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007591 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007592 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
joonhunshin4ac60942023-11-15 15:23:39 +00007593
7594 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7595 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage");
7596
chen xuf7e9fe82019-05-09 19:31:02 -07007597 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007598 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007599 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007600 Phone phone = getPhone(subId);
7601 if (phone == null) {
7602 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7603 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7604 }
7605 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7606 if (cpt == null) {
7607 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007608 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7609 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007610 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007611 }
7612
7613 @Override
7614 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007615 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007616
7617 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7618 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7619 "checkCarrierPrivilegesForPackageAnyPhone");
7620
Rambo Wange7209ce2022-02-23 13:41:02 -08007621 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7622 }
7623
7624 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007625 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007626 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007627 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007628 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007629 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7630 Phone phone = PhoneFactory.getPhone(phoneId);
7631 if (phone == null) {
7632 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007633 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007634 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7635 if (cpt == null) {
7636 continue;
7637 }
7638 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007639 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7640 break;
7641 }
7642 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007643 return result;
Junda Liu29340342014-07-10 15:23:27 -07007644 }
Derek Tan89e89d42014-07-08 17:00:10 -07007645
7646 @Override
Junda Liue64de782015-04-16 17:19:16 -07007647 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007648 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007649
7650 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7651 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7652 "getCarrierPackageNamesForIntentAndPhone");
7653
Rambo Wang8a247eb2022-02-08 21:11:18 +00007654 Phone phone = PhoneFactory.getPhone(phoneId);
7655 if (phone == null) {
7656 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007657 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007658 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7659 if (cpt == null) {
7660 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007661 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007662 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007663 }
7664
Amith Yamasani6e118872016-02-19 12:53:51 -08007665 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007666 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007667 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007668 Phone phone = PhoneFactory.getPhone(phoneId);
7669 if (phone == null) {
7670 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007671 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007672 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7673 if (cpt == null) {
7674 return Collections.emptyList();
7675 }
7676 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007677 }
7678
chen xuf7e9fe82019-05-09 19:31:02 -07007679 @Override
7680 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007681 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
joonhunshin4ac60942023-11-15 15:23:39 +00007682
7683 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7684 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7685 "getPackagesWithCarrierPrivilegesForAllPhones");
7686
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007687 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007688 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007689 try {
7690 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7691 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7692 }
7693 } finally {
7694 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007695 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007696 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007697 }
7698
Rambo Wang6812ffb2022-03-15 16:54:17 -07007699 @Override
7700 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7701 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7702
joonhunshin4ac60942023-11-15 15:23:39 +00007703 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7704 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7705 "getCarrierServicePackageNameForLogicalSlot");
7706
Rambo Wang6812ffb2022-03-15 16:54:17 -07007707 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7708 if (phone == null) {
7709 return null;
7710 }
7711 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7712 if (cpt == null) {
7713 return null;
7714 }
7715 return cpt.getCarrierServicePackageName();
7716 }
7717
Wink Savilleb564aae2014-10-23 10:18:09 -07007718 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007719 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007720 UiccPort port = phone == null ? null : phone.getUiccPort();
7721 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007722 return null;
7723 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007724 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007725 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007726 return null;
7727 }
7728 return iccId;
7729 }
7730
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007731 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007732 public void setCallComposerStatus(int subId, int status) {
7733 enforceModifyPermission();
7734
joonhunshin4ac60942023-11-15 15:23:39 +00007735 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7736 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus");
7737
Shuo Qiane4e11672020-12-15 22:15:33 -08007738 final long identity = Binder.clearCallingIdentity();
7739 try {
7740 Phone phone = getPhone(subId);
7741 if (phone != null) {
7742 Phone defaultPhone = phone.getImsPhone();
7743 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7744 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7745 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007746 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7747 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007748 }
7749 }
Shuo Qian284ae752020-12-22 19:10:14 -08007750 } catch (ImsException e) {
7751 throw new ServiceSpecificException(e.getCode());
7752 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007753 Binder.restoreCallingIdentity(identity);
7754 }
7755 }
7756
7757 @Override
7758 public int getCallComposerStatus(int subId) {
7759 enforceReadPrivilegedPermission("getCallComposerStatus");
7760
joonhunshin4ac60942023-11-15 15:23:39 +00007761 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7762 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus");
7763
Shuo Qiane4e11672020-12-15 22:15:33 -08007764 final long identity = Binder.clearCallingIdentity();
7765 try {
7766 Phone phone = getPhone(subId);
7767 if (phone != null) {
7768 Phone defaultPhone = phone.getImsPhone();
7769 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7770 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7771 return imsPhone.getCallComposerStatus();
7772 }
7773 }
7774 } finally {
7775 Binder.restoreCallingIdentity(identity);
7776 }
7777 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7778 }
7779
7780 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007781 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7782 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007783 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007784 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007785
joonhunshin4ac60942023-11-15 15:23:39 +00007786 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7787 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7788 "setLine1NumberForDisplayForSubscriber");
7789
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007790 final long identity = Binder.clearCallingIdentity();
7791 try {
7792 final String iccId = getIccId(subId);
7793 final Phone phone = getPhone(subId);
7794 if (phone == null) {
7795 return false;
7796 }
7797 final String subscriberId = phone.getSubscriberId();
7798
7799 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007800 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007801 + subscriberId + " to " + number);
7802 }
7803
7804 if (TextUtils.isEmpty(iccId)) {
7805 return false;
7806 }
7807
7808 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7809
7810 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7811 if (alphaTag == null) {
7812 editor.remove(alphaTagPrefKey);
7813 } else {
7814 editor.putString(alphaTagPrefKey, alphaTag);
7815 }
7816
7817 // Record both the line number and IMSI for this ICCID, since we need to
7818 // track all merged IMSIs based on line number
7819 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7820 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7821 if (number == null) {
7822 editor.remove(numberPrefKey);
7823 editor.remove(subscriberPrefKey);
7824 } else {
7825 editor.putString(numberPrefKey, number);
7826 editor.putString(subscriberPrefKey, subscriberId);
7827 }
7828
7829 editor.commit();
7830 return true;
7831 } finally {
7832 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007833 }
Derek Tan7226c842014-07-02 17:42:23 -07007834 }
7835
7836 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007837 public String getLine1NumberForDisplay(int subId, String callingPackage,
7838 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007839 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007840 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007841 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007842 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007843 return null;
7844 }
Derek Tan97ebb422014-09-05 16:55:38 -07007845
joonhunshin4ac60942023-11-15 15:23:39 +00007846 enforceTelephonyFeatureWithException(callingPackage,
7847 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay");
7848
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007849 final long identity = Binder.clearCallingIdentity();
7850 try {
7851 String iccId = getIccId(subId);
7852 if (iccId != null) {
7853 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7854 if (DBG_MERGE) {
7855 log("getLine1NumberForDisplay returning "
7856 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7857 }
7858 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007859 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007860 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7861 return null;
7862 } finally {
7863 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007864 }
Derek Tan7226c842014-07-02 17:42:23 -07007865 }
7866
7867 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007868 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7869 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007870 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007871 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007872 return null;
7873 }
Derek Tan97ebb422014-09-05 16:55:38 -07007874
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007875 final long identity = Binder.clearCallingIdentity();
7876 try {
7877 String iccId = getIccId(subId);
7878 if (iccId != null) {
7879 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7880 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7881 }
7882 return null;
7883 } finally {
7884 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007885 }
Derek Tan7226c842014-07-02 17:42:23 -07007886 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007887
7888 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007889 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7890 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007891 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7892 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007893 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007894 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007895 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007896 return null;
7897 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007898
Jordan Liub49b04b2019-05-06 14:45:15 -07007899 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7900 // the process, where TelephonyManager was instantiated.
7901 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007902 final long identity = Binder.clearCallingIdentity();
7903 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007904 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007905 final TelephonyManager tele = TelephonyManager.from(context);
7906 final SubscriptionManager sub = SubscriptionManager.from(context);
7907
7908 // Figure out what subscribers are currently active
7909 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007910
Jordan Liub49b04b2019-05-06 14:45:15 -07007911 // Only consider subs which match the current subId
7912 // This logic can be simplified. See b/131189269 for progress.
7913 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007914 activeSubscriberIds.add(tele.getSubscriberId(subId));
7915 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007916
7917 // First pass, find a number override for an active subscriber
7918 String mergeNumber = null;
7919 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7920 for (String key : prefs.keySet()) {
7921 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7922 final String subscriberId = (String) prefs.get(key);
7923 if (activeSubscriberIds.contains(subscriberId)) {
7924 final String iccId = key.substring(
7925 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7926 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7927 mergeNumber = (String) prefs.get(numberKey);
7928 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007929 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007930 + " for active subscriber " + subscriberId);
7931 }
7932 if (!TextUtils.isEmpty(mergeNumber)) {
7933 break;
7934 }
7935 }
7936 }
7937 }
7938
7939 // Shortcut when no active merged subscribers
7940 if (TextUtils.isEmpty(mergeNumber)) {
7941 return null;
7942 }
7943
7944 // Second pass, find all subscribers under that line override
7945 final ArraySet<String> result = new ArraySet<>();
7946 for (String key : prefs.keySet()) {
7947 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7948 final String number = (String) prefs.get(key);
7949 if (mergeNumber.equals(number)) {
7950 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7951 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7952 final String subscriberId = (String) prefs.get(subscriberKey);
7953 if (!TextUtils.isEmpty(subscriberId)) {
7954 result.add(subscriberId);
7955 }
7956 }
7957 }
7958 }
7959
7960 final String[] resultArray = result.toArray(new String[result.size()]);
7961 Arrays.sort(resultArray);
7962 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007963 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007964 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7965 }
7966 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007967 } finally {
7968 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007969 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007970 }
7971
7972 @Override
zoey chen38003472019-12-13 17:16:31 +08007973 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7974 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007975
joonhunshin4ac60942023-11-15 15:23:39 +00007976 enforceTelephonyFeatureWithException(callingPackage,
7977 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup");
7978
Malcolm Chen6ca97372019-07-01 16:28:21 -07007979 final long identity = Binder.clearCallingIdentity();
7980 try {
7981 final TelephonyManager telephonyManager = mApp.getSystemService(
7982 TelephonyManager.class);
7983 String subscriberId = telephonyManager.getSubscriberId(subId);
7984 if (subscriberId == null) {
7985 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007986 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007987 + subId);
7988 }
7989 return null;
7990 }
7991
Jack Yu3beaf9d2023-04-14 09:17:27 -07007992 final SubscriptionInfo info = getSubscriptionManagerService()
7993 .getSubscriptionInfo(subId);
7994 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07007995 // If it doesn't belong to any group, return just subscriberId of itself.
7996 if (groupUuid == null) {
7997 return new String[]{subscriberId};
7998 }
7999
8000 // Get all subscriberIds from the group.
8001 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07008002 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
8003 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
8004 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07008005 for (SubscriptionInfo subInfo : groupInfos) {
8006 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
8007 if (subscriberId != null) {
8008 mergedSubscriberIds.add(subscriberId);
8009 }
8010 }
8011
8012 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
8013 } finally {
8014 Binder.restoreCallingIdentity(identity);
8015
8016 }
8017 }
8018
8019 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008020 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008021 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08008022 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008023
joonhunshin4ac60942023-11-15 15:23:39 +00008024 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8025 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride");
8026
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008027 final long identity = Binder.clearCallingIdentity();
8028 try {
8029 final Phone phone = getPhone(subId);
8030 return phone == null ? false : phone.setOperatorBrandOverride(brand);
8031 } finally {
8032 Binder.restoreCallingIdentity(identity);
8033 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07008034 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05008035
8036 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008037 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008038 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
8039 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008040 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
8041 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008042
8043 final long identity = Binder.clearCallingIdentity();
8044 try {
8045 final Phone phone = getPhone(subId);
8046 if (phone == null) {
8047 return false;
8048 }
8049 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
8050 cdmaNonRoamingList);
8051 } finally {
8052 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008053 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008054 }
8055
8056 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07008057 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008058 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08008059 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008060 if (phone == null) {
8061 return raf;
8062 }
8063
Shuo Qiandee53402020-05-29 14:08:15 -07008064 try {
8065 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008066 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07008067 mApp, phone.getSubId(), "getRadioAccessFamily");
8068 } catch (SecurityException e) {
8069 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
8070 throw e;
8071 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008072
joonhunshin4ac60942023-11-15 15:23:39 +00008073 enforceTelephonyFeatureWithException(callingPackage,
8074 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily");
8075
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008076 final long identity = Binder.clearCallingIdentity();
8077 try {
chen xub97461a2018-10-26 14:17:57 -07008078 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008079 } finally {
8080 Binder.restoreCallingIdentity(identity);
8081 }
chen xub97461a2018-10-26 14:17:57 -07008082 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07008083 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008084
8085 @Override
Hall Liu82694d52020-12-11 18:22:04 -08008086 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08008087 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08008088 try {
8089 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
8090 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008091 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008092 }
8093 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008094 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008095 }
joonhunshin4ac60942023-11-15 15:23:39 +00008096
8097 enforceTelephonyFeatureWithException(callingPackage,
8098 PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture");
8099
Hall Liu82694d52020-12-11 18:22:04 -08008100 RoleManager rm = mApp.getSystemService(RoleManager.class);
8101 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
8102 if (!dialerRoleHolders.contains(callingPackage)) {
8103 throw new SecurityException("App must be the dialer role holder to"
8104 + " upload a call composer pic");
8105 }
8106
8107 Executors.newSingleThreadExecutor().execute(() -> {
8108 ByteArrayOutputStream output = new ByteArrayOutputStream(
8109 (int) TelephonyManager.getMaximumCallComposerPictureSize());
8110 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
8111 boolean readUntilEnd = false;
8112 int totalBytesRead = 0;
8113 byte[] buffer = new byte[16 * 1024];
8114 while (true) {
8115 int numRead;
8116 try {
8117 numRead = input.read(buffer);
8118 } catch (IOException e) {
8119 try {
8120 fd.checkError();
8121 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
8122 null);
8123 } catch (IOException e1) {
8124 // This means that the other side closed explicitly with an error. If this
8125 // happens, log and ignore.
8126 loge("Remote end of call composer picture pipe closed: " + e1);
8127 }
8128 break;
8129 }
8130 if (numRead == -1) {
8131 readUntilEnd = true;
8132 break;
8133 }
8134 totalBytesRead += numRead;
8135 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
8136 loge("Too many bytes read for call composer picture: " + totalBytesRead);
8137 try {
8138 input.close();
8139 } catch (IOException e) {
8140 // ignore
8141 }
8142 break;
8143 }
8144 output.write(buffer, 0, numRead);
8145 }
8146 // Generally, the remote end will close the file descriptors. The only case where we
8147 // close is above, where the picture size is too big.
8148
8149 try {
8150 fd.checkError();
8151 } catch (IOException e) {
8152 loge("Remote end for call composer closed with an error: " + e);
8153 return;
8154 }
8155
Hall Liuaa4211e2021-01-20 15:43:39 -08008156 if (!readUntilEnd) {
8157 loge("Did not finish reading entire image; aborting");
8158 return;
8159 }
Hall Liu82694d52020-12-11 18:22:04 -08008160
Hall Liuaa4211e2021-01-20 15:43:39 -08008161 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
8162 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
8163 new CallComposerPictureTransfer.Factory() {},
8164 imageData,
8165 (result) -> {
8166 if (result.first != null) {
8167 ParcelUuid parcelUuid = new ParcelUuid(result.first);
8168 Bundle outputResult = new Bundle();
8169 outputResult.putParcelable(
8170 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
8171 callback.send(TelephonyManager.CallComposerException.SUCCESS,
8172 outputResult);
8173 } else {
8174 callback.send(result.second, null);
8175 }
8176 }
8177 );
Hall Liu82694d52020-12-11 18:22:04 -08008178 });
8179 }
8180
8181 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07008182 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008183 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07008184 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008185
joonhunshin4ac60942023-11-15 15:23:39 +00008186 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8187 PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling");
8188
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008189 final long identity = Binder.clearCallingIdentity();
8190 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008191 ImsManager.getInstance(defaultPhone.getContext(),
8192 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008193 } finally {
8194 Binder.restoreCallingIdentity(identity);
8195 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008196 }
8197
8198 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008199 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008200 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008201 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
8202 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00008203 return false;
8204 }
Svet Ganovb320e182015-04-16 12:30:10 -07008205
joonhunshin4ac60942023-11-15 15:23:39 +00008206 enforceTelephonyFeatureWithException(callingPackage,
8207 PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled");
8208
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008209 final long identity = Binder.clearCallingIdentity();
8210 try {
8211 // Check the user preference and the system-level IMS setting. Even if the user has
8212 // enabled video calling, if IMS is disabled we aren't able to support video calling.
8213 // In the long run, we may instead need to check if there exists a connection service
8214 // which can support video calling.
8215 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008216 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008217 return imsManager.isVtEnabledByPlatform()
8218 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
8219 && imsManager.isVtEnabledByUser();
8220 } finally {
8221 Binder.restoreCallingIdentity(identity);
8222 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008223 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06008224
Andrew Leea1239f22015-03-02 17:44:07 -08008225 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008226 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
8227 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008228 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008229 mApp, subId, callingPackage, callingFeatureId,
8230 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008231 return false;
8232 }
8233
joonhunshin4ac60942023-11-15 15:23:39 +00008234 enforceTelephonyFeatureWithException(callingPackage,
8235 PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength");
8236
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008237 final long identity = Binder.clearCallingIdentity();
8238 try {
8239 CarrierConfigManager configManager =
8240 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008241 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008242 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
8243 } finally {
8244 Binder.restoreCallingIdentity(identity);
8245 }
Andrew Leea1239f22015-03-02 17:44:07 -08008246 }
8247
8248 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008249 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008250 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008251 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008252 return false;
8253 }
8254
joonhunshin4ac60942023-11-15 15:23:39 +00008255 enforceTelephonyFeatureWithException(callingPackage,
8256 PackageManager.FEATURE_TELEPHONY, "isWorldPhone");
8257
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008258 final long identity = Binder.clearCallingIdentity();
8259 try {
8260 CarrierConfigManager configManager =
8261 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008262 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008263 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
8264 } finally {
8265 Binder.restoreCallingIdentity(identity);
8266 }
Andrew Leea1239f22015-03-02 17:44:07 -08008267 }
8268
Andrew Lee9431b832015-03-09 18:46:45 -07008269 @Override
8270 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008271 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08008272 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07008273 }
8274
8275 @Override
8276 public boolean isHearingAidCompatibilitySupported() {
joonhunshin4ac60942023-11-15 15:23:39 +00008277 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8278 PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported");
8279
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008280 final long identity = Binder.clearCallingIdentity();
8281 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008282 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008283 } finally {
8284 Binder.restoreCallingIdentity(identity);
8285 }
Andrew Lee9431b832015-03-09 18:46:45 -07008286 }
8287
Hall Liuf6668912018-10-31 17:05:23 -07008288 /**
8289 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
8290 * support for the feature and device firmware support.
8291 *
8292 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
8293 */
8294 @Override
8295 public boolean isRttSupported(int subscriptionId) {
joonhunshin4ac60942023-11-15 15:23:39 +00008296 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8297 PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported");
8298
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008299 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008300 final Phone phone = getPhone(subscriptionId);
8301 if (phone == null) {
8302 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
8303 return false;
8304 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008305 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008306 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008307 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
joonhunshin4ac60942023-11-15 15:23:39 +00008308 boolean isDeviceSupported = (phone.getContext().getResources() != null)
8309 ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt)
8310 : false;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008311 return isCarrierSupported && isDeviceSupported;
8312 } finally {
8313 Binder.restoreCallingIdentity(identity);
8314 }
Hall Liu98187582018-01-22 19:15:32 -08008315 }
8316
Hall Liuf6668912018-10-31 17:05:23 -07008317 /**
Hall Liuf2daa022019-07-23 18:39:00 -07008318 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
8319 * RTT setting, will return true if the device and carrier both support RTT.
8320 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07008321 */
8322 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008323 final long identity = Binder.clearCallingIdentity();
8324 try {
joonhunshin4ac60942023-11-15 15:23:39 +00008325 if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) {
8326 if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
8327 return false;
8328 }
8329 }
8330
Hall Liu5bab75c2019-12-11 23:58:20 +00008331 boolean isRttSupported = isRttSupported(subscriptionId);
8332 boolean isUserRttSettingOn = Settings.Secure.getInt(
8333 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
8334 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
8335 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
8336 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008337 } finally {
8338 Binder.restoreCallingIdentity(identity);
8339 }
Hall Liu3ad5f012018-04-06 16:23:39 -07008340 }
8341
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008342 @Deprecated
8343 @Override
8344 public String getDeviceId(String callingPackage) {
8345 return getDeviceIdWithFeature(callingPackage, null);
8346 }
8347
Sanket Padawe7310cc72015-01-14 09:53:20 -08008348 /**
8349 * Returns the unique device ID of phone, for example, the IMEI for
8350 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
8351 *
8352 * <p>Requires Permission:
8353 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
8354 */
8355 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008356 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07008357 try {
8358 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
8359 } catch (SecurityException se) {
8360 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
8361 throw new SecurityException("Package " + callingPackage + " does not belong to "
8362 + Binder.getCallingUid());
8363 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008364 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008365 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008366 return null;
8367 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008368 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008369 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008370 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008371 return null;
8372 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008373
8374 final long identity = Binder.clearCallingIdentity();
8375 try {
8376 return phone.getDeviceId();
8377 } finally {
8378 Binder.restoreCallingIdentity(identity);
8379 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008380 }
8381
Ping Sunc67b7c22016-03-02 19:16:45 +08008382 /**
8383 * {@hide}
8384 * Returns the IMS Registration Status on a particular subid
8385 *
8386 * @param subId
8387 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008388 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008389 Phone phone = getPhone(subId);
8390 if (phone != null) {
8391 return phone.isImsRegistered();
8392 } else {
8393 return false;
8394 }
8395 }
8396
Santos Cordon7a1885b2015-02-03 11:15:19 -08008397 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008398 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008399 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008400 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008401 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008402 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8403 }
8404 final long identity = Binder.clearCallingIdentity();
8405 try {
8406 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8407 } finally {
8408 Binder.restoreCallingIdentity(identity);
8409 }
8410 }
8411
8412 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008413 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008414 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008415 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008416 mApp,
8417 subscriptionId,
8418 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
8419 + subscriptionId);
joonhunshin4ac60942023-11-15 15:23:39 +00008420
8421 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8422 PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId");
8423
Tyler Gunnf70ed162019-04-03 15:28:53 -07008424 final long identity = Binder.clearCallingIdentity();
8425 try {
8426 Phone phone = getPhone(subscriptionId);
8427 if (phone == null) {
8428 return null;
8429 }
8430 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8431 } finally {
8432 Binder.restoreCallingIdentity(identity);
8433 }
8434 }
8435
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008436 /**
8437 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008438 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008439 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008440 final long identity = Binder.clearCallingIdentity();
8441 try {
8442 Phone phone = getPhone(subId);
8443 if (phone != null) {
8444 return phone.isWifiCallingEnabled();
8445 } else {
8446 return false;
8447 }
8448 } finally {
8449 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008450 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008451 }
8452
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008453 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008454 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008455 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008456 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008457 final long identity = Binder.clearCallingIdentity();
8458 try {
8459 Phone phone = getPhone(subId);
8460 if (phone != null) {
8461 return phone.isVideoEnabled();
8462 } else {
8463 return false;
8464 }
8465 } finally {
8466 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008467 }
8468 }
8469
8470 /**
8471 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8472 * defined in {@link ImsRegistrationImplBase}.
8473 */
8474 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008475 final long identity = Binder.clearCallingIdentity();
8476 try {
8477 Phone phone = getPhone(subId);
8478 if (phone != null) {
8479 return phone.getImsRegistrationTech();
8480 } else {
8481 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8482 }
8483 } finally {
8484 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008485 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008486 }
8487
Stuart Scott8eef64f2015-04-08 15:13:54 -07008488 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008489 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008490 enforceSettingsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008491
8492 enforceTelephonyFeatureWithException(callingPackage,
8493 PackageManager.FEATURE_TELEPHONY, "factoryReset");
8494
Stuart Scott981d8582015-04-21 14:09:50 -07008495 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8496 return;
8497 }
Kai Shif70f46f2021-03-03 13:59:46 -08008498 Phone defaultPhone = getDefaultPhone();
8499 if (defaultPhone != null) {
8500 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8501 mApp, getDefaultPhone().getSubId(), "factoryReset");
8502 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008503 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008504
Svet Ganovcc087f82015-05-12 20:35:54 -07008505 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008506 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8507 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008508 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008509 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008510 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008511 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008512 cleanUpAllowedNetworkTypes(phone, subId);
Rambo Wang71f6aa62024-02-23 20:16:22 +00008513 setDataRoamingEnabled(subId, phone == null ? false
8514 : phone.getDataSettingsManager().isDefaultDataRoamingEnabled());
Jordan Liu857e73a2021-03-05 16:24:04 -08008515 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008516 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008517 // There has been issues when Sms raw table somehow stores orphan
8518 // fragments. They lead to garbled message when new fragments come
8519 // in and combined with those stale ones. In case this happens again,
8520 // user can reset all network settings which will clean up this table.
8521 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008522 // Clean up IMS settings as well here.
8523 int slotId = getSlotIndex(subId);
8524 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
8525 ImsManager.getInstance(mApp, slotId).factoryReset();
8526 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008527
Kai Shif70f46f2021-03-03 13:59:46 -08008528 if (defaultPhone == null) {
8529 return;
8530 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008531 // Erase modem config if erase modem on network setting is enabled.
8532 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8533 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8534 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008535 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008536 }
Kai Shif70f46f2021-03-03 13:59:46 -08008537
8538 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008539 } finally {
8540 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008541 }
8542 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008543
SongFerngWangfd89b102021-05-27 22:44:54 +08008544 @VisibleForTesting
8545 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8546 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8547 return;
8548 }
8549 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8550 RILConstants.PREFERRED_NETWORK_MODE);
8551 SubscriptionManager.setSubscriptionProperty(subId,
8552 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8553 "user=" + defaultNetworkType);
8554 phone.loadAllowedNetworksFromSubscriptionDatabase();
8555 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8556 defaultNetworkType, null);
8557 }
8558
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008559 private void cleanUpSmsRawTable(Context context) {
8560 ContentResolver resolver = context.getContentResolver();
8561 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8562 resolver.delete(uri, null, null);
8563 }
8564
Narayan Kamath1c496c22015-04-16 14:40:19 +01008565 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008566 public String getSimLocaleForSubscriber(int subId) {
8567 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
joonhunshin4ac60942023-11-15 15:23:39 +00008568
8569 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8570 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber");
8571
chen xu5d3637b2019-01-21 23:31:38 -08008572 final Phone phone = getPhone(subId);
8573 if (phone == null) {
8574 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008575 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008576 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008577 final long identity = Binder.clearCallingIdentity();
8578 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008579 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
8580 phone.getContext().getOpPackageName(),
8581 phone.getContext().getAttributionTag());
8582 if (info == null) {
8583 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8584 return null;
chen xu6291c472019-02-04 12:55:53 -08008585 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008586 // Try and fetch the locale from the carrier properties or from the SIM language
8587 // preferences (EF-PL and EF-LI)...
8588 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008589 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008590 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8591 if (localeFromDefaultSim != null) {
8592 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8593 if (DBG) log("Using locale from subId: " + subId + " locale: "
8594 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008595 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008596 } else {
8597 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008598 }
8599 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008600
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008601 // The SIM language preferences only store a language (e.g. fr = French), not an
8602 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8603 // the SIM and carrier preferences does not include a country we add the country
8604 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008605 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008606 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008607 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008608 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008609 }
8610
8611 if (DBG) log("No locale found - returning null");
8612 return null;
8613 } finally {
8614 Binder.restoreCallingIdentity(identity);
8615 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008616 }
8617
tom hsu0b59d292022-09-29 23:49:21 +08008618 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008619 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008620 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008621 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008622 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008623 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8624 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008625 Locale.forLanguageTag(localeTag).getCountry())) {
8626 return localeTag;
8627 }
8628 }
8629 return inputLocale.toLanguageTag();
8630 }
8631
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008632 /**
8633 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8634 */
8635 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008636 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Ling Ma9fa67412023-11-13 14:13:19 -08008637 mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/);
Narayan Kamath1c496c22015-04-16 14:40:19 +01008638 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008639
Gary Jian3aa9a762022-01-24 16:41:19 +08008640 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8641 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008642
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008643 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008644 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8645 * representing the state of the modem.
8646 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008647 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8648 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008649 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008650 */
8651 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008652 public void requestModemActivityInfo(ResultReceiver result) {
8653 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008654
8655 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8656 PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo");
8657
vagdeviaf9a5b92018-08-15 16:01:53 -07008658 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008659
8660 final long identity = Binder.clearCallingIdentity();
8661 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008662 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008663 } finally {
8664 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008665 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008666 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008667
Gary Jian76280a42022-12-07 16:18:33 +08008668 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008669 // less than total activity duration.
8670 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8671 if (info == null) {
8672 return false;
8673 }
8674 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008675 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008676 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8677
Hall Liu49656c02020-10-09 19:00:11 -07008678 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8679
Siddharth Rayb8114062018-06-17 15:02:38 -07008680 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008681 && (info.getSleepTimeMillis() <= activityDurationMs)
8682 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008683 }
8684
Gary Jian3aa9a762022-01-24 16:41:19 +08008685 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8686 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8687 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8688 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8689
8690 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8691 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8692 }
8693
8694 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8695 mLastModemActivityInfo.setReceiveTimeMillis(
8696 rat,
8697 freq,
8698 info.getReceiveTimeMillis(rat, freq)
8699 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8700 }
8701
8702 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8703 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8704 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8705 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8706
8707 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8708 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8709 }
8710 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8711 mLastModemActivityInfo.setReceiveTimeMillis(
8712 rat,
8713 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8714 }
8715
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008716 /**
8717 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8718 * @param info recent ModemActivityInfo
8719 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008720 private void mergeModemActivityInfo(ModemActivityInfo info) {
8721 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008722 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008723 boolean matched;
8724 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8725 matched = false;
8726 int rat = info.getSpecificInfoRat(i);
8727 int freq = info.getSpecificInfoFrequencyRange(i);
8728 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8729 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8730 //if it already exists
8731 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8732 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8733 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8734 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8735 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8736 updateLastModemActivityInfo(info, rat, freq);
8737 matched = true;
8738 }
8739 } else {
8740 updateLastModemActivityInfo(info, rat);
8741 matched = true;
8742 }
8743 }
8744 }
8745
8746 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008747 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008748 new ActivityStatsTechSpecificInfo(
8749 rat,
8750 freq,
8751 info.getTransmitTimeMillis(rat, freq),
8752 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008753 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008754 }
8755 }
8756 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8757 mLastModemActivitySpecificInfo =
8758 new ActivityStatsTechSpecificInfo[merged.size()];
8759 merged.toArray(mLastModemActivitySpecificInfo);
8760
8761 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8762 mLastModemActivityInfo.setSleepTimeMillis(
8763 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008764 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008765 mLastModemActivityInfo.setIdleTimeMillis(
8766 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008767 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008768
8769 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008770 new ModemActivityInfo(
8771 mLastModemActivityInfo.getTimestampMillis(),
8772 mLastModemActivityInfo.getSleepTimeMillis(),
8773 mLastModemActivityInfo.getIdleTimeMillis(),
8774 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008775 }
8776
8777 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8778 ActivityStatsTechSpecificInfo[] info) {
8779 int infoSize = info.length;
8780 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8781 for (int i = 0; i < infoSize; i++) {
8782 ret[i] = new ActivityStatsTechSpecificInfo(
8783 info[i].getRat(), info[i].getFrequencyRange(),
8784 info[i].getTransmitTimeMillis(),
8785 (int) info[i].getReceiveTimeMillis());
8786 }
8787 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008788 }
8789
Jack Yu85bd38a2015-11-09 11:34:32 -08008790 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008791 * Returns the service state information on specified subscription.
8792 */
8793 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008794 public ServiceState getServiceStateForSubscriber(int subId,
8795 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8796 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008797 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008798 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008799 return null;
8800 }
8801
joonhunshin4ac60942023-11-15 15:23:39 +00008802 enforceTelephonyFeatureWithException(callingPackage,
8803 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber");
8804
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008805 boolean hasFinePermission = false;
8806 boolean hasCoarsePermission = false;
8807 if (!renounceFineLocationAccess) {
8808 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8809 LocationAccessPolicy.checkLocationPermission(mApp,
8810 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8811 .setCallingPackage(callingPackage)
8812 .setCallingFeatureId(callingFeatureId)
8813 .setCallingPid(Binder.getCallingPid())
8814 .setCallingUid(Binder.getCallingUid())
8815 .setMethod("getServiceStateForSubscriber")
8816 .setLogAsInfo(true)
8817 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8818 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8819 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8820 .build());
8821 hasFinePermission =
8822 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8823 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008824
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008825 if (!renounceCoarseLocationAccess) {
8826 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8827 LocationAccessPolicy.checkLocationPermission(mApp,
8828 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8829 .setCallingPackage(callingPackage)
8830 .setCallingFeatureId(callingFeatureId)
8831 .setCallingPid(Binder.getCallingPid())
8832 .setCallingUid(Binder.getCallingUid())
8833 .setMethod("getServiceStateForSubscriber")
8834 .setLogAsInfo(true)
8835 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8836 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8837 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8838 .build());
8839 hasCoarsePermission =
8840 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8841 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008842
Jack Yu479f40e2020-10-27 21:29:25 -07008843 final Phone phone = getPhone(subId);
8844 if (phone == null) {
8845 return null;
8846 }
8847
Jordan Liu0f2bc442020-11-18 16:47:37 -08008848 final long identity = Binder.clearCallingIdentity();
8849
Jack Yu479f40e2020-10-27 21:29:25 -07008850 boolean isCallingPackageDataService = phone.getDataServicePackages()
8851 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008852 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008853 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu3beaf9d2023-04-14 09:17:27 -07008854 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8855 .getSubscriptionInfoInternal(subId);
8856 if (subInfo == null || !subInfo.isActive()) {
8857 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8858 + "subId=" + subId);
8859 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008860 }
8861
Hall Liuf19c44f2018-11-27 14:38:17 -08008862 ServiceState ss = phone.getServiceState();
8863
8864 // Scrub out the location info in ServiceState depending on what level of access
8865 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008866 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008867 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8868 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008869 } finally {
8870 Binder.restoreCallingIdentity(identity);
8871 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008872 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008873
8874 /**
8875 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8876 *
8877 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8878 * voicemail ringtone.
8879 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8880 * PhoneAccount.
8881 */
8882 @Override
8883 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008884 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8885 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri");
8886
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008887 final long identity = Binder.clearCallingIdentity();
8888 try {
8889 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8890 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008891 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008892 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008893
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008894 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8895 } finally {
8896 Binder.restoreCallingIdentity(identity);
8897 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008898 }
8899
8900 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008901 * Sets the per-account voicemail ringtone.
8902 *
8903 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8904 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8905 *
8906 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8907 * voicemail ringtone.
8908 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8909 * PhoneAccount.
8910 */
8911 @Override
8912 public void setVoicemailRingtoneUri(String callingPackage,
8913 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008914 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008915 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008916 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8917 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008918 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8919 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8920 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008921 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008922
joonhunshin4ac60942023-11-15 15:23:39 +00008923 enforceTelephonyFeatureWithException(callingPackage,
8924 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri");
8925
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008926 final long identity = Binder.clearCallingIdentity();
8927 try {
8928 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8929 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008930 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008931 }
8932 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8933 } finally {
8934 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008935 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008936 }
8937
8938 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008939 * Returns whether vibration is set for voicemail notification in Phone settings.
8940 *
8941 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8942 * voicemail vibration setting.
8943 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8944 */
8945 @Override
8946 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008947 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8948 PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled");
8949
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008950 final long identity = Binder.clearCallingIdentity();
8951 try {
8952 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8953 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008954 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008955 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008956
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008957 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8958 } finally {
8959 Binder.restoreCallingIdentity(identity);
8960 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008961 }
8962
Youhan Wange64578a2016-05-02 15:32:42 -07008963 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008964 * Sets the per-account voicemail vibration.
8965 *
8966 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8967 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8968 *
8969 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8970 * voicemail vibration setting.
8971 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8972 * specific PhoneAccount.
8973 */
8974 @Override
8975 public void setVoicemailVibrationEnabled(String callingPackage,
8976 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008977 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008978 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008979 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8980 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008981 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8982 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8983 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008984 }
8985
joonhunshin4ac60942023-11-15 15:23:39 +00008986 enforceTelephonyFeatureWithException(callingPackage,
8987 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled");
8988
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008989 final long identity = Binder.clearCallingIdentity();
8990 try {
8991 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8992 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008993 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008994 }
8995 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8996 } finally {
8997 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008998 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008999 }
9000
9001 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009002 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
9003 *
9004 * @throws SecurityException if the caller does not have the required permission
9005 */
arunvoddud7401012022-12-15 16:08:12 +00009006 @VisibleForTesting
9007 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07009008 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07009009 message);
Youhan Wange64578a2016-05-02 15:32:42 -07009010 }
9011
9012 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009013 * Make sure either called from same process as self (phone) or IPC caller has send SMS
9014 * permission.
9015 *
9016 * @throws SecurityException if the caller does not have the required permission
9017 */
9018 private void enforceSendSmsPermission() {
9019 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
9020 }
9021
9022 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00009023 * Make sure either called from same process as self (phone) or IPC caller has interact across
9024 * users permission.
9025 *
9026 * @throws SecurityException if the caller does not have the required permission
9027 */
9028 private void enforceInteractAcrossUsersPermission(String message) {
9029 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
9030 }
9031
9032 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009033 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009034 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009035 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009036 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009037 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009038 final long identity = Binder.clearCallingIdentity();
9039 try {
9040 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009041 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009042 if (componentName == null) {
9043 throw new SecurityException(
9044 "Caller not current active visual voicemail package[null]");
9045 }
9046 String vvmPackage = componentName.getPackageName();
9047 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00009048 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009049 }
9050 } finally {
9051 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009052 }
9053 }
9054
9055 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009056 * Return the application ID for the app type.
9057 *
9058 * @param subId the subscription ID that this request applies to.
9059 * @param appType the uicc app type.
9060 * @return Application ID for specificied app type, or null if no uicc.
9061 */
9062 @Override
9063 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009064 enforceReadPrivilegedPermission("getAidForAppType");
joonhunshin4ac60942023-11-15 15:23:39 +00009065
9066 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9067 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType");
9068
Youhan Wange64578a2016-05-02 15:32:42 -07009069 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009070
9071 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07009072 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009073 if (phone == null) {
9074 return null;
9075 }
9076 String aid = null;
9077 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009078 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009079 .getApplicationByType(appType).getAid();
9080 } catch (Exception e) {
9081 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
9082 }
9083 return aid;
9084 } finally {
9085 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07009086 }
Youhan Wange64578a2016-05-02 15:32:42 -07009087 }
9088
Youhan Wang4001d252016-05-11 10:29:41 -07009089 /**
9090 * Return the Electronic Serial Number.
9091 *
9092 * @param subId the subscription ID that this request applies to.
9093 * @return ESN or null if error.
9094 */
9095 @Override
9096 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009097 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07009098 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009099
9100 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07009101 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009102 if (phone == null) {
9103 return null;
9104 }
9105 String esn = null;
9106 try {
9107 esn = phone.getEsn();
9108 } catch (Exception e) {
9109 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
9110 }
9111 return esn;
9112 } finally {
9113 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07009114 }
Youhan Wang4001d252016-05-11 10:29:41 -07009115 }
9116
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009117 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009118 * Return the Preferred Roaming List Version.
9119 *
9120 * @param subId the subscription ID that this request applies to.
9121 * @return PRLVersion or null if error.
9122 */
9123 @Override
9124 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009125 enforceReadPrivilegedPermission("getCdmaPrlVersion");
joonhunshin4ac60942023-11-15 15:23:39 +00009126
9127 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9128 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion");
9129
Youhan Wang66ad5d72016-07-18 17:56:58 -07009130 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009131
9132 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009133 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009134 if (phone == null) {
9135 return null;
9136 }
9137 String cdmaPrlVersion = null;
9138 try {
9139 cdmaPrlVersion = phone.getCdmaPrlVersion();
9140 } catch (Exception e) {
9141 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9142 }
9143 return cdmaPrlVersion;
9144 } finally {
9145 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009146 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009147 }
9148
9149 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009150 * Get snapshot of Telephony histograms
9151 * @return List of Telephony histograms
9152 * @hide
9153 */
9154 @Override
9155 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009156 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9157 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009158
9159 final long identity = Binder.clearCallingIdentity();
9160 try {
9161 return RIL.getTelephonyRILTimingHistograms();
9162 } finally {
9163 Binder.restoreCallingIdentity(identity);
9164 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009165 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009166
9167 /**
9168 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009169 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9170 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009171 * Require system privileges. In the future we may add this to carrier APIs.
9172 *
Michele Berionne482f8202018-11-27 18:57:59 -08009173 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009174 */
9175 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009176 @TelephonyManager.SetCarrierRestrictionResult
9177 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009178 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009179
9180 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9181 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers");
9182
vagdeviaf9a5b92018-08-15 16:01:53 -07009183 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009184
Michele Berionne482f8202018-11-27 18:57:59 -08009185 if (carrierRestrictionRules == null) {
9186 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009187 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009188
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009189 final long identity = Binder.clearCallingIdentity();
9190 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009191 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009192 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009193 } finally {
9194 Binder.restoreCallingIdentity(identity);
9195 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009196 }
9197
9198 /**
9199 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009200 * Get the allowed carrier list and the excluded carrier list, including the priority between
9201 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009202 * Require system privileges. In the future we may add this to carrier APIs.
9203 *
Michele Berionne482f8202018-11-27 18:57:59 -08009204 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009205 */
9206 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009207 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009208 enforceReadPrivilegedPermission("getAllowedCarriers");
joonhunshin4ac60942023-11-15 15:23:39 +00009209
9210 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9211 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers");
9212
vagdeviaf9a5b92018-08-15 16:01:53 -07009213 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009214
9215 final long identity = Binder.clearCallingIdentity();
9216 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009217 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9218 if (response instanceof CarrierRestrictionRules) {
9219 return (CarrierRestrictionRules) response;
9220 }
9221 // Response is an Exception of some kind,
9222 // which is signalled to the user as a NULL retval
9223 return null;
9224 } catch (Exception e) {
9225 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9226 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009227 } finally {
9228 Binder.restoreCallingIdentity(identity);
9229 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009230 }
9231
fionaxu59545b42016-05-25 15:53:37 -07009232 /**
arunvoddud7401012022-12-15 16:08:12 +00009233 * Fetches the carrier restriction status of the device and sends the status to the caller
9234 * through the callback.
9235 *
9236 * @param callback The callback that will be used to send the result.
9237 * @throws SecurityException if the caller does not have the required permission/privileges or
9238 * the caller is not allowlisted.
9239 */
9240 @Override
9241 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
9242 enforceReadPermission("getCarrierRestrictionStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00009243
9244 enforceTelephonyFeatureWithException(packageName,
9245 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierRestrictionStatus");
9246
Steve Statia28b7cb32024-03-11 23:58:50 +00009247 Set<Integer> carrierIds = validateCallerAndGetCarrierIds(packageName);
9248 if (carrierIds.contains(CarrierAllowListInfo.INVALID_CARRIER_ID)) {
arunvoddud7401012022-12-15 16:08:12 +00009249 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9250 throw new SecurityException("Not an authorized caller");
9251 }
9252 final long identity = Binder.clearCallingIdentity();
9253 try {
9254 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
Steve Statia28b7cb32024-03-11 23:58:50 +00009255 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierIds);
arunvoddud7401012022-12-15 16:08:12 +00009256 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9257 } finally {
9258 Binder.restoreCallingIdentity(identity);
9259 }
9260 }
9261
arunvoddu567f2b42023-04-25 17:22:00 +00009262 @Override
9263 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
9264 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
9265 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9266 return allowListInfo.getShaIdList(pkgName, carrierId);
9267 }
9268
arunvoddud7401012022-12-15 16:08:12 +00009269 @VisibleForTesting
Steve Statia28b7cb32024-03-11 23:58:50 +00009270 public Set<Integer> validateCallerAndGetCarrierIds(String packageName) {
arunvoddud7401012022-12-15 16:08:12 +00009271 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
Steve Statia28b7cb32024-03-11 23:58:50 +00009272 return allowListInfo.validateCallerAndGetCarrierIds(packageName);
arunvoddud7401012022-12-15 16:08:12 +00009273 }
9274
9275 /**
fionaxu59545b42016-05-25 15:53:37 -07009276 * Action set from carrier signalling broadcast receivers to enable/disable radio
9277 * @param subId the subscription ID that this action applies to.
9278 * @param enabled control enable or disable radio.
9279 * {@hide}
9280 */
9281 @Override
9282 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9283 enforceModifyPermission();
9284 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009285
9286 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009287 if (phone == null) {
9288 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9289 return;
9290 }
9291 try {
9292 phone.carrierActionSetRadioEnabled(enabled);
9293 } catch (Exception e) {
9294 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009295 } finally {
9296 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009297 }
9298 }
9299
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009300 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009301 * Enable or disable Voice over NR (VoNR)
9302 * @param subId the subscription ID that this action applies to.
9303 * @param enabled enable or disable VoNR.
9304 * @return operation result.
9305 */
9306 @Override
9307 public int setVoNrEnabled(int subId, boolean enabled) {
9308 enforceModifyPermission();
9309 final Phone phone = getPhone(subId);
9310
9311 final long identity = Binder.clearCallingIdentity();
9312 if (phone == null) {
9313 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9314 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9315 }
9316
9317 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9318 try {
9319 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9320 workSource);
9321 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009322
9323 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9324 if (DBG) {
9325 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9326 }
9327 SubscriptionManager.setSubscriptionProperty(
9328 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9329 (enabled ? "1" : "0"));
9330 }
9331
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009332 return result;
9333 } finally {
9334 Binder.restoreCallingIdentity(identity);
9335 }
9336 }
9337
9338 /**
9339 * Is voice over NR enabled
9340 * @return true if VoNR is enabled else false
9341 */
9342 @Override
9343 public boolean isVoNrEnabled(int subId) {
9344 enforceReadPrivilegedPermission("isVoNrEnabled");
9345 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9346 final long identity = Binder.clearCallingIdentity();
9347 try {
9348 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9349 null, subId, workSource);
9350 if (DBG) log("isVoNrEnabled: " + isEnabled);
9351 return isEnabled;
9352 } finally {
9353 Binder.restoreCallingIdentity(identity);
9354 }
9355 }
9356
9357 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009358 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9359 * network status based on which carrier apps could apply actions accordingly,
9360 * enable/disable default url handler for example.
9361 *
9362 * @param subId the subscription ID that this action applies to.
9363 * @param report control start/stop reporting the default network status.
9364 * {@hide}
9365 */
9366 @Override
9367 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9368 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009369
9370 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9371 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
9372 "carrierActionReportDefaultNetworkStatus");
9373
fionaxu8da9cb12017-05-23 15:02:46 -07009374 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009375
9376 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009377 if (phone == null) {
9378 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9379 return;
9380 }
9381 try {
9382 phone.carrierActionReportDefaultNetworkStatus(report);
9383 } catch (Exception e) {
9384 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009385 } finally {
9386 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009387 }
9388 }
9389
9390 /**
fionaxud9622282017-07-17 17:51:30 -07009391 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9392 * @param subId the subscription ID that this action applies to.
9393 * {@hide}
9394 */
9395 @Override
9396 public void carrierActionResetAll(int subId) {
9397 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009398
9399 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9400 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll");
9401
fionaxud9622282017-07-17 17:51:30 -07009402 final Phone phone = getPhone(subId);
9403 if (phone == null) {
9404 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9405 return;
9406 }
9407 try {
9408 phone.carrierActionResetAll();
9409 } catch (Exception e) {
9410 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9411 }
9412 }
9413
9414 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009415 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9416 * bug report is being generated.
9417 */
9418 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009419 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009420 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9421 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009422 writer.println("Permission Denial: can't dump Phone from pid="
9423 + Binder.getCallingPid()
9424 + ", uid=" + Binder.getCallingUid()
9425 + "without permission "
9426 + android.Manifest.permission.DUMP);
9427 return;
9428 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009429 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009430 }
Jack Yueb89b242016-06-22 13:27:47 -07009431
Brad Ebingerdac2f002018-04-03 15:17:52 -07009432 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009433 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9434 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9435 @NonNull String[] args) {
9436 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9437 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009438 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009439 }
9440
Jack Yueb89b242016-06-22 13:27:47 -07009441 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009442 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009443 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009444 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009445 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009446 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009447 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009448 */
9449 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009450 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009451 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009452 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9453 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9454 try {
9455 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009456 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009457 } catch (SecurityException se) {
9458 enforceModifyPermission();
9459 }
9460 } else {
9461 enforceModifyPermission();
9462 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009463
joonhunshin4ac60942023-11-15 15:23:39 +00009464 enforceTelephonyFeatureWithException(callingPackage,
9465 PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason");
9466
Nate Myren116695d2024-02-09 09:36:01 -08009467 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009468 final long identity = Binder.clearCallingIdentity();
9469 try {
Nate Myren116695d2024-02-09 09:36:01 -08009470 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
9471 && null != callingPackage && opEnableMobileDataByUser()) {
Nate Myren453c3472024-03-13 11:28:11 -07009472 mAppOps.noteOpNoThrow(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER,
Nate Myren116695d2024-02-09 09:36:01 -08009473 callingUid, callingPackage, null, null);
9474 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009475 Phone phone = getPhone(subId);
9476 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009477 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9478 phone.carrierActionSetMeteredApnsEnabled(enabled);
9479 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07009480 phone.getDataSettingsManager().setDataEnabled(
9481 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009482 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009483 }
9484 } finally {
9485 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009486 }
9487 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009488
9489 /**
9490 * Get Client request stats
9491 * @return List of Client Request Stats
9492 * @hide
9493 */
9494 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009495 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9496 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009497 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009498 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009499 return null;
9500 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009501 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009502
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009503 final long identity = Binder.clearCallingIdentity();
9504 try {
9505 if (phone != null) {
9506 return phone.getClientRequestStats();
9507 }
9508
9509 return null;
9510 } finally {
9511 Binder.restoreCallingIdentity(identity);
9512 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009513 }
9514
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009515 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009516 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009517 if (uid == Process.ROOT_UID && packageName == null) {
9518 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9519 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9520 // exception. ROOT_UID seems not to have a valid package name returned by
9521 // PackageManager, so just fake it here to avoid issues when running telephony shell
9522 // commands that plumb through the RIL as root, like so:
9523 // $ adb root
9524 // $ adb shell cmd phone ...
9525 packageName = "root";
9526 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009527 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009528 }
Jack Yueb4124c2017-02-16 15:32:43 -08009529
9530 /**
Grace Chen70990072017-03-24 17:21:30 -07009531 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009532 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009533 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009534 * @param state State of SIM (power down, power up, pass through)
9535 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9536 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9537 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009538 *
9539 **/
9540 @Override
Grace Chen70990072017-03-24 17:21:30 -07009541 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009542 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009543
9544 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9545 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot");
9546
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009547 Phone phone = PhoneFactory.getPhone(slotIndex);
9548
vagdeviaf9a5b92018-08-15 16:01:53 -07009549 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9550
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009551 final long identity = Binder.clearCallingIdentity();
9552 try {
9553 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009554 phone.setSimPowerState(state, null, workSource);
9555 }
9556 } finally {
9557 Binder.restoreCallingIdentity(identity);
9558 }
9559 }
9560
9561 /**
9562 * Set SIM card power state.
9563 *
9564 * @param slotIndex SIM slot id.
9565 * @param state State of SIM (power down, power up, pass through)
9566 * @param callback callback to trigger after success or failure
9567 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9568 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9569 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9570 *
9571 **/
9572 @Override
9573 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9574 IIntegerConsumer callback) {
9575 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009576
9577 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9578 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
9579 "setSimPowerStateForSlotWithCallback");
9580
Jordan Liu109698e2020-11-24 14:50:34 -08009581 Phone phone = PhoneFactory.getPhone(slotIndex);
9582
9583 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9584
9585 final long identity = Binder.clearCallingIdentity();
9586 try {
9587 if (phone != null) {
9588 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9589 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009590 }
9591 } finally {
9592 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009593 }
9594 }
Shuo Qiandd210312017-04-12 22:11:33 +00009595
Tyler Gunn65d45c22017-06-05 11:22:26 -07009596 private boolean isUssdApiAllowed(int subId) {
9597 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009598 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009599 if (configManager == null) {
9600 return false;
9601 }
9602 PersistableBundle pb = configManager.getConfigForSubId(subId);
9603 if (pb == null) {
9604 return false;
9605 }
9606 return pb.getBoolean(
9607 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9608 }
9609
Shuo Qiandd210312017-04-12 22:11:33 +00009610 /**
Ling Mac28f0212023-03-24 16:07:15 -07009611 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00009612 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07009613 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00009614 */
goneil9c5f4872017-12-05 14:07:56 -08009615 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009616 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009617 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
joonhunshin4ac60942023-11-15 15:23:39 +00009618
9619 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9620 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode");
9621
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009622 final long identity = Binder.clearCallingIdentity();
9623 try {
Ling Mac28f0212023-03-24 16:07:15 -07009624 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009625 } finally {
9626 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009627 }
9628 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009629
9630 /**
9631 * Get the current signal strength information for the given subscription.
9632 * Because this information is not updated when the device is in a low power state
9633 * it should not be relied-upon to be current.
9634 * @param subId Subscription index
9635 * @return the most recent cached signal strength info from the modem
9636 */
9637 @Override
9638 public SignalStrength getSignalStrength(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00009639 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9640 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength");
9641
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009642 final long identity = Binder.clearCallingIdentity();
9643 try {
9644 Phone p = getPhone(subId);
9645 if (p == null) {
9646 return null;
9647 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009648
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009649 return p.getSignalStrength();
9650 } finally {
9651 Binder.restoreCallingIdentity(identity);
9652 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009653 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009654
Pengquan Meng77b7f132018-08-22 14:49:57 -07009655 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009656 * Get the current modem radio state for the given slot.
9657 * @param slotIndex slot index.
9658 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009659 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009660 * @return the current radio power state from the modem
9661 */
9662 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009663 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009664 Phone phone = PhoneFactory.getPhone(slotIndex);
9665 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009666 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9667 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009668 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9669 }
9670
joonhunshin4ac60942023-11-15 15:23:39 +00009671 enforceTelephonyFeatureWithException(callingPackage,
9672 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState");
9673
Chen Xuf792fd62018-10-17 17:54:36 +00009674 final long identity = Binder.clearCallingIdentity();
9675 try {
9676 return phone.getRadioPowerState();
9677 } finally {
9678 Binder.restoreCallingIdentity(identity);
9679 }
9680 }
9681 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9682 }
9683
9684 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009685 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9686 *
9687 * <p>Requires one of the following permissions:
9688 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009689 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009690 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9691 * privileges.
9692 *
9693 * @param subId subscription id
9694 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9695 * {@code false}.
9696 */
9697 @Override
9698 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009699 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009700 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009701 try {
9702 mApp.enforceCallingOrSelfPermission(
9703 android.Manifest.permission.ACCESS_NETWORK_STATE,
9704 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009705 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009706 mApp.enforceCallingOrSelfPermission(
9707 permission.READ_BASIC_PHONE_STATE, functionName);
9708 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009709 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009710 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009711 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009712 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009713
joonhunshin4ac60942023-11-15 15:23:39 +00009714 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9715 PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled");
9716
Pengquan Menga1bb6272018-09-06 09:59:22 -07009717 boolean isEnabled = false;
9718 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009719 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009720 Phone phone = getPhone(subId);
9721 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009722 } finally {
9723 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009724 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009725 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009726 }
9727
9728
9729 /**
9730 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9731 *
9732 * <p> Requires permission:
9733 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9734 * privileges.
9735 *
9736 * @param subId subscription id
9737 * @param isEnabled {@code true} means enable, {@code false} means disable.
9738 */
9739 @Override
9740 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009741 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9742 mApp, subId, "setDataRoamingEnabled");
9743
joonhunshin4ac60942023-11-15 15:23:39 +00009744 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9745 PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled");
9746
Pengquan Menga1bb6272018-09-06 09:59:22 -07009747 final long identity = Binder.clearCallingIdentity();
9748 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009749 Phone phone = getPhone(subId);
9750 if (phone != null) {
9751 phone.setDataRoamingEnabled(isEnabled);
9752 }
9753 } finally {
9754 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009755 }
9756 }
9757
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009758 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009759 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009760 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009761 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009762 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009763
joonhunshin4ac60942023-11-15 15:23:39 +00009764 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9765 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed");
9766
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009767 boolean isAllowed = true;
9768 final long identity = Binder.clearCallingIdentity();
9769 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009770 Phone phone = getPhone(subId);
9771 if (phone != null) {
9772 isAllowed = phone.isCspPlmnEnabled();
9773 }
9774 } finally {
9775 Binder.restoreCallingIdentity(identity);
9776 }
9777 return isAllowed;
9778 }
9779
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009780 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9781 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009782 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009783 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009784 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009785 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9786 if (phone == null) {
9787 return false;
9788 }
9789 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9790 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9791 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009792 }
9793
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009794 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009795 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009796 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009797 mApp.getSystemService(AppOpsManager.class)
9798 .checkPackage(Binder.getCallingUid(), callingPackage);
9799
Jordan Liu1e142fc2019-04-22 15:10:43 -07009800 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009801 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009802 try {
9803 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009804 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009805 } catch (SecurityException e) {
9806 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9807 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009808 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009809 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009810 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009811 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009812 }
joonhunshin4ac60942023-11-15 15:23:39 +00009813
9814 enforceTelephonyFeatureWithException(callingPackage,
9815 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo");
9816
sandeepjsb6c87872021-09-27 15:34:44 +00009817 // checking compatibility, if calling app's target SDK is T and beyond.
9818 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9819 Binder.getCallingUid())) {
9820 isIccIdAccessRestricted = true;
9821 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009822 final long identity = Binder.clearCallingIdentity();
9823 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009824 UiccController uiccController = UiccController.getInstance();
9825 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009826 if (hasReadPermission) {
9827 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009828 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009829
9830 // Remove private info if the caller doesn't have access
9831 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9832 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009833 //setting the value after compatibility check
9834 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009835 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9836 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009837 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009838 if (card == null) {
9839 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009840 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009841 continue;
9842 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009843 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9844 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009845 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009846 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009847 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009848 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9849 for (UiccPortInfo portInfo : portInfos) {
9850 UiccPort port = uiccController.getUiccPortForSlot(
9851 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9852 if (port == null) {
9853 // assume no access if port is null
9854 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9855 continue;
9856 }
9857 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9858 uiccPortInfos.add(portInfo);
9859 } else {
9860 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9861 }
9862 }
9863 filteredInfos.add(new UiccCardInfo(
9864 cardInfo.isEuicc(),
9865 cardInfo.getCardId(),
9866 null,
9867 cardInfo.getPhysicalSlotIndex(),
9868 cardInfo.isRemovable(),
9869 cardInfo.isMultipleEnabledProfilesSupported(),
9870 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009871 }
9872 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009873 } finally {
9874 Binder.restoreCallingIdentity(identity);
9875 }
9876 }
9877
sandeepjsb6c87872021-09-27 15:34:44 +00009878 /**
9879 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9880 * generally private and require carrier privileges to view.
9881 *
9882 * @hide
9883 */
9884 @NonNull
9885 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9886 List<UiccPortInfo> portinfo = new ArrayList<>();
9887 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9888 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9889 }
9890 return new UiccCardInfo(
9891 cardInfo.isEuicc(),
9892 cardInfo.getCardId(),
9893 null,
9894 cardInfo.getPhysicalSlotIndex(),
9895 cardInfo.isRemovable(),
9896 cardInfo.isMultipleEnabledProfilesSupported(),
9897 portinfo
9898 );
9899 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009900
sandeepjsb6c87872021-09-27 15:34:44 +00009901 /**
9902 * @hide
9903 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9904 * These values are generally private and require carrier privileges to view.
9905 */
9906 @NonNull
9907 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9908 return new UiccPortInfo(
9909 UiccPortInfo.ICCID_REDACTED,
9910 portInfo.getPortIndex(),
9911 portInfo.getLogicalSlotIndex(),
9912 portInfo.isActive()
9913 );
9914 }
9915 @Override
9916 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009917 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009918 mApp.getSystemService(AppOpsManager.class)
9919 .checkPackage(Binder.getCallingUid(), callingPackage);
9920
sandeepjsb6c87872021-09-27 15:34:44 +00009921 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009922
Aman Guptaf3c90b32022-03-17 04:54:16 +00009923 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9924 // we are reading iccId which is PII data.
9925 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009926
joonhunshin4ac60942023-11-15 15:23:39 +00009927 enforceTelephonyFeatureWithException(callingPackage,
9928 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo");
9929
sandeepjsb6c87872021-09-27 15:34:44 +00009930 // checking compatibility, if calling app's target SDK is T and beyond.
9931 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9932 Binder.getCallingUid())) {
9933 isLogicalSlotAccessRestricted = true;
9934 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009935 final long identity = Binder.clearCallingIdentity();
9936 try {
9937 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009938 if (slots == null || slots.length == 0) {
9939 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009940 return null;
9941 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009942 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9943 for (int i = 0; i < slots.length; i++) {
9944 UiccSlot slot = slots[i];
9945 if (slot == null) {
9946 continue;
9947 }
9948
Jordan Liu7be7e652019-05-06 18:55:02 +00009949 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009950 UiccCard card = slot.getUiccCard();
9951 if (card != null) {
9952 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009953 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009954 cardId = slot.getEid();
9955 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009956 // If cardId is null, use iccId of default port as cardId.
9957 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009958 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009959 }
9960
Jordan Liu857451f2019-05-09 16:35:35 -07009961 if (cardId != null) {
9962 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9963 // if cardId is an EID, it's all digits so this is fine
9964 cardId = IccUtils.stripTrailingFs(cardId);
9965 }
9966
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009967 int cardState = 0;
9968 switch (slot.getCardState()) {
9969 case CARDSTATE_ABSENT:
9970 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9971 break;
9972 case CARDSTATE_PRESENT:
9973 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9974 break;
9975 case CARDSTATE_ERROR:
9976 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9977 break;
9978 case CARDSTATE_RESTRICTED:
9979 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9980 break;
9981 default:
9982 break;
9983
9984 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009985 List<UiccPortInfo> portInfos = new ArrayList<>();
9986 int[] portIndexes = slot.getPortList();
9987 for (int portIdx : portIndexes) {
9988 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009989 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009990 portInfos.add(new UiccPortInfo(iccId, portIdx,
9991 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009992 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009993 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009994 slot.isEuicc(),
9995 cardId,
9996 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009997 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009998 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009999 //setting the value after compatibility check
10000 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010001 }
10002 return infos;
10003 } finally {
10004 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -070010005 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010006 }
10007
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010008 /* Returns null if doesn't have read permission or carrier privilege access. */
10009 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
10010 boolean hasReadPermission) {
10011 String iccId = slot.getIccId(portIndex);
10012 if (hasReadPermission) { // if has read permission
10013 return iccId;
10014 } else {
10015 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
10016 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
10017 // if no read permission, checking carrier privilege access
10018 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
10019 return iccId;
10020 }
10021 }
10022 }
10023 // No read permission or carrier privilege access.
10024 return UiccPortInfo.ICCID_REDACTED;
10025 }
10026
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010027 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010028 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010029 public boolean switchSlots(int[] physicalSlots) {
10030 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010031
joonhunshin4ac60942023-11-15 15:23:39 +000010032 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10033 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots");
10034
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010035 final long identity = Binder.clearCallingIdentity();
10036 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010037 List<UiccSlotMapping> slotMappings = new ArrayList<>();
10038 for (int i = 0; i < physicalSlots.length; i++) {
10039 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
10040 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
10041 physicalSlots[i], i));
10042 }
10043 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010044 } finally {
10045 Binder.restoreCallingIdentity(identity);
10046 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010047 }
Jack Yu4c988042018-02-27 15:30:01 -080010048
10049 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010050 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
10051 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
10052 enforceModifyPermission();
10053
joonhunshin4ac60942023-11-15 15:23:39 +000010054 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10055 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping");
10056
sandeepjsb6c87872021-09-27 15:34:44 +000010057 final long identity = Binder.clearCallingIdentity();
10058 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010059 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +000010060 } finally {
10061 Binder.restoreCallingIdentity(identity);
10062 }
10063 }
10064
10065 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -080010066 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
joonhunshin4ac60942023-11-15 15:23:39 +000010067 enforceTelephonyFeatureWithException(callingPackage,
10068 PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc");
10069
Jordan Liu7de49fa2018-12-06 14:48:49 -080010070 final long identity = Binder.clearCallingIdentity();
10071 try {
10072 return UiccController.getInstance().getCardIdForDefaultEuicc();
10073 } finally {
10074 Binder.restoreCallingIdentity(identity);
10075 }
10076 }
10077
Pengquan Meng85728fb2018-03-12 16:31:21 -070010078 /**
goneil47ffb6e2018-04-06 15:40:58 -070010079 * A test API to reload the UICC profile.
10080 *
10081 * <p>Requires that the calling app has permission
10082 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
10083 * @hide
10084 */
10085 @Override
10086 public void refreshUiccProfile(int subId) {
10087 enforceModifyPermission();
10088
10089 final long identity = Binder.clearCallingIdentity();
10090 try {
10091 Phone phone = getPhone(subId);
10092 if (phone == null) {
10093 return;
10094 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010095 UiccPort uiccPort = phone.getUiccPort();
10096 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -070010097 return;
10098 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010099 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -070010100 if (uiccProfile == null) {
10101 return;
10102 }
10103 uiccProfile.refresh();
10104 } finally {
10105 Binder.restoreCallingIdentity(identity);
10106 }
10107 }
10108
10109 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010110 * Returns false if the mobile data is disabled by default, otherwise return true.
10111 */
10112 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010113 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010114 }
10115
10116 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010117 * Returns the default network type for the given {@code subId}, if the default network type is
10118 * not set, return {@link Phone#PREFERRED_NT_MODE}.
10119 */
10120 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010121 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -080010122 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +090010123 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
10124 return list.get(phoneId);
10125 }
10126 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -070010127 }
fionaxua13278b2018-03-21 00:08:13 -070010128
10129 @Override
10130 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -070010131 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -070010132 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010133
10134 final long identity = Binder.clearCallingIdentity();
10135 try {
10136 final Phone phone = getPhone(subId);
10137 if (phone == null) {
10138 loge("setCarrierTestOverride fails with invalid subId: " + subId);
10139 return;
10140 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -080010141 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10142 if (cpt != null) {
10143 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
10144 }
10145 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -070010146 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
10147 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -070010148 if (carrierPrivilegeRules == null) {
10149 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
10150 } else {
10151 mCarrierPrivilegeTestOverrideSubIds.add(subId);
10152 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010153 } finally {
10154 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010155 }
fionaxua13278b2018-03-21 00:08:13 -070010156 }
10157
10158 @Override
Benedict Wong66477622023-02-03 23:30:57 +000010159 public void setCarrierServicePackageOverride(
10160 int subId, String carrierServicePackage, String callingPackage) {
10161 TelephonyPermissions.enforceShellOnly(
10162 Binder.getCallingUid(), "setCarrierServicePackageOverride");
10163
Benedict Wong66477622023-02-03 23:30:57 +000010164 final long identity = Binder.clearCallingIdentity();
10165 try {
10166 final Phone phone = getPhone(subId);
10167 if (phone == null || phone.getSubId() != subId) {
10168 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
10169 throw new IllegalArgumentException("No phone for subid");
10170 }
10171 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10172 if (cpt == null) {
10173 loge("setCarrierServicePackageOverride failed with no CPT for phone");
10174 throw new IllegalStateException("No CPT for phone");
10175 }
10176 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
10177 } finally {
10178 Binder.restoreCallingIdentity(identity);
10179 }
10180 }
10181
10182 @Override
fionaxua13278b2018-03-21 00:08:13 -070010183 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -070010184 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010185
10186 final long identity = Binder.clearCallingIdentity();
10187 try {
10188 final Phone phone = getPhone(subId);
10189 if (phone == null) {
10190 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
10191 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
10192 }
10193 return phone.getCarrierIdListVersion();
10194 } finally {
10195 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010196 }
fionaxua13278b2018-03-21 00:08:13 -070010197 }
Malcolm Chen2c63d402018-08-14 16:00:53 -070010198
10199 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010200 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
10201 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010202 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010203 mApp, subId, callingPackage, callingFeatureId,
10204 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010205 return -1;
10206 }
10207
10208 final long identity = Binder.clearCallingIdentity();
10209 try {
10210 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10211 } finally {
10212 Binder.restoreCallingIdentity(identity);
10213 }
10214 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010215
10216 @Override
10217 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +080010218 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010219 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010220 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010221
joonhunshin4ac60942023-11-15 15:23:39 +000010222 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10223 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode");
10224
Pengquan Menga1bb6272018-09-06 09:59:22 -070010225 final long identity = Binder.clearCallingIdentity();
10226 try {
10227 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10228 } finally {
10229 Binder.restoreCallingIdentity(identity);
10230 }
10231 }
10232
10233 @Override
10234 public boolean setCdmaRoamingMode(int subId, int mode) {
10235 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10236 mApp, subId, "setCdmaRoamingMode");
10237
joonhunshin4ac60942023-11-15 15:23:39 +000010238 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10239 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode");
10240
Pengquan Menga1bb6272018-09-06 09:59:22 -070010241 final long identity = Binder.clearCallingIdentity();
10242 try {
10243 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10244 } finally {
10245 Binder.restoreCallingIdentity(identity);
10246 }
10247 }
10248
10249 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010250 public int getCdmaSubscriptionMode(int subId) {
10251 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010252 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010253 mApp, subId, "getCdmaSubscriptionMode");
10254
joonhunshin4ac60942023-11-15 15:23:39 +000010255 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10256 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode");
10257
Sarah Chinbaab1432020-10-28 13:46:24 -070010258 final long identity = Binder.clearCallingIdentity();
10259 try {
10260 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10261 } finally {
10262 Binder.restoreCallingIdentity(identity);
10263 }
10264 }
10265
10266 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010267 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10268 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10269 mApp, subId, "setCdmaSubscriptionMode");
10270
joonhunshin4ac60942023-11-15 15:23:39 +000010271 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10272 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode");
10273
Pengquan Menga1bb6272018-09-06 09:59:22 -070010274 final long identity = Binder.clearCallingIdentity();
10275 try {
10276 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10277 } finally {
10278 Binder.restoreCallingIdentity(identity);
10279 }
10280 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010281
sqianc5eccab2018-10-19 18:46:41 -070010282 @Override
sqian8c685422019-02-22 15:55:18 -080010283 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010284 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010285 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010286 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10287 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010288 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10289 }
joonhunshin4ac60942023-11-15 15:23:39 +000010290
10291 enforceTelephonyFeatureWithException(callingPackage,
10292 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList");
10293
sqian11b7a0e2018-12-05 18:48:28 -080010294 final long identity = Binder.clearCallingIdentity();
10295 try {
sqian854d44b2018-12-12 16:48:18 -080010296 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10297 for (Phone phone: PhoneFactory.getPhones()) {
10298 if (phone.getEmergencyNumberTracker() != null
10299 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10300 emergencyNumberListInternal.put(
10301 phone.getSubId(),
10302 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10303 }
sqian11b7a0e2018-12-05 18:48:28 -080010304 }
sqian854d44b2018-12-12 16:48:18 -080010305 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010306 } finally {
10307 Binder.restoreCallingIdentity(identity);
10308 }
sqianc5eccab2018-10-19 18:46:41 -070010309 }
10310
10311 @Override
sqian8c685422019-02-22 15:55:18 -080010312 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010313 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010314 if (!exactMatch) {
10315 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010316 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010317 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010318 }
joonhunshin4ac60942023-11-15 15:23:39 +000010319
10320 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10321 PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber");
10322
sqian11b7a0e2018-12-05 18:48:28 -080010323 final long identity = Binder.clearCallingIdentity();
10324 try {
sqian854d44b2018-12-12 16:48:18 -080010325 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010326 //Note: we ignore passed in param exactMatch. We can remove it once
10327 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010328 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010329 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010330 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010331 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010332 }
sqian11b7a0e2018-12-05 18:48:28 -080010333 }
10334 return false;
10335 } finally {
10336 Binder.restoreCallingIdentity(identity);
10337 }
10338 }
10339
sqianf4ca7ed2019-01-15 18:32:07 -080010340 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010341 * Start emergency callback mode for GsmCdmaPhone for testing.
10342 */
10343 @Override
10344 public void startEmergencyCallbackMode() {
10345 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10346 "startEmergencyCallbackMode");
10347 enforceModifyPermission();
10348 final long identity = Binder.clearCallingIdentity();
10349 try {
10350 for (Phone phone : PhoneFactory.getPhones()) {
10351 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10352 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10353 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10354 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10355 gsmCdmaPhone.obtainMessage(
10356 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10357 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10358 }
10359 }
10360 } finally {
10361 Binder.restoreCallingIdentity(identity);
10362 }
10363 }
10364
10365 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010366 * Update emergency number list for test mode.
10367 */
10368 @Override
10369 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10370 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10371 "updateEmergencyNumberListTestMode");
10372
10373 final long identity = Binder.clearCallingIdentity();
10374 try {
10375 for (Phone phone: PhoneFactory.getPhones()) {
10376 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10377 if (tracker != null) {
10378 tracker.executeEmergencyNumberTestModeCommand(action, num);
10379 }
10380 }
10381 } finally {
10382 Binder.restoreCallingIdentity(identity);
10383 }
10384 }
10385
10386 /**
10387 * Get the full emergency number list for test mode.
10388 */
10389 @Override
10390 public List<String> getEmergencyNumberListTestMode() {
10391 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10392 "getEmergencyNumberListTestMode");
10393
10394 final long identity = Binder.clearCallingIdentity();
10395 try {
10396 Set<String> emergencyNumbers = new HashSet<>();
10397 for (Phone phone: PhoneFactory.getPhones()) {
10398 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10399 if (tracker != null) {
10400 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10401 emergencyNumbers.add(num.getNumber());
10402 }
10403 }
10404 }
10405 return new ArrayList<>(emergencyNumbers);
10406 } finally {
10407 Binder.restoreCallingIdentity(identity);
10408 }
10409 }
10410
chen xud6b45bd2018-10-30 22:27:10 -070010411 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010412 public int getEmergencyNumberDbVersion(int subId) {
10413 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10414
joonhunshin4ac60942023-11-15 15:23:39 +000010415 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10416 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion");
10417
Shuo Qian3b6ee772019-11-13 17:43:31 -080010418 final long identity = Binder.clearCallingIdentity();
10419 try {
10420 final Phone phone = getPhone(subId);
10421 if (phone == null) {
10422 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10423 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10424 }
10425 return phone.getEmergencyNumberDbVersion();
10426 } finally {
10427 Binder.restoreCallingIdentity(identity);
10428 }
10429 }
10430
10431 @Override
10432 public void notifyOtaEmergencyNumberDbInstalled() {
10433 enforceModifyPermission();
10434
joonhunshin4ac60942023-11-15 15:23:39 +000010435 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10436 PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled");
10437
Shuo Qian3b6ee772019-11-13 17:43:31 -080010438 final long identity = Binder.clearCallingIdentity();
10439 try {
10440 for (Phone phone: PhoneFactory.getPhones()) {
10441 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10442 if (tracker != null) {
10443 tracker.updateOtaEmergencyNumberDatabase();
10444 }
10445 }
10446 } finally {
10447 Binder.restoreCallingIdentity(identity);
10448 }
10449 }
10450
10451 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010452 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010453 enforceActiveEmergencySessionPermission();
10454
joonhunshin4ac60942023-11-15 15:23:39 +000010455 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10456 PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath");
10457
Shuo Qian3b6ee772019-11-13 17:43:31 -080010458 final long identity = Binder.clearCallingIdentity();
10459 try {
10460 for (Phone phone: PhoneFactory.getPhones()) {
10461 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10462 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010463 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10464 }
10465 }
10466 } finally {
10467 Binder.restoreCallingIdentity(identity);
10468 }
10469 }
10470
10471 @Override
10472 public void resetOtaEmergencyNumberDbFilePath() {
10473 enforceActiveEmergencySessionPermission();
10474
joonhunshin4ac60942023-11-15 15:23:39 +000010475 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10476 PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath");
10477
Shuo Qianc373f112020-03-05 17:55:34 -080010478 final long identity = Binder.clearCallingIdentity();
10479 try {
10480 for (Phone phone: PhoneFactory.getPhones()) {
10481 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10482 if (tracker != null) {
10483 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010484 }
10485 }
10486 } finally {
10487 Binder.restoreCallingIdentity(identity);
10488 }
10489 }
10490
10491 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010492 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10493 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10494 Phone phone = getPhone(subId);
10495 if (phone == null) {
10496 return null;
10497 }
10498 final long identity = Binder.clearCallingIdentity();
10499 try {
10500 UiccProfile profile = UiccController.getInstance()
10501 .getUiccProfileForPhone(phone.getPhoneId());
10502 if (profile != null) {
10503 return profile.getCertsFromCarrierPrivilegeAccessRules();
10504 }
10505 } finally {
10506 Binder.restoreCallingIdentity(identity);
10507 }
10508 return null;
10509 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010510
10511 /**
10512 * Enable or disable a modem stack.
10513 */
10514 @Override
10515 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10516 enforceModifyPermission();
10517
joonhunshin4ac60942023-11-15 15:23:39 +000010518 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10519 PackageManager.FEATURE_TELEPHONY, "enableModemForSlot");
10520
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010521 final long identity = Binder.clearCallingIdentity();
10522 try {
10523 Phone phone = PhoneFactory.getPhone(slotIndex);
10524 if (phone == null) {
10525 return false;
10526 } else {
10527 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10528 }
10529 } finally {
10530 Binder.restoreCallingIdentity(identity);
10531 }
10532 }
Michelecea4cf22018-12-21 15:00:11 -080010533
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010534 /**
10535 * Whether a modem stack is enabled or not.
10536 */
10537 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010538 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10539 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010540 Phone phone = PhoneFactory.getPhone(slotIndex);
10541 if (phone == null) return false;
10542
10543 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010544 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10545 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010546 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10547 }
10548
joonhunshin4ac60942023-11-15 15:23:39 +000010549 enforceTelephonyFeatureWithException(callingPackage,
10550 PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot");
10551
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010552 final long identity = Binder.clearCallingIdentity();
10553 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010554 try {
10555 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10556 } catch (NoSuchElementException ex) {
10557 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10558 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010559 } finally {
10560 Binder.restoreCallingIdentity(identity);
10561 }
10562 }
10563
Michelecea4cf22018-12-21 15:00:11 -080010564 @Override
Michele0ea7d782019-03-19 14:58:42 -070010565 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010566 enforceModifyPermission();
10567
joonhunshin4ac60942023-11-15 15:23:39 +000010568 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10569 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction");
10570
Michelecea4cf22018-12-21 15:00:11 -080010571 final long identity = Binder.clearCallingIdentity();
10572 try {
10573 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010574 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010575 .commit();
10576 } finally {
10577 Binder.restoreCallingIdentity(identity);
10578 }
10579 }
10580
10581 @Override
Michele0ea7d782019-03-19 14:58:42 -070010582 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010583 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010584 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010585 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10586 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010587 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010588 }
Michelecea4cf22018-12-21 15:00:11 -080010589
joonhunshin4ac60942023-11-15 15:23:39 +000010590 enforceTelephonyFeatureWithException(callingPackage,
10591 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported");
10592
Michelecea4cf22018-12-21 15:00:11 -080010593 final long identity = Binder.clearCallingIdentity();
10594 try {
Michele0ea7d782019-03-19 14:58:42 -070010595 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010596 } finally {
10597 Binder.restoreCallingIdentity(identity);
10598 }
10599 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010600
Michele0ea7d782019-03-19 14:58:42 -070010601 @TelephonyManager.IsMultiSimSupportedResult
10602 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010603 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10604 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10605 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010606 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10607 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010608 }
10609 // Check if the hardware supports multisim functionality. If usage of multisim is not
10610 // supported by the modem, indicate that it is restricted.
10611 PhoneCapability staticCapability =
10612 mPhoneConfigurationManager.getStaticPhoneCapability();
10613 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010614 loge("isMultiSimSupportedInternal: no static configuration available");
10615 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010616 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010617 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010618 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10619 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010620 }
10621 // Check if support of multiple SIMs is restricted by carrier
10622 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010623 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010624 }
10625
Michele0ea7d782019-03-19 14:58:42 -070010626 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010627 }
10628
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010629 /**
10630 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010631 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10632 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10633 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010634 * @param numOfSims number of active sims we want to switch to
10635 */
10636 @Override
10637 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010638 if (numOfSims == 1) {
10639 enforceModifyPermission();
10640 } else {
10641 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10642 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10643 }
joonhunshin4ac60942023-11-15 15:23:39 +000010644
10645 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10646 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig");
10647
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010648 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010649
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010650 try {
Michele30b57b22019-03-01 12:01:14 -080010651 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010652 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010653 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10654 return;
10655 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010656 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10657 } finally {
10658 Binder.restoreCallingIdentity(identity);
10659 }
10660 }
10661
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010662 @Override
10663 public boolean isApplicationOnUicc(int subId, int appType) {
10664 enforceReadPrivilegedPermission("isApplicationOnUicc");
joonhunshin4ac60942023-11-15 15:23:39 +000010665
10666 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10667 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc");
10668
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010669 Phone phone = getPhone(subId);
10670 if (phone == null) {
10671 return false;
10672 }
10673 final long identity = Binder.clearCallingIdentity();
10674 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010675 UiccPort uiccPort = phone.getUiccPort();
10676 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010677 return false;
10678 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010679 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010680 if (uiccProfile == null) {
10681 return false;
10682 }
10683 if (TelephonyManager.APPTYPE_SIM <= appType
10684 && appType <= TelephonyManager.APPTYPE_ISIM) {
10685 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10686 }
10687 return false;
10688 } finally {
10689 Binder.restoreCallingIdentity(identity);
10690 }
10691 }
10692
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010693 /**
chen xub4baa772019-04-03 10:23:41 -070010694 * Get whether making changes to modem configurations will trigger reboot.
10695 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010696 */
10697 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010698 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10699 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010700 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010701 mApp, subId, callingPackage, callingFeatureId,
10702 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010703 return false;
10704 }
joonhunshin4ac60942023-11-15 15:23:39 +000010705
10706 enforceTelephonyFeatureWithException(callingPackage,
10707 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
10708 "doesSwitchMultiSimConfigTriggerReboot");
10709
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010710 final long identity = Binder.clearCallingIdentity();
10711 try {
10712 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10713 } finally {
10714 Binder.restoreCallingIdentity(identity);
10715 }
10716 }
10717
Nathan Harold29f5f052019-02-15 13:41:57 -080010718 private void updateModemStateMetrics() {
10719 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10720 // TODO: check the state for each modem if the api is ready.
10721 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10722 }
10723
Pengquan Meng3889a572019-01-23 11:16:29 -080010724 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010725 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010726 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010727 // Verify that the callingPackage belongs to the calling UID
10728 mApp.getSystemService(AppOpsManager.class)
10729 .checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000010730
10731 enforceTelephonyFeatureWithException(callingPackage,
10732 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping");
10733
Pengquan Meng3889a572019-01-23 11:16:29 -080010734 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010735 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010736 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010737 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10738 if (slotInfos != null) {
10739 for (int i = 0; i < slotInfos.length; i++) {
10740 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10741 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10742 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10743 portInfo.getLogicalSlotIndex()));
10744 }
10745 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010746 }
10747 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010748 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010749 } finally {
10750 Binder.restoreCallingIdentity(identity);
10751 }
10752 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010753
10754 /**
10755 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010756 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010757 */
jimsunf9ec1622022-09-13 21:18:43 +080010758 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010759 @Override
10760 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010761 return getHalVersion(HAL_SERVICE_RADIO);
10762 }
10763
10764 /**
10765 * Get the HAL Version of a specific service
10766 */
10767 @Override
10768 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010769 Phone phone = getDefaultPhone();
10770 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010771 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010772 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10773 return hv.major * 100 + hv.minor;
10774 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010775
10776 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010777 * Get the current calling package name.
sangyun097dcf72024-01-04 10:35:49 +090010778 *
10779 * @return the current calling package name, or null if there is no known package.
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010780 */
10781 @Override
sangyun097dcf72024-01-04 10:35:49 +090010782 public @Nullable String getCurrentPackageName() {
10783 PackageManager pm = mApp.getPackageManager();
10784 String[] packageNames = pm == null ? null : pm.getPackagesForUid(Binder.getCallingUid());
10785 return packageNames == null ? null : packageNames[0];
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010786 }
10787
10788 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010789 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10790 * corresponding network requests on a subId.
10791 *
10792 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010793 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010794 * 2) APN is un-metered for this subscription, or
10795 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010796 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010797 *
10798 * @return whether data is allowed for a apn type.
10799 *
10800 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010801 */
10802 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010803 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010804 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10805 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010806
joonhunshin4ac60942023-11-15 15:23:39 +000010807 enforceTelephonyFeatureWithException(callingPackage,
10808 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn");
10809
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010810 // Now that all security checks passes, perform the operation as ourselves.
10811 final long identity = Binder.clearCallingIdentity();
10812 try {
10813 Phone phone = getPhone(subId);
10814 if (phone == null) return false;
10815
Jack Yu27422a52022-03-21 10:38:05 -070010816 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010817 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010818 isMetered = phone.getDataNetworkController().getDataConfigManager()
10819 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10820 phone.getServiceState().getDataRoaming());
10821 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010822 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010823 } finally {
10824 Binder.restoreCallingIdentity(identity);
10825 }
10826 }
10827
10828 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010829 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010830 enforceReadPrivilegedPermission("isApnMetered");
10831
joonhunshin4ac60942023-11-15 15:23:39 +000010832 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10833 PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered");
10834
Malcolm Chene5ad5792019-04-18 13:51:02 -070010835 // Now that all security checks passes, perform the operation as ourselves.
10836 final long identity = Binder.clearCallingIdentity();
10837 try {
10838 Phone phone = getPhone(subId);
10839 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010840 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10841 DataUtils.apnTypeToNetworkCapability(apnType),
10842 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010843 } finally {
10844 Binder.restoreCallingIdentity(identity);
10845 }
10846 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010847
10848 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010849 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10850 int subscriptionId, IBooleanConsumer resultCallback) {
10851 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +000010852
10853 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10854 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels");
10855
Hall Liu73f5d362020-01-20 13:42:00 -080010856 long token = Binder.clearCallingIdentity();
10857 try {
10858 Phone phone = getPhone(subscriptionId);
10859 if (phone == null) {
10860 try {
10861 if (resultCallback != null) {
10862 resultCallback.accept(false);
10863 }
10864 } catch (RemoteException e) {
10865 // ignore
10866 }
10867 return;
10868 }
10869 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10870 Pair.create(specifiers, (x) -> {
10871 try {
10872 if (resultCallback != null) {
10873 resultCallback.accept(x);
10874 }
10875 } catch (RemoteException e) {
10876 // ignore
10877 }
10878 });
10879 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10880 } finally {
10881 Binder.restoreCallingIdentity(token);
10882 }
10883 }
10884
10885 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010886 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10887 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010888 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010889 mApp, subId, "getSystemSelectionChannels");
joonhunshin4ac60942023-11-15 15:23:39 +000010890
10891 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10892 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels");
10893
Sarah Chin679c08a2020-11-18 13:39:35 -080010894 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10895 final long identity = Binder.clearCallingIdentity();
10896 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010897 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10898 if (result instanceof IllegalStateException) {
10899 throw (IllegalStateException) result;
10900 }
10901 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010902 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10903 return specifiers;
10904 } finally {
10905 Binder.restoreCallingIdentity(identity);
10906 }
10907 }
10908
10909 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010910 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010911 enforceReadPrivilegedPermission("isMvnoMatched");
joonhunshin4ac60942023-11-15 15:23:39 +000010912
10913 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10914 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched");
10915
Jack Yu8b766fc2022-03-21 09:42:33 -070010916 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010917 }
10918
10919 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010920 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10921 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010922 if (callingPackage == null) {
10923 callingPackage = getCurrentPackageName();
10924 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010925 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10926 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010927 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10928 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010929 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10930 }
10931 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10932 Intent intent = new Intent();
10933 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10934 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10935 // Bring up choose default SMS subscription dialog right now
10936 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10937 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10938 mApp.startActivity(intent);
10939 }
chen xud5ca2d52019-05-28 15:20:57 -070010940
10941 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010942 public void showSwitchToManagedProfileDialog() {
10943 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000010944 try {
10945 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
10946 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
10947 // for work telephony.
10948 Intent intent = new Intent(Intent.ACTION_SENDTO);
10949 intent.setData(Uri.parse("smsto:"));
10950 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10951 mApp.startActivity(intent);
10952 } catch (ActivityNotFoundException e) {
10953 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
10954 Intent intent = new Intent();
10955 intent.setClass(mApp, ErrorDialogActivity.class);
10956 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10957 mApp.startActivity(intent);
10958 }
Ayush Sharma787854b2022-12-12 14:55:02 +000010959 }
10960
10961 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010962 public String getMmsUAProfUrl(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000010963 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10964 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl");
10965
chen xud5ca2d52019-05-28 15:20:57 -070010966 //TODO investigate if this API should require proper permission check in R b/133791609
10967 final long identity = Binder.clearCallingIdentity();
10968 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010969 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10970 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10971 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10972 return carrierUAProfUrl;
10973 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010974 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10975 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010976 } finally {
10977 Binder.restoreCallingIdentity(identity);
10978 }
10979 }
10980
10981 @Override
10982 public String getMmsUserAgent(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000010983 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10984 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent");
10985
chen xud5ca2d52019-05-28 15:20:57 -070010986 //TODO investigate if this API should require proper permission check in R b/133791609
10987 final long identity = Binder.clearCallingIdentity();
10988 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010989 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10990 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10991 if (!TextUtils.isEmpty(carrierUserAgent)) {
10992 return carrierUserAgent;
10993 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010994 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10995 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010996 } finally {
10997 Binder.restoreCallingIdentity(identity);
10998 }
10999 }
Jack Yub07d4972019-05-28 16:12:25 -070011000
11001 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070011002 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
11003 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070011004
joonhunshin4ac60942023-11-15 15:23:39 +000011005 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11006 PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled");
11007
Jack Yub07d4972019-05-28 16:12:25 -070011008 final long identity = Binder.clearCallingIdentity();
11009 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011010 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070011011 if (phone == null) return false;
11012
Ling Maf188d502022-09-16 15:22:36 -070011013 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070011014 } finally {
11015 Binder.restoreCallingIdentity(identity);
11016 }
11017 }
11018
11019 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080011020 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070011021 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080011022 enforceModifyPermission();
11023
joonhunshin4ac60942023-11-15 15:23:39 +000011024 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11025 PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled");
11026
changbettyd5c246e2019-12-24 15:40:37 +080011027 final long identity = Binder.clearCallingIdentity();
11028 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011029 Phone phone = getPhone(subscriptionId);
11030 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080011031
Ling Maf188d502022-09-16 15:22:36 -070011032 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080011033 } finally {
11034 Binder.restoreCallingIdentity(identity);
11035 }
11036 }
11037
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011038 /**
Hall Liu746e03c2020-09-25 11:13:49 -070011039 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011040 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
11041 * otherwise.
11042 */
11043 @Override
11044 public void setCepEnabled(boolean isCepEnabled) {
11045 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
11046
11047 final long identity = Binder.clearCallingIdentity();
11048 try {
11049 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
11050 for (Phone phone : PhoneFactory.getPhones()) {
11051 Phone defaultPhone = phone.getImsPhone();
11052 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
11053 ImsPhone imsPhone = (ImsPhone) defaultPhone;
11054 ImsPhoneCallTracker imsPhoneCallTracker =
11055 (ImsPhoneCallTracker) imsPhone.getCallTracker();
11056 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
11057 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
11058 + imsPhone.getMsisdn());
11059 }
11060 }
11061 } finally {
11062 Binder.restoreCallingIdentity(identity);
11063 }
11064 }
allenwtsu46dcc572020-01-08 18:24:03 +080011065
11066 /**
11067 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
11068 *
11069 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
11070 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
11071 * before being read.
11072 */
11073 @Override
11074 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
11075 isCompressed) {
11076 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11077 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011078 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11079 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11080 }
joonhunshin4ac60942023-11-15 15:23:39 +000011081
11082 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11083 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11084 Binder.getCallingUserHandle())) {
11085 if (!isImsAvailableOnDevice()) {
11086 // ProvisioningManager can not handle ServiceSpecificException.
11087 // Throw the IllegalStateException and annotate ProvisioningManager.
11088 throw new IllegalStateException("IMS not available on device.");
11089 }
11090 } else {
11091 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11092 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11093 "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011094 }
11095
11096 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080011097 try {
Hui Wang761a6682020-10-31 05:12:53 +000011098 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
11099 } finally {
11100 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080011101 }
11102 }
zoey chene02881a2019-12-30 16:11:23 +080011103
11104 @Override
11105 public boolean isIccLockEnabled(int subId) {
11106 enforceReadPrivilegedPermission("isIccLockEnabled");
11107
joonhunshin4ac60942023-11-15 15:23:39 +000011108 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11109 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled");
11110
zoey chene02881a2019-12-30 16:11:23 +080011111 // Now that all security checks passes, perform the operation as ourselves.
11112 final long identity = Binder.clearCallingIdentity();
11113 try {
11114 Phone phone = getPhone(subId);
11115 if (phone != null && phone.getIccCard() != null) {
11116 return phone.getIccCard().getIccLockEnabled();
11117 } else {
11118 return false;
11119 }
11120 } finally {
11121 Binder.restoreCallingIdentity(identity);
11122 }
11123 }
11124
11125 /**
11126 * Set the ICC pin lock enabled or disabled.
11127 *
11128 * @return an integer representing the status of IccLock enabled or disabled in the following
11129 * three cases:
11130 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
11131 * successfully.
11132 * - Positive number and zero for remaining password attempts.
11133 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11134 *
11135 */
11136 @Override
11137 public int setIccLockEnabled(int subId, boolean enabled, String password) {
11138 enforceModifyPermission();
11139
joonhunshin4ac60942023-11-15 15:23:39 +000011140 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11141 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled");
11142
zoey chene02881a2019-12-30 16:11:23 +080011143 Phone phone = getPhone(subId);
11144 if (phone == null) {
11145 return 0;
11146 }
11147 // Now that all security checks passes, perform the operation as ourselves.
11148 final long identity = Binder.clearCallingIdentity();
11149 try {
11150 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
11151 new Pair<Boolean, String>(enabled, password), phone, null);
11152 return attemptsRemaining;
11153
11154 } catch (Exception e) {
11155 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
11156 } finally {
11157 Binder.restoreCallingIdentity(identity);
11158 }
11159 return 0;
11160 }
11161
11162 /**
11163 * Change the ICC password used in ICC pin lock.
11164 *
11165 * @return an integer representing the status of IccLock changed in the following three cases:
11166 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
11167 * - Positive number and zero for remaining password attempts.
11168 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11169 *
11170 */
11171 @Override
11172 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
11173 enforceModifyPermission();
11174
joonhunshin4ac60942023-11-15 15:23:39 +000011175 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11176 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword");
11177
zoey chene02881a2019-12-30 16:11:23 +080011178 Phone phone = getPhone(subId);
11179 if (phone == null) {
11180 return 0;
11181 }
11182 // Now that all security checks passes, perform the operation as ourselves.
11183 final long identity = Binder.clearCallingIdentity();
11184 try {
11185 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
11186 new Pair<String, String>(oldPassword, newPassword), phone, null);
11187 return attemptsRemaining;
11188
11189 } catch (Exception e) {
11190 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
11191 } finally {
11192 Binder.restoreCallingIdentity(identity);
11193 }
11194 return 0;
11195 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080011196
11197 /**
11198 * Request for receiving user activity notification
11199 */
11200 @Override
11201 public void requestUserActivityNotification() {
11202 if (!mNotifyUserActivity.get()
11203 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
11204 mNotifyUserActivity.set(true);
11205 }
11206 }
11207
11208 /**
11209 * Called when userActivity is signalled in the power manager.
11210 * This is safe to call from any thread, with any window manager locks held or not.
11211 */
11212 @Override
11213 public void userActivity() {
11214 // ***************************************
11215 // * Inherited from PhoneWindowManager *
11216 // ***************************************
11217 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
11218 // WITH ITS LOCKS HELD.
11219 //
11220 // This code must be VERY careful about the locks
11221 // it acquires.
11222 // In fact, the current code acquires way too many,
11223 // and probably has lurking deadlocks.
11224
11225 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
11226 throw new SecurityException("Only the OS may call notifyUserActivity()");
11227 }
11228
11229 if (mNotifyUserActivity.getAndSet(false)) {
11230 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
11231 USER_ACTIVITY_NOTIFICATION_DELAY);
11232 }
11233 }
Malcolm Chen4639c562020-04-13 11:59:40 -070011234
11235 @Override
11236 public boolean canConnectTo5GInDsdsMode() {
11237 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
11238 }
Jack Yud10cdd42020-09-28 20:28:01 -070011239
11240 @Override
11241 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
11242 String callingFeatureId) {
11243 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
11244 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
11245 throw new SecurityException("Requires READ_PHONE_STATE permission.");
11246 }
11247
joonhunshin4ac60942023-11-15 15:23:39 +000011248 enforceTelephonyFeatureWithException(callingPackage,
11249 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns");
11250
Jack Yud10cdd42020-09-28 20:28:01 -070011251 Phone phone = getPhone(subId);
11252 if (phone == null) {
11253 throw new RuntimeException("phone is not available");
11254 }
11255 // Now that all security checks passes, perform the operation as ourselves.
11256 final long identity = Binder.clearCallingIdentity();
11257 try {
11258 return phone.getEquivalentHomePlmns();
11259 } finally {
11260 Binder.restoreCallingIdentity(identity);
11261 }
11262 }
Daniel Bright59e67312020-11-13 11:49:37 -080011263
11264 @Override
11265 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011266 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
joonhunshin4ac60942023-11-15 15:23:39 +000011267 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11268 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
11269 "isRadioInterfaceCapabilitySupported");
11270
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011271 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080011272 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080011273 if (radioInterfaceCapabilities == null) {
11274 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080011275 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011276 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080011277 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011278
Hui Wang641e81c2020-10-12 12:14:23 -070011279 @Override
11280 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
11281 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000011282 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
11283 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11284 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
11285 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11286 Manifest.permission.MODIFY_PHONE_STATE);
joonhunshin4ac60942023-11-15 15:23:39 +000011287
11288 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11289 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest");
11290
Hui Wang641e81c2020-10-12 12:14:23 -070011291 if (DBG) {
11292 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
11293 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
11294 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
11295 }
11296
11297 if (!SubscriptionManager.isValidSubscriptionId(subId)
11298 || appType < TelephonyManager.APPTYPE_UNKNOWN
11299 || appType > TelephonyManager.APPTYPE_ISIM
11300 || nafUrl == null || securityProtocol == null || callback == null) {
11301 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
11302 if (callback != null) {
11303 try {
11304 callback.onAuthenticationFailure(
11305 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
11306 } catch (RemoteException exception) {
11307 log("Fail to notify onAuthenticationFailure due to " + exception);
11308 }
11309 return;
11310 }
11311 }
11312
11313 final long token = Binder.clearCallingIdentity();
11314 try {
11315 getGbaManager(subId).bootstrapAuthenticationRequest(
11316 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011317 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070011318 } finally {
11319 Binder.restoreCallingIdentity(token);
11320 }
11321 }
11322
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011323 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011324 * Attempts to set the radio power state for all phones for thermal reason.
11325 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011326 * requested radio power state will actually be set. See {@link
11327 * PhoneInternalInterface#setRadioPowerForReason} for more details.
11328 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011329 * @param enable {@code true} if trying to turn radio on.
11330 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
11331 * false}.
11332 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011333 private boolean setRadioPowerForThermal(boolean enable) {
11334 boolean isPhoneAvailable = false;
11335 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
11336 Phone phone = PhoneFactory.getPhone(i);
11337 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011338 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011339 isPhoneAvailable = true;
11340 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011341 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011342
11343 // return true if successfully informed the phone object about the thermal radio power
11344 // request.
11345 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011346 }
11347
11348 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011349 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011350 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11351 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11352 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11353 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11354 throw new IllegalArgumentException("modem does not support data throttling");
11355 }
11356
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011357 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11358 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011359 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011360 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11361 }
11362
Sarah Chinecc78c42022-03-31 21:16:48 -070011363 setDataEnabledForReason(
11364 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011365
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011366 if (isDataThrottlingSupported) {
11367 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011368 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011369 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11370 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11371 } else if (thermalMitigationResult
11372 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011373 log("Modem likely does not support data throttling on secondary carrier. Data " +
11374 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11375 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011376 }
11377 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011378 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011379
11380 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011381 }
11382
Jack Nudelman644b91a2021-03-12 14:09:48 -080011383 private static List<String> getThermalMitigationAllowlist(Context context) {
11384 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11385 for (String pckg : context.getResources()
11386 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11387 sThermalMitigationAllowlistedPackages.add(pckg);
11388 }
11389 }
11390
11391 return sThermalMitigationAllowlistedPackages;
11392 }
11393
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011394 private boolean isAnyPhoneInEmergencyState() {
11395 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11396 if (tm.isInEmergencyCall()) {
11397 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11398 return true;
11399 }
11400 for (Phone phone : PhoneFactory.getPhones()) {
11401 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11402 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011403 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11404 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011405 return true;
11406 }
11407 }
11408
11409 return false;
11410 }
11411
Jack Nudelman644b91a2021-03-12 14:09:48 -080011412 /**
11413 * Used by shell commands to add an authorized package name for thermal mitigation.
11414 * @param packageName name of package to be allowlisted
11415 * @param context
11416 */
11417 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11418 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11419 sThermalMitigationAllowlistedPackages.add(packageName);
11420 }
11421
11422 /**
11423 * Used by shell commands to remove an authorized package name for thermal mitigation.
11424 * @param packageName name of package to remove from allowlist
11425 * @param context
11426 */
11427 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11428 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11429 sThermalMitigationAllowlistedPackages.remove(packageName);
11430 }
11431
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011432 /**
11433 * Thermal mitigation request to control functionalities at modem.
11434 *
11435 * @param subId the id of the subscription.
11436 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011437 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011438 *
11439 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11440 */
11441 @Override
11442 @ThermalMitigationResult
11443 public int sendThermalMitigationRequest(
11444 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011445 ThermalMitigationRequest thermalMitigationRequest,
11446 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011447 enforceModifyPermission();
11448
Jack Nudelman644b91a2021-03-12 14:09:48 -080011449 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000011450
11451 enforceTelephonyFeatureWithException(callingPackage,
11452 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest");
11453
Jack Nudelman644b91a2021-03-12 14:09:48 -080011454 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11455 .contains(callingPackage)) {
11456 throw new SecurityException("Calling package must be configured in the device config. "
11457 + "calling package: " + callingPackage);
11458 }
11459
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011460 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11461 final long identity = Binder.clearCallingIdentity();
11462
11463 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11464 try {
11465 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11466 switch (thermalMitigationAction) {
11467 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11468 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011469 handleDataThrottlingRequest(subId,
11470 thermalMitigationRequest.getDataThrottlingRequest(),
11471 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011472 break;
11473 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11474 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11475 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11476 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11477 }
11478
11479 // Ensure that radio is on. If not able to power on due to phone being
11480 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011481 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011482 thermalMitigationResult =
11483 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11484 break;
11485 }
11486
11487 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011488 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011489 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11490 break;
11491 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11492 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11493 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11494 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11495 }
11496
11497 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11498 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011499 Phone phone = getPhone(subId);
11500 if (phone == null) {
11501 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011502 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011503 break;
11504 }
11505
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011506 TelephonyConnectionService service =
11507 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011508 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011509 Log.e(LOG_TAG, "An emergency call is pending");
11510 thermalMitigationResult =
11511 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11512 break;
11513 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011514 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011515 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011516 break;
11517 }
11518 } else {
11519 thermalMitigationResult =
11520 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11521 break;
11522 }
11523
11524 // Turn radio off. If not able to power off due to phone being unavailable,
11525 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011526 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011527 thermalMitigationResult =
11528 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11529 break;
11530 }
11531 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011532 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011533 break;
11534 default:
11535 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11536 + "not exist. Requested action: " + thermalMitigationAction);
11537 }
11538 } catch (IllegalArgumentException e) {
11539 throw e;
11540 } catch (Exception e) {
11541 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11542 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11543 } finally {
11544 Binder.restoreCallingIdentity(identity);
11545 }
11546
11547 if (DBG) {
11548 log("thermalMitigationRequest returning with thermalMitigationResult: "
11549 + thermalMitigationResult);
11550 }
11551
11552 return thermalMitigationResult;
11553 }
Hui Wang641e81c2020-10-12 12:14:23 -070011554
11555 /**
11556 * Set the GbaService Package Name that Telephony will bind to.
11557 *
11558 * @param subId The sim that the GbaService is associated with.
11559 * @param packageName The name of the package to be replaced with.
11560 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11561 */
11562 @Override
11563 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11564 enforceModifyPermission();
11565
11566 final long identity = Binder.clearCallingIdentity();
11567 try {
11568 return getGbaManager(subId).overrideServicePackage(packageName);
11569 } finally {
11570 Binder.restoreCallingIdentity(identity);
11571 }
11572 }
11573
11574 /**
11575 * Return the package name of the currently bound GbaService.
11576 *
11577 * @param subId The sim that the GbaService is associated with.
11578 * @return the package name of the GbaService configuration, null if GBA is not supported.
11579 */
11580 @Override
11581 public String getBoundGbaService(int subId) {
11582 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11583
11584 final long identity = Binder.clearCallingIdentity();
11585 try {
11586 return getGbaManager(subId).getServicePackage();
11587 } finally {
11588 Binder.restoreCallingIdentity(identity);
11589 }
11590 }
11591
11592 /**
11593 * Set the release time for telephony to unbind GbaService.
11594 *
11595 * @param subId The sim that the GbaService is associated with.
11596 * @param interval The release time to unbind GbaService by millisecond.
11597 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11598 */
11599 @Override
11600 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11601 enforceModifyPermission();
11602
11603 final long identity = Binder.clearCallingIdentity();
11604 try {
11605 return getGbaManager(subId).overrideReleaseTime(interval);
11606 } finally {
11607 Binder.restoreCallingIdentity(identity);
11608 }
11609 }
11610
11611 /**
11612 * Return the release time for telephony to unbind GbaService.
11613 *
11614 * @param subId The sim that the GbaService is associated with.
11615 * @return The release time to unbind GbaService by millisecond.
11616 */
11617 @Override
11618 public int getGbaReleaseTime(int subId) {
11619 enforceReadPrivilegedPermission("getGbaReleaseTime");
11620
11621 final long identity = Binder.clearCallingIdentity();
11622 try {
11623 return getGbaManager(subId).getReleaseTime();
11624 } finally {
11625 Binder.restoreCallingIdentity(identity);
11626 }
11627 }
11628
11629 private GbaManager getGbaManager(int subId) {
11630 GbaManager instance = GbaManager.getInstance(subId);
11631 if (instance == null) {
11632 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11633 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11634 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11635 }
11636 return instance;
11637 }
Hui Wang761a6682020-10-31 05:12:53 +000011638
11639 /**
11640 * indicate whether the device and the carrier can support
11641 * RCS VoLTE single registration.
11642 */
11643 @Override
11644 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011645 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11646 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11647 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11648 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011649
11650 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11651 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11652 }
11653
11654 final long identity = Binder.clearCallingIdentity();
11655 try {
11656 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11657 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011658 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11659 if (isCapable != null) {
11660 return isCapable;
11661 }
Hui Wang761a6682020-10-31 05:12:53 +000011662 }
Hui Wang67af90e2021-06-04 16:57:15 -070011663 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11664 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011665 } finally {
11666 Binder.restoreCallingIdentity(identity);
11667 }
11668 }
11669
11670 /**
11671 * Register RCS provisioning callback.
11672 */
11673 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011674 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011675 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011676 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011677 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011678 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11679 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011680
11681 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11682 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11683 }
joonhunshin4ac60942023-11-15 15:23:39 +000011684 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11685 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11686 Binder.getCallingUserHandle())) {
11687 if (!isImsAvailableOnDevice()) {
11688 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11689 "IMS not available on device.");
11690 }
11691 } else {
11692 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11693 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011694 }
11695
11696 final long identity = Binder.clearCallingIdentity();
11697 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011698 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011699 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011700 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11701 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011702 }
Hui Wang761a6682020-10-31 05:12:53 +000011703 } finally {
11704 Binder.restoreCallingIdentity(identity);
11705 }
11706 }
11707
11708 /**
11709 * Unregister RCS provisioning callback.
11710 */
11711 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011712 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011713 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011714 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011715 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011716 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11717 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011718
11719 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11720 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11721 }
joonhunshin4ac60942023-11-15 15:23:39 +000011722
11723 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11724 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11725 Binder.getCallingUserHandle())) {
11726 if (!isImsAvailableOnDevice()) {
11727 // operation failed silently
11728 Rlog.w(LOG_TAG, "IMS not available on device.");
11729 return;
11730 }
11731 } else {
11732 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11733 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11734 "unregisterRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011735 }
11736
11737 final long identity = Binder.clearCallingIdentity();
11738 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011739 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011740 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011741 } finally {
11742 Binder.restoreCallingIdentity(identity);
11743 }
11744 }
11745
11746 /**
11747 * trigger RCS reconfiguration.
11748 */
11749 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011750 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11751 "triggerRcsReconfiguration",
11752 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011753
11754 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11755 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11756 }
joonhunshin4ac60942023-11-15 15:23:39 +000011757 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11758 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11759 Binder.getCallingUserHandle())) {
11760 if (!isImsAvailableOnDevice()) {
11761 // ProvisioningManager can not handle ServiceSpecificException.
11762 // Throw the IllegalStateException and annotate ProvisioningManager.
11763 throw new IllegalStateException("IMS not available on device.");
11764 }
11765 } else {
11766 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11767 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011768 }
11769
11770 final long identity = Binder.clearCallingIdentity();
11771 try {
11772 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11773 } finally {
11774 Binder.restoreCallingIdentity(identity);
11775 }
11776 }
11777
11778 /**
11779 * Provide the client configuration parameters of the RCS application.
11780 */
11781 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011782 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11783 "setRcsClientConfiguration",
11784 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011785
11786 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11787 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11788 }
joonhunshin4ac60942023-11-15 15:23:39 +000011789 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11790 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11791 Binder.getCallingUserHandle())) {
11792 if (!isImsAvailableOnDevice()) {
11793 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11794 "IMS not available on device.");
11795 }
11796 } else {
11797 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11798 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011799 }
11800
11801 final long identity = Binder.clearCallingIdentity();
11802
11803 try {
11804 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11805 if (configBinder == null) {
11806 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011807 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11808 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011809 } else {
11810 configBinder.setRcsClientConfiguration(rcc);
11811 }
joonhunshin3e154242021-09-17 06:33:39 +000011812
11813 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11814 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011815 } catch (RemoteException e) {
11816 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011817 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11818 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011819 } finally {
11820 Binder.restoreCallingIdentity(identity);
11821 }
11822 }
11823
11824 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011825 * Enables or disables the test mode for RCS VoLTE single registration.
11826 */
11827 @Override
11828 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11829 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11830 "setRcsSingleRegistrationTestModeEnabled");
11831
11832 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11833 }
11834
11835 /**
11836 * Gets the test mode for RCS VoLTE single registration.
11837 */
11838 @Override
11839 public boolean getRcsSingleRegistrationTestModeEnabled() {
11840 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11841 "getRcsSingleRegistrationTestModeEnabled");
11842
11843 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11844 }
11845
11846 /**
Hui Wang761a6682020-10-31 05:12:53 +000011847 * Overrides the config of RCS VoLTE single registration enabled for the device.
11848 */
11849 @Override
11850 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11851 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11852 "setDeviceSingleRegistrationEnabledOverride");
11853 enforceModifyPermission();
11854
11855 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11856 : Boolean.parseBoolean(enabledStr);
11857 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011858 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011859 }
11860
11861 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011862 * Sends a device to device communication message. Only usable via shell.
11863 * @param message message to send.
11864 * @param value message value.
11865 */
11866 @Override
11867 public void sendDeviceToDeviceMessage(int message, int value) {
11868 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011869 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011870 enforceModifyPermission();
11871
11872 final long identity = Binder.clearCallingIdentity();
11873 try {
11874 TelephonyConnectionService service =
11875 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11876 if (service == null) {
11877 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11878 return;
11879 }
11880 service.sendTestDeviceToDeviceMessage(message, value);
11881 } finally {
11882 Binder.restoreCallingIdentity(identity);
11883 }
11884 }
11885
Tyler Gunnbabbda02021-02-10 11:05:02 -080011886 /**
11887 * Sets the specified device to device transport active.
11888 * @param transport The transport to set active.
11889 */
11890 @Override
11891 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11892 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11893 "setActiveDeviceToDeviceTransport");
11894 enforceModifyPermission();
11895
11896 final long identity = Binder.clearCallingIdentity();
11897 try {
11898 TelephonyConnectionService service =
11899 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11900 if (service == null) {
11901 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11902 return;
11903 }
11904 service.setActiveDeviceToDeviceTransport(transport);
11905 } finally {
11906 Binder.restoreCallingIdentity(identity);
11907 }
11908 }
Tyler Gunn92479152021-01-20 16:30:10 -080011909
Tyler Gunnd4339262021-05-03 14:46:49 -070011910 @Override
11911 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11912 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11913 "setDeviceToDeviceForceEnabled");
11914
11915 final long identity = Binder.clearCallingIdentity();
11916 try {
11917 Arrays.stream(PhoneFactory.getPhones()).forEach(
11918 p -> {
11919 Phone thePhone = p.getImsPhone();
11920 if (thePhone != null && thePhone instanceof ImsPhone) {
11921 ImsPhone imsPhone = (ImsPhone) thePhone;
11922 CallTracker tracker = imsPhone.getCallTracker();
11923 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11924 ImsPhoneCallTracker imsPhoneCallTracker =
11925 (ImsPhoneCallTracker) tracker;
11926 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11927 }
11928 }
11929 }
11930 );
11931 } finally {
11932 Binder.restoreCallingIdentity(identity);
11933 }
11934 }
11935
Tyler Gunn92479152021-01-20 16:30:10 -080011936 /**
Hui Wang761a6682020-10-31 05:12:53 +000011937 * Gets the config of RCS VoLTE single registration enabled for the device.
11938 */
11939 @Override
11940 public boolean getDeviceSingleRegistrationEnabled() {
11941 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11942 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11943 }
11944
11945 /**
11946 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11947 */
11948 @Override
11949 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11950 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11951 "setCarrierSingleRegistrationEnabledOverride");
11952 enforceModifyPermission();
11953
11954 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11955 : Boolean.parseBoolean(enabledStr);
11956 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11957 subId, enabled);
11958 }
11959
11960 /**
11961 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11962 */
11963 @Override
11964 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11965 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11966 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11967 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011968
11969 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011970 * Overrides the ims feature validation result
11971 */
11972 @Override
11973 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11974 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11975 "setImsFeatureValidationOverride");
11976
11977 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11978 : Boolean.parseBoolean(enabledStr);
11979 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11980 subId, enabled);
11981 }
11982
11983 /**
11984 * Gets the ims feature validation override value
11985 */
11986 @Override
11987 public boolean getImsFeatureValidationOverride(int subId) {
11988 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11989 "getImsFeatureValidationOverride");
11990 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11991 }
11992
11993 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011994 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11995 * their mobile plan.
11996 */
11997 @Override
11998 public String getMobileProvisioningUrl() {
11999 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
12000 final long identity = Binder.clearCallingIdentity();
12001 try {
12002 return getDefaultPhone().getMobileProvisioningUrl();
12003 } finally {
12004 Binder.restoreCallingIdentity(identity);
12005 }
12006 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012007
James.cf Linbcdf8b32021-01-14 16:44:13 +080012008 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080012009 * Get the EAB contact from the EAB database.
12010 */
12011 @Override
12012 public String getContactFromEab(String contact) {
12013 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
12014 enforceModifyPermission();
12015 final long identity = Binder.clearCallingIdentity();
12016 try {
12017 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
12018 } finally {
12019 Binder.restoreCallingIdentity(identity);
12020 }
12021 }
12022
12023 /**
Calvin Pana1434322021-07-01 19:27:01 +080012024 * Get the EAB capability from the EAB database.
12025 */
12026 @Override
12027 public String getCapabilityFromEab(String contact) {
12028 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
12029 enforceModifyPermission();
12030 final long identity = Binder.clearCallingIdentity();
12031 try {
12032 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
12033 } finally {
12034 Binder.restoreCallingIdentity(identity);
12035 }
12036 }
12037
12038 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080012039 * Remove the EAB contacts from the EAB database.
12040 */
12041 @Override
12042 public int removeContactFromEab(int subId, String contacts) {
12043 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
12044 enforceModifyPermission();
12045 final long identity = Binder.clearCallingIdentity();
12046 try {
12047 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
12048 } finally {
12049 Binder.restoreCallingIdentity(identity);
12050 }
12051 }
12052
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012053 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080012054 public boolean getDeviceUceEnabled() {
12055 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
12056 final long identity = Binder.clearCallingIdentity();
12057 try {
12058 return mApp.getDeviceUceEnabled();
12059 } finally {
12060 Binder.restoreCallingIdentity(identity);
12061 }
12062 }
12063
12064 @Override
12065 public void setDeviceUceEnabled(boolean isEnabled) {
12066 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
12067 final long identity = Binder.clearCallingIdentity();
12068 try {
12069 mApp.setDeviceUceEnabled(isEnabled);
12070 } finally {
12071 Binder.restoreCallingIdentity(identity);
12072 }
12073 }
12074
Brad Ebinger14d467f2021-02-12 06:18:28 +000012075 /**
12076 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
12077 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12078 */
12079 // Used for SHELL command only right now.
12080 @Override
12081 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
12082 List<String> featureTags) {
12083 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12084 "addUceRegistrationOverrideShell");
12085 final long identity = Binder.clearCallingIdentity();
12086 try {
12087 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
12088 new ArraySet<>(featureTags));
12089 } catch (ImsException e) {
12090 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12091 } finally {
12092 Binder.restoreCallingIdentity(identity);
12093 }
12094 }
12095
12096 /**
12097 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
12098 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12099 */
12100 // Used for SHELL command only right now.
12101 @Override
12102 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
12103 List<String> featureTags) {
12104 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12105 "removeUceRegistrationOverrideShell");
12106 final long identity = Binder.clearCallingIdentity();
12107 try {
12108 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
12109 new ArraySet<>(featureTags));
12110 } catch (ImsException e) {
12111 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12112 } finally {
12113 Binder.restoreCallingIdentity(identity);
12114 }
12115 }
12116
12117 /**
12118 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
12119 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12120 */
12121 // Used for SHELL command only right now.
12122 @Override
12123 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
12124 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12125 "clearUceRegistrationOverrideShell");
12126 final long identity = Binder.clearCallingIdentity();
12127 try {
12128 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
12129 } catch (ImsException e) {
12130 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12131 } finally {
12132 Binder.restoreCallingIdentity(identity);
12133 }
12134 }
12135
12136 /**
12137 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12138 */
12139 // Used for SHELL command only right now.
12140 @Override
12141 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
12142 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12143 "getLatestRcsContactUceCapabilityShell");
12144 final long identity = Binder.clearCallingIdentity();
12145 try {
12146 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
12147 } catch (ImsException e) {
12148 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12149 } finally {
12150 Binder.restoreCallingIdentity(identity);
12151 }
12152 }
12153
12154 /**
12155 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
12156 * device does not have an active PUBLISH.
12157 */
12158 // Used for SHELL command only right now.
12159 @Override
12160 public String getLastUcePidfXmlShell(int subId) {
12161 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
12162 final long identity = Binder.clearCallingIdentity();
12163 try {
12164 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
12165 } catch (ImsException e) {
12166 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12167 } finally {
12168 Binder.restoreCallingIdentity(identity);
12169 }
12170 }
12171
James.cf Line8713a42021-04-29 16:04:26 +080012172 /**
12173 * Remove UCE requests cannot be sent to the network status.
12174 */
12175 // Used for SHELL command only right now.
12176 @Override
12177 public boolean removeUceRequestDisallowedStatus(int subId) {
12178 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
12179 final long identity = Binder.clearCallingIdentity();
12180 try {
12181 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
12182 } catch (ImsException e) {
12183 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12184 } finally {
12185 Binder.restoreCallingIdentity(identity);
12186 }
12187 }
12188
James.cf Lin18bb9002021-05-25 01:37:38 +080012189 /**
12190 * Remove UCE requests cannot be sent to the network status.
12191 */
12192 // Used for SHELL command only.
12193 @Override
12194 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
12195 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
12196 final long identity = Binder.clearCallingIdentity();
12197 try {
12198 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
12199 } catch (ImsException e) {
12200 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12201 } finally {
12202 Binder.restoreCallingIdentity(identity);
12203 }
12204 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000012205
James.cf Lin4b784aa2021-01-31 03:25:15 +080012206 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012207 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12208 String callingPackage) {
12209 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12210 mApp, subId, "setSignalStrengthUpdateRequest");
12211
joonhunshin4ac60942023-11-15 15:23:39 +000012212 enforceTelephonyFeatureWithException(callingPackage,
12213 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest");
12214
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012215 final int callingUid = Binder.getCallingUid();
12216 // Verify that tha callingPackage belongs to the calling UID
12217 mApp.getSystemService(AppOpsManager.class)
12218 .checkPackage(callingUid, callingPackage);
12219
Rambo Wang3607f502021-02-01 21:51:40 -080012220 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012221
12222 final long identity = Binder.clearCallingIdentity();
12223 try {
12224 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
12225 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12226
12227 if (result instanceof IllegalStateException) {
12228 throw (IllegalStateException) result;
12229 }
12230 } finally {
12231 Binder.restoreCallingIdentity(identity);
12232 }
12233 }
12234
12235 @Override
12236 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12237 String callingPackage) {
12238 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12239 mApp, subId, "clearSignalStrengthUpdateRequest");
12240
joonhunshin4ac60942023-11-15 15:23:39 +000012241 enforceTelephonyFeatureWithException(callingPackage,
12242 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest");
12243
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012244 final int callingUid = Binder.getCallingUid();
12245 // Verify that tha callingPackage belongs to the calling UID
12246 mApp.getSystemService(AppOpsManager.class)
12247 .checkPackage(callingUid, callingPackage);
12248
12249 final long identity = Binder.clearCallingIdentity();
12250 try {
12251 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
12252 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12253
12254 if (result instanceof IllegalStateException) {
12255 throw (IllegalStateException) result;
12256 }
12257 } finally {
12258 Binder.restoreCallingIdentity(identity);
12259 }
12260 }
12261
Rambo Wang3607f502021-02-01 21:51:40 -080012262 private static void validateSignalStrengthUpdateRequest(Context context,
12263 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012264 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
12265 // phone/system process do not have further restriction on request
12266 return;
12267 }
12268
12269 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080012270 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012271 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080012272 context.enforceCallingOrSelfPermission(
12273 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
12274 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012275 }
12276
12277 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000012278 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012279 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012280 || info.isEnabled()) {
12281 throw new IllegalArgumentException(
12282 "Only system can set hide fields in SignalThresholdInfo");
12283 }
12284
12285 // Thresholds length for each RAN need in range. This has been validated in
12286 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
12287 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
12288 final int[] thresholds = info.getThresholds();
12289 Objects.requireNonNull(thresholds);
12290 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
12291 || thresholds.length
12292 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
12293 throw new IllegalArgumentException(
12294 "thresholds length is out of range: " + thresholds.length);
12295 }
12296 }
12297 }
SongFerngWang8236caa2021-01-17 21:51:44 +080012298
12299 /**
12300 * Gets the current phone capability.
12301 *
12302 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
12303 * @return the PhoneCapability which describes the data connection capability of modem.
12304 * It's used to evaluate possible phone config change, for example from single
12305 * SIM device to multi-SIM device.
12306 */
12307 @Override
12308 public PhoneCapability getPhoneCapability() {
12309 enforceReadPrivilegedPermission("getPhoneCapability");
joonhunshin4ac60942023-11-15 15:23:39 +000012310
12311 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12312 PackageManager.FEATURE_TELEPHONY, "getPhoneCapability");
12313
SongFerngWang8236caa2021-01-17 21:51:44 +080012314 final long identity = Binder.clearCallingIdentity();
12315 try {
12316 return mPhoneConfigurationManager.getCurrentPhoneCapability();
12317 } finally {
12318 Binder.restoreCallingIdentity(identity);
12319 }
12320 }
Michele Berionne5e411512020-11-13 02:36:59 +000012321
12322 /**
12323 * Prepare TelephonyManager for an unattended reboot. The reboot is
12324 * required to be done shortly after the API is invoked.
12325 */
12326 @Override
12327 @TelephonyManager.PrepareUnattendedRebootResult
12328 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012329 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000012330 enforceRebootPermission();
12331
joonhunshin4ac60942023-11-15 15:23:39 +000012332 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12333 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot");
12334
Michele Berionne5e411512020-11-13 02:36:59 +000012335 final long identity = Binder.clearCallingIdentity();
12336 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012337 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000012338 } finally {
12339 Binder.restoreCallingIdentity(identity);
12340 }
12341 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012342
12343 /**
12344 * Request to get the current slicing configuration including URSP rules and
12345 * NSSAIs (configured, allowed and rejected).
12346 *
12347 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
12348 */
12349 @Override
12350 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000012351 TelephonyPermissions
12352 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
12353 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012354
joonhunshin4ac60942023-11-15 15:23:39 +000012355 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12356 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
12357 "getSlicingConfig");
12358
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012359 final long identity = Binder.clearCallingIdentity();
12360 try {
12361 Phone phone = getDefaultPhone();
12362 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
12363 } finally {
12364 Binder.restoreCallingIdentity(identity);
12365 }
12366 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012367
12368 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070012369 * Check whether the given premium capability is available for purchase from the carrier.
12370 *
12371 * @param capability The premium capability to check.
12372 * @param subId The subId to check the premium capability for.
12373 *
12374 * @return Whether the given premium capability is available to purchase.
12375 */
12376 @Override
12377 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
12378 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12379 mApp, "isPremiumCapabilityAvailableForPurchase")) {
12380 log("Premium capability "
12381 + TelephonyManager.convertPremiumCapabilityToString(capability)
12382 + " is not available for purchase due to missing permissions.");
12383 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
12384 + "permission READ_BASIC_PHONE_STATE.");
12385 }
12386
joonhunshin4ac60942023-11-15 15:23:39 +000012387 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12388 PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase");
12389
Sarah Chin2ec39f62022-08-31 17:03:26 -070012390 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080012391 if (phone == null) {
12392 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12393 return false;
12394 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012395 final long identity = Binder.clearCallingIdentity();
12396 try {
Sarah Chincc5446f2023-10-23 17:57:19 -070012397 return SlicePurchaseController.getInstance(phone, mFeatureFlags)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012398 .isPremiumCapabilityAvailableForPurchase(capability);
12399 } finally {
12400 Binder.restoreCallingIdentity(identity);
12401 }
12402 }
12403
12404 /**
12405 * Purchase the given premium capability from the carrier.
12406 *
12407 * @param capability The premium capability to purchase.
12408 * @param callback The result of the purchase request.
12409 * @param subId The subId to purchase the premium capability for.
12410 */
12411 @Override
12412 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12413 log("purchasePremiumCapability: capability="
12414 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12415 + getCurrentPackageName());
12416
12417 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12418 mApp, "purchasePremiumCapability")) {
12419 log("purchasePremiumCapability "
12420 + TelephonyManager.convertPremiumCapabilityToString(capability)
12421 + " failed due to missing permissions.");
12422 throw new SecurityException("purchasePremiumCapability requires permission "
12423 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012424 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12425 mApp, "purchasePremiumCapability")) {
12426 log("purchasePremiumCapability "
12427 + TelephonyManager.convertPremiumCapabilityToString(capability)
12428 + " failed due to missing permissions.");
12429 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012430 }
12431
joonhunshin4ac60942023-11-15 15:23:39 +000012432 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12433 PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability");
12434
Sarah Chin2ec39f62022-08-31 17:03:26 -070012435 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012436 if (phone == null) {
12437 try {
12438 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12439 callback.accept(result);
12440 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12441 } catch (RemoteException e) {
12442 String logStr = "Purchase premium capability "
12443 + TelephonyManager.convertPremiumCapabilityToString(capability)
12444 + " failed due to RemoteException handling null phone: " + e;
12445 if (DBG) log(logStr);
12446 AnomalyReporter.reportAnomaly(
12447 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12448 }
12449 return;
12450 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012451
12452 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012453 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012454 callingProcess = mApp.getPackageManager().getApplicationInfo(
12455 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070012456 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012457 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012458 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012459
12460 boolean isVisible = false;
12461 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12462 if (am != null) {
12463 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12464 if (processes != null) {
12465 for (ActivityManager.RunningAppProcessInfo process : processes) {
12466 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070012467 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080012468 if (process.processName.equals(callingProcess) && process.importance
12469 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12470 isVisible = true;
12471 break;
12472 }
12473 }
12474 }
12475 }
12476
12477 if (!isVisible) {
12478 try {
12479 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12480 callback.accept(result);
12481 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12482 } catch (RemoteException e) {
12483 String logStr = "Purchase premium capability "
12484 + TelephonyManager.convertPremiumCapabilityToString(capability)
12485 + " failed due to RemoteException handling background application: " + e;
12486 if (DBG) log(logStr);
12487 AnomalyReporter.reportAnomaly(
12488 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12489 }
12490 return;
12491 }
12492
Sarah Chin71b3a852022-09-28 15:54:19 -070012493 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012494 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012495 }
12496
12497 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012498 * Register an IMS connection state callback
12499 */
12500 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012501 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12502 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012503 if (feature == ImsFeature.FEATURE_MMTEL) {
12504 // ImsMmTelManager
12505 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12506 TelephonyPermissions
12507 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12508 mApp, subId, "registerImsStateCallback");
12509 } else if (feature == ImsFeature.FEATURE_RCS) {
12510 // ImsRcsManager or SipDelegateManager
12511 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12512 Binder.getCallingUid(), "registerImsStateCallback",
12513 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12514 Manifest.permission.READ_PRECISE_PHONE_STATE,
12515 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12516 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12517 }
12518
12519 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12520 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12521 "IMS not available on device.");
12522 }
12523
12524 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12525 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12526 }
12527
12528 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12529 if (controller == null) {
12530 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12531 "IMS not available on device.");
12532 }
12533
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012534 if (callingPackage == null) {
12535 callingPackage = getCurrentPackageName();
12536 }
12537
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012538 final long token = Binder.clearCallingIdentity();
12539 try {
12540 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012541 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012542 } catch (ImsException e) {
12543 throw new ServiceSpecificException(e.getCode());
12544 } finally {
12545 Binder.restoreCallingIdentity(token);
12546 }
12547 }
12548
12549 /**
12550 * Unregister an IMS connection state callback
12551 */
12552 @Override
12553 public void unregisterImsStateCallback(IImsStateCallback cb) {
12554 final long token = Binder.clearCallingIdentity();
12555 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12556 if (controller == null) {
12557 return;
12558 }
12559 try {
12560 controller.unregisterImsStateCallback(cb);
12561 } finally {
12562 Binder.restoreCallingIdentity(token);
12563 }
12564 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012565
12566 /**
12567 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12568 *
12569 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012570 * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012571 * SecurityException.
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012572 *
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012573 * If there is current registered network this value will be same as the registered cell
12574 * identity. If the device goes out of service the previous cell identity is cached and
12575 * will be returned. If the cache age of the Cell identity is more than 24 hours
12576 * it will be cleared and null will be returned.
12577 *
12578 */
12579 @Override
12580 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12581 String callingFeatureId) {
12582 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12583 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12584 LocationAccessPolicy.checkLocationPermission(mApp,
12585 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12586 .setCallingPackage(callingPackage)
12587 .setCallingFeatureId(callingFeatureId)
12588 .setCallingPid(Binder.getCallingPid())
12589 .setCallingUid(Binder.getCallingUid())
12590 .setMethod("getLastKnownCellIdentity")
12591 .setLogAsInfo(true)
12592 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12593 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12594 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12595 .build());
12596
12597 boolean hasFinePermission =
12598 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12599 if (!hasFinePermission
12600 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12601 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012602 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012603 }
12604
12605 final long identity = Binder.clearCallingIdentity();
12606 try {
Ling Mac28f0212023-03-24 16:07:15 -070012607 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012608 if (sst == null) return null;
12609 return sst.getLastKnownCellIdentity();
12610 } finally {
12611 Binder.restoreCallingIdentity(identity);
12612 }
12613 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012614
jimsun3b9ccac2021-10-26 15:01:23 +080012615 /**
12616 * Sets the modem service class Name that Telephony will bind to.
12617 *
12618 * @param serviceName The class name of the modem service.
12619 * @return true if the operation is succeed, otherwise false.
12620 */
12621 public boolean setModemService(String serviceName) {
12622 Log.d(LOG_TAG, "setModemService - " + serviceName);
12623 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12624 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012625 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12626 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012627 return mPhoneConfigurationManager.setModemService(serviceName);
12628 }
12629
12630 /**
12631 * Return the class name of the currently bounded modem service.
12632 *
12633 * @return the class name of the modem service.
12634 */
12635 public String getModemService() {
12636 String result;
12637 Log.d(LOG_TAG, "getModemService");
12638 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12639 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012640 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012641 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12642 "getModemService");
12643 result = mPhoneConfigurationManager.getModemService();
12644 Log.d(LOG_TAG, "result = " + result);
12645 return result;
12646 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012647
Hakjun Choi3ee81112023-12-19 15:40:58 +000012648 /**
12649 * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources,
12650 * including carrier config, entitlement server, and config update.
12651 *
12652 * @param subId subId The subscription ID of the carrier.
12653 *
12654 * @return List of plmns for carrier satellite service. If no plmn is available, empty list will
12655 * be returned.
12656 *
12657 * @throws SecurityException if the caller doesn't have the required permission.
12658 */
Hakjun Choi74c16be2024-01-19 08:18:09 +000012659 @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) {
12660 enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier");
Hakjun Choi3ee81112023-12-19 15:40:58 +000012661 final long identity = Binder.clearCallingIdentity();
12662 try {
Hakjun Choi74c16be2024-01-19 08:18:09 +000012663 return mSatelliteController.getSatellitePlmnsForCarrier(subId);
Hakjun Choi3ee81112023-12-19 15:40:58 +000012664 } finally {
12665 Binder.restoreCallingIdentity(identity);
12666 }
12667 }
12668
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012669 @Override
12670 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12671 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12672 mApp.enforceCallingOrSelfPermission(
12673 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12674 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12675
12676 final long identity = Binder.clearCallingIdentity();
12677 try {
12678 Phone phone = getPhone(subId);
12679 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012680 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12681 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012682 phone.setVoiceServiceStateOverride(hasService);
12683 } finally {
12684 Binder.restoreCallingIdentity(identity);
12685 }
12686 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012687
12688 /**
12689 * set removable eSIM as default eUICC.
12690 *
12691 * @hide
12692 */
12693 @Override
12694 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12695 enforceModifyPermission();
12696 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12697
12698 final long identity = Binder.clearCallingIdentity();
12699 try {
12700 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12701 } finally {
12702 Binder.restoreCallingIdentity(identity);
12703 }
12704 }
12705
12706 /**
12707 * Returns whether the removable eSIM is default eUICC or not.
12708 *
12709 * @hide
12710 */
12711 @Override
12712 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12713 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12714 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12715
12716 final long identity = Binder.clearCallingIdentity();
12717 try {
12718 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12719 } finally {
12720 Binder.restoreCallingIdentity(identity);
12721 }
12722 }
12723
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012724 /**
12725 * Get the component name of the default app to direct respond-via-message intent for the
12726 * user associated with this subscription, update the cache if there is no respond-via-message
12727 * application currently configured for this user.
12728 * @return component name of the app and class to direct Respond Via Message intent to, or
12729 * {@code null} if the functionality is not supported.
12730 * @hide
12731 */
12732 @Override
12733 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12734 boolean updateIfNeeded) {
12735 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012736
joonhunshin4ac60942023-11-15 15:23:39 +000012737 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12738 PackageManager.FEATURE_TELEPHONY_MESSAGING,
12739 "getDefaultRespondViaMessageApplication");
12740
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012741 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12742
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012743 UserHandle userHandle = null;
12744 final long identity = Binder.clearCallingIdentity();
12745 try {
12746 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12747 } finally {
12748 Binder.restoreCallingIdentity(identity);
12749 }
12750 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12751 updateIfNeeded, userHandle);
12752 }
Jack Yuf5badd92022-12-08 00:50:53 -080012753
12754 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012755 * Set whether the device is able to connect with null ciphering or integrity
12756 * algorithms. This is a global setting and will apply to all active subscriptions
12757 * and all new subscriptions after this.
12758 *
12759 * @param enabled when true, null cipher and integrity algorithms are allowed.
12760 * @hide
12761 */
12762 @Override
12763 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12764 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12765 enforceModifyPermission();
12766 checkForNullCipherAndIntegritySupport();
12767
12768 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12769 // for listening to these preference changes and applying them immediately.
12770 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12771 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12772 editor.apply();
12773
12774 for (Phone phone: PhoneFactory.getPhones()) {
12775 phone.handleNullCipherEnabledChange();
12776 }
12777 }
12778
12779
12780 /**
12781 * Get whether the device is able to connect with null ciphering or integrity
12782 * algorithms. Note that this retrieves the phone-global preference and not
12783 * the state of the radio.
12784 *
12785 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12786 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12787 * version for this feature.
12788 * @hide
12789 */
12790 @Override
12791 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12792 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12793 enforceReadPermission();
12794 checkForNullCipherAndIntegritySupport();
12795 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12796 }
12797
12798 private void checkForNullCipherAndIntegritySupport() {
12799 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12800 throw new UnsupportedOperationException(
12801 "Null cipher and integrity operations require HAL 2.1 or above");
12802 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012803 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12804 throw new UnsupportedOperationException(
12805 "Null cipher and integrity operations unsupported by modem");
12806 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012807 }
12808
Gil Cukierman06403e12023-11-29 16:33:03 +000012809 private void checkForIdentifierDisclosureNotificationSupport() {
12810 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) {
12811 throw new UnsupportedOperationException(
12812 "Cellular identifier disclosure transparency operations require HAL 2.2 or "
12813 + "above");
12814 }
12815 if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) {
12816 throw new UnsupportedOperationException(
12817 "Cellular identifier disclosure transparency operations unsupported by modem");
12818 }
12819 }
12820
Michael Groover826b71d2023-12-21 22:08:06 -060012821 private void checkForNullCipherNotificationSupport() {
12822 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) {
12823 throw new UnsupportedOperationException(
12824 "Null cipher notification operations require HAL 2.2 or above");
12825 }
12826 if (!getDefaultPhone().isNullCipherNotificationSupported()) {
12827 throw new UnsupportedOperationException(
12828 "Null cipher notification operations unsupported by modem");
12829 }
12830 }
12831
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012832 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012833 * Get the SIM state for the slot index.
12834 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12835 *
12836 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12837 */
12838 @Override
12839 @SimState
12840 public int getSimStateForSlotIndex(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +000012841 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12842 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex");
12843
Jack Yuf5badd92022-12-08 00:50:53 -080012844 IccCardConstants.State simState;
12845 if (slotIndex < 0) {
12846 simState = IccCardConstants.State.UNKNOWN;
12847 } else {
12848 Phone phone = null;
12849 try {
12850 phone = PhoneFactory.getPhone(slotIndex);
12851 } catch (IllegalStateException e) {
12852 // ignore
12853 }
12854 if (phone == null) {
12855 simState = IccCardConstants.State.UNKNOWN;
12856 } else {
12857 IccCard icc = phone.getIccCard();
12858 if (icc == null) {
12859 simState = IccCardConstants.State.UNKNOWN;
12860 } else {
12861 simState = icc.getState();
12862 }
12863 }
12864 }
12865 return simState.ordinal();
12866 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012867
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012868 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
12869 boolean enableLogcat,
12870 long logcatStartTimestampMillis, boolean enableTelecomDump,
12871 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012872 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012873 TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder =
12874 new TelephonyManager.EmergencyCallDiagnosticData.Builder();
12875 ecdDataBuilder
12876 .setTelecomDumpsysCollectionEnabled(enableTelecomDump)
12877 .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012878 if (enableLogcat) {
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012879 ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012880 }
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012881 TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build();
12882 Log.d(LOG_TAG, "persisting with Params " + ecdData.toString());
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012883 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
12884 Executors.newCachedThreadPool(), db,
12885 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012886 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012887 }
12888
12889 /**
12890 * Request telephony to persist state for debugging emergency call failures.
12891 *
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012892 * @param dropboxTag Tag to use when persisting data to dropbox service.
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012893 * @param enableLogcat whether to collect logcat output
12894 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
12895 * @param enableTelecomDump whether to collect telecom dumpsys
12896 * @param enableTelephonyDump whether to collect telephony dumpsys
12897 */
12898 @Override
12899 @RequiresPermission(android.Manifest.permission.DUMP)
12900 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
12901 long logcatStartTimestampMillis, boolean enableTelecomDump,
12902 boolean enableTelephonyDump) {
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -080012903 // Verify that the caller has READ_DROPBOX_DATA permission.
12904 if (mTelecomFeatureFlags.telecomResolveHiddenDependencies()
12905 && Flags.enableReadDropboxPermission()) {
12906 mApp.enforceCallingPermission(permission.READ_DROPBOX_DATA,
12907 "persistEmergencyCallDiagnosticData");
12908 } else {
12909 // Otherwise, enforce legacy permission.
12910 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
12911 "persistEmergencyCallDiagnosticData");
12912 }
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012913 final long identity = Binder.clearCallingIdentity();
12914 try {
12915 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
12916 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
12917
12918 } finally {
12919 Binder.restoreCallingIdentity(identity);
12920 }
12921 }
12922
Hui Wang9b5793a2022-12-05 14:38:06 -060012923 /**
12924 * Get current cell broadcast ranges.
12925 */
12926 @Override
12927 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12928 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12929 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12930 "getCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012931
12932 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12933 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges");
12934
Hui Wang9b5793a2022-12-05 14:38:06 -060012935 final long identity = Binder.clearCallingIdentity();
12936 try {
12937 return getPhone(subId).getCellBroadcastIdRanges();
12938 } finally {
12939 Binder.restoreCallingIdentity(identity);
12940 }
12941 }
12942
12943 /**
12944 * Set reception of cell broadcast messages with the list of the given ranges
12945 *
12946 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12947 */
12948 @Override
12949 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12950 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12951 @Nullable IIntegerConsumer callback) {
12952 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12953 "setCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012954
12955 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12956 PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges");
12957
Hui Wang9b5793a2022-12-05 14:38:06 -060012958 final long identity = Binder.clearCallingIdentity();
12959 try {
12960 Phone phone = getPhoneFromSubId(subId);
12961 if (DBG) {
12962 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12963 }
12964 phone.setCellBroadcastIdRanges(ranges, result -> {
12965 if (callback != null) {
12966 try {
12967 callback.accept(result);
12968 } catch (RemoteException e) {
12969 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12970 }
12971 }
12972 });
12973 } finally {
12974 Binder.restoreCallingIdentity(identity);
12975 }
12976 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012977
12978 /**
12979 * Returns whether the device supports the domain selection service.
12980 *
12981 * @return {@code true} if the device supports the domain selection service.
12982 */
12983 @Override
12984 public boolean isDomainSelectionSupported() {
12985 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12986 "isDomainSelectionSupported");
12987
12988 final long identity = Binder.clearCallingIdentity();
12989 try {
12990 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12991 } finally {
12992 Binder.restoreCallingIdentity(identity);
12993 }
12994 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012995
12996 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012997 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
12998 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
12999 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080013000 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013001 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chinabf081b2023-03-09 23:00:57 -080013002 * @param enableSatellite {@code true} to enable the satellite modem and
13003 * {@code false} to disable.
13004 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
Thomas Nguyena8062672024-02-05 14:18:19 -080013005 * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise.
Sarah Chinabf081b2023-03-09 23:00:57 -080013006 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080013007 *
13008 * @throws SecurityException if the caller doesn't have the required permission.
13009 */
13010 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013011 public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode,
Thomas Nguyena8062672024-02-05 14:18:19 -080013012 boolean isEmergency, @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013013 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013014 if (enableSatellite) {
13015 ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) {
13016 @Override
13017 protected void onReceiveResult(int resultCode, Bundle resultData) {
13018 Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode
13019 + ", resultData=" + resultData);
13020 boolean isAllowed = false;
13021 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(
13022 callback::accept);
13023 if (resultCode == SATELLITE_RESULT_SUCCESS) {
13024 if (resultData != null
13025 && resultData.containsKey(KEY_SATELLITE_COMMUNICATION_ALLOWED)) {
13026 isAllowed = resultData.getBoolean(KEY_SATELLITE_COMMUNICATION_ALLOWED);
13027 } else {
13028 loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist.");
13029 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013030 } else {
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013031 result.accept(resultCode);
13032 return;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013033 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013034 if (isAllowed) {
13035 mSatelliteController.requestSatelliteEnabled(
Hyosun Kimab304792024-03-29 09:18:03 +000013036 subId, enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013037 } else {
13038 result.accept(SATELLITE_RESULT_ACCESS_BARRED);
13039 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013040 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013041 };
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013042 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013043 subId, resultReceiver);
13044 } else {
13045 // No need to check if satellite is allowed at current location when disabling satellite
13046 mSatelliteController.requestSatelliteEnabled(
Hyosun Kimab304792024-03-29 09:18:03 +000013047 subId, enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013048 }
Sarah Chin503828c2023-02-01 23:54:20 -080013049 }
13050
13051 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013052 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080013053 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013054 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013055 * @param result The result receiver that returns whether the satellite modem is enabled
13056 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013057 *
13058 * @throws SecurityException if the caller doesn't have the required permission.
13059 */
13060 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013061 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
13062 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013063 mSatelliteController.requestIsSatelliteEnabled(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013064 }
13065
13066 /**
Sarah Chin43457982023-02-15 17:50:38 -080013067 * Request to get whether the satellite service demo mode is enabled.
13068 *
13069 * @param subId The subId of the subscription to check whether the satellite demo mode
13070 * is enabled for.
13071 * @param result The result receiver that returns whether the satellite demo mode is enabled
13072 * if the request is successful or an error code if the request failed.
13073 *
13074 * @throws SecurityException if the caller doesn't have the required permission.
13075 */
13076 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013077 public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
13078 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
13079 mSatelliteController.requestIsDemoModeEnabled(subId, result);
Sarah Chin43457982023-02-15 17:50:38 -080013080 }
13081
13082 /**
Thomas Nguyena8062672024-02-05 14:18:19 -080013083 * Request to get whether the satellite service is enabled with emergency mode.
13084 *
13085 * @param subId The subId of the subscription to check whether the satellite demo mode
13086 * is enabled for.
13087 * @param result The result receiver that returns whether the satellite emergency mode is
13088 * enabled if the request is successful or an error code if the request failed.
13089 *
13090 * @throws SecurityException if the caller doesn't have the required permission.
13091 */
13092 @Override
13093 public void requestIsEmergencyModeEnabled(int subId, @NonNull ResultReceiver result) {
13094 enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled");
13095 result.send(SATELLITE_RESULT_REQUEST_NOT_SUPPORTED, null);
13096 }
13097
13098 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013099 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080013100 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013101 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013102 * @param result The result receiver that returns whether the satellite service is supported on
13103 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013104 */
13105 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013106 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013107 mSatelliteController.requestIsSatelliteSupported(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013108 }
13109
13110 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013111 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080013112 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013113 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013114 * @param result The result receiver that returns the {@link SatelliteCapabilities}
13115 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013116 *
13117 * @throws SecurityException if the caller doesn't have required permission.
13118 */
13119 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013120 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
13121 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013122 mSatelliteController.requestSatelliteCapabilities(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013123 }
13124
13125 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013126 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013127 * This can be called by the pointing UI when the user starts pointing to the satellite.
13128 * Modem should continue to report the pointing input as the device or satellite moves.
13129 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013130 * @param subId The subId of the subscription to start satellite transmission updates for.
13131 * @param resultCallback The callback to get the result of the request.
13132 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080013133 *
13134 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013135 */
13136 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013137 public void startSatelliteTransmissionUpdates(int subId,
13138 @NonNull IIntegerConsumer resultCallback,
13139 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13140 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
13141 mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080013142 }
13143
13144 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013145 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013146 * This can be called by the pointing UI when the user stops pointing to the satellite.
13147 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013148 * @param subId The subId of the subscription to stop satellite transmission updates for.
13149 * @param resultCallback The callback to get the result of the request.
13150 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
13151 * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080013152 *
13153 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013154 */
13155 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013156 public void stopSatelliteTransmissionUpdates(int subId,
13157 @NonNull IIntegerConsumer resultCallback,
13158 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13159 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
13160 mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013161 }
13162
13163 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013164 * Register the subscription with a satellite provider.
13165 * This is needed to register the subscription if the provider allows dynamic registration.
13166 *
13167 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013168 * @param token The token to be used as a unique identifier for provisioning with satellite
13169 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013170 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080013171 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013172 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013173 * @return The signal transport used by the caller to cancel the provision request,
13174 * or {@code null} if the request failed.
13175 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013176 * @throws SecurityException if the caller doesn't have the required permission.
13177 */
13178 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013179 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013180 @NonNull String token, @NonNull byte[] provisionData,
13181 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013182 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013183 return mSatelliteController.provisionSatelliteService(subId, token, provisionData,
13184 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013185 }
13186
13187 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013188 * Unregister the device/subscription with the satellite provider.
13189 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013190 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013191 * should report as deprovisioned.
13192 *
13193 * @param subId The subId of the subscription to be deprovisioned.
13194 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080013195 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013196 *
13197 * @throws SecurityException if the caller doesn't have the required permission.
13198 */
13199 @Override
13200 public void deprovisionSatelliteService(int subId,
13201 @NonNull String token, @NonNull IIntegerConsumer callback) {
13202 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013203 mSatelliteController.deprovisionSatelliteService(subId, token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013204 }
13205
13206 /**
Sarah Chin43457982023-02-15 17:50:38 -080013207 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013208 *
Sarah Chin43457982023-02-15 17:50:38 -080013209 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013210 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013211 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013212 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013213 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013214 * @throws SecurityException if the caller doesn't have the required permission.
13215 */
13216 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013217 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
13218 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013219 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013220 return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013221 }
13222
13223 /**
Sarah Chin43457982023-02-15 17:50:38 -080013224 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013225 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013226 *
Sarah Chin43457982023-02-15 17:50:38 -080013227 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013228 * @param callback The callback that was passed to
13229 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013230 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013231 * @throws SecurityException if the caller doesn't have the required permission.
13232 */
13233 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013234 public void unregisterForSatelliteProvisionStateChanged(
13235 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013236 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013237 mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013238 }
13239
13240 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013241 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013242 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013243 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013244 * @param result The result receiver that returns whether the device is provisioned with a
13245 * satellite provider if the request is successful or an error code if the
13246 * request failed.
13247 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013248 * @throws SecurityException if the caller doesn't have the required permission.
13249 */
13250 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013251 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
13252 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013253 mSatelliteController.requestIsSatelliteProvisioned(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013254 }
13255
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013256 /**
Sarah Chin43457982023-02-15 17:50:38 -080013257 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013258 *
Sarah Chin43457982023-02-15 17:50:38 -080013259 * @param subId The subId of the subscription to register for satellite modem state changed.
13260 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080013261 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013262 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013263 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013264 * @throws SecurityException if the caller doesn't have the required permission.
13265 */
13266 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013267 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013268 @NonNull ISatelliteModemStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080013269 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013270 return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013271 }
13272
13273 /**
Sarah Chin43457982023-02-15 17:50:38 -080013274 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013275 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013276 *
Sarah Chin43457982023-02-15 17:50:38 -080013277 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080013278 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013279 * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013280 *
13281 * @throws SecurityException if the caller doesn't have the required permission.
13282 */
13283 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013284 public void unregisterForModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013285 @NonNull ISatelliteModemStateCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013286 enforceSatelliteCommunicationPermission("unregisterForModemStateChanged");
13287 mSatelliteController.unregisterForModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013288 }
13289
13290 /**
13291 * Register to receive incoming datagrams over satellite.
13292 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013293 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Sarah Chindf715ec2023-02-13 13:46:24 -080013294 * @param callback The callback to handle incoming datagrams over satellite.
13295 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013296 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013297 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013298 * @throws SecurityException if the caller doesn't have the required permission.
13299 */
13300 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013301 @SatelliteManager.SatelliteResult public int registerForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013302 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013303 enforceSatelliteCommunicationPermission("registerForIncomingDatagram");
13304 return mSatelliteController.registerForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013305 }
13306
13307 /**
13308 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013309 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013310 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013311 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
13312 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013313 * {@link #registerForIncomingDatagram(int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013314 *
13315 * @throws SecurityException if the caller doesn't have the required permission.
13316 */
13317 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013318 public void unregisterForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013319 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013320 enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram");
13321 mSatelliteController.unregisterForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013322 }
13323
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013324 /**
13325 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013326 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013327 * This method requests modem to check if there are any pending datagrams to be received over
13328 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000013329 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080013330 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013331 * @param subId The subId of the subscription used for receiving datagrams.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013332 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013333 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013334 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013335 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013336 public void pollPendingDatagrams(int subId, IIntegerConsumer callback) {
13337 enforceSatelliteCommunicationPermission("pollPendingDatagrams");
13338 mSatelliteController.pollPendingDatagrams(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013339 }
13340
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013341 /**
13342 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013343 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013344 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
13345 * input to this method. Datagram received here will be passed down to modem without any
13346 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080013347 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013348 * @param subId The subId of the subscription to send satellite datagrams for.
13349 * @param datagramType datagram type indicating whether the datagram is of type
13350 * SOS_SMS or LOCATION_SHARING.
13351 * @param datagram encoded gateway datagram which is encrypted by the caller.
13352 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000013353 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
13354 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013355 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013356 *
13357 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013358 */
13359 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013360 public void sendDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000013361 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
13362 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013363 enforceSatelliteCommunicationPermission("sendDatagram");
13364 mSatelliteController.sendDatagram(subId, datagramType, datagram, needFullScreenPointingUI,
13365 callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013366 }
13367
Sarah Chindf715ec2023-02-13 13:46:24 -080013368 /**
13369 * Request to get whether satellite communication is allowed for the current location.
13370 *
13371 * @param subId The subId of the subscription to check whether satellite communication is
13372 * allowed for the current location for.
13373 * @param result The result receiver that returns whether satellite communication is allowed
13374 * for the current location if the request is successful or an error code
13375 * if the request failed.
13376 *
13377 * @throws SecurityException if the caller doesn't have the required permission.
13378 */
13379 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013380 public void requestIsCommunicationAllowedForCurrentLocation(int subId,
Sarah Chindf715ec2023-02-13 13:46:24 -080013381 @NonNull ResultReceiver result) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013382 enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation");
13383 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(subId,
13384 result);
Sarah Chindf715ec2023-02-13 13:46:24 -080013385 }
13386
13387 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013388 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080013389 *
Sarah Chin5f57c582023-02-14 04:16:10 -080013390 * @param subId The subId to get the time after which the satellite will be visible for.
13391 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080013392 * be visible if the request is successful or an error code if the request failed.
13393 *
13394 * @throws SecurityException if the caller doesn't have the required permission.
13395 */
13396 @Override
13397 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
13398 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013399 mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013400 }
13401
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013402 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013403 * Inform that Device is aligned to satellite for demo mode.
13404 *
13405 * @param subId The subId to get the time after which the satellite will be visible for.
13406 * @param isAligned {@code true} Device is aligned with the satellite for demo mode
13407 * {@code false} Device fails to align with the satellite for demo mode.
13408 *
13409 * @throws SecurityException if the caller doesn't have required permission.
13410 */
13411 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
13412
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013413 public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) {
Hakjun Choiae365972023-04-25 11:00:31 +000013414 enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite");
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013415 mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned);
Hakjun Choiae365972023-04-25 11:00:31 +000013416 }
13417
13418 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000013419 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
13420 * by modem.
13421 *
13422 * @param subId The subId of the subscription to request for.
13423 * @param reason Reason for disallowing satellite communication for carrier.
Hakjun Choif92ac752024-03-18 19:34:29 +000013424 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013425 * operation.
13426 *
13427 * @throws SecurityException if the caller doesn't have required permission.
13428 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013429 public void addAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013430 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13431 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013432 enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013433 final long identity = Binder.clearCallingIdentity();
13434 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013435 mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013436 } finally {
13437 Binder.restoreCallingIdentity(identity);
13438 }
13439 }
13440
13441 /**
13442 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
13443 * by modem.
13444 *
13445 * @param subId The subId of the subscription to request for.
13446 * @param reason Reason for disallowing satellite communication.
Hakjun Choif92ac752024-03-18 19:34:29 +000013447 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013448 * operation.
13449 *
13450 * @throws SecurityException if the caller doesn't have required permission.
13451 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013452 public void removeAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013453 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13454 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013455 enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013456 final long identity = Binder.clearCallingIdentity();
13457 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013458 mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013459 } finally {
13460 Binder.restoreCallingIdentity(identity);
13461 }
13462 }
13463
13464 /**
13465 * Get reasons for disallowing satellite communication, as requested by
Hakjun Choif92ac752024-03-18 19:34:29 +000013466 * {@link #addAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
Hakjun Choicb39db92023-07-14 15:51:12 +000013467 *
13468 * @param subId The subId of the subscription to request for.
13469 *
13470 * @return Integer array of reasons for disallowing satellite communication.
13471 *
13472 * @throws SecurityException if the caller doesn't have the required permission.
13473 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013474 public @NonNull int[] getAttachRestrictionReasonsForCarrier(
Hakjun Choicb39db92023-07-14 15:51:12 +000013475 int subId) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013476 enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013477 final long identity = Binder.clearCallingIdentity();
13478 try {
13479 Set<Integer> reasonSet =
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013480 mSatelliteController.getAttachRestrictionReasonsForCarrier(subId);
Hakjun Choicb39db92023-07-14 15:51:12 +000013481 return reasonSet.stream().mapToInt(i->i).toArray();
13482 } finally {
13483 Binder.restoreCallingIdentity(identity);
13484 }
13485 }
13486
13487 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000013488 * Request to get the signal strength of the satellite connection.
13489 *
13490 * @param subId The subId of the subscription to request for.
13491 * @param result Result receiver to get the error code of the request and the current signal
13492 * strength of the satellite connection.
13493 *
13494 * @throws SecurityException if the caller doesn't have required permission.
13495 */
13496 @Override
13497 public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) {
13498 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
13499 final long identity = Binder.clearCallingIdentity();
13500 try {
13501 mSatelliteController.requestNtnSignalStrength(subId, result);
13502 } finally {
13503 Binder.restoreCallingIdentity(identity);
13504 }
13505 }
13506
13507 /**
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013508 * Registers for NTN signal strength changed from satellite modem. If the registration operation
13509 * is not successful, a {@link ServiceSpecificException} that contains
13510 * {@link SatelliteManager.SatelliteResult} will be thrown.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013511 *
13512 * @param subId The subId of the subscription to request for.
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013513 * @param callback The callback to handle the NTN signal strength changed event. If the
13514 * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged(
13515 * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of
13516 * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial
13517 * network has changed.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013518 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013519 * @throws SecurityException If the caller doesn't have the required permission.
13520 * @throws ServiceSpecificException If the callback registration operation fails.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013521 */
13522 @Override
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013523 public void registerForNtnSignalStrengthChanged(int subId,
13524 @NonNull INtnSignalStrengthCallback callback) throws RemoteException {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013525 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
13526 final long identity = Binder.clearCallingIdentity();
13527 try {
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013528 mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013529 } finally {
13530 Binder.restoreCallingIdentity(identity);
13531 }
13532 }
13533
13534 /**
13535 * Unregisters for NTN signal strength changed from satellite modem.
13536 * If callback was not registered before, the request will be ignored.
13537 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013538 * @param subId The subId of the subscription to unregister for listening NTN signal strength
13539 * changed event.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013540 * @param callback The callback that was passed to
13541 * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)}
13542 *
13543 * @throws SecurityException if the caller doesn't have the required permission.
13544 */
13545 @Override
13546 public void unregisterForNtnSignalStrengthChanged(
13547 int subId, @NonNull INtnSignalStrengthCallback callback) {
13548 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
13549 final long identity = Binder.clearCallingIdentity();
13550 try {
13551 mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback);
13552 } finally {
13553 Binder.restoreCallingIdentity(identity);
13554 }
13555 }
13556
13557 /**
Hakjun Choi8d96a562023-10-26 15:01:40 +000013558 * Registers for satellite capabilities change event from the satellite service.
13559 *
13560 * @param subId The subId of the subscription to request for.
13561 * @param callback The callback to handle the satellite capabilities changed event.
13562 *
13563 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13564 *
13565 * @throws SecurityException if the caller doesn't have required permission.
13566 */
13567 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013568 @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged(
Hakjun Choi8d96a562023-10-26 15:01:40 +000013569 int subId, @NonNull ISatelliteCapabilitiesCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013570 enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013571 final long identity = Binder.clearCallingIdentity();
13572 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013573 return mSatelliteController.registerForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013574 } finally {
13575 Binder.restoreCallingIdentity(identity);
13576 }
13577 }
13578
13579 /**
13580 * Unregisters for satellite capabilities change event from the satellite service.
13581 * If callback was not registered before, the request will be ignored.
13582 *
13583 * @param subId The subId of the subscription to unregister for satellite capabilities change.
13584 * @param callback The callback that was passed to.
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013585 * {@link #registerForCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}.
Hakjun Choi8d96a562023-10-26 15:01:40 +000013586 *
13587 * @throws SecurityException if the caller doesn't have required permission.
13588 */
13589 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013590 public void unregisterForCapabilitiesChanged(int subId,
13591 @NonNull ISatelliteCapabilitiesCallback callback) {
13592 enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013593 final long identity = Binder.clearCallingIdentity();
13594 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013595 mSatelliteController.unregisterForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013596 } finally {
13597 Binder.restoreCallingIdentity(identity);
13598 }
13599 }
13600
13601 /**
Hakjun Choif92ac752024-03-18 19:34:29 +000013602 * Registers for the satellite supported state changed.
13603 *
13604 * @param subId The subId of the subscription to register for supported state changed.
13605 * @param callback The callback to handle the satellite supported state changed event.
13606 *
13607 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13608 *
13609 * @throws SecurityException if the caller doesn't have the required permission.
13610 */
13611 @Override
13612 @SatelliteManager.SatelliteResult public int registerForSatelliteSupportedStateChanged(
13613 int subId, @NonNull ISatelliteSupportedStateCallback callback) {
13614 enforceSatelliteCommunicationPermission("registerForSatelliteSupportedStateChanged");
13615 return mSatelliteController.registerForSatelliteSupportedStateChanged(subId, callback);
13616 }
13617
13618 /**
13619 * Unregisters for the satellite supported state changed.
13620 * If callback was not registered before, the request will be ignored.
13621 *
13622 * @param subId The subId of the subscription to unregister for supported state changed.
13623 * @param callback The callback that was passed to
13624 * {@link #registerForSatelliteSupportedStateChanged(int, ISatelliteSupportedStateCallback)}.
13625 *
13626 * @throws SecurityException if the caller doesn't have the required permission.
13627 */
13628 @Override
13629 public void unregisterForSatelliteSupportedStateChanged(
13630 int subId, @NonNull ISatelliteSupportedStateCallback callback) {
13631 enforceSatelliteCommunicationPermission("unregisterForSatelliteSupportedStateChanged");
13632 mSatelliteController.unregisterForSatelliteSupportedStateChanged(subId, callback);
13633 }
13634
13635 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013636 * This API can be used by only CTS to update satellite vendor service package name.
13637 *
13638 * @param servicePackageName The package name of the satellite vendor service.
13639 * @return {@code true} if the satellite vendor service is set successfully,
13640 * {@code false} otherwise.
13641 */
13642 public boolean setSatelliteServicePackageName(String servicePackageName) {
13643 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName);
13644 TelephonyPermissions.enforceShellOnly(
13645 Binder.getCallingUid(), "setSatelliteServicePackageName");
13646 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13647 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13648 "setSatelliteServicePackageName");
13649 return mSatelliteController.setSatelliteServicePackageName(servicePackageName);
13650 }
13651
13652 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070013653 * This API can be used by only CTS to update satellite gateway service package name.
13654 *
13655 * @param servicePackageName The package name of the satellite gateway service.
13656 * @return {@code true} if the satellite gateway service is set successfully,
13657 * {@code false} otherwise.
13658 */
13659 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
13660 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
13661 TelephonyPermissions.enforceShellOnly(
13662 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
13663 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13664 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13665 "setSatelliteGatewayServicePackageName");
13666 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
13667 }
13668
13669 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070013670 * This API can be used by only CTS to update satellite pointing UI app package and class names.
13671 *
13672 * @param packageName The package name of the satellite pointing UI app.
13673 * @param className The class name of the satellite pointing UI app.
13674 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
13675 * {@code false} otherwise.
13676 */
13677 public boolean setSatellitePointingUiClassName(
13678 @Nullable String packageName, @Nullable String className) {
13679 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
13680 + ", className=" + className);
13681 TelephonyPermissions.enforceShellOnly(
13682 Binder.getCallingUid(), "setSatellitePointingUiClassName");
13683 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13684 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13685 "setSatelliteGatewayServicePackageName");
13686 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
13687 }
13688
13689 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070013690 * This API can be used by only CTS to update the timeout duration in milliseconds that
13691 * satellite should stay at listening mode to wait for the next incoming page before disabling
13692 * listening mode.
13693 *
13694 * @param timeoutMillis The timeout duration in millisecond.
13695 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13696 */
13697 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
13698 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
13699 TelephonyPermissions.enforceShellOnly(
13700 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
13701 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13702 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13703 "setSatelliteListeningTimeoutDuration");
13704 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
13705 }
13706
13707 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013708 * This API can be used by only CTS to override the timeout durations used by the
13709 * DatagramController module.
Hakjun Choiae365972023-04-25 11:00:31 +000013710 *
13711 * @param timeoutMillis The timeout duration in millisecond.
13712 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13713 */
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013714 public boolean setDatagramControllerTimeoutDuration(
13715 boolean reset, int timeoutType, long timeoutMillis) {
13716 Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset="
13717 + reset + ", timeoutMillis=" + timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013718 TelephonyPermissions.enforceShellOnly(
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013719 Binder.getCallingUid(), "setDatagramControllerTimeoutDuration");
Hakjun Choiae365972023-04-25 11:00:31 +000013720 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13721 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013722 "setDatagramControllerTimeoutDuration");
13723 return mSatelliteController.setDatagramControllerTimeoutDuration(
13724 reset, timeoutType, timeoutMillis);
13725 }
13726
13727 /**
13728 * This API can be used by only CTS to override the timeout durations used by the
13729 * SatelliteController module.
13730 *
13731 * @param timeoutMillis The timeout duration in millisecond.
13732 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13733 */
13734 public boolean setSatelliteControllerTimeoutDuration(
13735 boolean reset, int timeoutType, long timeoutMillis) {
13736 Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset="
13737 + reset + ", timeoutMillis=" + timeoutMillis);
13738 TelephonyPermissions.enforceShellOnly(
13739 Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration");
13740 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13741 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13742 "setSatelliteControllerTimeoutDuration");
13743 return mSatelliteController.setSatelliteControllerTimeoutDuration(
13744 reset, timeoutType, timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013745 }
13746
13747 /**
Thomas Nguyen11a051f2023-10-25 10:14:55 -070013748 * This API can be used in only testing to override connectivity status in monitoring emergency
13749 * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.
13750 *
13751 * @param handoverType The type of handover from emergency call to satellite messaging. Use one
13752 * of the following values to enable the override:
13753 * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS
13754 * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911
13755 * To disable the override, use -1 for handoverType.
13756 * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer
13757 * delaySeconds after the emergency call starts.
13758 * @return {@code true} if the handover type is set successfully, {@code false} otherwise.
13759 */
13760 public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) {
13761 Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType);
13762 TelephonyPermissions.enforceShellOnly(
13763 Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType");
13764 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13765 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13766 "setEmergencyCallToSatelliteHandoverType");
13767 return mSatelliteController.setEmergencyCallToSatelliteHandoverType(
13768 handoverType, delaySeconds);
13769 }
13770
13771 /**
Thomas Nguyen3d602742024-01-19 11:29:35 -080013772 * This API can be used in only testing to override oem-enabled satellite provision status.
13773 *
13774 * @param reset {@code true} mean the overriding status should not be used, {@code false}
13775 * otherwise.
13776 * @param isProvisioned The overriding provision status.
13777 * @return {@code true} if the provision status is set successfully, {@code false} otherwise.
13778 */
13779 public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) {
13780 Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset
13781 + ", isProvisioned=" + isProvisioned);
13782 TelephonyPermissions.enforceShellOnly(
13783 Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus");
13784 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13785 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13786 "setOemEnabledSatelliteProvisionStatus");
13787 return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned);
13788 }
13789
13790 /**
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013791 * This API should be used by only CTS tests to forcefully set telephony country codes.
13792 *
13793 * @return {@code true} if the country code is set successfully, {@code false} otherwise.
13794 */
13795 public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes,
13796 Map cachedNetworkCountryCodes, String locationCountryCode,
13797 long locationCountryCodeTimestampNanos) {
13798 Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes="
13799 + String.join(", ", currentNetworkCountryCodes)
13800 + ", locationCountryCode=" + locationCountryCode
13801 + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos
13802 + ", reset=" + reset + ", cachedNetworkCountryCodes="
13803 + String.join(", ", cachedNetworkCountryCodes.keySet()));
13804 TelephonyPermissions.enforceShellOnly(
13805 Binder.getCallingUid(), "setCachedLocationCountryCode");
13806 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13807 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13808 "setCachedLocationCountryCode");
13809 return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext()).setCountryCodes(
13810 reset, currentNetworkCountryCodes, cachedNetworkCountryCodes, locationCountryCode,
13811 locationCountryCodeTimestampNanos);
13812 }
13813
13814 /**
13815 * This API should be used by only CTS tests to override the overlay configs of satellite
13816 * access controller.
13817 *
13818 * @param reset {@code true} mean the overridden configs should not be used, {@code false}
13819 * otherwise.
13820 * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise.
13821 */
13822 public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed,
13823 String s2CellFile, long locationFreshDurationNanos,
13824 List<String> satelliteCountryCodes) {
13825 Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset
13826 + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile
13827 + ", locationFreshDurationNanos=" + locationFreshDurationNanos
13828 + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null)
13829 ? String.join(", ", satelliteCountryCodes) : null));
13830 TelephonyPermissions.enforceShellOnly(
13831 Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs");
13832 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13833 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13834 "setSatelliteAccessControlOverlayConfigs");
13835 return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset, isAllowed,
13836 s2CellFile, locationFreshDurationNanos, satelliteCountryCodes);
13837 }
13838
13839 /**
Hakjun Choibc6ce992023-11-07 16:04:33 +000013840 * This API can be used by only CTS to override the cached value for the device overlay config
13841 * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether
13842 * outgoing satellite datagrams should be sent to modem in demo mode.
13843 *
13844 * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to
13845 * satellite modem or not.
13846 *
13847 * @return {@code true} if the operation is successful, {@code false} otherwise.
13848 */
13849 public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) {
13850 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
13851 Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is "
13852 + "disabled");
13853 return false;
13854 }
13855 Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode");
13856 TelephonyPermissions.enforceShellOnly(
13857 Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode");
13858 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13859 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13860 "setShouldSendDatagramToModemInDemoMode");
13861 return mSatelliteController.setShouldSendDatagramToModemInDemoMode(
13862 shouldSendToModemInDemoMode);
13863 }
13864
13865 /**
Hunsuk Choi13078be2023-09-13 10:55:21 +000013866 * Sets the service defined in ComponentName to be bound.
13867 *
13868 * This should only be used for testing.
13869 * @return {@code true} if the DomainSelectionService to bind to was set,
13870 * {@code false} otherwise.
13871 */
13872 @Override
13873 public boolean setDomainSelectionServiceOverride(ComponentName componentName) {
13874 Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName);
13875
13876 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
13877 "setDomainSelectionServiceOverride");
13878 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13879 getDefaultSubscription(), "setDomainSelectionServiceOverride");
13880
13881 final long identity = Binder.clearCallingIdentity();
13882 try {
13883 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13884 return DomainSelectionResolver.getInstance()
13885 .setDomainSelectionServiceOverride(componentName);
13886 }
13887 } finally {
13888 Binder.restoreCallingIdentity(identity);
13889 }
13890 return false;
13891 }
13892
13893 /**
13894 * Clears the DomainSelectionService override.
13895 *
13896 * This should only be used for testing.
13897 * @return {@code true} if the DomainSelectionService override was cleared,
13898 * {@code false} otherwise.
13899 */
13900 @Override
13901 public boolean clearDomainSelectionServiceOverride() {
13902 Log.i(LOG_TAG, "clearDomainSelectionServiceOverride");
13903
13904 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
13905 "clearDomainSelectionServiceOverride");
13906 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13907 getDefaultSubscription(), "clearDomainSelectionServiceOverride");
13908
13909 final long identity = Binder.clearCallingIdentity();
13910 try {
13911 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13912 return DomainSelectionResolver.getInstance()
13913 .clearDomainSelectionServiceOverride();
13914 }
13915 } finally {
13916 Binder.restoreCallingIdentity(identity);
13917 }
13918 return false;
13919 }
13920
13921 /**
Gil Cukierman06403e12023-11-29 16:33:03 +000013922 * Enable or disable notifications sent for cellular identifier disclosure events.
13923 *
13924 * Disclosure events are defined as instances where a device has sent a cellular identifier
13925 * on the Non-access stratum (NAS) before a security context is established. As a result the
13926 * identifier is sent in the clear, which has privacy implications for the user.
13927 *
13928 * @param enable if notifications about disclosure events should be enabled
13929 * @throws SecurityException if the caller does not have the required privileges
13930 * @throws UnsupportedOperationException if the modem does not support this feature.
13931 */
13932 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000013933 public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) {
Gil Cukierman06403e12023-11-29 16:33:03 +000013934 enforceModifyPermission();
13935 checkForIdentifierDisclosureNotificationSupport();
13936
13937 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
13938 editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable);
13939 editor.apply();
13940
13941 // Each phone instance is responsible for updating its respective modem immediately
13942 // after we've made a preference change.
13943 for (Phone phone : PhoneFactory.getPhones()) {
13944 phone.handleIdentifierDisclosureNotificationPreferenceChange();
13945 }
13946 }
13947
13948 /**
13949 * Get whether or not cellular identifier disclosure notifications are enabled.
13950 *
13951 * @throws SecurityException if the caller does not have the required privileges
13952 * @throws UnsupportedOperationException if the modem does not support this feature.
13953 */
13954 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000013955 public boolean isCellularIdentifierDisclosureNotificationsEnabled() {
Gil Cukierman06403e12023-11-29 16:33:03 +000013956 enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled");
13957 checkForIdentifierDisclosureNotificationSupport();
13958 return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled();
13959 }
13960
13961 /**
Michael Groover826b71d2023-12-21 22:08:06 -060013962 * Enables or disables notifications sent when cellular null cipher or integrity algorithms
13963 * are in use by the cellular modem.
13964 *
13965 * @throws IllegalStateException if the Telephony process is not currently available
13966 * @throws SecurityException if the caller does not have the required privileges
13967 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
13968 * and integrity algorithms in use
13969 * @hide
13970 */
13971 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Michael Grooverae447b22024-01-24 22:35:46 -060013972 public void setNullCipherNotificationsEnabled(boolean enable) {
Michael Groover826b71d2023-12-21 22:08:06 -060013973 enforceModifyPermission();
13974 checkForNullCipherNotificationSupport();
13975
13976 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
13977 editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable);
13978 editor.apply();
13979
13980 // Each phone instance is responsible for updating its respective modem immediately
13981 // after a preference change.
13982 for (Phone phone : PhoneFactory.getPhones()) {
13983 phone.handleNullCipherNotificationPreferenceChanged();
13984 }
13985 }
13986
13987 /**
13988 * Get whether notifications are enabled for null cipher or integrity algorithms in use by the
13989 * cellular modem.
13990 *
13991 * @throws IllegalStateException if the Telephony process is not currently available
13992 * @throws SecurityException if the caller does not have the required privileges
13993 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
13994 * and integrity algorithms in use
13995 * @hide
13996 */
13997 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
13998 public boolean isNullCipherNotificationsEnabled() {
13999 enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled");
14000 checkForNullCipherNotificationSupport();
14001 return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled();
14002 }
14003
14004 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000014005 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
14006 *
14007 * <p>This method behaves in one of the following ways:
14008 * <ul>
14009 * <li>return true : if the calling package has the appop permission {@link
14010 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
14011 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
14012 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
14013 * Owner device identifier access check, or the calling package has carrier privileges</>
14014 * <li>throw SecurityException: if the caller does not meet any of the requirements.
14015 * </ul>
14016 */
14017 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
14018 String callingPackage, @Nullable String callingFeatureId, String message) {
14019 for (Phone phone : PhoneFactory.getPhones()) {
14020 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
14021 phone.getSubId(), callingPackage, callingFeatureId, message)) {
14022 return true;
14023 }
14024 }
14025 return false;
14026 }
arunvoddud7401012022-12-15 16:08:12 +000014027
14028 /**
Jack Yufa8ed012023-02-11 15:42:28 -080014029 * @return The subscription manager service instance.
14030 */
14031 public SubscriptionManagerService getSubscriptionManagerService() {
14032 return SubscriptionManagerService.getInstance();
14033 }
14034
14035 /**
arunvoddud7401012022-12-15 16:08:12 +000014036 * Class binds the consumer[callback] and carrierId.
14037 */
14038 private static class CallerCallbackInfo {
14039 private final Consumer<Integer> mConsumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014040 private final Set<Integer> mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014041
Steve Statia28b7cb32024-03-11 23:58:50 +000014042 public CallerCallbackInfo(Consumer<Integer> consumer, Set<Integer> carrierIds) {
arunvoddud7401012022-12-15 16:08:12 +000014043 mConsumer = consumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014044 mCarrierIds = carrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014045 }
14046
14047 public Consumer<Integer> getConsumer() {
14048 return mConsumer;
14049 }
14050
Steve Statia28b7cb32024-03-11 23:58:50 +000014051 public Set<Integer> getCarrierIds() {
14052 return mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014053 }
14054 }
joonhunshin4ac60942023-11-15 15:23:39 +000014055
14056 /*
14057 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14058 * But the context that is passed in is unused if the phone app is already alive.
14059 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14060 */
14061 @VisibleForTesting
14062 public void setPackageManager(PackageManager packageManager) {
14063 mPackageManager = packageManager;
14064 }
14065
14066 /*
Nate Myren453c3472024-03-13 11:28:11 -070014067 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14068 * But the context that is passed in is unused if the phone app is already alive.
14069 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14070 */
14071 @VisibleForTesting
14072 public void setAppOpsManager(AppOpsManager appOps) {
14073 mAppOps = appOps;
14074 }
14075
14076 /*
joonhunshin4ac60942023-11-15 15:23:39 +000014077 * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags.
14078 * But the FeatureFlags that is passed in is unused if the phone app is already alive.
14079 * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test.
14080 */
14081 @VisibleForTesting
14082 public void setFeatureFlags(FeatureFlags featureFlags) {
14083 mFeatureFlags = featureFlags;
14084 }
14085
14086 /**
14087 * Make sure the device has required telephony feature
14088 *
14089 * @throws UnsupportedOperationException if the device does not have required telephony feature
14090 */
14091 private void enforceTelephonyFeatureWithException(@Nullable String callingPackage,
14092 @NonNull String telephonyFeature, @NonNull String methodName) {
14093 if (callingPackage == null || mPackageManager == null) {
14094 return;
14095 }
14096
14097 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
14098 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage,
14099 Binder.getCallingUserHandle())) {
14100 return;
14101 }
14102
14103 if (!mPackageManager.hasSystemFeature(telephonyFeature)) {
14104 throw new UnsupportedOperationException(
14105 methodName + " is unsupported without " + telephonyFeature);
14106 }
14107 }
Jack Yufa8ed012023-02-11 15:42:28 -080014108}