blob: c382a441c8a1d3cd996fa086fcb10639d3664a8e [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;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800261import com.android.services.telephony.TelecomAccountRegistry;
262import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800263import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800264
Hall Liu82694d52020-12-11 18:22:04 -0800265import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700266import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800267import java.io.IOException;
268import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700269import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700270import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800271import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000272import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800273import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800274import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800275import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800276import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100277import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800278import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700279import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800280import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800281import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700282import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800283import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800284import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800285import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700286
287/**
288 * Implementation of the ITelephony interface.
289 */
Santos Cordon117fee72014-05-16 17:56:12 -0700290public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700291 private static final String LOG_TAG = "PhoneInterfaceManager";
292 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
293 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800294 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700295
296 // Message codes used with mMainThreadHandler
297 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700298 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
299 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700300 private static final int CMD_OPEN_CHANNEL = 9;
301 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
302 private static final int CMD_CLOSE_CHANNEL = 11;
303 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800304 private static final int CMD_NV_READ_ITEM = 13;
305 private static final int EVENT_NV_READ_ITEM_DONE = 14;
306 private static final int CMD_NV_WRITE_ITEM = 15;
307 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
308 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
309 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700310 private static final int CMD_RESET_MODEM_CONFIG = 19;
311 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800312 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
313 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800314 private static final int CMD_SEND_ENVELOPE = 25;
315 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700316 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
317 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
318 private static final int CMD_EXCHANGE_SIM_IO = 31;
319 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800320 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
321 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700322 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
323 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700324 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
325 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700326 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
327 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
328 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
329 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700330 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
331 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
332 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
333 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700334 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800335 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
336 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000337 private static final int CMD_SWITCH_SLOTS = 50;
338 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700339 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
340 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
341 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
342 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
343 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
344 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
345 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
346 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700347 private static final int CMD_GET_ALL_CELL_INFO = 60;
348 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
349 private static final int CMD_GET_CELL_LOCATION = 62;
350 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700351 private static final int CMD_MODEM_REBOOT = 64;
352 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700353 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
354 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800355 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
356 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700357 private static final int CMD_GET_MODEM_STATUS = 70;
358 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700359 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
360 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700361 private static final int CMD_ERASE_MODEM_CONFIG = 74;
362 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800363 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
364 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
365 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
366 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800367 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
368 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800369 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800370 private static final int CMD_GET_CALL_FORWARDING = 83;
371 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
372 private static final int CMD_SET_CALL_FORWARDING = 85;
373 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
374 private static final int CMD_GET_CALL_WAITING = 87;
375 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
376 private static final int CMD_SET_CALL_WAITING = 89;
377 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700378 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
379 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
380 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
381 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700382 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
383 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800384 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
385 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800386 private static final int CMD_SET_DATA_THROTTLING = 99;
387 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800388 private static final int CMD_SET_SIM_POWER = 101;
389 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800390 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
391 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
392 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
393 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800394 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
395 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000396 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800397 private static final int CMD_GET_SLICING_CONFIG = 110;
398 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800399 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700400 private static final int CMD_ENABLE_VONR = 113;
401 private static final int EVENT_ENABLE_VONR_DONE = 114;
402 private static final int CMD_IS_VONR_ENABLED = 115;
403 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700404 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
405 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000406
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800407 // Parameters of select command.
408 private static final int SELECT_COMMAND = 0xA4;
409 private static final int SELECT_P1 = 0x04;
410 private static final int SELECT_P2 = 0;
411 private static final int SELECT_P3 = 0x10;
412
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000413 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
414 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
Gil Cukierman06403e12023-11-29 16:33:03 +0000415 // Cellular identifier disclosure transparency was added in IRadioNetwork 2.2
416 private static final int MIN_IDENTIFIER_DISCLOSURE_VERSION = 202;
Michael Groover826b71d2023-12-21 22:08:06 -0600417 // Null cipher notification support was added in IRadioNetwork 2.2
418 private static final int MIN_NULL_CIPHER_NOTIFICATION_VERSION = 202;
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000419
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700420 /** The singleton instance. */
421 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800422 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700423
Sarah Chin4beb2b72023-02-14 14:47:54 -0800424 private final PhoneGlobals mApp;
joonhunshin4ac60942023-11-15 15:23:39 +0000425 private FeatureFlags mFeatureFlags;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800426 private final CallManager mCM;
427 private final ImsResolver mImsResolver;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000428
429 private final SatelliteController mSatelliteController;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800430 private final SatelliteAccessController mSatelliteAccessController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800431 private final UserManager mUserManager;
432 private final AppOpsManager mAppOps;
433 private final MainThreadHandler mMainThreadHandler;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800434 private final SharedPreferences mTelephonySharedPreferences;
435 private final PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800436 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
joonhunshin4ac60942023-11-15 15:23:39 +0000437 private PackageManager mPackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700438
Peter Wangdafb9ac2020-01-15 14:13:38 -0800439 /** User Activity */
Sarah Chin4beb2b72023-02-14 14:47:54 -0800440 private final AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800441 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800442 private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800443
Derek Tan97ebb422014-09-05 16:55:38 -0700444 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
445 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800446 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800447 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700448
Michelecea4cf22018-12-21 15:00:11 -0800449 // String to store multi SIM allowed
450 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
451
Derek Tan740e1672017-06-27 14:56:27 -0700452 // The AID of ISD-R.
453 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
454
yinxub1bed742017-04-17 11:45:04 -0700455 private NetworkScanRequestTracker mNetworkScanRequestTracker;
456
David Kelly5e06a7f2018-03-12 14:10:59 +0000457 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
458 private static final int MANUFACTURER_CODE_LENGTH = 8;
459
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800460 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800461 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800462
Sarah Chin2ec39f62022-08-31 17:03:26 -0700463 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
464 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
465
Derek Tan89e89d42014-07-08 17:00:10 -0700466 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700467 * Experiment flag to enable erase modem config on reset network, default value is false
468 */
469 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
470 "reset_network_erase_modem_config_enabled";
471
Rambo Wang0f050d82021-02-12 11:43:36 -0800472 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800473
Gary Jian76280a42022-12-07 16:18:33 +0800474 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
475
sandeepjsb6c87872021-09-27 15:34:44 +0000476 /**
477 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
478 * one ICCID active at the same time.
479 * Apps should use below API signatures if targeting SDK is T and beyond.
480 *
481 * @hide
482 */
483 @ChangeId
484 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
485 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800486
Naina Nallurid63128d2019-09-17 14:10:30 -0700487 /**
Chen Xu540470b2021-12-14 17:15:47 -0800488 * Apps targeting on Android T and beyond will get exception whenever icc close channel
489 * operation fails.
490 */
491 @ChangeId
492 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
493 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
494
495 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700496 * A request object to use for transmitting data to an ICC.
497 */
498 private static final class IccAPDUArgument {
499 public int channel, cla, command, p1, p2, p3;
500 public String data;
501
502 public IccAPDUArgument(int channel, int cla, int command,
503 int p1, int p2, int p3, String data) {
504 this.channel = channel;
505 this.cla = cla;
506 this.command = command;
507 this.p1 = p1;
508 this.p2 = p2;
509 this.p3 = p3;
510 this.data = data;
511 }
512 }
513
514 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700515 * A request object to use for transmitting data to an ICC.
516 */
517 private static final class ManualNetworkSelectionArgument {
518 public OperatorInfo operatorInfo;
519 public boolean persistSelection;
520
521 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
522 this.operatorInfo = operatorInfo;
523 this.persistSelection = persistSelection;
524 }
525 }
526
Sarah Chin71b3a852022-09-28 15:54:19 -0700527 private static final class PurchasePremiumCapabilityArgument {
528 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700529 public @NonNull IIntegerConsumer callback;
530
531 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800532 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700533 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700534 this.callback = callback;
535 }
536 }
537
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700538 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700539 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
540 * request after sending. The main thread will notify the request when it is complete.
541 */
542 private static final class MainThreadRequest {
543 /** The argument to use for the request */
544 public Object argument;
545 /** The result of the request that is run on the main thread */
546 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800547 // The subscriber id that this request applies to. Defaults to
548 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
549 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700550
Nathan Harold92bed182018-10-12 18:16:49 -0700551 // In cases where subId is unavailable, the caller needs to specify the phone.
552 public Phone phone;
553
vagdeviaf9a5b92018-08-15 16:01:53 -0700554 public WorkSource workSource;
555
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700556 public MainThreadRequest(Object argument) {
557 this.argument = argument;
558 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800559
Nathan Harold92bed182018-10-12 18:16:49 -0700560 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
561 this.argument = argument;
562 if (phone != null) {
563 this.phone = phone;
564 }
565 this.workSource = workSource;
566 }
567
vagdeviaf9a5b92018-08-15 16:01:53 -0700568 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800569 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800570 if (subId != null) {
571 this.subId = subId;
572 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700573 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800574 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700575 }
576
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800577 private static final class IncomingThirdPartyCallArgs {
578 public final ComponentName component;
579 public final String callId;
580 public final String callerDisplayName;
581
582 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
583 String callerDisplayName) {
584 this.component = component;
585 this.callId = callId;
586 this.callerDisplayName = callerDisplayName;
587 }
588 }
589
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700590 /**
591 * A handler that processes messages on the main thread in the phone process. Since many
592 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
593 * inbound binder threads to the main thread in the phone process. The Binder thread
594 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
595 * on, which will be notified when the operation completes and will contain the result of the
596 * request.
597 *
598 * <p>If a MainThreadRequest object is provided in the msg.obj field,
599 * note that request.result must be set to something non-null for the calling thread to
600 * unblock.
601 */
602 private final class MainThreadHandler extends Handler {
603 @Override
604 public void handleMessage(Message msg) {
605 MainThreadRequest request;
606 Message onCompleted;
607 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000608 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700609 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800610 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700611
612 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700613 case CMD_HANDLE_USSD_REQUEST: {
614 request = (MainThreadRequest) msg.obj;
615 final Phone phone = getPhoneFromRequest(request);
616 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800617 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700618 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700619
Pengquan Menga1bb6272018-09-06 09:59:22 -0700620 if (!isUssdApiAllowed(request.subId)) {
621 // Carrier does not support use of this API, return failure.
622 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
623 UssdResponse response = new UssdResponse(ussdRequest, null);
624 Bundle returnData = new Bundle();
625 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
626 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700627
Pengquan Menga1bb6272018-09-06 09:59:22 -0700628 request.result = true;
629 notifyRequester(request);
630 return;
631 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700632
Pengquan Menga1bb6272018-09-06 09:59:22 -0700633 try {
634 request.result = phone != null
635 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
636 } catch (CallStateException cse) {
637 request.result = false;
638 }
639 // Wake up the requesting thread
640 notifyRequester(request);
641 break;
pkanwar32d516d2016-10-14 19:37:38 -0700642 }
643
Yorke Lee716f67e2015-06-17 15:39:16 -0700644 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700645 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700646 final Phone phone = getPhoneFromRequest(request);
647 request.result = phone != null ?
648 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
649 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700650 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700651 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700652 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700653 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700654
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700655 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700656 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700657 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000658 uiccPort = getUiccPortFromRequest(request);
659 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700660 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800661 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700662 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700663 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700664 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800665 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000666 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800667 iccArgument.channel, iccArgument.cla, iccArgument.command,
668 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
669 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700670 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700671 break;
672
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700673 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700674 ar = (AsyncResult) msg.obj;
675 request = (MainThreadRequest) ar.userObj;
676 if (ar.exception == null && ar.result != null) {
677 request.result = ar.result;
678 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800679 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700680 if (ar.result == null) {
681 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800682 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700683 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800684 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700685 } else {
686 loge("iccTransmitApduLogicalChannel: Unknown exception");
687 }
688 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700689 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700690 break;
691
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700692 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
693 request = (MainThreadRequest) msg.obj;
694 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000695 uiccPort = getUiccPortFromRequest(request);
696 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700697 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800698 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700699 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700700 } else {
701 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800702 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000703 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800704 iccArgument.cla, iccArgument.command, iccArgument.p1,
705 iccArgument.p2,
706 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700707 }
708 break;
709
710 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
711 ar = (AsyncResult) msg.obj;
712 request = (MainThreadRequest) ar.userObj;
713 if (ar.exception == null && ar.result != null) {
714 request.result = ar.result;
715 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800716 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700717 if (ar.result == null) {
718 loge("iccTransmitApduBasicChannel: Empty response");
719 } else if (ar.exception instanceof CommandException) {
720 loge("iccTransmitApduBasicChannel: CommandException: " +
721 ar.exception);
722 } else {
723 loge("iccTransmitApduBasicChannel: Unknown exception");
724 }
725 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700726 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700727 break;
728
729 case CMD_EXCHANGE_SIM_IO:
730 request = (MainThreadRequest) msg.obj;
731 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000732 uiccPort = getUiccPortFromRequest(request);
733 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700734 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800735 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700736 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700737 } else {
738 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
739 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000740 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700741 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
742 iccArgument.data, onCompleted);
743 }
744 break;
745
746 case EVENT_EXCHANGE_SIM_IO_DONE:
747 ar = (AsyncResult) msg.obj;
748 request = (MainThreadRequest) ar.userObj;
749 if (ar.exception == null && ar.result != null) {
750 request.result = ar.result;
751 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800752 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700753 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700754 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700755 break;
756
Derek Tan4d5e5c12014-02-04 11:54:58 -0800757 case CMD_SEND_ENVELOPE:
758 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000759 uiccPort = getUiccPortFromRequest(request);
760 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700761 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800762 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700763 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700764 } else {
765 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800766 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700767 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800768 break;
769
770 case EVENT_SEND_ENVELOPE_DONE:
771 ar = (AsyncResult) msg.obj;
772 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700773 if (ar.exception == null && ar.result != null) {
774 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800775 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800776 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700777 if (ar.result == null) {
778 loge("sendEnvelopeWithStatus: Empty response");
779 } else if (ar.exception instanceof CommandException) {
780 loge("sendEnvelopeWithStatus: CommandException: " +
781 ar.exception);
782 } else {
783 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
784 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800785 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700786 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800787 break;
788
Shishir Agrawal566b7612013-10-28 14:41:00 -0700789 case CMD_OPEN_CHANNEL:
790 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000791 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800792 IccLogicalChannelRequest openChannelRequest =
793 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000794 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700795 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800796 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800797 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700798 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700799 } else {
800 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800801 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
802 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700803 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700804 break;
805
806 case EVENT_OPEN_CHANNEL_DONE:
807 ar = (AsyncResult) msg.obj;
808 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700809 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700810 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700811 int[] result = (int[]) ar.result;
812 int channelId = result[0];
813 byte[] selectResponse = null;
814 if (result.length > 1) {
815 selectResponse = new byte[result.length - 1];
816 for (int i = 1; i < result.length; ++i) {
817 selectResponse[i - 1] = (byte) result[i];
818 }
819 }
820 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800821 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800822
823 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700824 if (uiccPort == null) {
825 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
826 } else {
827 IccLogicalChannelRequest channelRequest =
828 (IccLogicalChannelRequest) request.argument;
829 channelRequest.channel = channelId;
830 uiccPort.onLogicalChannelOpened(channelRequest);
831 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700832 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700833 if (ar.result == null) {
834 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700835 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700836 if (ar.exception != null) {
837 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
838 }
839
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700840 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700841 if (ar.exception instanceof CommandException) {
842 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800843 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700844 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700845 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700846 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700847 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700848 }
849 }
850 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800851 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700852 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700853 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700854 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700855 break;
856
857 case CMD_CLOSE_CHANNEL:
858 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000859 uiccPort = getUiccPortFromRequest(request);
860 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700861 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800862 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800863 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800864 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700865 } else {
866 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000867 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700868 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700869 break;
870
871 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800872 ar = (AsyncResult) msg.obj;
873 request = (MainThreadRequest) ar.userObj;
874 if (ar.exception == null) {
875 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800876 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700877 if (uiccPort == null) {
878 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
879 } else {
880 final int channelId = (Integer) request.argument;
881 uiccPort.onLogicalChannelClosed(channelId);
882 }
Chen Xu540470b2021-12-14 17:15:47 -0800883 } else {
884 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800885 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800886 if (ar.exception instanceof CommandException) {
887 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
888 CommandException.Error error =
889 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800890 if (error == CommandException.Error.INVALID_ARGUMENTS) {
891 // should only throw exceptions from the binder threads.
892 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800893 "iccCloseLogicalChannel: invalid argument ");
894 }
895 } else {
896 loge("iccCloseLogicalChannel: Unknown exception");
897 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800898 request.result = (exception != null) ? exception :
899 new IllegalStateException(
900 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800901 }
902 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800903 break;
904
905 case CMD_NV_READ_ITEM:
906 request = (MainThreadRequest) msg.obj;
907 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800908 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
909 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800910 break;
911
912 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700913 ar = (AsyncResult) msg.obj;
914 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800915 if (ar.exception == null && ar.result != null) {
916 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700917 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800918 request.result = "";
919 if (ar.result == null) {
920 loge("nvReadItem: Empty response");
921 } else if (ar.exception instanceof CommandException) {
922 loge("nvReadItem: CommandException: " +
923 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700924 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800925 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700926 }
927 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700928 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700929 break;
930
Jake Hambye994d462014-02-03 13:10:13 -0800931 case CMD_NV_WRITE_ITEM:
932 request = (MainThreadRequest) msg.obj;
933 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
934 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800935 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700936 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800937 break;
938
939 case EVENT_NV_WRITE_ITEM_DONE:
940 handleNullReturnEvent(msg, "nvWriteItem");
941 break;
942
943 case CMD_NV_WRITE_CDMA_PRL:
944 request = (MainThreadRequest) msg.obj;
945 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800946 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800947 break;
948
949 case EVENT_NV_WRITE_CDMA_PRL_DONE:
950 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
951 break;
952
chen xu6dac5ab2018-10-26 17:39:23 -0700953 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800954 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700955 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800956 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800957 break;
958
chen xu6dac5ab2018-10-26 17:39:23 -0700959 case EVENT_RESET_MODEM_CONFIG_DONE:
960 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800961 break;
962
Sooraj Sasindran37444802020-08-11 10:40:43 -0700963 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
964 request = (MainThreadRequest) msg.obj;
965 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
966 request);
967 Phone phone = getPhoneFromRequest(request);
968 if (phone != null) {
969 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
970 } else {
971 loge("isNRDualConnectivityEnabled: No phone object");
972 request.result = false;
973 notifyRequester(request);
974 }
975 break;
976 }
977
978 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
979 ar = (AsyncResult) msg.obj;
980 request = (MainThreadRequest) ar.userObj;
981 if (ar.exception == null && ar.result != null) {
982 request.result = ar.result;
983 } else {
984 // request.result must be set to something non-null
985 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700986 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700987 request.result = ar.result;
988 } else {
989 request.result = false;
990 }
991 if (ar.result == null) {
992 loge("isNRDualConnectivityEnabled: Empty response");
993 } else if (ar.exception instanceof CommandException) {
994 loge("isNRDualConnectivityEnabled: CommandException: "
995 + ar.exception);
996 } else {
997 loge("isNRDualConnectivityEnabled: Unknown exception");
998 }
999 }
1000 notifyRequester(request);
1001 break;
1002
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001003 case CMD_IS_VONR_ENABLED: {
1004 request = (MainThreadRequest) msg.obj;
1005 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
1006 request);
1007 Phone phone = getPhoneFromRequest(request);
1008 if (phone != null) {
1009 phone.isVoNrEnabled(onCompleted, request.workSource);
1010 } else {
1011 loge("isVoNrEnabled: No phone object");
1012 request.result = false;
1013 notifyRequester(request);
1014 }
1015 break;
1016 }
1017
1018 case EVENT_IS_VONR_ENABLED_DONE:
1019 ar = (AsyncResult) msg.obj;
1020 request = (MainThreadRequest) ar.userObj;
1021 if (ar.exception == null && ar.result != null) {
1022 request.result = ar.result;
1023 } else {
1024 // request.result must be set to something non-null
1025 // for the calling thread to unblock
1026 if (ar.result != null) {
1027 request.result = ar.result;
1028 } else {
1029 request.result = false;
1030 }
1031 if (ar.result == null) {
1032 loge("isVoNrEnabled: Empty response");
1033 } else if (ar.exception instanceof CommandException) {
1034 loge("isVoNrEnabled: CommandException: "
1035 + ar.exception);
1036 } else {
1037 loge("isVoNrEnabled: Unknown exception");
1038 }
1039 }
1040 notifyRequester(request);
1041 break;
1042
Sooraj Sasindran37444802020-08-11 10:40:43 -07001043 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1044 request = (MainThreadRequest) msg.obj;
1045 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1046 Phone phone = getPhoneFromRequest(request);
1047 if (phone != null) {
1048 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1049 request.workSource);
1050 } else {
1051 loge("enableNrDualConnectivity: No phone object");
1052 request.result =
1053 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1054 notifyRequester(request);
1055 }
1056 break;
1057 }
1058
1059 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1060 ar = (AsyncResult) msg.obj;
1061 request = (MainThreadRequest) ar.userObj;
1062 if (ar.exception == null) {
1063 request.result =
1064 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1065 } else {
1066 request.result =
1067 TelephonyManager
1068 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1069 if (ar.exception instanceof CommandException) {
1070 CommandException.Error error =
1071 ((CommandException) (ar.exception)).getCommandError();
1072 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1073 request.result =
1074 TelephonyManager
1075 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001076 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1077 request.result =
1078 TelephonyManager
1079 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001080 }
1081 loge("enableNrDualConnectivity" + ": CommandException: "
1082 + ar.exception);
1083 } else {
1084 loge("enableNrDualConnectivity" + ": Unknown exception");
1085 }
1086 }
1087 notifyRequester(request);
1088 break;
1089 }
1090
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001091 case CMD_ENABLE_VONR: {
1092 request = (MainThreadRequest) msg.obj;
1093 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1094 Phone phone = getPhoneFromRequest(request);
1095 if (phone != null) {
1096 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1097 request.workSource);
1098 } else {
1099 loge("setVoNrEnabled: No phone object");
1100 request.result =
1101 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1102 notifyRequester(request);
1103 }
1104 break;
1105 }
1106
1107 case EVENT_ENABLE_VONR_DONE: {
1108 ar = (AsyncResult) msg.obj;
1109 request = (MainThreadRequest) ar.userObj;
1110 if (ar.exception == null) {
1111 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1112 } else {
1113 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1114 if (ar.exception instanceof CommandException) {
1115 CommandException.Error error =
1116 ((CommandException) (ar.exception)).getCommandError();
1117 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1118 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1119 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1120 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1121 } else {
1122 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1123 }
1124 loge("setVoNrEnabled" + ": CommandException: "
1125 + ar.exception);
1126 } else {
1127 loge("setVoNrEnabled" + ": Unknown exception");
1128 }
1129 }
1130 notifyRequester(request);
1131 break;
1132 }
1133
SongFerngWang3ef3e072020-12-21 16:41:52 +08001134 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001135 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001136 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1137 request);
1138 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001139 break;
1140
SongFerngWang3ef3e072020-12-21 16:41:52 +08001141 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001142 ar = (AsyncResult) msg.obj;
1143 request = (MainThreadRequest) ar.userObj;
1144 if (ar.exception == null && ar.result != null) {
1145 request.result = ar.result; // Integer
1146 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301147 // request.result must be set to something non-null
1148 // for the calling thread to unblock
1149 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001150 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001151 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001152 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001153 loge("getAllowedNetworkTypesBitmask: CommandException: "
1154 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001155 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001156 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001157 }
1158 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001159 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001160 break;
1161
SongFerngWang3ef3e072020-12-21 16:41:52 +08001162 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001163 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001164 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1165 request);
1166 Pair<Integer, Long> reasonWithNetworkTypes =
1167 (Pair<Integer, Long>) request.argument;
1168 getPhoneFromRequest(request).setAllowedNetworkTypes(
1169 reasonWithNetworkTypes.first,
1170 reasonWithNetworkTypes.second,
1171 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001172 break;
1173
SongFerngWang3ef3e072020-12-21 16:41:52 +08001174 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1175 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001176 break;
1177
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001178 case CMD_SET_VOICEMAIL_NUMBER:
1179 request = (MainThreadRequest) msg.obj;
1180 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1181 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001182 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1183 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001184 break;
1185
1186 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1187 handleNullReturnEvent(msg, "setVoicemailNumber");
1188 break;
1189
Stuart Scott54788802015-03-30 13:18:01 -07001190 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1191 request = (MainThreadRequest) msg.obj;
1192 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1193 request);
1194 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1195 break;
1196
1197 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1198 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1199 break;
1200
Shishir Agrawal302c8692015-06-19 13:49:39 -07001201 case CMD_PERFORM_NETWORK_SCAN:
1202 request = (MainThreadRequest) msg.obj;
1203 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1204 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1205 break;
1206
Hall Liu27d24262020-09-18 19:04:59 -07001207 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001208 request = (MainThreadRequest) msg.obj;
1209 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001210 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1211 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1212 request.argument;
1213 int callForwardingReason = args.first;
1214 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001215 break;
Hall Liu27d24262020-09-18 19:04:59 -07001216 }
1217 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001218 ar = (AsyncResult) msg.obj;
1219 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001220 TelephonyManager.CallForwardingInfoCallback callback =
1221 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1222 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001223 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001224 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001225 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1226 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1227 // Service Class is a bit mask per 3gpp 27.007. Search for
1228 // any service for voice call.
1229 if ((callForwardInfo.serviceClass
1230 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001231 callForwardingInfo = new CallForwardingInfo(
1232 callForwardInfo.status
1233 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001234 callForwardInfo.reason,
1235 callForwardInfo.number,
1236 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001237 break;
1238 }
1239 }
1240 // Didn't find a call forward info for voice call.
1241 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001242 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1243 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001244 }
Hall Liu27d24262020-09-18 19:04:59 -07001245 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001246 } else {
1247 if (ar.result == null) {
1248 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1249 }
1250 if (ar.exception != null) {
1251 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1252 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001253 int errorCode = TelephonyManager
1254 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001255 if (ar.exception instanceof CommandException) {
1256 CommandException.Error error =
1257 ((CommandException) (ar.exception)).getCommandError();
1258 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001259 errorCode = TelephonyManager
1260 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001261 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001262 errorCode = TelephonyManager
1263 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001264 }
1265 }
Hall Liu27d24262020-09-18 19:04:59 -07001266 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001267 }
Shuo Qian4a594052020-01-23 11:59:30 -08001268 break;
Hall Liu27d24262020-09-18 19:04:59 -07001269 }
Shuo Qian4a594052020-01-23 11:59:30 -08001270
Hall Liu27d24262020-09-18 19:04:59 -07001271 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001272 request = (MainThreadRequest) msg.obj;
1273 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001274 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001275 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001276 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1277 request.argument).first;
1278 request.phone.setCallForwardingOption(
1279 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001280 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001281 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001282 callForwardingInfoToSet.getReason(),
1283 callForwardingInfoToSet.getNumber(),
1284 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1285 break;
Hall Liu27d24262020-09-18 19:04:59 -07001286 }
Shuo Qian4a594052020-01-23 11:59:30 -08001287
Hall Liu27d24262020-09-18 19:04:59 -07001288 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001289 ar = (AsyncResult) msg.obj;
1290 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001291 Consumer<Integer> callback =
1292 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1293 request.argument).second;
1294 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001295 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001296 int errorCode = TelephonyManager.CallForwardingInfoCallback
1297 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001298 if (ar.exception instanceof CommandException) {
1299 CommandException.Error error =
1300 ((CommandException) (ar.exception)).getCommandError();
1301 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001302 errorCode = TelephonyManager.CallForwardingInfoCallback
1303 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001304 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001305 errorCode = TelephonyManager.CallForwardingInfoCallback
1306 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001307 }
1308 }
1309 callback.accept(errorCode);
1310 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001311 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001312 }
Shuo Qian4a594052020-01-23 11:59:30 -08001313 break;
Hall Liu27d24262020-09-18 19:04:59 -07001314 }
Shuo Qian4a594052020-01-23 11:59:30 -08001315
Hall Liu27d24262020-09-18 19:04:59 -07001316 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001317 request = (MainThreadRequest) msg.obj;
1318 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1319 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1320 break;
Hall Liu27d24262020-09-18 19:04:59 -07001321 }
Shuo Qian4a594052020-01-23 11:59:30 -08001322
Hall Liu27d24262020-09-18 19:04:59 -07001323 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001324 ar = (AsyncResult) msg.obj;
1325 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001326 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001327 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001328 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001329 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001330 // Service Class is a bit mask per 3gpp 27.007.
1331 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001332 if (callForwardResults.length > 1
1333 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001334 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001335 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001336 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1337 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001338 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001339 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001340 }
1341 } else {
1342 if (ar.result == null) {
1343 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1344 }
1345 if (ar.exception != null) {
1346 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1347 }
1348 if (ar.exception instanceof CommandException) {
1349 CommandException.Error error =
1350 ((CommandException) (ar.exception)).getCommandError();
1351 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001352 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001353 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001354 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1355 callWaitingStatus =
1356 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001357 }
1358 }
1359 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001360 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001361 break;
Hall Liu27d24262020-09-18 19:04:59 -07001362 }
Shuo Qian4a594052020-01-23 11:59:30 -08001363
Hall Liu27d24262020-09-18 19:04:59 -07001364 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001365 request = (MainThreadRequest) msg.obj;
1366 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001367 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1368 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001369 break;
Hall Liu27d24262020-09-18 19:04:59 -07001370 }
Shuo Qian4a594052020-01-23 11:59:30 -08001371
Hall Liu27d24262020-09-18 19:04:59 -07001372 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001373 ar = (AsyncResult) msg.obj;
1374 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001375 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1376 Consumer<Integer> callback =
1377 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1378 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001379 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001380 if (ar.exception instanceof CommandException) {
1381 CommandException.Error error =
1382 ((CommandException) (ar.exception)).getCommandError();
1383 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1384 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001385 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1386 callback.accept(
1387 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001388 } else {
1389 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1390 }
1391 } else {
1392 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1393 }
1394 } else {
1395 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1396 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001397 }
Shuo Qian4a594052020-01-23 11:59:30 -08001398 break;
Hall Liu27d24262020-09-18 19:04:59 -07001399 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001400 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1401 ar = (AsyncResult) msg.obj;
1402 request = (MainThreadRequest) ar.userObj;
1403 CellNetworkScanResult cellScanResult;
1404 if (ar.exception == null && ar.result != null) {
1405 cellScanResult = new CellNetworkScanResult(
1406 CellNetworkScanResult.STATUS_SUCCESS,
1407 (List<OperatorInfo>) ar.result);
1408 } else {
1409 if (ar.result == null) {
1410 loge("getCellNetworkScanResults: Empty response");
1411 }
1412 if (ar.exception != null) {
1413 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1414 }
1415 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1416 if (ar.exception instanceof CommandException) {
1417 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001418 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001419 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1420 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1421 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1422 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1423 }
1424 }
1425 cellScanResult = new CellNetworkScanResult(errorCode, null);
1426 }
1427 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001428 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001429 break;
1430
1431 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1432 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001433 ManualNetworkSelectionArgument selArg =
1434 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001435 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1436 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001437 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1438 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001439 break;
1440
1441 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001442 ar = (AsyncResult) msg.obj;
1443 request = (MainThreadRequest) ar.userObj;
1444 if (ar.exception == null) {
1445 request.result = true;
1446 } else {
1447 request.result = false;
1448 loge("setNetworkSelectionModeManual " + ar.exception);
1449 }
1450 notifyRequester(request);
1451 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001452 break;
1453
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001454 case CMD_GET_MODEM_ACTIVITY_INFO:
1455 request = (MainThreadRequest) msg.obj;
1456 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001457 if (defaultPhone != null) {
1458 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001459 } else {
1460 ResultReceiver result = (ResultReceiver) request.argument;
1461 Bundle bundle = new Bundle();
1462 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001463 new ModemActivityInfo(0, 0, 0,
1464 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001465 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001466 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001467 break;
1468
Hall Liud0f208c2020-10-14 16:54:44 -07001469 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001470 ar = (AsyncResult) msg.obj;
1471 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001472 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001473 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001474 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001475 if (mLastModemActivityInfo == null) {
1476 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1477 mLastModemActivitySpecificInfo[0] =
1478 new ActivityStatsTechSpecificInfo(
1479 0,
1480 0,
1481 new int[ModemActivityInfo.getNumTxPowerLevels()],
1482 0);
1483 mLastModemActivityInfo =
1484 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1485 }
1486
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001487 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001488 // Update the last modem activity info and the result of the request.
1489 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1490 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001491 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001492 } else {
1493 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001494 }
Kai Shi917fdc62022-11-28 14:01:02 -08001495 // This is needed to decouple ret from mLastModemActivityInfo
1496 // We don't want to return mLastModemActivityInfo which is updated
1497 // inside mergeModemActivityInfo()
1498 ret = new ModemActivityInfo(
1499 mLastModemActivityInfo.getTimestampMillis(),
1500 mLastModemActivityInfo.getSleepTimeMillis(),
1501 mLastModemActivityInfo.getIdleTimeMillis(),
1502 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001503
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001504 } else {
1505 if (ar.result == null) {
1506 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001507 error = TelephonyManager.ModemActivityInfoException
1508 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001509 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001510 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001511 error = TelephonyManager.ModemActivityInfoException
1512 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001513 } else {
1514 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001515 error = TelephonyManager.ModemActivityInfoException
1516 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001517 }
1518 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001519 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001520 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001521 bundle.putParcelable(
1522 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001523 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001524 } else {
1525 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1526 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001527 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001528 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001529 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001530 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001531
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001532 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001533 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001534 CarrierRestrictionRules argument =
1535 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001536 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001537 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001538 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001539 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001540
1541 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1542 ar = (AsyncResult) msg.obj;
1543 request = (MainThreadRequest) ar.userObj;
1544 if (ar.exception == null && ar.result != null) {
1545 request.result = ar.result;
1546 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001547 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1548 if (ar.exception instanceof CommandException) {
1549 loge("setAllowedCarriers: CommandException: " + ar.exception);
1550 CommandException.Error error =
1551 ((CommandException) (ar.exception)).getCommandError();
1552 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1553 request.result =
1554 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1555 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001556 } else {
1557 loge("setAllowedCarriers: Unknown exception");
1558 }
1559 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001560 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001561 break;
1562
1563 case CMD_GET_ALLOWED_CARRIERS:
1564 request = (MainThreadRequest) msg.obj;
1565 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001566 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001567 break;
1568
1569 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1570 ar = (AsyncResult) msg.obj;
1571 request = (MainThreadRequest) ar.userObj;
1572 if (ar.exception == null && ar.result != null) {
1573 request.result = ar.result;
1574 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001575 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001576 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001577 if (ar.result == null) {
1578 loge("getAllowedCarriers: Empty response");
1579 } else if (ar.exception instanceof CommandException) {
1580 loge("getAllowedCarriers: CommandException: " +
1581 ar.exception);
1582 } else {
1583 loge("getAllowedCarriers: Unknown exception");
1584 }
1585 }
arunvoddud7401012022-12-15 16:08:12 +00001586 if (request.argument != null) {
1587 // This is for the implementation of carrierRestrictionStatus.
1588 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1589 Consumer<Integer> callback = callbackInfo.getConsumer();
1590 int callerCarrierId = callbackInfo.getCarrierId();
1591 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1592 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1593 CarrierRestrictionRules carrierRestrictionRules =
1594 (CarrierRestrictionRules) ar.result;
1595 int carrierId = -1;
1596 try {
1597 CarrierIdentifier carrierIdentifier =
1598 carrierRestrictionRules.getAllowedCarriers().get(0);
1599 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1600 carrierIdentifier);
1601 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1602 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1603 }
1604 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
1605 if (carrierId != -1 && callerCarrierId == carrierId && lockStatus
1606 == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001607 lockStatus = TelephonyManager
1608 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001609 }
1610 } else {
1611 Rlog.e(LOG_TAG,
1612 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1613 }
1614 callback.accept(lockStatus);
1615 } else {
1616 // This is for the implementation of getAllowedCarriers.
1617 notifyRequester(request);
1618 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001619 break;
1620
Nathan Haroldb3014052017-01-25 15:57:32 -08001621 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1622 ar = (AsyncResult) msg.obj;
1623 request = (MainThreadRequest) ar.userObj;
1624 if (ar.exception == null && ar.result != null) {
1625 request.result = ar.result;
1626 } else {
1627 request.result = new IllegalArgumentException(
1628 "Failed to retrieve Forbidden Plmns");
1629 if (ar.result == null) {
1630 loge("getForbiddenPlmns: Empty response");
1631 } else {
1632 loge("getForbiddenPlmns: Unknown exception");
1633 }
1634 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001635 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001636 break;
1637
1638 case CMD_GET_FORBIDDEN_PLMNS:
1639 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001640 uiccPort = getUiccPortFromRequest(request);
1641 if (uiccPort == null) {
1642 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001643 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001644 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001645 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001646 break;
1647 }
1648 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001649 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001650 if (uiccApp == null) {
1651 loge("getForbiddenPlmns() no app with specified type -- "
1652 + appType);
1653 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001654 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001655 break;
1656 } else {
1657 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1658 + " specified type -- " + appType);
1659 }
1660 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1661 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001662 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001663 break;
1664
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001665 case CMD_SWITCH_SLOTS:
1666 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001667 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001668 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001669 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001670 break;
1671
1672 case EVENT_SWITCH_SLOTS_DONE:
1673 ar = (AsyncResult) msg.obj;
1674 request = (MainThreadRequest) ar.userObj;
1675 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001676 notifyRequester(request);
1677 break;
1678 case CMD_GET_NETWORK_SELECTION_MODE:
1679 request = (MainThreadRequest) msg.obj;
1680 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1681 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1682 break;
1683
1684 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1685 ar = (AsyncResult) msg.obj;
1686 request = (MainThreadRequest) ar.userObj;
1687 if (ar.exception != null) {
1688 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1689 } else {
1690 int mode = ((int[]) ar.result)[0];
1691 if (mode == 0) {
1692 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1693 } else {
1694 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1695 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001696 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001697 notifyRequester(request);
1698 break;
1699 case CMD_GET_CDMA_ROAMING_MODE:
1700 request = (MainThreadRequest) msg.obj;
1701 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1702 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1703 break;
1704 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1705 ar = (AsyncResult) msg.obj;
1706 request = (MainThreadRequest) ar.userObj;
1707 if (ar.exception != null) {
1708 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1709 } else {
1710 request.result = ((int[]) ar.result)[0];
1711 }
1712 notifyRequester(request);
1713 break;
1714 case CMD_SET_CDMA_ROAMING_MODE:
1715 request = (MainThreadRequest) msg.obj;
1716 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1717 int mode = (int) request.argument;
1718 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1719 break;
1720 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1721 ar = (AsyncResult) msg.obj;
1722 request = (MainThreadRequest) ar.userObj;
1723 request.result = ar.exception == null;
1724 notifyRequester(request);
1725 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001726 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1727 request = (MainThreadRequest) msg.obj;
1728 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1729 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1730 break;
1731 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1732 ar = (AsyncResult) msg.obj;
1733 request = (MainThreadRequest) ar.userObj;
1734 if (ar.exception != null) {
1735 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1736 } else {
1737 request.result = ((int[]) ar.result)[0];
1738 }
1739 notifyRequester(request);
1740 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001741 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1742 request = (MainThreadRequest) msg.obj;
1743 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1744 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001745 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1746 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001747 break;
1748 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1749 ar = (AsyncResult) msg.obj;
1750 request = (MainThreadRequest) ar.userObj;
1751 request.result = ar.exception == null;
1752 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001753 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001754 case CMD_GET_ALL_CELL_INFO:
1755 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001756 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001757 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001758 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001759 case EVENT_GET_ALL_CELL_INFO_DONE:
1760 ar = (AsyncResult) msg.obj;
1761 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001762 // If a timeout occurs, the response will be null
1763 request.result = (ar.exception == null && ar.result != null)
1764 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001765 synchronized (request) {
1766 request.notifyAll();
1767 }
1768 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001769 case CMD_REQUEST_CELL_INFO_UPDATE:
1770 request = (MainThreadRequest) msg.obj;
1771 request.phone.requestCellInfoUpdate(request.workSource,
1772 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1773 break;
1774 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1775 ar = (AsyncResult) msg.obj;
1776 request = (MainThreadRequest) ar.userObj;
1777 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1778 try {
1779 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001780 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001781 cb.onError(
1782 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1783 ar.exception.getClass().getName(),
1784 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001785 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001786 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001787 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001788 } else {
1789 // use the result as returned
1790 cb.onCellInfo((List<CellInfo>) ar.result);
1791 }
1792 } catch (RemoteException re) {
1793 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1794 }
1795 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001796 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001797 request = (MainThreadRequest) msg.obj;
1798 WorkSource ws = (WorkSource) request.argument;
1799 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001800 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001801 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001802 }
1803 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001804 ar = (AsyncResult) msg.obj;
1805 request = (MainThreadRequest) ar.userObj;
1806 if (ar.exception == null) {
1807 request.result = ar.result;
1808 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001809 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001810 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001811 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001812 }
1813
1814 synchronized (request) {
1815 request.notifyAll();
1816 }
1817 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001818 }
chen xu6dac5ab2018-10-26 17:39:23 -07001819 case CMD_MODEM_REBOOT:
1820 request = (MainThreadRequest) msg.obj;
1821 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001822 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001823 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001824 case EVENT_CMD_MODEM_REBOOT_DONE:
1825 handleNullReturnEvent(msg, "rebootModem");
1826 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001827 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001828 request = (MainThreadRequest) msg.obj;
1829 boolean enable = (boolean) request.argument;
1830 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001831 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001832 PhoneConfigurationManager.getInstance()
1833 .enablePhone(request.phone, enable, onCompleted);
1834 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001835 }
Michele Berionne5e411512020-11-13 02:36:59 +00001836 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001837 ar = (AsyncResult) msg.obj;
1838 request = (MainThreadRequest) ar.userObj;
1839 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001840 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001841 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001842 if ((boolean) request.result) {
1843 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1844 updateModemStateMetrics();
1845 } else {
1846 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1847 + ar.exception);
1848 }
1849 notifyRequester(request);
1850 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001851 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001852 case CMD_GET_MODEM_STATUS:
1853 request = (MainThreadRequest) msg.obj;
1854 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1855 PhoneConfigurationManager.getInstance()
1856 .getPhoneStatusFromModem(request.phone, onCompleted);
1857 break;
1858 case EVENT_GET_MODEM_STATUS_DONE:
1859 ar = (AsyncResult) msg.obj;
1860 request = (MainThreadRequest) ar.userObj;
1861 int id = request.phone.getPhoneId();
1862 if (ar.exception == null && ar.result != null) {
1863 request.result = ar.result;
1864 //update the cache as modem status has changed
1865 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1866 (boolean) request.result);
1867 } else {
1868 // Return true if modem status cannot be retrieved. For most cases,
1869 // modem status is on. And for older version modems, GET_MODEM_STATUS
1870 // and disable modem are not supported. Modem is always on.
1871 // TODO: this should be fixed in R to support a third
1872 // status UNKNOWN b/131631629
1873 request.result = true;
1874 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1875 + ar.exception);
1876 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001877 notifyRequester(request);
1878 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001879 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1880 request = (MainThreadRequest) msg.obj;
1881 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1882 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1883 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1884 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1885 break;
1886 }
1887 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1888 ar = (AsyncResult) msg.obj;
1889 request = (MainThreadRequest) ar.userObj;
1890 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1891 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1892 args.second.accept(ar.exception == null);
1893 notifyRequester(request);
1894 break;
1895 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001896 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1897 request = (MainThreadRequest) msg.obj;
1898 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1899 Phone phone = getPhoneFromRequest(request);
1900 if (phone != null) {
1901 phone.getSystemSelectionChannels(onCompleted);
1902 } else {
1903 loge("getSystemSelectionChannels: No phone object");
1904 request.result = new ArrayList<RadioAccessSpecifier>();
1905 notifyRequester(request);
1906 }
1907 break;
1908 }
1909 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1910 ar = (AsyncResult) msg.obj;
1911 request = (MainThreadRequest) ar.userObj;
1912 if (ar.exception == null && ar.result != null) {
1913 request.result = ar.result;
1914 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001915 request.result = new IllegalStateException(
1916 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001917 if (ar.result == null) {
1918 loge("getSystemSelectionChannels: Empty response");
1919 } else {
1920 loge("getSystemSelectionChannels: Unknown exception");
1921 }
1922 }
1923 notifyRequester(request);
1924 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001925 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1926 ar = (AsyncResult) msg.obj;
1927 request = (MainThreadRequest) ar.userObj;
1928 if (ar.exception == null && ar.result != null) {
1929 request.result = ar.result;
1930 } else {
1931 request.result = -1;
1932 loge("Failed to set Forbidden Plmns");
1933 if (ar.result == null) {
1934 loge("setForbidenPlmns: Empty response");
1935 } else if (ar.exception != null) {
1936 loge("setForbiddenPlmns: Exception: " + ar.exception);
1937 request.result = -1;
1938 } else {
1939 loge("setForbiddenPlmns: Unknown exception");
1940 }
1941 }
1942 notifyRequester(request);
1943 break;
1944 case CMD_SET_FORBIDDEN_PLMNS:
1945 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001946 uiccPort = getUiccPortFromRequest(request);
1947 if (uiccPort == null) {
1948 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001949 request.result = -1;
1950 notifyRequester(request);
1951 break;
1952 }
1953 Pair<Integer, List<String>> setFplmnsArgs =
1954 (Pair<Integer, List<String>>) request.argument;
1955 appType = setFplmnsArgs.first;
1956 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001957 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001958 if (uiccApp == null) {
1959 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1960 request.result = -1;
1961 loge("Failed to get UICC App");
1962 notifyRequester(request);
1963 } else {
1964 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1965 ((SIMRecords) uiccApp.getIccRecords())
1966 .setForbiddenPlmns(onCompleted, fplmns);
1967 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001968 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001969 case CMD_ERASE_MODEM_CONFIG:
1970 request = (MainThreadRequest) msg.obj;
1971 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1972 defaultPhone.eraseModemConfig(onCompleted);
1973 break;
1974 case EVENT_ERASE_MODEM_CONFIG_DONE:
1975 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001976 break;
zoey chene02881a2019-12-30 16:11:23 +08001977
Kai Shif70f46f2021-03-03 13:59:46 -08001978 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1979 request = (MainThreadRequest) msg.obj;
1980 request.result = defaultPhone.eraseDataInSharedPreferences();
1981 notifyRequester(request);
1982 break;
1983
zoey chene02881a2019-12-30 16:11:23 +08001984 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1985 request = (MainThreadRequest) msg.obj;
1986 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1987 Pair<String, String> changed = (Pair<String, String>) request.argument;
1988 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1989 changed.first, changed.second, onCompleted);
1990 break;
1991 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1992 ar = (AsyncResult) msg.obj;
1993 request = (MainThreadRequest) ar.userObj;
1994 if (ar.exception == null) {
1995 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001996 // If the operation is successful, update the PIN storage
1997 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1998 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001999 UiccController.getInstance().getPinStorage()
2000 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08002001 } else {
2002 request.result = msg.arg1;
2003 }
2004 notifyRequester(request);
2005 break;
2006
Michele Berionne5e411512020-11-13 02:36:59 +00002007 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08002008 request = (MainThreadRequest) msg.obj;
2009 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
2010 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2011 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2012 enabled.first, enabled.second, onCompleted);
2013 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002014 }
zoey chene02881a2019-12-30 16:11:23 +08002015 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2016 ar = (AsyncResult) msg.obj;
2017 request = (MainThreadRequest) ar.userObj;
2018 if (ar.exception == null) {
2019 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002020 // If the operation is successful, update the PIN storage
2021 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2022 int phoneId = getPhoneFromRequest(request).getPhoneId();
2023 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002024 UiccController.getInstance().getPinStorage()
2025 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002026 } else {
2027 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2028 }
zoey chene02881a2019-12-30 16:11:23 +08002029 } else {
2030 request.result = msg.arg1;
2031 }
Michele Berionne5e411512020-11-13 02:36:59 +00002032
2033
zoey chene02881a2019-12-30 16:11:23 +08002034 notifyRequester(request);
2035 break;
2036
Peter Wangdafb9ac2020-01-15 14:13:38 -08002037 case MSG_NOTIFY_USER_ACTIVITY:
2038 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002039 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002040 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2041 getDefaultPhone().getContext().sendBroadcastAsUser(
2042 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2043 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002044
2045 case CMD_SET_DATA_THROTTLING: {
2046 request = (MainThreadRequest) msg.obj;
2047 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2048 DataThrottlingRequest dataThrottlingRequest =
2049 (DataThrottlingRequest) request.argument;
2050 Phone phone = getPhoneFromRequest(request);
2051 if (phone != null) {
2052 phone.setDataThrottling(onCompleted,
2053 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2054 dataThrottlingRequest.getCompletionDurationMillis());
2055 } else {
2056 loge("setDataThrottling: No phone object");
2057 request.result =
2058 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2059 notifyRequester(request);
2060 }
2061
2062 break;
2063 }
2064 case EVENT_SET_DATA_THROTTLING_DONE:
2065 ar = (AsyncResult) msg.obj;
2066 request = (MainThreadRequest) ar.userObj;
2067
2068 if (ar.exception == null) {
2069 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2070 } else if (ar.exception instanceof CommandException) {
2071 loge("setDataThrottling: CommandException: " + ar.exception);
2072 CommandException.Error error =
2073 ((CommandException) (ar.exception)).getCommandError();
2074
2075 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2076 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002077 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002078 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2079 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002080 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2081 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002082 } else {
2083 request.result =
2084 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2085 }
2086 } else {
2087 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2088 }
2089 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2090 notifyRequester(request);
2091 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002092
2093 case CMD_SET_SIM_POWER: {
2094 request = (MainThreadRequest) msg.obj;
2095 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2096 request = (MainThreadRequest) msg.obj;
2097 int stateToSet =
2098 ((Pair<Integer, IIntegerConsumer>)
2099 request.argument).first;
2100 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2101 break;
2102 }
2103 case EVENT_SET_SIM_POWER_DONE: {
2104 ar = (AsyncResult) msg.obj;
2105 request = (MainThreadRequest) ar.userObj;
2106 IIntegerConsumer callback =
2107 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2108 if (ar.exception != null) {
2109 loge("setSimPower exception: " + ar.exception);
2110 int errorCode = TelephonyManager.CallForwardingInfoCallback
2111 .RESULT_ERROR_UNKNOWN;
2112 if (ar.exception instanceof CommandException) {
2113 CommandException.Error error =
2114 ((CommandException) (ar.exception)).getCommandError();
2115 if (error == CommandException.Error.SIM_ERR) {
2116 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2117 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2118 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2119 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2120 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2121 } else {
2122 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2123 }
2124 }
2125 try {
2126 callback.accept(errorCode);
2127 } catch (RemoteException e) {
2128 // Ignore if the remote process is no longer available to call back.
2129 Log.w(LOG_TAG, "setSimPower: callback not available.");
2130 }
2131 } else {
2132 try {
2133 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2134 } catch (RemoteException e) {
2135 // Ignore if the remote process is no longer available to call back.
2136 Log.w(LOG_TAG, "setSimPower: callback not available.");
2137 }
2138 }
2139 break;
2140 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002141 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2142 request = (MainThreadRequest) msg.obj;
2143
2144 final Phone phone = getPhoneFromRequest(request);
2145 if (phone == null || phone.getServiceStateTracker() == null) {
2146 request.result = new IllegalStateException("Phone or SST is null");
2147 notifyRequester(request);
2148 break;
2149 }
2150
2151 Pair<Integer, SignalStrengthUpdateRequest> pair =
2152 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2153 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2154 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002155 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002156 request.subId, pair.first /*callingUid*/,
2157 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002158 break;
2159 }
2160 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2161 ar = (AsyncResult) msg.obj;
2162 request = (MainThreadRequest) ar.userObj;
2163 // request.result will be the exception of ar if present, true otherwise.
2164 // Be cautious not to leave result null which will wait() forever
2165 request.result = ar.exception != null ? ar.exception : true;
2166 notifyRequester(request);
2167 break;
2168 }
2169 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2170 request = (MainThreadRequest) msg.obj;
2171
2172 Phone phone = getPhoneFromRequest(request);
2173 if (phone == null || phone.getServiceStateTracker() == null) {
2174 request.result = new IllegalStateException("Phone or SST is null");
2175 notifyRequester(request);
2176 break;
2177 }
2178
2179 Pair<Integer, SignalStrengthUpdateRequest> pair =
2180 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2181 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2182 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002183 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002184 request.subId, pair.first /*callingUid*/,
2185 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002186 break;
2187 }
2188 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2189 ar = (AsyncResult) msg.obj;
2190 request = (MainThreadRequest) ar.userObj;
2191 request.result = ar.exception != null ? ar.exception : true;
2192 notifyRequester(request);
2193 break;
2194 }
Jordan Liu109698e2020-11-24 14:50:34 -08002195
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002196 case CMD_GET_SLICING_CONFIG: {
2197 request = (MainThreadRequest) msg.obj;
2198 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2199 request.phone.getSlicingConfig(onCompleted);
2200 break;
2201 }
2202 case EVENT_GET_SLICING_CONFIG_DONE: {
2203 ar = (AsyncResult) msg.obj;
2204 request = (MainThreadRequest) ar.userObj;
2205 ResultReceiver result = (ResultReceiver) request.argument;
2206
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002207 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002208 Bundle bundle = new Bundle();
2209 int resultCode = 0;
2210 if (ar.exception != null) {
2211 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2212 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002213 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002214 } else if (ar.result == null) {
2215 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002216 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002217 } else {
2218 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002219 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2220 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002221 }
2222
2223 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002224 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002225 }
2226 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2227 result.send(resultCode, bundle);
2228 notifyRequester(request);
2229 break;
2230 }
2231
Sarah Chin71b3a852022-09-28 15:54:19 -07002232 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002233 request = (MainThreadRequest) msg.obj;
2234 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002235 PurchasePremiumCapabilityArgument arg =
2236 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chincc5446f2023-10-23 17:57:19 -07002237 SlicePurchaseController.getInstance(request.phone, mFeatureFlags)
2238 .purchasePremiumCapability(arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002239 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002240 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002241
Sarah Chin71b3a852022-09-28 15:54:19 -07002242 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002243 ar = (AsyncResult) msg.obj;
2244 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002245 PurchasePremiumCapabilityArgument arg =
2246 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002247 try {
2248 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002249 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002250 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002251 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chinff8b1802023-04-11 14:22:14 -07002252 + ", result="
Sarah Chin2ec39f62022-08-31 17:03:26 -07002253 + TelephonyManager.convertPurchaseResultToString(result));
2254 } catch (RemoteException e) {
2255 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002256 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002257 + " failed: " + e;
2258 if (DBG) log(logStr);
2259 AnomalyReporter.reportAnomaly(
2260 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2261 }
2262 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002263 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002264
Michele Berionne5e411512020-11-13 02:36:59 +00002265 case CMD_PREPARE_UNATTENDED_REBOOT:
2266 request = (MainThreadRequest) msg.obj;
2267 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002268 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002269 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002270 notifyRequester(request);
2271 break;
2272
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002273 default:
2274 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2275 break;
2276 }
2277 }
Jake Hambye994d462014-02-03 13:10:13 -08002278
Pengquan Menga1bb6272018-09-06 09:59:22 -07002279 private void notifyRequester(MainThreadRequest request) {
2280 synchronized (request) {
2281 request.notifyAll();
2282 }
2283 }
2284
Jake Hambye994d462014-02-03 13:10:13 -08002285 private void handleNullReturnEvent(Message msg, String command) {
2286 AsyncResult ar = (AsyncResult) msg.obj;
2287 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2288 if (ar.exception == null) {
2289 request.result = true;
2290 } else {
2291 request.result = false;
2292 if (ar.exception instanceof CommandException) {
2293 loge(command + ": CommandException: " + ar.exception);
2294 } else {
2295 loge(command + ": Unknown exception");
2296 }
2297 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002298 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002299 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002300 }
2301
2302 /**
2303 * Posts the specified command to be executed on the main thread,
2304 * waits for the request to complete, and returns the result.
2305 * @see #sendRequestAsync
2306 */
2307 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002308 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2309 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002310 }
2311
2312 /**
2313 * Posts the specified command to be executed on the main thread,
2314 * waits for the request to complete, and returns the result.
2315 * @see #sendRequestAsync
2316 */
2317 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2318 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002319 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002320 }
2321
2322 /**
2323 * Posts the specified command to be executed on the main thread,
2324 * waits for the request to complete, and returns the result.
2325 * @see #sendRequestAsync
2326 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002327 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002328 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2329 }
2330
2331 /**
2332 * Posts the specified command to be executed on the main thread,
2333 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2334 * if not timeout or null otherwise.
2335 * @see #sendRequestAsync
2336 */
2337 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2338 long timeoutInMs) {
2339 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002340 }
2341
2342 /**
2343 * Posts the specified command to be executed on the main thread,
2344 * waits for the request to complete, and returns the result.
2345 * @see #sendRequestAsync
2346 */
Nathan Harold92bed182018-10-12 18:16:49 -07002347 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002348 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002349 }
2350
2351 /**
2352 * Posts the specified command to be executed on the main thread,
2353 * waits for the request to complete, and returns the result.
2354 * @see #sendRequestAsync
2355 */
2356 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002357 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2358 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002359 }
2360
2361 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002362 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2363 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2364 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002365 * @see #sendRequestAsync
2366 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002367 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2368 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002369 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2370 throw new RuntimeException("This method will deadlock if called from the main thread.");
2371 }
2372
Nathan Harold92bed182018-10-12 18:16:49 -07002373 MainThreadRequest request = null;
2374 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2375 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2376 } else if (phone != null) {
2377 request = new MainThreadRequest(argument, phone, workSource);
2378 } else {
2379 request = new MainThreadRequest(argument, subId, workSource);
2380 }
2381
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002382 Message msg = mMainThreadHandler.obtainMessage(command, request);
2383 msg.sendToTarget();
2384
Rambo Wang0f050d82021-02-12 11:43:36 -08002385
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002386 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002387 if (timeoutInMs >= 0) {
2388 // Wait for at least timeoutInMs before returning null request result
2389 long now = SystemClock.elapsedRealtime();
2390 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002391 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002392 try {
2393 request.wait(deadline - now);
2394 } catch (InterruptedException e) {
2395 // Do nothing, go back and check if request is completed or timeout
2396 } finally {
2397 now = SystemClock.elapsedRealtime();
2398 }
2399 }
2400 } else {
2401 // Wait for the request to complete
2402 while (request.result == null) {
2403 try {
2404 request.wait();
2405 } catch (InterruptedException e) {
2406 // Do nothing, go back and wait until the request is complete
2407 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002408 }
2409 }
2410 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002411 if (request.result == null) {
2412 Log.wtf(LOG_TAG,
2413 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2414 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002415 return request.result;
2416 }
2417
2418 /**
2419 * Asynchronous ("fire and forget") version of sendRequest():
2420 * Posts the specified command to be executed on the main thread, and
2421 * returns immediately.
2422 * @see #sendRequest
2423 */
2424 private void sendRequestAsync(int command) {
2425 mMainThreadHandler.sendEmptyMessage(command);
2426 }
2427
2428 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002429 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002430 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002431 */
2432 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002433 sendRequestAsync(command, argument, null, null);
2434 }
2435
2436 /**
2437 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2438 * @see {@link #sendRequest(int,Object)}
2439 */
2440 private void sendRequestAsync(
2441 int command, Object argument, Phone phone, WorkSource workSource) {
2442 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002443 Message msg = mMainThreadHandler.obtainMessage(command, request);
2444 msg.sendToTarget();
2445 }
2446
2447 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002448 * Initialize the singleton PhoneInterfaceManager instance.
2449 * This is only done once, at startup, from PhoneApp.onCreate().
2450 */
Sarah Chincc5446f2023-10-23 17:57:19 -07002451 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002452 synchronized (PhoneInterfaceManager.class) {
2453 if (sInstance == null) {
Sarah Chincc5446f2023-10-23 17:57:19 -07002454 sInstance = new PhoneInterfaceManager(app, featureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002455 } else {
2456 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2457 }
2458 return sInstance;
2459 }
2460 }
2461
2462 /** Private constructor; @see init() */
Sarah Chincc5446f2023-10-23 17:57:19 -07002463 private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002464 mApp = app;
Sarah Chincc5446f2023-10-23 17:57:19 -07002465 mFeatureFlags = featureFlags;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002466 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002467 mImsResolver = ImsResolver.getInstance();
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +00002468 mSatelliteController = SatelliteController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002469 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002470 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2471 mMainThreadHandler = new MainThreadHandler();
Sarah Chin4beb2b72023-02-14 14:47:54 -08002472 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002473 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002474 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002475 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002476 mNotifyUserActivity = new AtomicBoolean(false);
joonhunshin4ac60942023-11-15 15:23:39 +00002477 mPackageManager = app.getPackageManager();
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -08002478 mSatelliteAccessController = SatelliteAccessController.getOrCreateInstance(
2479 getDefaultPhone().getContext(), featureFlags);
Tyler Gunn64144d92022-03-17 14:16:41 -07002480 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002481 publish();
arunvoddud7401012022-12-15 16:08:12 +00002482 CarrierAllowListInfo.loadInstance(mApp);
Hyosun Kim240214a2023-11-02 13:30:15 +00002483
2484 // Create the SatelliteEntitlementController singleton, for using the get the
2485 // entitlementStatus for satellite service.
2486 SatelliteEntitlementController.make(mApp, mFeatureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002487 }
2488
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002489 @VisibleForTesting
2490 public SharedPreferences getSharedPreferences() {
2491 return mTelephonySharedPreferences;
2492 }
2493
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002494 /**
2495 * Get the default phone for this device.
2496 */
2497 @VisibleForTesting
2498 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002499 Phone thePhone = getPhone(getDefaultSubscription());
2500 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2501 }
2502
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002503 private void publish() {
2504 if (DBG) log("publish: " + this);
2505
Peter Wangc035ce42020-01-08 21:00:22 -08002506 TelephonyFrameworkInitializer
2507 .getTelephonyServiceManager()
2508 .getTelephonyServiceRegisterer()
2509 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002510 }
2511
Stuart Scott584921c2015-01-15 17:10:34 -08002512 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002513 if (request.phone != null) {
2514 return request.phone;
2515 } else {
2516 return getPhoneFromSubId(request.subId);
2517 }
2518 }
2519
2520 private Phone getPhoneFromSubId(int subId) {
2521 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2522 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002523 }
2524
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002525 /**
2526 * Get phone object associated with a subscription.
2527 * Return default phone if phone object associated with subscription is null
2528 * @param subId - subscriptionId
2529 * @return phone object associated with a subscription or default phone if null.
2530 */
Ling Mac28f0212023-03-24 16:07:15 -07002531 private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) {
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002532 Phone phone = getPhoneFromSubId(subId);
2533 if (phone == null) {
Ling Mac28f0212023-03-24 16:07:15 -07002534 loge("Called with invalid subId: " + subId + ". Retrying with default phone.");
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002535 phone = getDefaultPhone();
2536 }
2537 return phone;
2538 }
2539
Rambo Wange53e07d2022-05-10 13:01:13 -07002540 @Nullable
2541 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002542 Phone phone = getPhoneFromRequest(request);
2543 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002544 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002545 }
2546
Ling Mac28f0212023-03-24 16:07:15 -07002547 /**
2548 * @param subId The sub Id that associates the phone. If the device has no active SIM, passing
2549 * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <=
2550 * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}.
2551 * @return The Phone associated the sub Id
2552 */
2553 private @Nullable Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002554 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002555 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002556
Kai Shif70f46f2021-03-03 13:59:46 -08002557 private void sendEraseModemConfig(@NonNull Phone phone) {
2558 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2559 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2560 }
2561
2562 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2563 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2564 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002565 }
2566
Peter Wang44b186e2020-01-13 23:33:09 -08002567 private boolean isImsAvailableOnDevice() {
2568 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2569 if (pm == null) {
2570 // For some reason package manger is not available.. This will fail internally anyway,
2571 // so do not throw error and allow.
2572 return true;
2573 }
2574 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2575 }
2576
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002577 public void dial(String number) {
joonhunshin4ac60942023-11-15 15:23:39 +00002578 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2579 PackageManager.FEATURE_TELEPHONY_CALLING, "dial");
2580
Wink Savilleadd7cc52014-09-08 14:23:09 -07002581 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002582 }
2583
Wink Savilleb564aae2014-10-23 10:18:09 -07002584 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002585 if (DBG) log("dial: " + number);
2586 // No permission check needed here: This is just a wrapper around the
2587 // ACTION_DIAL intent, which is available to any app since it puts up
2588 // the UI before it does anything.
2589
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002590 final long identity = Binder.clearCallingIdentity();
2591 try {
2592 String url = createTelUrl(number);
2593 if (url == null) {
2594 return;
2595 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002596
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002597 // PENDING: should we just silently fail if phone is offhook or ringing?
2598 PhoneConstants.State state = mCM.getState(subId);
2599 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2600 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2601 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2602 mApp.startActivity(intent);
2603 }
2604 } finally {
2605 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002606 }
2607 }
2608
2609 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002610 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002611 }
2612
Wink Savilleb564aae2014-10-23 10:18:09 -07002613 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002614 if (DBG) log("call: " + number);
2615
2616 // This is just a wrapper around the ACTION_CALL intent, but we still
2617 // need to do a permission check since we're calling startActivity()
2618 // from the context of the phone app.
2619 enforceCallPermission();
2620
Jordan Liu1617b712019-07-10 15:06:26 -07002621 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002622 != AppOpsManager.MODE_ALLOWED) {
2623 return;
2624 }
2625
joonhunshin4ac60942023-11-15 15:23:39 +00002626 enforceTelephonyFeatureWithException(callingPackage,
2627 PackageManager.FEATURE_TELEPHONY_CALLING, "call");
2628
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002629 final long identity = Binder.clearCallingIdentity();
2630 try {
2631 String url = createTelUrl(number);
2632 if (url == null) {
2633 return;
2634 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002635
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002636 boolean isValid = false;
2637 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2638 if (slist != null) {
2639 for (SubscriptionInfo subInfoRecord : slist) {
2640 if (subInfoRecord.getSubscriptionId() == subId) {
2641 isValid = true;
2642 break;
2643 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002644 }
Wink Saville08874612014-08-31 19:19:58 -07002645 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002646 if (!isValid) {
2647 return;
2648 }
Wink Saville08874612014-08-31 19:19:58 -07002649
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002650 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2651 intent.putExtra(SUBSCRIPTION_KEY, subId);
2652 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2653 mApp.startActivity(intent);
2654 } finally {
2655 Binder.restoreCallingIdentity(identity);
2656 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002657 }
2658
Wink Savilleb564aae2014-10-23 10:18:09 -07002659 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002660 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002661 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2662 }
2663
Wink Savilleb564aae2014-10-23 10:18:09 -07002664 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002665 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, 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 int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002670 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002671
joonhunshin4ac60942023-11-15 15:23:39 +00002672 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2673 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
2674 "supplyPinReportResultForSubscriber");
2675
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002676 final long identity = Binder.clearCallingIdentity();
2677 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002678 Phone phone = getPhone(subId);
2679 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002680 checkSimPin.start();
2681 return checkSimPin.unlockSim(null, pin);
2682 } finally {
2683 Binder.restoreCallingIdentity(identity);
2684 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002685 }
2686
Wink Savilleb564aae2014-10-23 10:18:09 -07002687 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002688 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002689
joonhunshin4ac60942023-11-15 15:23:39 +00002690 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2691 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "supplyPukForSubscriber");
2692
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002693 final long identity = Binder.clearCallingIdentity();
2694 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002695 Phone phone = getPhone(subId);
2696 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002697 checkSimPuk.start();
2698 return checkSimPuk.unlockSim(puk, pin);
2699 } finally {
2700 Binder.restoreCallingIdentity(identity);
2701 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002702 }
2703
2704 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002705 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002706 * a synchronous one.
2707 */
2708 private static class UnlockSim extends Thread {
2709
2710 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002711 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002712
2713 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002714 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2715 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002716
2717 // For replies from SimCard interface
2718 private Handler mHandler;
2719
2720 // For async handler to identify request type
2721 private static final int SUPPLY_PIN_COMPLETE = 100;
2722
Michele Berionne5e411512020-11-13 02:36:59 +00002723 UnlockSim(int phoneId, IccCard simCard) {
2724 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002725 mSimCard = simCard;
2726 }
2727
2728 @Override
2729 public void run() {
2730 Looper.prepare();
2731 synchronized (UnlockSim.this) {
2732 mHandler = new Handler() {
2733 @Override
2734 public void handleMessage(Message msg) {
2735 AsyncResult ar = (AsyncResult) msg.obj;
2736 switch (msg.what) {
2737 case SUPPLY_PIN_COMPLETE:
2738 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2739 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002740 mRetryCount = msg.arg1;
2741 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002742 CommandException.Error error = null;
2743 if (ar.exception instanceof CommandException) {
2744 error = ((CommandException) (ar.exception))
2745 .getCommandError();
2746 }
2747 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07002748 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002749 } else if (error == CommandException.Error.ABORTED) {
2750 /* When UiccCardApp dispose, handle message and return
2751 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08002752 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002753 } else {
2754 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2755 }
2756 } else {
2757 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2758 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002759 mDone = true;
2760 UnlockSim.this.notifyAll();
2761 }
2762 break;
2763 }
2764 }
2765 };
2766 UnlockSim.this.notifyAll();
2767 }
2768 Looper.loop();
2769 }
2770
2771 /*
2772 * Use PIN or PUK to unlock SIM card
2773 *
2774 * If PUK is null, unlock SIM card with PIN
2775 *
2776 * If PUK is not null, unlock SIM card with PUK and set PIN code
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302777 *
2778 * Besides, since it is reused in class level, the thread's looper will be stopped to avoid
2779 * its thread leak.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002780 */
Wink Saville9de0f752013-10-22 19:04:03 -07002781 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002782
2783 while (mHandler == null) {
2784 try {
2785 wait();
2786 } catch (InterruptedException e) {
2787 Thread.currentThread().interrupt();
2788 }
2789 }
2790 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2791
2792 if (puk == null) {
2793 mSimCard.supplyPin(pin, callback);
2794 } else {
2795 mSimCard.supplyPuk(puk, pin, callback);
2796 }
2797
2798 while (!mDone) {
2799 try {
2800 Log.d(LOG_TAG, "wait for done");
2801 wait();
2802 } catch (InterruptedException e) {
2803 // Restore the interrupted status
2804 Thread.currentThread().interrupt();
2805 }
2806 }
2807 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002808 int[] resultArray = new int[2];
2809 resultArray[0] = mResult;
2810 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002811
2812 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002813 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002814 }
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302815 // This instance is no longer reused, so quit its thread's looper.
2816 mHandler.getLooper().quitSafely();
Michele Berionne5e411512020-11-13 02:36:59 +00002817
Wink Saville9de0f752013-10-22 19:04:03 -07002818 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002819 }
2820 }
2821
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002822 /**
2823 * This method has been removed due to privacy and stability concerns.
2824 */
2825 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002826 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002827 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2828 return;
Wink Saville36469e72014-06-11 15:17:00 -07002829 }
2830
Nathan Harold1f889d82020-06-04 17:05:26 -07002831 @Override
2832 public void updateServiceLocationWithPackageName(String callingPackage) {
2833 mApp.getSystemService(AppOpsManager.class)
2834 .checkPackage(Binder.getCallingUid(), callingPackage);
2835
Nathan Haroldf096d982020-11-18 17:18:06 -08002836 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002837 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2838 // Callers targeting S have no business invoking this method.
2839 return;
2840 }
2841
2842 LocationAccessPolicy.LocationPermissionResult locationResult =
2843 LocationAccessPolicy.checkLocationPermission(mApp,
2844 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2845 .setCallingPackage(callingPackage)
2846 .setCallingFeatureId(null)
2847 .setCallingPid(Binder.getCallingPid())
2848 .setCallingUid(Binder.getCallingUid())
2849 .setMethod("updateServiceLocation")
2850 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2851 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2852 .build());
2853 // Apps that lack location permission have no business calling this method;
2854 // however, because no permission was declared in the public API, denials must
2855 // all be "soft".
2856 switch (locationResult) {
2857 case DENIED_HARD: /* fall through */
2858 case DENIED_SOFT:
2859 return;
2860 }
2861
2862 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002863 final long identity = Binder.clearCallingIdentity();
2864 try {
Ling Mac28f0212023-03-24 16:07:15 -07002865 getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002866 } finally {
2867 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002868 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002869 }
2870
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002871 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002872 @Override
2873 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002874 return isRadioOnWithFeature(callingPackage, null);
2875 }
2876
2877
2878 @Override
2879 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2880 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2881 callingFeatureId);
2882 }
2883
2884 @Deprecated
2885 @Override
2886 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2887 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002888 }
2889
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002890 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002891 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2892 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002893 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002894 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002895 return false;
2896 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002897
joonhunshin4ac60942023-11-15 15:23:39 +00002898 enforceTelephonyFeatureWithException(callingPackage,
2899 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isRadioOnWithFeature");
2900
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002901 final long identity = Binder.clearCallingIdentity();
2902 try {
2903 return isRadioOnForSubscriber(subId);
2904 } finally {
2905 Binder.restoreCallingIdentity(identity);
2906 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002907 }
2908
2909 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002910 final long identity = Binder.clearCallingIdentity();
2911 try {
2912 final Phone phone = getPhone(subId);
2913 if (phone != null) {
2914 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2915 } else {
2916 return false;
2917 }
2918 } finally {
2919 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002920 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002921 }
2922
2923 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002924 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002925 }
Wink Saville36469e72014-06-11 15:17:00 -07002926
Wink Savilleb564aae2014-10-23 10:18:09 -07002927 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002928 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002929
joonhunshin4ac60942023-11-15 15:23:39 +00002930 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2931 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "toggleRadioOnOffForSubscriber");
2932
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002933 final long identity = Binder.clearCallingIdentity();
2934 try {
2935 final Phone phone = getPhone(subId);
2936 if (phone != null) {
2937 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2938 }
2939 } finally {
2940 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002941 }
Wink Saville36469e72014-06-11 15:17:00 -07002942 }
2943
2944 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002945 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002946 }
2947
Wink Savilleb564aae2014-10-23 10:18:09 -07002948 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002949 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002950
2951 final long identity = Binder.clearCallingIdentity();
2952 try {
2953 final Phone phone = getPhone(subId);
2954 if (phone == null) {
2955 return false;
2956 }
2957 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2958 toggleRadioOnOffForSubscriber(subId);
2959 }
2960 return true;
2961 } finally {
2962 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002963 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002964 }
Wink Saville36469e72014-06-11 15:17:00 -07002965
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002966 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002967 enforceReadPrivilegedPermission("needMobileRadioShutdown");
joonhunshin4ac60942023-11-15 15:23:39 +00002968
2969 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2970 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needMobileRadioShutdown");
2971
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002972 /*
2973 * If any of the Radios are available, it will need to be
2974 * shutdown. So return true if any Radio is available.
2975 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002976 final long identity = Binder.clearCallingIdentity();
2977 try {
2978 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2979 Phone phone = PhoneFactory.getPhone(i);
2980 if (phone != null && phone.isRadioAvailable()) return true;
2981 }
2982 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2983 return false;
2984 } finally {
2985 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002986 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002987 }
2988
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002989 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002990 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002991 enforceModifyPermission();
2992
joonhunshin4ac60942023-11-15 15:23:39 +00002993 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2994 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "shutdownMobileRadios");
2995
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002996 final long identity = Binder.clearCallingIdentity();
2997 try {
2998 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2999 logv("Shutting down Phone " + i);
3000 shutdownRadioUsingPhoneId(i);
3001 }
3002 } finally {
3003 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003004 }
3005 }
3006
3007 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003008 Phone phone = PhoneFactory.getPhone(phoneId);
3009 if (phone != null && phone.isRadioAvailable()) {
3010 phone.shutdownRadio();
3011 }
3012 }
3013
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003014 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07003015 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003016
Ling Ma83dc5ea2023-01-12 15:06:04 -08003017 if (!turnOn) {
3018 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
3019 }
3020
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003021 final long identity = Binder.clearCallingIdentity();
3022 try {
3023 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
3024 if (defaultPhone != null) {
3025 defaultPhone.setRadioPower(turnOn);
3026 return true;
3027 } else {
3028 loge("There's no default phone.");
3029 return false;
3030 }
3031 } finally {
3032 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07003033 }
Wink Saville36469e72014-06-11 15:17:00 -07003034 }
3035
Wink Savilleb564aae2014-10-23 10:18:09 -07003036 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003037 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003038
Ling Ma83dc5ea2023-01-12 15:06:04 -08003039 if (!turnOn) {
3040 log("setRadioPowerForSubscriber off: subId=" + subId
3041 + ",callingPackage=" + getCurrentPackageName());
3042 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003043 final long identity = Binder.clearCallingIdentity();
3044 try {
3045 final Phone phone = getPhone(subId);
3046 if (phone != null) {
3047 phone.setRadioPower(turnOn);
3048 return true;
3049 } else {
3050 return false;
3051 }
3052 } finally {
3053 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003054 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003055 }
3056
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003057 /**
3058 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3059 * no reason to power it off. When any of the voters want to power it off, it will be turned
3060 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3061 * powering it off, and these radio off votes will be cleared.
3062 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3063 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3064 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3065 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3066 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3067 * check its vote.
3068 *
3069 * @param subId The subscription ID.
3070 * @param reason The reason for powering off radio.
3071 * @return true on success and false on failure.
3072 */
3073 public boolean requestRadioPowerOffForReason(int subId,
3074 @TelephonyManager.RadioPowerReason int reason) {
3075 enforceModifyPermission();
3076
joonhunshin4ac60942023-11-15 15:23:39 +00003077 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3078 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestRadioPowerOffForReason");
3079
Ling Ma83dc5ea2023-01-12 15:06:04 -08003080 log("requestRadioPowerOffForReason: subId=" + subId
3081 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003082 final long identity = Binder.clearCallingIdentity();
3083 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003084 boolean result = false;
3085 for (Phone phone : PhoneFactory.getPhones()) {
3086 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003087 phone.setRadioPowerForReason(false, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003088 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003089 if (!result) {
3090 loge("requestRadioPowerOffForReason: no phone exists");
3091 }
3092 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003093 } finally {
3094 Binder.restoreCallingIdentity(identity);
3095 }
3096 }
3097
3098 /**
3099 * Remove the vote on powering off the radio for a reason, as requested by
3100 * {@link requestRadioPowerOffForReason}.
3101 *
3102 * @param subId The subscription ID.
3103 * @param reason The reason for powering off radio.
3104 * @return true on success and false on failure.
3105 */
3106 public boolean clearRadioPowerOffForReason(int subId,
3107 @TelephonyManager.RadioPowerReason int reason) {
3108 enforceModifyPermission();
3109
joonhunshin4ac60942023-11-15 15:23:39 +00003110 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3111 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearRadioPowerOffForReason");
3112
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003113 final long identity = Binder.clearCallingIdentity();
3114 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003115 boolean result = false;
3116 for (Phone phone : PhoneFactory.getPhones()) {
3117 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003118 phone.setRadioPowerForReason(true, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003119 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003120 if (!result) {
3121 loge("clearRadioPowerOffForReason: no phone exists");
3122 }
3123 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003124 } finally {
3125 Binder.restoreCallingIdentity(identity);
3126 }
3127 }
3128
3129 /**
3130 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3131 *
3132 * @param subId The subscription ID.
3133 * @param callingPackage The package making the call.
3134 * @param callingFeatureId The feature in the package.
3135 * @return List of reasons for powering off radio.
3136 */
3137 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3138 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3139
joonhunshin4ac60942023-11-15 15:23:39 +00003140 enforceTelephonyFeatureWithException(callingPackage,
3141 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerOffReasons");
3142
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003143 final long identity = Binder.clearCallingIdentity();
3144 List result = new ArrayList();
3145 try {
3146 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3147 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3148 return result;
3149 }
3150
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003151 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003152 if (phone != null) {
3153 result.addAll(phone.getRadioPowerOffReasons());
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003154 } else {
3155 loge("getRadioPowerOffReasons: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003156 }
3157 } finally {
3158 Binder.restoreCallingIdentity(identity);
3159 }
3160 return result;
3161 }
3162
Wink Saville36469e72014-06-11 15:17:00 -07003163 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003164 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003165 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003166 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003167
joonhunshin4ac60942023-11-15 15:23:39 +00003168 enforceTelephonyFeatureWithException(callingPackage,
3169 PackageManager.FEATURE_TELEPHONY_DATA, "enableDataConnectivity");
3170
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003171 final long identity = Binder.clearCallingIdentity();
3172 try {
Jack Yu285100e2022-12-02 22:48:35 -08003173 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003174 final Phone phone = getPhone(subId);
3175 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003176 phone.getDataSettingsManager().setDataEnabled(
3177 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003178 return true;
3179 } else {
3180 return false;
3181 }
3182 } finally {
3183 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003184 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003185 }
3186
Wink Saville36469e72014-06-11 15:17:00 -07003187 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003188 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003189 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003190 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003191
joonhunshin4ac60942023-11-15 15:23:39 +00003192 enforceTelephonyFeatureWithException(callingPackage,
3193 PackageManager.FEATURE_TELEPHONY_DATA, "disableDataConnectivity");
3194
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003195 final long identity = Binder.clearCallingIdentity();
3196 try {
Jack Yu285100e2022-12-02 22:48:35 -08003197 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003198 final Phone phone = getPhone(subId);
3199 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003200 phone.getDataSettingsManager().setDataEnabled(
3201 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003202 return true;
3203 } else {
3204 return false;
3205 }
3206 } finally {
3207 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003208 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003209 }
3210
Sanket Padawe356d7632015-06-22 14:03:32 -07003211 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003212 public boolean isDataConnectivityPossible(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003213 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3214 PackageManager.FEATURE_TELEPHONY_DATA, "isDataConnectivityPossible");
3215
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003216 final long identity = Binder.clearCallingIdentity();
3217 try {
3218 final Phone phone = getPhone(subId);
3219 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003220 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003221 } else {
3222 return false;
3223 }
3224 } finally {
3225 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003226 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003227 }
3228
3229 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003230 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003231 }
3232
pkanwarae03a6b2016-11-06 20:37:09 -08003233 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003234 enforceCallPermission();
3235
joonhunshin4ac60942023-11-15 15:23:39 +00003236 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3237 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "handleUssdRequest");
3238
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003239 final long identity = Binder.clearCallingIdentity();
3240 try {
3241 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3242 return;
3243 }
3244 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3245 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3246 } finally {
3247 Binder.restoreCallingIdentity(identity);
3248 }
pkanwar32d516d2016-10-14 19:37:38 -07003249 };
3250
Wink Savilleb564aae2014-10-23 10:18:09 -07003251 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003252 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003253
joonhunshin4ac60942023-11-15 15:23:39 +00003254 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3255 PackageManager.FEATURE_TELEPHONY_CALLING, "handlePinMmiForSubscriber");
3256
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003257 final long identity = Binder.clearCallingIdentity();
3258 try {
3259 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3260 return false;
3261 }
3262 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3263 } finally {
3264 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003265 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003266 }
3267
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003268 /**
3269 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3270 * tag on getCallState Binder call.
3271 */
3272 @Deprecated
3273 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003274 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003275 if (CompatChanges.isChangeEnabled(
3276 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3277 Binder.getCallingUid())) {
3278 // Do not allow this API to be called on API version 31+, it should only be
3279 // called on old apps using this Binder call directly.
3280 throw new SecurityException("This method can only be used for applications "
3281 + "targeting API version 30 or less.");
3282 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003283 final long identity = Binder.clearCallingIdentity();
3284 try {
Ling Mac28f0212023-03-24 16:07:15 -07003285 Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription());
3286 return PhoneConstantConversions.convertCallState(phone.getState());
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003287 } finally {
3288 Binder.restoreCallingIdentity(identity);
3289 }
3290 }
3291
3292 @Override
3293 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3294 if (CompatChanges.isChangeEnabled(
3295 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3296 Binder.getCallingUid())) {
3297 // Check READ_PHONE_STATE for API version 31+
3298 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3299 featureId, "getCallStateForSubscription")) {
3300 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3301 + "targeting API level 31+.");
3302 }
3303 }
joonhunshin4ac60942023-11-15 15:23:39 +00003304
3305 enforceTelephonyFeatureWithException(callingPackage,
3306 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallStateForSubscription");
3307
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003308 final long identity = Binder.clearCallingIdentity();
3309 try {
3310 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003311 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3312 PhoneConstantConversions.convertCallState(phone.getState());
3313 } finally {
3314 Binder.restoreCallingIdentity(identity);
3315 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003316 }
3317
Sanket Padawe356d7632015-06-22 14:03:32 -07003318 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003319 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003320 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003321 }
3322
3323 @Override
3324 public int getDataStateForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003325 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3326 PackageManager.FEATURE_TELEPHONY_DATA, "getDataStateForSubId");
3327
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003328 final long identity = Binder.clearCallingIdentity();
3329 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003330 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003331 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003332 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003333 } else {
3334 return PhoneConstantConversions.convertDataState(
3335 PhoneConstants.DataState.DISCONNECTED);
3336 }
3337 } finally {
3338 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003339 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003340 }
3341
Sanket Padawe356d7632015-06-22 14:03:32 -07003342 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003343 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003344 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003345 }
3346
3347 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003348 public @DataActivityType int getDataActivityForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003349 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3350 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivityForSubId");
3351
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003352 final long identity = Binder.clearCallingIdentity();
3353 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003354 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003355 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003356 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003357 } else {
3358 return TelephonyManager.DATA_ACTIVITY_NONE;
3359 }
3360 } finally {
3361 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003362 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003363 }
3364
3365 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003366 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003367 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003368 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003369
3370 LocationAccessPolicy.LocationPermissionResult locationResult =
3371 LocationAccessPolicy.checkLocationPermission(mApp,
3372 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3373 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003374 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003375 .setCallingPid(Binder.getCallingPid())
3376 .setCallingUid(Binder.getCallingUid())
3377 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003378 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003379 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3380 .build());
3381 switch (locationResult) {
3382 case DENIED_HARD:
3383 throw new SecurityException("Not allowed to access cell location");
3384 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003385 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3386 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003387 }
3388
joonhunshin4ac60942023-11-15 15:23:39 +00003389 enforceTelephonyFeatureWithException(callingPackage,
3390 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getCellLocation");
3391
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003392 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003393 final long identity = Binder.clearCallingIdentity();
3394 try {
3395 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003396 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003397 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003398 } finally {
3399 Binder.restoreCallingIdentity(identity);
3400 }
Svetoslav64fad262015-04-14 14:35:21 -07003401 }
3402
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003403 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003404 public String getNetworkCountryIsoForPhone(int phoneId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003405 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3406 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkCountryIsoForPhone");
3407
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003408 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3409 // registered cell info, so return a NULL country instead.
3410 final long identity = Binder.clearCallingIdentity();
3411 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003412 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3413 // Get default phone in this case.
3414 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3415 }
Jack Yu285100e2022-12-02 22:48:35 -08003416 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003417 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003418 if (phone == null) return "";
3419 ServiceStateTracker sst = phone.getServiceStateTracker();
3420 if (sst == null) return "";
3421 LocaleTracker lt = sst.getLocaleTracker();
3422 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003423 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003424 } finally {
3425 Binder.restoreCallingIdentity(identity);
3426 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003427 }
3428
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003429 /**
3430 * This method was removed due to potential issues caused by performing partial
3431 * updates of service state, and lack of a credible use case.
3432 *
3433 * This has the ability to break the telephony implementation by disabling notification of
3434 * changes in device connectivity. DO NOT USE THIS!
3435 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003436 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003437 public void enableLocationUpdates() {
3438 mApp.enforceCallingOrSelfPermission(
3439 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003440 }
3441
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003442 /**
3443 * This method was removed due to potential issues caused by performing partial
3444 * updates of service state, and lack of a credible use case.
3445 *
3446 * This has the ability to break the telephony implementation by disabling notification of
3447 * changes in device connectivity. DO NOT USE THIS!
3448 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003449 @Override
3450 public void disableLocationUpdates() {
3451 mApp.enforceCallingOrSelfPermission(
3452 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003453 }
3454
3455 @Override
3456 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003457 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3458 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003459 try {
3460 mApp.getSystemService(AppOpsManager.class)
3461 .checkPackage(Binder.getCallingUid(), callingPackage);
3462 } catch (SecurityException e) {
3463 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3464 throw e;
3465 }
3466
Nathan Haroldf096d982020-11-18 17:18:06 -08003467 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003468 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3469 throw new SecurityException(
3470 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3471 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003472
Jordan Liu1617b712019-07-10 15:06:26 -07003473 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003474 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3475 return null;
3476 }
Svetoslav64fad262015-04-14 14:35:21 -07003477
joonhunshin4ac60942023-11-15 15:23:39 +00003478 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3479 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNeighboringCellInfo");
3480
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003481 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003482
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003483 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003484 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003485
Nathan Haroldf180aac2018-06-01 18:43:55 -07003486 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3487 for (CellInfo ci : info) {
3488 if (ci instanceof CellInfoGsm) {
3489 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3490 } else if (ci instanceof CellInfoWcdma) {
3491 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3492 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003493 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003494 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003495 }
3496
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003497 private List<CellInfo> getCachedCellInfo() {
3498 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3499 for (Phone phone : PhoneFactory.getPhones()) {
3500 List<CellInfo> info = phone.getAllCellInfo();
3501 if (info != null) cellInfos.addAll(info);
3502 }
3503 return cellInfos;
3504 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003505
3506 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003507 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003508 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003509 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003510
3511 LocationAccessPolicy.LocationPermissionResult locationResult =
3512 LocationAccessPolicy.checkLocationPermission(mApp,
3513 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3514 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003515 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003516 .setCallingPid(Binder.getCallingPid())
3517 .setCallingUid(Binder.getCallingUid())
3518 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003519 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003520 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3521 .build());
3522 switch (locationResult) {
3523 case DENIED_HARD:
3524 throw new SecurityException("Not allowed to access cell info");
3525 case DENIED_SOFT:
3526 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003527 }
3528
Nathan Haroldf096d982020-11-18 17:18:06 -08003529 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003530 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3531 return getCachedCellInfo();
3532 }
3533
joonhunshin4ac60942023-11-15 15:23:39 +00003534 enforceTelephonyFeatureWithException(callingPackage,
3535 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllCellInfo");
3536
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003537 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003538 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003539 final long identity = Binder.clearCallingIdentity();
3540 try {
3541 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3542 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003543 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003544 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003545 if (info != null) cellInfos.addAll(info);
3546 }
3547 return cellInfos;
3548 } finally {
3549 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003550 }
3551 }
3552
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003553 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003554 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3555 String callingFeatureId) {
3556 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3557 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003558 }
3559
3560 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003561 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3562 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003563 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003564 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003565 }
3566
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003567 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3568 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003569 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003570 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003571
3572 LocationAccessPolicy.LocationPermissionResult locationResult =
3573 LocationAccessPolicy.checkLocationPermission(mApp,
3574 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3575 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003576 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003577 .setCallingPid(Binder.getCallingPid())
3578 .setCallingUid(Binder.getCallingUid())
3579 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003580 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3581 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003582 .build());
3583 switch (locationResult) {
3584 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003585 if (TelephonyPermissions
3586 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003587 // Safetynet logging for b/154934934
3588 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3589 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003590 throw new SecurityException("Not allowed to access cell info");
3591 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003592 if (TelephonyPermissions
3593 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003594 // Safetynet logging for b/154934934
3595 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3596 }
Nathan Harold5320c422019-05-09 10:26:08 -07003597 try {
3598 cb.onCellInfo(new ArrayList<CellInfo>());
3599 } catch (RemoteException re) {
3600 // Drop without consequences
3601 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003602 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003603 }
3604
joonhunshin4ac60942023-11-15 15:23:39 +00003605 enforceTelephonyFeatureWithException(callingPackage,
3606 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestCellInfoUpdateInternal");
Nathan Harolda939a962019-05-09 10:13:47 -07003607
3608 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003609 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3610
3611 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3612 }
3613
3614 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003615 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003616 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003617 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003618
3619 final long identity = Binder.clearCallingIdentity();
3620 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003621 Phone phone = getPhone(subId);
3622 if (phone == null) {
3623 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3624 } else {
3625 phone.setCellInfoListRate(rateInMillis, workSource);
3626 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003627 } finally {
3628 Binder.restoreCallingIdentity(identity);
3629 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003630 }
3631
Shishir Agrawala9f32182016-04-12 12:00:16 -07003632 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003633 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003634 Phone phone = PhoneFactory.getPhone(slotIndex);
3635 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003636 return null;
3637 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003638 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003639 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003640 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003641 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003642 return null;
3643 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003644
joonhunshin4ac60942023-11-15 15:23:39 +00003645 enforceTelephonyFeatureWithException(callingPackage,
3646 PackageManager.FEATURE_TELEPHONY_GSM, "getImeiForSlot");
3647
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003648 final long identity = Binder.clearCallingIdentity();
3649 try {
3650 return phone.getImei();
3651 } finally {
3652 Binder.restoreCallingIdentity(identity);
3653 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003654 }
3655
3656 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003657 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3658 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3659 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3660 callingFeatureId, "getPrimaryImei")) {
3661 throw new SecurityException("Caller does not have permission");
3662 }
joonhunshin4ac60942023-11-15 15:23:39 +00003663
3664 enforceTelephonyFeatureWithException(callingPackage,
3665 PackageManager.FEATURE_TELEPHONY_GSM, "getPrimaryImei");
3666
arunvoddud5c6ce02022-12-11 06:03:12 +00003667 final long identity = Binder.clearCallingIdentity();
3668 try {
3669 for (Phone phone : PhoneFactory.getPhones()) {
3670 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3671 return phone.getImei();
3672 }
3673 }
3674 throw new UnsupportedOperationException("Operation not supported");
3675 } finally {
3676 Binder.restoreCallingIdentity(identity);
3677 }
3678 }
3679
3680 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003681 public String getTypeAllocationCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003682 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3683 PackageManager.FEATURE_TELEPHONY_GSM, "getTypeAllocationCodeForSlot");
3684
David Kelly5e06a7f2018-03-12 14:10:59 +00003685 Phone phone = PhoneFactory.getPhone(slotIndex);
3686 String tac = null;
3687 if (phone != null) {
3688 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003689 try {
3690 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3691 } catch (IndexOutOfBoundsException e) {
3692 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3693 return null;
3694 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003695 }
3696 return tac;
3697 }
3698
3699 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003700 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003701 try {
3702 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3703 } catch (SecurityException se) {
3704 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3705 throw new SecurityException("Package " + callingPackage + " does not belong to "
3706 + Binder.getCallingUid());
3707 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003708 Phone phone = PhoneFactory.getPhone(slotIndex);
3709 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003710 return null;
3711 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003712
Jeff Davidson913390f2018-02-23 17:11:49 -08003713 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003714 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003715 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003716 return null;
3717 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003718
joonhunshin4ac60942023-11-15 15:23:39 +00003719 enforceTelephonyFeatureWithException(callingPackage,
3720 PackageManager.FEATURE_TELEPHONY_CDMA, "getMeidForSlot");
3721
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003722 final long identity = Binder.clearCallingIdentity();
3723 try {
3724 return phone.getMeid();
3725 } finally {
3726 Binder.restoreCallingIdentity(identity);
3727 }
Jack Yu2af8d712017-03-15 17:14:14 -07003728 }
3729
3730 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003731 public String getManufacturerCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003732 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3733 PackageManager.FEATURE_TELEPHONY_CDMA, "getManufacturerCodeForSlot");
3734
David Kelly5e06a7f2018-03-12 14:10:59 +00003735 Phone phone = PhoneFactory.getPhone(slotIndex);
3736 String manufacturerCode = null;
3737 if (phone != null) {
3738 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003739 try {
3740 manufacturerCode =
3741 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3742 } catch (IndexOutOfBoundsException e) {
3743 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3744 return null;
3745 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003746 }
3747 return manufacturerCode;
3748 }
3749
3750 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003751 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3752 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003753 Phone phone = PhoneFactory.getPhone(slotIndex);
3754 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003755 return null;
3756 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003757 int subId = phone.getSubId();
3758 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003759 mApp, subId, callingPackage, callingFeatureId,
3760 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003761 return null;
3762 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003763
joonhunshin4ac60942023-11-15 15:23:39 +00003764 enforceTelephonyFeatureWithException(callingPackage,
3765 PackageManager.FEATURE_TELEPHONY, "getDeviceSoftwareVersionForSlot");
3766
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003767 final long identity = Binder.clearCallingIdentity();
3768 try {
3769 return phone.getDeviceSvn();
3770 } finally {
3771 Binder.restoreCallingIdentity(identity);
3772 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003773 }
3774
fionaxu43304da2017-11-27 22:51:16 -08003775 @Override
3776 public int getSubscriptionCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003777 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3778 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierId");
3779
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003780 final long identity = Binder.clearCallingIdentity();
3781 try {
3782 final Phone phone = getPhone(subId);
3783 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3784 } finally {
3785 Binder.restoreCallingIdentity(identity);
3786 }
fionaxu43304da2017-11-27 22:51:16 -08003787 }
3788
3789 @Override
3790 public String getSubscriptionCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003791 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3792 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierName");
3793
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003794 final long identity = Binder.clearCallingIdentity();
3795 try {
3796 final Phone phone = getPhone(subId);
3797 return phone == null ? null : phone.getCarrierName();
3798 } finally {
3799 Binder.restoreCallingIdentity(identity);
3800 }
fionaxu43304da2017-11-27 22:51:16 -08003801 }
3802
calvinpanffe225e2018-11-01 19:43:06 +08003803 @Override
chen xu0026ca62019-03-06 15:28:50 -08003804 public int getSubscriptionSpecificCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003805 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3806 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionSpecificCarrierId");
3807
chen xu25637222018-11-04 17:17:00 -08003808 final long identity = Binder.clearCallingIdentity();
3809 try {
3810 final Phone phone = getPhone(subId);
3811 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003812 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003813 } finally {
3814 Binder.restoreCallingIdentity(identity);
3815 }
3816 }
3817
3818 @Override
chen xu0026ca62019-03-06 15:28:50 -08003819 public String getSubscriptionSpecificCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003820 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3821 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
3822 "getSubscriptionSpecificCarrierName");
3823
chen xu25637222018-11-04 17:17:00 -08003824 final long identity = Binder.clearCallingIdentity();
3825 try {
3826 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003827 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003828 } finally {
3829 Binder.restoreCallingIdentity(identity);
3830 }
3831 }
3832
chen xu651eec72018-11-11 19:03:44 -08003833 @Override
chen xu864e11c2018-12-06 22:10:03 -08003834 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3835 if (!isSubscriptionMccMnc) {
3836 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3837 }
chen xu651eec72018-11-11 19:03:44 -08003838 final Phone phone = PhoneFactory.getPhone(slotIndex);
3839 if (phone == null) {
3840 return TelephonyManager.UNKNOWN_CARRIER_ID;
3841 }
joonhunshin4ac60942023-11-15 15:23:39 +00003842
3843 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3844 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromMccMnc");
3845
chen xu651eec72018-11-11 19:03:44 -08003846 final long identity = Binder.clearCallingIdentity();
3847 try {
3848 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3849 } finally {
3850 Binder.restoreCallingIdentity(identity);
3851 }
3852 }
3853
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003854 //
3855 // Internal helper methods.
3856 //
3857
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003858 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003859 * Make sure the caller is the calling package itself
3860 *
3861 * @throws SecurityException if the caller is not the calling package
3862 */
3863 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3864 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003865 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3866 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003867 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003868 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003869 } catch (PackageManager.NameNotFoundException e) {
3870 // packageUid is -1
3871 }
3872 if (packageUid != callingUid) {
3873 throw new SecurityException(message + ": Package " + callingPackage
3874 + " does not belong to " + callingUid);
3875 }
3876 }
3877
3878 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003879 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3880 *
3881 * @throws SecurityException if the caller does not have the required permission
3882 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003883 @VisibleForTesting
3884 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003885 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3886 }
3887
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003888 /**
arunvoddud7401012022-12-15 16:08:12 +00003889 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003890 *
3891 * @throws SecurityException if the caller does not have the required permission
3892 */
3893 @VisibleForTesting
3894 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003895 enforceReadPermission(null);
3896 }
3897
3898 /**
3899 * Make sure the caller has the READ_PHONE_STATE permissions.
3900 *
3901 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3902 */
3903 @VisibleForTesting
3904 public void enforceReadPermission(String msg) {
3905 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003906 }
3907
Shuo Qian3b6ee772019-11-13 17:43:31 -08003908 private void enforceActiveEmergencySessionPermission() {
3909 mApp.enforceCallingOrSelfPermission(
3910 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3911 }
3912
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003913 /**
3914 * Make sure the caller has the CALL_PHONE permission.
3915 *
3916 * @throws SecurityException if the caller does not have the required permission
3917 */
3918 private void enforceCallPermission() {
3919 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3920 }
3921
paulhu5a773602019-08-23 19:17:33 +08003922 private void enforceSettingsPermission() {
3923 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003924 }
3925
Michele Berionne5e411512020-11-13 02:36:59 +00003926 private void enforceRebootPermission() {
3927 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3928 }
3929
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003930 /**
3931 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3932 * @param message - log message to print.
3933 * @throws SecurityException if the caller does not have the required permission
3934 */
3935 private void enforceSatelliteCommunicationPermission(String message) {
3936 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3937 }
3938
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003939 private String createTelUrl(String number) {
3940 if (TextUtils.isEmpty(number)) {
3941 return null;
3942 }
3943
Jake Hambye994d462014-02-03 13:10:13 -08003944 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003945 }
3946
Ihab Awadf9e92732013-12-05 18:02:52 -08003947 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003948 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003949 }
3950
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003951 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003952 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003953 }
3954
Ihab Awadf9e92732013-12-05 18:02:52 -08003955 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003956 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003957 }
3958
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003959 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003960 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003961 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003962 }
3963
Sanket Padawe356d7632015-06-22 14:03:32 -07003964 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003965 public int getActivePhoneTypeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003966 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3967 PackageManager.FEATURE_TELEPHONY, "getActivePhoneTypeForSlot");
3968
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003969 final long identity = Binder.clearCallingIdentity();
3970 try {
3971 final Phone phone = PhoneFactory.getPhone(slotIndex);
3972 if (phone == null) {
3973 return PhoneConstants.PHONE_TYPE_NONE;
3974 } else {
3975 return phone.getPhoneType();
3976 }
3977 } finally {
3978 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003979 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003980 }
3981
3982 /**
3983 * Returns the CDMA ERI icon index to display
3984 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003985 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003986 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3987 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3988 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003989 }
3990
Sanket Padawe356d7632015-06-22 14:03:32 -07003991 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003992 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3993 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003994 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003995 mApp, subId, callingPackage, callingFeatureId,
3996 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003997 return -1;
3998 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003999
joonhunshin4ac60942023-11-15 15:23:39 +00004000 enforceTelephonyFeatureWithException(callingPackage,
4001 PackageManager.FEATURE_TELEPHONY_CDMA,
4002 "getCdmaEriIconIndexForSubscriber");
4003
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004004 final long identity = Binder.clearCallingIdentity();
4005 try {
4006 final Phone phone = getPhone(subId);
4007 if (phone != null) {
4008 return phone.getCdmaEriIconIndex();
4009 } else {
4010 return -1;
4011 }
4012 } finally {
4013 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004014 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004015 }
4016
4017 /**
4018 * Returns the CDMA ERI icon mode,
4019 * 0 - ON
4020 * 1 - FLASHING
4021 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004022 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004023 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
4024 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
4025 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004026 }
4027
Sanket Padawe356d7632015-06-22 14:03:32 -07004028 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004029 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
4030 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004031 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004032 mApp, subId, callingPackage, callingFeatureId,
4033 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004034 return -1;
4035 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004036
4037 final long identity = Binder.clearCallingIdentity();
4038 try {
4039 final Phone phone = getPhone(subId);
4040 if (phone != null) {
4041 return phone.getCdmaEriIconMode();
4042 } else {
4043 return -1;
4044 }
4045 } finally {
4046 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004047 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004048 }
4049
4050 /**
4051 * Returns the CDMA ERI text,
4052 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004053 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004054 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
4055 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
4056 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004057 }
4058
Sanket Padawe356d7632015-06-22 14:03:32 -07004059 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004060 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
4061 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004062 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004063 mApp, subId, callingPackage, callingFeatureId,
4064 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004065 return null;
4066 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004067
4068 final long identity = Binder.clearCallingIdentity();
4069 try {
4070 final Phone phone = getPhone(subId);
4071 if (phone != null) {
4072 return phone.getCdmaEriText();
4073 } else {
4074 return null;
4075 }
4076 } finally {
4077 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004078 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004079 }
4080
4081 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07004082 * Returns the CDMA MDN.
4083 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004084 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004085 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004086 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4087 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004088
joonhunshin4ac60942023-11-15 15:23:39 +00004089 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4090 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMdn");
4091
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004092 final long identity = Binder.clearCallingIdentity();
4093 try {
4094 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004095 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004096 return phone.getLine1Number();
4097 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004098 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004099 return null;
4100 }
4101 } finally {
4102 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004103 }
4104 }
4105
4106 /**
4107 * Returns the CDMA MIN.
4108 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004109 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004110 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004111 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4112 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004113
joonhunshin4ac60942023-11-15 15:23:39 +00004114 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4115 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMin");
4116
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004117 final long identity = Binder.clearCallingIdentity();
4118 try {
4119 final Phone phone = getPhone(subId);
4120 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
4121 return phone.getCdmaMin();
4122 } else {
4123 return null;
4124 }
4125 } finally {
4126 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004127 }
4128 }
4129
Hall Liud892bec2018-11-30 14:51:45 -08004130 @Override
4131 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
4132 INumberVerificationCallback callback, String callingPackage) {
4133 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
4134 != PERMISSION_GRANTED) {
4135 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
4136 }
4137 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4138
4139 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
4140 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08004141 throw new SecurityException("Calling package must be configured in the device config: "
4142 + "calling package: " + callingPackage
4143 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004144 }
4145
joonhunshin4ac60942023-11-15 15:23:39 +00004146 enforceTelephonyFeatureWithException(callingPackage,
4147 PackageManager.FEATURE_TELEPHONY_CALLING, "requestNumberVerification");
4148
Hall Liud892bec2018-11-30 14:51:45 -08004149 if (range == null) {
4150 throw new NullPointerException("Range must be non-null");
4151 }
4152
4153 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004154 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004155
4156 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4157 }
4158
Junda Liuca05d5d2014-08-14 22:36:34 -07004159 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004160 * Returns true if CDMA provisioning needs to run.
4161 */
4162 public boolean needsOtaServiceProvisioning() {
joonhunshin4ac60942023-11-15 15:23:39 +00004163 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4164 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needsOtaServiceProvisioning");
4165
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004166 final long identity = Binder.clearCallingIdentity();
4167 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004168 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004169 } finally {
4170 Binder.restoreCallingIdentity(identity);
4171 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004172 }
4173
4174 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004175 * Sets the voice mail number of a given subId.
4176 */
4177 @Override
4178 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004179 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4180 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004181
joonhunshin4ac60942023-11-15 15:23:39 +00004182 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4183 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceMailNumber");
4184
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004185 final long identity = Binder.clearCallingIdentity();
4186 try {
4187 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4188 new Pair<String, String>(alphaTag, number), new Integer(subId));
4189 return success;
4190 } finally {
4191 Binder.restoreCallingIdentity(identity);
4192 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004193 }
4194
Ta-wei Yen87c49842016-05-13 21:19:52 -07004195 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004196 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4197 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004198 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4199 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004200 if (!TextUtils.equals(callingPackage, systemDialer)) {
4201 throw new SecurityException("caller must be system dialer");
4202 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004203
joonhunshin4ac60942023-11-15 15:23:39 +00004204 enforceTelephonyFeatureWithException(callingPackage,
4205 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailSettings");
4206
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004207 final long identity = Binder.clearCallingIdentity();
4208 try {
4209 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4210 if (phoneAccountHandle == null) {
4211 return null;
4212 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004213 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004214 } finally {
4215 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004216 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004217 }
4218
4219 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004220 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4221 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004222 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004223 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004224 mApp, subId, callingPackage, callingFeatureId,
4225 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004226 return null;
4227 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004228
joonhunshin4ac60942023-11-15 15:23:39 +00004229 enforceTelephonyFeatureWithException(callingPackage,
4230 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailPackageName");
4231
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004232 final long identity = Binder.clearCallingIdentity();
4233 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004234 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004235 } finally {
4236 Binder.restoreCallingIdentity(identity);
4237 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004238 }
4239
4240 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004241 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4242 VisualVoicemailSmsFilterSettings settings) {
4243 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004244
joonhunshin4ac60942023-11-15 15:23:39 +00004245 enforceTelephonyFeatureWithException(callingPackage,
4246 PackageManager.FEATURE_TELEPHONY_CALLING, "enableVisualVoicemailSmsFilter");
4247
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004248 final long identity = Binder.clearCallingIdentity();
4249 try {
4250 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004251 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004252 } finally {
4253 Binder.restoreCallingIdentity(identity);
4254 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004255 }
4256
4257 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004258 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4259 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004260
joonhunshin4ac60942023-11-15 15:23:39 +00004261 enforceTelephonyFeatureWithException(callingPackage,
4262 PackageManager.FEATURE_TELEPHONY_CALLING, "disableVisualVoicemailSmsFilter");
4263
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004264 final long identity = Binder.clearCallingIdentity();
4265 try {
4266 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004267 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004268 } finally {
4269 Binder.restoreCallingIdentity(identity);
4270 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004271 }
4272
4273 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004274 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4275 String callingPackage, int subId) {
4276 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004277
4278 final long identity = Binder.clearCallingIdentity();
4279 try {
4280 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004281 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004282 } finally {
4283 Binder.restoreCallingIdentity(identity);
4284 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004285 }
4286
4287 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004288 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004289 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004290
4291 final long identity = Binder.clearCallingIdentity();
4292 try {
4293 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004294 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004295 } finally {
4296 Binder.restoreCallingIdentity(identity);
4297 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004298 }
4299
4300 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004301 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4302 String callingAttributionTag, int subId, String number, int port, String text,
4303 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004304 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004305 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004306 enforceSendSmsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00004307
4308 enforceTelephonyFeatureWithException(callingPackage,
4309 PackageManager.FEATURE_TELEPHONY_CALLING, "sendVisualVoicemailSmsForSubscriber");
4310
Amit Mahajandccb3f12019-05-13 13:48:32 -07004311 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004312 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4313 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004314 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004315
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004316 /**
fionaxu0152e512016-11-14 13:36:14 -08004317 * Sets the voice activation state of a given subId.
4318 */
4319 @Override
4320 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004321 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4322 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004323
joonhunshin4ac60942023-11-15 15:23:39 +00004324 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4325 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState");
4326
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004327 final long identity = Binder.clearCallingIdentity();
4328 try {
4329 final Phone phone = getPhone(subId);
4330 if (phone != null) {
4331 phone.setVoiceActivationState(activationState);
4332 } else {
4333 loge("setVoiceActivationState fails with invalid subId: " + subId);
4334 }
4335 } finally {
4336 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004337 }
4338 }
4339
4340 /**
4341 * Sets the data activation state of a given subId.
4342 */
4343 @Override
4344 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004345 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4346 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004347
joonhunshin4ac60942023-11-15 15:23:39 +00004348 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4349 PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState");
4350
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004351 final long identity = Binder.clearCallingIdentity();
4352 try {
4353 final Phone phone = getPhone(subId);
4354 if (phone != null) {
4355 phone.setDataActivationState(activationState);
4356 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004357 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004358 }
4359 } finally {
4360 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004361 }
4362 }
4363
4364 /**
4365 * Returns the voice activation state of a given subId.
4366 */
4367 @Override
4368 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004369 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004370
joonhunshin4ac60942023-11-15 15:23:39 +00004371 enforceTelephonyFeatureWithException(callingPackage,
4372 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState");
4373
fionaxu0152e512016-11-14 13:36:14 -08004374 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004375 final long identity = Binder.clearCallingIdentity();
4376 try {
4377 if (phone != null) {
4378 return phone.getVoiceActivationState();
4379 } else {
4380 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4381 }
4382 } finally {
4383 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004384 }
4385 }
4386
4387 /**
4388 * Returns the data activation state of a given subId.
4389 */
4390 @Override
4391 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004392 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004393
joonhunshin4ac60942023-11-15 15:23:39 +00004394 enforceTelephonyFeatureWithException(callingPackage,
4395 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState");
4396
fionaxu0152e512016-11-14 13:36:14 -08004397 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004398 final long identity = Binder.clearCallingIdentity();
4399 try {
4400 if (phone != null) {
4401 return phone.getDataActivationState();
4402 } else {
4403 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4404 }
4405 } finally {
4406 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004407 }
4408 }
4409
4410 /**
Wink Saville36469e72014-06-11 15:17:00 -07004411 * Returns the unread count of voicemails for a subId
4412 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004413 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004414 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4415 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004416 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004417 mApp, subId, callingPackage, callingFeatureId,
4418 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004419 return 0;
4420 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004421 final long identity = Binder.clearCallingIdentity();
4422 try {
4423 final Phone phone = getPhone(subId);
4424 if (phone != null) {
4425 return phone.getVoiceMessageCount();
4426 } else {
4427 return 0;
4428 }
4429 } finally {
4430 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004431 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004432 }
4433
4434 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004435 * returns true, if the device is in a state where both voice and data
4436 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004437 */
4438 @Override
4439 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00004440 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4441 PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed");
4442
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004443 final long identity = Binder.clearCallingIdentity();
4444 try {
Ling Mac28f0212023-03-24 16:07:15 -07004445 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004446 } finally {
4447 Binder.restoreCallingIdentity(identity);
4448 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004449 }
4450
4451 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004452 * Send the dialer code if called from the current default dialer or the caller has
4453 * carrier privilege.
4454 * @param inputCode The dialer code to send
4455 */
4456 @Override
4457 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004458 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004459 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004460 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4461 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004462 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004463 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004464 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004465 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004466
joonhunshin4ac60942023-11-15 15:23:39 +00004467 enforceTelephonyFeatureWithException(callingPackage,
4468 PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode");
4469
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004470 final long identity = Binder.clearCallingIdentity();
4471 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004472 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004473 } finally {
4474 Binder.restoreCallingIdentity(identity);
4475 }
fionaxu235cc5e2017-03-06 22:25:57 -08004476 }
4477
Pengquan Menga1bb6272018-09-06 09:59:22 -07004478 @Override
4479 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004480 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004481 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4482 mApp, subId, "getNetworkSelectionMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004483
4484 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4485 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode");
4486
shilufc958392020-01-20 11:36:01 -08004487 final long identity = Binder.clearCallingIdentity();
4488 try {
4489 if (!isActiveSubscription(subId)) {
4490 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4491 }
4492 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4493 } finally {
4494 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004495 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004496 }
4497
Brad Ebinger35c841c2018-10-01 10:40:55 -07004498 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004499 public boolean isInEmergencySmsMode() {
4500 enforceReadPrivilegedPermission("isInEmergencySmsMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004501
4502 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4503 PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode");
4504
Brad Ebingerb2b65522019-03-15 13:48:47 -07004505 final long identity = Binder.clearCallingIdentity();
4506 try {
4507 for (Phone phone : PhoneFactory.getPhones()) {
4508 if (phone.isInEmergencySmsMode()) {
4509 return true;
4510 }
4511 }
4512 } finally {
4513 Binder.restoreCallingIdentity(identity);
4514 }
4515 return false;
4516 }
4517
shilu366312e2019-12-17 09:28:10 -08004518 /**
4519 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4520 * @param subId The subscription to use to check the configuration.
4521 * @param c The callback that will be used to send the result.
4522 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004523 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004524 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4525 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004526 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004527 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004528
4529 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4530 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4531 "IMS not available on device.");
4532 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004533 final long token = Binder.clearCallingIdentity();
4534 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004535 int slotId = getSlotIndexOrException(subId);
4536 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004537
4538 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4539 if (controller != null) {
4540 ImsManager imsManager = controller.getImsManager(subId);
4541 if (imsManager != null) {
4542 imsManager.addRegistrationCallbackForSubscription(c, subId);
4543 } else {
4544 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4545 }
4546 } else {
4547 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4548 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004549 } catch (ImsException e) {
4550 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004551 } finally {
4552 Binder.restoreCallingIdentity(token);
4553 }
4554 }
4555
shilu366312e2019-12-17 09:28:10 -08004556 /**
4557 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4558 * @param subId The subscription to use to check the configuration.
4559 * @param c The callback that will be used to send the result.
4560 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004561 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004562 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004563 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004564 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004565 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4566 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4567 }
Meng Wangafbc5852019-09-19 17:37:13 -07004568 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004569
Meng Wangafbc5852019-09-19 17:37:13 -07004570 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004571 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4572 if (controller != null) {
4573 ImsManager imsManager = controller.getImsManager(subId);
4574 if (imsManager != null) {
4575 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4576 } else {
4577 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4578 + "is inactive, ignoring unregister.");
4579 // If the ImsManager is not valid, just return, since the callback
4580 // will already have been removed internally.
4581 }
4582 }
Meng Wangafbc5852019-09-19 17:37:13 -07004583 } finally {
4584 Binder.restoreCallingIdentity(token);
4585 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004586 }
4587
Brad Ebingera34a6c22019-10-22 17:36:18 -07004588 /**
Hidayat Khan99ea48f2023-12-11 04:37:45 +00004589 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4590 * @param subId The subscription to use to check the configuration.
4591 * @param c The callback that will be used to send the result.
4592 */
4593 @Override
4594 public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c)
4595 throws RemoteException {
4596 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4597 mApp, subId, "registerImsEmergencyRegistrationCallback");
4598
4599 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4600 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4601 "IMS not available on device.");
4602 }
4603 final long token = Binder.clearCallingIdentity();
4604 try {
4605 int slotId = getSlotIndexOrException(subId);
4606 verifyImsMmTelConfiguredOrThrow(slotId);
4607
4608 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4609 if (controller != null) {
4610 ImsManager imsManager = controller.getImsManager(subId);
4611 if (imsManager != null) {
4612 imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId);
4613 } else {
4614 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4615 }
4616 } else {
4617 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4618 }
4619 } catch (ImsException e) {
4620 throw new ServiceSpecificException(e.getCode());
4621 } finally {
4622 Binder.restoreCallingIdentity(token);
4623 }
4624 }
4625
4626 /**
4627 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4628 * @param subId The subscription to use to check the configuration.
4629 * @param c The callback that will be used to send the result.
4630 */
4631 @Override
4632 public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) {
4633 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4634 mApp, subId, "unregisterImsEmergencyRegistrationCallback");
4635 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4636 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4637 }
4638 final long token = Binder.clearCallingIdentity();
4639
4640 try {
4641 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4642 if (controller != null) {
4643 ImsManager imsManager = controller.getImsManager(subId);
4644 if (imsManager != null) {
4645 imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId);
4646 } else {
4647 Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId
4648 + "is inactive, ignoring unregister.");
4649 // If the ImsManager is not valid, just return, since the callback
4650 // will already have been removed internally.
4651 }
4652 }
4653 } finally {
4654 Binder.restoreCallingIdentity(token);
4655 }
4656 }
4657
4658 /**
Brad Ebingera34a6c22019-10-22 17:36:18 -07004659 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4660 */
4661 @Override
4662 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4663 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4664 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4665 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4666 "IMS not available on device.");
4667 }
4668 final long token = Binder.clearCallingIdentity();
4669 try {
4670 Phone phone = getPhone(subId);
4671 if (phone == null) {
4672 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4673 + subId + "'");
4674 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4675 }
4676 phone.getImsRegistrationState(regState -> {
4677 try {
4678 consumer.accept((regState == null)
4679 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4680 } catch (RemoteException e) {
4681 // Ignore if the remote process is no longer available to call back.
4682 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4683 }
4684 });
4685 } finally {
4686 Binder.restoreCallingIdentity(token);
4687 }
4688 }
4689
4690 /**
4691 * Get the transport type for the IMS service registration state.
4692 */
4693 @Override
4694 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004695 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004696 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004697 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4698 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4699 "IMS not available on device.");
4700 }
4701 final long token = Binder.clearCallingIdentity();
4702 try {
4703 Phone phone = getPhone(subId);
4704 if (phone == null) {
4705 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4706 + subId + "'");
4707 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4708 }
4709 phone.getImsRegistrationTech(regTech -> {
4710 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4711 int regTechConverted = (regTech == null)
4712 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4713 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4714 regTechConverted);
4715 try {
4716 consumer.accept(regTechConverted);
4717 } catch (RemoteException e) {
4718 // Ignore if the remote process is no longer available to call back.
4719 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4720 }
4721 });
4722 } finally {
4723 Binder.restoreCallingIdentity(token);
4724 }
4725 }
4726
shilu366312e2019-12-17 09:28:10 -08004727 /**
4728 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4729 * @param subId The subscription to use to check the configuration.
4730 * @param c The callback that will be used to send the result.
4731 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004732 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004733 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4734 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004735 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004736 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004737 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4738 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4739 "IMS not available on device.");
4740 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004741 final long token = Binder.clearCallingIdentity();
4742 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004743 int slotId = getSlotIndexOrException(subId);
4744 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004745
4746 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4747 if (controller != null) {
4748 ImsManager imsManager = controller.getImsManager(subId);
4749 if (imsManager != null) {
4750 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4751 } else {
4752 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4753 }
4754 } else {
4755 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4756 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004757 } catch (ImsException e) {
4758 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004759 } finally {
4760 Binder.restoreCallingIdentity(token);
4761 }
4762 }
4763
shilu366312e2019-12-17 09:28:10 -08004764 /**
4765 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4766 * @param subId The subscription to use to check the configuration.
4767 * @param c The callback that will be used to send the result.
4768 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004769 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004770 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004771 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004772 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004773 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4774 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4775 }
Meng Wangafbc5852019-09-19 17:37:13 -07004776
4777 final long token = Binder.clearCallingIdentity();
4778 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004779 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4780 if (controller != null) {
4781 ImsManager imsManager = controller.getImsManager(subId);
4782 if (imsManager != null) {
4783 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4784 } else {
4785 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4786 + " is inactive, ignoring unregister.");
4787 // If the ImsManager is not valid, just return, since the callback
4788 // will already have been removed internally.
4789 }
4790 }
Meng Wangafbc5852019-09-19 17:37:13 -07004791 } finally {
4792 Binder.restoreCallingIdentity(token);
4793 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004794 }
4795
4796 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004797 public boolean isCapable(int subId, int capability, int regTech) {
4798 enforceReadPrivilegedPermission("isCapable");
joonhunshin4ac60942023-11-15 15:23:39 +00004799
4800 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4801 FEATURE_TELEPHONY_IMS, "isCapable");
4802
Brad Ebinger35c841c2018-10-01 10:40:55 -07004803 final long token = Binder.clearCallingIdentity();
4804 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004805 int slotId = getSlotIndexOrException(subId);
4806 verifyImsMmTelConfiguredOrThrow(slotId);
4807 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4808 } catch (com.android.ims.ImsException e) {
4809 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4810 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004811 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004812 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4813 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004814 } finally {
4815 Binder.restoreCallingIdentity(token);
4816 }
4817 }
4818
4819 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004820 public boolean isAvailable(int subId, int capability, int regTech) {
4821 enforceReadPrivilegedPermission("isAvailable");
joonhunshin4ac60942023-11-15 15:23:39 +00004822
4823 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4824 FEATURE_TELEPHONY_IMS, "isAvailable");
4825
Brad Ebinger35c841c2018-10-01 10:40:55 -07004826 final long token = Binder.clearCallingIdentity();
4827 try {
4828 Phone phone = getPhone(subId);
4829 if (phone == null) return false;
4830 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004831 } catch (com.android.ims.ImsException e) {
4832 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4833 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004834 } finally {
4835 Binder.restoreCallingIdentity(token);
4836 }
4837 }
4838
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004839 /**
4840 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4841 * subscription.
4842 * @param subId The subscription to use to check the configuration.
4843 * @param callback The callback that will be used to send the result.
4844 * @param capability The MmTelFeature capability that will be used to send the result.
4845 * @param transportType The transport type of the MmTelFeature capability.
4846 */
4847 @Override
4848 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4849 int transportType) {
4850 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004851 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4852 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4853 "IMS not available on device.");
4854 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004855 final long token = Binder.clearCallingIdentity();
4856 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004857 int slotId = getSlotIndex(subId);
4858 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4859 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4860 + subId + "'");
4861 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4862 }
4863 verifyImsMmTelConfiguredOrThrow(slotId);
4864 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4865 transportType, aBoolean -> {
4866 try {
4867 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4868 } catch (RemoteException e) {
4869 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4870 + "running. Ignore");
4871 }
4872 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004873 } catch (ImsException e) {
4874 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004875 } finally {
4876 Binder.restoreCallingIdentity(token);
4877 }
4878 }
4879
shilu366312e2019-12-17 09:28:10 -08004880 /**
4881 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4882 * @param subId The subscription to use to check the configuration.
4883 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004884 @Override
4885 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004886 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004887 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004888
joonhunshin4ac60942023-11-15 15:23:39 +00004889 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4890 FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled");
4891
Brad Ebinger35c841c2018-10-01 10:40:55 -07004892 final long token = Binder.clearCallingIdentity();
4893 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004894 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004895 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004896 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004897 } catch (ImsException e) {
4898 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004899 } finally {
4900 Binder.restoreCallingIdentity(token);
4901 }
4902 }
4903
4904 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004905 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004906 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004907 "setAdvancedCallingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004908
4909 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4910 FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled");
4911
Brad Ebinger35c841c2018-10-01 10:40:55 -07004912 final long identity = Binder.clearCallingIdentity();
4913 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004914 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004915 // This setting doesn't require an active ImsService connection, so do not verify. The
4916 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004917 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004918 } catch (ImsException e) {
4919 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004920 } finally {
4921 Binder.restoreCallingIdentity(identity);
4922 }
4923 }
4924
shilu366312e2019-12-17 09:28:10 -08004925 /**
4926 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4927 * @param subId The subscription to use to check the configuration.
4928 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004929 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004930 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004931 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004932 mApp, subId, "isVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004933
4934 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4935 FEATURE_TELEPHONY_IMS, "isVtSettingEnabled");
4936
Brad Ebinger35c841c2018-10-01 10:40:55 -07004937 final long identity = Binder.clearCallingIdentity();
4938 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004939 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004940 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004941 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004942 } catch (ImsException e) {
4943 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004944 } finally {
4945 Binder.restoreCallingIdentity(identity);
4946 }
4947 }
4948
4949 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004950 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004951 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004952 "setVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004953
4954 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4955 FEATURE_TELEPHONY_IMS, "setVtSettingEnabled");
4956
Brad Ebinger35c841c2018-10-01 10:40:55 -07004957 final long identity = Binder.clearCallingIdentity();
4958 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004959 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004960 // This setting doesn't require an active ImsService connection, so do not verify. The
4961 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004962 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004963 } catch (ImsException e) {
4964 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004965 } finally {
4966 Binder.restoreCallingIdentity(identity);
4967 }
4968 }
4969
shilu366312e2019-12-17 09:28:10 -08004970 /**
4971 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4972 * @param subId The subscription to use to check the configuration.
4973 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004974 @Override
4975 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004976 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004977 mApp, subId, "isVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004978
4979 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4980 FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled");
4981
Brad Ebinger35c841c2018-10-01 10:40:55 -07004982 final long identity = Binder.clearCallingIdentity();
4983 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004984 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004985 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004986 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004987 } catch (ImsException e) {
4988 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004989 } finally {
4990 Binder.restoreCallingIdentity(identity);
4991 }
4992 }
4993
4994 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004995 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004996 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004997 "setVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004998
4999 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5000 FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled");
5001
Brad Ebinger35c841c2018-10-01 10:40:55 -07005002 final long identity = Binder.clearCallingIdentity();
5003 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005004 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005005 // This setting doesn't require an active ImsService connection, so do not verify. The
5006 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005007 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005008 } catch (ImsException e) {
5009 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005010 } finally {
5011 Binder.restoreCallingIdentity(identity);
5012 }
5013 }
5014
shilu366312e2019-12-17 09:28:10 -08005015 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005016 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
5017 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5018 * @param subId The subscription to use to check the configuration.
5019 */
5020 @Override
5021 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005022 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005023 mApp, subId, "isCrossSimCallingEnabledByUser");
joonhunshin4ac60942023-11-15 15:23:39 +00005024
5025 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5026 FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser");
5027
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005028 final long identity = Binder.clearCallingIdentity();
5029 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005030 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005031 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005032 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005033 } catch (ImsException e) {
5034 throw new ServiceSpecificException(e.getCode());
5035 } finally {
5036 Binder.restoreCallingIdentity(identity);
5037 }
5038 }
5039
5040 /**
5041 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
5042 * Requires MODIFY_PHONE_STATE permission.
5043 * @param subId The subscription to use to check the configuration.
5044 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
5045 * false otherwise
5046 */
5047 @Override
5048 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
5049 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5050 "setCrossSimCallingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005051
5052 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5053 FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled");
5054
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005055 final long identity = Binder.clearCallingIdentity();
5056 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005057 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005058 // This setting doesn't require an active ImsService connection, so do not verify. The
5059 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005060 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005061 } catch (ImsException e) {
5062 throw new ServiceSpecificException(e.getCode());
5063 } finally {
5064 Binder.restoreCallingIdentity(identity);
5065 }
5066 }
5067
5068 /**
shilu366312e2019-12-17 09:28:10 -08005069 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5070 * @param subId The subscription to use to check the configuration.
5071 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005072 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07005073
Brad Ebinger35c841c2018-10-01 10:40:55 -07005074 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005075 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005076 mApp, subId, "isVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005077
5078 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5079 FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled");
5080
Brad Ebinger35c841c2018-10-01 10:40:55 -07005081 final long identity = Binder.clearCallingIdentity();
5082 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005083 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005084 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005085 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005086 } catch (ImsException e) {
5087 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005088 } finally {
5089 Binder.restoreCallingIdentity(identity);
5090 }
5091 }
5092
5093 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005094 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005095 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005096 "setVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005097
5098 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5099 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled");
5100
Brad Ebinger35c841c2018-10-01 10:40:55 -07005101 final long identity = Binder.clearCallingIdentity();
5102 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005103 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005104 // This setting doesn't require an active ImsService connection, so do not verify. The
5105 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005106 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005107 } catch (ImsException e) {
5108 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005109 } finally {
5110 Binder.restoreCallingIdentity(identity);
5111 }
5112 }
5113
5114 @Override
5115 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
5116 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5117 "setVoWiFiNonPersistent");
joonhunshin4ac60942023-11-15 15:23:39 +00005118
5119 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5120 FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent");
5121
Brad Ebinger35c841c2018-10-01 10:40:55 -07005122 final long identity = Binder.clearCallingIdentity();
5123 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005124 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005125 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005126 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005127 } catch (ImsException e) {
5128 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005129 } finally {
5130 Binder.restoreCallingIdentity(identity);
5131 }
5132 }
5133
shilu366312e2019-12-17 09:28:10 -08005134 /**
5135 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5136 * @param subId The subscription to use to check the configuration.
5137 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005138 @Override
5139 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005140 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005141 mApp, subId, "getVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005142
5143 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5144 FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting");
5145
Brad Ebinger35c841c2018-10-01 10:40:55 -07005146 final long identity = Binder.clearCallingIdentity();
5147 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005148 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005149 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005150 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005151 } catch (ImsException e) {
5152 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005153 } finally {
5154 Binder.restoreCallingIdentity(identity);
5155 }
5156 }
5157
5158 @Override
5159 public void setVoWiFiModeSetting(int subId, int mode) {
5160 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5161 "setVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005162
5163 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5164 FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting");
5165
Brad Ebinger35c841c2018-10-01 10:40:55 -07005166 final long identity = Binder.clearCallingIdentity();
5167 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005168 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005169 // This setting doesn't require an active ImsService connection, so do not verify. The
5170 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005171 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005172 } catch (ImsException e) {
5173 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005174 } finally {
5175 Binder.restoreCallingIdentity(identity);
5176 }
5177 }
5178
5179 @Override
5180 public int getVoWiFiRoamingModeSetting(int subId) {
5181 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005182
5183 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5184 FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting");
5185
Brad Ebinger35c841c2018-10-01 10:40:55 -07005186 final long identity = Binder.clearCallingIdentity();
5187 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005188 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005189 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005190 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005191 } catch (ImsException e) {
5192 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005193 } finally {
5194 Binder.restoreCallingIdentity(identity);
5195 }
5196 }
5197
5198 @Override
5199 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
5200 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5201 "setVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005202
5203 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5204 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting");
5205
Brad Ebinger35c841c2018-10-01 10:40:55 -07005206 final long identity = Binder.clearCallingIdentity();
5207 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005208 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005209 // This setting doesn't require an active ImsService connection, so do not verify. The
5210 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005211 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005212 } catch (ImsException e) {
5213 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005214 } finally {
5215 Binder.restoreCallingIdentity(identity);
5216 }
5217 }
5218
5219 @Override
5220 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
5221 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5222 "setRttCapabilityEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005223
5224 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5225 FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting");
5226
Brad Ebinger35c841c2018-10-01 10:40:55 -07005227 final long identity = Binder.clearCallingIdentity();
5228 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005229 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005230 // This setting doesn't require an active ImsService connection, so do not verify. The
5231 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005232 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005233 } catch (ImsException e) {
5234 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005235 } finally {
5236 Binder.restoreCallingIdentity(identity);
5237 }
5238 }
5239
shilu366312e2019-12-17 09:28:10 -08005240 /**
5241 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5242 * @param subId The subscription to use to check the configuration.
5243 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005244 @Override
5245 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005246 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005247 mApp, subId, "isTtyOverVolteEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005248
5249 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5250 FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled");
5251
Brad Ebinger35c841c2018-10-01 10:40:55 -07005252 final long identity = Binder.clearCallingIdentity();
5253 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005254 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005255 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005256 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005257 } catch (ImsException e) {
5258 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005259 } finally {
5260 Binder.restoreCallingIdentity(identity);
5261 }
5262 }
5263
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005264 @Override
5265 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5266 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005267
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005268 final long identity = Binder.clearCallingIdentity();
5269 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005270 if (!isImsAvailableOnDevice()) {
5271 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5272 "IMS not available on device.");
5273 }
5274 int slotId = getSlotIndexOrException(subId);
5275 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005276
5277 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5278 if (controller != null) {
5279 ImsManager imsManager = controller.getImsManager(subId);
5280 if (imsManager != null) {
5281 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5282 } else {
5283 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5284 }
5285 } else {
5286 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5287 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005288 } catch (ImsException e) {
5289 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005290 } finally {
5291 Binder.restoreCallingIdentity(identity);
5292 }
5293 }
5294
5295 @Override
5296 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5297 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005298
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005299 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005300 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5301 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5302 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005303 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005304 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5305 if (controller != null) {
5306 ImsManager imsManager = controller.getImsManager(subId);
5307 if (imsManager != null) {
5308 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5309 } else {
5310 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5311 + " is inactive, ignoring unregister.");
5312 // If the ImsManager is not valid, just return, since the callback will already
5313 // have been removed internally.
5314 }
5315 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005316 } finally {
5317 Binder.restoreCallingIdentity(identity);
5318 }
5319 }
5320
joonhunshincffb7fc2021-11-28 07:32:01 +00005321 @Override
5322 public void registerFeatureProvisioningChangedCallback(int subId,
5323 IFeatureProvisioningCallback callback) {
5324 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5325 mApp, subId, "registerFeatureProvisioningChangedCallback");
5326
5327 final long identity = Binder.clearCallingIdentity();
5328 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5329 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5330 }
5331
joonhunshin91bc1952022-04-29 08:47:15 +00005332 try {
5333 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5334 if (controller == null) {
5335 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5336 "Device does not support IMS");
5337 }
5338 controller.addFeatureProvisioningChangedCallback(subId, callback);
5339 } finally {
5340 Binder.restoreCallingIdentity(identity);
5341 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005342 }
5343
5344 @Override
5345 public void unregisterFeatureProvisioningChangedCallback(int subId,
5346 IFeatureProvisioningCallback callback) {
5347 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5348 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5349
5350 final long identity = Binder.clearCallingIdentity();
5351 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5352 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5353 }
5354
joonhunshin91bc1952022-04-29 08:47:15 +00005355 try {
5356 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5357 if (controller == null) {
5358 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5359 return;
5360 }
5361 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5362 } finally {
5363 Binder.restoreCallingIdentity(identity);
5364 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005365 }
allenwtsu99c623b2020-01-03 18:24:23 +08005366
5367 private void checkModifyPhoneStatePermission(int subId, String message) {
5368 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5369 message);
5370 }
5371
allenwtsu99c623b2020-01-03 18:24:23 +08005372 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005373 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005374 boolean isProvisioned) {
5375 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5376
joonhunshin4ac60942023-11-15 15:23:39 +00005377 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5378 FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability");
5379
allenwtsu99c623b2020-01-03 18:24:23 +08005380 final long identity = Binder.clearCallingIdentity();
5381 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005382 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5383 if (controller == null) {
5384 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5385 return;
5386 }
5387 controller.setRcsProvisioningStatusForCapability(
5388 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005389 } finally {
5390 Binder.restoreCallingIdentity(identity);
5391 }
allenwtsu99c623b2020-01-03 18:24:23 +08005392 }
5393
5394
5395 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005396 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5397 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5398 mApp, subId, "getRcsProvisioningStatusForCapability");
5399
joonhunshin4ac60942023-11-15 15:23:39 +00005400 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5401 FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability");
5402
allenwtsu99c623b2020-01-03 18:24:23 +08005403 final long identity = Binder.clearCallingIdentity();
5404 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005405 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5406 if (controller == null) {
5407 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5408
5409 // device does not support IMS, this method will return true always.
5410 return true;
5411 }
5412 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005413 } finally {
5414 Binder.restoreCallingIdentity(identity);
5415 }
5416 }
5417
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005418 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005419 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5420 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005421 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005422
joonhunshin4ac60942023-11-15 15:23:39 +00005423 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5424 FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability");
5425
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005426 final long identity = Binder.clearCallingIdentity();
5427 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005428 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5429 if (controller == null) {
5430 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5431 return;
5432 }
5433 controller.setImsProvisioningStatusForCapability(
5434 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005435 } finally {
5436 Binder.restoreCallingIdentity(identity);
5437 }
5438 }
5439
5440 @Override
5441 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005442 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5443 mApp, subId, "getProvisioningStatusForCapability");
5444
joonhunshin4ac60942023-11-15 15:23:39 +00005445 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5446 FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability");
5447
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005448 final long identity = Binder.clearCallingIdentity();
5449 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005450 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5451 if (controller == null) {
5452 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005453
joonhunshin91bc1952022-04-29 08:47:15 +00005454 // device does not support IMS, this method will return true always.
5455 return true;
5456 }
5457 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005458 } finally {
5459 Binder.restoreCallingIdentity(identity);
5460 }
5461 }
5462
5463 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005464 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5465 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5466 mApp, subId, "isProvisioningRequiredForCapability");
5467
joonhunshin4ac60942023-11-15 15:23:39 +00005468 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5469 FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability");
5470
joonhunshincffb7fc2021-11-28 07:32:01 +00005471 final long identity = Binder.clearCallingIdentity();
5472 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005473 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5474 if (controller == null) {
5475 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5476
5477 // device does not support IMS, this method will return false
5478 return false;
5479 }
5480 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005481 } finally {
5482 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005483 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005484 }
5485
5486 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005487 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5488 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5489 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005490
joonhunshin4ac60942023-11-15 15:23:39 +00005491 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5492 FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability");
5493
joonhunshincffb7fc2021-11-28 07:32:01 +00005494 final long identity = Binder.clearCallingIdentity();
5495 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005496 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5497 if (controller == null) {
5498 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5499
5500 // device does not support IMS, this method will return false
5501 return false;
5502 }
5503 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005504 } finally {
5505 Binder.restoreCallingIdentity(identity);
5506 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005507 }
5508
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005509 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005510 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005511 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5512 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5513 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005514 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5515 mApp, subId, "getImsProvisioningInt");
5516
joonhunshin4ac60942023-11-15 15:23:39 +00005517 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5518 FEATURE_TELEPHONY_IMS, "getImsProvisioningInt");
5519
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005520 final long identity = Binder.clearCallingIdentity();
5521 try {
5522 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005523 int slotId = getSlotIndex(subId);
5524 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5525 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5526 + subId + "' for key:" + key);
5527 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5528 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005529
joonhunshin91bc1952022-04-29 08:47:15 +00005530 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5531 if (controller == null) {
5532 loge("getImsProvisioningInt: Device does not support IMS");
5533
5534 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5535 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5536 }
5537 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005538 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5539 return retVal;
5540 }
5541
calvinpanb5a34062021-02-08 19:59:36 +08005542 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005543 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005544 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5545 + subId + "' for key:" + key);
5546 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005547 } finally {
5548 Binder.restoreCallingIdentity(identity);
5549 }
5550 }
5551
5552 @Override
5553 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005554 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5555 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5556 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005557 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5558 mApp, subId, "getImsProvisioningString");
5559
joonhunshin4ac60942023-11-15 15:23:39 +00005560 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5561 FEATURE_TELEPHONY_IMS, "getImsProvisioningString");
5562
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005563 final long identity = Binder.clearCallingIdentity();
5564 try {
5565 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005566 int slotId = getSlotIndex(subId);
5567 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5568 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5569 + subId + "' for key:" + key);
5570 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5571 }
calvinpanb5a34062021-02-08 19:59:36 +08005572 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005573 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005574 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5575 + subId + "' for key:" + key);
5576 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005577 } finally {
5578 Binder.restoreCallingIdentity(identity);
5579 }
5580 }
5581
5582 @Override
5583 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005584 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5585 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5586 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005587 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5588 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005589
joonhunshin4ac60942023-11-15 15:23:39 +00005590 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5591 FEATURE_TELEPHONY_IMS, "setImsProvisioningInt");
5592
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005593 final long identity = Binder.clearCallingIdentity();
5594 try {
5595 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005596 int slotId = getSlotIndex(subId);
5597 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5598 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5599 + subId + "' for key:" + key);
5600 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5601 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005602
joonhunshin91bc1952022-04-29 08:47:15 +00005603 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5604 if (controller == null) {
5605 loge("setImsProvisioningInt: Device does not support IMS");
5606
5607 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5608 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5609 }
5610 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005611 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5612 return retVal;
5613 }
5614
calvinpanb5a34062021-02-08 19:59:36 +08005615 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5616 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005617 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005618 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005619 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005620 } finally {
5621 Binder.restoreCallingIdentity(identity);
5622 }
5623 }
5624
5625 @Override
5626 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005627 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5628 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5629 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005630 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5631 "setImsProvisioningString");
joonhunshin4ac60942023-11-15 15:23:39 +00005632
5633 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5634 FEATURE_TELEPHONY_IMS, "setImsProvisioningString");
5635
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005636 final long identity = Binder.clearCallingIdentity();
5637 try {
5638 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005639 int slotId = getSlotIndex(subId);
5640 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5641 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5642 + subId + "' for key:" + key);
5643 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5644 }
calvinpanb5a34062021-02-08 19:59:36 +08005645 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5646 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005647 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005648 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005649 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005650 } finally {
5651 Binder.restoreCallingIdentity(identity);
5652 }
5653 }
5654
Brad Ebinger919631e2021-06-02 17:46:35 -07005655 /**
5656 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5657 * for the given slot ID or no ImsResolver instance has been created.
5658 * @param slotId The slot ID that the IMS service is created for.
5659 * @throws ImsException If there is no ImsService configured for this slot.
5660 */
5661 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5662 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5663 ImsFeature.FEATURE_MMTEL)) {
5664 throw new ImsException("This subscription does not support MMTEL over IMS",
5665 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5666 }
5667 }
5668
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005669 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005670 int slotId = SubscriptionManager.getSlotIndex(subId);
5671 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005672 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5673 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005674 }
5675 return slotId;
5676 }
5677
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005678 private int getSlotIndex(int subId) {
5679 int slotId = SubscriptionManager.getSlotIndex(subId);
5680 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5681 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5682 }
5683 return slotId;
5684 }
5685
Wink Saville36469e72014-06-11 15:17:00 -07005686 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005687 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005688 */
5689 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005690 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5691 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005692 try {
5693 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5694 } catch (SecurityException se) {
5695 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5696 throw new SecurityException("Package " + callingPackage + " does not belong to "
5697 + Binder.getCallingUid());
5698 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005699 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005700 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005701 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005702 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005703 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005704 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005705 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005706 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5707 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005708
joonhunshin4ac60942023-11-15 15:23:39 +00005709 enforceTelephonyFeatureWithException(callingPackage,
5710 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber");
5711
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005712 final long identity = Binder.clearCallingIdentity();
5713 try {
5714 final Phone phone = getPhone(subId);
5715 if (phone != null) {
5716 return phone.getServiceState().getDataNetworkType();
5717 } else {
5718 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5719 }
5720 } finally {
5721 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005722 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005723 }
5724
5725 /**
5726 * Returns the data network type
5727 */
5728 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005729 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005730 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005731 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005732 }
5733
5734 /**
5735 * Returns the data network type for a subId
5736 */
5737 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005738 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5739 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005740 String functionName = "getDataNetworkTypeForSubscriber";
5741 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5742 mApp, functionName)) {
5743 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5744 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5745 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5746 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005747 }
5748
joonhunshin4ac60942023-11-15 15:23:39 +00005749 enforceTelephonyFeatureWithException(callingPackage,
5750 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber");
5751
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005752 final long identity = Binder.clearCallingIdentity();
5753 try {
5754 final Phone phone = getPhone(subId);
5755 if (phone != null) {
5756 return phone.getServiceState().getDataNetworkType();
5757 } else {
5758 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5759 }
5760 } finally {
5761 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005762 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005763 }
5764
5765 /**
Wink Saville36469e72014-06-11 15:17:00 -07005766 * Returns the Voice network type for a subId
5767 */
5768 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005769 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5770 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005771 String functionName = "getVoiceNetworkTypeForSubscriber";
5772 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5773 mApp, functionName)) {
5774 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5775 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5776 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5777 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005778 }
5779
joonhunshin4ac60942023-11-15 15:23:39 +00005780 enforceTelephonyFeatureWithException(callingPackage,
5781 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber");
5782
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005783 final long identity = Binder.clearCallingIdentity();
5784 try {
5785 final Phone phone = getPhone(subId);
5786 if (phone != null) {
5787 return phone.getServiceState().getVoiceNetworkType();
5788 } else {
5789 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5790 }
5791 } finally {
5792 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005793 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005794 }
5795
5796 /**
5797 * @return true if a ICC card is present
5798 */
5799 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005800 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005801 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005802 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005803 }
5804
5805 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005806 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005807 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005808 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005809 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00005810 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5811 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex");
5812
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005813 final long identity = Binder.clearCallingIdentity();
5814 try {
5815 final Phone phone = PhoneFactory.getPhone(slotIndex);
5816 if (phone != null) {
5817 return phone.getIccCard().hasIccCard();
5818 } else {
5819 return false;
5820 }
5821 } finally {
5822 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005823 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005824 }
5825
5826 /**
5827 * Return if the current radio is LTE on CDMA. This
5828 * is a tri-state return value as for a period of time
5829 * the mode may be unknown.
5830 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005831 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005832 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005833 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005834 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005835 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005836 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5837 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5838 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005839 }
5840
Sanket Padawe356d7632015-06-22 14:03:32 -07005841 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005842 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5843 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005844 try {
5845 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5846 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005847 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5848 }
5849
joonhunshin4ac60942023-11-15 15:23:39 +00005850 enforceTelephonyFeatureWithException(callingPackage,
5851 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber");
5852
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005853 final long identity = Binder.clearCallingIdentity();
5854 try {
5855 final Phone phone = getPhone(subId);
5856 if (phone == null) {
5857 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5858 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005859 return TelephonyProperties.lte_on_cdma_device()
5860 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005861 }
5862 } finally {
5863 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005864 }
Wink Saville36469e72014-06-11 15:17:00 -07005865 }
5866
Wink Saville36469e72014-06-11 15:17:00 -07005867 /**
5868 * {@hide}
5869 * Returns Default subId, 0 in the case of single standby.
5870 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005871 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005872 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005873 }
5874
Shishir Agrawala9f32182016-04-12 12:00:16 -07005875 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005876 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005877 }
5878
Wink Savilleb564aae2014-10-23 10:18:09 -07005879 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005880 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005881 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005882
Pengquan Menge92a50d2018-09-21 15:54:48 -07005883 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005884 return getSubscriptionManagerService().isActiveSubId(subId,
5885 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005886 }
5887
Ihab Awadf2177b72013-11-25 13:33:23 -08005888 /**
5889 * @see android.telephony.TelephonyManager.WifiCallingChoices
5890 */
5891 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005892 final long identity = Binder.clearCallingIdentity();
5893 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005894 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005895 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5896 getWhenToMakeWifiCallsDefaultPreference());
5897 } finally {
5898 Binder.restoreCallingIdentity(identity);
5899 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005900 }
5901
5902 /**
5903 * @see android.telephony.TelephonyManager.WifiCallingChoices
5904 */
5905 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005906 final long identity = Binder.clearCallingIdentity();
5907 try {
5908 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005909 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005910 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5911 } finally {
5912 Binder.restoreCallingIdentity(identity);
5913 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005914 }
5915
Sailesh Nepald1e68152013-12-12 19:08:02 -08005916 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005917 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005918 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005919 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005920
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005921 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5922 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5923 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005924 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005925 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005926 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005927 }
5928 return PhoneFactory.getPhone(phoneId);
5929 }
5930
Shishir Agrawal566b7612013-10-28 14:41:00 -07005931 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005932 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005933 @NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00005934
Rambo Wanga1782702021-11-10 20:15:19 -08005935 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5936 /*message=*/ "iccOpenLogicalChannel");
5937
5938 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5939 // Verify that the callingPackage in the request belongs to the calling UID
5940 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5941
joonhunshin4ac60942023-11-15 15:23:39 +00005942 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5943 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel");
5944
Rambo Wanga1782702021-11-10 20:15:19 -08005945 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005946 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005947
Rambo Wanga1782702021-11-10 20:15:19 -08005948 private Phone getPhoneFromValidIccLogicalChannelRequest(
5949 @NonNull IccLogicalChannelRequest request, String message) {
5950 Phone phone;
5951 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5952 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5953 mApp, request.subId, message);
5954 phone = getPhoneFromSubId(request.subId);
5955 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5956 enforceModifyPermission();
5957 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5958 } else {
5959 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005960 }
Rambo Wanga1782702021-11-10 20:15:19 -08005961 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005962 }
5963
5964 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005965 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005966 final long identity = Binder.clearCallingIdentity();
5967 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005968 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005969 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005970 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5971 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005972 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5973 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005974 loge("The calling package is not allowed to access ISD-R.");
5975 throw new SecurityException(
5976 "The calling package is not allowed to access ISD-R.");
5977 }
Derek Tan740e1672017-06-27 14:56:27 -07005978 }
Derek Tan740e1672017-06-27 14:56:27 -07005979
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005980 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005981 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5982 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005983 return response;
5984 } finally {
5985 Binder.restoreCallingIdentity(identity);
5986 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005987 }
5988
5989 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005990 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00005991 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5992 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel");
5993
Rambo Wanga1782702021-11-10 20:15:19 -08005994 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5995 /*message=*/"iccCloseLogicalChannel");
5996
5997 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5998
5999 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006000 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006001
Rambo Wanga1782702021-11-10 20:15:19 -08006002 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
6003 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08006004 // before this feature is enabled, this API should only return false if
6005 // the operation fails instead of throwing runtime exception for
6006 // backward-compatibility.
6007 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
6008 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006009 final long identity = Binder.clearCallingIdentity();
6010 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006011 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08006012 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006013 }
Chen Xue9d737e2022-01-01 23:41:31 -08006014 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08006015 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08006016 Boolean success = false;
6017 if (result instanceof RuntimeException) {
6018 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08006019 if (shouldThrowExceptionOnFailure) {
6020 throw (RuntimeException) result;
6021 } else {
6022 return false;
6023 }
Chen Xue9d737e2022-01-01 23:41:31 -08006024 } else if (result instanceof Boolean) {
6025 success = (Boolean) result;
6026 } else {
6027 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
6028 }
Rambo Wanga1782702021-11-10 20:15:19 -08006029 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006030 return success;
6031 } finally {
6032 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006033 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006034 }
6035
6036 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006037 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07006038 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006039 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6040 mApp, subId, "iccTransmitApduLogicalChannel");
joonhunshin4ac60942023-11-15 15:23:39 +00006041
6042 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6043 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel");
6044
Jordan Liu4c733742019-02-28 12:03:40 -08006045 if (DBG) {
6046 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
6047 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
6048 + p3 + " data=" + data);
6049 }
6050 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
6051 command, p1, p2, p3, data);
6052 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006053
Jordan Liu4c733742019-02-28 12:03:40 -08006054 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006055 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006056 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006057 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006058
6059 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6060 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
6061 "iccTransmitApduLogicalChannelBySlot");
6062
Jordan Liu4c733742019-02-28 12:03:40 -08006063 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006064 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006065 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
6066 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006067 }
6068 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006069 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
6070 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006071 }
6072
6073 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
6074 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006075 final long identity = Binder.clearCallingIdentity();
6076 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07006077 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006078 return "";
6079 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006080
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006081 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006082 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
6083 null /* workSource */);
6084 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006085
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006086 // Append the returned status code to the end of the response payload.
6087 String s = Integer.toHexString(
6088 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6089 if (response.payload != null) {
6090 s = IccUtils.bytesToHexString(response.payload) + s;
6091 }
6092 return s;
6093 } finally {
6094 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006095 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006096 }
Jake Hambye994d462014-02-03 13:10:13 -08006097
Evan Charltonc66da362014-05-16 14:06:40 -07006098 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006099 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
6100 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006101 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6102 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006103 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006104
6105 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6106 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel");
6107
Jordan Liu4c733742019-02-28 12:03:40 -08006108 if (DBG) {
6109 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
6110 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
6111 }
6112 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
6113 cla, command, p1, p2, p3, data);
6114 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006115
Jordan Liu4c733742019-02-28 12:03:40 -08006116 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006117 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006118 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006119 enforceModifyPermission();
6120 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006121
6122 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6123 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot");
6124
Jordan Liu4c733742019-02-28 12:03:40 -08006125 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006126 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006127 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
6128 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006129 }
6130
6131 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006132 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
6133 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006134 }
6135
6136 // open APDU basic channel assuming the caller has sufficient permissions
6137 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
6138 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006139 final long identity = Binder.clearCallingIdentity();
6140 try {
6141 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
6142 && TextUtils.equals(ISDR_AID, data)) {
6143 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006144 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6145 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006146 if (bestComponent == null
6147 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
6148 loge("The calling package is not allowed to select ISD-R.");
6149 throw new SecurityException(
6150 "The calling package is not allowed to select ISD-R.");
6151 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006152 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006153
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006154 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006155 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
6156 null /* workSource */);
6157 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006158
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006159 // Append the returned status code to the end of the response payload.
6160 String s = Integer.toHexString(
6161 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6162 if (response.payload != null) {
6163 s = IccUtils.bytesToHexString(response.payload) + s;
6164 }
6165 return s;
6166 } finally {
6167 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006168 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006169 }
6170
6171 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006172 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006173 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006174 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6175 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006176
joonhunshin4ac60942023-11-15 15:23:39 +00006177 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6178 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO");
6179
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006180 final long identity = Binder.clearCallingIdentity();
6181 try {
6182 if (DBG) {
6183 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
6184 + p1 + " " + p2 + " " + p3 + ":" + filePath);
6185 }
6186
6187 IccIoResult response =
6188 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
6189 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
6190 subId);
6191
6192 if (DBG) {
6193 log("Exchange SIM_IO [R]" + response);
6194 }
6195
6196 byte[] result = null;
6197 int length = 2;
6198 if (response.payload != null) {
6199 length = 2 + response.payload.length;
6200 result = new byte[length];
6201 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
6202 } else {
6203 result = new byte[length];
6204 }
6205
6206 result[length - 1] = (byte) response.sw2;
6207 result[length - 2] = (byte) response.sw1;
6208 return result;
6209 } finally {
6210 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006211 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006212 }
6213
Nathan Haroldb3014052017-01-25 15:57:32 -08006214 /**
6215 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
6216 * on a particular subscription
6217 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006218 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
6219 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07006220 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006221 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07006222 return null;
6223 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006224
joonhunshin4ac60942023-11-15 15:23:39 +00006225 enforceTelephonyFeatureWithException(callingPackage,
6226 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns");
6227
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006228 final long identity = Binder.clearCallingIdentity();
6229 try {
6230 if (appType != TelephonyManager.APPTYPE_USIM
6231 && appType != TelephonyManager.APPTYPE_SIM) {
6232 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
6233 return null;
6234 }
6235 Object response = sendRequest(
6236 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
6237 if (response instanceof String[]) {
6238 return (String[]) response;
6239 }
yincheng zhao2737e882019-09-06 17:06:54 -07006240 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006241 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08006242 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006243 } finally {
6244 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08006245 }
Nathan Haroldb3014052017-01-25 15:57:32 -08006246 }
6247
yincheng zhao2737e882019-09-06 17:06:54 -07006248 /**
6249 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
6250 * subscription.
6251 *
6252 * @param subId the id of the subscription.
6253 * @param appType the uicc app type, must be USIM or SIM.
6254 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
6255 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006256 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07006257 * @return number of fplmns that is successfully written to the SIM.
6258 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006259 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
6260 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07006261 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6262 mApp, subId, "setForbiddenPlmns");
6263
joonhunshin4ac60942023-11-15 15:23:39 +00006264 enforceTelephonyFeatureWithException(callingPackage,
6265 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns");
6266
yincheng zhao2737e882019-09-06 17:06:54 -07006267 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
6268 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
6269 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
6270 }
6271 if (fplmns == null) {
6272 throw new IllegalArgumentException("Fplmn List provided is null");
6273 }
6274 for (String fplmn : fplmns) {
6275 if (!CellIdentity.isValidPlmn(fplmn)) {
6276 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
6277 }
6278 }
6279 final long identity = Binder.clearCallingIdentity();
6280 try {
6281 Object response = sendRequest(
6282 CMD_SET_FORBIDDEN_PLMNS,
6283 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
6284 subId);
6285 return (int) response;
6286 } finally {
6287 Binder.restoreCallingIdentity(identity);
6288 }
6289 }
6290
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006291 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006292 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006293 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6294 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07006295
joonhunshin4ac60942023-11-15 15:23:39 +00006296 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6297 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus");
6298
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006299 final long identity = Binder.clearCallingIdentity();
6300 try {
6301 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
6302 if (response.payload == null) {
6303 return "";
6304 }
Evan Charltonc66da362014-05-16 14:06:40 -07006305
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006306 // Append the returned status code to the end of the response payload.
6307 String s = Integer.toHexString(
6308 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6309 s = IccUtils.bytesToHexString(response.payload) + s;
6310 return s;
6311 } finally {
6312 Binder.restoreCallingIdentity(identity);
6313 }
Evan Charltonc66da362014-05-16 14:06:40 -07006314 }
6315
Jake Hambye994d462014-02-03 13:10:13 -08006316 /**
6317 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6318 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6319 *
6320 * @param itemID the ID of the item to read
6321 * @return the NV item as a String, or null on error.
6322 */
6323 @Override
6324 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006325 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006326 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6327 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006328
6329 final long identity = Binder.clearCallingIdentity();
6330 try {
6331 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07006332 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006333 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
6334 return value;
6335 } finally {
6336 Binder.restoreCallingIdentity(identity);
6337 }
Jake Hambye994d462014-02-03 13:10:13 -08006338 }
6339
6340 /**
6341 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6342 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6343 *
6344 * @param itemID the ID of the item to read
6345 * @param itemValue the value to write, as a String
6346 * @return true on success; false on any failure
6347 */
6348 @Override
6349 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006350 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006351 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6352 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006353
6354 final long identity = Binder.clearCallingIdentity();
6355 try {
6356 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6357 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006358 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006359 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6360 return success;
6361 } finally {
6362 Binder.restoreCallingIdentity(identity);
6363 }
Jake Hambye994d462014-02-03 13:10:13 -08006364 }
6365
6366 /**
6367 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6368 * Used for device configuration by some CDMA operators.
6369 *
6370 * @param preferredRoamingList byte array containing the new PRL
6371 * @return true on success; false on any failure
6372 */
6373 @Override
6374 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006375 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6376 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006377
6378 final long identity = Binder.clearCallingIdentity();
6379 try {
6380 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6381 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6382 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6383 return success;
6384 } finally {
6385 Binder.restoreCallingIdentity(identity);
6386 }
Jake Hambye994d462014-02-03 13:10:13 -08006387 }
6388
6389 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006390 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006391 * Used for device configuration by some CDMA operators.
6392 *
chen xu6dac5ab2018-10-26 17:39:23 -07006393 * @param slotIndex - device slot.
6394 *
Jake Hambye994d462014-02-03 13:10:13 -08006395 * @return true on success; false on any failure
6396 */
6397 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006398 public boolean resetModemConfig(int slotIndex) {
6399 Phone phone = PhoneFactory.getPhone(slotIndex);
6400 if (phone != null) {
6401 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6402 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006403
joonhunshin4ac60942023-11-15 15:23:39 +00006404 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6405 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig");
6406
chen xu6dac5ab2018-10-26 17:39:23 -07006407 final long identity = Binder.clearCallingIdentity();
6408 try {
6409 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6410 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6411 return success;
6412 } finally {
6413 Binder.restoreCallingIdentity(identity);
6414 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006415 }
chen xu6dac5ab2018-10-26 17:39:23 -07006416 return false;
6417 }
6418
6419 /**
6420 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6421 *
6422 * @param slotIndex - device slot.
6423 *
6424 * @return true on success; false on any failure
6425 */
6426 @Override
6427 public boolean rebootModem(int slotIndex) {
6428 Phone phone = PhoneFactory.getPhone(slotIndex);
6429 if (phone != null) {
6430 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6431 mApp, phone.getSubId(), "rebootModem");
6432
joonhunshin4ac60942023-11-15 15:23:39 +00006433 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6434 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem");
6435
chen xu6dac5ab2018-10-26 17:39:23 -07006436 final long identity = Binder.clearCallingIdentity();
6437 try {
6438 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6439 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6440 return success;
6441 } finally {
6442 Binder.restoreCallingIdentity(identity);
6443 }
6444 }
6445 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006446 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006447
Brad Ebinger51f743a2017-01-23 13:50:20 -08006448 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006449 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6450 * {@link #disableIms(int)}.
6451 * @param slotIndex device slot.
6452 */
6453 public void resetIms(int slotIndex) {
6454 enforceModifyPermission();
6455
joonhunshin4ac60942023-11-15 15:23:39 +00006456 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6457 PackageManager.FEATURE_TELEPHONY_IMS, "resetIms");
6458
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006459 final long identity = Binder.clearCallingIdentity();
6460 try {
6461 if (mImsResolver == null) {
6462 // may happen if the does not support IMS.
6463 return;
6464 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006465 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006466 } finally {
6467 Binder.restoreCallingIdentity(identity);
6468 }
6469 }
6470
6471 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006472 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6473 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006474 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006475 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006476 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006477
6478 final long identity = Binder.clearCallingIdentity();
6479 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006480 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006481 // may happen if the device does not support IMS.
6482 return;
6483 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006484 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006485 } finally {
6486 Binder.restoreCallingIdentity(identity);
6487 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006488 }
6489
6490 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006491 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6492 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006493 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006494 public void disableIms(int slotId) {
6495 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006496
6497 final long identity = Binder.clearCallingIdentity();
6498 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006499 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006500 // may happen if the device does not support IMS.
6501 return;
6502 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006503 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006504 } finally {
6505 Binder.restoreCallingIdentity(identity);
6506 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006507 }
6508
6509 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006510 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6511 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006512 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006513 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006514 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006515 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006516
6517 final long identity = Binder.clearCallingIdentity();
6518 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006519 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006520 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6521 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006522 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006523 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006524 } finally {
6525 Binder.restoreCallingIdentity(identity);
6526 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006527 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006528 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006529 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6530 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006531 @Override
6532 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006533 enforceModifyPermission();
6534
6535 final long identity = Binder.clearCallingIdentity();
6536 try {
6537 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006538 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006539 } finally {
6540 Binder.restoreCallingIdentity(identity);
6541 }
6542 }
6543
6544 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006545 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006546 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006547 */
6548 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6549 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006550
6551 final long identity = Binder.clearCallingIdentity();
6552 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006553 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006554 // may happen if the device does not support IMS.
6555 return null;
6556 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006557 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006558 } finally {
6559 Binder.restoreCallingIdentity(identity);
6560 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006561 }
6562
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006563 /**
6564 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006565 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006566 */
6567 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6568 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006569
6570 final long identity = Binder.clearCallingIdentity();
6571 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006572 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006573 // may happen if the device does not support IMS.
6574 return null;
6575 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006576 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006577 } finally {
6578 Binder.restoreCallingIdentity(identity);
6579 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006580 }
6581
Brad Ebinger884c07b2018-02-15 16:17:40 -08006582 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006583 * Sets the ImsService Package Name that Telephony will bind to.
6584 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006585 * @param slotIndex the slot ID that the ImsService should bind for.
6586 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006587 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006588 * @param featureTypes An integer array of feature types associated with a packageName.
6589 * @param packageName The name of the package that the current configuration will be replaced
6590 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006591 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006592 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006593 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6594 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006595 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006596 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006597 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006598
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006599 final long identity = Binder.clearCallingIdentity();
6600 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006601 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006602 // may happen if the device does not support IMS.
6603 return false;
6604 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006605 Map<Integer, String> featureConfig = new HashMap<>();
6606 for (int featureType : featureTypes) {
6607 featureConfig.put(featureType, packageName);
6608 }
6609 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6610 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006611 } finally {
6612 Binder.restoreCallingIdentity(identity);
6613 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006614 }
6615
6616 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006617 * Clears any carrier ImsService overrides for the slot index specified that were previously
6618 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6619 *
6620 * This should only be used for testing.
6621 *
6622 * @param slotIndex the slot ID that the ImsService should bind for.
6623 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6624 */
6625 @Override
6626 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006627 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6628 "clearCarrierImsServiceOverride");
6629 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006630 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006631
6632 final long identity = Binder.clearCallingIdentity();
6633 try {
6634 if (mImsResolver == null) {
6635 // may happen if the device does not support IMS.
6636 return false;
6637 }
6638 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6639 } finally {
6640 Binder.restoreCallingIdentity(identity);
6641 }
6642 }
6643
6644 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006645 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006646 *
6647 * @param slotId The slot that the ImsService is associated with.
6648 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6649 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006650 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006651 * @return the package name of the ImsService configuration.
6652 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006653 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6654 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006655 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006656 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6657 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006658
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006659 final long identity = Binder.clearCallingIdentity();
6660 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006661 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006662 // may happen if the device does not support IMS.
6663 return "";
6664 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006665 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006666 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6667 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006668 } finally {
6669 Binder.restoreCallingIdentity(identity);
6670 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006671 }
6672
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006673 /**
6674 * Get the MmTelFeature state associated with the requested subscription id.
6675 * @param subId The subscription that the MmTelFeature is associated with.
6676 * @param callback A callback with an integer containing the
6677 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6678 */
6679 @Override
6680 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6681 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006682 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6683 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6684 "IMS not available on device.");
6685 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006686 final long token = Binder.clearCallingIdentity();
6687 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006688 int slotId = getSlotIndex(subId);
6689 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6690 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6691 + subId + "'");
6692 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6693 }
6694 verifyImsMmTelConfiguredOrThrow(slotId);
6695 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6696 try {
6697 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6698 } catch (RemoteException e) {
6699 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6700 + "Ignore");
6701 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006702 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006703 } catch (ImsException e) {
6704 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006705 } finally {
6706 Binder.restoreCallingIdentity(token);
6707 }
6708 }
6709
Daniel Brightbb5840b2021-01-12 15:48:18 -08006710 /**
6711 * Sets the ims registration state on all valid {@link Phone}s.
6712 */
6713 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006714 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006715
6716 final long identity = Binder.clearCallingIdentity();
6717 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006718 // NOTE: Before S, this method only set the default phone.
6719 for (final Phone phone : PhoneFactory.getPhones()) {
6720 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6721 phone.setImsRegistrationState(registered);
6722 }
6723 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006724 } finally {
6725 Binder.restoreCallingIdentity(identity);
6726 }
Wink Saville36469e72014-06-11 15:17:00 -07006727 }
6728
6729 /**
Stuart Scott54788802015-03-30 13:18:01 -07006730 * Set the network selection mode to automatic.
6731 *
6732 */
6733 @Override
6734 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006735 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6736 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006737
joonhunshin4ac60942023-11-15 15:23:39 +00006738 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6739 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic");
6740
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006741 final long identity = Binder.clearCallingIdentity();
6742 try {
shilufc958392020-01-20 11:36:01 -08006743 if (!isActiveSubscription(subId)) {
6744 return;
6745 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006746 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006747 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6748 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006749 } finally {
6750 Binder.restoreCallingIdentity(identity);
6751 }
Stuart Scott54788802015-03-30 13:18:01 -07006752 }
6753
Jack Yud10cdd42020-09-28 20:28:01 -07006754 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006755 * Ask the radio to connect to the input network and change selection mode to manual.
6756 *
6757 * @param subId the id of the subscription.
6758 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6759 * the operator to attach to.
6760 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6761 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6762 * normal network selection next time.
6763 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006764 */
6765 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006766 public boolean setNetworkSelectionModeManual(
6767 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006768 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6769 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006770
joonhunshin4ac60942023-11-15 15:23:39 +00006771 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6772 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual");
6773
Jack Yu285100e2022-12-02 22:48:35 -08006774 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006775 if (!isActiveSubscription(subId)) {
6776 return false;
6777 }
6778
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006779 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006780 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006781 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006782 if (DBG) {
6783 log("setNetworkSelectionModeManual: subId: " + subId
6784 + " operator: " + operatorInfo);
6785 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006786 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6787 } finally {
6788 Binder.restoreCallingIdentity(identity);
6789 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006790 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006791 /**
shilu84f6e8b2019-12-19 13:58:01 -08006792 * Get the manual network selection
6793 *
6794 * @param subId the id of the subscription.
6795 *
6796 * @return the previously saved user selected PLMN
6797 */
6798 @Override
6799 public String getManualNetworkSelectionPlmn(int subId) {
6800 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006801 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6802 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006803
joonhunshin4ac60942023-11-15 15:23:39 +00006804 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6805 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn");
6806
shilu84f6e8b2019-12-19 13:58:01 -08006807 final long identity = Binder.clearCallingIdentity();
6808 try {
6809 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006810 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006811 }
6812
6813 final Phone phone = getPhone(subId);
6814 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006815 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006816 }
6817 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6818 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006819 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006820 } finally {
6821 Binder.restoreCallingIdentity(identity);
6822 }
6823 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006824
6825 /**
6826 * Scans for available networks.
6827 */
6828 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006829 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6830 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006831 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6832 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006833 LocationAccessPolicy.LocationPermissionResult locationResult =
6834 LocationAccessPolicy.checkLocationPermission(mApp,
6835 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6836 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006837 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006838 .setCallingPid(Binder.getCallingPid())
6839 .setCallingUid(Binder.getCallingUid())
6840 .setMethod("getCellNetworkScanResults")
6841 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006842 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6843 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006844 .build());
6845 switch (locationResult) {
6846 case DENIED_HARD:
6847 throw new SecurityException("Not allowed to access scan results -- location");
6848 case DENIED_SOFT:
6849 return null;
6850 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006851
Pengquan Menga1bb6272018-09-06 09:59:22 -07006852 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006853 try {
6854 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006855 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006856 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006857 } finally {
6858 Binder.restoreCallingIdentity(identity);
6859 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006860 }
6861
6862 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006863 * Get the call forwarding info, given the call forwarding reason.
6864 */
6865 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006866 public void getCallForwarding(int subId, int callForwardingReason,
6867 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006868 enforceReadPrivilegedPermission("getCallForwarding");
joonhunshin4ac60942023-11-15 15:23:39 +00006869
6870 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6871 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding");
6872
Shuo Qian4a594052020-01-23 11:59:30 -08006873 long identity = Binder.clearCallingIdentity();
6874 try {
6875 if (DBG) {
6876 log("getCallForwarding: subId " + subId
6877 + " callForwardingReason" + callForwardingReason);
6878 }
Hall Liu27d24262020-09-18 19:04:59 -07006879
6880 Phone phone = getPhone(subId);
6881 if (phone == null) {
6882 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006883 callback.onError(
6884 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006885 } catch (RemoteException e) {
6886 // ignore
6887 }
6888 return;
6889 }
6890
6891 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6892 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6893 @Override
6894 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6895 try {
6896 callback.onCallForwardingInfoAvailable(info);
6897 } catch (RemoteException e) {
6898 // ignore
6899 }
6900 }
6901
6902 @Override
6903 public void onError(int error) {
6904 try {
6905 callback.onError(error);
6906 } catch (RemoteException e) {
6907 // ignore
6908 }
6909 }
6910 });
6911 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006912 } finally {
6913 Binder.restoreCallingIdentity(identity);
6914 }
6915 }
6916
6917 /**
6918 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6919 * reason, the number to forward, and the timeout before the forwarding is attempted.
6920 */
6921 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006922 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6923 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006924 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006925
6926 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6927 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding");
6928
Shuo Qian4a594052020-01-23 11:59:30 -08006929 long identity = Binder.clearCallingIdentity();
6930 try {
6931 if (DBG) {
6932 log("setCallForwarding: subId " + subId
6933 + " callForwardingInfo" + callForwardingInfo);
6934 }
Hall Liu27d24262020-09-18 19:04:59 -07006935
6936 Phone phone = getPhone(subId);
6937 if (phone == null) {
6938 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006939 callback.accept(
6940 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006941 } catch (RemoteException e) {
6942 // ignore
6943 }
6944 return;
6945 }
6946
6947 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6948 FunctionalUtils.ignoreRemoteException(callback::accept));
6949
6950 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006951 } finally {
6952 Binder.restoreCallingIdentity(identity);
6953 }
6954 }
6955
6956 /**
Hall Liu27d24262020-09-18 19:04:59 -07006957 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006958 */
6959 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006960 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006961 enforceReadPrivilegedPermission("getCallWaitingStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00006962
6963 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6964 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus");
6965
Shuo Qian4a594052020-01-23 11:59:30 -08006966 long identity = Binder.clearCallingIdentity();
6967 try {
Hall Liu27d24262020-09-18 19:04:59 -07006968 Phone phone = getPhone(subId);
6969 if (phone == null) {
6970 try {
6971 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6972 } catch (RemoteException e) {
6973 // ignore
6974 }
6975 return;
6976 }
SongFerngWang0e767992021-03-31 22:08:45 +08006977 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6978 PersistableBundle c = configManager.getConfigForSubId(subId);
6979 boolean requireUssd = c.getBoolean(
6980 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006981
Shuo Qian4a594052020-01-23 11:59:30 -08006982 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006983 if (requireUssd) {
6984 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6985 getSubscriptionCarrierId(subId));
6986 String newUssdCommand = "";
6987 try {
6988 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006989 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006990 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6991 } catch (NullPointerException e) {
6992 loge("Failed to generate USSD number" + e);
6993 }
6994 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6995 mMainThreadHandler, callback, carrierXmlParser,
6996 CarrierXmlParser.SsEntry.SSAction.QUERY);
6997 final String ussdCommand = newUssdCommand;
6998 Executors.newSingleThreadExecutor().execute(() -> {
6999 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7000 });
7001 } else {
7002 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
7003 callback::accept);
7004 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
7005 }
Shuo Qian4a594052020-01-23 11:59:30 -08007006 } finally {
7007 Binder.restoreCallingIdentity(identity);
7008 }
7009 }
7010
7011 /**
Hall Liu27d24262020-09-18 19:04:59 -07007012 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007013 */
7014 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007015 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007016 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007017
7018 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7019 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus");
7020
Shuo Qian4a594052020-01-23 11:59:30 -08007021 long identity = Binder.clearCallingIdentity();
7022 try {
Hall Liu27d24262020-09-18 19:04:59 -07007023 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
7024
7025 Phone phone = getPhone(subId);
7026 if (phone == null) {
7027 try {
7028 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7029 } catch (RemoteException e) {
7030 // ignore
7031 }
7032 return;
7033 }
7034
SongFerngWang0e767992021-03-31 22:08:45 +08007035 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7036 PersistableBundle c = configManager.getConfigForSubId(subId);
7037 boolean requireUssd = c.getBoolean(
7038 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007039
SongFerngWang0e767992021-03-31 22:08:45 +08007040 if (DBG) log("getCallWaitingStatus: subId " + subId);
7041 if (requireUssd) {
7042 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7043 getSubscriptionCarrierId(subId));
7044 CarrierXmlParser.SsEntry.SSAction ssAction =
7045 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
7046 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
7047 String newUssdCommand = "";
7048 try {
7049 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007050 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007051 .makeCommand(ssAction, null);
7052 } catch (NullPointerException e) {
7053 loge("Failed to generate USSD number" + e);
7054 }
7055 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7056 mMainThreadHandler, callback, carrierXmlParser, ssAction);
7057 final String ussdCommand = newUssdCommand;
7058 Executors.newSingleThreadExecutor().execute(() -> {
7059 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7060 });
7061 } else {
7062 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
7063 FunctionalUtils.ignoreRemoteException(callback::accept));
7064
7065 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
7066 }
Shuo Qian4a594052020-01-23 11:59:30 -08007067 } finally {
7068 Binder.restoreCallingIdentity(identity);
7069 }
7070 }
7071
7072 /**
yinxub1bed742017-04-17 11:45:04 -07007073 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07007074 *
yinxub1bed742017-04-17 11:45:04 -07007075 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007076 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
7077 * location related information which will be sent if the caller already possess
7078 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07007079 * @param request contains the radio access networks with bands/channels to scan
7080 * @param messenger callback messenger for scan results or errors
7081 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07007082 * @return the id of the requested scan which can be used to stop the scan.
7083 */
7084 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007085 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
7086 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007087 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007088 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7089 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08007090 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007091 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
7092 if (!renounceFineLocationAccess) {
7093 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007094 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7095 .setCallingPackage(callingPackage)
7096 .setCallingFeatureId(callingFeatureId)
7097 .setCallingPid(Binder.getCallingPid())
7098 .setCallingUid(Binder.getCallingUid())
7099 .setMethod("requestNetworkScan")
7100 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7101 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7102 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7103 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007104 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08007105 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07007106 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
7107 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08007108 if (e != null) {
7109 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
7110 throw e;
7111 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07007112 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08007113 return TelephonyScanManager.INVALID_SCAN_ID;
7114 }
7115 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007116 }
joonhunshin4ac60942023-11-15 15:23:39 +00007117
7118 enforceTelephonyFeatureWithException(callingPackage,
7119 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan");
7120
Hall Liu912dfd32019-04-25 14:02:26 -07007121 int callingUid = Binder.getCallingUid();
7122 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07007123 final long identity = Binder.clearCallingIdentity();
7124 try {
7125 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07007126 renounceFineLocationAccess, request, messenger, binder,
7127 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07007128 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07007129 } finally {
7130 Binder.restoreCallingIdentity(identity);
7131 }
yinxu504e1392017-04-12 16:03:22 -07007132 }
7133
Hall Liub2ac8ef2019-02-28 15:56:23 -08007134 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07007135 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00007136 boolean hasCarrierPriv;
7137 final long identity = Binder.clearCallingIdentity();
7138 try {
7139 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
7140 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
7141 } finally {
7142 Binder.restoreCallingIdentity(identity);
7143 }
Hall Liu558027f2019-05-15 19:14:05 -07007144 boolean hasNetworkScanPermission =
7145 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007146 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07007147
7148 if (!hasCarrierPriv && !hasNetworkScanPermission) {
7149 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
7150 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08007151 }
7152
7153 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
7154 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08007155 if (ras.getChannels() != null && ras.getChannels().length > 0) {
7156 return new SecurityException("Specific channels must not be"
7157 + " scanned without location access.");
7158 }
7159 }
7160 }
7161
Hall Liub2ac8ef2019-02-28 15:56:23 -08007162 return null;
7163 }
7164
yinxu504e1392017-04-12 16:03:22 -07007165 /**
7166 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07007167 *
7168 * @param subId id of the subscription
7169 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07007170 */
7171 @Override
7172 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007173 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7174 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007175
Hall Liu912dfd32019-04-25 14:02:26 -07007176 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007177 final long identity = Binder.clearCallingIdentity();
7178 try {
Hall Liu912dfd32019-04-25 14:02:26 -07007179 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007180 } finally {
7181 Binder.restoreCallingIdentity(identity);
7182 }
yinxu504e1392017-04-12 16:03:22 -07007183 }
7184
7185 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08007186 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07007187 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08007188 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07007189 */
7190 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08007191 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08007192 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007193 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08007194 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007195
joonhunshin4ac60942023-11-15 15:23:39 +00007196 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7197 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask");
7198
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007199 final long identity = Binder.clearCallingIdentity();
7200 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007201 if (DBG) log("getAllowedNetworkTypesBitmask");
7202 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
7203 int networkTypesBitmask = (result != null ? result[0] : -1);
7204 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
7205 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007206 } finally {
7207 Binder.restoreCallingIdentity(identity);
7208 }
Jake Hamby7c27be32014-03-03 13:25:59 -08007209 }
7210
7211 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007212 * Get the allowed network types for certain reason.
7213 *
7214 * @param subId the id of the subscription.
7215 * @param reason the reason the allowed network type change is taking place
7216 * @return the allowed network types.
7217 */
7218 @Override
7219 public long getAllowedNetworkTypesForReason(int subId,
7220 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07007221 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007222 mApp, subId, "getAllowedNetworkTypesForReason");
joonhunshin4ac60942023-11-15 15:23:39 +00007223
7224 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7225 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesForReason");
7226
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007227 final long identity = Binder.clearCallingIdentity();
7228 try {
Jack Yu7247ac82023-03-02 23:52:10 -08007229 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007230 } finally {
7231 Binder.restoreCallingIdentity(identity);
7232 }
7233 }
7234
7235 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07007236 * Enable/Disable E-UTRA-NR Dual Connectivity
7237 * @param subId subscription id of the sim card
7238 * @param nrDualConnectivityState expected NR dual connectivity state
7239 * This can be passed following states
7240 * <ol>
7241 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
7242 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
7243 * <li>Disable NR dual connectivity and force secondary cell to be released
7244 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
7245 * </ol>
7246 * @return operation result.
7247 */
7248 @Override
7249 public int setNrDualConnectivityState(int subId,
7250 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
7251 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7252 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007253 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007254 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7255 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
7256 }
7257
Sooraj Sasindran37444802020-08-11 10:40:43 -07007258 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7259 final long identity = Binder.clearCallingIdentity();
7260 try {
7261 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
7262 nrDualConnectivityState, subId,
7263 workSource);
7264 if (DBG) log("enableNRDualConnectivity result: " + result);
7265 return result;
7266 } finally {
7267 Binder.restoreCallingIdentity(identity);
7268 }
7269 }
7270
7271 /**
7272 * Is E-UTRA-NR Dual Connectivity enabled
7273 * @return true if dual connectivity is enabled else false
7274 */
7275 @Override
7276 public boolean isNrDualConnectivityEnabled(int subId) {
7277 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007278 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07007279 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007280 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007281 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7282 return false;
7283 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07007284 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7285 final long identity = Binder.clearCallingIdentity();
7286 try {
7287 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
7288 null, subId, workSource);
7289 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
7290 return isEnabled;
7291 } finally {
7292 Binder.restoreCallingIdentity(identity);
7293 }
7294 }
7295
7296 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007297 * Set the allowed network types of the device and
7298 * provide the reason triggering the allowed network change.
7299 *
7300 * @param subId the id of the subscription.
7301 * @param reason the reason the allowed network type change is taking place
7302 * @param allowedNetworkTypes the allowed network types.
7303 * @return true on success; false on any failure.
7304 */
7305 @Override
7306 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08007307 @TelephonyManager.AllowedNetworkTypesReason int reason,
7308 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007309 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7310 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007311 // If the caller only has carrier privileges, then they should not be able to override
7312 // any network types which were set for security reasons.
7313 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
7314 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007315 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007316 throw new SecurityException(
7317 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007318 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007319 }
joonhunshin4ac60942023-11-15 15:23:39 +00007320
7321 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7322 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason");
7323
SongFerngWang3ef3e072020-12-21 16:41:52 +08007324 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007325 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08007326 return false;
7327 }
7328 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
7329 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007330 return false;
7331 }
7332
Jack Yu5b494332023-01-23 18:18:04 +00007333 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
7334 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007335
Jack Yue37dd262022-12-16 11:53:37 -08007336 Phone phone = getPhone(subId);
7337 if (phone == null) {
7338 return false;
7339 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007340
Jack Yue37dd262022-12-16 11:53:37 -08007341 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007342 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007343 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08007344 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007345
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007346 final long identity = Binder.clearCallingIdentity();
7347 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007348 Boolean success = (Boolean) sendRequest(
7349 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
7350 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
7351
7352 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
7353 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007354 } finally {
7355 Binder.restoreCallingIdentity(identity);
7356 }
7357 }
7358
7359 /**
Miaoa84611c2019-03-15 09:21:10 +08007360 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08007361 *
Miaoa84611c2019-03-15 09:21:10 +08007362 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07007363 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08007364 * @hide
7365 */
7366 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08007367 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007368 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007369
7370 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7371 PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber");
7372
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007373 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08007374 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007375 try {
Miaoa84611c2019-03-15 09:21:10 +08007376 if (phone != null) {
7377 return phone.hasMatchedTetherApnSetting();
7378 } else {
7379 return false;
7380 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007381 } finally {
7382 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007383 }
Junda Liu475951f2014-11-07 16:45:03 -08007384 }
7385
7386 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007387 * Get the user enabled state of Mobile Data.
7388 *
7389 * TODO: remove and use isUserDataEnabled.
7390 * This can't be removed now because some vendor codes
7391 * calls through ITelephony directly while they should
7392 * use TelephonyManager.
7393 *
7394 * @return true on enabled
7395 */
7396 @Override
7397 public boolean getDataEnabled(int subId) {
7398 return isUserDataEnabled(subId);
7399 }
7400
7401 /**
7402 * Get whether mobile data is enabled per user setting.
7403 *
7404 * There are other factors deciding whether mobile data is actually enabled, but they are
7405 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007406 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007407 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7408 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007409 *
7410 * @return {@code true} if data is enabled else {@code false}
7411 */
7412 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007413 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007414 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007415 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007416 try {
7417 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7418 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007419 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007420 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7421 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007422 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007423 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007424 mApp, subId, functionName);
7425
Robert Greenwalt646120a2014-05-23 11:54:03 -07007426 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007427
7428 final long identity = Binder.clearCallingIdentity();
7429 try {
Jack Yu285100e2022-12-02 22:48:35 -08007430 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007431 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7432 Phone phone = PhoneFactory.getPhone(phoneId);
7433 if (phone != null) {
7434 boolean retVal = phone.isUserDataEnabled();
7435 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7436 return retVal;
7437 } else {
7438 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7439 return false;
7440 }
7441 } finally {
7442 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007443 }
7444 }
7445
7446 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007447 * Checks if the device is capable of mobile data by considering whether whether the
7448 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7449 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007450 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007451 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007452 */
7453 @Override
7454 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007455 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007456 try {
7457 try {
7458 mApp.enforceCallingOrSelfPermission(
7459 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007460 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007461 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007462 try {
7463 mApp.enforceCallingOrSelfPermission(
7464 android.Manifest.permission.READ_PHONE_STATE,
7465 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007466 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007467 mApp.enforceCallingOrSelfPermission(
7468 permission.READ_BASIC_PHONE_STATE, functionName);
7469 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007470 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007471 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007472 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007473 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007474
joonhunshin4ac60942023-11-15 15:23:39 +00007475 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7476 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled");
7477
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007478 final long identity = Binder.clearCallingIdentity();
7479 try {
Jack Yu285100e2022-12-02 22:48:35 -08007480 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007481 Phone phone = PhoneFactory.getPhone(phoneId);
7482 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007483 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007484 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007485 return retVal;
7486 } else {
7487 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7488 return false;
7489 }
7490 } finally {
7491 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007492 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007493 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007494
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007495 /**
7496 * Check if data is enabled for a specific reason
7497 * @param subId Subscription index
7498 * @param reason the reason the data enable change is taking place
7499 * @return {@code true} if the overall data is enabled; {@code false} if not.
7500 */
7501 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007502 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007503 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007504 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007505 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007506 try {
7507 mApp.enforceCallingOrSelfPermission(
7508 android.Manifest.permission.ACCESS_NETWORK_STATE,
7509 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007510 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007511 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7512 functionName);
7513 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007514 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007515 try {
7516 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007517 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007518 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007519 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007520 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007521 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007522 }
7523
joonhunshin4ac60942023-11-15 15:23:39 +00007524 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7525 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007526
7527 final long identity = Binder.clearCallingIdentity();
7528 try {
Jack Yu285100e2022-12-02 22:48:35 -08007529 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007530 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007531 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007532 + " reason=" + reason);
7533 }
7534 Phone phone = PhoneFactory.getPhone(phoneId);
7535 if (phone != null) {
7536 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007537 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007538 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007539 return retVal;
7540 } else {
7541 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007542 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007543 + subId + " retVal=false");
7544 }
7545 return false;
7546 }
7547 } finally {
7548 Binder.restoreCallingIdentity(identity);
7549 }
7550 }
7551
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007552 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007553 public int getCarrierPrivilegeStatus(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00007554 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7555 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus");
7556
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007557 // No permission needed; this only lets the caller inspect their own status.
7558 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007559 }
Junda Liu29340342014-07-10 15:23:27 -07007560
7561 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007562 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007563 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
joonhunshin4ac60942023-11-15 15:23:39 +00007564
7565 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7566 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatusForUid");
7567
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007568 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7569 }
7570
7571 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7572 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007573 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007574 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007575 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7576 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007577 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7578 if (cpt == null) {
7579 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007580 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7581 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007582 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007583 }
7584
7585 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007586 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007587 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
joonhunshin4ac60942023-11-15 15:23:39 +00007588
7589 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7590 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage");
7591
chen xuf7e9fe82019-05-09 19:31:02 -07007592 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007593 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007594 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007595 Phone phone = getPhone(subId);
7596 if (phone == null) {
7597 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7598 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7599 }
7600 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7601 if (cpt == null) {
7602 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007603 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7604 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007605 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007606 }
7607
7608 @Override
7609 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007610 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007611
7612 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7613 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7614 "checkCarrierPrivilegesForPackageAnyPhone");
7615
Rambo Wange7209ce2022-02-23 13:41:02 -08007616 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7617 }
7618
7619 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007620 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007621 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007622 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007623 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007624 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7625 Phone phone = PhoneFactory.getPhone(phoneId);
7626 if (phone == null) {
7627 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007628 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007629 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7630 if (cpt == null) {
7631 continue;
7632 }
7633 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007634 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7635 break;
7636 }
7637 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007638 return result;
Junda Liu29340342014-07-10 15:23:27 -07007639 }
Derek Tan89e89d42014-07-08 17:00:10 -07007640
7641 @Override
Junda Liue64de782015-04-16 17:19:16 -07007642 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007643 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007644
7645 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7646 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7647 "getCarrierPackageNamesForIntentAndPhone");
7648
Rambo Wang8a247eb2022-02-08 21:11:18 +00007649 Phone phone = PhoneFactory.getPhone(phoneId);
7650 if (phone == null) {
7651 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007652 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007653 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7654 if (cpt == null) {
7655 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007656 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007657 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007658 }
7659
Amith Yamasani6e118872016-02-19 12:53:51 -08007660 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007661 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007662 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007663 Phone phone = PhoneFactory.getPhone(phoneId);
7664 if (phone == null) {
7665 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007666 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007667 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7668 if (cpt == null) {
7669 return Collections.emptyList();
7670 }
7671 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007672 }
7673
chen xuf7e9fe82019-05-09 19:31:02 -07007674 @Override
7675 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007676 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
joonhunshin4ac60942023-11-15 15:23:39 +00007677
7678 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7679 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7680 "getPackagesWithCarrierPrivilegesForAllPhones");
7681
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007682 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007683 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007684 try {
7685 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7686 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7687 }
7688 } finally {
7689 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007690 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007691 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007692 }
7693
Rambo Wang6812ffb2022-03-15 16:54:17 -07007694 @Override
7695 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7696 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7697
joonhunshin4ac60942023-11-15 15:23:39 +00007698 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7699 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7700 "getCarrierServicePackageNameForLogicalSlot");
7701
Rambo Wang6812ffb2022-03-15 16:54:17 -07007702 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7703 if (phone == null) {
7704 return null;
7705 }
7706 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7707 if (cpt == null) {
7708 return null;
7709 }
7710 return cpt.getCarrierServicePackageName();
7711 }
7712
Wink Savilleb564aae2014-10-23 10:18:09 -07007713 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007714 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007715 UiccPort port = phone == null ? null : phone.getUiccPort();
7716 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007717 return null;
7718 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007719 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007720 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007721 return null;
7722 }
7723 return iccId;
7724 }
7725
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007726 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007727 public void setCallComposerStatus(int subId, int status) {
7728 enforceModifyPermission();
7729
joonhunshin4ac60942023-11-15 15:23:39 +00007730 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7731 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus");
7732
Shuo Qiane4e11672020-12-15 22:15:33 -08007733 final long identity = Binder.clearCallingIdentity();
7734 try {
7735 Phone phone = getPhone(subId);
7736 if (phone != null) {
7737 Phone defaultPhone = phone.getImsPhone();
7738 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7739 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7740 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007741 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7742 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007743 }
7744 }
Shuo Qian284ae752020-12-22 19:10:14 -08007745 } catch (ImsException e) {
7746 throw new ServiceSpecificException(e.getCode());
7747 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007748 Binder.restoreCallingIdentity(identity);
7749 }
7750 }
7751
7752 @Override
7753 public int getCallComposerStatus(int subId) {
7754 enforceReadPrivilegedPermission("getCallComposerStatus");
7755
joonhunshin4ac60942023-11-15 15:23:39 +00007756 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7757 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus");
7758
Shuo Qiane4e11672020-12-15 22:15:33 -08007759 final long identity = Binder.clearCallingIdentity();
7760 try {
7761 Phone phone = getPhone(subId);
7762 if (phone != null) {
7763 Phone defaultPhone = phone.getImsPhone();
7764 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7765 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7766 return imsPhone.getCallComposerStatus();
7767 }
7768 }
7769 } finally {
7770 Binder.restoreCallingIdentity(identity);
7771 }
7772 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7773 }
7774
7775 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007776 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7777 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007778 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007779 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007780
joonhunshin4ac60942023-11-15 15:23:39 +00007781 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7782 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7783 "setLine1NumberForDisplayForSubscriber");
7784
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007785 final long identity = Binder.clearCallingIdentity();
7786 try {
7787 final String iccId = getIccId(subId);
7788 final Phone phone = getPhone(subId);
7789 if (phone == null) {
7790 return false;
7791 }
7792 final String subscriberId = phone.getSubscriberId();
7793
7794 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007795 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007796 + subscriberId + " to " + number);
7797 }
7798
7799 if (TextUtils.isEmpty(iccId)) {
7800 return false;
7801 }
7802
7803 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7804
7805 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7806 if (alphaTag == null) {
7807 editor.remove(alphaTagPrefKey);
7808 } else {
7809 editor.putString(alphaTagPrefKey, alphaTag);
7810 }
7811
7812 // Record both the line number and IMSI for this ICCID, since we need to
7813 // track all merged IMSIs based on line number
7814 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7815 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7816 if (number == null) {
7817 editor.remove(numberPrefKey);
7818 editor.remove(subscriberPrefKey);
7819 } else {
7820 editor.putString(numberPrefKey, number);
7821 editor.putString(subscriberPrefKey, subscriberId);
7822 }
7823
7824 editor.commit();
7825 return true;
7826 } finally {
7827 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007828 }
Derek Tan7226c842014-07-02 17:42:23 -07007829 }
7830
7831 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007832 public String getLine1NumberForDisplay(int subId, String callingPackage,
7833 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007834 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007835 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007836 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007837 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007838 return null;
7839 }
Derek Tan97ebb422014-09-05 16:55:38 -07007840
joonhunshin4ac60942023-11-15 15:23:39 +00007841 enforceTelephonyFeatureWithException(callingPackage,
7842 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay");
7843
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007844 final long identity = Binder.clearCallingIdentity();
7845 try {
7846 String iccId = getIccId(subId);
7847 if (iccId != null) {
7848 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7849 if (DBG_MERGE) {
7850 log("getLine1NumberForDisplay returning "
7851 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7852 }
7853 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007854 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007855 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7856 return null;
7857 } finally {
7858 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007859 }
Derek Tan7226c842014-07-02 17:42:23 -07007860 }
7861
7862 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007863 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7864 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007865 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007866 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007867 return null;
7868 }
Derek Tan97ebb422014-09-05 16:55:38 -07007869
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007870 final long identity = Binder.clearCallingIdentity();
7871 try {
7872 String iccId = getIccId(subId);
7873 if (iccId != null) {
7874 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7875 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7876 }
7877 return null;
7878 } finally {
7879 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007880 }
Derek Tan7226c842014-07-02 17:42:23 -07007881 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007882
7883 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007884 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7885 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007886 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7887 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007888 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007889 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007890 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007891 return null;
7892 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007893
Jordan Liub49b04b2019-05-06 14:45:15 -07007894 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7895 // the process, where TelephonyManager was instantiated.
7896 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007897 final long identity = Binder.clearCallingIdentity();
7898 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007899 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007900 final TelephonyManager tele = TelephonyManager.from(context);
7901 final SubscriptionManager sub = SubscriptionManager.from(context);
7902
7903 // Figure out what subscribers are currently active
7904 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007905
Jordan Liub49b04b2019-05-06 14:45:15 -07007906 // Only consider subs which match the current subId
7907 // This logic can be simplified. See b/131189269 for progress.
7908 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007909 activeSubscriberIds.add(tele.getSubscriberId(subId));
7910 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007911
7912 // First pass, find a number override for an active subscriber
7913 String mergeNumber = null;
7914 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7915 for (String key : prefs.keySet()) {
7916 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7917 final String subscriberId = (String) prefs.get(key);
7918 if (activeSubscriberIds.contains(subscriberId)) {
7919 final String iccId = key.substring(
7920 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7921 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7922 mergeNumber = (String) prefs.get(numberKey);
7923 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007924 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007925 + " for active subscriber " + subscriberId);
7926 }
7927 if (!TextUtils.isEmpty(mergeNumber)) {
7928 break;
7929 }
7930 }
7931 }
7932 }
7933
7934 // Shortcut when no active merged subscribers
7935 if (TextUtils.isEmpty(mergeNumber)) {
7936 return null;
7937 }
7938
7939 // Second pass, find all subscribers under that line override
7940 final ArraySet<String> result = new ArraySet<>();
7941 for (String key : prefs.keySet()) {
7942 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7943 final String number = (String) prefs.get(key);
7944 if (mergeNumber.equals(number)) {
7945 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7946 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7947 final String subscriberId = (String) prefs.get(subscriberKey);
7948 if (!TextUtils.isEmpty(subscriberId)) {
7949 result.add(subscriberId);
7950 }
7951 }
7952 }
7953 }
7954
7955 final String[] resultArray = result.toArray(new String[result.size()]);
7956 Arrays.sort(resultArray);
7957 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007958 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007959 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7960 }
7961 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007962 } finally {
7963 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007964 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007965 }
7966
7967 @Override
zoey chen38003472019-12-13 17:16:31 +08007968 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7969 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007970
joonhunshin4ac60942023-11-15 15:23:39 +00007971 enforceTelephonyFeatureWithException(callingPackage,
7972 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup");
7973
Malcolm Chen6ca97372019-07-01 16:28:21 -07007974 final long identity = Binder.clearCallingIdentity();
7975 try {
7976 final TelephonyManager telephonyManager = mApp.getSystemService(
7977 TelephonyManager.class);
7978 String subscriberId = telephonyManager.getSubscriberId(subId);
7979 if (subscriberId == null) {
7980 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007981 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007982 + subId);
7983 }
7984 return null;
7985 }
7986
Jack Yu3beaf9d2023-04-14 09:17:27 -07007987 final SubscriptionInfo info = getSubscriptionManagerService()
7988 .getSubscriptionInfo(subId);
7989 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07007990 // If it doesn't belong to any group, return just subscriberId of itself.
7991 if (groupUuid == null) {
7992 return new String[]{subscriberId};
7993 }
7994
7995 // Get all subscriberIds from the group.
7996 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07007997 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
7998 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7999 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07008000 for (SubscriptionInfo subInfo : groupInfos) {
8001 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
8002 if (subscriberId != null) {
8003 mergedSubscriberIds.add(subscriberId);
8004 }
8005 }
8006
8007 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
8008 } finally {
8009 Binder.restoreCallingIdentity(identity);
8010
8011 }
8012 }
8013
8014 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008015 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008016 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08008017 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008018
joonhunshin4ac60942023-11-15 15:23:39 +00008019 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8020 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride");
8021
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008022 final long identity = Binder.clearCallingIdentity();
8023 try {
8024 final Phone phone = getPhone(subId);
8025 return phone == null ? false : phone.setOperatorBrandOverride(brand);
8026 } finally {
8027 Binder.restoreCallingIdentity(identity);
8028 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07008029 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05008030
8031 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008032 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008033 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
8034 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008035 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
8036 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008037
8038 final long identity = Binder.clearCallingIdentity();
8039 try {
8040 final Phone phone = getPhone(subId);
8041 if (phone == null) {
8042 return false;
8043 }
8044 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
8045 cdmaNonRoamingList);
8046 } finally {
8047 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008048 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008049 }
8050
8051 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07008052 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008053 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08008054 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008055 if (phone == null) {
8056 return raf;
8057 }
8058
Shuo Qiandee53402020-05-29 14:08:15 -07008059 try {
8060 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008061 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07008062 mApp, phone.getSubId(), "getRadioAccessFamily");
8063 } catch (SecurityException e) {
8064 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
8065 throw e;
8066 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008067
joonhunshin4ac60942023-11-15 15:23:39 +00008068 enforceTelephonyFeatureWithException(callingPackage,
8069 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily");
8070
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008071 final long identity = Binder.clearCallingIdentity();
8072 try {
chen xub97461a2018-10-26 14:17:57 -07008073 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008074 } finally {
8075 Binder.restoreCallingIdentity(identity);
8076 }
chen xub97461a2018-10-26 14:17:57 -07008077 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07008078 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008079
8080 @Override
Hall Liu82694d52020-12-11 18:22:04 -08008081 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08008082 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08008083 try {
8084 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
8085 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008086 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008087 }
8088 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008089 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008090 }
joonhunshin4ac60942023-11-15 15:23:39 +00008091
8092 enforceTelephonyFeatureWithException(callingPackage,
8093 PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture");
8094
Hall Liu82694d52020-12-11 18:22:04 -08008095 RoleManager rm = mApp.getSystemService(RoleManager.class);
8096 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
8097 if (!dialerRoleHolders.contains(callingPackage)) {
8098 throw new SecurityException("App must be the dialer role holder to"
8099 + " upload a call composer pic");
8100 }
8101
8102 Executors.newSingleThreadExecutor().execute(() -> {
8103 ByteArrayOutputStream output = new ByteArrayOutputStream(
8104 (int) TelephonyManager.getMaximumCallComposerPictureSize());
8105 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
8106 boolean readUntilEnd = false;
8107 int totalBytesRead = 0;
8108 byte[] buffer = new byte[16 * 1024];
8109 while (true) {
8110 int numRead;
8111 try {
8112 numRead = input.read(buffer);
8113 } catch (IOException e) {
8114 try {
8115 fd.checkError();
8116 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
8117 null);
8118 } catch (IOException e1) {
8119 // This means that the other side closed explicitly with an error. If this
8120 // happens, log and ignore.
8121 loge("Remote end of call composer picture pipe closed: " + e1);
8122 }
8123 break;
8124 }
8125 if (numRead == -1) {
8126 readUntilEnd = true;
8127 break;
8128 }
8129 totalBytesRead += numRead;
8130 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
8131 loge("Too many bytes read for call composer picture: " + totalBytesRead);
8132 try {
8133 input.close();
8134 } catch (IOException e) {
8135 // ignore
8136 }
8137 break;
8138 }
8139 output.write(buffer, 0, numRead);
8140 }
8141 // Generally, the remote end will close the file descriptors. The only case where we
8142 // close is above, where the picture size is too big.
8143
8144 try {
8145 fd.checkError();
8146 } catch (IOException e) {
8147 loge("Remote end for call composer closed with an error: " + e);
8148 return;
8149 }
8150
Hall Liuaa4211e2021-01-20 15:43:39 -08008151 if (!readUntilEnd) {
8152 loge("Did not finish reading entire image; aborting");
8153 return;
8154 }
Hall Liu82694d52020-12-11 18:22:04 -08008155
Hall Liuaa4211e2021-01-20 15:43:39 -08008156 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
8157 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
8158 new CallComposerPictureTransfer.Factory() {},
8159 imageData,
8160 (result) -> {
8161 if (result.first != null) {
8162 ParcelUuid parcelUuid = new ParcelUuid(result.first);
8163 Bundle outputResult = new Bundle();
8164 outputResult.putParcelable(
8165 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
8166 callback.send(TelephonyManager.CallComposerException.SUCCESS,
8167 outputResult);
8168 } else {
8169 callback.send(result.second, null);
8170 }
8171 }
8172 );
Hall Liu82694d52020-12-11 18:22:04 -08008173 });
8174 }
8175
8176 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07008177 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008178 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07008179 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008180
joonhunshin4ac60942023-11-15 15:23:39 +00008181 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8182 PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling");
8183
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008184 final long identity = Binder.clearCallingIdentity();
8185 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008186 ImsManager.getInstance(defaultPhone.getContext(),
8187 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008188 } finally {
8189 Binder.restoreCallingIdentity(identity);
8190 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008191 }
8192
8193 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008194 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008195 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008196 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
8197 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00008198 return false;
8199 }
Svet Ganovb320e182015-04-16 12:30:10 -07008200
joonhunshin4ac60942023-11-15 15:23:39 +00008201 enforceTelephonyFeatureWithException(callingPackage,
8202 PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled");
8203
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008204 final long identity = Binder.clearCallingIdentity();
8205 try {
8206 // Check the user preference and the system-level IMS setting. Even if the user has
8207 // enabled video calling, if IMS is disabled we aren't able to support video calling.
8208 // In the long run, we may instead need to check if there exists a connection service
8209 // which can support video calling.
8210 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008211 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008212 return imsManager.isVtEnabledByPlatform()
8213 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
8214 && imsManager.isVtEnabledByUser();
8215 } finally {
8216 Binder.restoreCallingIdentity(identity);
8217 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008218 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06008219
Andrew Leea1239f22015-03-02 17:44:07 -08008220 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008221 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
8222 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008223 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008224 mApp, subId, callingPackage, callingFeatureId,
8225 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008226 return false;
8227 }
8228
joonhunshin4ac60942023-11-15 15:23:39 +00008229 enforceTelephonyFeatureWithException(callingPackage,
8230 PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength");
8231
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008232 final long identity = Binder.clearCallingIdentity();
8233 try {
8234 CarrierConfigManager configManager =
8235 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008236 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008237 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
8238 } finally {
8239 Binder.restoreCallingIdentity(identity);
8240 }
Andrew Leea1239f22015-03-02 17:44:07 -08008241 }
8242
8243 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008244 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008245 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008246 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008247 return false;
8248 }
8249
joonhunshin4ac60942023-11-15 15:23:39 +00008250 enforceTelephonyFeatureWithException(callingPackage,
8251 PackageManager.FEATURE_TELEPHONY, "isWorldPhone");
8252
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008253 final long identity = Binder.clearCallingIdentity();
8254 try {
8255 CarrierConfigManager configManager =
8256 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008257 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008258 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
8259 } finally {
8260 Binder.restoreCallingIdentity(identity);
8261 }
Andrew Leea1239f22015-03-02 17:44:07 -08008262 }
8263
Andrew Lee9431b832015-03-09 18:46:45 -07008264 @Override
8265 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008266 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08008267 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07008268 }
8269
8270 @Override
8271 public boolean isHearingAidCompatibilitySupported() {
joonhunshin4ac60942023-11-15 15:23:39 +00008272 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8273 PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported");
8274
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008275 final long identity = Binder.clearCallingIdentity();
8276 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008277 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008278 } finally {
8279 Binder.restoreCallingIdentity(identity);
8280 }
Andrew Lee9431b832015-03-09 18:46:45 -07008281 }
8282
Hall Liuf6668912018-10-31 17:05:23 -07008283 /**
8284 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
8285 * support for the feature and device firmware support.
8286 *
8287 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
8288 */
8289 @Override
8290 public boolean isRttSupported(int subscriptionId) {
joonhunshin4ac60942023-11-15 15:23:39 +00008291 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8292 PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported");
8293
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008294 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008295 final Phone phone = getPhone(subscriptionId);
8296 if (phone == null) {
8297 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
8298 return false;
8299 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008300 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008301 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008302 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
joonhunshin4ac60942023-11-15 15:23:39 +00008303 boolean isDeviceSupported = (phone.getContext().getResources() != null)
8304 ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt)
8305 : false;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008306 return isCarrierSupported && isDeviceSupported;
8307 } finally {
8308 Binder.restoreCallingIdentity(identity);
8309 }
Hall Liu98187582018-01-22 19:15:32 -08008310 }
8311
Hall Liuf6668912018-10-31 17:05:23 -07008312 /**
Hall Liuf2daa022019-07-23 18:39:00 -07008313 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
8314 * RTT setting, will return true if the device and carrier both support RTT.
8315 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07008316 */
8317 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008318 final long identity = Binder.clearCallingIdentity();
8319 try {
joonhunshin4ac60942023-11-15 15:23:39 +00008320 if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) {
8321 if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
8322 return false;
8323 }
8324 }
8325
Hall Liu5bab75c2019-12-11 23:58:20 +00008326 boolean isRttSupported = isRttSupported(subscriptionId);
8327 boolean isUserRttSettingOn = Settings.Secure.getInt(
8328 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
8329 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
8330 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
8331 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008332 } finally {
8333 Binder.restoreCallingIdentity(identity);
8334 }
Hall Liu3ad5f012018-04-06 16:23:39 -07008335 }
8336
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008337 @Deprecated
8338 @Override
8339 public String getDeviceId(String callingPackage) {
8340 return getDeviceIdWithFeature(callingPackage, null);
8341 }
8342
Sanket Padawe7310cc72015-01-14 09:53:20 -08008343 /**
8344 * Returns the unique device ID of phone, for example, the IMEI for
8345 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
8346 *
8347 * <p>Requires Permission:
8348 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
8349 */
8350 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008351 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07008352 try {
8353 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
8354 } catch (SecurityException se) {
8355 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
8356 throw new SecurityException("Package " + callingPackage + " does not belong to "
8357 + Binder.getCallingUid());
8358 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008359 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008360 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008361 return null;
8362 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008363 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008364 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008365 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008366 return null;
8367 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008368
8369 final long identity = Binder.clearCallingIdentity();
8370 try {
8371 return phone.getDeviceId();
8372 } finally {
8373 Binder.restoreCallingIdentity(identity);
8374 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008375 }
8376
Ping Sunc67b7c22016-03-02 19:16:45 +08008377 /**
8378 * {@hide}
8379 * Returns the IMS Registration Status on a particular subid
8380 *
8381 * @param subId
8382 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008383 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008384 Phone phone = getPhone(subId);
8385 if (phone != null) {
8386 return phone.isImsRegistered();
8387 } else {
8388 return false;
8389 }
8390 }
8391
Santos Cordon7a1885b2015-02-03 11:15:19 -08008392 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008393 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008394 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008395 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008396 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008397 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8398 }
8399 final long identity = Binder.clearCallingIdentity();
8400 try {
8401 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8402 } finally {
8403 Binder.restoreCallingIdentity(identity);
8404 }
8405 }
8406
8407 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008408 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008409 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008410 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008411 mApp,
8412 subscriptionId,
8413 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
8414 + subscriptionId);
joonhunshin4ac60942023-11-15 15:23:39 +00008415
8416 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8417 PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId");
8418
Tyler Gunnf70ed162019-04-03 15:28:53 -07008419 final long identity = Binder.clearCallingIdentity();
8420 try {
8421 Phone phone = getPhone(subscriptionId);
8422 if (phone == null) {
8423 return null;
8424 }
8425 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8426 } finally {
8427 Binder.restoreCallingIdentity(identity);
8428 }
8429 }
8430
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008431 /**
8432 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008433 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008434 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008435 final long identity = Binder.clearCallingIdentity();
8436 try {
8437 Phone phone = getPhone(subId);
8438 if (phone != null) {
8439 return phone.isWifiCallingEnabled();
8440 } else {
8441 return false;
8442 }
8443 } finally {
8444 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008445 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008446 }
8447
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008448 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008449 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008450 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008451 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008452 final long identity = Binder.clearCallingIdentity();
8453 try {
8454 Phone phone = getPhone(subId);
8455 if (phone != null) {
8456 return phone.isVideoEnabled();
8457 } else {
8458 return false;
8459 }
8460 } finally {
8461 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008462 }
8463 }
8464
8465 /**
8466 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8467 * defined in {@link ImsRegistrationImplBase}.
8468 */
8469 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008470 final long identity = Binder.clearCallingIdentity();
8471 try {
8472 Phone phone = getPhone(subId);
8473 if (phone != null) {
8474 return phone.getImsRegistrationTech();
8475 } else {
8476 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8477 }
8478 } finally {
8479 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008480 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008481 }
8482
Stuart Scott8eef64f2015-04-08 15:13:54 -07008483 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008484 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008485 enforceSettingsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008486
8487 enforceTelephonyFeatureWithException(callingPackage,
8488 PackageManager.FEATURE_TELEPHONY, "factoryReset");
8489
Stuart Scott981d8582015-04-21 14:09:50 -07008490 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8491 return;
8492 }
Kai Shif70f46f2021-03-03 13:59:46 -08008493 Phone defaultPhone = getDefaultPhone();
8494 if (defaultPhone != null) {
8495 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8496 mApp, getDefaultPhone().getSubId(), "factoryReset");
8497 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008498 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008499
Svet Ganovcc087f82015-05-12 20:35:54 -07008500 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008501 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8502 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008503 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008504 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008505 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008506 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008507 cleanUpAllowedNetworkTypes(phone, subId);
Rambo Wang71f6aa62024-02-23 20:16:22 +00008508 setDataRoamingEnabled(subId, phone == null ? false
8509 : phone.getDataSettingsManager().isDefaultDataRoamingEnabled());
Jordan Liu857e73a2021-03-05 16:24:04 -08008510 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008511 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008512 // There has been issues when Sms raw table somehow stores orphan
8513 // fragments. They lead to garbled message when new fragments come
8514 // in and combined with those stale ones. In case this happens again,
8515 // user can reset all network settings which will clean up this table.
8516 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008517 // Clean up IMS settings as well here.
8518 int slotId = getSlotIndex(subId);
8519 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
8520 ImsManager.getInstance(mApp, slotId).factoryReset();
8521 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008522
Kai Shif70f46f2021-03-03 13:59:46 -08008523 if (defaultPhone == null) {
8524 return;
8525 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008526 // Erase modem config if erase modem on network setting is enabled.
8527 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8528 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8529 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008530 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008531 }
Kai Shif70f46f2021-03-03 13:59:46 -08008532
8533 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008534 } finally {
8535 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008536 }
8537 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008538
SongFerngWangfd89b102021-05-27 22:44:54 +08008539 @VisibleForTesting
8540 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8541 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8542 return;
8543 }
8544 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8545 RILConstants.PREFERRED_NETWORK_MODE);
8546 SubscriptionManager.setSubscriptionProperty(subId,
8547 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8548 "user=" + defaultNetworkType);
8549 phone.loadAllowedNetworksFromSubscriptionDatabase();
8550 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8551 defaultNetworkType, null);
8552 }
8553
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008554 private void cleanUpSmsRawTable(Context context) {
8555 ContentResolver resolver = context.getContentResolver();
8556 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8557 resolver.delete(uri, null, null);
8558 }
8559
Narayan Kamath1c496c22015-04-16 14:40:19 +01008560 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008561 public String getSimLocaleForSubscriber(int subId) {
8562 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
joonhunshin4ac60942023-11-15 15:23:39 +00008563
8564 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8565 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber");
8566
chen xu5d3637b2019-01-21 23:31:38 -08008567 final Phone phone = getPhone(subId);
8568 if (phone == null) {
8569 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008570 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008571 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008572 final long identity = Binder.clearCallingIdentity();
8573 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008574 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
8575 phone.getContext().getOpPackageName(),
8576 phone.getContext().getAttributionTag());
8577 if (info == null) {
8578 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8579 return null;
chen xu6291c472019-02-04 12:55:53 -08008580 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008581 // Try and fetch the locale from the carrier properties or from the SIM language
8582 // preferences (EF-PL and EF-LI)...
8583 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008584 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008585 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8586 if (localeFromDefaultSim != null) {
8587 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8588 if (DBG) log("Using locale from subId: " + subId + " locale: "
8589 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008590 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008591 } else {
8592 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008593 }
8594 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008595
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008596 // The SIM language preferences only store a language (e.g. fr = French), not an
8597 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8598 // the SIM and carrier preferences does not include a country we add the country
8599 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008600 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008601 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008602 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008603 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008604 }
8605
8606 if (DBG) log("No locale found - returning null");
8607 return null;
8608 } finally {
8609 Binder.restoreCallingIdentity(identity);
8610 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008611 }
8612
tom hsu0b59d292022-09-29 23:49:21 +08008613 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008614 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008615 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008616 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008617 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008618 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8619 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008620 Locale.forLanguageTag(localeTag).getCountry())) {
8621 return localeTag;
8622 }
8623 }
8624 return inputLocale.toLanguageTag();
8625 }
8626
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008627 /**
8628 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8629 */
8630 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008631 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Ling Ma9fa67412023-11-13 14:13:19 -08008632 mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/);
Narayan Kamath1c496c22015-04-16 14:40:19 +01008633 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008634
Gary Jian3aa9a762022-01-24 16:41:19 +08008635 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8636 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008637
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008638 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008639 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8640 * representing the state of the modem.
8641 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008642 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8643 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008644 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008645 */
8646 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008647 public void requestModemActivityInfo(ResultReceiver result) {
8648 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008649
8650 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8651 PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo");
8652
vagdeviaf9a5b92018-08-15 16:01:53 -07008653 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008654
8655 final long identity = Binder.clearCallingIdentity();
8656 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008657 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008658 } finally {
8659 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008660 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008661 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008662
Gary Jian76280a42022-12-07 16:18:33 +08008663 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008664 // less than total activity duration.
8665 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8666 if (info == null) {
8667 return false;
8668 }
8669 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008670 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008671 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8672
Hall Liu49656c02020-10-09 19:00:11 -07008673 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8674
Siddharth Rayb8114062018-06-17 15:02:38 -07008675 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008676 && (info.getSleepTimeMillis() <= activityDurationMs)
8677 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008678 }
8679
Gary Jian3aa9a762022-01-24 16:41:19 +08008680 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8681 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8682 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8683 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8684
8685 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8686 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8687 }
8688
8689 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8690 mLastModemActivityInfo.setReceiveTimeMillis(
8691 rat,
8692 freq,
8693 info.getReceiveTimeMillis(rat, freq)
8694 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8695 }
8696
8697 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8698 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8699 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8700 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8701
8702 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8703 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8704 }
8705 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8706 mLastModemActivityInfo.setReceiveTimeMillis(
8707 rat,
8708 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8709 }
8710
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008711 /**
8712 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8713 * @param info recent ModemActivityInfo
8714 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008715 private void mergeModemActivityInfo(ModemActivityInfo info) {
8716 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008717 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008718 boolean matched;
8719 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8720 matched = false;
8721 int rat = info.getSpecificInfoRat(i);
8722 int freq = info.getSpecificInfoFrequencyRange(i);
8723 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8724 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8725 //if it already exists
8726 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8727 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8728 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8729 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8730 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8731 updateLastModemActivityInfo(info, rat, freq);
8732 matched = true;
8733 }
8734 } else {
8735 updateLastModemActivityInfo(info, rat);
8736 matched = true;
8737 }
8738 }
8739 }
8740
8741 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008742 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008743 new ActivityStatsTechSpecificInfo(
8744 rat,
8745 freq,
8746 info.getTransmitTimeMillis(rat, freq),
8747 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008748 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008749 }
8750 }
8751 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8752 mLastModemActivitySpecificInfo =
8753 new ActivityStatsTechSpecificInfo[merged.size()];
8754 merged.toArray(mLastModemActivitySpecificInfo);
8755
8756 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8757 mLastModemActivityInfo.setSleepTimeMillis(
8758 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008759 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008760 mLastModemActivityInfo.setIdleTimeMillis(
8761 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008762 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008763
8764 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008765 new ModemActivityInfo(
8766 mLastModemActivityInfo.getTimestampMillis(),
8767 mLastModemActivityInfo.getSleepTimeMillis(),
8768 mLastModemActivityInfo.getIdleTimeMillis(),
8769 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008770 }
8771
8772 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8773 ActivityStatsTechSpecificInfo[] info) {
8774 int infoSize = info.length;
8775 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8776 for (int i = 0; i < infoSize; i++) {
8777 ret[i] = new ActivityStatsTechSpecificInfo(
8778 info[i].getRat(), info[i].getFrequencyRange(),
8779 info[i].getTransmitTimeMillis(),
8780 (int) info[i].getReceiveTimeMillis());
8781 }
8782 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008783 }
8784
Jack Yu85bd38a2015-11-09 11:34:32 -08008785 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008786 * Returns the service state information on specified subscription.
8787 */
8788 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008789 public ServiceState getServiceStateForSubscriber(int subId,
8790 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8791 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008792 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008793 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008794 return null;
8795 }
8796
joonhunshin4ac60942023-11-15 15:23:39 +00008797 enforceTelephonyFeatureWithException(callingPackage,
8798 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber");
8799
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008800 boolean hasFinePermission = false;
8801 boolean hasCoarsePermission = false;
8802 if (!renounceFineLocationAccess) {
8803 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8804 LocationAccessPolicy.checkLocationPermission(mApp,
8805 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8806 .setCallingPackage(callingPackage)
8807 .setCallingFeatureId(callingFeatureId)
8808 .setCallingPid(Binder.getCallingPid())
8809 .setCallingUid(Binder.getCallingUid())
8810 .setMethod("getServiceStateForSubscriber")
8811 .setLogAsInfo(true)
8812 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8813 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8814 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8815 .build());
8816 hasFinePermission =
8817 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8818 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008819
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008820 if (!renounceCoarseLocationAccess) {
8821 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8822 LocationAccessPolicy.checkLocationPermission(mApp,
8823 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8824 .setCallingPackage(callingPackage)
8825 .setCallingFeatureId(callingFeatureId)
8826 .setCallingPid(Binder.getCallingPid())
8827 .setCallingUid(Binder.getCallingUid())
8828 .setMethod("getServiceStateForSubscriber")
8829 .setLogAsInfo(true)
8830 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8831 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8832 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8833 .build());
8834 hasCoarsePermission =
8835 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8836 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008837
Jack Yu479f40e2020-10-27 21:29:25 -07008838 final Phone phone = getPhone(subId);
8839 if (phone == null) {
8840 return null;
8841 }
8842
Jordan Liu0f2bc442020-11-18 16:47:37 -08008843 final long identity = Binder.clearCallingIdentity();
8844
Jack Yu479f40e2020-10-27 21:29:25 -07008845 boolean isCallingPackageDataService = phone.getDataServicePackages()
8846 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008847 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008848 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu3beaf9d2023-04-14 09:17:27 -07008849 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8850 .getSubscriptionInfoInternal(subId);
8851 if (subInfo == null || !subInfo.isActive()) {
8852 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8853 + "subId=" + subId);
8854 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008855 }
8856
Hall Liuf19c44f2018-11-27 14:38:17 -08008857 ServiceState ss = phone.getServiceState();
8858
8859 // Scrub out the location info in ServiceState depending on what level of access
8860 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008861 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008862 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8863 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008864 } finally {
8865 Binder.restoreCallingIdentity(identity);
8866 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008867 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008868
8869 /**
8870 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8871 *
8872 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8873 * voicemail ringtone.
8874 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8875 * PhoneAccount.
8876 */
8877 @Override
8878 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008879 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8880 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri");
8881
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008882 final long identity = Binder.clearCallingIdentity();
8883 try {
8884 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8885 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008886 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008887 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008888
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008889 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8890 } finally {
8891 Binder.restoreCallingIdentity(identity);
8892 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008893 }
8894
8895 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008896 * Sets the per-account voicemail ringtone.
8897 *
8898 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8899 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8900 *
8901 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8902 * voicemail ringtone.
8903 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8904 * PhoneAccount.
8905 */
8906 @Override
8907 public void setVoicemailRingtoneUri(String callingPackage,
8908 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008909 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008910 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008911 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8912 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008913 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8914 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8915 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008916 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008917
joonhunshin4ac60942023-11-15 15:23:39 +00008918 enforceTelephonyFeatureWithException(callingPackage,
8919 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri");
8920
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008921 final long identity = Binder.clearCallingIdentity();
8922 try {
8923 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8924 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008925 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008926 }
8927 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8928 } finally {
8929 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008930 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008931 }
8932
8933 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008934 * Returns whether vibration is set for voicemail notification in Phone settings.
8935 *
8936 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8937 * voicemail vibration setting.
8938 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8939 */
8940 @Override
8941 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008942 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8943 PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled");
8944
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008945 final long identity = Binder.clearCallingIdentity();
8946 try {
8947 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8948 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008949 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008950 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008951
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008952 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8953 } finally {
8954 Binder.restoreCallingIdentity(identity);
8955 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008956 }
8957
Youhan Wange64578a2016-05-02 15:32:42 -07008958 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008959 * Sets the per-account voicemail vibration.
8960 *
8961 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8962 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8963 *
8964 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8965 * voicemail vibration setting.
8966 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8967 * specific PhoneAccount.
8968 */
8969 @Override
8970 public void setVoicemailVibrationEnabled(String callingPackage,
8971 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008972 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008973 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008974 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8975 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008976 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8977 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8978 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008979 }
8980
joonhunshin4ac60942023-11-15 15:23:39 +00008981 enforceTelephonyFeatureWithException(callingPackage,
8982 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled");
8983
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008984 final long identity = Binder.clearCallingIdentity();
8985 try {
8986 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8987 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008988 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008989 }
8990 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8991 } finally {
8992 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008993 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008994 }
8995
8996 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008997 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8998 *
8999 * @throws SecurityException if the caller does not have the required permission
9000 */
arunvoddud7401012022-12-15 16:08:12 +00009001 @VisibleForTesting
9002 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07009003 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07009004 message);
Youhan Wange64578a2016-05-02 15:32:42 -07009005 }
9006
9007 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009008 * Make sure either called from same process as self (phone) or IPC caller has send SMS
9009 * permission.
9010 *
9011 * @throws SecurityException if the caller does not have the required permission
9012 */
9013 private void enforceSendSmsPermission() {
9014 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
9015 }
9016
9017 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00009018 * Make sure either called from same process as self (phone) or IPC caller has interact across
9019 * users permission.
9020 *
9021 * @throws SecurityException if the caller does not have the required permission
9022 */
9023 private void enforceInteractAcrossUsersPermission(String message) {
9024 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
9025 }
9026
9027 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009028 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009029 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009030 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009031 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009032 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009033 final long identity = Binder.clearCallingIdentity();
9034 try {
9035 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009036 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009037 if (componentName == null) {
9038 throw new SecurityException(
9039 "Caller not current active visual voicemail package[null]");
9040 }
9041 String vvmPackage = componentName.getPackageName();
9042 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00009043 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009044 }
9045 } finally {
9046 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009047 }
9048 }
9049
9050 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009051 * Return the application ID for the app type.
9052 *
9053 * @param subId the subscription ID that this request applies to.
9054 * @param appType the uicc app type.
9055 * @return Application ID for specificied app type, or null if no uicc.
9056 */
9057 @Override
9058 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009059 enforceReadPrivilegedPermission("getAidForAppType");
joonhunshin4ac60942023-11-15 15:23:39 +00009060
9061 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9062 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType");
9063
Youhan Wange64578a2016-05-02 15:32:42 -07009064 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009065
9066 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07009067 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009068 if (phone == null) {
9069 return null;
9070 }
9071 String aid = null;
9072 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009073 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009074 .getApplicationByType(appType).getAid();
9075 } catch (Exception e) {
9076 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
9077 }
9078 return aid;
9079 } finally {
9080 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07009081 }
Youhan Wange64578a2016-05-02 15:32:42 -07009082 }
9083
Youhan Wang4001d252016-05-11 10:29:41 -07009084 /**
9085 * Return the Electronic Serial Number.
9086 *
9087 * @param subId the subscription ID that this request applies to.
9088 * @return ESN or null if error.
9089 */
9090 @Override
9091 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009092 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07009093 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009094
9095 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07009096 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009097 if (phone == null) {
9098 return null;
9099 }
9100 String esn = null;
9101 try {
9102 esn = phone.getEsn();
9103 } catch (Exception e) {
9104 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
9105 }
9106 return esn;
9107 } finally {
9108 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07009109 }
Youhan Wang4001d252016-05-11 10:29:41 -07009110 }
9111
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009112 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009113 * Return the Preferred Roaming List Version.
9114 *
9115 * @param subId the subscription ID that this request applies to.
9116 * @return PRLVersion or null if error.
9117 */
9118 @Override
9119 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009120 enforceReadPrivilegedPermission("getCdmaPrlVersion");
joonhunshin4ac60942023-11-15 15:23:39 +00009121
9122 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9123 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion");
9124
Youhan Wang66ad5d72016-07-18 17:56:58 -07009125 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009126
9127 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009128 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009129 if (phone == null) {
9130 return null;
9131 }
9132 String cdmaPrlVersion = null;
9133 try {
9134 cdmaPrlVersion = phone.getCdmaPrlVersion();
9135 } catch (Exception e) {
9136 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9137 }
9138 return cdmaPrlVersion;
9139 } finally {
9140 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009141 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009142 }
9143
9144 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009145 * Get snapshot of Telephony histograms
9146 * @return List of Telephony histograms
9147 * @hide
9148 */
9149 @Override
9150 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009151 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9152 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009153
9154 final long identity = Binder.clearCallingIdentity();
9155 try {
9156 return RIL.getTelephonyRILTimingHistograms();
9157 } finally {
9158 Binder.restoreCallingIdentity(identity);
9159 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009160 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009161
9162 /**
9163 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009164 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9165 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009166 * Require system privileges. In the future we may add this to carrier APIs.
9167 *
Michele Berionne482f8202018-11-27 18:57:59 -08009168 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009169 */
9170 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009171 @TelephonyManager.SetCarrierRestrictionResult
9172 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009173 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009174
9175 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9176 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers");
9177
vagdeviaf9a5b92018-08-15 16:01:53 -07009178 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009179
Michele Berionne482f8202018-11-27 18:57:59 -08009180 if (carrierRestrictionRules == null) {
9181 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009182 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009183
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009184 final long identity = Binder.clearCallingIdentity();
9185 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009186 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009187 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009188 } finally {
9189 Binder.restoreCallingIdentity(identity);
9190 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009191 }
9192
9193 /**
9194 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009195 * Get the allowed carrier list and the excluded carrier list, including the priority between
9196 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009197 * Require system privileges. In the future we may add this to carrier APIs.
9198 *
Michele Berionne482f8202018-11-27 18:57:59 -08009199 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009200 */
9201 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009202 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009203 enforceReadPrivilegedPermission("getAllowedCarriers");
joonhunshin4ac60942023-11-15 15:23:39 +00009204
9205 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9206 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers");
9207
vagdeviaf9a5b92018-08-15 16:01:53 -07009208 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009209
9210 final long identity = Binder.clearCallingIdentity();
9211 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009212 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9213 if (response instanceof CarrierRestrictionRules) {
9214 return (CarrierRestrictionRules) response;
9215 }
9216 // Response is an Exception of some kind,
9217 // which is signalled to the user as a NULL retval
9218 return null;
9219 } catch (Exception e) {
9220 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9221 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009222 } finally {
9223 Binder.restoreCallingIdentity(identity);
9224 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009225 }
9226
fionaxu59545b42016-05-25 15:53:37 -07009227 /**
arunvoddud7401012022-12-15 16:08:12 +00009228 * Fetches the carrier restriction status of the device and sends the status to the caller
9229 * through the callback.
9230 *
9231 * @param callback The callback that will be used to send the result.
9232 * @throws SecurityException if the caller does not have the required permission/privileges or
9233 * the caller is not allowlisted.
9234 */
9235 @Override
9236 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
9237 enforceReadPermission("getCarrierRestrictionStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00009238
9239 enforceTelephonyFeatureWithException(packageName,
9240 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierRestrictionStatus");
9241
arunvoddud7401012022-12-15 16:08:12 +00009242 int carrierId = validateCallerAndGetCarrierId(packageName);
9243 if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) {
9244 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9245 throw new SecurityException("Not an authorized caller");
9246 }
9247 final long identity = Binder.clearCallingIdentity();
9248 try {
9249 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
9250 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId);
9251 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9252 } finally {
9253 Binder.restoreCallingIdentity(identity);
9254 }
9255 }
9256
arunvoddu567f2b42023-04-25 17:22:00 +00009257 @Override
9258 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
9259 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
9260 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9261 return allowListInfo.getShaIdList(pkgName, carrierId);
9262 }
9263
arunvoddud7401012022-12-15 16:08:12 +00009264 @VisibleForTesting
9265 public int validateCallerAndGetCarrierId(String packageName) {
9266 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9267 return allowListInfo.validateCallerAndGetCarrierId(packageName);
9268 }
9269
9270 /**
fionaxu59545b42016-05-25 15:53:37 -07009271 * Action set from carrier signalling broadcast receivers to enable/disable radio
9272 * @param subId the subscription ID that this action applies to.
9273 * @param enabled control enable or disable radio.
9274 * {@hide}
9275 */
9276 @Override
9277 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9278 enforceModifyPermission();
9279 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009280
9281 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009282 if (phone == null) {
9283 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9284 return;
9285 }
9286 try {
9287 phone.carrierActionSetRadioEnabled(enabled);
9288 } catch (Exception e) {
9289 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009290 } finally {
9291 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009292 }
9293 }
9294
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009295 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009296 * Enable or disable Voice over NR (VoNR)
9297 * @param subId the subscription ID that this action applies to.
9298 * @param enabled enable or disable VoNR.
9299 * @return operation result.
9300 */
9301 @Override
9302 public int setVoNrEnabled(int subId, boolean enabled) {
9303 enforceModifyPermission();
9304 final Phone phone = getPhone(subId);
9305
9306 final long identity = Binder.clearCallingIdentity();
9307 if (phone == null) {
9308 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9309 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9310 }
9311
9312 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9313 try {
9314 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9315 workSource);
9316 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009317
9318 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9319 if (DBG) {
9320 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9321 }
9322 SubscriptionManager.setSubscriptionProperty(
9323 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9324 (enabled ? "1" : "0"));
9325 }
9326
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009327 return result;
9328 } finally {
9329 Binder.restoreCallingIdentity(identity);
9330 }
9331 }
9332
9333 /**
9334 * Is voice over NR enabled
9335 * @return true if VoNR is enabled else false
9336 */
9337 @Override
9338 public boolean isVoNrEnabled(int subId) {
9339 enforceReadPrivilegedPermission("isVoNrEnabled");
9340 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9341 final long identity = Binder.clearCallingIdentity();
9342 try {
9343 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9344 null, subId, workSource);
9345 if (DBG) log("isVoNrEnabled: " + isEnabled);
9346 return isEnabled;
9347 } finally {
9348 Binder.restoreCallingIdentity(identity);
9349 }
9350 }
9351
9352 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009353 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9354 * network status based on which carrier apps could apply actions accordingly,
9355 * enable/disable default url handler for example.
9356 *
9357 * @param subId the subscription ID that this action applies to.
9358 * @param report control start/stop reporting the default network status.
9359 * {@hide}
9360 */
9361 @Override
9362 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9363 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009364
9365 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9366 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
9367 "carrierActionReportDefaultNetworkStatus");
9368
fionaxu8da9cb12017-05-23 15:02:46 -07009369 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009370
9371 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009372 if (phone == null) {
9373 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9374 return;
9375 }
9376 try {
9377 phone.carrierActionReportDefaultNetworkStatus(report);
9378 } catch (Exception e) {
9379 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009380 } finally {
9381 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009382 }
9383 }
9384
9385 /**
fionaxud9622282017-07-17 17:51:30 -07009386 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9387 * @param subId the subscription ID that this action applies to.
9388 * {@hide}
9389 */
9390 @Override
9391 public void carrierActionResetAll(int subId) {
9392 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009393
9394 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9395 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll");
9396
fionaxud9622282017-07-17 17:51:30 -07009397 final Phone phone = getPhone(subId);
9398 if (phone == null) {
9399 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9400 return;
9401 }
9402 try {
9403 phone.carrierActionResetAll();
9404 } catch (Exception e) {
9405 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9406 }
9407 }
9408
9409 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009410 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9411 * bug report is being generated.
9412 */
9413 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009414 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009415 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9416 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009417 writer.println("Permission Denial: can't dump Phone from pid="
9418 + Binder.getCallingPid()
9419 + ", uid=" + Binder.getCallingUid()
9420 + "without permission "
9421 + android.Manifest.permission.DUMP);
9422 return;
9423 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009424 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009425 }
Jack Yueb89b242016-06-22 13:27:47 -07009426
Brad Ebingerdac2f002018-04-03 15:17:52 -07009427 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009428 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9429 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9430 @NonNull String[] args) {
9431 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9432 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009433 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009434 }
9435
Jack Yueb89b242016-06-22 13:27:47 -07009436 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009437 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009438 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009439 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009440 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009441 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009442 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009443 */
9444 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009445 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009446 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009447 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9448 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9449 try {
9450 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009451 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009452 } catch (SecurityException se) {
9453 enforceModifyPermission();
9454 }
9455 } else {
9456 enforceModifyPermission();
9457 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009458
joonhunshin4ac60942023-11-15 15:23:39 +00009459 enforceTelephonyFeatureWithException(callingPackage,
9460 PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason");
9461
Nate Myren116695d2024-02-09 09:36:01 -08009462 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009463 final long identity = Binder.clearCallingIdentity();
9464 try {
Nate Myren116695d2024-02-09 09:36:01 -08009465 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
9466 && null != callingPackage && opEnableMobileDataByUser()) {
9467 mAppOps.noteOp(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER,
9468 callingUid, callingPackage, null, null);
9469 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009470 Phone phone = getPhone(subId);
9471 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009472 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9473 phone.carrierActionSetMeteredApnsEnabled(enabled);
9474 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07009475 phone.getDataSettingsManager().setDataEnabled(
9476 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009477 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009478 }
9479 } finally {
9480 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009481 }
9482 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009483
9484 /**
9485 * Get Client request stats
9486 * @return List of Client Request Stats
9487 * @hide
9488 */
9489 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009490 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9491 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009492 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009493 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009494 return null;
9495 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009496 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009497
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009498 final long identity = Binder.clearCallingIdentity();
9499 try {
9500 if (phone != null) {
9501 return phone.getClientRequestStats();
9502 }
9503
9504 return null;
9505 } finally {
9506 Binder.restoreCallingIdentity(identity);
9507 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009508 }
9509
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009510 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009511 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009512 if (uid == Process.ROOT_UID && packageName == null) {
9513 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9514 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9515 // exception. ROOT_UID seems not to have a valid package name returned by
9516 // PackageManager, so just fake it here to avoid issues when running telephony shell
9517 // commands that plumb through the RIL as root, like so:
9518 // $ adb root
9519 // $ adb shell cmd phone ...
9520 packageName = "root";
9521 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009522 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009523 }
Jack Yueb4124c2017-02-16 15:32:43 -08009524
9525 /**
Grace Chen70990072017-03-24 17:21:30 -07009526 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009527 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009528 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009529 * @param state State of SIM (power down, power up, pass through)
9530 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9531 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9532 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009533 *
9534 **/
9535 @Override
Grace Chen70990072017-03-24 17:21:30 -07009536 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009537 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009538
9539 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9540 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot");
9541
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009542 Phone phone = PhoneFactory.getPhone(slotIndex);
9543
vagdeviaf9a5b92018-08-15 16:01:53 -07009544 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9545
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009546 final long identity = Binder.clearCallingIdentity();
9547 try {
9548 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009549 phone.setSimPowerState(state, null, workSource);
9550 }
9551 } finally {
9552 Binder.restoreCallingIdentity(identity);
9553 }
9554 }
9555
9556 /**
9557 * Set SIM card power state.
9558 *
9559 * @param slotIndex SIM slot id.
9560 * @param state State of SIM (power down, power up, pass through)
9561 * @param callback callback to trigger after success or failure
9562 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9563 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9564 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9565 *
9566 **/
9567 @Override
9568 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9569 IIntegerConsumer callback) {
9570 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009571
9572 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9573 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
9574 "setSimPowerStateForSlotWithCallback");
9575
Jordan Liu109698e2020-11-24 14:50:34 -08009576 Phone phone = PhoneFactory.getPhone(slotIndex);
9577
9578 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9579
9580 final long identity = Binder.clearCallingIdentity();
9581 try {
9582 if (phone != null) {
9583 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9584 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009585 }
9586 } finally {
9587 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009588 }
9589 }
Shuo Qiandd210312017-04-12 22:11:33 +00009590
Tyler Gunn65d45c22017-06-05 11:22:26 -07009591 private boolean isUssdApiAllowed(int subId) {
9592 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009593 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009594 if (configManager == null) {
9595 return false;
9596 }
9597 PersistableBundle pb = configManager.getConfigForSubId(subId);
9598 if (pb == null) {
9599 return false;
9600 }
9601 return pb.getBoolean(
9602 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9603 }
9604
Shuo Qiandd210312017-04-12 22:11:33 +00009605 /**
Ling Mac28f0212023-03-24 16:07:15 -07009606 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00009607 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07009608 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00009609 */
goneil9c5f4872017-12-05 14:07:56 -08009610 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009611 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009612 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
joonhunshin4ac60942023-11-15 15:23:39 +00009613
9614 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9615 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode");
9616
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009617 final long identity = Binder.clearCallingIdentity();
9618 try {
Ling Mac28f0212023-03-24 16:07:15 -07009619 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009620 } finally {
9621 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009622 }
9623 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009624
9625 /**
9626 * Get the current signal strength information for the given subscription.
9627 * Because this information is not updated when the device is in a low power state
9628 * it should not be relied-upon to be current.
9629 * @param subId Subscription index
9630 * @return the most recent cached signal strength info from the modem
9631 */
9632 @Override
9633 public SignalStrength getSignalStrength(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00009634 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9635 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength");
9636
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009637 final long identity = Binder.clearCallingIdentity();
9638 try {
9639 Phone p = getPhone(subId);
9640 if (p == null) {
9641 return null;
9642 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009643
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009644 return p.getSignalStrength();
9645 } finally {
9646 Binder.restoreCallingIdentity(identity);
9647 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009648 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009649
Pengquan Meng77b7f132018-08-22 14:49:57 -07009650 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009651 * Get the current modem radio state for the given slot.
9652 * @param slotIndex slot index.
9653 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009654 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009655 * @return the current radio power state from the modem
9656 */
9657 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009658 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009659 Phone phone = PhoneFactory.getPhone(slotIndex);
9660 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009661 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9662 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009663 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9664 }
9665
joonhunshin4ac60942023-11-15 15:23:39 +00009666 enforceTelephonyFeatureWithException(callingPackage,
9667 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState");
9668
Chen Xuf792fd62018-10-17 17:54:36 +00009669 final long identity = Binder.clearCallingIdentity();
9670 try {
9671 return phone.getRadioPowerState();
9672 } finally {
9673 Binder.restoreCallingIdentity(identity);
9674 }
9675 }
9676 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9677 }
9678
9679 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009680 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9681 *
9682 * <p>Requires one of the following permissions:
9683 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009684 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009685 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9686 * privileges.
9687 *
9688 * @param subId subscription id
9689 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9690 * {@code false}.
9691 */
9692 @Override
9693 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009694 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009695 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009696 try {
9697 mApp.enforceCallingOrSelfPermission(
9698 android.Manifest.permission.ACCESS_NETWORK_STATE,
9699 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009700 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009701 mApp.enforceCallingOrSelfPermission(
9702 permission.READ_BASIC_PHONE_STATE, functionName);
9703 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009704 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009705 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009706 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009707 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009708
joonhunshin4ac60942023-11-15 15:23:39 +00009709 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9710 PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled");
9711
Pengquan Menga1bb6272018-09-06 09:59:22 -07009712 boolean isEnabled = false;
9713 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009714 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009715 Phone phone = getPhone(subId);
9716 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009717 } finally {
9718 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009719 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009720 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009721 }
9722
9723
9724 /**
9725 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9726 *
9727 * <p> Requires permission:
9728 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9729 * privileges.
9730 *
9731 * @param subId subscription id
9732 * @param isEnabled {@code true} means enable, {@code false} means disable.
9733 */
9734 @Override
9735 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009736 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9737 mApp, subId, "setDataRoamingEnabled");
9738
joonhunshin4ac60942023-11-15 15:23:39 +00009739 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9740 PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled");
9741
Pengquan Menga1bb6272018-09-06 09:59:22 -07009742 final long identity = Binder.clearCallingIdentity();
9743 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009744 Phone phone = getPhone(subId);
9745 if (phone != null) {
9746 phone.setDataRoamingEnabled(isEnabled);
9747 }
9748 } finally {
9749 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009750 }
9751 }
9752
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009753 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009754 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009755 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009756 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009757 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009758
joonhunshin4ac60942023-11-15 15:23:39 +00009759 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9760 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed");
9761
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009762 boolean isAllowed = true;
9763 final long identity = Binder.clearCallingIdentity();
9764 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009765 Phone phone = getPhone(subId);
9766 if (phone != null) {
9767 isAllowed = phone.isCspPlmnEnabled();
9768 }
9769 } finally {
9770 Binder.restoreCallingIdentity(identity);
9771 }
9772 return isAllowed;
9773 }
9774
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009775 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9776 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009777 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009778 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009779 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009780 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9781 if (phone == null) {
9782 return false;
9783 }
9784 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9785 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9786 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009787 }
9788
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009789 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009790 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009791 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009792 mApp.getSystemService(AppOpsManager.class)
9793 .checkPackage(Binder.getCallingUid(), callingPackage);
9794
Jordan Liu1e142fc2019-04-22 15:10:43 -07009795 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009796 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009797 try {
9798 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009799 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009800 } catch (SecurityException e) {
9801 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9802 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009803 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009804 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009805 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009806 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009807 }
joonhunshin4ac60942023-11-15 15:23:39 +00009808
9809 enforceTelephonyFeatureWithException(callingPackage,
9810 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo");
9811
sandeepjsb6c87872021-09-27 15:34:44 +00009812 // checking compatibility, if calling app's target SDK is T and beyond.
9813 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9814 Binder.getCallingUid())) {
9815 isIccIdAccessRestricted = true;
9816 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009817 final long identity = Binder.clearCallingIdentity();
9818 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009819 UiccController uiccController = UiccController.getInstance();
9820 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009821 if (hasReadPermission) {
9822 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009823 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009824
9825 // Remove private info if the caller doesn't have access
9826 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9827 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009828 //setting the value after compatibility check
9829 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009830 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9831 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009832 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009833 if (card == null) {
9834 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009835 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009836 continue;
9837 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009838 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9839 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009840 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009841 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009842 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009843 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9844 for (UiccPortInfo portInfo : portInfos) {
9845 UiccPort port = uiccController.getUiccPortForSlot(
9846 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9847 if (port == null) {
9848 // assume no access if port is null
9849 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9850 continue;
9851 }
9852 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9853 uiccPortInfos.add(portInfo);
9854 } else {
9855 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9856 }
9857 }
9858 filteredInfos.add(new UiccCardInfo(
9859 cardInfo.isEuicc(),
9860 cardInfo.getCardId(),
9861 null,
9862 cardInfo.getPhysicalSlotIndex(),
9863 cardInfo.isRemovable(),
9864 cardInfo.isMultipleEnabledProfilesSupported(),
9865 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009866 }
9867 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009868 } finally {
9869 Binder.restoreCallingIdentity(identity);
9870 }
9871 }
9872
sandeepjsb6c87872021-09-27 15:34:44 +00009873 /**
9874 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9875 * generally private and require carrier privileges to view.
9876 *
9877 * @hide
9878 */
9879 @NonNull
9880 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9881 List<UiccPortInfo> portinfo = new ArrayList<>();
9882 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9883 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9884 }
9885 return new UiccCardInfo(
9886 cardInfo.isEuicc(),
9887 cardInfo.getCardId(),
9888 null,
9889 cardInfo.getPhysicalSlotIndex(),
9890 cardInfo.isRemovable(),
9891 cardInfo.isMultipleEnabledProfilesSupported(),
9892 portinfo
9893 );
9894 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009895
sandeepjsb6c87872021-09-27 15:34:44 +00009896 /**
9897 * @hide
9898 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9899 * These values are generally private and require carrier privileges to view.
9900 */
9901 @NonNull
9902 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9903 return new UiccPortInfo(
9904 UiccPortInfo.ICCID_REDACTED,
9905 portInfo.getPortIndex(),
9906 portInfo.getLogicalSlotIndex(),
9907 portInfo.isActive()
9908 );
9909 }
9910 @Override
9911 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009912 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009913 mApp.getSystemService(AppOpsManager.class)
9914 .checkPackage(Binder.getCallingUid(), callingPackage);
9915
sandeepjsb6c87872021-09-27 15:34:44 +00009916 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009917
Aman Guptaf3c90b32022-03-17 04:54:16 +00009918 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9919 // we are reading iccId which is PII data.
9920 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009921
joonhunshin4ac60942023-11-15 15:23:39 +00009922 enforceTelephonyFeatureWithException(callingPackage,
9923 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo");
9924
sandeepjsb6c87872021-09-27 15:34:44 +00009925 // checking compatibility, if calling app's target SDK is T and beyond.
9926 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9927 Binder.getCallingUid())) {
9928 isLogicalSlotAccessRestricted = true;
9929 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009930 final long identity = Binder.clearCallingIdentity();
9931 try {
9932 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009933 if (slots == null || slots.length == 0) {
9934 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009935 return null;
9936 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009937 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9938 for (int i = 0; i < slots.length; i++) {
9939 UiccSlot slot = slots[i];
9940 if (slot == null) {
9941 continue;
9942 }
9943
Jordan Liu7be7e652019-05-06 18:55:02 +00009944 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009945 UiccCard card = slot.getUiccCard();
9946 if (card != null) {
9947 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009948 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009949 cardId = slot.getEid();
9950 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009951 // If cardId is null, use iccId of default port as cardId.
9952 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009953 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009954 }
9955
Jordan Liu857451f2019-05-09 16:35:35 -07009956 if (cardId != null) {
9957 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9958 // if cardId is an EID, it's all digits so this is fine
9959 cardId = IccUtils.stripTrailingFs(cardId);
9960 }
9961
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009962 int cardState = 0;
9963 switch (slot.getCardState()) {
9964 case CARDSTATE_ABSENT:
9965 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9966 break;
9967 case CARDSTATE_PRESENT:
9968 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9969 break;
9970 case CARDSTATE_ERROR:
9971 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9972 break;
9973 case CARDSTATE_RESTRICTED:
9974 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9975 break;
9976 default:
9977 break;
9978
9979 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009980 List<UiccPortInfo> portInfos = new ArrayList<>();
9981 int[] portIndexes = slot.getPortList();
9982 for (int portIdx : portIndexes) {
9983 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009984 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009985 portInfos.add(new UiccPortInfo(iccId, portIdx,
9986 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009987 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009988 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009989 slot.isEuicc(),
9990 cardId,
9991 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009992 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009993 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009994 //setting the value after compatibility check
9995 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009996 }
9997 return infos;
9998 } finally {
9999 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -070010000 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010001 }
10002
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010003 /* Returns null if doesn't have read permission or carrier privilege access. */
10004 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
10005 boolean hasReadPermission) {
10006 String iccId = slot.getIccId(portIndex);
10007 if (hasReadPermission) { // if has read permission
10008 return iccId;
10009 } else {
10010 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
10011 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
10012 // if no read permission, checking carrier privilege access
10013 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
10014 return iccId;
10015 }
10016 }
10017 }
10018 // No read permission or carrier privilege access.
10019 return UiccPortInfo.ICCID_REDACTED;
10020 }
10021
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010022 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010023 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010024 public boolean switchSlots(int[] physicalSlots) {
10025 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010026
joonhunshin4ac60942023-11-15 15:23:39 +000010027 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10028 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots");
10029
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010030 final long identity = Binder.clearCallingIdentity();
10031 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010032 List<UiccSlotMapping> slotMappings = new ArrayList<>();
10033 for (int i = 0; i < physicalSlots.length; i++) {
10034 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
10035 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
10036 physicalSlots[i], i));
10037 }
10038 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010039 } finally {
10040 Binder.restoreCallingIdentity(identity);
10041 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010042 }
Jack Yu4c988042018-02-27 15:30:01 -080010043
10044 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010045 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
10046 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
10047 enforceModifyPermission();
10048
joonhunshin4ac60942023-11-15 15:23:39 +000010049 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10050 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping");
10051
sandeepjsb6c87872021-09-27 15:34:44 +000010052 final long identity = Binder.clearCallingIdentity();
10053 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010054 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +000010055 } finally {
10056 Binder.restoreCallingIdentity(identity);
10057 }
10058 }
10059
10060 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -080010061 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
joonhunshin4ac60942023-11-15 15:23:39 +000010062 enforceTelephonyFeatureWithException(callingPackage,
10063 PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc");
10064
Jordan Liu7de49fa2018-12-06 14:48:49 -080010065 final long identity = Binder.clearCallingIdentity();
10066 try {
10067 return UiccController.getInstance().getCardIdForDefaultEuicc();
10068 } finally {
10069 Binder.restoreCallingIdentity(identity);
10070 }
10071 }
10072
Pengquan Meng85728fb2018-03-12 16:31:21 -070010073 /**
goneil47ffb6e2018-04-06 15:40:58 -070010074 * A test API to reload the UICC profile.
10075 *
10076 * <p>Requires that the calling app has permission
10077 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
10078 * @hide
10079 */
10080 @Override
10081 public void refreshUiccProfile(int subId) {
10082 enforceModifyPermission();
10083
10084 final long identity = Binder.clearCallingIdentity();
10085 try {
10086 Phone phone = getPhone(subId);
10087 if (phone == null) {
10088 return;
10089 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010090 UiccPort uiccPort = phone.getUiccPort();
10091 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -070010092 return;
10093 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010094 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -070010095 if (uiccProfile == null) {
10096 return;
10097 }
10098 uiccProfile.refresh();
10099 } finally {
10100 Binder.restoreCallingIdentity(identity);
10101 }
10102 }
10103
10104 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010105 * Returns false if the mobile data is disabled by default, otherwise return true.
10106 */
10107 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010108 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010109 }
10110
10111 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010112 * Returns the default network type for the given {@code subId}, if the default network type is
10113 * not set, return {@link Phone#PREFERRED_NT_MODE}.
10114 */
10115 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010116 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -080010117 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +090010118 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
10119 return list.get(phoneId);
10120 }
10121 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -070010122 }
fionaxua13278b2018-03-21 00:08:13 -070010123
10124 @Override
10125 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -070010126 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -070010127 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010128
10129 final long identity = Binder.clearCallingIdentity();
10130 try {
10131 final Phone phone = getPhone(subId);
10132 if (phone == null) {
10133 loge("setCarrierTestOverride fails with invalid subId: " + subId);
10134 return;
10135 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -080010136 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10137 if (cpt != null) {
10138 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
10139 }
10140 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -070010141 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
10142 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -070010143 if (carrierPrivilegeRules == null) {
10144 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
10145 } else {
10146 mCarrierPrivilegeTestOverrideSubIds.add(subId);
10147 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010148 } finally {
10149 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010150 }
fionaxua13278b2018-03-21 00:08:13 -070010151 }
10152
10153 @Override
Benedict Wong66477622023-02-03 23:30:57 +000010154 public void setCarrierServicePackageOverride(
10155 int subId, String carrierServicePackage, String callingPackage) {
10156 TelephonyPermissions.enforceShellOnly(
10157 Binder.getCallingUid(), "setCarrierServicePackageOverride");
10158
Benedict Wong66477622023-02-03 23:30:57 +000010159 final long identity = Binder.clearCallingIdentity();
10160 try {
10161 final Phone phone = getPhone(subId);
10162 if (phone == null || phone.getSubId() != subId) {
10163 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
10164 throw new IllegalArgumentException("No phone for subid");
10165 }
10166 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10167 if (cpt == null) {
10168 loge("setCarrierServicePackageOverride failed with no CPT for phone");
10169 throw new IllegalStateException("No CPT for phone");
10170 }
10171 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
10172 } finally {
10173 Binder.restoreCallingIdentity(identity);
10174 }
10175 }
10176
10177 @Override
fionaxua13278b2018-03-21 00:08:13 -070010178 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -070010179 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010180
10181 final long identity = Binder.clearCallingIdentity();
10182 try {
10183 final Phone phone = getPhone(subId);
10184 if (phone == null) {
10185 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
10186 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
10187 }
10188 return phone.getCarrierIdListVersion();
10189 } finally {
10190 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010191 }
fionaxua13278b2018-03-21 00:08:13 -070010192 }
Malcolm Chen2c63d402018-08-14 16:00:53 -070010193
10194 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010195 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
10196 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010197 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010198 mApp, subId, callingPackage, callingFeatureId,
10199 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010200 return -1;
10201 }
10202
10203 final long identity = Binder.clearCallingIdentity();
10204 try {
10205 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10206 } finally {
10207 Binder.restoreCallingIdentity(identity);
10208 }
10209 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010210
10211 @Override
10212 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +080010213 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010214 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010215 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010216
joonhunshin4ac60942023-11-15 15:23:39 +000010217 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10218 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode");
10219
Pengquan Menga1bb6272018-09-06 09:59:22 -070010220 final long identity = Binder.clearCallingIdentity();
10221 try {
10222 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10223 } finally {
10224 Binder.restoreCallingIdentity(identity);
10225 }
10226 }
10227
10228 @Override
10229 public boolean setCdmaRoamingMode(int subId, int mode) {
10230 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10231 mApp, subId, "setCdmaRoamingMode");
10232
joonhunshin4ac60942023-11-15 15:23:39 +000010233 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10234 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode");
10235
Pengquan Menga1bb6272018-09-06 09:59:22 -070010236 final long identity = Binder.clearCallingIdentity();
10237 try {
10238 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10239 } finally {
10240 Binder.restoreCallingIdentity(identity);
10241 }
10242 }
10243
10244 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010245 public int getCdmaSubscriptionMode(int subId) {
10246 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010247 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010248 mApp, subId, "getCdmaSubscriptionMode");
10249
joonhunshin4ac60942023-11-15 15:23:39 +000010250 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10251 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode");
10252
Sarah Chinbaab1432020-10-28 13:46:24 -070010253 final long identity = Binder.clearCallingIdentity();
10254 try {
10255 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10256 } finally {
10257 Binder.restoreCallingIdentity(identity);
10258 }
10259 }
10260
10261 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010262 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10263 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10264 mApp, subId, "setCdmaSubscriptionMode");
10265
joonhunshin4ac60942023-11-15 15:23:39 +000010266 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10267 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode");
10268
Pengquan Menga1bb6272018-09-06 09:59:22 -070010269 final long identity = Binder.clearCallingIdentity();
10270 try {
10271 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10272 } finally {
10273 Binder.restoreCallingIdentity(identity);
10274 }
10275 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010276
sqianc5eccab2018-10-19 18:46:41 -070010277 @Override
sqian8c685422019-02-22 15:55:18 -080010278 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010279 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010280 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010281 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10282 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010283 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10284 }
joonhunshin4ac60942023-11-15 15:23:39 +000010285
10286 enforceTelephonyFeatureWithException(callingPackage,
10287 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList");
10288
sqian11b7a0e2018-12-05 18:48:28 -080010289 final long identity = Binder.clearCallingIdentity();
10290 try {
sqian854d44b2018-12-12 16:48:18 -080010291 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10292 for (Phone phone: PhoneFactory.getPhones()) {
10293 if (phone.getEmergencyNumberTracker() != null
10294 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10295 emergencyNumberListInternal.put(
10296 phone.getSubId(),
10297 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10298 }
sqian11b7a0e2018-12-05 18:48:28 -080010299 }
sqian854d44b2018-12-12 16:48:18 -080010300 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010301 } finally {
10302 Binder.restoreCallingIdentity(identity);
10303 }
sqianc5eccab2018-10-19 18:46:41 -070010304 }
10305
10306 @Override
sqian8c685422019-02-22 15:55:18 -080010307 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010308 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010309 if (!exactMatch) {
10310 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010311 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010312 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010313 }
joonhunshin4ac60942023-11-15 15:23:39 +000010314
10315 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10316 PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber");
10317
sqian11b7a0e2018-12-05 18:48:28 -080010318 final long identity = Binder.clearCallingIdentity();
10319 try {
sqian854d44b2018-12-12 16:48:18 -080010320 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010321 //Note: we ignore passed in param exactMatch. We can remove it once
10322 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010323 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010324 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010325 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010326 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010327 }
sqian11b7a0e2018-12-05 18:48:28 -080010328 }
10329 return false;
10330 } finally {
10331 Binder.restoreCallingIdentity(identity);
10332 }
10333 }
10334
sqianf4ca7ed2019-01-15 18:32:07 -080010335 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010336 * Start emergency callback mode for GsmCdmaPhone for testing.
10337 */
10338 @Override
10339 public void startEmergencyCallbackMode() {
10340 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10341 "startEmergencyCallbackMode");
10342 enforceModifyPermission();
10343 final long identity = Binder.clearCallingIdentity();
10344 try {
10345 for (Phone phone : PhoneFactory.getPhones()) {
10346 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10347 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10348 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10349 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10350 gsmCdmaPhone.obtainMessage(
10351 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10352 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10353 }
10354 }
10355 } finally {
10356 Binder.restoreCallingIdentity(identity);
10357 }
10358 }
10359
10360 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010361 * Update emergency number list for test mode.
10362 */
10363 @Override
10364 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10365 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10366 "updateEmergencyNumberListTestMode");
10367
10368 final long identity = Binder.clearCallingIdentity();
10369 try {
10370 for (Phone phone: PhoneFactory.getPhones()) {
10371 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10372 if (tracker != null) {
10373 tracker.executeEmergencyNumberTestModeCommand(action, num);
10374 }
10375 }
10376 } finally {
10377 Binder.restoreCallingIdentity(identity);
10378 }
10379 }
10380
10381 /**
10382 * Get the full emergency number list for test mode.
10383 */
10384 @Override
10385 public List<String> getEmergencyNumberListTestMode() {
10386 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10387 "getEmergencyNumberListTestMode");
10388
10389 final long identity = Binder.clearCallingIdentity();
10390 try {
10391 Set<String> emergencyNumbers = new HashSet<>();
10392 for (Phone phone: PhoneFactory.getPhones()) {
10393 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10394 if (tracker != null) {
10395 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10396 emergencyNumbers.add(num.getNumber());
10397 }
10398 }
10399 }
10400 return new ArrayList<>(emergencyNumbers);
10401 } finally {
10402 Binder.restoreCallingIdentity(identity);
10403 }
10404 }
10405
chen xud6b45bd2018-10-30 22:27:10 -070010406 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010407 public int getEmergencyNumberDbVersion(int subId) {
10408 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10409
joonhunshin4ac60942023-11-15 15:23:39 +000010410 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10411 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion");
10412
Shuo Qian3b6ee772019-11-13 17:43:31 -080010413 final long identity = Binder.clearCallingIdentity();
10414 try {
10415 final Phone phone = getPhone(subId);
10416 if (phone == null) {
10417 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10418 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10419 }
10420 return phone.getEmergencyNumberDbVersion();
10421 } finally {
10422 Binder.restoreCallingIdentity(identity);
10423 }
10424 }
10425
10426 @Override
10427 public void notifyOtaEmergencyNumberDbInstalled() {
10428 enforceModifyPermission();
10429
joonhunshin4ac60942023-11-15 15:23:39 +000010430 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10431 PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled");
10432
Shuo Qian3b6ee772019-11-13 17:43:31 -080010433 final long identity = Binder.clearCallingIdentity();
10434 try {
10435 for (Phone phone: PhoneFactory.getPhones()) {
10436 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10437 if (tracker != null) {
10438 tracker.updateOtaEmergencyNumberDatabase();
10439 }
10440 }
10441 } finally {
10442 Binder.restoreCallingIdentity(identity);
10443 }
10444 }
10445
10446 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010447 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010448 enforceActiveEmergencySessionPermission();
10449
joonhunshin4ac60942023-11-15 15:23:39 +000010450 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10451 PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath");
10452
Shuo Qian3b6ee772019-11-13 17:43:31 -080010453 final long identity = Binder.clearCallingIdentity();
10454 try {
10455 for (Phone phone: PhoneFactory.getPhones()) {
10456 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10457 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010458 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10459 }
10460 }
10461 } finally {
10462 Binder.restoreCallingIdentity(identity);
10463 }
10464 }
10465
10466 @Override
10467 public void resetOtaEmergencyNumberDbFilePath() {
10468 enforceActiveEmergencySessionPermission();
10469
joonhunshin4ac60942023-11-15 15:23:39 +000010470 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10471 PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath");
10472
Shuo Qianc373f112020-03-05 17:55:34 -080010473 final long identity = Binder.clearCallingIdentity();
10474 try {
10475 for (Phone phone: PhoneFactory.getPhones()) {
10476 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10477 if (tracker != null) {
10478 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010479 }
10480 }
10481 } finally {
10482 Binder.restoreCallingIdentity(identity);
10483 }
10484 }
10485
10486 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010487 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10488 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10489 Phone phone = getPhone(subId);
10490 if (phone == null) {
10491 return null;
10492 }
10493 final long identity = Binder.clearCallingIdentity();
10494 try {
10495 UiccProfile profile = UiccController.getInstance()
10496 .getUiccProfileForPhone(phone.getPhoneId());
10497 if (profile != null) {
10498 return profile.getCertsFromCarrierPrivilegeAccessRules();
10499 }
10500 } finally {
10501 Binder.restoreCallingIdentity(identity);
10502 }
10503 return null;
10504 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010505
10506 /**
10507 * Enable or disable a modem stack.
10508 */
10509 @Override
10510 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10511 enforceModifyPermission();
10512
joonhunshin4ac60942023-11-15 15:23:39 +000010513 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10514 PackageManager.FEATURE_TELEPHONY, "enableModemForSlot");
10515
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010516 final long identity = Binder.clearCallingIdentity();
10517 try {
10518 Phone phone = PhoneFactory.getPhone(slotIndex);
10519 if (phone == null) {
10520 return false;
10521 } else {
10522 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10523 }
10524 } finally {
10525 Binder.restoreCallingIdentity(identity);
10526 }
10527 }
Michelecea4cf22018-12-21 15:00:11 -080010528
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010529 /**
10530 * Whether a modem stack is enabled or not.
10531 */
10532 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010533 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10534 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010535 Phone phone = PhoneFactory.getPhone(slotIndex);
10536 if (phone == null) return false;
10537
10538 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010539 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10540 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010541 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10542 }
10543
joonhunshin4ac60942023-11-15 15:23:39 +000010544 enforceTelephonyFeatureWithException(callingPackage,
10545 PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot");
10546
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010547 final long identity = Binder.clearCallingIdentity();
10548 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010549 try {
10550 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10551 } catch (NoSuchElementException ex) {
10552 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10553 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010554 } finally {
10555 Binder.restoreCallingIdentity(identity);
10556 }
10557 }
10558
Michelecea4cf22018-12-21 15:00:11 -080010559 @Override
Michele0ea7d782019-03-19 14:58:42 -070010560 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010561 enforceModifyPermission();
10562
joonhunshin4ac60942023-11-15 15:23:39 +000010563 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10564 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction");
10565
Michelecea4cf22018-12-21 15:00:11 -080010566 final long identity = Binder.clearCallingIdentity();
10567 try {
10568 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010569 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010570 .commit();
10571 } finally {
10572 Binder.restoreCallingIdentity(identity);
10573 }
10574 }
10575
10576 @Override
Michele0ea7d782019-03-19 14:58:42 -070010577 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010578 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010579 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010580 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10581 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010582 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010583 }
Michelecea4cf22018-12-21 15:00:11 -080010584
joonhunshin4ac60942023-11-15 15:23:39 +000010585 enforceTelephonyFeatureWithException(callingPackage,
10586 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported");
10587
Michelecea4cf22018-12-21 15:00:11 -080010588 final long identity = Binder.clearCallingIdentity();
10589 try {
Michele0ea7d782019-03-19 14:58:42 -070010590 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010591 } finally {
10592 Binder.restoreCallingIdentity(identity);
10593 }
10594 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010595
Michele0ea7d782019-03-19 14:58:42 -070010596 @TelephonyManager.IsMultiSimSupportedResult
10597 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010598 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10599 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10600 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010601 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10602 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010603 }
10604 // Check if the hardware supports multisim functionality. If usage of multisim is not
10605 // supported by the modem, indicate that it is restricted.
10606 PhoneCapability staticCapability =
10607 mPhoneConfigurationManager.getStaticPhoneCapability();
10608 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010609 loge("isMultiSimSupportedInternal: no static configuration available");
10610 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010611 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010612 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010613 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10614 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010615 }
10616 // Check if support of multiple SIMs is restricted by carrier
10617 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010618 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010619 }
10620
Michele0ea7d782019-03-19 14:58:42 -070010621 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010622 }
10623
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010624 /**
10625 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010626 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10627 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10628 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010629 * @param numOfSims number of active sims we want to switch to
10630 */
10631 @Override
10632 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010633 if (numOfSims == 1) {
10634 enforceModifyPermission();
10635 } else {
10636 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10637 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10638 }
joonhunshin4ac60942023-11-15 15:23:39 +000010639
10640 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10641 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig");
10642
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010643 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010644
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010645 try {
Michele30b57b22019-03-01 12:01:14 -080010646 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010647 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010648 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10649 return;
10650 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010651 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10652 } finally {
10653 Binder.restoreCallingIdentity(identity);
10654 }
10655 }
10656
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010657 @Override
10658 public boolean isApplicationOnUicc(int subId, int appType) {
10659 enforceReadPrivilegedPermission("isApplicationOnUicc");
joonhunshin4ac60942023-11-15 15:23:39 +000010660
10661 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10662 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc");
10663
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010664 Phone phone = getPhone(subId);
10665 if (phone == null) {
10666 return false;
10667 }
10668 final long identity = Binder.clearCallingIdentity();
10669 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010670 UiccPort uiccPort = phone.getUiccPort();
10671 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010672 return false;
10673 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010674 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010675 if (uiccProfile == null) {
10676 return false;
10677 }
10678 if (TelephonyManager.APPTYPE_SIM <= appType
10679 && appType <= TelephonyManager.APPTYPE_ISIM) {
10680 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10681 }
10682 return false;
10683 } finally {
10684 Binder.restoreCallingIdentity(identity);
10685 }
10686 }
10687
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010688 /**
chen xub4baa772019-04-03 10:23:41 -070010689 * Get whether making changes to modem configurations will trigger reboot.
10690 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010691 */
10692 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010693 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10694 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010695 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010696 mApp, subId, callingPackage, callingFeatureId,
10697 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010698 return false;
10699 }
joonhunshin4ac60942023-11-15 15:23:39 +000010700
10701 enforceTelephonyFeatureWithException(callingPackage,
10702 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
10703 "doesSwitchMultiSimConfigTriggerReboot");
10704
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010705 final long identity = Binder.clearCallingIdentity();
10706 try {
10707 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10708 } finally {
10709 Binder.restoreCallingIdentity(identity);
10710 }
10711 }
10712
Nathan Harold29f5f052019-02-15 13:41:57 -080010713 private void updateModemStateMetrics() {
10714 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10715 // TODO: check the state for each modem if the api is ready.
10716 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10717 }
10718
Pengquan Meng3889a572019-01-23 11:16:29 -080010719 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010720 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010721 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010722 // Verify that the callingPackage belongs to the calling UID
10723 mApp.getSystemService(AppOpsManager.class)
10724 .checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000010725
10726 enforceTelephonyFeatureWithException(callingPackage,
10727 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping");
10728
Pengquan Meng3889a572019-01-23 11:16:29 -080010729 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010730 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010731 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010732 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10733 if (slotInfos != null) {
10734 for (int i = 0; i < slotInfos.length; i++) {
10735 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10736 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10737 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10738 portInfo.getLogicalSlotIndex()));
10739 }
10740 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010741 }
10742 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010743 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010744 } finally {
10745 Binder.restoreCallingIdentity(identity);
10746 }
10747 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010748
10749 /**
10750 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010751 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010752 */
jimsunf9ec1622022-09-13 21:18:43 +080010753 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010754 @Override
10755 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010756 return getHalVersion(HAL_SERVICE_RADIO);
10757 }
10758
10759 /**
10760 * Get the HAL Version of a specific service
10761 */
10762 @Override
10763 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010764 Phone phone = getDefaultPhone();
10765 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010766 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010767 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10768 return hv.major * 100 + hv.minor;
10769 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010770
10771 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010772 * Get the current calling package name.
sangyun097dcf72024-01-04 10:35:49 +090010773 *
10774 * @return the current calling package name, or null if there is no known package.
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010775 */
10776 @Override
sangyun097dcf72024-01-04 10:35:49 +090010777 public @Nullable String getCurrentPackageName() {
10778 PackageManager pm = mApp.getPackageManager();
10779 String[] packageNames = pm == null ? null : pm.getPackagesForUid(Binder.getCallingUid());
10780 return packageNames == null ? null : packageNames[0];
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010781 }
10782
10783 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010784 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10785 * corresponding network requests on a subId.
10786 *
10787 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010788 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010789 * 2) APN is un-metered for this subscription, or
10790 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010791 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010792 *
10793 * @return whether data is allowed for a apn type.
10794 *
10795 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010796 */
10797 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010798 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010799 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10800 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010801
joonhunshin4ac60942023-11-15 15:23:39 +000010802 enforceTelephonyFeatureWithException(callingPackage,
10803 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn");
10804
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010805 // Now that all security checks passes, perform the operation as ourselves.
10806 final long identity = Binder.clearCallingIdentity();
10807 try {
10808 Phone phone = getPhone(subId);
10809 if (phone == null) return false;
10810
Jack Yu27422a52022-03-21 10:38:05 -070010811 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010812 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010813 isMetered = phone.getDataNetworkController().getDataConfigManager()
10814 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10815 phone.getServiceState().getDataRoaming());
10816 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010817 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010818 } finally {
10819 Binder.restoreCallingIdentity(identity);
10820 }
10821 }
10822
10823 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010824 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010825 enforceReadPrivilegedPermission("isApnMetered");
10826
joonhunshin4ac60942023-11-15 15:23:39 +000010827 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10828 PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered");
10829
Malcolm Chene5ad5792019-04-18 13:51:02 -070010830 // Now that all security checks passes, perform the operation as ourselves.
10831 final long identity = Binder.clearCallingIdentity();
10832 try {
10833 Phone phone = getPhone(subId);
10834 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010835 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10836 DataUtils.apnTypeToNetworkCapability(apnType),
10837 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010838 } finally {
10839 Binder.restoreCallingIdentity(identity);
10840 }
10841 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010842
10843 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010844 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10845 int subscriptionId, IBooleanConsumer resultCallback) {
10846 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +000010847
10848 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10849 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels");
10850
Hall Liu73f5d362020-01-20 13:42:00 -080010851 long token = Binder.clearCallingIdentity();
10852 try {
10853 Phone phone = getPhone(subscriptionId);
10854 if (phone == null) {
10855 try {
10856 if (resultCallback != null) {
10857 resultCallback.accept(false);
10858 }
10859 } catch (RemoteException e) {
10860 // ignore
10861 }
10862 return;
10863 }
10864 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10865 Pair.create(specifiers, (x) -> {
10866 try {
10867 if (resultCallback != null) {
10868 resultCallback.accept(x);
10869 }
10870 } catch (RemoteException e) {
10871 // ignore
10872 }
10873 });
10874 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10875 } finally {
10876 Binder.restoreCallingIdentity(token);
10877 }
10878 }
10879
10880 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010881 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10882 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010883 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010884 mApp, subId, "getSystemSelectionChannels");
joonhunshin4ac60942023-11-15 15:23:39 +000010885
10886 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10887 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels");
10888
Sarah Chin679c08a2020-11-18 13:39:35 -080010889 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10890 final long identity = Binder.clearCallingIdentity();
10891 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010892 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10893 if (result instanceof IllegalStateException) {
10894 throw (IllegalStateException) result;
10895 }
10896 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010897 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10898 return specifiers;
10899 } finally {
10900 Binder.restoreCallingIdentity(identity);
10901 }
10902 }
10903
10904 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010905 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010906 enforceReadPrivilegedPermission("isMvnoMatched");
joonhunshin4ac60942023-11-15 15:23:39 +000010907
10908 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10909 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched");
10910
Jack Yu8b766fc2022-03-21 09:42:33 -070010911 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010912 }
10913
10914 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010915 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10916 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010917 if (callingPackage == null) {
10918 callingPackage = getCurrentPackageName();
10919 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010920 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10921 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010922 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10923 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010924 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10925 }
10926 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10927 Intent intent = new Intent();
10928 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10929 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10930 // Bring up choose default SMS subscription dialog right now
10931 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10932 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10933 mApp.startActivity(intent);
10934 }
chen xud5ca2d52019-05-28 15:20:57 -070010935
10936 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010937 public void showSwitchToManagedProfileDialog() {
10938 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000010939 try {
10940 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
10941 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
10942 // for work telephony.
10943 Intent intent = new Intent(Intent.ACTION_SENDTO);
10944 intent.setData(Uri.parse("smsto:"));
10945 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10946 mApp.startActivity(intent);
10947 } catch (ActivityNotFoundException e) {
10948 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
10949 Intent intent = new Intent();
10950 intent.setClass(mApp, ErrorDialogActivity.class);
10951 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10952 mApp.startActivity(intent);
10953 }
Ayush Sharma787854b2022-12-12 14:55:02 +000010954 }
10955
10956 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010957 public String getMmsUAProfUrl(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000010958 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10959 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl");
10960
chen xud5ca2d52019-05-28 15:20:57 -070010961 //TODO investigate if this API should require proper permission check in R b/133791609
10962 final long identity = Binder.clearCallingIdentity();
10963 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010964 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10965 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10966 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10967 return carrierUAProfUrl;
10968 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010969 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10970 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010971 } finally {
10972 Binder.restoreCallingIdentity(identity);
10973 }
10974 }
10975
10976 @Override
10977 public String getMmsUserAgent(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000010978 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10979 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent");
10980
chen xud5ca2d52019-05-28 15:20:57 -070010981 //TODO investigate if this API should require proper permission check in R b/133791609
10982 final long identity = Binder.clearCallingIdentity();
10983 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010984 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10985 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10986 if (!TextUtils.isEmpty(carrierUserAgent)) {
10987 return carrierUserAgent;
10988 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010989 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10990 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010991 } finally {
10992 Binder.restoreCallingIdentity(identity);
10993 }
10994 }
Jack Yub07d4972019-05-28 16:12:25 -070010995
10996 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010997 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10998 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070010999
joonhunshin4ac60942023-11-15 15:23:39 +000011000 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11001 PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled");
11002
Jack Yub07d4972019-05-28 16:12:25 -070011003 final long identity = Binder.clearCallingIdentity();
11004 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011005 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070011006 if (phone == null) return false;
11007
Ling Maf188d502022-09-16 15:22:36 -070011008 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070011009 } finally {
11010 Binder.restoreCallingIdentity(identity);
11011 }
11012 }
11013
11014 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080011015 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070011016 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080011017 enforceModifyPermission();
11018
joonhunshin4ac60942023-11-15 15:23:39 +000011019 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11020 PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled");
11021
changbettyd5c246e2019-12-24 15:40:37 +080011022 final long identity = Binder.clearCallingIdentity();
11023 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011024 Phone phone = getPhone(subscriptionId);
11025 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080011026
Ling Maf188d502022-09-16 15:22:36 -070011027 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080011028 } finally {
11029 Binder.restoreCallingIdentity(identity);
11030 }
11031 }
11032
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011033 /**
Hall Liu746e03c2020-09-25 11:13:49 -070011034 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011035 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
11036 * otherwise.
11037 */
11038 @Override
11039 public void setCepEnabled(boolean isCepEnabled) {
11040 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
11041
11042 final long identity = Binder.clearCallingIdentity();
11043 try {
11044 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
11045 for (Phone phone : PhoneFactory.getPhones()) {
11046 Phone defaultPhone = phone.getImsPhone();
11047 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
11048 ImsPhone imsPhone = (ImsPhone) defaultPhone;
11049 ImsPhoneCallTracker imsPhoneCallTracker =
11050 (ImsPhoneCallTracker) imsPhone.getCallTracker();
11051 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
11052 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
11053 + imsPhone.getMsisdn());
11054 }
11055 }
11056 } finally {
11057 Binder.restoreCallingIdentity(identity);
11058 }
11059 }
allenwtsu46dcc572020-01-08 18:24:03 +080011060
11061 /**
11062 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
11063 *
11064 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
11065 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
11066 * before being read.
11067 */
11068 @Override
11069 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
11070 isCompressed) {
11071 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11072 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011073 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11074 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11075 }
joonhunshin4ac60942023-11-15 15:23:39 +000011076
11077 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11078 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11079 Binder.getCallingUserHandle())) {
11080 if (!isImsAvailableOnDevice()) {
11081 // ProvisioningManager can not handle ServiceSpecificException.
11082 // Throw the IllegalStateException and annotate ProvisioningManager.
11083 throw new IllegalStateException("IMS not available on device.");
11084 }
11085 } else {
11086 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11087 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11088 "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011089 }
11090
11091 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080011092 try {
Hui Wang761a6682020-10-31 05:12:53 +000011093 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
11094 } finally {
11095 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080011096 }
11097 }
zoey chene02881a2019-12-30 16:11:23 +080011098
11099 @Override
11100 public boolean isIccLockEnabled(int subId) {
11101 enforceReadPrivilegedPermission("isIccLockEnabled");
11102
joonhunshin4ac60942023-11-15 15:23:39 +000011103 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11104 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled");
11105
zoey chene02881a2019-12-30 16:11:23 +080011106 // Now that all security checks passes, perform the operation as ourselves.
11107 final long identity = Binder.clearCallingIdentity();
11108 try {
11109 Phone phone = getPhone(subId);
11110 if (phone != null && phone.getIccCard() != null) {
11111 return phone.getIccCard().getIccLockEnabled();
11112 } else {
11113 return false;
11114 }
11115 } finally {
11116 Binder.restoreCallingIdentity(identity);
11117 }
11118 }
11119
11120 /**
11121 * Set the ICC pin lock enabled or disabled.
11122 *
11123 * @return an integer representing the status of IccLock enabled or disabled in the following
11124 * three cases:
11125 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
11126 * successfully.
11127 * - Positive number and zero for remaining password attempts.
11128 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11129 *
11130 */
11131 @Override
11132 public int setIccLockEnabled(int subId, boolean enabled, String password) {
11133 enforceModifyPermission();
11134
joonhunshin4ac60942023-11-15 15:23:39 +000011135 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11136 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled");
11137
zoey chene02881a2019-12-30 16:11:23 +080011138 Phone phone = getPhone(subId);
11139 if (phone == null) {
11140 return 0;
11141 }
11142 // Now that all security checks passes, perform the operation as ourselves.
11143 final long identity = Binder.clearCallingIdentity();
11144 try {
11145 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
11146 new Pair<Boolean, String>(enabled, password), phone, null);
11147 return attemptsRemaining;
11148
11149 } catch (Exception e) {
11150 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
11151 } finally {
11152 Binder.restoreCallingIdentity(identity);
11153 }
11154 return 0;
11155 }
11156
11157 /**
11158 * Change the ICC password used in ICC pin lock.
11159 *
11160 * @return an integer representing the status of IccLock changed in the following three cases:
11161 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
11162 * - Positive number and zero for remaining password attempts.
11163 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11164 *
11165 */
11166 @Override
11167 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
11168 enforceModifyPermission();
11169
joonhunshin4ac60942023-11-15 15:23:39 +000011170 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11171 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword");
11172
zoey chene02881a2019-12-30 16:11:23 +080011173 Phone phone = getPhone(subId);
11174 if (phone == null) {
11175 return 0;
11176 }
11177 // Now that all security checks passes, perform the operation as ourselves.
11178 final long identity = Binder.clearCallingIdentity();
11179 try {
11180 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
11181 new Pair<String, String>(oldPassword, newPassword), phone, null);
11182 return attemptsRemaining;
11183
11184 } catch (Exception e) {
11185 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
11186 } finally {
11187 Binder.restoreCallingIdentity(identity);
11188 }
11189 return 0;
11190 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080011191
11192 /**
11193 * Request for receiving user activity notification
11194 */
11195 @Override
11196 public void requestUserActivityNotification() {
11197 if (!mNotifyUserActivity.get()
11198 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
11199 mNotifyUserActivity.set(true);
11200 }
11201 }
11202
11203 /**
11204 * Called when userActivity is signalled in the power manager.
11205 * This is safe to call from any thread, with any window manager locks held or not.
11206 */
11207 @Override
11208 public void userActivity() {
11209 // ***************************************
11210 // * Inherited from PhoneWindowManager *
11211 // ***************************************
11212 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
11213 // WITH ITS LOCKS HELD.
11214 //
11215 // This code must be VERY careful about the locks
11216 // it acquires.
11217 // In fact, the current code acquires way too many,
11218 // and probably has lurking deadlocks.
11219
11220 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
11221 throw new SecurityException("Only the OS may call notifyUserActivity()");
11222 }
11223
11224 if (mNotifyUserActivity.getAndSet(false)) {
11225 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
11226 USER_ACTIVITY_NOTIFICATION_DELAY);
11227 }
11228 }
Malcolm Chen4639c562020-04-13 11:59:40 -070011229
11230 @Override
11231 public boolean canConnectTo5GInDsdsMode() {
11232 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
11233 }
Jack Yud10cdd42020-09-28 20:28:01 -070011234
11235 @Override
11236 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
11237 String callingFeatureId) {
11238 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
11239 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
11240 throw new SecurityException("Requires READ_PHONE_STATE permission.");
11241 }
11242
joonhunshin4ac60942023-11-15 15:23:39 +000011243 enforceTelephonyFeatureWithException(callingPackage,
11244 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns");
11245
Jack Yud10cdd42020-09-28 20:28:01 -070011246 Phone phone = getPhone(subId);
11247 if (phone == null) {
11248 throw new RuntimeException("phone is not available");
11249 }
11250 // Now that all security checks passes, perform the operation as ourselves.
11251 final long identity = Binder.clearCallingIdentity();
11252 try {
11253 return phone.getEquivalentHomePlmns();
11254 } finally {
11255 Binder.restoreCallingIdentity(identity);
11256 }
11257 }
Daniel Bright59e67312020-11-13 11:49:37 -080011258
11259 @Override
11260 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011261 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
joonhunshin4ac60942023-11-15 15:23:39 +000011262 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11263 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
11264 "isRadioInterfaceCapabilitySupported");
11265
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011266 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080011267 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080011268 if (radioInterfaceCapabilities == null) {
11269 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080011270 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011271 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080011272 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011273
Hui Wang641e81c2020-10-12 12:14:23 -070011274 @Override
11275 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
11276 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000011277 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
11278 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11279 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
11280 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11281 Manifest.permission.MODIFY_PHONE_STATE);
joonhunshin4ac60942023-11-15 15:23:39 +000011282
11283 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11284 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest");
11285
Hui Wang641e81c2020-10-12 12:14:23 -070011286 if (DBG) {
11287 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
11288 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
11289 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
11290 }
11291
11292 if (!SubscriptionManager.isValidSubscriptionId(subId)
11293 || appType < TelephonyManager.APPTYPE_UNKNOWN
11294 || appType > TelephonyManager.APPTYPE_ISIM
11295 || nafUrl == null || securityProtocol == null || callback == null) {
11296 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
11297 if (callback != null) {
11298 try {
11299 callback.onAuthenticationFailure(
11300 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
11301 } catch (RemoteException exception) {
11302 log("Fail to notify onAuthenticationFailure due to " + exception);
11303 }
11304 return;
11305 }
11306 }
11307
11308 final long token = Binder.clearCallingIdentity();
11309 try {
11310 getGbaManager(subId).bootstrapAuthenticationRequest(
11311 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011312 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070011313 } finally {
11314 Binder.restoreCallingIdentity(token);
11315 }
11316 }
11317
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011318 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011319 * Attempts to set the radio power state for all phones for thermal reason.
11320 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011321 * requested radio power state will actually be set. See {@link
11322 * PhoneInternalInterface#setRadioPowerForReason} for more details.
11323 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011324 * @param enable {@code true} if trying to turn radio on.
11325 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
11326 * false}.
11327 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011328 private boolean setRadioPowerForThermal(boolean enable) {
11329 boolean isPhoneAvailable = false;
11330 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
11331 Phone phone = PhoneFactory.getPhone(i);
11332 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011333 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011334 isPhoneAvailable = true;
11335 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011336 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011337
11338 // return true if successfully informed the phone object about the thermal radio power
11339 // request.
11340 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011341 }
11342
11343 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011344 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011345 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11346 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11347 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11348 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11349 throw new IllegalArgumentException("modem does not support data throttling");
11350 }
11351
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011352 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11353 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011354 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011355 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11356 }
11357
Sarah Chinecc78c42022-03-31 21:16:48 -070011358 setDataEnabledForReason(
11359 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011360
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011361 if (isDataThrottlingSupported) {
11362 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011363 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011364 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11365 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11366 } else if (thermalMitigationResult
11367 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011368 log("Modem likely does not support data throttling on secondary carrier. Data " +
11369 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11370 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011371 }
11372 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011373 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011374
11375 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011376 }
11377
Jack Nudelman644b91a2021-03-12 14:09:48 -080011378 private static List<String> getThermalMitigationAllowlist(Context context) {
11379 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11380 for (String pckg : context.getResources()
11381 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11382 sThermalMitigationAllowlistedPackages.add(pckg);
11383 }
11384 }
11385
11386 return sThermalMitigationAllowlistedPackages;
11387 }
11388
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011389 private boolean isAnyPhoneInEmergencyState() {
11390 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11391 if (tm.isInEmergencyCall()) {
11392 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11393 return true;
11394 }
11395 for (Phone phone : PhoneFactory.getPhones()) {
11396 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11397 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011398 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11399 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011400 return true;
11401 }
11402 }
11403
11404 return false;
11405 }
11406
Jack Nudelman644b91a2021-03-12 14:09:48 -080011407 /**
11408 * Used by shell commands to add an authorized package name for thermal mitigation.
11409 * @param packageName name of package to be allowlisted
11410 * @param context
11411 */
11412 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11413 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11414 sThermalMitigationAllowlistedPackages.add(packageName);
11415 }
11416
11417 /**
11418 * Used by shell commands to remove an authorized package name for thermal mitigation.
11419 * @param packageName name of package to remove from allowlist
11420 * @param context
11421 */
11422 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11423 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11424 sThermalMitigationAllowlistedPackages.remove(packageName);
11425 }
11426
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011427 /**
11428 * Thermal mitigation request to control functionalities at modem.
11429 *
11430 * @param subId the id of the subscription.
11431 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011432 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011433 *
11434 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11435 */
11436 @Override
11437 @ThermalMitigationResult
11438 public int sendThermalMitigationRequest(
11439 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011440 ThermalMitigationRequest thermalMitigationRequest,
11441 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011442 enforceModifyPermission();
11443
Jack Nudelman644b91a2021-03-12 14:09:48 -080011444 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000011445
11446 enforceTelephonyFeatureWithException(callingPackage,
11447 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest");
11448
Jack Nudelman644b91a2021-03-12 14:09:48 -080011449 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11450 .contains(callingPackage)) {
11451 throw new SecurityException("Calling package must be configured in the device config. "
11452 + "calling package: " + callingPackage);
11453 }
11454
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011455 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11456 final long identity = Binder.clearCallingIdentity();
11457
11458 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11459 try {
11460 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11461 switch (thermalMitigationAction) {
11462 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11463 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011464 handleDataThrottlingRequest(subId,
11465 thermalMitigationRequest.getDataThrottlingRequest(),
11466 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011467 break;
11468 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11469 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11470 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11471 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11472 }
11473
11474 // Ensure that radio is on. If not able to power on due to phone being
11475 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011476 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011477 thermalMitigationResult =
11478 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11479 break;
11480 }
11481
11482 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011483 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011484 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11485 break;
11486 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11487 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11488 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11489 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11490 }
11491
11492 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11493 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011494 Phone phone = getPhone(subId);
11495 if (phone == null) {
11496 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011497 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011498 break;
11499 }
11500
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011501 TelephonyConnectionService service =
11502 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011503 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011504 Log.e(LOG_TAG, "An emergency call is pending");
11505 thermalMitigationResult =
11506 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11507 break;
11508 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011509 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011510 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011511 break;
11512 }
11513 } else {
11514 thermalMitigationResult =
11515 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11516 break;
11517 }
11518
11519 // Turn radio off. If not able to power off due to phone being unavailable,
11520 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011521 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011522 thermalMitigationResult =
11523 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11524 break;
11525 }
11526 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011527 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011528 break;
11529 default:
11530 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11531 + "not exist. Requested action: " + thermalMitigationAction);
11532 }
11533 } catch (IllegalArgumentException e) {
11534 throw e;
11535 } catch (Exception e) {
11536 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11537 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11538 } finally {
11539 Binder.restoreCallingIdentity(identity);
11540 }
11541
11542 if (DBG) {
11543 log("thermalMitigationRequest returning with thermalMitigationResult: "
11544 + thermalMitigationResult);
11545 }
11546
11547 return thermalMitigationResult;
11548 }
Hui Wang641e81c2020-10-12 12:14:23 -070011549
11550 /**
11551 * Set the GbaService Package Name that Telephony will bind to.
11552 *
11553 * @param subId The sim that the GbaService is associated with.
11554 * @param packageName The name of the package to be replaced with.
11555 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11556 */
11557 @Override
11558 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11559 enforceModifyPermission();
11560
11561 final long identity = Binder.clearCallingIdentity();
11562 try {
11563 return getGbaManager(subId).overrideServicePackage(packageName);
11564 } finally {
11565 Binder.restoreCallingIdentity(identity);
11566 }
11567 }
11568
11569 /**
11570 * Return the package name of the currently bound GbaService.
11571 *
11572 * @param subId The sim that the GbaService is associated with.
11573 * @return the package name of the GbaService configuration, null if GBA is not supported.
11574 */
11575 @Override
11576 public String getBoundGbaService(int subId) {
11577 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11578
11579 final long identity = Binder.clearCallingIdentity();
11580 try {
11581 return getGbaManager(subId).getServicePackage();
11582 } finally {
11583 Binder.restoreCallingIdentity(identity);
11584 }
11585 }
11586
11587 /**
11588 * Set the release time for telephony to unbind GbaService.
11589 *
11590 * @param subId The sim that the GbaService is associated with.
11591 * @param interval The release time to unbind GbaService by millisecond.
11592 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11593 */
11594 @Override
11595 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11596 enforceModifyPermission();
11597
11598 final long identity = Binder.clearCallingIdentity();
11599 try {
11600 return getGbaManager(subId).overrideReleaseTime(interval);
11601 } finally {
11602 Binder.restoreCallingIdentity(identity);
11603 }
11604 }
11605
11606 /**
11607 * Return the release time for telephony to unbind GbaService.
11608 *
11609 * @param subId The sim that the GbaService is associated with.
11610 * @return The release time to unbind GbaService by millisecond.
11611 */
11612 @Override
11613 public int getGbaReleaseTime(int subId) {
11614 enforceReadPrivilegedPermission("getGbaReleaseTime");
11615
11616 final long identity = Binder.clearCallingIdentity();
11617 try {
11618 return getGbaManager(subId).getReleaseTime();
11619 } finally {
11620 Binder.restoreCallingIdentity(identity);
11621 }
11622 }
11623
11624 private GbaManager getGbaManager(int subId) {
11625 GbaManager instance = GbaManager.getInstance(subId);
11626 if (instance == null) {
11627 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11628 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11629 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11630 }
11631 return instance;
11632 }
Hui Wang761a6682020-10-31 05:12:53 +000011633
11634 /**
11635 * indicate whether the device and the carrier can support
11636 * RCS VoLTE single registration.
11637 */
11638 @Override
11639 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011640 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11641 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11642 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11643 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011644
11645 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11646 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11647 }
11648
11649 final long identity = Binder.clearCallingIdentity();
11650 try {
11651 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11652 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011653 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11654 if (isCapable != null) {
11655 return isCapable;
11656 }
Hui Wang761a6682020-10-31 05:12:53 +000011657 }
Hui Wang67af90e2021-06-04 16:57:15 -070011658 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11659 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011660 } finally {
11661 Binder.restoreCallingIdentity(identity);
11662 }
11663 }
11664
11665 /**
11666 * Register RCS provisioning callback.
11667 */
11668 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011669 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011670 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011671 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011672 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011673 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11674 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011675
11676 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11677 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11678 }
joonhunshin4ac60942023-11-15 15:23:39 +000011679 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11680 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11681 Binder.getCallingUserHandle())) {
11682 if (!isImsAvailableOnDevice()) {
11683 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11684 "IMS not available on device.");
11685 }
11686 } else {
11687 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11688 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011689 }
11690
11691 final long identity = Binder.clearCallingIdentity();
11692 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011693 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011694 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011695 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11696 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011697 }
Hui Wang761a6682020-10-31 05:12:53 +000011698 } finally {
11699 Binder.restoreCallingIdentity(identity);
11700 }
11701 }
11702
11703 /**
11704 * Unregister RCS provisioning callback.
11705 */
11706 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011707 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011708 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011709 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011710 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011711 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11712 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011713
11714 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11715 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11716 }
joonhunshin4ac60942023-11-15 15:23:39 +000011717
11718 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11719 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11720 Binder.getCallingUserHandle())) {
11721 if (!isImsAvailableOnDevice()) {
11722 // operation failed silently
11723 Rlog.w(LOG_TAG, "IMS not available on device.");
11724 return;
11725 }
11726 } else {
11727 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11728 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11729 "unregisterRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011730 }
11731
11732 final long identity = Binder.clearCallingIdentity();
11733 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011734 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011735 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011736 } finally {
11737 Binder.restoreCallingIdentity(identity);
11738 }
11739 }
11740
11741 /**
11742 * trigger RCS reconfiguration.
11743 */
11744 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011745 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11746 "triggerRcsReconfiguration",
11747 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011748
11749 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11750 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11751 }
joonhunshin4ac60942023-11-15 15:23:39 +000011752 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11753 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11754 Binder.getCallingUserHandle())) {
11755 if (!isImsAvailableOnDevice()) {
11756 // ProvisioningManager can not handle ServiceSpecificException.
11757 // Throw the IllegalStateException and annotate ProvisioningManager.
11758 throw new IllegalStateException("IMS not available on device.");
11759 }
11760 } else {
11761 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11762 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011763 }
11764
11765 final long identity = Binder.clearCallingIdentity();
11766 try {
11767 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11768 } finally {
11769 Binder.restoreCallingIdentity(identity);
11770 }
11771 }
11772
11773 /**
11774 * Provide the client configuration parameters of the RCS application.
11775 */
11776 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011777 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11778 "setRcsClientConfiguration",
11779 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011780
11781 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11782 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11783 }
joonhunshin4ac60942023-11-15 15:23:39 +000011784 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11785 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11786 Binder.getCallingUserHandle())) {
11787 if (!isImsAvailableOnDevice()) {
11788 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11789 "IMS not available on device.");
11790 }
11791 } else {
11792 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11793 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011794 }
11795
11796 final long identity = Binder.clearCallingIdentity();
11797
11798 try {
11799 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11800 if (configBinder == null) {
11801 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011802 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11803 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011804 } else {
11805 configBinder.setRcsClientConfiguration(rcc);
11806 }
joonhunshin3e154242021-09-17 06:33:39 +000011807
11808 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11809 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011810 } catch (RemoteException e) {
11811 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011812 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11813 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011814 } finally {
11815 Binder.restoreCallingIdentity(identity);
11816 }
11817 }
11818
11819 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011820 * Enables or disables the test mode for RCS VoLTE single registration.
11821 */
11822 @Override
11823 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11824 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11825 "setRcsSingleRegistrationTestModeEnabled");
11826
11827 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11828 }
11829
11830 /**
11831 * Gets the test mode for RCS VoLTE single registration.
11832 */
11833 @Override
11834 public boolean getRcsSingleRegistrationTestModeEnabled() {
11835 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11836 "getRcsSingleRegistrationTestModeEnabled");
11837
11838 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11839 }
11840
11841 /**
Hui Wang761a6682020-10-31 05:12:53 +000011842 * Overrides the config of RCS VoLTE single registration enabled for the device.
11843 */
11844 @Override
11845 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11846 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11847 "setDeviceSingleRegistrationEnabledOverride");
11848 enforceModifyPermission();
11849
11850 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11851 : Boolean.parseBoolean(enabledStr);
11852 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011853 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011854 }
11855
11856 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011857 * Sends a device to device communication message. Only usable via shell.
11858 * @param message message to send.
11859 * @param value message value.
11860 */
11861 @Override
11862 public void sendDeviceToDeviceMessage(int message, int value) {
11863 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011864 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011865 enforceModifyPermission();
11866
11867 final long identity = Binder.clearCallingIdentity();
11868 try {
11869 TelephonyConnectionService service =
11870 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11871 if (service == null) {
11872 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11873 return;
11874 }
11875 service.sendTestDeviceToDeviceMessage(message, value);
11876 } finally {
11877 Binder.restoreCallingIdentity(identity);
11878 }
11879 }
11880
Tyler Gunnbabbda02021-02-10 11:05:02 -080011881 /**
11882 * Sets the specified device to device transport active.
11883 * @param transport The transport to set active.
11884 */
11885 @Override
11886 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11887 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11888 "setActiveDeviceToDeviceTransport");
11889 enforceModifyPermission();
11890
11891 final long identity = Binder.clearCallingIdentity();
11892 try {
11893 TelephonyConnectionService service =
11894 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11895 if (service == null) {
11896 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11897 return;
11898 }
11899 service.setActiveDeviceToDeviceTransport(transport);
11900 } finally {
11901 Binder.restoreCallingIdentity(identity);
11902 }
11903 }
Tyler Gunn92479152021-01-20 16:30:10 -080011904
Tyler Gunnd4339262021-05-03 14:46:49 -070011905 @Override
11906 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11907 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11908 "setDeviceToDeviceForceEnabled");
11909
11910 final long identity = Binder.clearCallingIdentity();
11911 try {
11912 Arrays.stream(PhoneFactory.getPhones()).forEach(
11913 p -> {
11914 Phone thePhone = p.getImsPhone();
11915 if (thePhone != null && thePhone instanceof ImsPhone) {
11916 ImsPhone imsPhone = (ImsPhone) thePhone;
11917 CallTracker tracker = imsPhone.getCallTracker();
11918 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11919 ImsPhoneCallTracker imsPhoneCallTracker =
11920 (ImsPhoneCallTracker) tracker;
11921 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11922 }
11923 }
11924 }
11925 );
11926 } finally {
11927 Binder.restoreCallingIdentity(identity);
11928 }
11929 }
11930
Tyler Gunn92479152021-01-20 16:30:10 -080011931 /**
Hui Wang761a6682020-10-31 05:12:53 +000011932 * Gets the config of RCS VoLTE single registration enabled for the device.
11933 */
11934 @Override
11935 public boolean getDeviceSingleRegistrationEnabled() {
11936 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11937 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11938 }
11939
11940 /**
11941 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11942 */
11943 @Override
11944 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11945 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11946 "setCarrierSingleRegistrationEnabledOverride");
11947 enforceModifyPermission();
11948
11949 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11950 : Boolean.parseBoolean(enabledStr);
11951 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11952 subId, enabled);
11953 }
11954
11955 /**
11956 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11957 */
11958 @Override
11959 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11960 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11961 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11962 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011963
11964 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011965 * Overrides the ims feature validation result
11966 */
11967 @Override
11968 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11969 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11970 "setImsFeatureValidationOverride");
11971
11972 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11973 : Boolean.parseBoolean(enabledStr);
11974 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11975 subId, enabled);
11976 }
11977
11978 /**
11979 * Gets the ims feature validation override value
11980 */
11981 @Override
11982 public boolean getImsFeatureValidationOverride(int subId) {
11983 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11984 "getImsFeatureValidationOverride");
11985 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11986 }
11987
11988 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011989 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11990 * their mobile plan.
11991 */
11992 @Override
11993 public String getMobileProvisioningUrl() {
11994 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
11995 final long identity = Binder.clearCallingIdentity();
11996 try {
11997 return getDefaultPhone().getMobileProvisioningUrl();
11998 } finally {
11999 Binder.restoreCallingIdentity(identity);
12000 }
12001 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012002
James.cf Linbcdf8b32021-01-14 16:44:13 +080012003 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080012004 * Get the EAB contact from the EAB database.
12005 */
12006 @Override
12007 public String getContactFromEab(String contact) {
12008 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
12009 enforceModifyPermission();
12010 final long identity = Binder.clearCallingIdentity();
12011 try {
12012 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
12013 } finally {
12014 Binder.restoreCallingIdentity(identity);
12015 }
12016 }
12017
12018 /**
Calvin Pana1434322021-07-01 19:27:01 +080012019 * Get the EAB capability from the EAB database.
12020 */
12021 @Override
12022 public String getCapabilityFromEab(String contact) {
12023 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
12024 enforceModifyPermission();
12025 final long identity = Binder.clearCallingIdentity();
12026 try {
12027 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
12028 } finally {
12029 Binder.restoreCallingIdentity(identity);
12030 }
12031 }
12032
12033 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080012034 * Remove the EAB contacts from the EAB database.
12035 */
12036 @Override
12037 public int removeContactFromEab(int subId, String contacts) {
12038 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
12039 enforceModifyPermission();
12040 final long identity = Binder.clearCallingIdentity();
12041 try {
12042 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
12043 } finally {
12044 Binder.restoreCallingIdentity(identity);
12045 }
12046 }
12047
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012048 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080012049 public boolean getDeviceUceEnabled() {
12050 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
12051 final long identity = Binder.clearCallingIdentity();
12052 try {
12053 return mApp.getDeviceUceEnabled();
12054 } finally {
12055 Binder.restoreCallingIdentity(identity);
12056 }
12057 }
12058
12059 @Override
12060 public void setDeviceUceEnabled(boolean isEnabled) {
12061 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
12062 final long identity = Binder.clearCallingIdentity();
12063 try {
12064 mApp.setDeviceUceEnabled(isEnabled);
12065 } finally {
12066 Binder.restoreCallingIdentity(identity);
12067 }
12068 }
12069
Brad Ebinger14d467f2021-02-12 06:18:28 +000012070 /**
12071 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
12072 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12073 */
12074 // Used for SHELL command only right now.
12075 @Override
12076 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
12077 List<String> featureTags) {
12078 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12079 "addUceRegistrationOverrideShell");
12080 final long identity = Binder.clearCallingIdentity();
12081 try {
12082 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
12083 new ArraySet<>(featureTags));
12084 } catch (ImsException e) {
12085 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12086 } finally {
12087 Binder.restoreCallingIdentity(identity);
12088 }
12089 }
12090
12091 /**
12092 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
12093 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12094 */
12095 // Used for SHELL command only right now.
12096 @Override
12097 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
12098 List<String> featureTags) {
12099 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12100 "removeUceRegistrationOverrideShell");
12101 final long identity = Binder.clearCallingIdentity();
12102 try {
12103 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
12104 new ArraySet<>(featureTags));
12105 } catch (ImsException e) {
12106 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12107 } finally {
12108 Binder.restoreCallingIdentity(identity);
12109 }
12110 }
12111
12112 /**
12113 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
12114 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12115 */
12116 // Used for SHELL command only right now.
12117 @Override
12118 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
12119 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12120 "clearUceRegistrationOverrideShell");
12121 final long identity = Binder.clearCallingIdentity();
12122 try {
12123 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
12124 } catch (ImsException e) {
12125 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12126 } finally {
12127 Binder.restoreCallingIdentity(identity);
12128 }
12129 }
12130
12131 /**
12132 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12133 */
12134 // Used for SHELL command only right now.
12135 @Override
12136 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
12137 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12138 "getLatestRcsContactUceCapabilityShell");
12139 final long identity = Binder.clearCallingIdentity();
12140 try {
12141 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
12142 } catch (ImsException e) {
12143 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12144 } finally {
12145 Binder.restoreCallingIdentity(identity);
12146 }
12147 }
12148
12149 /**
12150 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
12151 * device does not have an active PUBLISH.
12152 */
12153 // Used for SHELL command only right now.
12154 @Override
12155 public String getLastUcePidfXmlShell(int subId) {
12156 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
12157 final long identity = Binder.clearCallingIdentity();
12158 try {
12159 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
12160 } catch (ImsException e) {
12161 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12162 } finally {
12163 Binder.restoreCallingIdentity(identity);
12164 }
12165 }
12166
James.cf Line8713a42021-04-29 16:04:26 +080012167 /**
12168 * Remove UCE requests cannot be sent to the network status.
12169 */
12170 // Used for SHELL command only right now.
12171 @Override
12172 public boolean removeUceRequestDisallowedStatus(int subId) {
12173 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
12174 final long identity = Binder.clearCallingIdentity();
12175 try {
12176 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
12177 } catch (ImsException e) {
12178 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12179 } finally {
12180 Binder.restoreCallingIdentity(identity);
12181 }
12182 }
12183
James.cf Lin18bb9002021-05-25 01:37:38 +080012184 /**
12185 * Remove UCE requests cannot be sent to the network status.
12186 */
12187 // Used for SHELL command only.
12188 @Override
12189 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
12190 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
12191 final long identity = Binder.clearCallingIdentity();
12192 try {
12193 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
12194 } catch (ImsException e) {
12195 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12196 } finally {
12197 Binder.restoreCallingIdentity(identity);
12198 }
12199 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000012200
James.cf Lin4b784aa2021-01-31 03:25:15 +080012201 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012202 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12203 String callingPackage) {
12204 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12205 mApp, subId, "setSignalStrengthUpdateRequest");
12206
joonhunshin4ac60942023-11-15 15:23:39 +000012207 enforceTelephonyFeatureWithException(callingPackage,
12208 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest");
12209
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012210 final int callingUid = Binder.getCallingUid();
12211 // Verify that tha callingPackage belongs to the calling UID
12212 mApp.getSystemService(AppOpsManager.class)
12213 .checkPackage(callingUid, callingPackage);
12214
Rambo Wang3607f502021-02-01 21:51:40 -080012215 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012216
12217 final long identity = Binder.clearCallingIdentity();
12218 try {
12219 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
12220 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12221
12222 if (result instanceof IllegalStateException) {
12223 throw (IllegalStateException) result;
12224 }
12225 } finally {
12226 Binder.restoreCallingIdentity(identity);
12227 }
12228 }
12229
12230 @Override
12231 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12232 String callingPackage) {
12233 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12234 mApp, subId, "clearSignalStrengthUpdateRequest");
12235
joonhunshin4ac60942023-11-15 15:23:39 +000012236 enforceTelephonyFeatureWithException(callingPackage,
12237 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest");
12238
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012239 final int callingUid = Binder.getCallingUid();
12240 // Verify that tha callingPackage belongs to the calling UID
12241 mApp.getSystemService(AppOpsManager.class)
12242 .checkPackage(callingUid, callingPackage);
12243
12244 final long identity = Binder.clearCallingIdentity();
12245 try {
12246 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
12247 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12248
12249 if (result instanceof IllegalStateException) {
12250 throw (IllegalStateException) result;
12251 }
12252 } finally {
12253 Binder.restoreCallingIdentity(identity);
12254 }
12255 }
12256
Rambo Wang3607f502021-02-01 21:51:40 -080012257 private static void validateSignalStrengthUpdateRequest(Context context,
12258 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012259 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
12260 // phone/system process do not have further restriction on request
12261 return;
12262 }
12263
12264 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080012265 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012266 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080012267 context.enforceCallingOrSelfPermission(
12268 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
12269 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012270 }
12271
12272 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000012273 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012274 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012275 || info.isEnabled()) {
12276 throw new IllegalArgumentException(
12277 "Only system can set hide fields in SignalThresholdInfo");
12278 }
12279
12280 // Thresholds length for each RAN need in range. This has been validated in
12281 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
12282 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
12283 final int[] thresholds = info.getThresholds();
12284 Objects.requireNonNull(thresholds);
12285 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
12286 || thresholds.length
12287 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
12288 throw new IllegalArgumentException(
12289 "thresholds length is out of range: " + thresholds.length);
12290 }
12291 }
12292 }
SongFerngWang8236caa2021-01-17 21:51:44 +080012293
12294 /**
12295 * Gets the current phone capability.
12296 *
12297 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
12298 * @return the PhoneCapability which describes the data connection capability of modem.
12299 * It's used to evaluate possible phone config change, for example from single
12300 * SIM device to multi-SIM device.
12301 */
12302 @Override
12303 public PhoneCapability getPhoneCapability() {
12304 enforceReadPrivilegedPermission("getPhoneCapability");
joonhunshin4ac60942023-11-15 15:23:39 +000012305
12306 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12307 PackageManager.FEATURE_TELEPHONY, "getPhoneCapability");
12308
SongFerngWang8236caa2021-01-17 21:51:44 +080012309 final long identity = Binder.clearCallingIdentity();
12310 try {
12311 return mPhoneConfigurationManager.getCurrentPhoneCapability();
12312 } finally {
12313 Binder.restoreCallingIdentity(identity);
12314 }
12315 }
Michele Berionne5e411512020-11-13 02:36:59 +000012316
12317 /**
12318 * Prepare TelephonyManager for an unattended reboot. The reboot is
12319 * required to be done shortly after the API is invoked.
12320 */
12321 @Override
12322 @TelephonyManager.PrepareUnattendedRebootResult
12323 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012324 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000012325 enforceRebootPermission();
12326
joonhunshin4ac60942023-11-15 15:23:39 +000012327 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12328 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot");
12329
Michele Berionne5e411512020-11-13 02:36:59 +000012330 final long identity = Binder.clearCallingIdentity();
12331 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012332 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000012333 } finally {
12334 Binder.restoreCallingIdentity(identity);
12335 }
12336 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012337
12338 /**
12339 * Request to get the current slicing configuration including URSP rules and
12340 * NSSAIs (configured, allowed and rejected).
12341 *
12342 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
12343 */
12344 @Override
12345 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000012346 TelephonyPermissions
12347 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
12348 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012349
joonhunshin4ac60942023-11-15 15:23:39 +000012350 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12351 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
12352 "getSlicingConfig");
12353
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012354 final long identity = Binder.clearCallingIdentity();
12355 try {
12356 Phone phone = getDefaultPhone();
12357 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
12358 } finally {
12359 Binder.restoreCallingIdentity(identity);
12360 }
12361 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012362
12363 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070012364 * Check whether the given premium capability is available for purchase from the carrier.
12365 *
12366 * @param capability The premium capability to check.
12367 * @param subId The subId to check the premium capability for.
12368 *
12369 * @return Whether the given premium capability is available to purchase.
12370 */
12371 @Override
12372 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
12373 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12374 mApp, "isPremiumCapabilityAvailableForPurchase")) {
12375 log("Premium capability "
12376 + TelephonyManager.convertPremiumCapabilityToString(capability)
12377 + " is not available for purchase due to missing permissions.");
12378 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
12379 + "permission READ_BASIC_PHONE_STATE.");
12380 }
12381
joonhunshin4ac60942023-11-15 15:23:39 +000012382 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12383 PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase");
12384
Sarah Chin2ec39f62022-08-31 17:03:26 -070012385 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080012386 if (phone == null) {
12387 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12388 return false;
12389 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012390 final long identity = Binder.clearCallingIdentity();
12391 try {
Sarah Chincc5446f2023-10-23 17:57:19 -070012392 return SlicePurchaseController.getInstance(phone, mFeatureFlags)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012393 .isPremiumCapabilityAvailableForPurchase(capability);
12394 } finally {
12395 Binder.restoreCallingIdentity(identity);
12396 }
12397 }
12398
12399 /**
12400 * Purchase the given premium capability from the carrier.
12401 *
12402 * @param capability The premium capability to purchase.
12403 * @param callback The result of the purchase request.
12404 * @param subId The subId to purchase the premium capability for.
12405 */
12406 @Override
12407 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12408 log("purchasePremiumCapability: capability="
12409 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12410 + getCurrentPackageName());
12411
12412 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12413 mApp, "purchasePremiumCapability")) {
12414 log("purchasePremiumCapability "
12415 + TelephonyManager.convertPremiumCapabilityToString(capability)
12416 + " failed due to missing permissions.");
12417 throw new SecurityException("purchasePremiumCapability requires permission "
12418 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012419 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12420 mApp, "purchasePremiumCapability")) {
12421 log("purchasePremiumCapability "
12422 + TelephonyManager.convertPremiumCapabilityToString(capability)
12423 + " failed due to missing permissions.");
12424 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012425 }
12426
joonhunshin4ac60942023-11-15 15:23:39 +000012427 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12428 PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability");
12429
Sarah Chin2ec39f62022-08-31 17:03:26 -070012430 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012431 if (phone == null) {
12432 try {
12433 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12434 callback.accept(result);
12435 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12436 } catch (RemoteException e) {
12437 String logStr = "Purchase premium capability "
12438 + TelephonyManager.convertPremiumCapabilityToString(capability)
12439 + " failed due to RemoteException handling null phone: " + e;
12440 if (DBG) log(logStr);
12441 AnomalyReporter.reportAnomaly(
12442 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12443 }
12444 return;
12445 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012446
12447 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012448 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012449 callingProcess = mApp.getPackageManager().getApplicationInfo(
12450 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070012451 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012452 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012453 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012454
12455 boolean isVisible = false;
12456 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12457 if (am != null) {
12458 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12459 if (processes != null) {
12460 for (ActivityManager.RunningAppProcessInfo process : processes) {
12461 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070012462 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080012463 if (process.processName.equals(callingProcess) && process.importance
12464 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12465 isVisible = true;
12466 break;
12467 }
12468 }
12469 }
12470 }
12471
12472 if (!isVisible) {
12473 try {
12474 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12475 callback.accept(result);
12476 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12477 } catch (RemoteException e) {
12478 String logStr = "Purchase premium capability "
12479 + TelephonyManager.convertPremiumCapabilityToString(capability)
12480 + " failed due to RemoteException handling background application: " + e;
12481 if (DBG) log(logStr);
12482 AnomalyReporter.reportAnomaly(
12483 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12484 }
12485 return;
12486 }
12487
Sarah Chin71b3a852022-09-28 15:54:19 -070012488 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012489 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012490 }
12491
12492 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012493 * Register an IMS connection state callback
12494 */
12495 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012496 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12497 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012498 if (feature == ImsFeature.FEATURE_MMTEL) {
12499 // ImsMmTelManager
12500 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12501 TelephonyPermissions
12502 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12503 mApp, subId, "registerImsStateCallback");
12504 } else if (feature == ImsFeature.FEATURE_RCS) {
12505 // ImsRcsManager or SipDelegateManager
12506 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12507 Binder.getCallingUid(), "registerImsStateCallback",
12508 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12509 Manifest.permission.READ_PRECISE_PHONE_STATE,
12510 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12511 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12512 }
12513
12514 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12515 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12516 "IMS not available on device.");
12517 }
12518
12519 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12520 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12521 }
12522
12523 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12524 if (controller == null) {
12525 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12526 "IMS not available on device.");
12527 }
12528
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012529 if (callingPackage == null) {
12530 callingPackage = getCurrentPackageName();
12531 }
12532
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012533 final long token = Binder.clearCallingIdentity();
12534 try {
12535 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012536 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012537 } catch (ImsException e) {
12538 throw new ServiceSpecificException(e.getCode());
12539 } finally {
12540 Binder.restoreCallingIdentity(token);
12541 }
12542 }
12543
12544 /**
12545 * Unregister an IMS connection state callback
12546 */
12547 @Override
12548 public void unregisterImsStateCallback(IImsStateCallback cb) {
12549 final long token = Binder.clearCallingIdentity();
12550 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12551 if (controller == null) {
12552 return;
12553 }
12554 try {
12555 controller.unregisterImsStateCallback(cb);
12556 } finally {
12557 Binder.restoreCallingIdentity(token);
12558 }
12559 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012560
12561 /**
12562 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12563 *
12564 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012565 * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012566 * SecurityException.
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012567 *
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012568 * If there is current registered network this value will be same as the registered cell
12569 * identity. If the device goes out of service the previous cell identity is cached and
12570 * will be returned. If the cache age of the Cell identity is more than 24 hours
12571 * it will be cleared and null will be returned.
12572 *
12573 */
12574 @Override
12575 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12576 String callingFeatureId) {
12577 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12578 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12579 LocationAccessPolicy.checkLocationPermission(mApp,
12580 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12581 .setCallingPackage(callingPackage)
12582 .setCallingFeatureId(callingFeatureId)
12583 .setCallingPid(Binder.getCallingPid())
12584 .setCallingUid(Binder.getCallingUid())
12585 .setMethod("getLastKnownCellIdentity")
12586 .setLogAsInfo(true)
12587 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12588 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12589 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12590 .build());
12591
12592 boolean hasFinePermission =
12593 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12594 if (!hasFinePermission
12595 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12596 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012597 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012598 }
12599
12600 final long identity = Binder.clearCallingIdentity();
12601 try {
Ling Mac28f0212023-03-24 16:07:15 -070012602 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012603 if (sst == null) return null;
12604 return sst.getLastKnownCellIdentity();
12605 } finally {
12606 Binder.restoreCallingIdentity(identity);
12607 }
12608 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012609
jimsun3b9ccac2021-10-26 15:01:23 +080012610 /**
12611 * Sets the modem service class Name that Telephony will bind to.
12612 *
12613 * @param serviceName The class name of the modem service.
12614 * @return true if the operation is succeed, otherwise false.
12615 */
12616 public boolean setModemService(String serviceName) {
12617 Log.d(LOG_TAG, "setModemService - " + serviceName);
12618 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12619 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012620 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12621 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012622 return mPhoneConfigurationManager.setModemService(serviceName);
12623 }
12624
12625 /**
12626 * Return the class name of the currently bounded modem service.
12627 *
12628 * @return the class name of the modem service.
12629 */
12630 public String getModemService() {
12631 String result;
12632 Log.d(LOG_TAG, "getModemService");
12633 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12634 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012635 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012636 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12637 "getModemService");
12638 result = mPhoneConfigurationManager.getModemService();
12639 Log.d(LOG_TAG, "result = " + result);
12640 return result;
12641 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012642
Hakjun Choi3ee81112023-12-19 15:40:58 +000012643 /**
12644 * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources,
12645 * including carrier config, entitlement server, and config update.
12646 *
12647 * @param subId subId The subscription ID of the carrier.
12648 *
12649 * @return List of plmns for carrier satellite service. If no plmn is available, empty list will
12650 * be returned.
12651 *
12652 * @throws SecurityException if the caller doesn't have the required permission.
12653 */
Hakjun Choi74c16be2024-01-19 08:18:09 +000012654 @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) {
12655 enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier");
Hakjun Choi3ee81112023-12-19 15:40:58 +000012656 final long identity = Binder.clearCallingIdentity();
12657 try {
Hakjun Choi74c16be2024-01-19 08:18:09 +000012658 return mSatelliteController.getSatellitePlmnsForCarrier(subId);
Hakjun Choi3ee81112023-12-19 15:40:58 +000012659 } finally {
12660 Binder.restoreCallingIdentity(identity);
12661 }
12662 }
12663
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012664 @Override
12665 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12666 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12667 mApp.enforceCallingOrSelfPermission(
12668 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12669 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12670
12671 final long identity = Binder.clearCallingIdentity();
12672 try {
12673 Phone phone = getPhone(subId);
12674 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012675 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12676 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012677 phone.setVoiceServiceStateOverride(hasService);
12678 } finally {
12679 Binder.restoreCallingIdentity(identity);
12680 }
12681 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012682
12683 /**
12684 * set removable eSIM as default eUICC.
12685 *
12686 * @hide
12687 */
12688 @Override
12689 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12690 enforceModifyPermission();
12691 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12692
12693 final long identity = Binder.clearCallingIdentity();
12694 try {
12695 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12696 } finally {
12697 Binder.restoreCallingIdentity(identity);
12698 }
12699 }
12700
12701 /**
12702 * Returns whether the removable eSIM is default eUICC or not.
12703 *
12704 * @hide
12705 */
12706 @Override
12707 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12708 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12709 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12710
12711 final long identity = Binder.clearCallingIdentity();
12712 try {
12713 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12714 } finally {
12715 Binder.restoreCallingIdentity(identity);
12716 }
12717 }
12718
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012719 /**
12720 * Get the component name of the default app to direct respond-via-message intent for the
12721 * user associated with this subscription, update the cache if there is no respond-via-message
12722 * application currently configured for this user.
12723 * @return component name of the app and class to direct Respond Via Message intent to, or
12724 * {@code null} if the functionality is not supported.
12725 * @hide
12726 */
12727 @Override
12728 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12729 boolean updateIfNeeded) {
12730 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012731
joonhunshin4ac60942023-11-15 15:23:39 +000012732 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12733 PackageManager.FEATURE_TELEPHONY_MESSAGING,
12734 "getDefaultRespondViaMessageApplication");
12735
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012736 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12737
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012738 UserHandle userHandle = null;
12739 final long identity = Binder.clearCallingIdentity();
12740 try {
12741 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12742 } finally {
12743 Binder.restoreCallingIdentity(identity);
12744 }
12745 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12746 updateIfNeeded, userHandle);
12747 }
Jack Yuf5badd92022-12-08 00:50:53 -080012748
12749 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012750 * Set whether the device is able to connect with null ciphering or integrity
12751 * algorithms. This is a global setting and will apply to all active subscriptions
12752 * and all new subscriptions after this.
12753 *
12754 * @param enabled when true, null cipher and integrity algorithms are allowed.
12755 * @hide
12756 */
12757 @Override
12758 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12759 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12760 enforceModifyPermission();
12761 checkForNullCipherAndIntegritySupport();
12762
12763 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12764 // for listening to these preference changes and applying them immediately.
12765 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12766 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12767 editor.apply();
12768
12769 for (Phone phone: PhoneFactory.getPhones()) {
12770 phone.handleNullCipherEnabledChange();
12771 }
12772 }
12773
12774
12775 /**
12776 * Get whether the device is able to connect with null ciphering or integrity
12777 * algorithms. Note that this retrieves the phone-global preference and not
12778 * the state of the radio.
12779 *
12780 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12781 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12782 * version for this feature.
12783 * @hide
12784 */
12785 @Override
12786 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12787 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12788 enforceReadPermission();
12789 checkForNullCipherAndIntegritySupport();
12790 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12791 }
12792
12793 private void checkForNullCipherAndIntegritySupport() {
12794 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12795 throw new UnsupportedOperationException(
12796 "Null cipher and integrity operations require HAL 2.1 or above");
12797 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012798 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12799 throw new UnsupportedOperationException(
12800 "Null cipher and integrity operations unsupported by modem");
12801 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012802 }
12803
Gil Cukierman06403e12023-11-29 16:33:03 +000012804 private void checkForIdentifierDisclosureNotificationSupport() {
12805 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) {
12806 throw new UnsupportedOperationException(
12807 "Cellular identifier disclosure transparency operations require HAL 2.2 or "
12808 + "above");
12809 }
12810 if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) {
12811 throw new UnsupportedOperationException(
12812 "Cellular identifier disclosure transparency operations unsupported by modem");
12813 }
12814 }
12815
Michael Groover826b71d2023-12-21 22:08:06 -060012816 private void checkForNullCipherNotificationSupport() {
12817 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) {
12818 throw new UnsupportedOperationException(
12819 "Null cipher notification operations require HAL 2.2 or above");
12820 }
12821 if (!getDefaultPhone().isNullCipherNotificationSupported()) {
12822 throw new UnsupportedOperationException(
12823 "Null cipher notification operations unsupported by modem");
12824 }
12825 }
12826
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012827 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012828 * Get the SIM state for the slot index.
12829 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12830 *
12831 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12832 */
12833 @Override
12834 @SimState
12835 public int getSimStateForSlotIndex(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +000012836 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12837 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex");
12838
Jack Yuf5badd92022-12-08 00:50:53 -080012839 IccCardConstants.State simState;
12840 if (slotIndex < 0) {
12841 simState = IccCardConstants.State.UNKNOWN;
12842 } else {
12843 Phone phone = null;
12844 try {
12845 phone = PhoneFactory.getPhone(slotIndex);
12846 } catch (IllegalStateException e) {
12847 // ignore
12848 }
12849 if (phone == null) {
12850 simState = IccCardConstants.State.UNKNOWN;
12851 } else {
12852 IccCard icc = phone.getIccCard();
12853 if (icc == null) {
12854 simState = IccCardConstants.State.UNKNOWN;
12855 } else {
12856 simState = icc.getState();
12857 }
12858 }
12859 }
12860 return simState.ordinal();
12861 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012862
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012863 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
12864 boolean enableLogcat,
12865 long logcatStartTimestampMillis, boolean enableTelecomDump,
12866 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012867 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012868 TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder =
12869 new TelephonyManager.EmergencyCallDiagnosticData.Builder();
12870 ecdDataBuilder
12871 .setTelecomDumpsysCollectionEnabled(enableTelecomDump)
12872 .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012873 if (enableLogcat) {
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012874 ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012875 }
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012876 TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build();
12877 Log.d(LOG_TAG, "persisting with Params " + ecdData.toString());
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012878 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
12879 Executors.newCachedThreadPool(), db,
12880 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012881 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012882 }
12883
12884 /**
12885 * Request telephony to persist state for debugging emergency call failures.
12886 *
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012887 * @param dropboxTag Tag to use when persisting data to dropbox service.
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012888 * @param enableLogcat whether to collect logcat output
12889 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
12890 * @param enableTelecomDump whether to collect telecom dumpsys
12891 * @param enableTelephonyDump whether to collect telephony dumpsys
12892 */
12893 @Override
12894 @RequiresPermission(android.Manifest.permission.DUMP)
12895 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
12896 long logcatStartTimestampMillis, boolean enableTelecomDump,
12897 boolean enableTelephonyDump) {
12898 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
12899 "persistEmergencyCallDiagnosticData");
12900 final long identity = Binder.clearCallingIdentity();
12901 try {
12902 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
12903 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
12904
12905 } finally {
12906 Binder.restoreCallingIdentity(identity);
12907 }
12908 }
12909
Hui Wang9b5793a2022-12-05 14:38:06 -060012910 /**
12911 * Get current cell broadcast ranges.
12912 */
12913 @Override
12914 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12915 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12916 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12917 "getCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012918
12919 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12920 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges");
12921
Hui Wang9b5793a2022-12-05 14:38:06 -060012922 final long identity = Binder.clearCallingIdentity();
12923 try {
12924 return getPhone(subId).getCellBroadcastIdRanges();
12925 } finally {
12926 Binder.restoreCallingIdentity(identity);
12927 }
12928 }
12929
12930 /**
12931 * Set reception of cell broadcast messages with the list of the given ranges
12932 *
12933 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12934 */
12935 @Override
12936 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12937 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12938 @Nullable IIntegerConsumer callback) {
12939 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12940 "setCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012941
12942 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12943 PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges");
12944
Hui Wang9b5793a2022-12-05 14:38:06 -060012945 final long identity = Binder.clearCallingIdentity();
12946 try {
12947 Phone phone = getPhoneFromSubId(subId);
12948 if (DBG) {
12949 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12950 }
12951 phone.setCellBroadcastIdRanges(ranges, result -> {
12952 if (callback != null) {
12953 try {
12954 callback.accept(result);
12955 } catch (RemoteException e) {
12956 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12957 }
12958 }
12959 });
12960 } finally {
12961 Binder.restoreCallingIdentity(identity);
12962 }
12963 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012964
12965 /**
12966 * Returns whether the device supports the domain selection service.
12967 *
12968 * @return {@code true} if the device supports the domain selection service.
12969 */
12970 @Override
12971 public boolean isDomainSelectionSupported() {
12972 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12973 "isDomainSelectionSupported");
12974
12975 final long identity = Binder.clearCallingIdentity();
12976 try {
12977 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12978 } finally {
12979 Binder.restoreCallingIdentity(identity);
12980 }
12981 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012982
12983 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012984 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
12985 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
12986 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080012987 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012988 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chinabf081b2023-03-09 23:00:57 -080012989 * @param enableSatellite {@code true} to enable the satellite modem and
12990 * {@code false} to disable.
12991 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
Thomas Nguyena8062672024-02-05 14:18:19 -080012992 * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise.
Sarah Chinabf081b2023-03-09 23:00:57 -080012993 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080012994 *
12995 * @throws SecurityException if the caller doesn't have the required permission.
12996 */
12997 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012998 public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode,
Thomas Nguyena8062672024-02-05 14:18:19 -080012999 boolean isEmergency, @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013000 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013001 if (enableSatellite) {
13002 ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) {
13003 @Override
13004 protected void onReceiveResult(int resultCode, Bundle resultData) {
13005 Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode
13006 + ", resultData=" + resultData);
13007 boolean isAllowed = false;
13008 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(
13009 callback::accept);
13010 if (resultCode == SATELLITE_RESULT_SUCCESS) {
13011 if (resultData != null
13012 && resultData.containsKey(KEY_SATELLITE_COMMUNICATION_ALLOWED)) {
13013 isAllowed = resultData.getBoolean(KEY_SATELLITE_COMMUNICATION_ALLOWED);
13014 } else {
13015 loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist.");
13016 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013017 } else {
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013018 result.accept(resultCode);
13019 return;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013020 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013021 if (isAllowed) {
13022 mSatelliteController.requestSatelliteEnabled(
13023 subId, enableSatellite, enableDemoMode, callback);
13024 } else {
13025 result.accept(SATELLITE_RESULT_ACCESS_BARRED);
13026 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013027 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013028 };
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013029 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013030 subId, resultReceiver);
13031 } else {
13032 // No need to check if satellite is allowed at current location when disabling satellite
13033 mSatelliteController.requestSatelliteEnabled(
13034 subId, enableSatellite, enableDemoMode, callback);
13035 }
Sarah Chin503828c2023-02-01 23:54:20 -080013036 }
13037
13038 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013039 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080013040 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013041 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013042 * @param result The result receiver that returns whether the satellite modem is enabled
13043 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013044 *
13045 * @throws SecurityException if the caller doesn't have the required permission.
13046 */
13047 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013048 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
13049 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013050 mSatelliteController.requestIsSatelliteEnabled(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013051 }
13052
13053 /**
Sarah Chin43457982023-02-15 17:50:38 -080013054 * Request to get whether the satellite service demo mode is enabled.
13055 *
13056 * @param subId The subId of the subscription to check whether the satellite demo mode
13057 * is enabled for.
13058 * @param result The result receiver that returns whether the satellite demo mode is enabled
13059 * if the request is successful or an error code if the request failed.
13060 *
13061 * @throws SecurityException if the caller doesn't have the required permission.
13062 */
13063 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013064 public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
13065 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
13066 mSatelliteController.requestIsDemoModeEnabled(subId, result);
Sarah Chin43457982023-02-15 17:50:38 -080013067 }
13068
13069 /**
Thomas Nguyena8062672024-02-05 14:18:19 -080013070 * Request to get whether the satellite service is enabled with emergency mode.
13071 *
13072 * @param subId The subId of the subscription to check whether the satellite demo mode
13073 * is enabled for.
13074 * @param result The result receiver that returns whether the satellite emergency mode is
13075 * enabled if the request is successful or an error code if the request failed.
13076 *
13077 * @throws SecurityException if the caller doesn't have the required permission.
13078 */
13079 @Override
13080 public void requestIsEmergencyModeEnabled(int subId, @NonNull ResultReceiver result) {
13081 enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled");
13082 result.send(SATELLITE_RESULT_REQUEST_NOT_SUPPORTED, null);
13083 }
13084
13085 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013086 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080013087 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013088 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013089 * @param result The result receiver that returns whether the satellite service is supported on
13090 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013091 */
13092 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013093 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013094 mSatelliteController.requestIsSatelliteSupported(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013095 }
13096
13097 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013098 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080013099 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013100 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013101 * @param result The result receiver that returns the {@link SatelliteCapabilities}
13102 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013103 *
13104 * @throws SecurityException if the caller doesn't have required permission.
13105 */
13106 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013107 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
13108 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013109 mSatelliteController.requestSatelliteCapabilities(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013110 }
13111
13112 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013113 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013114 * This can be called by the pointing UI when the user starts pointing to the satellite.
13115 * Modem should continue to report the pointing input as the device or satellite moves.
13116 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013117 * @param subId The subId of the subscription to start satellite transmission updates for.
13118 * @param resultCallback The callback to get the result of the request.
13119 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080013120 *
13121 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013122 */
13123 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013124 public void startSatelliteTransmissionUpdates(int subId,
13125 @NonNull IIntegerConsumer resultCallback,
13126 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13127 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
13128 mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080013129 }
13130
13131 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013132 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013133 * This can be called by the pointing UI when the user stops pointing to the satellite.
13134 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013135 * @param subId The subId of the subscription to stop satellite transmission updates for.
13136 * @param resultCallback The callback to get the result of the request.
13137 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
13138 * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080013139 *
13140 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013141 */
13142 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013143 public void stopSatelliteTransmissionUpdates(int subId,
13144 @NonNull IIntegerConsumer resultCallback,
13145 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13146 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
13147 mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013148 }
13149
13150 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013151 * Register the subscription with a satellite provider.
13152 * This is needed to register the subscription if the provider allows dynamic registration.
13153 *
13154 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013155 * @param token The token to be used as a unique identifier for provisioning with satellite
13156 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013157 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080013158 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013159 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013160 * @return The signal transport used by the caller to cancel the provision request,
13161 * or {@code null} if the request failed.
13162 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013163 * @throws SecurityException if the caller doesn't have the required permission.
13164 */
13165 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013166 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013167 @NonNull String token, @NonNull byte[] provisionData,
13168 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013169 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013170 return mSatelliteController.provisionSatelliteService(subId, token, provisionData,
13171 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013172 }
13173
13174 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013175 * Unregister the device/subscription with the satellite provider.
13176 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013177 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013178 * should report as deprovisioned.
13179 *
13180 * @param subId The subId of the subscription to be deprovisioned.
13181 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080013182 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013183 *
13184 * @throws SecurityException if the caller doesn't have the required permission.
13185 */
13186 @Override
13187 public void deprovisionSatelliteService(int subId,
13188 @NonNull String token, @NonNull IIntegerConsumer callback) {
13189 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013190 mSatelliteController.deprovisionSatelliteService(subId, token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013191 }
13192
13193 /**
Sarah Chin43457982023-02-15 17:50:38 -080013194 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013195 *
Sarah Chin43457982023-02-15 17:50:38 -080013196 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013197 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013198 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013199 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013200 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013201 * @throws SecurityException if the caller doesn't have the required permission.
13202 */
13203 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013204 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
13205 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013206 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013207 return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013208 }
13209
13210 /**
Sarah Chin43457982023-02-15 17:50:38 -080013211 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013212 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013213 *
Sarah Chin43457982023-02-15 17:50:38 -080013214 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013215 * @param callback The callback that was passed to
13216 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013217 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013218 * @throws SecurityException if the caller doesn't have the required permission.
13219 */
13220 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013221 public void unregisterForSatelliteProvisionStateChanged(
13222 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013223 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013224 mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013225 }
13226
13227 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013228 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013229 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013230 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013231 * @param result The result receiver that returns whether the device is provisioned with a
13232 * satellite provider if the request is successful or an error code if the
13233 * request failed.
13234 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013235 * @throws SecurityException if the caller doesn't have the required permission.
13236 */
13237 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013238 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
13239 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013240 mSatelliteController.requestIsSatelliteProvisioned(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013241 }
13242
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013243 /**
Sarah Chin43457982023-02-15 17:50:38 -080013244 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013245 *
Sarah Chin43457982023-02-15 17:50:38 -080013246 * @param subId The subId of the subscription to register for satellite modem state changed.
13247 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080013248 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013249 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013250 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013251 * @throws SecurityException if the caller doesn't have the required permission.
13252 */
13253 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013254 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013255 @NonNull ISatelliteModemStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080013256 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013257 return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013258 }
13259
13260 /**
Sarah Chin43457982023-02-15 17:50:38 -080013261 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013262 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013263 *
Sarah Chin43457982023-02-15 17:50:38 -080013264 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080013265 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013266 * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013267 *
13268 * @throws SecurityException if the caller doesn't have the required permission.
13269 */
13270 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013271 public void unregisterForModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013272 @NonNull ISatelliteModemStateCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013273 enforceSatelliteCommunicationPermission("unregisterForModemStateChanged");
13274 mSatelliteController.unregisterForModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013275 }
13276
13277 /**
13278 * Register to receive incoming datagrams over satellite.
13279 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013280 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Sarah Chindf715ec2023-02-13 13:46:24 -080013281 * @param callback The callback to handle incoming datagrams over satellite.
13282 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013283 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013284 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013285 * @throws SecurityException if the caller doesn't have the required permission.
13286 */
13287 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013288 @SatelliteManager.SatelliteResult public int registerForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013289 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013290 enforceSatelliteCommunicationPermission("registerForIncomingDatagram");
13291 return mSatelliteController.registerForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013292 }
13293
13294 /**
13295 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013296 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013297 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013298 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
13299 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013300 * {@link #registerForIncomingDatagram(int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013301 *
13302 * @throws SecurityException if the caller doesn't have the required permission.
13303 */
13304 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013305 public void unregisterForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013306 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013307 enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram");
13308 mSatelliteController.unregisterForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013309 }
13310
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013311 /**
13312 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013313 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013314 * This method requests modem to check if there are any pending datagrams to be received over
13315 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000013316 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080013317 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013318 * @param subId The subId of the subscription used for receiving datagrams.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013319 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013320 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013321 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013322 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013323 public void pollPendingDatagrams(int subId, IIntegerConsumer callback) {
13324 enforceSatelliteCommunicationPermission("pollPendingDatagrams");
13325 mSatelliteController.pollPendingDatagrams(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013326 }
13327
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013328 /**
13329 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013330 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013331 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
13332 * input to this method. Datagram received here will be passed down to modem without any
13333 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080013334 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013335 * @param subId The subId of the subscription to send satellite datagrams for.
13336 * @param datagramType datagram type indicating whether the datagram is of type
13337 * SOS_SMS or LOCATION_SHARING.
13338 * @param datagram encoded gateway datagram which is encrypted by the caller.
13339 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000013340 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
13341 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013342 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013343 *
13344 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013345 */
13346 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013347 public void sendDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000013348 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
13349 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013350 enforceSatelliteCommunicationPermission("sendDatagram");
13351 mSatelliteController.sendDatagram(subId, datagramType, datagram, needFullScreenPointingUI,
13352 callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013353 }
13354
Sarah Chindf715ec2023-02-13 13:46:24 -080013355 /**
13356 * Request to get whether satellite communication is allowed for the current location.
13357 *
13358 * @param subId The subId of the subscription to check whether satellite communication is
13359 * allowed for the current location for.
13360 * @param result The result receiver that returns whether satellite communication is allowed
13361 * for the current location if the request is successful or an error code
13362 * if the request failed.
13363 *
13364 * @throws SecurityException if the caller doesn't have the required permission.
13365 */
13366 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013367 public void requestIsCommunicationAllowedForCurrentLocation(int subId,
Sarah Chindf715ec2023-02-13 13:46:24 -080013368 @NonNull ResultReceiver result) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013369 enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation");
13370 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(subId,
13371 result);
Sarah Chindf715ec2023-02-13 13:46:24 -080013372 }
13373
13374 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013375 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080013376 *
Sarah Chin5f57c582023-02-14 04:16:10 -080013377 * @param subId The subId to get the time after which the satellite will be visible for.
13378 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080013379 * be visible if the request is successful or an error code if the request failed.
13380 *
13381 * @throws SecurityException if the caller doesn't have the required permission.
13382 */
13383 @Override
13384 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
13385 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013386 mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013387 }
13388
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013389 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013390 * Inform that Device is aligned to satellite for demo mode.
13391 *
13392 * @param subId The subId to get the time after which the satellite will be visible for.
13393 * @param isAligned {@code true} Device is aligned with the satellite for demo mode
13394 * {@code false} Device fails to align with the satellite for demo mode.
13395 *
13396 * @throws SecurityException if the caller doesn't have required permission.
13397 */
13398 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
13399
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013400 public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) {
Hakjun Choiae365972023-04-25 11:00:31 +000013401 enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite");
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013402 mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned);
Hakjun Choiae365972023-04-25 11:00:31 +000013403 }
13404
13405 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000013406 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
13407 * by modem.
13408 *
13409 * @param subId The subId of the subscription to request for.
13410 * @param reason Reason for disallowing satellite communication for carrier.
Hakjun Choif92ac752024-03-18 19:34:29 +000013411 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013412 * operation.
13413 *
13414 * @throws SecurityException if the caller doesn't have required permission.
13415 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013416 public void addAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013417 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13418 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013419 enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013420 final long identity = Binder.clearCallingIdentity();
13421 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013422 mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013423 } finally {
13424 Binder.restoreCallingIdentity(identity);
13425 }
13426 }
13427
13428 /**
13429 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
13430 * by modem.
13431 *
13432 * @param subId The subId of the subscription to request for.
13433 * @param reason Reason for disallowing satellite communication.
Hakjun Choif92ac752024-03-18 19:34:29 +000013434 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013435 * operation.
13436 *
13437 * @throws SecurityException if the caller doesn't have required permission.
13438 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013439 public void removeAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013440 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13441 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013442 enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013443 final long identity = Binder.clearCallingIdentity();
13444 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013445 mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013446 } finally {
13447 Binder.restoreCallingIdentity(identity);
13448 }
13449 }
13450
13451 /**
13452 * Get reasons for disallowing satellite communication, as requested by
Hakjun Choif92ac752024-03-18 19:34:29 +000013453 * {@link #addAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
Hakjun Choicb39db92023-07-14 15:51:12 +000013454 *
13455 * @param subId The subId of the subscription to request for.
13456 *
13457 * @return Integer array of reasons for disallowing satellite communication.
13458 *
13459 * @throws SecurityException if the caller doesn't have the required permission.
13460 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013461 public @NonNull int[] getAttachRestrictionReasonsForCarrier(
Hakjun Choicb39db92023-07-14 15:51:12 +000013462 int subId) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013463 enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013464 final long identity = Binder.clearCallingIdentity();
13465 try {
13466 Set<Integer> reasonSet =
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013467 mSatelliteController.getAttachRestrictionReasonsForCarrier(subId);
Hakjun Choicb39db92023-07-14 15:51:12 +000013468 return reasonSet.stream().mapToInt(i->i).toArray();
13469 } finally {
13470 Binder.restoreCallingIdentity(identity);
13471 }
13472 }
13473
13474 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000013475 * Request to get the signal strength of the satellite connection.
13476 *
13477 * @param subId The subId of the subscription to request for.
13478 * @param result Result receiver to get the error code of the request and the current signal
13479 * strength of the satellite connection.
13480 *
13481 * @throws SecurityException if the caller doesn't have required permission.
13482 */
13483 @Override
13484 public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) {
13485 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
13486 final long identity = Binder.clearCallingIdentity();
13487 try {
13488 mSatelliteController.requestNtnSignalStrength(subId, result);
13489 } finally {
13490 Binder.restoreCallingIdentity(identity);
13491 }
13492 }
13493
13494 /**
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013495 * Registers for NTN signal strength changed from satellite modem. If the registration operation
13496 * is not successful, a {@link ServiceSpecificException} that contains
13497 * {@link SatelliteManager.SatelliteResult} will be thrown.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013498 *
13499 * @param subId The subId of the subscription to request for.
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013500 * @param callback The callback to handle the NTN signal strength changed event. If the
13501 * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged(
13502 * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of
13503 * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial
13504 * network has changed.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013505 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013506 * @throws SecurityException If the caller doesn't have the required permission.
13507 * @throws ServiceSpecificException If the callback registration operation fails.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013508 */
13509 @Override
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013510 public void registerForNtnSignalStrengthChanged(int subId,
13511 @NonNull INtnSignalStrengthCallback callback) throws RemoteException {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013512 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
13513 final long identity = Binder.clearCallingIdentity();
13514 try {
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013515 mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013516 } finally {
13517 Binder.restoreCallingIdentity(identity);
13518 }
13519 }
13520
13521 /**
13522 * Unregisters for NTN signal strength changed from satellite modem.
13523 * If callback was not registered before, the request will be ignored.
13524 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013525 * @param subId The subId of the subscription to unregister for listening NTN signal strength
13526 * changed event.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013527 * @param callback The callback that was passed to
13528 * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)}
13529 *
13530 * @throws SecurityException if the caller doesn't have the required permission.
13531 */
13532 @Override
13533 public void unregisterForNtnSignalStrengthChanged(
13534 int subId, @NonNull INtnSignalStrengthCallback callback) {
13535 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
13536 final long identity = Binder.clearCallingIdentity();
13537 try {
13538 mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback);
13539 } finally {
13540 Binder.restoreCallingIdentity(identity);
13541 }
13542 }
13543
13544 /**
Hakjun Choi8d96a562023-10-26 15:01:40 +000013545 * Registers for satellite capabilities change event from the satellite service.
13546 *
13547 * @param subId The subId of the subscription to request for.
13548 * @param callback The callback to handle the satellite capabilities changed event.
13549 *
13550 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13551 *
13552 * @throws SecurityException if the caller doesn't have required permission.
13553 */
13554 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013555 @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged(
Hakjun Choi8d96a562023-10-26 15:01:40 +000013556 int subId, @NonNull ISatelliteCapabilitiesCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013557 enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013558 final long identity = Binder.clearCallingIdentity();
13559 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013560 return mSatelliteController.registerForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013561 } finally {
13562 Binder.restoreCallingIdentity(identity);
13563 }
13564 }
13565
13566 /**
13567 * Unregisters for satellite capabilities change event from the satellite service.
13568 * If callback was not registered before, the request will be ignored.
13569 *
13570 * @param subId The subId of the subscription to unregister for satellite capabilities change.
13571 * @param callback The callback that was passed to.
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013572 * {@link #registerForCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}.
Hakjun Choi8d96a562023-10-26 15:01:40 +000013573 *
13574 * @throws SecurityException if the caller doesn't have required permission.
13575 */
13576 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013577 public void unregisterForCapabilitiesChanged(int subId,
13578 @NonNull ISatelliteCapabilitiesCallback callback) {
13579 enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013580 final long identity = Binder.clearCallingIdentity();
13581 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013582 mSatelliteController.unregisterForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013583 } finally {
13584 Binder.restoreCallingIdentity(identity);
13585 }
13586 }
13587
13588 /**
Hakjun Choif92ac752024-03-18 19:34:29 +000013589 * Registers for the satellite supported state changed.
13590 *
13591 * @param subId The subId of the subscription to register for supported state changed.
13592 * @param callback The callback to handle the satellite supported state changed event.
13593 *
13594 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13595 *
13596 * @throws SecurityException if the caller doesn't have the required permission.
13597 */
13598 @Override
13599 @SatelliteManager.SatelliteResult public int registerForSatelliteSupportedStateChanged(
13600 int subId, @NonNull ISatelliteSupportedStateCallback callback) {
13601 enforceSatelliteCommunicationPermission("registerForSatelliteSupportedStateChanged");
13602 return mSatelliteController.registerForSatelliteSupportedStateChanged(subId, callback);
13603 }
13604
13605 /**
13606 * Unregisters for the satellite supported state changed.
13607 * If callback was not registered before, the request will be ignored.
13608 *
13609 * @param subId The subId of the subscription to unregister for supported state changed.
13610 * @param callback The callback that was passed to
13611 * {@link #registerForSatelliteSupportedStateChanged(int, ISatelliteSupportedStateCallback)}.
13612 *
13613 * @throws SecurityException if the caller doesn't have the required permission.
13614 */
13615 @Override
13616 public void unregisterForSatelliteSupportedStateChanged(
13617 int subId, @NonNull ISatelliteSupportedStateCallback callback) {
13618 enforceSatelliteCommunicationPermission("unregisterForSatelliteSupportedStateChanged");
13619 mSatelliteController.unregisterForSatelliteSupportedStateChanged(subId, callback);
13620 }
13621
13622 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013623 * This API can be used by only CTS to update satellite vendor service package name.
13624 *
13625 * @param servicePackageName The package name of the satellite vendor service.
13626 * @return {@code true} if the satellite vendor service is set successfully,
13627 * {@code false} otherwise.
13628 */
13629 public boolean setSatelliteServicePackageName(String servicePackageName) {
13630 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName);
13631 TelephonyPermissions.enforceShellOnly(
13632 Binder.getCallingUid(), "setSatelliteServicePackageName");
13633 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13634 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13635 "setSatelliteServicePackageName");
13636 return mSatelliteController.setSatelliteServicePackageName(servicePackageName);
13637 }
13638
13639 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070013640 * This API can be used by only CTS to update satellite gateway service package name.
13641 *
13642 * @param servicePackageName The package name of the satellite gateway service.
13643 * @return {@code true} if the satellite gateway service is set successfully,
13644 * {@code false} otherwise.
13645 */
13646 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
13647 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
13648 TelephonyPermissions.enforceShellOnly(
13649 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
13650 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13651 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13652 "setSatelliteGatewayServicePackageName");
13653 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
13654 }
13655
13656 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070013657 * This API can be used by only CTS to update satellite pointing UI app package and class names.
13658 *
13659 * @param packageName The package name of the satellite pointing UI app.
13660 * @param className The class name of the satellite pointing UI app.
13661 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
13662 * {@code false} otherwise.
13663 */
13664 public boolean setSatellitePointingUiClassName(
13665 @Nullable String packageName, @Nullable String className) {
13666 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
13667 + ", className=" + className);
13668 TelephonyPermissions.enforceShellOnly(
13669 Binder.getCallingUid(), "setSatellitePointingUiClassName");
13670 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13671 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13672 "setSatelliteGatewayServicePackageName");
13673 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
13674 }
13675
13676 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070013677 * This API can be used by only CTS to update the timeout duration in milliseconds that
13678 * satellite should stay at listening mode to wait for the next incoming page before disabling
13679 * listening mode.
13680 *
13681 * @param timeoutMillis The timeout duration in millisecond.
13682 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13683 */
13684 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
13685 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
13686 TelephonyPermissions.enforceShellOnly(
13687 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
13688 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13689 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13690 "setSatelliteListeningTimeoutDuration");
13691 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
13692 }
13693
13694 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013695 * This API can be used by only CTS to override the timeout durations used by the
13696 * DatagramController module.
Hakjun Choiae365972023-04-25 11:00:31 +000013697 *
13698 * @param timeoutMillis The timeout duration in millisecond.
13699 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13700 */
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013701 public boolean setDatagramControllerTimeoutDuration(
13702 boolean reset, int timeoutType, long timeoutMillis) {
13703 Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset="
13704 + reset + ", timeoutMillis=" + timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013705 TelephonyPermissions.enforceShellOnly(
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013706 Binder.getCallingUid(), "setDatagramControllerTimeoutDuration");
Hakjun Choiae365972023-04-25 11:00:31 +000013707 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13708 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013709 "setDatagramControllerTimeoutDuration");
13710 return mSatelliteController.setDatagramControllerTimeoutDuration(
13711 reset, timeoutType, timeoutMillis);
13712 }
13713
13714 /**
13715 * This API can be used by only CTS to override the timeout durations used by the
13716 * SatelliteController module.
13717 *
13718 * @param timeoutMillis The timeout duration in millisecond.
13719 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13720 */
13721 public boolean setSatelliteControllerTimeoutDuration(
13722 boolean reset, int timeoutType, long timeoutMillis) {
13723 Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset="
13724 + reset + ", timeoutMillis=" + timeoutMillis);
13725 TelephonyPermissions.enforceShellOnly(
13726 Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration");
13727 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13728 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13729 "setSatelliteControllerTimeoutDuration");
13730 return mSatelliteController.setSatelliteControllerTimeoutDuration(
13731 reset, timeoutType, timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013732 }
13733
13734 /**
Thomas Nguyen11a051f2023-10-25 10:14:55 -070013735 * This API can be used in only testing to override connectivity status in monitoring emergency
13736 * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.
13737 *
13738 * @param handoverType The type of handover from emergency call to satellite messaging. Use one
13739 * of the following values to enable the override:
13740 * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS
13741 * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911
13742 * To disable the override, use -1 for handoverType.
13743 * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer
13744 * delaySeconds after the emergency call starts.
13745 * @return {@code true} if the handover type is set successfully, {@code false} otherwise.
13746 */
13747 public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) {
13748 Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType);
13749 TelephonyPermissions.enforceShellOnly(
13750 Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType");
13751 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13752 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13753 "setEmergencyCallToSatelliteHandoverType");
13754 return mSatelliteController.setEmergencyCallToSatelliteHandoverType(
13755 handoverType, delaySeconds);
13756 }
13757
13758 /**
Thomas Nguyen3d602742024-01-19 11:29:35 -080013759 * This API can be used in only testing to override oem-enabled satellite provision status.
13760 *
13761 * @param reset {@code true} mean the overriding status should not be used, {@code false}
13762 * otherwise.
13763 * @param isProvisioned The overriding provision status.
13764 * @return {@code true} if the provision status is set successfully, {@code false} otherwise.
13765 */
13766 public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) {
13767 Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset
13768 + ", isProvisioned=" + isProvisioned);
13769 TelephonyPermissions.enforceShellOnly(
13770 Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus");
13771 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13772 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13773 "setOemEnabledSatelliteProvisionStatus");
13774 return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned);
13775 }
13776
13777 /**
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013778 * This API should be used by only CTS tests to forcefully set telephony country codes.
13779 *
13780 * @return {@code true} if the country code is set successfully, {@code false} otherwise.
13781 */
13782 public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes,
13783 Map cachedNetworkCountryCodes, String locationCountryCode,
13784 long locationCountryCodeTimestampNanos) {
13785 Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes="
13786 + String.join(", ", currentNetworkCountryCodes)
13787 + ", locationCountryCode=" + locationCountryCode
13788 + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos
13789 + ", reset=" + reset + ", cachedNetworkCountryCodes="
13790 + String.join(", ", cachedNetworkCountryCodes.keySet()));
13791 TelephonyPermissions.enforceShellOnly(
13792 Binder.getCallingUid(), "setCachedLocationCountryCode");
13793 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13794 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13795 "setCachedLocationCountryCode");
13796 return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext()).setCountryCodes(
13797 reset, currentNetworkCountryCodes, cachedNetworkCountryCodes, locationCountryCode,
13798 locationCountryCodeTimestampNanos);
13799 }
13800
13801 /**
13802 * This API should be used by only CTS tests to override the overlay configs of satellite
13803 * access controller.
13804 *
13805 * @param reset {@code true} mean the overridden configs should not be used, {@code false}
13806 * otherwise.
13807 * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise.
13808 */
13809 public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed,
13810 String s2CellFile, long locationFreshDurationNanos,
13811 List<String> satelliteCountryCodes) {
13812 Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset
13813 + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile
13814 + ", locationFreshDurationNanos=" + locationFreshDurationNanos
13815 + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null)
13816 ? String.join(", ", satelliteCountryCodes) : null));
13817 TelephonyPermissions.enforceShellOnly(
13818 Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs");
13819 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13820 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13821 "setSatelliteAccessControlOverlayConfigs");
13822 return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset, isAllowed,
13823 s2CellFile, locationFreshDurationNanos, satelliteCountryCodes);
13824 }
13825
13826 /**
Hakjun Choibc6ce992023-11-07 16:04:33 +000013827 * This API can be used by only CTS to override the cached value for the device overlay config
13828 * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether
13829 * outgoing satellite datagrams should be sent to modem in demo mode.
13830 *
13831 * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to
13832 * satellite modem or not.
13833 *
13834 * @return {@code true} if the operation is successful, {@code false} otherwise.
13835 */
13836 public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) {
13837 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
13838 Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is "
13839 + "disabled");
13840 return false;
13841 }
13842 Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode");
13843 TelephonyPermissions.enforceShellOnly(
13844 Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode");
13845 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13846 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13847 "setShouldSendDatagramToModemInDemoMode");
13848 return mSatelliteController.setShouldSendDatagramToModemInDemoMode(
13849 shouldSendToModemInDemoMode);
13850 }
13851
13852 /**
Hunsuk Choi13078be2023-09-13 10:55:21 +000013853 * Sets the service defined in ComponentName to be bound.
13854 *
13855 * This should only be used for testing.
13856 * @return {@code true} if the DomainSelectionService to bind to was set,
13857 * {@code false} otherwise.
13858 */
13859 @Override
13860 public boolean setDomainSelectionServiceOverride(ComponentName componentName) {
13861 Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName);
13862
13863 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
13864 "setDomainSelectionServiceOverride");
13865 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13866 getDefaultSubscription(), "setDomainSelectionServiceOverride");
13867
13868 final long identity = Binder.clearCallingIdentity();
13869 try {
13870 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13871 return DomainSelectionResolver.getInstance()
13872 .setDomainSelectionServiceOverride(componentName);
13873 }
13874 } finally {
13875 Binder.restoreCallingIdentity(identity);
13876 }
13877 return false;
13878 }
13879
13880 /**
13881 * Clears the DomainSelectionService override.
13882 *
13883 * This should only be used for testing.
13884 * @return {@code true} if the DomainSelectionService override was cleared,
13885 * {@code false} otherwise.
13886 */
13887 @Override
13888 public boolean clearDomainSelectionServiceOverride() {
13889 Log.i(LOG_TAG, "clearDomainSelectionServiceOverride");
13890
13891 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
13892 "clearDomainSelectionServiceOverride");
13893 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13894 getDefaultSubscription(), "clearDomainSelectionServiceOverride");
13895
13896 final long identity = Binder.clearCallingIdentity();
13897 try {
13898 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13899 return DomainSelectionResolver.getInstance()
13900 .clearDomainSelectionServiceOverride();
13901 }
13902 } finally {
13903 Binder.restoreCallingIdentity(identity);
13904 }
13905 return false;
13906 }
13907
13908 /**
Gil Cukierman06403e12023-11-29 16:33:03 +000013909 * Enable or disable notifications sent for cellular identifier disclosure events.
13910 *
13911 * Disclosure events are defined as instances where a device has sent a cellular identifier
13912 * on the Non-access stratum (NAS) before a security context is established. As a result the
13913 * identifier is sent in the clear, which has privacy implications for the user.
13914 *
13915 * @param enable if notifications about disclosure events should be enabled
13916 * @throws SecurityException if the caller does not have the required privileges
13917 * @throws UnsupportedOperationException if the modem does not support this feature.
13918 */
13919 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000013920 public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) {
Gil Cukierman06403e12023-11-29 16:33:03 +000013921 enforceModifyPermission();
13922 checkForIdentifierDisclosureNotificationSupport();
13923
13924 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
13925 editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable);
13926 editor.apply();
13927
13928 // Each phone instance is responsible for updating its respective modem immediately
13929 // after we've made a preference change.
13930 for (Phone phone : PhoneFactory.getPhones()) {
13931 phone.handleIdentifierDisclosureNotificationPreferenceChange();
13932 }
13933 }
13934
13935 /**
13936 * Get whether or not cellular identifier disclosure notifications are enabled.
13937 *
13938 * @throws SecurityException if the caller does not have the required privileges
13939 * @throws UnsupportedOperationException if the modem does not support this feature.
13940 */
13941 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000013942 public boolean isCellularIdentifierDisclosureNotificationsEnabled() {
Gil Cukierman06403e12023-11-29 16:33:03 +000013943 enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled");
13944 checkForIdentifierDisclosureNotificationSupport();
13945 return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled();
13946 }
13947
13948 /**
Michael Groover826b71d2023-12-21 22:08:06 -060013949 * Enables or disables notifications sent when cellular null cipher or integrity algorithms
13950 * are in use by the cellular modem.
13951 *
13952 * @throws IllegalStateException if the Telephony process is not currently available
13953 * @throws SecurityException if the caller does not have the required privileges
13954 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
13955 * and integrity algorithms in use
13956 * @hide
13957 */
13958 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Michael Grooverae447b22024-01-24 22:35:46 -060013959 public void setNullCipherNotificationsEnabled(boolean enable) {
Michael Groover826b71d2023-12-21 22:08:06 -060013960 enforceModifyPermission();
13961 checkForNullCipherNotificationSupport();
13962
13963 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
13964 editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable);
13965 editor.apply();
13966
13967 // Each phone instance is responsible for updating its respective modem immediately
13968 // after a preference change.
13969 for (Phone phone : PhoneFactory.getPhones()) {
13970 phone.handleNullCipherNotificationPreferenceChanged();
13971 }
13972 }
13973
13974 /**
13975 * Get whether notifications are enabled for null cipher or integrity algorithms in use by the
13976 * cellular modem.
13977 *
13978 * @throws IllegalStateException if the Telephony process is not currently available
13979 * @throws SecurityException if the caller does not have the required privileges
13980 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
13981 * and integrity algorithms in use
13982 * @hide
13983 */
13984 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
13985 public boolean isNullCipherNotificationsEnabled() {
13986 enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled");
13987 checkForNullCipherNotificationSupport();
13988 return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled();
13989 }
13990
13991 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000013992 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
13993 *
13994 * <p>This method behaves in one of the following ways:
13995 * <ul>
13996 * <li>return true : if the calling package has the appop permission {@link
13997 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
13998 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
13999 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
14000 * Owner device identifier access check, or the calling package has carrier privileges</>
14001 * <li>throw SecurityException: if the caller does not meet any of the requirements.
14002 * </ul>
14003 */
14004 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
14005 String callingPackage, @Nullable String callingFeatureId, String message) {
14006 for (Phone phone : PhoneFactory.getPhones()) {
14007 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
14008 phone.getSubId(), callingPackage, callingFeatureId, message)) {
14009 return true;
14010 }
14011 }
14012 return false;
14013 }
arunvoddud7401012022-12-15 16:08:12 +000014014
14015 /**
Jack Yufa8ed012023-02-11 15:42:28 -080014016 * @return The subscription manager service instance.
14017 */
14018 public SubscriptionManagerService getSubscriptionManagerService() {
14019 return SubscriptionManagerService.getInstance();
14020 }
14021
14022 /**
arunvoddud7401012022-12-15 16:08:12 +000014023 * Class binds the consumer[callback] and carrierId.
14024 */
14025 private static class CallerCallbackInfo {
14026 private final Consumer<Integer> mConsumer;
14027 private final int mCarrierId;
14028
14029 public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) {
14030 mConsumer = consumer;
14031 mCarrierId = carrierId;
14032 }
14033
14034 public Consumer<Integer> getConsumer() {
14035 return mConsumer;
14036 }
14037
14038 public int getCarrierId() {
14039 return mCarrierId;
14040 }
14041 }
joonhunshin4ac60942023-11-15 15:23:39 +000014042
14043 /*
14044 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14045 * But the context that is passed in is unused if the phone app is already alive.
14046 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14047 */
14048 @VisibleForTesting
14049 public void setPackageManager(PackageManager packageManager) {
14050 mPackageManager = packageManager;
14051 }
14052
14053 /*
14054 * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags.
14055 * But the FeatureFlags that is passed in is unused if the phone app is already alive.
14056 * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test.
14057 */
14058 @VisibleForTesting
14059 public void setFeatureFlags(FeatureFlags featureFlags) {
14060 mFeatureFlags = featureFlags;
14061 }
14062
14063 /**
14064 * Make sure the device has required telephony feature
14065 *
14066 * @throws UnsupportedOperationException if the device does not have required telephony feature
14067 */
14068 private void enforceTelephonyFeatureWithException(@Nullable String callingPackage,
14069 @NonNull String telephonyFeature, @NonNull String methodName) {
14070 if (callingPackage == null || mPackageManager == null) {
14071 return;
14072 }
14073
14074 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
14075 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage,
14076 Binder.getCallingUserHandle())) {
14077 return;
14078 }
14079
14080 if (!mPackageManager.hasSystemFeature(telephonyFeature)) {
14081 throw new UnsupportedOperationException(
14082 methodName + " is unsupported without " + telephonyFeature);
14083 }
14084 }
Jack Yufa8ed012023-02-11 15:42:28 -080014085}