blob: 2efb48e04b03772fb4d0e9694efff9ff857d571c [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
joonhunshin4ac60942023-11-15 15:23:39 +000019import static android.content.pm.PackageManager.FEATURE_TELEPHONY_IMS;
20import static android.content.pm.PackageManager.FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION;
Hall Liud892bec2018-11-30 14:51:45 -080021import static android.content.pm.PackageManager.PERMISSION_GRANTED;
Nate Myrenae97d192023-06-09 15:22:31 -070022import static android.permission.flags.Flags.opEnableMobileDataByUser;
joonhunshin4ac60942023-11-15 15:23:39 +000023import static android.telephony.TelephonyManager.ENABLE_FEATURE_MAPPING;
Gil Cukierman1c0eb932022-12-06 22:28:24 +000024import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK;
jimsunf9ec1622022-09-13 21:18:43 +080025import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080026import static android.telephony.satellite.SatelliteManager.KEY_SATELLITE_COMMUNICATION_ALLOWED;
27import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_ACCESS_BARRED;
Thomas Nguyena8062672024-02-05 14:18:19 -080028import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_REQUEST_NOT_SUPPORTED;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080029import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_SUCCESS;
Hall Liud892bec2018-11-30 14:51:45 -080030
Shuo Qianccbaf742021-02-22 18:32:21 -080031import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
32import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070033import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070034import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000035import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070036
Brad Ebinger34c09a52021-02-17 23:23:21 +000037import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080038import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080039import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070040import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000041import android.annotation.RequiresPermission;
Sarah Chin532d6bb2022-12-28 22:50:43 -080042import android.app.ActivityManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070043import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080044import android.app.PendingIntent;
Tyler Gunn64144d92022-03-17 14:16:41 -070045import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000046import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080047import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000048import android.compat.annotation.ChangeId;
49import android.compat.annotation.EnabledSince;
Anthony Alridge70ba5572023-05-02 12:14:14 +000050import android.content.ActivityNotFoundException;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070051import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070052import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.content.Context;
54import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070055import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070056import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070057import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070058import android.net.Uri;
59import android.os.AsyncResult;
60import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080061import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070062import android.os.Bundle;
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080063import android.os.DropBoxManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070065import android.os.IBinder;
Thomas Nguyen8ee49682023-02-01 11:46:09 -080066import android.os.ICancellationSignal;
tom hsu0b59d292022-09-29 23:49:21 +080067import android.os.LocaleList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070068import android.os.Looper;
69import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070070import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080071import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070072import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070073import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080074import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080075import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070076import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070077import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080078import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070079import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070080import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070081import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070082import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070083import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080084import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070085import android.provider.Telephony;
arunvoddud7401012022-12-15 16:08:12 +000086import android.service.carrier.CarrierIdentifier;
Inseob Kim14bb3d02018-12-13 17:11:34 +090087import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080088import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080089import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070090import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080091import android.telephony.AccessNetworkConstants;
92import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070093import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070094import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080095import android.telephony.Annotation.ThermalMitigationResult;
Sarah Chin2ec39f62022-08-31 17:03:26 -070096import android.telephony.AnomalyReporter;
Shuo Qian4a594052020-01-23 11:59:30 -080097import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070098import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080099import android.telephony.CarrierRestrictionRules;
Hui Wang9b5793a2022-12-05 14:38:06 -0600100import android.telephony.CellBroadcastIdRange;
yincheng zhao2737e882019-09-06 17:06:54 -0700101import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -0800102import android.telephony.CellIdentityCdma;
103import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700104import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -0700105import android.telephony.CellInfoGsm;
106import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700107import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800108import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -0700109import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700110import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700111import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -0800112import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700113import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -0800114import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -0700115import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -0800116import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800117import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700118import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800119import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700120import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800121import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800122import android.telephony.SignalStrengthUpdateRequest;
123import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800124import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800125import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800126import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700127import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700128import android.telephony.TelephonyManager;
Jack Yuf5badd92022-12-08 00:50:53 -0800129import android.telephony.TelephonyManager.SimState;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800130import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800131import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800132import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000133import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000134import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000135import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700136import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700137import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800138import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800139import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700140import android.telephony.gba.GbaAuthRequest;
141import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700142import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800143import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000144import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000145import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700146import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000147import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700148import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800149import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700150import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800151import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700152import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000153import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700154import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800155import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800156import android.telephony.ims.stub.ImsRegistrationImplBase;
Hakjun Choifa3e6172023-09-22 03:56:34 +0000157import android.telephony.satellite.INtnSignalStrengthCallback;
Hakjun Choi8d96a562023-10-26 15:01:40 +0000158import android.telephony.satellite.ISatelliteCapabilitiesCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800159import android.telephony.satellite.ISatelliteDatagramCallback;
Hakjun Choid4a52a22023-12-13 09:48:24 +0000160import android.telephony.satellite.ISatelliteModemStateCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800161import android.telephony.satellite.ISatelliteProvisionStateCallback;
Hakjun Choif92ac752024-03-18 19:34:29 +0000162import android.telephony.satellite.ISatelliteSupportedStateCallback;
Sarah Chinabf081b2023-03-09 23:00:57 -0800163import android.telephony.satellite.ISatelliteTransmissionUpdateCallback;
Hakjun Choi4c3668a2023-12-05 11:55:36 +0000164import android.telephony.satellite.NtnSignalStrength;
165import android.telephony.satellite.NtnSignalStrengthCallback;
Sarah Chin503828c2023-02-01 23:54:20 -0800166import android.telephony.satellite.SatelliteCapabilities;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000167import android.telephony.satellite.SatelliteDatagram;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800168import android.telephony.satellite.SatelliteDatagramCallback;
Sarah Chineccfbd12023-01-20 19:00:35 -0800169import android.telephony.satellite.SatelliteManager;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800170import android.telephony.satellite.SatelliteProvisionStateCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700171import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800172import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700173import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700174import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800175import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800176
Andrew Lee312e8172014-10-23 17:01:36 -0700177import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800178import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800179import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800180import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800181import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700182import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700183import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700184import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800185import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800186import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700187import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700188import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800189import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700190import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800191import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800192import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800193import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700194import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000195import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700196import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800197import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700198import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800199import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800200import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800201import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700202import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700203import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700204import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700205import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700206import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800207import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700208import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700209import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700210import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700211import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800212import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800213import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700214import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000215import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700216import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700217import com.android.internal.telephony.SmsPermissions;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800218import com.android.internal.telephony.TelephonyCountryDetector;
Peter Wang59571be2020-01-27 12:35:15 +0800219import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800220import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700221import com.android.internal.telephony.data.DataUtils;
Hunsuk Choi42cc62a2022-10-16 06:03:40 +0000222import com.android.internal.telephony.domainselection.DomainSelectionResolver;
sqianf4ca7ed2019-01-15 18:32:07 -0800223import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700224import com.android.internal.telephony.euicc.EuiccConnector;
Sarah Chincc5446f2023-10-23 17:57:19 -0700225import com.android.internal.telephony.flags.FeatureFlags;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800226import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700227import com.android.internal.telephony.imsphone.ImsPhone;
228import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000229import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800230import com.android.internal.telephony.metrics.TelephonyMetrics;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000231import com.android.internal.telephony.satellite.SatelliteController;
Jack Yu285100e2022-12-02 22:48:35 -0800232import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
233import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700234import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700235import com.android.internal.telephony.uicc.IccIoResult;
236import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800237import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700238import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800239import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700240import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000241import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800242import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000243import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800244import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000245import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700246import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700247import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800248import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800249import com.android.phone.callcomposer.CallComposerPictureManager;
250import com.android.phone.callcomposer.CallComposerPictureTransfer;
251import com.android.phone.callcomposer.ImageData;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800252import com.android.phone.satellite.accesscontrol.SatelliteAccessController;
Hyosun Kim240214a2023-11-02 13:30:15 +0000253import com.android.phone.satellite.entitlement.SatelliteEntitlementController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700254import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700255import com.android.phone.slice.SlicePurchaseController;
arunvoddud7401012022-12-15 16:08:12 +0000256import com.android.phone.utils.CarrierAllowListInfo;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700257import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800258import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700259import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700260import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -0800261import com.android.server.feature.flags.Flags;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800262import com.android.services.telephony.TelecomAccountRegistry;
263import com.android.services.telephony.TelephonyConnectionService;
Hunsuk Choi9c69a802024-04-11 20:39:23 +0000264import com.android.services.telephony.domainselection.TelephonyDomainSelectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800265import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800266
Hall Liu82694d52020-12-11 18:22:04 -0800267import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700268import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800269import java.io.IOException;
270import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700271import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700272import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800273import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000274import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800275import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800276import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800277import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800278import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100279import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800280import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700281import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800282import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800283import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700284import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800285import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800286import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800287import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700288
289/**
290 * Implementation of the ITelephony interface.
291 */
Santos Cordon117fee72014-05-16 17:56:12 -0700292public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700293 private static final String LOG_TAG = "PhoneInterfaceManager";
294 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
295 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800296 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700297
298 // Message codes used with mMainThreadHandler
299 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700300 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
301 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700302 private static final int CMD_OPEN_CHANNEL = 9;
303 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
304 private static final int CMD_CLOSE_CHANNEL = 11;
305 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800306 private static final int CMD_NV_READ_ITEM = 13;
307 private static final int EVENT_NV_READ_ITEM_DONE = 14;
308 private static final int CMD_NV_WRITE_ITEM = 15;
309 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
310 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
311 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700312 private static final int CMD_RESET_MODEM_CONFIG = 19;
313 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800314 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
315 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800316 private static final int CMD_SEND_ENVELOPE = 25;
317 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700318 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
319 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
320 private static final int CMD_EXCHANGE_SIM_IO = 31;
321 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800322 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
323 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700324 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
325 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700326 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
327 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700328 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
329 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
330 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
331 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700332 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
333 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
334 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
335 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700336 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800337 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
338 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000339 private static final int CMD_SWITCH_SLOTS = 50;
340 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700341 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
342 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
343 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
344 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
345 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
346 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
347 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
348 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700349 private static final int CMD_GET_ALL_CELL_INFO = 60;
350 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
351 private static final int CMD_GET_CELL_LOCATION = 62;
352 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700353 private static final int CMD_MODEM_REBOOT = 64;
354 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700355 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
356 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800357 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
358 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700359 private static final int CMD_GET_MODEM_STATUS = 70;
360 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700361 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
362 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700363 private static final int CMD_ERASE_MODEM_CONFIG = 74;
364 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800365 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
366 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
367 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
368 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800369 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
370 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800371 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800372 private static final int CMD_GET_CALL_FORWARDING = 83;
373 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
374 private static final int CMD_SET_CALL_FORWARDING = 85;
375 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
376 private static final int CMD_GET_CALL_WAITING = 87;
377 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
378 private static final int CMD_SET_CALL_WAITING = 89;
379 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700380 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
381 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
382 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
383 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700384 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
385 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800386 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
387 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800388 private static final int CMD_SET_DATA_THROTTLING = 99;
389 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800390 private static final int CMD_SET_SIM_POWER = 101;
391 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800392 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
393 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
394 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
395 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800396 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
397 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000398 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800399 private static final int CMD_GET_SLICING_CONFIG = 110;
400 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800401 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700402 private static final int CMD_ENABLE_VONR = 113;
403 private static final int EVENT_ENABLE_VONR_DONE = 114;
404 private static final int CMD_IS_VONR_ENABLED = 115;
405 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700406 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
407 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000408
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800409 // Parameters of select command.
410 private static final int SELECT_COMMAND = 0xA4;
411 private static final int SELECT_P1 = 0x04;
412 private static final int SELECT_P2 = 0;
413 private static final int SELECT_P3 = 0x10;
414
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000415 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
416 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
Gil Cukierman06403e12023-11-29 16:33:03 +0000417 // Cellular identifier disclosure transparency was added in IRadioNetwork 2.2
418 private static final int MIN_IDENTIFIER_DISCLOSURE_VERSION = 202;
Michael Groover826b71d2023-12-21 22:08:06 -0600419 // Null cipher notification support was added in IRadioNetwork 2.2
420 private static final int MIN_NULL_CIPHER_NOTIFICATION_VERSION = 202;
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000421
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700422 /** The singleton instance. */
423 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800424 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700425
Sarah Chin4beb2b72023-02-14 14:47:54 -0800426 private final PhoneGlobals mApp;
joonhunshin4ac60942023-11-15 15:23:39 +0000427 private FeatureFlags mFeatureFlags;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -0800428 private com.android.server.telecom.flags.FeatureFlags mTelecomFeatureFlags;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800429 private final CallManager mCM;
430 private final ImsResolver mImsResolver;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000431
432 private final SatelliteController mSatelliteController;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800433 private final SatelliteAccessController mSatelliteAccessController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800434 private final UserManager mUserManager;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800435 private final MainThreadHandler mMainThreadHandler;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800436 private final SharedPreferences mTelephonySharedPreferences;
437 private final PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800438 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Nate Myren453c3472024-03-13 11:28:11 -0700439 private AppOpsManager mAppOps;
joonhunshin4ac60942023-11-15 15:23:39 +0000440 private PackageManager mPackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700441
Peter Wangdafb9ac2020-01-15 14:13:38 -0800442 /** User Activity */
Sarah Chin4beb2b72023-02-14 14:47:54 -0800443 private final AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800444 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800445 private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800446
Derek Tan97ebb422014-09-05 16:55:38 -0700447 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
448 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800449 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800450 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700451
Michelecea4cf22018-12-21 15:00:11 -0800452 // String to store multi SIM allowed
453 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
454
Derek Tan740e1672017-06-27 14:56:27 -0700455 // The AID of ISD-R.
456 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
457
yinxub1bed742017-04-17 11:45:04 -0700458 private NetworkScanRequestTracker mNetworkScanRequestTracker;
459
David Kelly5e06a7f2018-03-12 14:10:59 +0000460 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
461 private static final int MANUFACTURER_CODE_LENGTH = 8;
462
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800463 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800464 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800465
Sarah Chin2ec39f62022-08-31 17:03:26 -0700466 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
467 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
468
Derek Tan89e89d42014-07-08 17:00:10 -0700469 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700470 * Experiment flag to enable erase modem config on reset network, default value is false
471 */
472 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
473 "reset_network_erase_modem_config_enabled";
474
Rambo Wang0f050d82021-02-12 11:43:36 -0800475 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800476
Gary Jian76280a42022-12-07 16:18:33 +0800477 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
478
sandeepjsb6c87872021-09-27 15:34:44 +0000479 /**
480 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
481 * one ICCID active at the same time.
482 * Apps should use below API signatures if targeting SDK is T and beyond.
483 *
484 * @hide
485 */
486 @ChangeId
487 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
488 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800489
Naina Nallurid63128d2019-09-17 14:10:30 -0700490 /**
Chen Xu540470b2021-12-14 17:15:47 -0800491 * Apps targeting on Android T and beyond will get exception whenever icc close channel
492 * operation fails.
493 */
494 @ChangeId
495 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
496 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
497
498 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700499 * A request object to use for transmitting data to an ICC.
500 */
501 private static final class IccAPDUArgument {
502 public int channel, cla, command, p1, p2, p3;
503 public String data;
504
505 public IccAPDUArgument(int channel, int cla, int command,
506 int p1, int p2, int p3, String data) {
507 this.channel = channel;
508 this.cla = cla;
509 this.command = command;
510 this.p1 = p1;
511 this.p2 = p2;
512 this.p3 = p3;
513 this.data = data;
514 }
515 }
516
517 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700518 * A request object to use for transmitting data to an ICC.
519 */
520 private static final class ManualNetworkSelectionArgument {
521 public OperatorInfo operatorInfo;
522 public boolean persistSelection;
523
524 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
525 this.operatorInfo = operatorInfo;
526 this.persistSelection = persistSelection;
527 }
528 }
529
Sarah Chin71b3a852022-09-28 15:54:19 -0700530 private static final class PurchasePremiumCapabilityArgument {
531 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700532 public @NonNull IIntegerConsumer callback;
533
534 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800535 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700536 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700537 this.callback = callback;
538 }
539 }
540
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700541 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700542 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
543 * request after sending. The main thread will notify the request when it is complete.
544 */
545 private static final class MainThreadRequest {
546 /** The argument to use for the request */
547 public Object argument;
548 /** The result of the request that is run on the main thread */
549 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800550 // The subscriber id that this request applies to. Defaults to
551 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
552 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700553
Nathan Harold92bed182018-10-12 18:16:49 -0700554 // In cases where subId is unavailable, the caller needs to specify the phone.
555 public Phone phone;
556
vagdeviaf9a5b92018-08-15 16:01:53 -0700557 public WorkSource workSource;
558
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700559 public MainThreadRequest(Object argument) {
560 this.argument = argument;
561 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800562
Nathan Harold92bed182018-10-12 18:16:49 -0700563 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
564 this.argument = argument;
565 if (phone != null) {
566 this.phone = phone;
567 }
568 this.workSource = workSource;
569 }
570
vagdeviaf9a5b92018-08-15 16:01:53 -0700571 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800572 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800573 if (subId != null) {
574 this.subId = subId;
575 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700576 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800577 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700578 }
579
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800580 private static final class IncomingThirdPartyCallArgs {
581 public final ComponentName component;
582 public final String callId;
583 public final String callerDisplayName;
584
585 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
586 String callerDisplayName) {
587 this.component = component;
588 this.callId = callId;
589 this.callerDisplayName = callerDisplayName;
590 }
591 }
592
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700593 /**
594 * A handler that processes messages on the main thread in the phone process. Since many
595 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
596 * inbound binder threads to the main thread in the phone process. The Binder thread
597 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
598 * on, which will be notified when the operation completes and will contain the result of the
599 * request.
600 *
601 * <p>If a MainThreadRequest object is provided in the msg.obj field,
602 * note that request.result must be set to something non-null for the calling thread to
603 * unblock.
604 */
605 private final class MainThreadHandler extends Handler {
606 @Override
607 public void handleMessage(Message msg) {
608 MainThreadRequest request;
609 Message onCompleted;
610 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000611 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700612 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800613 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700614
615 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700616 case CMD_HANDLE_USSD_REQUEST: {
617 request = (MainThreadRequest) msg.obj;
618 final Phone phone = getPhoneFromRequest(request);
619 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800620 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700621 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700622
Pengquan Menga1bb6272018-09-06 09:59:22 -0700623 if (!isUssdApiAllowed(request.subId)) {
624 // Carrier does not support use of this API, return failure.
625 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
626 UssdResponse response = new UssdResponse(ussdRequest, null);
627 Bundle returnData = new Bundle();
628 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
629 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700630
Pengquan Menga1bb6272018-09-06 09:59:22 -0700631 request.result = true;
632 notifyRequester(request);
633 return;
634 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700635
Pengquan Menga1bb6272018-09-06 09:59:22 -0700636 try {
637 request.result = phone != null
638 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
639 } catch (CallStateException cse) {
640 request.result = false;
641 }
642 // Wake up the requesting thread
643 notifyRequester(request);
644 break;
pkanwar32d516d2016-10-14 19:37:38 -0700645 }
646
Yorke Lee716f67e2015-06-17 15:39:16 -0700647 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700648 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700649 final Phone phone = getPhoneFromRequest(request);
650 request.result = phone != null ?
651 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
652 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700653 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700654 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700655 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700656 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700657
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700658 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700659 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700660 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000661 uiccPort = getUiccPortFromRequest(request);
662 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700663 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800664 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700665 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700666 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700667 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800668 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000669 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800670 iccArgument.channel, iccArgument.cla, iccArgument.command,
671 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
672 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700673 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700674 break;
675
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700676 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700677 ar = (AsyncResult) msg.obj;
678 request = (MainThreadRequest) ar.userObj;
679 if (ar.exception == null && ar.result != null) {
680 request.result = ar.result;
681 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800682 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700683 if (ar.result == null) {
684 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800685 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700686 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800687 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700688 } else {
689 loge("iccTransmitApduLogicalChannel: Unknown exception");
690 }
691 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700692 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700693 break;
694
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700695 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
696 request = (MainThreadRequest) msg.obj;
697 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000698 uiccPort = getUiccPortFromRequest(request);
699 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700700 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800701 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700702 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700703 } else {
704 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800705 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000706 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800707 iccArgument.cla, iccArgument.command, iccArgument.p1,
708 iccArgument.p2,
709 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700710 }
711 break;
712
713 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
714 ar = (AsyncResult) msg.obj;
715 request = (MainThreadRequest) ar.userObj;
716 if (ar.exception == null && ar.result != null) {
717 request.result = ar.result;
718 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800719 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700720 if (ar.result == null) {
721 loge("iccTransmitApduBasicChannel: Empty response");
722 } else if (ar.exception instanceof CommandException) {
723 loge("iccTransmitApduBasicChannel: CommandException: " +
724 ar.exception);
725 } else {
726 loge("iccTransmitApduBasicChannel: Unknown exception");
727 }
728 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700729 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700730 break;
731
732 case CMD_EXCHANGE_SIM_IO:
733 request = (MainThreadRequest) msg.obj;
734 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000735 uiccPort = getUiccPortFromRequest(request);
736 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700737 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800738 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700739 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700740 } else {
741 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
742 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000743 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700744 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
745 iccArgument.data, onCompleted);
746 }
747 break;
748
749 case EVENT_EXCHANGE_SIM_IO_DONE:
750 ar = (AsyncResult) msg.obj;
751 request = (MainThreadRequest) ar.userObj;
752 if (ar.exception == null && ar.result != null) {
753 request.result = ar.result;
754 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800755 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700756 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700757 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700758 break;
759
Derek Tan4d5e5c12014-02-04 11:54:58 -0800760 case CMD_SEND_ENVELOPE:
761 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000762 uiccPort = getUiccPortFromRequest(request);
763 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700764 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800765 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700766 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700767 } else {
768 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800769 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700770 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800771 break;
772
773 case EVENT_SEND_ENVELOPE_DONE:
774 ar = (AsyncResult) msg.obj;
775 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700776 if (ar.exception == null && ar.result != null) {
777 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800778 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800779 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700780 if (ar.result == null) {
781 loge("sendEnvelopeWithStatus: Empty response");
782 } else if (ar.exception instanceof CommandException) {
783 loge("sendEnvelopeWithStatus: CommandException: " +
784 ar.exception);
785 } else {
786 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
787 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800788 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700789 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800790 break;
791
Shishir Agrawal566b7612013-10-28 14:41:00 -0700792 case CMD_OPEN_CHANNEL:
793 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000794 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800795 IccLogicalChannelRequest openChannelRequest =
796 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000797 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700798 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800799 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800800 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700801 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700802 } else {
803 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800804 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
805 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700806 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700807 break;
808
809 case EVENT_OPEN_CHANNEL_DONE:
810 ar = (AsyncResult) msg.obj;
811 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700812 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700813 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700814 int[] result = (int[]) ar.result;
815 int channelId = result[0];
816 byte[] selectResponse = null;
817 if (result.length > 1) {
818 selectResponse = new byte[result.length - 1];
819 for (int i = 1; i < result.length; ++i) {
820 selectResponse[i - 1] = (byte) result[i];
821 }
822 }
823 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800824 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800825
826 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700827 if (uiccPort == null) {
828 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
829 } else {
830 IccLogicalChannelRequest channelRequest =
831 (IccLogicalChannelRequest) request.argument;
832 channelRequest.channel = channelId;
833 uiccPort.onLogicalChannelOpened(channelRequest);
834 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700835 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700836 if (ar.result == null) {
837 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700838 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700839 if (ar.exception != null) {
840 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
841 }
842
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700843 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700844 if (ar.exception instanceof CommandException) {
845 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800846 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700847 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700848 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700849 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700850 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700851 }
852 }
853 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800854 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700855 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700856 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700857 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700858 break;
859
860 case CMD_CLOSE_CHANNEL:
861 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000862 uiccPort = getUiccPortFromRequest(request);
863 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700864 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800865 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800866 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800867 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700868 } else {
869 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000870 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700871 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700872 break;
873
874 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800875 ar = (AsyncResult) msg.obj;
876 request = (MainThreadRequest) ar.userObj;
877 if (ar.exception == null) {
878 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800879 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700880 if (uiccPort == null) {
881 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
882 } else {
883 final int channelId = (Integer) request.argument;
884 uiccPort.onLogicalChannelClosed(channelId);
885 }
Chen Xu540470b2021-12-14 17:15:47 -0800886 } else {
887 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800888 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800889 if (ar.exception instanceof CommandException) {
890 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
891 CommandException.Error error =
892 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800893 if (error == CommandException.Error.INVALID_ARGUMENTS) {
894 // should only throw exceptions from the binder threads.
895 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800896 "iccCloseLogicalChannel: invalid argument ");
897 }
898 } else {
899 loge("iccCloseLogicalChannel: Unknown exception");
900 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800901 request.result = (exception != null) ? exception :
902 new IllegalStateException(
903 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800904 }
905 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800906 break;
907
908 case CMD_NV_READ_ITEM:
909 request = (MainThreadRequest) msg.obj;
910 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800911 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
912 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800913 break;
914
915 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700916 ar = (AsyncResult) msg.obj;
917 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800918 if (ar.exception == null && ar.result != null) {
919 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700920 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800921 request.result = "";
922 if (ar.result == null) {
923 loge("nvReadItem: Empty response");
924 } else if (ar.exception instanceof CommandException) {
925 loge("nvReadItem: CommandException: " +
926 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700927 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800928 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700929 }
930 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700931 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700932 break;
933
Jake Hambye994d462014-02-03 13:10:13 -0800934 case CMD_NV_WRITE_ITEM:
935 request = (MainThreadRequest) msg.obj;
936 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
937 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800938 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700939 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800940 break;
941
942 case EVENT_NV_WRITE_ITEM_DONE:
943 handleNullReturnEvent(msg, "nvWriteItem");
944 break;
945
946 case CMD_NV_WRITE_CDMA_PRL:
947 request = (MainThreadRequest) msg.obj;
948 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800949 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800950 break;
951
952 case EVENT_NV_WRITE_CDMA_PRL_DONE:
953 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
954 break;
955
chen xu6dac5ab2018-10-26 17:39:23 -0700956 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800957 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700958 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800959 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800960 break;
961
chen xu6dac5ab2018-10-26 17:39:23 -0700962 case EVENT_RESET_MODEM_CONFIG_DONE:
963 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800964 break;
965
Sooraj Sasindran37444802020-08-11 10:40:43 -0700966 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
967 request = (MainThreadRequest) msg.obj;
968 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
969 request);
970 Phone phone = getPhoneFromRequest(request);
971 if (phone != null) {
972 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
973 } else {
974 loge("isNRDualConnectivityEnabled: No phone object");
975 request.result = false;
976 notifyRequester(request);
977 }
978 break;
979 }
980
981 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
982 ar = (AsyncResult) msg.obj;
983 request = (MainThreadRequest) ar.userObj;
984 if (ar.exception == null && ar.result != null) {
985 request.result = ar.result;
986 } else {
987 // request.result must be set to something non-null
988 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700989 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700990 request.result = ar.result;
991 } else {
992 request.result = false;
993 }
994 if (ar.result == null) {
995 loge("isNRDualConnectivityEnabled: Empty response");
996 } else if (ar.exception instanceof CommandException) {
997 loge("isNRDualConnectivityEnabled: CommandException: "
998 + ar.exception);
999 } else {
1000 loge("isNRDualConnectivityEnabled: Unknown exception");
1001 }
1002 }
1003 notifyRequester(request);
1004 break;
1005
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001006 case CMD_IS_VONR_ENABLED: {
1007 request = (MainThreadRequest) msg.obj;
1008 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
1009 request);
1010 Phone phone = getPhoneFromRequest(request);
1011 if (phone != null) {
1012 phone.isVoNrEnabled(onCompleted, request.workSource);
1013 } else {
1014 loge("isVoNrEnabled: No phone object");
1015 request.result = false;
1016 notifyRequester(request);
1017 }
1018 break;
1019 }
1020
1021 case EVENT_IS_VONR_ENABLED_DONE:
1022 ar = (AsyncResult) msg.obj;
1023 request = (MainThreadRequest) ar.userObj;
1024 if (ar.exception == null && ar.result != null) {
1025 request.result = ar.result;
1026 } else {
1027 // request.result must be set to something non-null
1028 // for the calling thread to unblock
1029 if (ar.result != null) {
1030 request.result = ar.result;
1031 } else {
1032 request.result = false;
1033 }
1034 if (ar.result == null) {
1035 loge("isVoNrEnabled: Empty response");
1036 } else if (ar.exception instanceof CommandException) {
1037 loge("isVoNrEnabled: CommandException: "
1038 + ar.exception);
1039 } else {
1040 loge("isVoNrEnabled: Unknown exception");
1041 }
1042 }
1043 notifyRequester(request);
1044 break;
1045
Sooraj Sasindran37444802020-08-11 10:40:43 -07001046 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1047 request = (MainThreadRequest) msg.obj;
1048 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1049 Phone phone = getPhoneFromRequest(request);
1050 if (phone != null) {
1051 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1052 request.workSource);
1053 } else {
1054 loge("enableNrDualConnectivity: No phone object");
1055 request.result =
1056 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1057 notifyRequester(request);
1058 }
1059 break;
1060 }
1061
1062 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1063 ar = (AsyncResult) msg.obj;
1064 request = (MainThreadRequest) ar.userObj;
1065 if (ar.exception == null) {
1066 request.result =
1067 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1068 } else {
1069 request.result =
1070 TelephonyManager
1071 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1072 if (ar.exception instanceof CommandException) {
1073 CommandException.Error error =
1074 ((CommandException) (ar.exception)).getCommandError();
1075 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1076 request.result =
1077 TelephonyManager
1078 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001079 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1080 request.result =
1081 TelephonyManager
1082 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001083 }
1084 loge("enableNrDualConnectivity" + ": CommandException: "
1085 + ar.exception);
1086 } else {
1087 loge("enableNrDualConnectivity" + ": Unknown exception");
1088 }
1089 }
1090 notifyRequester(request);
1091 break;
1092 }
1093
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001094 case CMD_ENABLE_VONR: {
1095 request = (MainThreadRequest) msg.obj;
1096 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1097 Phone phone = getPhoneFromRequest(request);
1098 if (phone != null) {
1099 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1100 request.workSource);
1101 } else {
1102 loge("setVoNrEnabled: No phone object");
1103 request.result =
1104 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1105 notifyRequester(request);
1106 }
1107 break;
1108 }
1109
1110 case EVENT_ENABLE_VONR_DONE: {
1111 ar = (AsyncResult) msg.obj;
1112 request = (MainThreadRequest) ar.userObj;
1113 if (ar.exception == null) {
1114 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1115 } else {
1116 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1117 if (ar.exception instanceof CommandException) {
1118 CommandException.Error error =
1119 ((CommandException) (ar.exception)).getCommandError();
1120 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1121 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1122 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1123 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1124 } else {
1125 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1126 }
1127 loge("setVoNrEnabled" + ": CommandException: "
1128 + ar.exception);
1129 } else {
1130 loge("setVoNrEnabled" + ": Unknown exception");
1131 }
1132 }
1133 notifyRequester(request);
1134 break;
1135 }
1136
SongFerngWang3ef3e072020-12-21 16:41:52 +08001137 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001138 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001139 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1140 request);
1141 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001142 break;
1143
SongFerngWang3ef3e072020-12-21 16:41:52 +08001144 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001145 ar = (AsyncResult) msg.obj;
1146 request = (MainThreadRequest) ar.userObj;
1147 if (ar.exception == null && ar.result != null) {
1148 request.result = ar.result; // Integer
1149 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301150 // request.result must be set to something non-null
1151 // for the calling thread to unblock
1152 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001153 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001154 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001155 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001156 loge("getAllowedNetworkTypesBitmask: CommandException: "
1157 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001158 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001159 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001160 }
1161 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001162 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001163 break;
1164
SongFerngWang3ef3e072020-12-21 16:41:52 +08001165 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001166 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001167 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1168 request);
1169 Pair<Integer, Long> reasonWithNetworkTypes =
1170 (Pair<Integer, Long>) request.argument;
1171 getPhoneFromRequest(request).setAllowedNetworkTypes(
1172 reasonWithNetworkTypes.first,
1173 reasonWithNetworkTypes.second,
1174 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001175 break;
1176
SongFerngWang3ef3e072020-12-21 16:41:52 +08001177 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1178 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001179 break;
1180
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001181 case CMD_SET_VOICEMAIL_NUMBER:
1182 request = (MainThreadRequest) msg.obj;
1183 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1184 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001185 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1186 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001187 break;
1188
1189 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1190 handleNullReturnEvent(msg, "setVoicemailNumber");
1191 break;
1192
Stuart Scott54788802015-03-30 13:18:01 -07001193 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1194 request = (MainThreadRequest) msg.obj;
1195 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1196 request);
1197 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1198 break;
1199
1200 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1201 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1202 break;
1203
Shishir Agrawal302c8692015-06-19 13:49:39 -07001204 case CMD_PERFORM_NETWORK_SCAN:
1205 request = (MainThreadRequest) msg.obj;
1206 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1207 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1208 break;
1209
Hall Liu27d24262020-09-18 19:04:59 -07001210 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001211 request = (MainThreadRequest) msg.obj;
1212 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001213 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1214 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1215 request.argument;
1216 int callForwardingReason = args.first;
1217 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001218 break;
Hall Liu27d24262020-09-18 19:04:59 -07001219 }
1220 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001221 ar = (AsyncResult) msg.obj;
1222 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001223 TelephonyManager.CallForwardingInfoCallback callback =
1224 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1225 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001226 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001227 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001228 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1229 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1230 // Service Class is a bit mask per 3gpp 27.007. Search for
1231 // any service for voice call.
1232 if ((callForwardInfo.serviceClass
1233 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001234 callForwardingInfo = new CallForwardingInfo(
1235 callForwardInfo.status
1236 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001237 callForwardInfo.reason,
1238 callForwardInfo.number,
1239 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001240 break;
1241 }
1242 }
1243 // Didn't find a call forward info for voice call.
1244 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001245 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1246 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001247 }
Hall Liu27d24262020-09-18 19:04:59 -07001248 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001249 } else {
1250 if (ar.result == null) {
1251 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1252 }
1253 if (ar.exception != null) {
1254 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1255 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001256 int errorCode = TelephonyManager
1257 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001258 if (ar.exception instanceof CommandException) {
1259 CommandException.Error error =
1260 ((CommandException) (ar.exception)).getCommandError();
1261 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001262 errorCode = TelephonyManager
1263 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001264 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001265 errorCode = TelephonyManager
1266 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001267 }
1268 }
Hall Liu27d24262020-09-18 19:04:59 -07001269 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001270 }
Shuo Qian4a594052020-01-23 11:59:30 -08001271 break;
Hall Liu27d24262020-09-18 19:04:59 -07001272 }
Shuo Qian4a594052020-01-23 11:59:30 -08001273
Hall Liu27d24262020-09-18 19:04:59 -07001274 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001275 request = (MainThreadRequest) msg.obj;
1276 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001277 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001278 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001279 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1280 request.argument).first;
1281 request.phone.setCallForwardingOption(
1282 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001283 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001284 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001285 callForwardingInfoToSet.getReason(),
1286 callForwardingInfoToSet.getNumber(),
1287 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1288 break;
Hall Liu27d24262020-09-18 19:04:59 -07001289 }
Shuo Qian4a594052020-01-23 11:59:30 -08001290
Hall Liu27d24262020-09-18 19:04:59 -07001291 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001292 ar = (AsyncResult) msg.obj;
1293 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001294 Consumer<Integer> callback =
1295 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1296 request.argument).second;
1297 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001298 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001299 int errorCode = TelephonyManager.CallForwardingInfoCallback
1300 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001301 if (ar.exception instanceof CommandException) {
1302 CommandException.Error error =
1303 ((CommandException) (ar.exception)).getCommandError();
1304 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001305 errorCode = TelephonyManager.CallForwardingInfoCallback
1306 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001307 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001308 errorCode = TelephonyManager.CallForwardingInfoCallback
1309 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001310 }
1311 }
1312 callback.accept(errorCode);
1313 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001314 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001315 }
Shuo Qian4a594052020-01-23 11:59:30 -08001316 break;
Hall Liu27d24262020-09-18 19:04:59 -07001317 }
Shuo Qian4a594052020-01-23 11:59:30 -08001318
Hall Liu27d24262020-09-18 19:04:59 -07001319 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001320 request = (MainThreadRequest) msg.obj;
1321 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1322 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1323 break;
Hall Liu27d24262020-09-18 19:04:59 -07001324 }
Shuo Qian4a594052020-01-23 11:59:30 -08001325
Hall Liu27d24262020-09-18 19:04:59 -07001326 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001327 ar = (AsyncResult) msg.obj;
1328 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001329 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001330 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001331 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001332 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001333 // Service Class is a bit mask per 3gpp 27.007.
1334 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001335 if (callForwardResults.length > 1
1336 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001337 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001338 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001339 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1340 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001341 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001342 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001343 }
1344 } else {
1345 if (ar.result == null) {
1346 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1347 }
1348 if (ar.exception != null) {
1349 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1350 }
1351 if (ar.exception instanceof CommandException) {
1352 CommandException.Error error =
1353 ((CommandException) (ar.exception)).getCommandError();
1354 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001355 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001356 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001357 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1358 callWaitingStatus =
1359 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001360 }
1361 }
1362 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001363 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001364 break;
Hall Liu27d24262020-09-18 19:04:59 -07001365 }
Shuo Qian4a594052020-01-23 11:59:30 -08001366
Hall Liu27d24262020-09-18 19:04:59 -07001367 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001368 request = (MainThreadRequest) msg.obj;
1369 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001370 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1371 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001372 break;
Hall Liu27d24262020-09-18 19:04:59 -07001373 }
Shuo Qian4a594052020-01-23 11:59:30 -08001374
Hall Liu27d24262020-09-18 19:04:59 -07001375 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001376 ar = (AsyncResult) msg.obj;
1377 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001378 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1379 Consumer<Integer> callback =
1380 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1381 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001382 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001383 if (ar.exception instanceof CommandException) {
1384 CommandException.Error error =
1385 ((CommandException) (ar.exception)).getCommandError();
1386 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1387 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001388 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1389 callback.accept(
1390 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001391 } else {
1392 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1393 }
1394 } else {
1395 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1396 }
1397 } else {
1398 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1399 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001400 }
Shuo Qian4a594052020-01-23 11:59:30 -08001401 break;
Hall Liu27d24262020-09-18 19:04:59 -07001402 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001403 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1404 ar = (AsyncResult) msg.obj;
1405 request = (MainThreadRequest) ar.userObj;
1406 CellNetworkScanResult cellScanResult;
1407 if (ar.exception == null && ar.result != null) {
1408 cellScanResult = new CellNetworkScanResult(
1409 CellNetworkScanResult.STATUS_SUCCESS,
1410 (List<OperatorInfo>) ar.result);
1411 } else {
1412 if (ar.result == null) {
1413 loge("getCellNetworkScanResults: Empty response");
1414 }
1415 if (ar.exception != null) {
1416 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1417 }
1418 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1419 if (ar.exception instanceof CommandException) {
1420 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001421 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001422 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1423 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1424 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1425 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1426 }
1427 }
1428 cellScanResult = new CellNetworkScanResult(errorCode, null);
1429 }
1430 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001431 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001432 break;
1433
1434 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1435 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001436 ManualNetworkSelectionArgument selArg =
1437 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001438 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1439 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001440 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1441 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001442 break;
1443
1444 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001445 ar = (AsyncResult) msg.obj;
1446 request = (MainThreadRequest) ar.userObj;
1447 if (ar.exception == null) {
1448 request.result = true;
1449 } else {
1450 request.result = false;
1451 loge("setNetworkSelectionModeManual " + ar.exception);
1452 }
1453 notifyRequester(request);
1454 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001455 break;
1456
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001457 case CMD_GET_MODEM_ACTIVITY_INFO:
1458 request = (MainThreadRequest) msg.obj;
1459 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001460 if (defaultPhone != null) {
1461 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001462 } else {
1463 ResultReceiver result = (ResultReceiver) request.argument;
1464 Bundle bundle = new Bundle();
1465 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001466 new ModemActivityInfo(0, 0, 0,
1467 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001468 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001469 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001470 break;
1471
Hall Liud0f208c2020-10-14 16:54:44 -07001472 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001473 ar = (AsyncResult) msg.obj;
1474 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001475 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001476 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001477 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001478 if (mLastModemActivityInfo == null) {
1479 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1480 mLastModemActivitySpecificInfo[0] =
1481 new ActivityStatsTechSpecificInfo(
1482 0,
1483 0,
1484 new int[ModemActivityInfo.getNumTxPowerLevels()],
1485 0);
1486 mLastModemActivityInfo =
1487 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1488 }
1489
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001490 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001491 // Update the last modem activity info and the result of the request.
1492 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1493 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001494 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001495 } else {
1496 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001497 }
Kai Shi917fdc62022-11-28 14:01:02 -08001498 // This is needed to decouple ret from mLastModemActivityInfo
1499 // We don't want to return mLastModemActivityInfo which is updated
1500 // inside mergeModemActivityInfo()
1501 ret = new ModemActivityInfo(
1502 mLastModemActivityInfo.getTimestampMillis(),
1503 mLastModemActivityInfo.getSleepTimeMillis(),
1504 mLastModemActivityInfo.getIdleTimeMillis(),
1505 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001506
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001507 } else {
1508 if (ar.result == null) {
1509 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001510 error = TelephonyManager.ModemActivityInfoException
1511 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001512 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001513 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001514 error = TelephonyManager.ModemActivityInfoException
1515 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001516 } else {
1517 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001518 error = TelephonyManager.ModemActivityInfoException
1519 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001520 }
1521 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001522 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001523 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001524 bundle.putParcelable(
1525 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001526 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001527 } else {
1528 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1529 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001530 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001531 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001532 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001533 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001534
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001535 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001536 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001537 CarrierRestrictionRules argument =
1538 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001539 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001540 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001541 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001542 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001543
1544 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1545 ar = (AsyncResult) msg.obj;
1546 request = (MainThreadRequest) ar.userObj;
1547 if (ar.exception == null && ar.result != null) {
1548 request.result = ar.result;
1549 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001550 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1551 if (ar.exception instanceof CommandException) {
1552 loge("setAllowedCarriers: CommandException: " + ar.exception);
1553 CommandException.Error error =
1554 ((CommandException) (ar.exception)).getCommandError();
1555 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1556 request.result =
1557 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1558 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001559 } else {
1560 loge("setAllowedCarriers: Unknown exception");
1561 }
1562 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001563 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001564 break;
1565
1566 case CMD_GET_ALLOWED_CARRIERS:
1567 request = (MainThreadRequest) msg.obj;
1568 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001569 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001570 break;
1571
1572 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1573 ar = (AsyncResult) msg.obj;
1574 request = (MainThreadRequest) ar.userObj;
1575 if (ar.exception == null && ar.result != null) {
1576 request.result = ar.result;
1577 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001578 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001579 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001580 if (ar.result == null) {
1581 loge("getAllowedCarriers: Empty response");
1582 } else if (ar.exception instanceof CommandException) {
1583 loge("getAllowedCarriers: CommandException: " +
1584 ar.exception);
1585 } else {
1586 loge("getAllowedCarriers: Unknown exception");
1587 }
1588 }
arunvoddud7401012022-12-15 16:08:12 +00001589 if (request.argument != null) {
1590 // This is for the implementation of carrierRestrictionStatus.
1591 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1592 Consumer<Integer> callback = callbackInfo.getConsumer();
Steve Statia28b7cb32024-03-11 23:58:50 +00001593 Set<Integer> callerCarrierIds = callbackInfo.getCarrierIds();
arunvoddud7401012022-12-15 16:08:12 +00001594 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1595 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1596 CarrierRestrictionRules carrierRestrictionRules =
1597 (CarrierRestrictionRules) ar.result;
1598 int carrierId = -1;
1599 try {
1600 CarrierIdentifier carrierIdentifier =
1601 carrierRestrictionRules.getAllowedCarriers().get(0);
1602 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1603 carrierIdentifier);
1604 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1605 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1606 }
1607 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
Steve Statia28b7cb32024-03-11 23:58:50 +00001608 int restrictedStatus =
1609 TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED;
1610 if (carrierId != -1 && callerCarrierIds.contains(carrierId) &&
1611 lockStatus == restrictedStatus) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001612 lockStatus = TelephonyManager
1613 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001614 }
1615 } else {
1616 Rlog.e(LOG_TAG,
1617 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1618 }
1619 callback.accept(lockStatus);
1620 } else {
1621 // This is for the implementation of getAllowedCarriers.
1622 notifyRequester(request);
1623 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001624 break;
1625
Nathan Haroldb3014052017-01-25 15:57:32 -08001626 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1627 ar = (AsyncResult) msg.obj;
1628 request = (MainThreadRequest) ar.userObj;
1629 if (ar.exception == null && ar.result != null) {
1630 request.result = ar.result;
1631 } else {
1632 request.result = new IllegalArgumentException(
1633 "Failed to retrieve Forbidden Plmns");
1634 if (ar.result == null) {
1635 loge("getForbiddenPlmns: Empty response");
1636 } else {
1637 loge("getForbiddenPlmns: Unknown exception");
1638 }
1639 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001640 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001641 break;
1642
1643 case CMD_GET_FORBIDDEN_PLMNS:
1644 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001645 uiccPort = getUiccPortFromRequest(request);
1646 if (uiccPort == null) {
1647 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001648 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001649 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001650 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001651 break;
1652 }
1653 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001654 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001655 if (uiccApp == null) {
1656 loge("getForbiddenPlmns() no app with specified type -- "
1657 + appType);
1658 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001659 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001660 break;
1661 } else {
1662 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1663 + " specified type -- " + appType);
1664 }
1665 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1666 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001667 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001668 break;
1669
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001670 case CMD_SWITCH_SLOTS:
1671 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001672 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001673 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001674 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001675 break;
1676
1677 case EVENT_SWITCH_SLOTS_DONE:
1678 ar = (AsyncResult) msg.obj;
1679 request = (MainThreadRequest) ar.userObj;
1680 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001681 notifyRequester(request);
1682 break;
1683 case CMD_GET_NETWORK_SELECTION_MODE:
1684 request = (MainThreadRequest) msg.obj;
1685 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1686 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1687 break;
1688
1689 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1690 ar = (AsyncResult) msg.obj;
1691 request = (MainThreadRequest) ar.userObj;
1692 if (ar.exception != null) {
1693 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1694 } else {
1695 int mode = ((int[]) ar.result)[0];
1696 if (mode == 0) {
1697 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1698 } else {
1699 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1700 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001701 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001702 notifyRequester(request);
1703 break;
1704 case CMD_GET_CDMA_ROAMING_MODE:
1705 request = (MainThreadRequest) msg.obj;
1706 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1707 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1708 break;
1709 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1710 ar = (AsyncResult) msg.obj;
1711 request = (MainThreadRequest) ar.userObj;
1712 if (ar.exception != null) {
1713 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1714 } else {
1715 request.result = ((int[]) ar.result)[0];
1716 }
1717 notifyRequester(request);
1718 break;
1719 case CMD_SET_CDMA_ROAMING_MODE:
1720 request = (MainThreadRequest) msg.obj;
1721 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1722 int mode = (int) request.argument;
1723 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1724 break;
1725 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1726 ar = (AsyncResult) msg.obj;
1727 request = (MainThreadRequest) ar.userObj;
1728 request.result = ar.exception == null;
1729 notifyRequester(request);
1730 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001731 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1732 request = (MainThreadRequest) msg.obj;
1733 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1734 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1735 break;
1736 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1737 ar = (AsyncResult) msg.obj;
1738 request = (MainThreadRequest) ar.userObj;
1739 if (ar.exception != null) {
1740 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1741 } else {
1742 request.result = ((int[]) ar.result)[0];
1743 }
1744 notifyRequester(request);
1745 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001746 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1747 request = (MainThreadRequest) msg.obj;
1748 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1749 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001750 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1751 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001752 break;
1753 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1754 ar = (AsyncResult) msg.obj;
1755 request = (MainThreadRequest) ar.userObj;
1756 request.result = ar.exception == null;
1757 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001758 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001759 case CMD_GET_ALL_CELL_INFO:
1760 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001761 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001762 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001763 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001764 case EVENT_GET_ALL_CELL_INFO_DONE:
1765 ar = (AsyncResult) msg.obj;
1766 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001767 // If a timeout occurs, the response will be null
1768 request.result = (ar.exception == null && ar.result != null)
1769 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001770 synchronized (request) {
1771 request.notifyAll();
1772 }
1773 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001774 case CMD_REQUEST_CELL_INFO_UPDATE:
1775 request = (MainThreadRequest) msg.obj;
1776 request.phone.requestCellInfoUpdate(request.workSource,
1777 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1778 break;
1779 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1780 ar = (AsyncResult) msg.obj;
1781 request = (MainThreadRequest) ar.userObj;
1782 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1783 try {
1784 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001785 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001786 cb.onError(
1787 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1788 ar.exception.getClass().getName(),
1789 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001790 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001791 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001792 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001793 } else {
1794 // use the result as returned
1795 cb.onCellInfo((List<CellInfo>) ar.result);
1796 }
1797 } catch (RemoteException re) {
1798 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1799 }
1800 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001801 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001802 request = (MainThreadRequest) msg.obj;
1803 WorkSource ws = (WorkSource) request.argument;
1804 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001805 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001806 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001807 }
1808 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001809 ar = (AsyncResult) msg.obj;
1810 request = (MainThreadRequest) ar.userObj;
1811 if (ar.exception == null) {
1812 request.result = ar.result;
1813 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001814 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001815 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001816 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001817 }
1818
1819 synchronized (request) {
1820 request.notifyAll();
1821 }
1822 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001823 }
chen xu6dac5ab2018-10-26 17:39:23 -07001824 case CMD_MODEM_REBOOT:
1825 request = (MainThreadRequest) msg.obj;
1826 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001827 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001828 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001829 case EVENT_CMD_MODEM_REBOOT_DONE:
1830 handleNullReturnEvent(msg, "rebootModem");
1831 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001832 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001833 request = (MainThreadRequest) msg.obj;
1834 boolean enable = (boolean) request.argument;
1835 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001836 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001837 PhoneConfigurationManager.getInstance()
1838 .enablePhone(request.phone, enable, onCompleted);
1839 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001840 }
Michele Berionne5e411512020-11-13 02:36:59 +00001841 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001842 ar = (AsyncResult) msg.obj;
1843 request = (MainThreadRequest) ar.userObj;
1844 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001845 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001846 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001847 if ((boolean) request.result) {
1848 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1849 updateModemStateMetrics();
1850 } else {
1851 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1852 + ar.exception);
1853 }
1854 notifyRequester(request);
1855 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001856 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001857 case CMD_GET_MODEM_STATUS:
1858 request = (MainThreadRequest) msg.obj;
1859 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1860 PhoneConfigurationManager.getInstance()
1861 .getPhoneStatusFromModem(request.phone, onCompleted);
1862 break;
1863 case EVENT_GET_MODEM_STATUS_DONE:
1864 ar = (AsyncResult) msg.obj;
1865 request = (MainThreadRequest) ar.userObj;
1866 int id = request.phone.getPhoneId();
1867 if (ar.exception == null && ar.result != null) {
1868 request.result = ar.result;
1869 //update the cache as modem status has changed
1870 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1871 (boolean) request.result);
1872 } else {
1873 // Return true if modem status cannot be retrieved. For most cases,
1874 // modem status is on. And for older version modems, GET_MODEM_STATUS
1875 // and disable modem are not supported. Modem is always on.
1876 // TODO: this should be fixed in R to support a third
1877 // status UNKNOWN b/131631629
1878 request.result = true;
1879 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1880 + ar.exception);
1881 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001882 notifyRequester(request);
1883 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001884 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1885 request = (MainThreadRequest) msg.obj;
1886 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1887 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1888 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1889 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1890 break;
1891 }
1892 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1893 ar = (AsyncResult) msg.obj;
1894 request = (MainThreadRequest) ar.userObj;
1895 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1896 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1897 args.second.accept(ar.exception == null);
1898 notifyRequester(request);
1899 break;
1900 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001901 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1902 request = (MainThreadRequest) msg.obj;
1903 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1904 Phone phone = getPhoneFromRequest(request);
1905 if (phone != null) {
1906 phone.getSystemSelectionChannels(onCompleted);
1907 } else {
1908 loge("getSystemSelectionChannels: No phone object");
1909 request.result = new ArrayList<RadioAccessSpecifier>();
1910 notifyRequester(request);
1911 }
1912 break;
1913 }
1914 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1915 ar = (AsyncResult) msg.obj;
1916 request = (MainThreadRequest) ar.userObj;
1917 if (ar.exception == null && ar.result != null) {
1918 request.result = ar.result;
1919 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001920 request.result = new IllegalStateException(
1921 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001922 if (ar.result == null) {
1923 loge("getSystemSelectionChannels: Empty response");
1924 } else {
1925 loge("getSystemSelectionChannels: Unknown exception");
1926 }
1927 }
1928 notifyRequester(request);
1929 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001930 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1931 ar = (AsyncResult) msg.obj;
1932 request = (MainThreadRequest) ar.userObj;
1933 if (ar.exception == null && ar.result != null) {
1934 request.result = ar.result;
1935 } else {
1936 request.result = -1;
1937 loge("Failed to set Forbidden Plmns");
1938 if (ar.result == null) {
1939 loge("setForbidenPlmns: Empty response");
1940 } else if (ar.exception != null) {
1941 loge("setForbiddenPlmns: Exception: " + ar.exception);
1942 request.result = -1;
1943 } else {
1944 loge("setForbiddenPlmns: Unknown exception");
1945 }
1946 }
1947 notifyRequester(request);
1948 break;
1949 case CMD_SET_FORBIDDEN_PLMNS:
1950 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001951 uiccPort = getUiccPortFromRequest(request);
1952 if (uiccPort == null) {
1953 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001954 request.result = -1;
1955 notifyRequester(request);
1956 break;
1957 }
1958 Pair<Integer, List<String>> setFplmnsArgs =
1959 (Pair<Integer, List<String>>) request.argument;
1960 appType = setFplmnsArgs.first;
1961 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001962 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001963 if (uiccApp == null) {
1964 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1965 request.result = -1;
1966 loge("Failed to get UICC App");
1967 notifyRequester(request);
1968 } else {
1969 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1970 ((SIMRecords) uiccApp.getIccRecords())
1971 .setForbiddenPlmns(onCompleted, fplmns);
1972 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001973 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001974 case CMD_ERASE_MODEM_CONFIG:
1975 request = (MainThreadRequest) msg.obj;
1976 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1977 defaultPhone.eraseModemConfig(onCompleted);
1978 break;
1979 case EVENT_ERASE_MODEM_CONFIG_DONE:
1980 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001981 break;
zoey chene02881a2019-12-30 16:11:23 +08001982
Kai Shif70f46f2021-03-03 13:59:46 -08001983 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1984 request = (MainThreadRequest) msg.obj;
1985 request.result = defaultPhone.eraseDataInSharedPreferences();
1986 notifyRequester(request);
1987 break;
1988
zoey chene02881a2019-12-30 16:11:23 +08001989 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1990 request = (MainThreadRequest) msg.obj;
1991 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1992 Pair<String, String> changed = (Pair<String, String>) request.argument;
1993 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1994 changed.first, changed.second, onCompleted);
1995 break;
1996 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1997 ar = (AsyncResult) msg.obj;
1998 request = (MainThreadRequest) ar.userObj;
1999 if (ar.exception == null) {
2000 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002001 // If the operation is successful, update the PIN storage
2002 Pair<String, String> passwords = (Pair<String, String>) request.argument;
2003 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00002004 UiccController.getInstance().getPinStorage()
2005 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08002006 } else {
2007 request.result = msg.arg1;
2008 }
2009 notifyRequester(request);
2010 break;
2011
Michele Berionne5e411512020-11-13 02:36:59 +00002012 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08002013 request = (MainThreadRequest) msg.obj;
2014 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
2015 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2016 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2017 enabled.first, enabled.second, onCompleted);
2018 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002019 }
zoey chene02881a2019-12-30 16:11:23 +08002020 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2021 ar = (AsyncResult) msg.obj;
2022 request = (MainThreadRequest) ar.userObj;
2023 if (ar.exception == null) {
2024 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002025 // If the operation is successful, update the PIN storage
2026 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2027 int phoneId = getPhoneFromRequest(request).getPhoneId();
2028 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002029 UiccController.getInstance().getPinStorage()
2030 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002031 } else {
2032 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2033 }
zoey chene02881a2019-12-30 16:11:23 +08002034 } else {
2035 request.result = msg.arg1;
2036 }
Michele Berionne5e411512020-11-13 02:36:59 +00002037
2038
zoey chene02881a2019-12-30 16:11:23 +08002039 notifyRequester(request);
2040 break;
2041
Peter Wangdafb9ac2020-01-15 14:13:38 -08002042 case MSG_NOTIFY_USER_ACTIVITY:
2043 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002044 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002045 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2046 getDefaultPhone().getContext().sendBroadcastAsUser(
2047 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2048 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002049
2050 case CMD_SET_DATA_THROTTLING: {
2051 request = (MainThreadRequest) msg.obj;
2052 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2053 DataThrottlingRequest dataThrottlingRequest =
2054 (DataThrottlingRequest) request.argument;
2055 Phone phone = getPhoneFromRequest(request);
2056 if (phone != null) {
2057 phone.setDataThrottling(onCompleted,
2058 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2059 dataThrottlingRequest.getCompletionDurationMillis());
2060 } else {
2061 loge("setDataThrottling: No phone object");
2062 request.result =
2063 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2064 notifyRequester(request);
2065 }
2066
2067 break;
2068 }
2069 case EVENT_SET_DATA_THROTTLING_DONE:
2070 ar = (AsyncResult) msg.obj;
2071 request = (MainThreadRequest) ar.userObj;
2072
2073 if (ar.exception == null) {
2074 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2075 } else if (ar.exception instanceof CommandException) {
2076 loge("setDataThrottling: CommandException: " + ar.exception);
2077 CommandException.Error error =
2078 ((CommandException) (ar.exception)).getCommandError();
2079
2080 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2081 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002082 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002083 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2084 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002085 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2086 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002087 } else {
2088 request.result =
2089 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2090 }
2091 } else {
2092 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2093 }
2094 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2095 notifyRequester(request);
2096 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002097
2098 case CMD_SET_SIM_POWER: {
2099 request = (MainThreadRequest) msg.obj;
2100 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2101 request = (MainThreadRequest) msg.obj;
2102 int stateToSet =
2103 ((Pair<Integer, IIntegerConsumer>)
2104 request.argument).first;
2105 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2106 break;
2107 }
2108 case EVENT_SET_SIM_POWER_DONE: {
2109 ar = (AsyncResult) msg.obj;
2110 request = (MainThreadRequest) ar.userObj;
2111 IIntegerConsumer callback =
2112 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2113 if (ar.exception != null) {
2114 loge("setSimPower exception: " + ar.exception);
2115 int errorCode = TelephonyManager.CallForwardingInfoCallback
2116 .RESULT_ERROR_UNKNOWN;
2117 if (ar.exception instanceof CommandException) {
2118 CommandException.Error error =
2119 ((CommandException) (ar.exception)).getCommandError();
2120 if (error == CommandException.Error.SIM_ERR) {
2121 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2122 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2123 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2124 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2125 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2126 } else {
2127 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2128 }
2129 }
2130 try {
2131 callback.accept(errorCode);
2132 } catch (RemoteException e) {
2133 // Ignore if the remote process is no longer available to call back.
2134 Log.w(LOG_TAG, "setSimPower: callback not available.");
2135 }
2136 } else {
2137 try {
2138 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2139 } catch (RemoteException e) {
2140 // Ignore if the remote process is no longer available to call back.
2141 Log.w(LOG_TAG, "setSimPower: callback not available.");
2142 }
2143 }
2144 break;
2145 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002146 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2147 request = (MainThreadRequest) msg.obj;
2148
2149 final Phone phone = getPhoneFromRequest(request);
2150 if (phone == null || phone.getServiceStateTracker() == null) {
2151 request.result = new IllegalStateException("Phone or SST is null");
2152 notifyRequester(request);
2153 break;
2154 }
2155
2156 Pair<Integer, SignalStrengthUpdateRequest> pair =
2157 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2158 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2159 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002160 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002161 request.subId, pair.first /*callingUid*/,
2162 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002163 break;
2164 }
2165 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2166 ar = (AsyncResult) msg.obj;
2167 request = (MainThreadRequest) ar.userObj;
2168 // request.result will be the exception of ar if present, true otherwise.
2169 // Be cautious not to leave result null which will wait() forever
2170 request.result = ar.exception != null ? ar.exception : true;
2171 notifyRequester(request);
2172 break;
2173 }
2174 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2175 request = (MainThreadRequest) msg.obj;
2176
2177 Phone phone = getPhoneFromRequest(request);
2178 if (phone == null || phone.getServiceStateTracker() == null) {
2179 request.result = new IllegalStateException("Phone or SST is null");
2180 notifyRequester(request);
2181 break;
2182 }
2183
2184 Pair<Integer, SignalStrengthUpdateRequest> pair =
2185 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2186 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2187 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002188 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002189 request.subId, pair.first /*callingUid*/,
2190 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002191 break;
2192 }
2193 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2194 ar = (AsyncResult) msg.obj;
2195 request = (MainThreadRequest) ar.userObj;
2196 request.result = ar.exception != null ? ar.exception : true;
2197 notifyRequester(request);
2198 break;
2199 }
Jordan Liu109698e2020-11-24 14:50:34 -08002200
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002201 case CMD_GET_SLICING_CONFIG: {
2202 request = (MainThreadRequest) msg.obj;
2203 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2204 request.phone.getSlicingConfig(onCompleted);
2205 break;
2206 }
2207 case EVENT_GET_SLICING_CONFIG_DONE: {
2208 ar = (AsyncResult) msg.obj;
2209 request = (MainThreadRequest) ar.userObj;
2210 ResultReceiver result = (ResultReceiver) request.argument;
2211
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002212 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002213 Bundle bundle = new Bundle();
2214 int resultCode = 0;
2215 if (ar.exception != null) {
2216 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2217 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002218 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002219 } else if (ar.result == null) {
2220 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002221 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002222 } else {
2223 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002224 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2225 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002226 }
2227
2228 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002229 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002230 }
2231 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2232 result.send(resultCode, bundle);
2233 notifyRequester(request);
2234 break;
2235 }
2236
Sarah Chin71b3a852022-09-28 15:54:19 -07002237 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002238 request = (MainThreadRequest) msg.obj;
2239 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002240 PurchasePremiumCapabilityArgument arg =
2241 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chincc5446f2023-10-23 17:57:19 -07002242 SlicePurchaseController.getInstance(request.phone, mFeatureFlags)
2243 .purchasePremiumCapability(arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002244 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002245 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002246
Sarah Chin71b3a852022-09-28 15:54:19 -07002247 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002248 ar = (AsyncResult) msg.obj;
2249 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002250 PurchasePremiumCapabilityArgument arg =
2251 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002252 try {
2253 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002254 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002255 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002256 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chinff8b1802023-04-11 14:22:14 -07002257 + ", result="
Sarah Chin2ec39f62022-08-31 17:03:26 -07002258 + TelephonyManager.convertPurchaseResultToString(result));
2259 } catch (RemoteException e) {
2260 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002261 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002262 + " failed: " + e;
2263 if (DBG) log(logStr);
2264 AnomalyReporter.reportAnomaly(
2265 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2266 }
2267 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002268 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002269
Michele Berionne5e411512020-11-13 02:36:59 +00002270 case CMD_PREPARE_UNATTENDED_REBOOT:
2271 request = (MainThreadRequest) msg.obj;
2272 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002273 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002274 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002275 notifyRequester(request);
2276 break;
2277
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002278 default:
2279 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2280 break;
2281 }
2282 }
Jake Hambye994d462014-02-03 13:10:13 -08002283
Pengquan Menga1bb6272018-09-06 09:59:22 -07002284 private void notifyRequester(MainThreadRequest request) {
2285 synchronized (request) {
2286 request.notifyAll();
2287 }
2288 }
2289
Jake Hambye994d462014-02-03 13:10:13 -08002290 private void handleNullReturnEvent(Message msg, String command) {
2291 AsyncResult ar = (AsyncResult) msg.obj;
2292 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2293 if (ar.exception == null) {
2294 request.result = true;
2295 } else {
2296 request.result = false;
2297 if (ar.exception instanceof CommandException) {
2298 loge(command + ": CommandException: " + ar.exception);
2299 } else {
2300 loge(command + ": Unknown exception");
2301 }
2302 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002303 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002304 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002305 }
2306
2307 /**
2308 * Posts the specified command to be executed on the main thread,
2309 * waits for the request to complete, and returns the result.
2310 * @see #sendRequestAsync
2311 */
2312 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002313 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2314 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002315 }
2316
2317 /**
2318 * Posts the specified command to be executed on the main thread,
2319 * waits for the request to complete, and returns the result.
2320 * @see #sendRequestAsync
2321 */
2322 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2323 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002324 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002325 }
2326
2327 /**
2328 * Posts the specified command to be executed on the main thread,
2329 * waits for the request to complete, and returns the result.
2330 * @see #sendRequestAsync
2331 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002332 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002333 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2334 }
2335
2336 /**
2337 * Posts the specified command to be executed on the main thread,
2338 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2339 * if not timeout or null otherwise.
2340 * @see #sendRequestAsync
2341 */
2342 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2343 long timeoutInMs) {
2344 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002345 }
2346
2347 /**
2348 * Posts the specified command to be executed on the main thread,
2349 * waits for the request to complete, and returns the result.
2350 * @see #sendRequestAsync
2351 */
Nathan Harold92bed182018-10-12 18:16:49 -07002352 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002353 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002354 }
2355
2356 /**
2357 * Posts the specified command to be executed on the main thread,
2358 * waits for the request to complete, and returns the result.
2359 * @see #sendRequestAsync
2360 */
2361 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002362 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2363 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002364 }
2365
2366 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002367 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2368 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2369 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002370 * @see #sendRequestAsync
2371 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002372 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2373 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002374 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2375 throw new RuntimeException("This method will deadlock if called from the main thread.");
2376 }
2377
Nathan Harold92bed182018-10-12 18:16:49 -07002378 MainThreadRequest request = null;
2379 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2380 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2381 } else if (phone != null) {
2382 request = new MainThreadRequest(argument, phone, workSource);
2383 } else {
2384 request = new MainThreadRequest(argument, subId, workSource);
2385 }
2386
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002387 Message msg = mMainThreadHandler.obtainMessage(command, request);
2388 msg.sendToTarget();
2389
Rambo Wang0f050d82021-02-12 11:43:36 -08002390
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002391 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002392 if (timeoutInMs >= 0) {
2393 // Wait for at least timeoutInMs before returning null request result
2394 long now = SystemClock.elapsedRealtime();
2395 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002396 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002397 try {
2398 request.wait(deadline - now);
2399 } catch (InterruptedException e) {
2400 // Do nothing, go back and check if request is completed or timeout
2401 } finally {
2402 now = SystemClock.elapsedRealtime();
2403 }
2404 }
2405 } else {
2406 // Wait for the request to complete
2407 while (request.result == null) {
2408 try {
2409 request.wait();
2410 } catch (InterruptedException e) {
2411 // Do nothing, go back and wait until the request is complete
2412 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002413 }
2414 }
2415 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002416 if (request.result == null) {
2417 Log.wtf(LOG_TAG,
2418 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2419 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002420 return request.result;
2421 }
2422
2423 /**
2424 * Asynchronous ("fire and forget") version of sendRequest():
2425 * Posts the specified command to be executed on the main thread, and
2426 * returns immediately.
2427 * @see #sendRequest
2428 */
2429 private void sendRequestAsync(int command) {
2430 mMainThreadHandler.sendEmptyMessage(command);
2431 }
2432
2433 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002434 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002435 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002436 */
2437 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002438 sendRequestAsync(command, argument, null, null);
2439 }
2440
2441 /**
2442 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2443 * @see {@link #sendRequest(int,Object)}
2444 */
2445 private void sendRequestAsync(
2446 int command, Object argument, Phone phone, WorkSource workSource) {
2447 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002448 Message msg = mMainThreadHandler.obtainMessage(command, request);
2449 msg.sendToTarget();
2450 }
2451
2452 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002453 * Initialize the singleton PhoneInterfaceManager instance.
2454 * This is only done once, at startup, from PhoneApp.onCreate().
2455 */
Sarah Chincc5446f2023-10-23 17:57:19 -07002456 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002457 synchronized (PhoneInterfaceManager.class) {
2458 if (sInstance == null) {
Sarah Chincc5446f2023-10-23 17:57:19 -07002459 sInstance = new PhoneInterfaceManager(app, featureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002460 } else {
2461 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2462 }
2463 return sInstance;
2464 }
2465 }
2466
2467 /** Private constructor; @see init() */
Sarah Chincc5446f2023-10-23 17:57:19 -07002468 private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002469 mApp = app;
Sarah Chincc5446f2023-10-23 17:57:19 -07002470 mFeatureFlags = featureFlags;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -08002471 mTelecomFeatureFlags = new com.android.server.telecom.flags.FeatureFlagsImpl();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002472 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002473 mImsResolver = ImsResolver.getInstance();
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +00002474 mSatelliteController = SatelliteController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002475 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002476 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2477 mMainThreadHandler = new MainThreadHandler();
Sarah Chin4beb2b72023-02-14 14:47:54 -08002478 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002479 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002480 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002481 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002482 mNotifyUserActivity = new AtomicBoolean(false);
joonhunshin4ac60942023-11-15 15:23:39 +00002483 mPackageManager = app.getPackageManager();
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -08002484 mSatelliteAccessController = SatelliteAccessController.getOrCreateInstance(
2485 getDefaultPhone().getContext(), featureFlags);
Tyler Gunn64144d92022-03-17 14:16:41 -07002486 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002487 publish();
arunvoddud7401012022-12-15 16:08:12 +00002488 CarrierAllowListInfo.loadInstance(mApp);
Hyosun Kim240214a2023-11-02 13:30:15 +00002489
2490 // Create the SatelliteEntitlementController singleton, for using the get the
2491 // entitlementStatus for satellite service.
2492 SatelliteEntitlementController.make(mApp, mFeatureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002493 }
2494
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002495 @VisibleForTesting
2496 public SharedPreferences getSharedPreferences() {
2497 return mTelephonySharedPreferences;
2498 }
2499
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002500 /**
2501 * Get the default phone for this device.
2502 */
2503 @VisibleForTesting
2504 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002505 Phone thePhone = getPhone(getDefaultSubscription());
2506 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2507 }
2508
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002509 private void publish() {
2510 if (DBG) log("publish: " + this);
2511
Peter Wangc035ce42020-01-08 21:00:22 -08002512 TelephonyFrameworkInitializer
2513 .getTelephonyServiceManager()
2514 .getTelephonyServiceRegisterer()
2515 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002516 }
2517
Stuart Scott584921c2015-01-15 17:10:34 -08002518 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002519 if (request.phone != null) {
2520 return request.phone;
2521 } else {
2522 return getPhoneFromSubId(request.subId);
2523 }
2524 }
2525
2526 private Phone getPhoneFromSubId(int subId) {
2527 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2528 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002529 }
2530
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002531 /**
2532 * Get phone object associated with a subscription.
2533 * Return default phone if phone object associated with subscription is null
2534 * @param subId - subscriptionId
2535 * @return phone object associated with a subscription or default phone if null.
2536 */
Ling Mac28f0212023-03-24 16:07:15 -07002537 private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) {
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002538 Phone phone = getPhoneFromSubId(subId);
2539 if (phone == null) {
Ling Mac28f0212023-03-24 16:07:15 -07002540 loge("Called with invalid subId: " + subId + ". Retrying with default phone.");
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002541 phone = getDefaultPhone();
2542 }
2543 return phone;
2544 }
2545
Rambo Wange53e07d2022-05-10 13:01:13 -07002546 @Nullable
2547 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002548 Phone phone = getPhoneFromRequest(request);
2549 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002550 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002551 }
2552
Ling Mac28f0212023-03-24 16:07:15 -07002553 /**
2554 * @param subId The sub Id that associates the phone. If the device has no active SIM, passing
2555 * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <=
2556 * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}.
2557 * @return The Phone associated the sub Id
2558 */
2559 private @Nullable Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002560 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002561 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002562
Kai Shif70f46f2021-03-03 13:59:46 -08002563 private void sendEraseModemConfig(@NonNull Phone phone) {
2564 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2565 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2566 }
2567
2568 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2569 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2570 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002571 }
2572
Peter Wang44b186e2020-01-13 23:33:09 -08002573 private boolean isImsAvailableOnDevice() {
2574 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2575 if (pm == null) {
2576 // For some reason package manger is not available.. This will fail internally anyway,
2577 // so do not throw error and allow.
2578 return true;
2579 }
2580 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2581 }
2582
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002583 public void dial(String number) {
joonhunshin4ac60942023-11-15 15:23:39 +00002584 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2585 PackageManager.FEATURE_TELEPHONY_CALLING, "dial");
2586
Wink Savilleadd7cc52014-09-08 14:23:09 -07002587 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002588 }
2589
Wink Savilleb564aae2014-10-23 10:18:09 -07002590 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002591 if (DBG) log("dial: " + number);
2592 // No permission check needed here: This is just a wrapper around the
2593 // ACTION_DIAL intent, which is available to any app since it puts up
2594 // the UI before it does anything.
2595
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002596 final long identity = Binder.clearCallingIdentity();
2597 try {
2598 String url = createTelUrl(number);
2599 if (url == null) {
2600 return;
2601 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002602
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002603 // PENDING: should we just silently fail if phone is offhook or ringing?
2604 PhoneConstants.State state = mCM.getState(subId);
2605 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2606 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2607 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2608 mApp.startActivity(intent);
2609 }
2610 } finally {
2611 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002612 }
2613 }
2614
2615 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002616 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002617 }
2618
Wink Savilleb564aae2014-10-23 10:18:09 -07002619 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002620 if (DBG) log("call: " + number);
2621
2622 // This is just a wrapper around the ACTION_CALL intent, but we still
2623 // need to do a permission check since we're calling startActivity()
2624 // from the context of the phone app.
2625 enforceCallPermission();
2626
Jordan Liu1617b712019-07-10 15:06:26 -07002627 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002628 != AppOpsManager.MODE_ALLOWED) {
2629 return;
2630 }
2631
joonhunshin4ac60942023-11-15 15:23:39 +00002632 enforceTelephonyFeatureWithException(callingPackage,
2633 PackageManager.FEATURE_TELEPHONY_CALLING, "call");
2634
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002635 final long identity = Binder.clearCallingIdentity();
2636 try {
2637 String url = createTelUrl(number);
2638 if (url == null) {
2639 return;
2640 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002641
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002642 boolean isValid = false;
2643 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2644 if (slist != null) {
2645 for (SubscriptionInfo subInfoRecord : slist) {
2646 if (subInfoRecord.getSubscriptionId() == subId) {
2647 isValid = true;
2648 break;
2649 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002650 }
Wink Saville08874612014-08-31 19:19:58 -07002651 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002652 if (!isValid) {
2653 return;
2654 }
Wink Saville08874612014-08-31 19:19:58 -07002655
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002656 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2657 intent.putExtra(SUBSCRIPTION_KEY, subId);
2658 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2659 mApp.startActivity(intent);
2660 } finally {
2661 Binder.restoreCallingIdentity(identity);
2662 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002663 }
2664
Wink Savilleb564aae2014-10-23 10:18:09 -07002665 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002666 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002667 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2668 }
2669
Wink Savilleb564aae2014-10-23 10:18:09 -07002670 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002671 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002672 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2673 }
2674
Wink Savilleb564aae2014-10-23 10:18:09 -07002675 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002676 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002677
joonhunshin4ac60942023-11-15 15:23:39 +00002678 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2679 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
2680 "supplyPinReportResultForSubscriber");
2681
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002682 final long identity = Binder.clearCallingIdentity();
2683 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002684 Phone phone = getPhone(subId);
2685 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002686 checkSimPin.start();
2687 return checkSimPin.unlockSim(null, pin);
2688 } finally {
2689 Binder.restoreCallingIdentity(identity);
2690 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002691 }
2692
Wink Savilleb564aae2014-10-23 10:18:09 -07002693 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002694 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002695
joonhunshin4ac60942023-11-15 15:23:39 +00002696 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2697 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "supplyPukForSubscriber");
2698
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002699 final long identity = Binder.clearCallingIdentity();
2700 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002701 Phone phone = getPhone(subId);
2702 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002703 checkSimPuk.start();
2704 return checkSimPuk.unlockSim(puk, pin);
2705 } finally {
2706 Binder.restoreCallingIdentity(identity);
2707 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002708 }
2709
2710 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002711 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002712 * a synchronous one.
2713 */
2714 private static class UnlockSim extends Thread {
2715
2716 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002717 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002718
2719 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002720 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2721 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002722
2723 // For replies from SimCard interface
2724 private Handler mHandler;
2725
2726 // For async handler to identify request type
2727 private static final int SUPPLY_PIN_COMPLETE = 100;
2728
Michele Berionne5e411512020-11-13 02:36:59 +00002729 UnlockSim(int phoneId, IccCard simCard) {
2730 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002731 mSimCard = simCard;
2732 }
2733
2734 @Override
2735 public void run() {
2736 Looper.prepare();
2737 synchronized (UnlockSim.this) {
2738 mHandler = new Handler() {
2739 @Override
2740 public void handleMessage(Message msg) {
2741 AsyncResult ar = (AsyncResult) msg.obj;
2742 switch (msg.what) {
2743 case SUPPLY_PIN_COMPLETE:
2744 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2745 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002746 mRetryCount = msg.arg1;
2747 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002748 CommandException.Error error = null;
2749 if (ar.exception instanceof CommandException) {
2750 error = ((CommandException) (ar.exception))
2751 .getCommandError();
2752 }
2753 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07002754 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002755 } else if (error == CommandException.Error.ABORTED) {
2756 /* When UiccCardApp dispose, handle message and return
2757 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08002758 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002759 } else {
2760 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2761 }
2762 } else {
2763 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2764 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002765 mDone = true;
2766 UnlockSim.this.notifyAll();
2767 }
2768 break;
2769 }
2770 }
2771 };
2772 UnlockSim.this.notifyAll();
2773 }
2774 Looper.loop();
2775 }
2776
2777 /*
2778 * Use PIN or PUK to unlock SIM card
2779 *
2780 * If PUK is null, unlock SIM card with PIN
2781 *
2782 * If PUK is not null, unlock SIM card with PUK and set PIN code
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302783 *
2784 * Besides, since it is reused in class level, the thread's looper will be stopped to avoid
2785 * its thread leak.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002786 */
Wink Saville9de0f752013-10-22 19:04:03 -07002787 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002788
2789 while (mHandler == null) {
2790 try {
2791 wait();
2792 } catch (InterruptedException e) {
2793 Thread.currentThread().interrupt();
2794 }
2795 }
2796 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2797
2798 if (puk == null) {
2799 mSimCard.supplyPin(pin, callback);
2800 } else {
2801 mSimCard.supplyPuk(puk, pin, callback);
2802 }
2803
2804 while (!mDone) {
2805 try {
2806 Log.d(LOG_TAG, "wait for done");
2807 wait();
2808 } catch (InterruptedException e) {
2809 // Restore the interrupted status
2810 Thread.currentThread().interrupt();
2811 }
2812 }
2813 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002814 int[] resultArray = new int[2];
2815 resultArray[0] = mResult;
2816 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002817
2818 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002819 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002820 }
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302821 // This instance is no longer reused, so quit its thread's looper.
2822 mHandler.getLooper().quitSafely();
Michele Berionne5e411512020-11-13 02:36:59 +00002823
Wink Saville9de0f752013-10-22 19:04:03 -07002824 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002825 }
2826 }
2827
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002828 /**
2829 * This method has been removed due to privacy and stability concerns.
2830 */
2831 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002832 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002833 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2834 return;
Wink Saville36469e72014-06-11 15:17:00 -07002835 }
2836
Nathan Harold1f889d82020-06-04 17:05:26 -07002837 @Override
2838 public void updateServiceLocationWithPackageName(String callingPackage) {
2839 mApp.getSystemService(AppOpsManager.class)
2840 .checkPackage(Binder.getCallingUid(), callingPackage);
2841
Nathan Haroldf096d982020-11-18 17:18:06 -08002842 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002843 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2844 // Callers targeting S have no business invoking this method.
2845 return;
2846 }
2847
2848 LocationAccessPolicy.LocationPermissionResult locationResult =
2849 LocationAccessPolicy.checkLocationPermission(mApp,
2850 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2851 .setCallingPackage(callingPackage)
2852 .setCallingFeatureId(null)
2853 .setCallingPid(Binder.getCallingPid())
2854 .setCallingUid(Binder.getCallingUid())
2855 .setMethod("updateServiceLocation")
2856 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2857 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2858 .build());
2859 // Apps that lack location permission have no business calling this method;
2860 // however, because no permission was declared in the public API, denials must
2861 // all be "soft".
2862 switch (locationResult) {
2863 case DENIED_HARD: /* fall through */
2864 case DENIED_SOFT:
2865 return;
2866 }
2867
2868 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002869 final long identity = Binder.clearCallingIdentity();
2870 try {
Ling Mac28f0212023-03-24 16:07:15 -07002871 getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002872 } finally {
2873 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002874 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002875 }
2876
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002877 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002878 @Override
2879 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002880 return isRadioOnWithFeature(callingPackage, null);
2881 }
2882
2883
2884 @Override
2885 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2886 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2887 callingFeatureId);
2888 }
2889
2890 @Deprecated
2891 @Override
2892 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2893 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002894 }
2895
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002896 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002897 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2898 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002899 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002900 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002901 return false;
2902 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002903
joonhunshin4ac60942023-11-15 15:23:39 +00002904 enforceTelephonyFeatureWithException(callingPackage,
2905 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isRadioOnWithFeature");
2906
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002907 final long identity = Binder.clearCallingIdentity();
2908 try {
2909 return isRadioOnForSubscriber(subId);
2910 } finally {
2911 Binder.restoreCallingIdentity(identity);
2912 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002913 }
2914
2915 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002916 final long identity = Binder.clearCallingIdentity();
2917 try {
2918 final Phone phone = getPhone(subId);
2919 if (phone != null) {
2920 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2921 } else {
2922 return false;
2923 }
2924 } finally {
2925 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002926 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002927 }
2928
2929 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002930 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002931 }
Wink Saville36469e72014-06-11 15:17:00 -07002932
Wink Savilleb564aae2014-10-23 10:18:09 -07002933 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002934 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002935
joonhunshin4ac60942023-11-15 15:23:39 +00002936 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2937 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "toggleRadioOnOffForSubscriber");
2938
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002939 final long identity = Binder.clearCallingIdentity();
2940 try {
2941 final Phone phone = getPhone(subId);
2942 if (phone != null) {
2943 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2944 }
2945 } finally {
2946 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002947 }
Wink Saville36469e72014-06-11 15:17:00 -07002948 }
2949
2950 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002951 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002952 }
2953
Wink Savilleb564aae2014-10-23 10:18:09 -07002954 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002955 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002956
2957 final long identity = Binder.clearCallingIdentity();
2958 try {
2959 final Phone phone = getPhone(subId);
2960 if (phone == null) {
2961 return false;
2962 }
2963 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2964 toggleRadioOnOffForSubscriber(subId);
2965 }
2966 return true;
2967 } finally {
2968 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002969 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002970 }
Wink Saville36469e72014-06-11 15:17:00 -07002971
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002972 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002973 enforceReadPrivilegedPermission("needMobileRadioShutdown");
joonhunshin4ac60942023-11-15 15:23:39 +00002974
2975 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2976 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needMobileRadioShutdown");
2977
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002978 /*
2979 * If any of the Radios are available, it will need to be
2980 * shutdown. So return true if any Radio is available.
2981 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002982 final long identity = Binder.clearCallingIdentity();
2983 try {
2984 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2985 Phone phone = PhoneFactory.getPhone(i);
2986 if (phone != null && phone.isRadioAvailable()) return true;
2987 }
2988 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2989 return false;
2990 } finally {
2991 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002992 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002993 }
2994
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002995 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002996 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002997 enforceModifyPermission();
2998
joonhunshin4ac60942023-11-15 15:23:39 +00002999 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3000 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "shutdownMobileRadios");
3001
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003002 final long identity = Binder.clearCallingIdentity();
3003 try {
3004 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3005 logv("Shutting down Phone " + i);
3006 shutdownRadioUsingPhoneId(i);
3007 }
3008 } finally {
3009 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003010 }
3011 }
3012
3013 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003014 Phone phone = PhoneFactory.getPhone(phoneId);
3015 if (phone != null && phone.isRadioAvailable()) {
3016 phone.shutdownRadio();
3017 }
3018 }
3019
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003020 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07003021 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003022
Ling Ma83dc5ea2023-01-12 15:06:04 -08003023 if (!turnOn) {
3024 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
3025 }
3026
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003027 final long identity = Binder.clearCallingIdentity();
3028 try {
3029 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
3030 if (defaultPhone != null) {
3031 defaultPhone.setRadioPower(turnOn);
3032 return true;
3033 } else {
3034 loge("There's no default phone.");
3035 return false;
3036 }
3037 } finally {
3038 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07003039 }
Wink Saville36469e72014-06-11 15:17:00 -07003040 }
3041
Wink Savilleb564aae2014-10-23 10:18:09 -07003042 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003043 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003044
Ling Ma83dc5ea2023-01-12 15:06:04 -08003045 if (!turnOn) {
3046 log("setRadioPowerForSubscriber off: subId=" + subId
3047 + ",callingPackage=" + getCurrentPackageName());
3048 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003049 final long identity = Binder.clearCallingIdentity();
3050 try {
3051 final Phone phone = getPhone(subId);
3052 if (phone != null) {
3053 phone.setRadioPower(turnOn);
3054 return true;
3055 } else {
3056 return false;
3057 }
3058 } finally {
3059 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003060 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003061 }
3062
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003063 /**
3064 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3065 * no reason to power it off. When any of the voters want to power it off, it will be turned
3066 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3067 * powering it off, and these radio off votes will be cleared.
3068 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3069 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3070 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3071 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3072 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3073 * check its vote.
3074 *
3075 * @param subId The subscription ID.
3076 * @param reason The reason for powering off radio.
3077 * @return true on success and false on failure.
3078 */
3079 public boolean requestRadioPowerOffForReason(int subId,
3080 @TelephonyManager.RadioPowerReason int reason) {
3081 enforceModifyPermission();
3082
joonhunshin4ac60942023-11-15 15:23:39 +00003083 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3084 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestRadioPowerOffForReason");
3085
Ling Ma83dc5ea2023-01-12 15:06:04 -08003086 log("requestRadioPowerOffForReason: subId=" + subId
3087 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003088 final long identity = Binder.clearCallingIdentity();
3089 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003090 boolean result = false;
3091 for (Phone phone : PhoneFactory.getPhones()) {
3092 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003093 phone.setRadioPowerForReason(false, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003094 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003095 if (!result) {
3096 loge("requestRadioPowerOffForReason: no phone exists");
3097 }
3098 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003099 } finally {
3100 Binder.restoreCallingIdentity(identity);
3101 }
3102 }
3103
3104 /**
3105 * Remove the vote on powering off the radio for a reason, as requested by
3106 * {@link requestRadioPowerOffForReason}.
3107 *
3108 * @param subId The subscription ID.
3109 * @param reason The reason for powering off radio.
3110 * @return true on success and false on failure.
3111 */
3112 public boolean clearRadioPowerOffForReason(int subId,
3113 @TelephonyManager.RadioPowerReason int reason) {
3114 enforceModifyPermission();
3115
joonhunshin4ac60942023-11-15 15:23:39 +00003116 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3117 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearRadioPowerOffForReason");
3118
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003119 final long identity = Binder.clearCallingIdentity();
3120 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003121 boolean result = false;
3122 for (Phone phone : PhoneFactory.getPhones()) {
3123 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003124 phone.setRadioPowerForReason(true, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003125 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003126 if (!result) {
3127 loge("clearRadioPowerOffForReason: no phone exists");
3128 }
3129 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003130 } finally {
3131 Binder.restoreCallingIdentity(identity);
3132 }
3133 }
3134
3135 /**
3136 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3137 *
3138 * @param subId The subscription ID.
3139 * @param callingPackage The package making the call.
3140 * @param callingFeatureId The feature in the package.
3141 * @return List of reasons for powering off radio.
3142 */
3143 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3144 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3145
joonhunshin4ac60942023-11-15 15:23:39 +00003146 enforceTelephonyFeatureWithException(callingPackage,
3147 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerOffReasons");
3148
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003149 final long identity = Binder.clearCallingIdentity();
3150 List result = new ArrayList();
3151 try {
3152 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3153 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3154 return result;
3155 }
3156
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003157 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003158 if (phone != null) {
3159 result.addAll(phone.getRadioPowerOffReasons());
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003160 } else {
3161 loge("getRadioPowerOffReasons: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003162 }
3163 } finally {
3164 Binder.restoreCallingIdentity(identity);
3165 }
3166 return result;
3167 }
3168
Wink Saville36469e72014-06-11 15:17:00 -07003169 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003170 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003171 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003172 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003173
joonhunshin4ac60942023-11-15 15:23:39 +00003174 enforceTelephonyFeatureWithException(callingPackage,
3175 PackageManager.FEATURE_TELEPHONY_DATA, "enableDataConnectivity");
3176
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003177 final long identity = Binder.clearCallingIdentity();
3178 try {
Jack Yu285100e2022-12-02 22:48:35 -08003179 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003180 final Phone phone = getPhone(subId);
3181 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003182 phone.getDataSettingsManager().setDataEnabled(
3183 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003184 return true;
3185 } else {
3186 return false;
3187 }
3188 } finally {
3189 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003190 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003191 }
3192
Wink Saville36469e72014-06-11 15:17:00 -07003193 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003194 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003195 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003196 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003197
joonhunshin4ac60942023-11-15 15:23:39 +00003198 enforceTelephonyFeatureWithException(callingPackage,
3199 PackageManager.FEATURE_TELEPHONY_DATA, "disableDataConnectivity");
3200
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003201 final long identity = Binder.clearCallingIdentity();
3202 try {
Jack Yu285100e2022-12-02 22:48:35 -08003203 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003204 final Phone phone = getPhone(subId);
3205 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003206 phone.getDataSettingsManager().setDataEnabled(
3207 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003208 return true;
3209 } else {
3210 return false;
3211 }
3212 } finally {
3213 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003214 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003215 }
3216
Sanket Padawe356d7632015-06-22 14:03:32 -07003217 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003218 public boolean isDataConnectivityPossible(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003219 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3220 PackageManager.FEATURE_TELEPHONY_DATA, "isDataConnectivityPossible");
3221
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003222 final long identity = Binder.clearCallingIdentity();
3223 try {
3224 final Phone phone = getPhone(subId);
3225 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003226 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003227 } else {
3228 return false;
3229 }
3230 } finally {
3231 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003232 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003233 }
3234
3235 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003236 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003237 }
3238
pkanwarae03a6b2016-11-06 20:37:09 -08003239 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003240 enforceCallPermission();
3241
joonhunshin4ac60942023-11-15 15:23:39 +00003242 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3243 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "handleUssdRequest");
3244
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003245 final long identity = Binder.clearCallingIdentity();
3246 try {
3247 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3248 return;
3249 }
3250 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3251 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3252 } finally {
3253 Binder.restoreCallingIdentity(identity);
3254 }
pkanwar32d516d2016-10-14 19:37:38 -07003255 };
3256
Wink Savilleb564aae2014-10-23 10:18:09 -07003257 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003258 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003259
joonhunshin4ac60942023-11-15 15:23:39 +00003260 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3261 PackageManager.FEATURE_TELEPHONY_CALLING, "handlePinMmiForSubscriber");
3262
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003263 final long identity = Binder.clearCallingIdentity();
3264 try {
3265 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3266 return false;
3267 }
3268 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3269 } finally {
3270 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003271 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003272 }
3273
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003274 /**
3275 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3276 * tag on getCallState Binder call.
3277 */
3278 @Deprecated
3279 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003280 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003281 if (CompatChanges.isChangeEnabled(
3282 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3283 Binder.getCallingUid())) {
3284 // Do not allow this API to be called on API version 31+, it should only be
3285 // called on old apps using this Binder call directly.
3286 throw new SecurityException("This method can only be used for applications "
3287 + "targeting API version 30 or less.");
3288 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003289 final long identity = Binder.clearCallingIdentity();
3290 try {
Ling Mac28f0212023-03-24 16:07:15 -07003291 Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription());
3292 return PhoneConstantConversions.convertCallState(phone.getState());
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003293 } finally {
3294 Binder.restoreCallingIdentity(identity);
3295 }
3296 }
3297
3298 @Override
3299 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3300 if (CompatChanges.isChangeEnabled(
3301 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3302 Binder.getCallingUid())) {
3303 // Check READ_PHONE_STATE for API version 31+
3304 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3305 featureId, "getCallStateForSubscription")) {
3306 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3307 + "targeting API level 31+.");
3308 }
3309 }
joonhunshin4ac60942023-11-15 15:23:39 +00003310
3311 enforceTelephonyFeatureWithException(callingPackage,
3312 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallStateForSubscription");
3313
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003314 final long identity = Binder.clearCallingIdentity();
3315 try {
3316 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003317 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3318 PhoneConstantConversions.convertCallState(phone.getState());
3319 } finally {
3320 Binder.restoreCallingIdentity(identity);
3321 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003322 }
3323
Sanket Padawe356d7632015-06-22 14:03:32 -07003324 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003325 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003326 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003327 }
3328
3329 @Override
3330 public int getDataStateForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003331 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3332 PackageManager.FEATURE_TELEPHONY_DATA, "getDataStateForSubId");
3333
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003334 final long identity = Binder.clearCallingIdentity();
3335 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003336 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003337 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003338 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003339 } else {
3340 return PhoneConstantConversions.convertDataState(
3341 PhoneConstants.DataState.DISCONNECTED);
3342 }
3343 } finally {
3344 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003345 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003346 }
3347
Sanket Padawe356d7632015-06-22 14:03:32 -07003348 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003349 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003350 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003351 }
3352
3353 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003354 public @DataActivityType int getDataActivityForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003355 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3356 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivityForSubId");
3357
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003358 final long identity = Binder.clearCallingIdentity();
3359 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003360 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003361 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003362 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003363 } else {
3364 return TelephonyManager.DATA_ACTIVITY_NONE;
3365 }
3366 } finally {
3367 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003368 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003369 }
3370
3371 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003372 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003373 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003374 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003375
3376 LocationAccessPolicy.LocationPermissionResult locationResult =
3377 LocationAccessPolicy.checkLocationPermission(mApp,
3378 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3379 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003380 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003381 .setCallingPid(Binder.getCallingPid())
3382 .setCallingUid(Binder.getCallingUid())
3383 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003384 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003385 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3386 .build());
3387 switch (locationResult) {
3388 case DENIED_HARD:
3389 throw new SecurityException("Not allowed to access cell location");
3390 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003391 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3392 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003393 }
3394
joonhunshin4ac60942023-11-15 15:23:39 +00003395 enforceTelephonyFeatureWithException(callingPackage,
3396 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getCellLocation");
3397
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003398 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003399 final long identity = Binder.clearCallingIdentity();
3400 try {
3401 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003402 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003403 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003404 } finally {
3405 Binder.restoreCallingIdentity(identity);
3406 }
Svetoslav64fad262015-04-14 14:35:21 -07003407 }
3408
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003409 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003410 public String getNetworkCountryIsoForPhone(int phoneId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003411 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3412 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkCountryIsoForPhone");
3413
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003414 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3415 // registered cell info, so return a NULL country instead.
3416 final long identity = Binder.clearCallingIdentity();
3417 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003418 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3419 // Get default phone in this case.
3420 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3421 }
Jack Yu285100e2022-12-02 22:48:35 -08003422 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003423 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003424 if (phone == null) return "";
3425 ServiceStateTracker sst = phone.getServiceStateTracker();
3426 if (sst == null) return "";
3427 LocaleTracker lt = sst.getLocaleTracker();
3428 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003429 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003430 } finally {
3431 Binder.restoreCallingIdentity(identity);
3432 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003433 }
3434
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003435 /**
3436 * This method was removed due to potential issues caused by performing partial
3437 * updates of service state, and lack of a credible use case.
3438 *
3439 * This has the ability to break the telephony implementation by disabling notification of
3440 * changes in device connectivity. DO NOT USE THIS!
3441 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003442 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003443 public void enableLocationUpdates() {
3444 mApp.enforceCallingOrSelfPermission(
3445 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003446 }
3447
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003448 /**
3449 * This method was removed due to potential issues caused by performing partial
3450 * updates of service state, and lack of a credible use case.
3451 *
3452 * This has the ability to break the telephony implementation by disabling notification of
3453 * changes in device connectivity. DO NOT USE THIS!
3454 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003455 @Override
3456 public void disableLocationUpdates() {
3457 mApp.enforceCallingOrSelfPermission(
3458 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003459 }
3460
3461 @Override
3462 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003463 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3464 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003465 try {
3466 mApp.getSystemService(AppOpsManager.class)
3467 .checkPackage(Binder.getCallingUid(), callingPackage);
3468 } catch (SecurityException e) {
3469 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3470 throw e;
3471 }
3472
Nathan Haroldf096d982020-11-18 17:18:06 -08003473 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003474 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3475 throw new SecurityException(
3476 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3477 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003478
Jordan Liu1617b712019-07-10 15:06:26 -07003479 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003480 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3481 return null;
3482 }
Svetoslav64fad262015-04-14 14:35:21 -07003483
joonhunshin4ac60942023-11-15 15:23:39 +00003484 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3485 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNeighboringCellInfo");
3486
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003487 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003488
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003489 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003490 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003491
Nathan Haroldf180aac2018-06-01 18:43:55 -07003492 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3493 for (CellInfo ci : info) {
3494 if (ci instanceof CellInfoGsm) {
3495 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3496 } else if (ci instanceof CellInfoWcdma) {
3497 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3498 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003499 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003500 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003501 }
3502
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003503 private List<CellInfo> getCachedCellInfo() {
3504 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3505 for (Phone phone : PhoneFactory.getPhones()) {
3506 List<CellInfo> info = phone.getAllCellInfo();
3507 if (info != null) cellInfos.addAll(info);
3508 }
3509 return cellInfos;
3510 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003511
3512 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003513 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003514 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003515 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003516
3517 LocationAccessPolicy.LocationPermissionResult locationResult =
3518 LocationAccessPolicy.checkLocationPermission(mApp,
3519 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3520 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003521 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003522 .setCallingPid(Binder.getCallingPid())
3523 .setCallingUid(Binder.getCallingUid())
3524 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003525 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003526 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3527 .build());
3528 switch (locationResult) {
3529 case DENIED_HARD:
3530 throw new SecurityException("Not allowed to access cell info");
3531 case DENIED_SOFT:
3532 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003533 }
3534
Nathan Haroldf096d982020-11-18 17:18:06 -08003535 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003536 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3537 return getCachedCellInfo();
3538 }
3539
joonhunshin4ac60942023-11-15 15:23:39 +00003540 enforceTelephonyFeatureWithException(callingPackage,
3541 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllCellInfo");
3542
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003543 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003544 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003545 final long identity = Binder.clearCallingIdentity();
3546 try {
3547 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3548 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003549 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003550 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003551 if (info != null) cellInfos.addAll(info);
3552 }
3553 return cellInfos;
3554 } finally {
3555 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003556 }
3557 }
3558
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003559 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003560 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3561 String callingFeatureId) {
3562 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3563 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003564 }
3565
3566 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003567 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3568 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003569 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003570 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003571 }
3572
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003573 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3574 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003575 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003576 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003577
3578 LocationAccessPolicy.LocationPermissionResult locationResult =
3579 LocationAccessPolicy.checkLocationPermission(mApp,
3580 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3581 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003582 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003583 .setCallingPid(Binder.getCallingPid())
3584 .setCallingUid(Binder.getCallingUid())
3585 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003586 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3587 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003588 .build());
3589 switch (locationResult) {
3590 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003591 if (TelephonyPermissions
3592 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003593 // Safetynet logging for b/154934934
3594 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3595 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003596 throw new SecurityException("Not allowed to access cell info");
3597 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003598 if (TelephonyPermissions
3599 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003600 // Safetynet logging for b/154934934
3601 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3602 }
Nathan Harold5320c422019-05-09 10:26:08 -07003603 try {
3604 cb.onCellInfo(new ArrayList<CellInfo>());
3605 } catch (RemoteException re) {
3606 // Drop without consequences
3607 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003608 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003609 }
3610
joonhunshin4ac60942023-11-15 15:23:39 +00003611 enforceTelephonyFeatureWithException(callingPackage,
3612 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestCellInfoUpdateInternal");
Nathan Harolda939a962019-05-09 10:13:47 -07003613
3614 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003615 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3616
3617 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3618 }
3619
3620 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003621 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003622 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003623 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003624
3625 final long identity = Binder.clearCallingIdentity();
3626 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003627 Phone phone = getPhone(subId);
3628 if (phone == null) {
3629 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3630 } else {
3631 phone.setCellInfoListRate(rateInMillis, workSource);
3632 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003633 } finally {
3634 Binder.restoreCallingIdentity(identity);
3635 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003636 }
3637
Shishir Agrawala9f32182016-04-12 12:00:16 -07003638 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003639 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003640 Phone phone = PhoneFactory.getPhone(slotIndex);
3641 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003642 return null;
3643 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003644 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003645 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003646 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003647 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003648 return null;
3649 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003650
joonhunshin4ac60942023-11-15 15:23:39 +00003651 enforceTelephonyFeatureWithException(callingPackage,
3652 PackageManager.FEATURE_TELEPHONY_GSM, "getImeiForSlot");
3653
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003654 final long identity = Binder.clearCallingIdentity();
3655 try {
3656 return phone.getImei();
3657 } finally {
3658 Binder.restoreCallingIdentity(identity);
3659 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003660 }
3661
3662 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003663 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3664 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3665 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3666 callingFeatureId, "getPrimaryImei")) {
3667 throw new SecurityException("Caller does not have permission");
3668 }
joonhunshin4ac60942023-11-15 15:23:39 +00003669
3670 enforceTelephonyFeatureWithException(callingPackage,
3671 PackageManager.FEATURE_TELEPHONY_GSM, "getPrimaryImei");
3672
arunvoddud5c6ce02022-12-11 06:03:12 +00003673 final long identity = Binder.clearCallingIdentity();
3674 try {
3675 for (Phone phone : PhoneFactory.getPhones()) {
3676 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3677 return phone.getImei();
3678 }
3679 }
3680 throw new UnsupportedOperationException("Operation not supported");
3681 } finally {
3682 Binder.restoreCallingIdentity(identity);
3683 }
3684 }
3685
3686 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003687 public String getTypeAllocationCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003688 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3689 PackageManager.FEATURE_TELEPHONY_GSM, "getTypeAllocationCodeForSlot");
3690
David Kelly5e06a7f2018-03-12 14:10:59 +00003691 Phone phone = PhoneFactory.getPhone(slotIndex);
3692 String tac = null;
3693 if (phone != null) {
3694 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003695 try {
3696 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3697 } catch (IndexOutOfBoundsException e) {
3698 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3699 return null;
3700 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003701 }
3702 return tac;
3703 }
3704
3705 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003706 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003707 try {
3708 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3709 } catch (SecurityException se) {
3710 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3711 throw new SecurityException("Package " + callingPackage + " does not belong to "
3712 + Binder.getCallingUid());
3713 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003714 Phone phone = PhoneFactory.getPhone(slotIndex);
3715 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003716 return null;
3717 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003718
Jeff Davidson913390f2018-02-23 17:11:49 -08003719 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003720 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003721 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003722 return null;
3723 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003724
joonhunshin4ac60942023-11-15 15:23:39 +00003725 enforceTelephonyFeatureWithException(callingPackage,
3726 PackageManager.FEATURE_TELEPHONY_CDMA, "getMeidForSlot");
3727
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003728 final long identity = Binder.clearCallingIdentity();
3729 try {
3730 return phone.getMeid();
3731 } finally {
3732 Binder.restoreCallingIdentity(identity);
3733 }
Jack Yu2af8d712017-03-15 17:14:14 -07003734 }
3735
3736 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003737 public String getManufacturerCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003738 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3739 PackageManager.FEATURE_TELEPHONY_CDMA, "getManufacturerCodeForSlot");
3740
David Kelly5e06a7f2018-03-12 14:10:59 +00003741 Phone phone = PhoneFactory.getPhone(slotIndex);
3742 String manufacturerCode = null;
3743 if (phone != null) {
3744 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003745 try {
3746 manufacturerCode =
3747 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3748 } catch (IndexOutOfBoundsException e) {
3749 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3750 return null;
3751 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003752 }
3753 return manufacturerCode;
3754 }
3755
3756 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003757 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3758 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003759 Phone phone = PhoneFactory.getPhone(slotIndex);
3760 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003761 return null;
3762 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003763 int subId = phone.getSubId();
3764 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003765 mApp, subId, callingPackage, callingFeatureId,
3766 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003767 return null;
3768 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003769
joonhunshin4ac60942023-11-15 15:23:39 +00003770 enforceTelephonyFeatureWithException(callingPackage,
3771 PackageManager.FEATURE_TELEPHONY, "getDeviceSoftwareVersionForSlot");
3772
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003773 final long identity = Binder.clearCallingIdentity();
3774 try {
3775 return phone.getDeviceSvn();
3776 } finally {
3777 Binder.restoreCallingIdentity(identity);
3778 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003779 }
3780
fionaxu43304da2017-11-27 22:51:16 -08003781 @Override
3782 public int getSubscriptionCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003783 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3784 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierId");
3785
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003786 final long identity = Binder.clearCallingIdentity();
3787 try {
3788 final Phone phone = getPhone(subId);
3789 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3790 } finally {
3791 Binder.restoreCallingIdentity(identity);
3792 }
fionaxu43304da2017-11-27 22:51:16 -08003793 }
3794
3795 @Override
3796 public String getSubscriptionCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003797 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3798 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierName");
3799
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003800 final long identity = Binder.clearCallingIdentity();
3801 try {
3802 final Phone phone = getPhone(subId);
3803 return phone == null ? null : phone.getCarrierName();
3804 } finally {
3805 Binder.restoreCallingIdentity(identity);
3806 }
fionaxu43304da2017-11-27 22:51:16 -08003807 }
3808
calvinpanffe225e2018-11-01 19:43:06 +08003809 @Override
chen xu0026ca62019-03-06 15:28:50 -08003810 public int getSubscriptionSpecificCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003811 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3812 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionSpecificCarrierId");
3813
chen xu25637222018-11-04 17:17:00 -08003814 final long identity = Binder.clearCallingIdentity();
3815 try {
3816 final Phone phone = getPhone(subId);
3817 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003818 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003819 } finally {
3820 Binder.restoreCallingIdentity(identity);
3821 }
3822 }
3823
3824 @Override
chen xu0026ca62019-03-06 15:28:50 -08003825 public String getSubscriptionSpecificCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003826 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3827 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
3828 "getSubscriptionSpecificCarrierName");
3829
chen xu25637222018-11-04 17:17:00 -08003830 final long identity = Binder.clearCallingIdentity();
3831 try {
3832 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003833 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003834 } finally {
3835 Binder.restoreCallingIdentity(identity);
3836 }
3837 }
3838
chen xu651eec72018-11-11 19:03:44 -08003839 @Override
chen xu864e11c2018-12-06 22:10:03 -08003840 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3841 if (!isSubscriptionMccMnc) {
3842 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3843 }
chen xu651eec72018-11-11 19:03:44 -08003844 final Phone phone = PhoneFactory.getPhone(slotIndex);
3845 if (phone == null) {
3846 return TelephonyManager.UNKNOWN_CARRIER_ID;
3847 }
joonhunshin4ac60942023-11-15 15:23:39 +00003848
3849 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3850 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromMccMnc");
3851
chen xu651eec72018-11-11 19:03:44 -08003852 final long identity = Binder.clearCallingIdentity();
3853 try {
3854 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3855 } finally {
3856 Binder.restoreCallingIdentity(identity);
3857 }
3858 }
3859
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003860 //
3861 // Internal helper methods.
3862 //
3863
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003864 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003865 * Make sure the caller is the calling package itself
3866 *
3867 * @throws SecurityException if the caller is not the calling package
3868 */
3869 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3870 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003871 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3872 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003873 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003874 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003875 } catch (PackageManager.NameNotFoundException e) {
3876 // packageUid is -1
3877 }
3878 if (packageUid != callingUid) {
3879 throw new SecurityException(message + ": Package " + callingPackage
3880 + " does not belong to " + callingUid);
3881 }
3882 }
3883
3884 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003885 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3886 *
3887 * @throws SecurityException if the caller does not have the required permission
3888 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003889 @VisibleForTesting
3890 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003891 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3892 }
3893
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003894 /**
arunvoddud7401012022-12-15 16:08:12 +00003895 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003896 *
3897 * @throws SecurityException if the caller does not have the required permission
3898 */
3899 @VisibleForTesting
3900 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003901 enforceReadPermission(null);
3902 }
3903
3904 /**
3905 * Make sure the caller has the READ_PHONE_STATE permissions.
3906 *
3907 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3908 */
3909 @VisibleForTesting
3910 public void enforceReadPermission(String msg) {
3911 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003912 }
3913
Shuo Qian3b6ee772019-11-13 17:43:31 -08003914 private void enforceActiveEmergencySessionPermission() {
3915 mApp.enforceCallingOrSelfPermission(
3916 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3917 }
3918
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003919 /**
3920 * Make sure the caller has the CALL_PHONE permission.
3921 *
3922 * @throws SecurityException if the caller does not have the required permission
3923 */
3924 private void enforceCallPermission() {
3925 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3926 }
3927
paulhu5a773602019-08-23 19:17:33 +08003928 private void enforceSettingsPermission() {
3929 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003930 }
3931
Michele Berionne5e411512020-11-13 02:36:59 +00003932 private void enforceRebootPermission() {
3933 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3934 }
3935
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003936 /**
3937 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3938 * @param message - log message to print.
3939 * @throws SecurityException if the caller does not have the required permission
3940 */
3941 private void enforceSatelliteCommunicationPermission(String message) {
3942 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3943 }
3944
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003945 private String createTelUrl(String number) {
3946 if (TextUtils.isEmpty(number)) {
3947 return null;
3948 }
3949
Jake Hambye994d462014-02-03 13:10:13 -08003950 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003951 }
3952
Ihab Awadf9e92732013-12-05 18:02:52 -08003953 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003954 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003955 }
3956
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003957 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003958 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003959 }
3960
Ihab Awadf9e92732013-12-05 18:02:52 -08003961 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003962 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003963 }
3964
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003965 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003966 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003967 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003968 }
3969
Sanket Padawe356d7632015-06-22 14:03:32 -07003970 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003971 public int getActivePhoneTypeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003972 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3973 PackageManager.FEATURE_TELEPHONY, "getActivePhoneTypeForSlot");
3974
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003975 final long identity = Binder.clearCallingIdentity();
3976 try {
3977 final Phone phone = PhoneFactory.getPhone(slotIndex);
3978 if (phone == null) {
3979 return PhoneConstants.PHONE_TYPE_NONE;
3980 } else {
3981 return phone.getPhoneType();
3982 }
3983 } finally {
3984 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003985 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003986 }
3987
3988 /**
3989 * Returns the CDMA ERI icon index to display
3990 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003991 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003992 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3993 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3994 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003995 }
3996
Sanket Padawe356d7632015-06-22 14:03:32 -07003997 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003998 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3999 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004000 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004001 mApp, subId, callingPackage, callingFeatureId,
4002 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004003 return -1;
4004 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004005
joonhunshin4ac60942023-11-15 15:23:39 +00004006 enforceTelephonyFeatureWithException(callingPackage,
4007 PackageManager.FEATURE_TELEPHONY_CDMA,
4008 "getCdmaEriIconIndexForSubscriber");
4009
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004010 final long identity = Binder.clearCallingIdentity();
4011 try {
4012 final Phone phone = getPhone(subId);
4013 if (phone != null) {
4014 return phone.getCdmaEriIconIndex();
4015 } else {
4016 return -1;
4017 }
4018 } finally {
4019 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004020 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004021 }
4022
4023 /**
4024 * Returns the CDMA ERI icon mode,
4025 * 0 - ON
4026 * 1 - FLASHING
4027 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004028 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004029 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
4030 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
4031 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004032 }
4033
Sanket Padawe356d7632015-06-22 14:03:32 -07004034 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004035 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
4036 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004037 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004038 mApp, subId, callingPackage, callingFeatureId,
4039 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004040 return -1;
4041 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004042
4043 final long identity = Binder.clearCallingIdentity();
4044 try {
4045 final Phone phone = getPhone(subId);
4046 if (phone != null) {
4047 return phone.getCdmaEriIconMode();
4048 } else {
4049 return -1;
4050 }
4051 } finally {
4052 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004053 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004054 }
4055
4056 /**
4057 * Returns the CDMA ERI text,
4058 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004059 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004060 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
4061 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
4062 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004063 }
4064
Sanket Padawe356d7632015-06-22 14:03:32 -07004065 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004066 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
4067 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004068 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004069 mApp, subId, callingPackage, callingFeatureId,
4070 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004071 return null;
4072 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004073
4074 final long identity = Binder.clearCallingIdentity();
4075 try {
4076 final Phone phone = getPhone(subId);
4077 if (phone != null) {
4078 return phone.getCdmaEriText();
4079 } else {
4080 return null;
4081 }
4082 } finally {
4083 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004084 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004085 }
4086
4087 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07004088 * Returns the CDMA MDN.
4089 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004090 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004091 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004092 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4093 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004094
joonhunshin4ac60942023-11-15 15:23:39 +00004095 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4096 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMdn");
4097
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004098 final long identity = Binder.clearCallingIdentity();
4099 try {
4100 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004101 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004102 return phone.getLine1Number();
4103 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004104 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004105 return null;
4106 }
4107 } finally {
4108 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004109 }
4110 }
4111
4112 /**
4113 * Returns the CDMA MIN.
4114 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004115 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004116 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004117 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4118 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004119
joonhunshin4ac60942023-11-15 15:23:39 +00004120 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4121 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMin");
4122
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004123 final long identity = Binder.clearCallingIdentity();
4124 try {
4125 final Phone phone = getPhone(subId);
4126 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
4127 return phone.getCdmaMin();
4128 } else {
4129 return null;
4130 }
4131 } finally {
4132 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004133 }
4134 }
4135
Hall Liud892bec2018-11-30 14:51:45 -08004136 @Override
4137 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
4138 INumberVerificationCallback callback, String callingPackage) {
4139 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
4140 != PERMISSION_GRANTED) {
4141 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
4142 }
4143 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4144
4145 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
4146 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08004147 throw new SecurityException("Calling package must be configured in the device config: "
4148 + "calling package: " + callingPackage
4149 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004150 }
4151
joonhunshin4ac60942023-11-15 15:23:39 +00004152 enforceTelephonyFeatureWithException(callingPackage,
4153 PackageManager.FEATURE_TELEPHONY_CALLING, "requestNumberVerification");
4154
Hall Liud892bec2018-11-30 14:51:45 -08004155 if (range == null) {
4156 throw new NullPointerException("Range must be non-null");
4157 }
4158
4159 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004160 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004161
4162 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4163 }
4164
Junda Liuca05d5d2014-08-14 22:36:34 -07004165 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004166 * Returns true if CDMA provisioning needs to run.
4167 */
4168 public boolean needsOtaServiceProvisioning() {
joonhunshin4ac60942023-11-15 15:23:39 +00004169 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4170 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needsOtaServiceProvisioning");
4171
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004172 final long identity = Binder.clearCallingIdentity();
4173 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004174 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004175 } finally {
4176 Binder.restoreCallingIdentity(identity);
4177 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004178 }
4179
4180 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004181 * Sets the voice mail number of a given subId.
4182 */
4183 @Override
4184 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004185 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4186 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004187
joonhunshin4ac60942023-11-15 15:23:39 +00004188 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4189 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceMailNumber");
4190
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004191 final long identity = Binder.clearCallingIdentity();
4192 try {
4193 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4194 new Pair<String, String>(alphaTag, number), new Integer(subId));
4195 return success;
4196 } finally {
4197 Binder.restoreCallingIdentity(identity);
4198 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004199 }
4200
Ta-wei Yen87c49842016-05-13 21:19:52 -07004201 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004202 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4203 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004204 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4205 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004206 if (!TextUtils.equals(callingPackage, systemDialer)) {
4207 throw new SecurityException("caller must be system dialer");
4208 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004209
joonhunshin4ac60942023-11-15 15:23:39 +00004210 enforceTelephonyFeatureWithException(callingPackage,
4211 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailSettings");
4212
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004213 final long identity = Binder.clearCallingIdentity();
4214 try {
4215 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4216 if (phoneAccountHandle == null) {
4217 return null;
4218 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004219 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004220 } finally {
4221 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004222 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004223 }
4224
4225 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004226 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4227 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004228 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004229 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004230 mApp, subId, callingPackage, callingFeatureId,
4231 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004232 return null;
4233 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004234
joonhunshin4ac60942023-11-15 15:23:39 +00004235 enforceTelephonyFeatureWithException(callingPackage,
4236 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailPackageName");
4237
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004238 final long identity = Binder.clearCallingIdentity();
4239 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004240 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004241 } finally {
4242 Binder.restoreCallingIdentity(identity);
4243 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004244 }
4245
4246 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004247 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4248 VisualVoicemailSmsFilterSettings settings) {
4249 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004250
joonhunshin4ac60942023-11-15 15:23:39 +00004251 enforceTelephonyFeatureWithException(callingPackage,
4252 PackageManager.FEATURE_TELEPHONY_CALLING, "enableVisualVoicemailSmsFilter");
4253
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004254 final long identity = Binder.clearCallingIdentity();
4255 try {
4256 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004257 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004258 } finally {
4259 Binder.restoreCallingIdentity(identity);
4260 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004261 }
4262
4263 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004264 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4265 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004266
joonhunshin4ac60942023-11-15 15:23:39 +00004267 enforceTelephonyFeatureWithException(callingPackage,
4268 PackageManager.FEATURE_TELEPHONY_CALLING, "disableVisualVoicemailSmsFilter");
4269
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004270 final long identity = Binder.clearCallingIdentity();
4271 try {
4272 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004273 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004274 } finally {
4275 Binder.restoreCallingIdentity(identity);
4276 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004277 }
4278
4279 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004280 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4281 String callingPackage, int subId) {
4282 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004283
4284 final long identity = Binder.clearCallingIdentity();
4285 try {
4286 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004287 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004288 } finally {
4289 Binder.restoreCallingIdentity(identity);
4290 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004291 }
4292
4293 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004294 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004295 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004296
4297 final long identity = Binder.clearCallingIdentity();
4298 try {
4299 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004300 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004301 } finally {
4302 Binder.restoreCallingIdentity(identity);
4303 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004304 }
4305
4306 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004307 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4308 String callingAttributionTag, int subId, String number, int port, String text,
4309 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004310 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004311 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004312 enforceSendSmsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00004313
4314 enforceTelephonyFeatureWithException(callingPackage,
4315 PackageManager.FEATURE_TELEPHONY_CALLING, "sendVisualVoicemailSmsForSubscriber");
4316
Amit Mahajandccb3f12019-05-13 13:48:32 -07004317 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004318 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4319 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004320 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004321
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004322 /**
fionaxu0152e512016-11-14 13:36:14 -08004323 * Sets the voice activation state of a given subId.
4324 */
4325 @Override
4326 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004327 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4328 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004329
joonhunshin4ac60942023-11-15 15:23:39 +00004330 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4331 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState");
4332
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004333 final long identity = Binder.clearCallingIdentity();
4334 try {
4335 final Phone phone = getPhone(subId);
4336 if (phone != null) {
4337 phone.setVoiceActivationState(activationState);
4338 } else {
4339 loge("setVoiceActivationState fails with invalid subId: " + subId);
4340 }
4341 } finally {
4342 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004343 }
4344 }
4345
4346 /**
4347 * Sets the data activation state of a given subId.
4348 */
4349 @Override
4350 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004351 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4352 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004353
joonhunshin4ac60942023-11-15 15:23:39 +00004354 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4355 PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState");
4356
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004357 final long identity = Binder.clearCallingIdentity();
4358 try {
4359 final Phone phone = getPhone(subId);
4360 if (phone != null) {
4361 phone.setDataActivationState(activationState);
4362 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004363 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004364 }
4365 } finally {
4366 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004367 }
4368 }
4369
4370 /**
4371 * Returns the voice activation state of a given subId.
4372 */
4373 @Override
4374 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004375 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004376
joonhunshin4ac60942023-11-15 15:23:39 +00004377 enforceTelephonyFeatureWithException(callingPackage,
4378 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState");
4379
fionaxu0152e512016-11-14 13:36:14 -08004380 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004381 final long identity = Binder.clearCallingIdentity();
4382 try {
4383 if (phone != null) {
4384 return phone.getVoiceActivationState();
4385 } else {
4386 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4387 }
4388 } finally {
4389 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004390 }
4391 }
4392
4393 /**
4394 * Returns the data activation state of a given subId.
4395 */
4396 @Override
4397 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004398 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004399
joonhunshin4ac60942023-11-15 15:23:39 +00004400 enforceTelephonyFeatureWithException(callingPackage,
4401 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState");
4402
fionaxu0152e512016-11-14 13:36:14 -08004403 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004404 final long identity = Binder.clearCallingIdentity();
4405 try {
4406 if (phone != null) {
4407 return phone.getDataActivationState();
4408 } else {
4409 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4410 }
4411 } finally {
4412 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004413 }
4414 }
4415
4416 /**
Wink Saville36469e72014-06-11 15:17:00 -07004417 * Returns the unread count of voicemails for a subId
4418 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004419 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004420 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4421 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004422 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004423 mApp, subId, callingPackage, callingFeatureId,
4424 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004425 return 0;
4426 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004427 final long identity = Binder.clearCallingIdentity();
4428 try {
4429 final Phone phone = getPhone(subId);
4430 if (phone != null) {
4431 return phone.getVoiceMessageCount();
4432 } else {
4433 return 0;
4434 }
4435 } finally {
4436 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004437 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004438 }
4439
4440 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004441 * returns true, if the device is in a state where both voice and data
4442 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004443 */
4444 @Override
4445 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00004446 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4447 PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed");
4448
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004449 final long identity = Binder.clearCallingIdentity();
4450 try {
Ling Mac28f0212023-03-24 16:07:15 -07004451 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004452 } finally {
4453 Binder.restoreCallingIdentity(identity);
4454 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004455 }
4456
4457 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004458 * Send the dialer code if called from the current default dialer or the caller has
4459 * carrier privilege.
4460 * @param inputCode The dialer code to send
4461 */
4462 @Override
4463 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004464 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004465 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004466 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4467 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004468 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004469 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004470 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004471 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004472
joonhunshin4ac60942023-11-15 15:23:39 +00004473 enforceTelephonyFeatureWithException(callingPackage,
4474 PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode");
4475
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004476 final long identity = Binder.clearCallingIdentity();
4477 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004478 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004479 } finally {
4480 Binder.restoreCallingIdentity(identity);
4481 }
fionaxu235cc5e2017-03-06 22:25:57 -08004482 }
4483
Pengquan Menga1bb6272018-09-06 09:59:22 -07004484 @Override
4485 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004486 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004487 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4488 mApp, subId, "getNetworkSelectionMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004489
4490 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4491 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode");
4492
shilufc958392020-01-20 11:36:01 -08004493 final long identity = Binder.clearCallingIdentity();
4494 try {
4495 if (!isActiveSubscription(subId)) {
4496 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4497 }
4498 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4499 } finally {
4500 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004501 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004502 }
4503
Brad Ebinger35c841c2018-10-01 10:40:55 -07004504 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004505 public boolean isInEmergencySmsMode() {
4506 enforceReadPrivilegedPermission("isInEmergencySmsMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004507
4508 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4509 PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode");
4510
Brad Ebingerb2b65522019-03-15 13:48:47 -07004511 final long identity = Binder.clearCallingIdentity();
4512 try {
4513 for (Phone phone : PhoneFactory.getPhones()) {
4514 if (phone.isInEmergencySmsMode()) {
4515 return true;
4516 }
4517 }
4518 } finally {
4519 Binder.restoreCallingIdentity(identity);
4520 }
4521 return false;
4522 }
4523
shilu366312e2019-12-17 09:28:10 -08004524 /**
4525 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4526 * @param subId The subscription to use to check the configuration.
4527 * @param c The callback that will be used to send the result.
4528 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004529 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004530 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4531 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004532 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004533 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004534
4535 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4536 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4537 "IMS not available on device.");
4538 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004539 final long token = Binder.clearCallingIdentity();
4540 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004541 int slotId = getSlotIndexOrException(subId);
4542 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004543
4544 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4545 if (controller != null) {
4546 ImsManager imsManager = controller.getImsManager(subId);
4547 if (imsManager != null) {
4548 imsManager.addRegistrationCallbackForSubscription(c, subId);
4549 } else {
4550 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4551 }
4552 } else {
4553 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4554 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004555 } catch (ImsException e) {
4556 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004557 } finally {
4558 Binder.restoreCallingIdentity(token);
4559 }
4560 }
4561
shilu366312e2019-12-17 09:28:10 -08004562 /**
4563 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4564 * @param subId The subscription to use to check the configuration.
4565 * @param c The callback that will be used to send the result.
4566 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004567 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004568 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004569 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004570 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004571 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4572 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4573 }
Meng Wangafbc5852019-09-19 17:37:13 -07004574 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004575
Meng Wangafbc5852019-09-19 17:37:13 -07004576 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004577 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4578 if (controller != null) {
4579 ImsManager imsManager = controller.getImsManager(subId);
4580 if (imsManager != null) {
4581 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4582 } else {
4583 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4584 + "is inactive, ignoring unregister.");
4585 // If the ImsManager is not valid, just return, since the callback
4586 // will already have been removed internally.
4587 }
4588 }
Meng Wangafbc5852019-09-19 17:37:13 -07004589 } finally {
4590 Binder.restoreCallingIdentity(token);
4591 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004592 }
4593
Brad Ebingera34a6c22019-10-22 17:36:18 -07004594 /**
Hidayat Khan99ea48f2023-12-11 04:37:45 +00004595 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4596 * @param subId The subscription to use to check the configuration.
4597 * @param c The callback that will be used to send the result.
4598 */
4599 @Override
4600 public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c)
4601 throws RemoteException {
4602 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4603 mApp, subId, "registerImsEmergencyRegistrationCallback");
4604
4605 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4606 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4607 "IMS not available on device.");
4608 }
4609 final long token = Binder.clearCallingIdentity();
4610 try {
4611 int slotId = getSlotIndexOrException(subId);
4612 verifyImsMmTelConfiguredOrThrow(slotId);
4613
4614 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4615 if (controller != null) {
4616 ImsManager imsManager = controller.getImsManager(subId);
4617 if (imsManager != null) {
4618 imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId);
4619 } else {
4620 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4621 }
4622 } else {
4623 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4624 }
4625 } catch (ImsException e) {
4626 throw new ServiceSpecificException(e.getCode());
4627 } finally {
4628 Binder.restoreCallingIdentity(token);
4629 }
4630 }
4631
4632 /**
4633 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4634 * @param subId The subscription to use to check the configuration.
4635 * @param c The callback that will be used to send the result.
4636 */
4637 @Override
4638 public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) {
4639 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4640 mApp, subId, "unregisterImsEmergencyRegistrationCallback");
4641 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4642 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4643 }
4644 final long token = Binder.clearCallingIdentity();
4645
4646 try {
4647 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4648 if (controller != null) {
4649 ImsManager imsManager = controller.getImsManager(subId);
4650 if (imsManager != null) {
4651 imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId);
4652 } else {
4653 Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId
4654 + "is inactive, ignoring unregister.");
4655 // If the ImsManager is not valid, just return, since the callback
4656 // will already have been removed internally.
4657 }
4658 }
4659 } finally {
4660 Binder.restoreCallingIdentity(token);
4661 }
4662 }
4663
4664 /**
Brad Ebingera34a6c22019-10-22 17:36:18 -07004665 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4666 */
4667 @Override
4668 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4669 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4670 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4671 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4672 "IMS not available on device.");
4673 }
4674 final long token = Binder.clearCallingIdentity();
4675 try {
4676 Phone phone = getPhone(subId);
4677 if (phone == null) {
4678 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4679 + subId + "'");
4680 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4681 }
4682 phone.getImsRegistrationState(regState -> {
4683 try {
4684 consumer.accept((regState == null)
4685 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4686 } catch (RemoteException e) {
4687 // Ignore if the remote process is no longer available to call back.
4688 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4689 }
4690 });
4691 } finally {
4692 Binder.restoreCallingIdentity(token);
4693 }
4694 }
4695
4696 /**
4697 * Get the transport type for the IMS service registration state.
4698 */
4699 @Override
4700 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004701 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004702 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004703 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4704 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4705 "IMS not available on device.");
4706 }
4707 final long token = Binder.clearCallingIdentity();
4708 try {
4709 Phone phone = getPhone(subId);
4710 if (phone == null) {
4711 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4712 + subId + "'");
4713 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4714 }
4715 phone.getImsRegistrationTech(regTech -> {
4716 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4717 int regTechConverted = (regTech == null)
4718 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4719 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4720 regTechConverted);
4721 try {
4722 consumer.accept(regTechConverted);
4723 } catch (RemoteException e) {
4724 // Ignore if the remote process is no longer available to call back.
4725 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4726 }
4727 });
4728 } finally {
4729 Binder.restoreCallingIdentity(token);
4730 }
4731 }
4732
shilu366312e2019-12-17 09:28:10 -08004733 /**
4734 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4735 * @param subId The subscription to use to check the configuration.
4736 * @param c The callback that will be used to send the result.
4737 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004738 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004739 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4740 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004741 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004742 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004743 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4744 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4745 "IMS not available on device.");
4746 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004747 final long token = Binder.clearCallingIdentity();
4748 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004749 int slotId = getSlotIndexOrException(subId);
4750 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004751
4752 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4753 if (controller != null) {
4754 ImsManager imsManager = controller.getImsManager(subId);
4755 if (imsManager != null) {
4756 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4757 } else {
4758 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4759 }
4760 } else {
4761 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4762 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004763 } catch (ImsException e) {
4764 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004765 } finally {
4766 Binder.restoreCallingIdentity(token);
4767 }
4768 }
4769
shilu366312e2019-12-17 09:28:10 -08004770 /**
4771 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4772 * @param subId The subscription to use to check the configuration.
4773 * @param c The callback that will be used to send the result.
4774 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004775 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004776 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004777 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004778 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004779 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4780 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4781 }
Meng Wangafbc5852019-09-19 17:37:13 -07004782
4783 final long token = Binder.clearCallingIdentity();
4784 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004785 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4786 if (controller != null) {
4787 ImsManager imsManager = controller.getImsManager(subId);
4788 if (imsManager != null) {
4789 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4790 } else {
4791 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4792 + " is inactive, ignoring unregister.");
4793 // If the ImsManager is not valid, just return, since the callback
4794 // will already have been removed internally.
4795 }
4796 }
Meng Wangafbc5852019-09-19 17:37:13 -07004797 } finally {
4798 Binder.restoreCallingIdentity(token);
4799 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004800 }
4801
4802 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004803 public boolean isCapable(int subId, int capability, int regTech) {
4804 enforceReadPrivilegedPermission("isCapable");
joonhunshin4ac60942023-11-15 15:23:39 +00004805
4806 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4807 FEATURE_TELEPHONY_IMS, "isCapable");
4808
Brad Ebinger35c841c2018-10-01 10:40:55 -07004809 final long token = Binder.clearCallingIdentity();
4810 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004811 int slotId = getSlotIndexOrException(subId);
4812 verifyImsMmTelConfiguredOrThrow(slotId);
4813 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4814 } catch (com.android.ims.ImsException e) {
4815 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4816 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004817 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004818 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4819 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004820 } finally {
4821 Binder.restoreCallingIdentity(token);
4822 }
4823 }
4824
4825 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004826 public boolean isAvailable(int subId, int capability, int regTech) {
4827 enforceReadPrivilegedPermission("isAvailable");
joonhunshin4ac60942023-11-15 15:23:39 +00004828
4829 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4830 FEATURE_TELEPHONY_IMS, "isAvailable");
4831
Brad Ebinger35c841c2018-10-01 10:40:55 -07004832 final long token = Binder.clearCallingIdentity();
4833 try {
4834 Phone phone = getPhone(subId);
4835 if (phone == null) return false;
4836 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004837 } catch (com.android.ims.ImsException e) {
4838 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4839 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004840 } finally {
4841 Binder.restoreCallingIdentity(token);
4842 }
4843 }
4844
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004845 /**
4846 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4847 * subscription.
4848 * @param subId The subscription to use to check the configuration.
4849 * @param callback The callback that will be used to send the result.
4850 * @param capability The MmTelFeature capability that will be used to send the result.
4851 * @param transportType The transport type of the MmTelFeature capability.
4852 */
4853 @Override
4854 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4855 int transportType) {
4856 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004857 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4858 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4859 "IMS not available on device.");
4860 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004861 final long token = Binder.clearCallingIdentity();
4862 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004863 int slotId = getSlotIndex(subId);
4864 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4865 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4866 + subId + "'");
4867 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4868 }
4869 verifyImsMmTelConfiguredOrThrow(slotId);
4870 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4871 transportType, aBoolean -> {
4872 try {
4873 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4874 } catch (RemoteException e) {
4875 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4876 + "running. Ignore");
4877 }
4878 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004879 } catch (ImsException e) {
4880 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004881 } finally {
4882 Binder.restoreCallingIdentity(token);
4883 }
4884 }
4885
shilu366312e2019-12-17 09:28:10 -08004886 /**
4887 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4888 * @param subId The subscription to use to check the configuration.
4889 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004890 @Override
4891 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004892 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004893 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004894
joonhunshin4ac60942023-11-15 15:23:39 +00004895 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4896 FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled");
4897
Brad Ebinger35c841c2018-10-01 10:40:55 -07004898 final long token = Binder.clearCallingIdentity();
4899 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004900 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004901 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004902 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004903 } catch (ImsException e) {
4904 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004905 } finally {
4906 Binder.restoreCallingIdentity(token);
4907 }
4908 }
4909
4910 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004911 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004912 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004913 "setAdvancedCallingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004914
4915 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4916 FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled");
4917
Brad Ebinger35c841c2018-10-01 10:40:55 -07004918 final long identity = Binder.clearCallingIdentity();
4919 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004920 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004921 // This setting doesn't require an active ImsService connection, so do not verify. The
4922 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004923 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004924 } catch (ImsException e) {
4925 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004926 } finally {
4927 Binder.restoreCallingIdentity(identity);
4928 }
4929 }
4930
shilu366312e2019-12-17 09:28:10 -08004931 /**
4932 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4933 * @param subId The subscription to use to check the configuration.
4934 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004935 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004936 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004937 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004938 mApp, subId, "isVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004939
4940 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4941 FEATURE_TELEPHONY_IMS, "isVtSettingEnabled");
4942
Brad Ebinger35c841c2018-10-01 10:40:55 -07004943 final long identity = Binder.clearCallingIdentity();
4944 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004945 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004946 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004947 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004948 } catch (ImsException e) {
4949 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004950 } finally {
4951 Binder.restoreCallingIdentity(identity);
4952 }
4953 }
4954
4955 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004956 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004957 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004958 "setVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004959
4960 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4961 FEATURE_TELEPHONY_IMS, "setVtSettingEnabled");
4962
Brad Ebinger35c841c2018-10-01 10:40:55 -07004963 final long identity = Binder.clearCallingIdentity();
4964 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004965 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004966 // This setting doesn't require an active ImsService connection, so do not verify. The
4967 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004968 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004969 } catch (ImsException e) {
4970 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004971 } finally {
4972 Binder.restoreCallingIdentity(identity);
4973 }
4974 }
4975
shilu366312e2019-12-17 09:28:10 -08004976 /**
4977 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4978 * @param subId The subscription to use to check the configuration.
4979 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004980 @Override
4981 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004982 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004983 mApp, subId, "isVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004984
4985 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4986 FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled");
4987
Brad Ebinger35c841c2018-10-01 10:40:55 -07004988 final long identity = Binder.clearCallingIdentity();
4989 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004990 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004991 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004992 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004993 } catch (ImsException e) {
4994 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004995 } finally {
4996 Binder.restoreCallingIdentity(identity);
4997 }
4998 }
4999
5000 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005001 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005002 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005003 "setVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005004
5005 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5006 FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled");
5007
Brad Ebinger35c841c2018-10-01 10:40:55 -07005008 final long identity = Binder.clearCallingIdentity();
5009 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005010 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005011 // This setting doesn't require an active ImsService connection, so do not verify. The
5012 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005013 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005014 } catch (ImsException e) {
5015 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005016 } finally {
5017 Binder.restoreCallingIdentity(identity);
5018 }
5019 }
5020
shilu366312e2019-12-17 09:28:10 -08005021 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005022 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
5023 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5024 * @param subId The subscription to use to check the configuration.
5025 */
5026 @Override
5027 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005028 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005029 mApp, subId, "isCrossSimCallingEnabledByUser");
joonhunshin4ac60942023-11-15 15:23:39 +00005030
5031 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5032 FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser");
5033
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005034 final long identity = Binder.clearCallingIdentity();
5035 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005036 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005037 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005038 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005039 } catch (ImsException e) {
5040 throw new ServiceSpecificException(e.getCode());
5041 } finally {
5042 Binder.restoreCallingIdentity(identity);
5043 }
5044 }
5045
5046 /**
5047 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
5048 * Requires MODIFY_PHONE_STATE permission.
5049 * @param subId The subscription to use to check the configuration.
5050 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
5051 * false otherwise
5052 */
5053 @Override
5054 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
5055 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5056 "setCrossSimCallingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005057
5058 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5059 FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled");
5060
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005061 final long identity = Binder.clearCallingIdentity();
5062 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005063 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005064 // This setting doesn't require an active ImsService connection, so do not verify. The
5065 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005066 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005067 } catch (ImsException e) {
5068 throw new ServiceSpecificException(e.getCode());
5069 } finally {
5070 Binder.restoreCallingIdentity(identity);
5071 }
5072 }
5073
5074 /**
shilu366312e2019-12-17 09:28:10 -08005075 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5076 * @param subId The subscription to use to check the configuration.
5077 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005078 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07005079
Brad Ebinger35c841c2018-10-01 10:40:55 -07005080 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005081 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005082 mApp, subId, "isVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005083
5084 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5085 FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled");
5086
Brad Ebinger35c841c2018-10-01 10:40:55 -07005087 final long identity = Binder.clearCallingIdentity();
5088 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005089 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005090 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005091 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005092 } catch (ImsException e) {
5093 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005094 } finally {
5095 Binder.restoreCallingIdentity(identity);
5096 }
5097 }
5098
5099 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005100 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005101 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005102 "setVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005103
5104 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5105 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled");
5106
Brad Ebinger35c841c2018-10-01 10:40:55 -07005107 final long identity = Binder.clearCallingIdentity();
5108 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005109 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005110 // This setting doesn't require an active ImsService connection, so do not verify. The
5111 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005112 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005113 } catch (ImsException e) {
5114 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005115 } finally {
5116 Binder.restoreCallingIdentity(identity);
5117 }
5118 }
5119
5120 @Override
5121 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
5122 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5123 "setVoWiFiNonPersistent");
joonhunshin4ac60942023-11-15 15:23:39 +00005124
5125 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5126 FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent");
5127
Brad Ebinger35c841c2018-10-01 10:40:55 -07005128 final long identity = Binder.clearCallingIdentity();
5129 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005130 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005131 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005132 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005133 } catch (ImsException e) {
5134 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005135 } finally {
5136 Binder.restoreCallingIdentity(identity);
5137 }
5138 }
5139
shilu366312e2019-12-17 09:28:10 -08005140 /**
5141 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5142 * @param subId The subscription to use to check the configuration.
5143 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005144 @Override
5145 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005146 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005147 mApp, subId, "getVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005148
5149 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5150 FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting");
5151
Brad Ebinger35c841c2018-10-01 10:40:55 -07005152 final long identity = Binder.clearCallingIdentity();
5153 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005154 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005155 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005156 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005157 } catch (ImsException e) {
5158 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005159 } finally {
5160 Binder.restoreCallingIdentity(identity);
5161 }
5162 }
5163
5164 @Override
5165 public void setVoWiFiModeSetting(int subId, int mode) {
5166 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5167 "setVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005168
5169 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5170 FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting");
5171
Brad Ebinger35c841c2018-10-01 10:40:55 -07005172 final long identity = Binder.clearCallingIdentity();
5173 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005174 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005175 // This setting doesn't require an active ImsService connection, so do not verify. The
5176 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005177 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005178 } catch (ImsException e) {
5179 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005180 } finally {
5181 Binder.restoreCallingIdentity(identity);
5182 }
5183 }
5184
5185 @Override
5186 public int getVoWiFiRoamingModeSetting(int subId) {
5187 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005188
5189 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5190 FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting");
5191
Brad Ebinger35c841c2018-10-01 10:40:55 -07005192 final long identity = Binder.clearCallingIdentity();
5193 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005194 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005195 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005196 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005197 } catch (ImsException e) {
5198 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005199 } finally {
5200 Binder.restoreCallingIdentity(identity);
5201 }
5202 }
5203
5204 @Override
5205 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
5206 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5207 "setVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005208
5209 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5210 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting");
5211
Brad Ebinger35c841c2018-10-01 10:40:55 -07005212 final long identity = Binder.clearCallingIdentity();
5213 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005214 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005215 // This setting doesn't require an active ImsService connection, so do not verify. The
5216 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005217 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005218 } catch (ImsException e) {
5219 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005220 } finally {
5221 Binder.restoreCallingIdentity(identity);
5222 }
5223 }
5224
5225 @Override
5226 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
5227 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5228 "setRttCapabilityEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005229
5230 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5231 FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting");
5232
Brad Ebinger35c841c2018-10-01 10:40:55 -07005233 final long identity = Binder.clearCallingIdentity();
5234 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005235 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005236 // This setting doesn't require an active ImsService connection, so do not verify. The
5237 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005238 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005239 } catch (ImsException e) {
5240 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005241 } finally {
5242 Binder.restoreCallingIdentity(identity);
5243 }
5244 }
5245
shilu366312e2019-12-17 09:28:10 -08005246 /**
5247 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5248 * @param subId The subscription to use to check the configuration.
5249 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005250 @Override
5251 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005252 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005253 mApp, subId, "isTtyOverVolteEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005254
5255 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5256 FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled");
5257
Brad Ebinger35c841c2018-10-01 10:40:55 -07005258 final long identity = Binder.clearCallingIdentity();
5259 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005260 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005261 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005262 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005263 } catch (ImsException e) {
5264 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005265 } finally {
5266 Binder.restoreCallingIdentity(identity);
5267 }
5268 }
5269
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005270 @Override
5271 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5272 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005273
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005274 final long identity = Binder.clearCallingIdentity();
5275 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005276 if (!isImsAvailableOnDevice()) {
5277 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5278 "IMS not available on device.");
5279 }
5280 int slotId = getSlotIndexOrException(subId);
5281 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005282
5283 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5284 if (controller != null) {
5285 ImsManager imsManager = controller.getImsManager(subId);
5286 if (imsManager != null) {
5287 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5288 } else {
5289 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5290 }
5291 } else {
5292 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5293 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005294 } catch (ImsException e) {
5295 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005296 } finally {
5297 Binder.restoreCallingIdentity(identity);
5298 }
5299 }
5300
5301 @Override
5302 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5303 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005304
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005305 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005306 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5307 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5308 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005309 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005310 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5311 if (controller != null) {
5312 ImsManager imsManager = controller.getImsManager(subId);
5313 if (imsManager != null) {
5314 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5315 } else {
5316 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5317 + " is inactive, ignoring unregister.");
5318 // If the ImsManager is not valid, just return, since the callback will already
5319 // have been removed internally.
5320 }
5321 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005322 } finally {
5323 Binder.restoreCallingIdentity(identity);
5324 }
5325 }
5326
joonhunshincffb7fc2021-11-28 07:32:01 +00005327 @Override
5328 public void registerFeatureProvisioningChangedCallback(int subId,
5329 IFeatureProvisioningCallback callback) {
5330 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5331 mApp, subId, "registerFeatureProvisioningChangedCallback");
5332
5333 final long identity = Binder.clearCallingIdentity();
5334 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5335 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5336 }
5337
joonhunshin91bc1952022-04-29 08:47:15 +00005338 try {
5339 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5340 if (controller == null) {
5341 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5342 "Device does not support IMS");
5343 }
5344 controller.addFeatureProvisioningChangedCallback(subId, callback);
5345 } finally {
5346 Binder.restoreCallingIdentity(identity);
5347 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005348 }
5349
5350 @Override
5351 public void unregisterFeatureProvisioningChangedCallback(int subId,
5352 IFeatureProvisioningCallback callback) {
5353 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5354 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5355
5356 final long identity = Binder.clearCallingIdentity();
5357 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5358 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5359 }
5360
joonhunshin91bc1952022-04-29 08:47:15 +00005361 try {
5362 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5363 if (controller == null) {
5364 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5365 return;
5366 }
5367 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5368 } finally {
5369 Binder.restoreCallingIdentity(identity);
5370 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005371 }
allenwtsu99c623b2020-01-03 18:24:23 +08005372
5373 private void checkModifyPhoneStatePermission(int subId, String message) {
5374 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5375 message);
5376 }
5377
allenwtsu99c623b2020-01-03 18:24:23 +08005378 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005379 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005380 boolean isProvisioned) {
5381 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5382
joonhunshin4ac60942023-11-15 15:23:39 +00005383 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5384 FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability");
5385
allenwtsu99c623b2020-01-03 18:24:23 +08005386 final long identity = Binder.clearCallingIdentity();
5387 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005388 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5389 if (controller == null) {
5390 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5391 return;
5392 }
5393 controller.setRcsProvisioningStatusForCapability(
5394 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005395 } finally {
5396 Binder.restoreCallingIdentity(identity);
5397 }
allenwtsu99c623b2020-01-03 18:24:23 +08005398 }
5399
5400
5401 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005402 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5403 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5404 mApp, subId, "getRcsProvisioningStatusForCapability");
5405
joonhunshin4ac60942023-11-15 15:23:39 +00005406 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5407 FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability");
5408
allenwtsu99c623b2020-01-03 18:24:23 +08005409 final long identity = Binder.clearCallingIdentity();
5410 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005411 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5412 if (controller == null) {
5413 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5414
5415 // device does not support IMS, this method will return true always.
5416 return true;
5417 }
5418 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005419 } finally {
5420 Binder.restoreCallingIdentity(identity);
5421 }
5422 }
5423
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005424 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005425 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5426 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005427 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005428
joonhunshin4ac60942023-11-15 15:23:39 +00005429 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5430 FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability");
5431
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005432 final long identity = Binder.clearCallingIdentity();
5433 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005434 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5435 if (controller == null) {
5436 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5437 return;
5438 }
5439 controller.setImsProvisioningStatusForCapability(
5440 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005441 } finally {
5442 Binder.restoreCallingIdentity(identity);
5443 }
5444 }
5445
5446 @Override
5447 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005448 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5449 mApp, subId, "getProvisioningStatusForCapability");
5450
joonhunshin4ac60942023-11-15 15:23:39 +00005451 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5452 FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability");
5453
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005454 final long identity = Binder.clearCallingIdentity();
5455 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005456 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5457 if (controller == null) {
5458 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005459
joonhunshin91bc1952022-04-29 08:47:15 +00005460 // device does not support IMS, this method will return true always.
5461 return true;
5462 }
5463 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005464 } finally {
5465 Binder.restoreCallingIdentity(identity);
5466 }
5467 }
5468
5469 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005470 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5471 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5472 mApp, subId, "isProvisioningRequiredForCapability");
5473
joonhunshin4ac60942023-11-15 15:23:39 +00005474 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5475 FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability");
5476
joonhunshincffb7fc2021-11-28 07:32:01 +00005477 final long identity = Binder.clearCallingIdentity();
5478 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005479 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5480 if (controller == null) {
5481 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5482
5483 // device does not support IMS, this method will return false
5484 return false;
5485 }
5486 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005487 } finally {
5488 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005489 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005490 }
5491
5492 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005493 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5494 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5495 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005496
joonhunshin4ac60942023-11-15 15:23:39 +00005497 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5498 FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability");
5499
joonhunshincffb7fc2021-11-28 07:32:01 +00005500 final long identity = Binder.clearCallingIdentity();
5501 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005502 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5503 if (controller == null) {
5504 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5505
5506 // device does not support IMS, this method will return false
5507 return false;
5508 }
5509 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005510 } finally {
5511 Binder.restoreCallingIdentity(identity);
5512 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005513 }
5514
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005515 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005516 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005517 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5518 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5519 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005520 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5521 mApp, subId, "getImsProvisioningInt");
5522
joonhunshin4ac60942023-11-15 15:23:39 +00005523 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5524 FEATURE_TELEPHONY_IMS, "getImsProvisioningInt");
5525
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005526 final long identity = Binder.clearCallingIdentity();
5527 try {
5528 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005529 int slotId = getSlotIndex(subId);
5530 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5531 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5532 + subId + "' for key:" + key);
5533 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5534 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005535
joonhunshin91bc1952022-04-29 08:47:15 +00005536 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5537 if (controller == null) {
5538 loge("getImsProvisioningInt: Device does not support IMS");
5539
5540 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5541 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5542 }
5543 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005544 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5545 return retVal;
5546 }
5547
calvinpanb5a34062021-02-08 19:59:36 +08005548 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005549 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005550 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5551 + subId + "' for key:" + key);
5552 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005553 } finally {
5554 Binder.restoreCallingIdentity(identity);
5555 }
5556 }
5557
5558 @Override
5559 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005560 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5561 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5562 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005563 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5564 mApp, subId, "getImsProvisioningString");
5565
joonhunshin4ac60942023-11-15 15:23:39 +00005566 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5567 FEATURE_TELEPHONY_IMS, "getImsProvisioningString");
5568
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005569 final long identity = Binder.clearCallingIdentity();
5570 try {
5571 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005572 int slotId = getSlotIndex(subId);
5573 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5574 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5575 + subId + "' for key:" + key);
5576 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5577 }
calvinpanb5a34062021-02-08 19:59:36 +08005578 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005579 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005580 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5581 + subId + "' for key:" + key);
5582 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005583 } finally {
5584 Binder.restoreCallingIdentity(identity);
5585 }
5586 }
5587
5588 @Override
5589 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005590 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5591 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5592 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005593 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5594 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005595
joonhunshin4ac60942023-11-15 15:23:39 +00005596 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5597 FEATURE_TELEPHONY_IMS, "setImsProvisioningInt");
5598
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005599 final long identity = Binder.clearCallingIdentity();
5600 try {
5601 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005602 int slotId = getSlotIndex(subId);
5603 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5604 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5605 + subId + "' for key:" + key);
5606 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5607 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005608
joonhunshin91bc1952022-04-29 08:47:15 +00005609 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5610 if (controller == null) {
5611 loge("setImsProvisioningInt: Device does not support IMS");
5612
5613 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5614 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5615 }
5616 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005617 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5618 return retVal;
5619 }
5620
calvinpanb5a34062021-02-08 19:59:36 +08005621 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5622 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005623 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005624 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005625 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005626 } finally {
5627 Binder.restoreCallingIdentity(identity);
5628 }
5629 }
5630
5631 @Override
5632 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005633 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5634 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5635 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005636 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5637 "setImsProvisioningString");
joonhunshin4ac60942023-11-15 15:23:39 +00005638
5639 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5640 FEATURE_TELEPHONY_IMS, "setImsProvisioningString");
5641
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005642 final long identity = Binder.clearCallingIdentity();
5643 try {
5644 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005645 int slotId = getSlotIndex(subId);
5646 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5647 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5648 + subId + "' for key:" + key);
5649 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5650 }
calvinpanb5a34062021-02-08 19:59:36 +08005651 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5652 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005653 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005654 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005655 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005656 } finally {
5657 Binder.restoreCallingIdentity(identity);
5658 }
5659 }
5660
Brad Ebinger919631e2021-06-02 17:46:35 -07005661 /**
5662 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5663 * for the given slot ID or no ImsResolver instance has been created.
5664 * @param slotId The slot ID that the IMS service is created for.
5665 * @throws ImsException If there is no ImsService configured for this slot.
5666 */
5667 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5668 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5669 ImsFeature.FEATURE_MMTEL)) {
5670 throw new ImsException("This subscription does not support MMTEL over IMS",
5671 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5672 }
5673 }
5674
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005675 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005676 int slotId = SubscriptionManager.getSlotIndex(subId);
5677 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005678 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5679 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005680 }
5681 return slotId;
5682 }
5683
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005684 private int getSlotIndex(int subId) {
5685 int slotId = SubscriptionManager.getSlotIndex(subId);
5686 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5687 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5688 }
5689 return slotId;
5690 }
5691
Wink Saville36469e72014-06-11 15:17:00 -07005692 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005693 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005694 */
5695 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005696 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5697 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005698 try {
5699 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5700 } catch (SecurityException se) {
5701 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5702 throw new SecurityException("Package " + callingPackage + " does not belong to "
5703 + Binder.getCallingUid());
5704 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005705 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005706 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005707 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005708 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005709 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005710 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005711 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005712 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5713 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005714
joonhunshin4ac60942023-11-15 15:23:39 +00005715 enforceTelephonyFeatureWithException(callingPackage,
5716 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber");
5717
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005718 final long identity = Binder.clearCallingIdentity();
5719 try {
5720 final Phone phone = getPhone(subId);
5721 if (phone != null) {
5722 return phone.getServiceState().getDataNetworkType();
5723 } else {
5724 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5725 }
5726 } finally {
5727 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005728 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005729 }
5730
5731 /**
5732 * Returns the data network type
5733 */
5734 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005735 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005736 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005737 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005738 }
5739
5740 /**
5741 * Returns the data network type for a subId
5742 */
5743 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005744 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5745 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005746 String functionName = "getDataNetworkTypeForSubscriber";
5747 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5748 mApp, functionName)) {
5749 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5750 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5751 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5752 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005753 }
5754
joonhunshin4ac60942023-11-15 15:23:39 +00005755 enforceTelephonyFeatureWithException(callingPackage,
5756 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber");
5757
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005758 final long identity = Binder.clearCallingIdentity();
5759 try {
5760 final Phone phone = getPhone(subId);
5761 if (phone != null) {
5762 return phone.getServiceState().getDataNetworkType();
5763 } else {
5764 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5765 }
5766 } finally {
5767 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005768 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005769 }
5770
5771 /**
Wink Saville36469e72014-06-11 15:17:00 -07005772 * Returns the Voice network type for a subId
5773 */
5774 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005775 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5776 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005777 String functionName = "getVoiceNetworkTypeForSubscriber";
5778 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5779 mApp, functionName)) {
5780 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5781 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5782 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5783 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005784 }
5785
joonhunshin4ac60942023-11-15 15:23:39 +00005786 enforceTelephonyFeatureWithException(callingPackage,
5787 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber");
5788
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005789 final long identity = Binder.clearCallingIdentity();
5790 try {
5791 final Phone phone = getPhone(subId);
5792 if (phone != null) {
5793 return phone.getServiceState().getVoiceNetworkType();
5794 } else {
5795 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5796 }
5797 } finally {
5798 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005799 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005800 }
5801
5802 /**
5803 * @return true if a ICC card is present
5804 */
5805 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005806 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005807 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005808 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005809 }
5810
5811 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005812 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005813 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005814 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005815 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00005816 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5817 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex");
5818
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005819 final long identity = Binder.clearCallingIdentity();
5820 try {
5821 final Phone phone = PhoneFactory.getPhone(slotIndex);
5822 if (phone != null) {
5823 return phone.getIccCard().hasIccCard();
5824 } else {
5825 return false;
5826 }
5827 } finally {
5828 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005829 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005830 }
5831
5832 /**
5833 * Return if the current radio is LTE on CDMA. This
5834 * is a tri-state return value as for a period of time
5835 * the mode may be unknown.
5836 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005837 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005838 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005839 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005840 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005841 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005842 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5843 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5844 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005845 }
5846
Sanket Padawe356d7632015-06-22 14:03:32 -07005847 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005848 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5849 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005850 try {
5851 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5852 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005853 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5854 }
5855
joonhunshin4ac60942023-11-15 15:23:39 +00005856 enforceTelephonyFeatureWithException(callingPackage,
5857 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber");
5858
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005859 final long identity = Binder.clearCallingIdentity();
5860 try {
5861 final Phone phone = getPhone(subId);
5862 if (phone == null) {
5863 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5864 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005865 return TelephonyProperties.lte_on_cdma_device()
5866 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005867 }
5868 } finally {
5869 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005870 }
Wink Saville36469e72014-06-11 15:17:00 -07005871 }
5872
Wink Saville36469e72014-06-11 15:17:00 -07005873 /**
5874 * {@hide}
5875 * Returns Default subId, 0 in the case of single standby.
5876 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005877 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005878 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005879 }
5880
Shishir Agrawala9f32182016-04-12 12:00:16 -07005881 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005882 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005883 }
5884
Wink Savilleb564aae2014-10-23 10:18:09 -07005885 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005886 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005887 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005888
Pengquan Menge92a50d2018-09-21 15:54:48 -07005889 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005890 return getSubscriptionManagerService().isActiveSubId(subId,
5891 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005892 }
5893
Ihab Awadf2177b72013-11-25 13:33:23 -08005894 /**
5895 * @see android.telephony.TelephonyManager.WifiCallingChoices
5896 */
5897 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005898 final long identity = Binder.clearCallingIdentity();
5899 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005900 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005901 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5902 getWhenToMakeWifiCallsDefaultPreference());
5903 } finally {
5904 Binder.restoreCallingIdentity(identity);
5905 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005906 }
5907
5908 /**
5909 * @see android.telephony.TelephonyManager.WifiCallingChoices
5910 */
5911 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005912 final long identity = Binder.clearCallingIdentity();
5913 try {
5914 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005915 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005916 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5917 } finally {
5918 Binder.restoreCallingIdentity(identity);
5919 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005920 }
5921
Sailesh Nepald1e68152013-12-12 19:08:02 -08005922 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005923 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005924 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005925 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005926
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005927 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5928 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5929 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005930 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005931 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005932 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005933 }
5934 return PhoneFactory.getPhone(phoneId);
5935 }
5936
Shishir Agrawal566b7612013-10-28 14:41:00 -07005937 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005938 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005939 @NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00005940
Rambo Wanga1782702021-11-10 20:15:19 -08005941 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5942 /*message=*/ "iccOpenLogicalChannel");
5943
5944 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5945 // Verify that the callingPackage in the request belongs to the calling UID
5946 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5947
joonhunshin4ac60942023-11-15 15:23:39 +00005948 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5949 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel");
5950
Rambo Wanga1782702021-11-10 20:15:19 -08005951 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005952 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005953
Rambo Wanga1782702021-11-10 20:15:19 -08005954 private Phone getPhoneFromValidIccLogicalChannelRequest(
5955 @NonNull IccLogicalChannelRequest request, String message) {
5956 Phone phone;
5957 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5958 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5959 mApp, request.subId, message);
5960 phone = getPhoneFromSubId(request.subId);
5961 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5962 enforceModifyPermission();
5963 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5964 } else {
5965 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005966 }
Rambo Wanga1782702021-11-10 20:15:19 -08005967 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005968 }
5969
5970 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005971 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005972 final long identity = Binder.clearCallingIdentity();
5973 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005974 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005975 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005976 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5977 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005978 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5979 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005980 loge("The calling package is not allowed to access ISD-R.");
5981 throw new SecurityException(
5982 "The calling package is not allowed to access ISD-R.");
5983 }
Derek Tan740e1672017-06-27 14:56:27 -07005984 }
Derek Tan740e1672017-06-27 14:56:27 -07005985
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005986 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005987 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5988 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005989 return response;
5990 } finally {
5991 Binder.restoreCallingIdentity(identity);
5992 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005993 }
5994
5995 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005996 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00005997 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5998 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel");
5999
Rambo Wanga1782702021-11-10 20:15:19 -08006000 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
6001 /*message=*/"iccCloseLogicalChannel");
6002
6003 if (DBG) log("iccCloseLogicalChannel: request=" + request);
6004
6005 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006006 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006007
Rambo Wanga1782702021-11-10 20:15:19 -08006008 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
6009 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08006010 // before this feature is enabled, this API should only return false if
6011 // the operation fails instead of throwing runtime exception for
6012 // backward-compatibility.
6013 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
6014 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006015 final long identity = Binder.clearCallingIdentity();
6016 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006017 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08006018 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006019 }
Chen Xue9d737e2022-01-01 23:41:31 -08006020 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08006021 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08006022 Boolean success = false;
6023 if (result instanceof RuntimeException) {
6024 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08006025 if (shouldThrowExceptionOnFailure) {
6026 throw (RuntimeException) result;
6027 } else {
6028 return false;
6029 }
Chen Xue9d737e2022-01-01 23:41:31 -08006030 } else if (result instanceof Boolean) {
6031 success = (Boolean) result;
6032 } else {
6033 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
6034 }
Rambo Wanga1782702021-11-10 20:15:19 -08006035 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006036 return success;
6037 } finally {
6038 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006039 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006040 }
6041
6042 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006043 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07006044 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006045 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6046 mApp, subId, "iccTransmitApduLogicalChannel");
joonhunshin4ac60942023-11-15 15:23:39 +00006047
6048 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6049 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel");
6050
Jordan Liu4c733742019-02-28 12:03:40 -08006051 if (DBG) {
6052 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
6053 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
6054 + p3 + " data=" + data);
6055 }
6056 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
6057 command, p1, p2, p3, data);
6058 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006059
Jordan Liu4c733742019-02-28 12:03:40 -08006060 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006061 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006062 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006063 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006064
6065 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6066 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
6067 "iccTransmitApduLogicalChannelBySlot");
6068
Jordan Liu4c733742019-02-28 12:03:40 -08006069 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006070 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006071 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
6072 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006073 }
6074 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006075 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
6076 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006077 }
6078
6079 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
6080 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006081 final long identity = Binder.clearCallingIdentity();
6082 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07006083 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006084 return "";
6085 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006086
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006087 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006088 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
6089 null /* workSource */);
6090 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006091
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006092 // Append the returned status code to the end of the response payload.
6093 String s = Integer.toHexString(
6094 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6095 if (response.payload != null) {
6096 s = IccUtils.bytesToHexString(response.payload) + s;
6097 }
6098 return s;
6099 } finally {
6100 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006101 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006102 }
Jake Hambye994d462014-02-03 13:10:13 -08006103
Evan Charltonc66da362014-05-16 14:06:40 -07006104 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006105 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
6106 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006107 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6108 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006109 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006110
6111 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6112 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel");
6113
Jordan Liu4c733742019-02-28 12:03:40 -08006114 if (DBG) {
6115 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
6116 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
6117 }
6118 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
6119 cla, command, p1, p2, p3, data);
6120 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006121
Jordan Liu4c733742019-02-28 12:03:40 -08006122 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006123 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006124 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006125 enforceModifyPermission();
6126 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006127
6128 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6129 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot");
6130
Jordan Liu4c733742019-02-28 12:03:40 -08006131 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006132 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006133 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
6134 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006135 }
6136
6137 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006138 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
6139 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006140 }
6141
6142 // open APDU basic channel assuming the caller has sufficient permissions
6143 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
6144 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006145 final long identity = Binder.clearCallingIdentity();
6146 try {
6147 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
6148 && TextUtils.equals(ISDR_AID, data)) {
6149 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006150 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6151 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006152 if (bestComponent == null
6153 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
6154 loge("The calling package is not allowed to select ISD-R.");
6155 throw new SecurityException(
6156 "The calling package is not allowed to select ISD-R.");
6157 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006158 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006159
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006160 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006161 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
6162 null /* workSource */);
6163 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006164
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006165 // Append the returned status code to the end of the response payload.
6166 String s = Integer.toHexString(
6167 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6168 if (response.payload != null) {
6169 s = IccUtils.bytesToHexString(response.payload) + s;
6170 }
6171 return s;
6172 } finally {
6173 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006174 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006175 }
6176
6177 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006178 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006179 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006180 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6181 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006182
joonhunshin4ac60942023-11-15 15:23:39 +00006183 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6184 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO");
6185
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006186 final long identity = Binder.clearCallingIdentity();
6187 try {
6188 if (DBG) {
6189 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
6190 + p1 + " " + p2 + " " + p3 + ":" + filePath);
6191 }
6192
6193 IccIoResult response =
6194 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
6195 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
6196 subId);
6197
6198 if (DBG) {
6199 log("Exchange SIM_IO [R]" + response);
6200 }
6201
6202 byte[] result = null;
6203 int length = 2;
6204 if (response.payload != null) {
6205 length = 2 + response.payload.length;
6206 result = new byte[length];
6207 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
6208 } else {
6209 result = new byte[length];
6210 }
6211
6212 result[length - 1] = (byte) response.sw2;
6213 result[length - 2] = (byte) response.sw1;
6214 return result;
6215 } finally {
6216 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006217 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006218 }
6219
Nathan Haroldb3014052017-01-25 15:57:32 -08006220 /**
6221 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
6222 * on a particular subscription
6223 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006224 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
6225 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07006226 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006227 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07006228 return null;
6229 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006230
joonhunshin4ac60942023-11-15 15:23:39 +00006231 enforceTelephonyFeatureWithException(callingPackage,
6232 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns");
6233
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006234 final long identity = Binder.clearCallingIdentity();
6235 try {
6236 if (appType != TelephonyManager.APPTYPE_USIM
6237 && appType != TelephonyManager.APPTYPE_SIM) {
6238 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
6239 return null;
6240 }
6241 Object response = sendRequest(
6242 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
6243 if (response instanceof String[]) {
6244 return (String[]) response;
6245 }
yincheng zhao2737e882019-09-06 17:06:54 -07006246 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006247 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08006248 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006249 } finally {
6250 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08006251 }
Nathan Haroldb3014052017-01-25 15:57:32 -08006252 }
6253
yincheng zhao2737e882019-09-06 17:06:54 -07006254 /**
6255 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
6256 * subscription.
6257 *
6258 * @param subId the id of the subscription.
6259 * @param appType the uicc app type, must be USIM or SIM.
6260 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
6261 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006262 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07006263 * @return number of fplmns that is successfully written to the SIM.
6264 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006265 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
6266 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07006267 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6268 mApp, subId, "setForbiddenPlmns");
6269
joonhunshin4ac60942023-11-15 15:23:39 +00006270 enforceTelephonyFeatureWithException(callingPackage,
6271 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns");
6272
yincheng zhao2737e882019-09-06 17:06:54 -07006273 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
6274 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
6275 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
6276 }
6277 if (fplmns == null) {
6278 throw new IllegalArgumentException("Fplmn List provided is null");
6279 }
6280 for (String fplmn : fplmns) {
6281 if (!CellIdentity.isValidPlmn(fplmn)) {
6282 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
6283 }
6284 }
6285 final long identity = Binder.clearCallingIdentity();
6286 try {
6287 Object response = sendRequest(
6288 CMD_SET_FORBIDDEN_PLMNS,
6289 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
6290 subId);
6291 return (int) response;
6292 } finally {
6293 Binder.restoreCallingIdentity(identity);
6294 }
6295 }
6296
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006297 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006298 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006299 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6300 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07006301
joonhunshin4ac60942023-11-15 15:23:39 +00006302 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6303 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus");
6304
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006305 final long identity = Binder.clearCallingIdentity();
6306 try {
6307 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
6308 if (response.payload == null) {
6309 return "";
6310 }
Evan Charltonc66da362014-05-16 14:06:40 -07006311
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006312 // Append the returned status code to the end of the response payload.
6313 String s = Integer.toHexString(
6314 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6315 s = IccUtils.bytesToHexString(response.payload) + s;
6316 return s;
6317 } finally {
6318 Binder.restoreCallingIdentity(identity);
6319 }
Evan Charltonc66da362014-05-16 14:06:40 -07006320 }
6321
Jake Hambye994d462014-02-03 13:10:13 -08006322 /**
6323 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6324 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6325 *
6326 * @param itemID the ID of the item to read
6327 * @return the NV item as a String, or null on error.
6328 */
6329 @Override
6330 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006331 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006332 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6333 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006334
6335 final long identity = Binder.clearCallingIdentity();
6336 try {
6337 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07006338 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006339 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
6340 return value;
6341 } finally {
6342 Binder.restoreCallingIdentity(identity);
6343 }
Jake Hambye994d462014-02-03 13:10:13 -08006344 }
6345
6346 /**
6347 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6348 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6349 *
6350 * @param itemID the ID of the item to read
6351 * @param itemValue the value to write, as a String
6352 * @return true on success; false on any failure
6353 */
6354 @Override
6355 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006356 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006357 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6358 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006359
6360 final long identity = Binder.clearCallingIdentity();
6361 try {
6362 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6363 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006364 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006365 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6366 return success;
6367 } finally {
6368 Binder.restoreCallingIdentity(identity);
6369 }
Jake Hambye994d462014-02-03 13:10:13 -08006370 }
6371
6372 /**
6373 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6374 * Used for device configuration by some CDMA operators.
6375 *
6376 * @param preferredRoamingList byte array containing the new PRL
6377 * @return true on success; false on any failure
6378 */
6379 @Override
6380 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006381 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6382 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006383
6384 final long identity = Binder.clearCallingIdentity();
6385 try {
6386 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6387 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6388 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6389 return success;
6390 } finally {
6391 Binder.restoreCallingIdentity(identity);
6392 }
Jake Hambye994d462014-02-03 13:10:13 -08006393 }
6394
6395 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006396 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006397 * Used for device configuration by some CDMA operators.
6398 *
chen xu6dac5ab2018-10-26 17:39:23 -07006399 * @param slotIndex - device slot.
6400 *
Jake Hambye994d462014-02-03 13:10:13 -08006401 * @return true on success; false on any failure
6402 */
6403 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006404 public boolean resetModemConfig(int slotIndex) {
6405 Phone phone = PhoneFactory.getPhone(slotIndex);
6406 if (phone != null) {
6407 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6408 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006409
joonhunshin4ac60942023-11-15 15:23:39 +00006410 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6411 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig");
6412
chen xu6dac5ab2018-10-26 17:39:23 -07006413 final long identity = Binder.clearCallingIdentity();
6414 try {
6415 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6416 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6417 return success;
6418 } finally {
6419 Binder.restoreCallingIdentity(identity);
6420 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006421 }
chen xu6dac5ab2018-10-26 17:39:23 -07006422 return false;
6423 }
6424
6425 /**
6426 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6427 *
6428 * @param slotIndex - device slot.
6429 *
6430 * @return true on success; false on any failure
6431 */
6432 @Override
6433 public boolean rebootModem(int slotIndex) {
6434 Phone phone = PhoneFactory.getPhone(slotIndex);
6435 if (phone != null) {
6436 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6437 mApp, phone.getSubId(), "rebootModem");
6438
joonhunshin4ac60942023-11-15 15:23:39 +00006439 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6440 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem");
6441
chen xu6dac5ab2018-10-26 17:39:23 -07006442 final long identity = Binder.clearCallingIdentity();
6443 try {
6444 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6445 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6446 return success;
6447 } finally {
6448 Binder.restoreCallingIdentity(identity);
6449 }
6450 }
6451 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006452 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006453
Brad Ebinger51f743a2017-01-23 13:50:20 -08006454 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006455 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6456 * {@link #disableIms(int)}.
6457 * @param slotIndex device slot.
6458 */
6459 public void resetIms(int slotIndex) {
6460 enforceModifyPermission();
6461
joonhunshin4ac60942023-11-15 15:23:39 +00006462 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6463 PackageManager.FEATURE_TELEPHONY_IMS, "resetIms");
6464
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006465 final long identity = Binder.clearCallingIdentity();
6466 try {
6467 if (mImsResolver == null) {
6468 // may happen if the does not support IMS.
6469 return;
6470 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006471 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006472 } finally {
6473 Binder.restoreCallingIdentity(identity);
6474 }
6475 }
6476
6477 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006478 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6479 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006480 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006481 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006482 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006483
6484 final long identity = Binder.clearCallingIdentity();
6485 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006486 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006487 // may happen if the device does not support IMS.
6488 return;
6489 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006490 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006491 } finally {
6492 Binder.restoreCallingIdentity(identity);
6493 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006494 }
6495
6496 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006497 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6498 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006499 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006500 public void disableIms(int slotId) {
6501 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006502
6503 final long identity = Binder.clearCallingIdentity();
6504 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006505 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006506 // may happen if the device does not support IMS.
6507 return;
6508 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006509 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006510 } finally {
6511 Binder.restoreCallingIdentity(identity);
6512 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006513 }
6514
6515 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006516 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6517 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006518 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006519 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006520 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006521 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006522
6523 final long identity = Binder.clearCallingIdentity();
6524 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006525 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006526 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6527 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006528 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006529 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006530 } finally {
6531 Binder.restoreCallingIdentity(identity);
6532 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006533 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006534 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006535 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6536 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006537 @Override
6538 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006539 enforceModifyPermission();
6540
6541 final long identity = Binder.clearCallingIdentity();
6542 try {
6543 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006544 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006545 } finally {
6546 Binder.restoreCallingIdentity(identity);
6547 }
6548 }
6549
6550 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006551 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006552 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006553 */
6554 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6555 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006556
6557 final long identity = Binder.clearCallingIdentity();
6558 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006559 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006560 // may happen if the device does not support IMS.
6561 return null;
6562 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006563 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006564 } finally {
6565 Binder.restoreCallingIdentity(identity);
6566 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006567 }
6568
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006569 /**
6570 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006571 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006572 */
6573 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6574 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006575
6576 final long identity = Binder.clearCallingIdentity();
6577 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006578 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006579 // may happen if the device does not support IMS.
6580 return null;
6581 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006582 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006583 } finally {
6584 Binder.restoreCallingIdentity(identity);
6585 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006586 }
6587
Brad Ebinger884c07b2018-02-15 16:17:40 -08006588 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006589 * Sets the ImsService Package Name that Telephony will bind to.
6590 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006591 * @param slotIndex the slot ID that the ImsService should bind for.
6592 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006593 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006594 * @param featureTypes An integer array of feature types associated with a packageName.
6595 * @param packageName The name of the package that the current configuration will be replaced
6596 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006597 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006598 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006599 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6600 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006601 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006602 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006603 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006604
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006605 final long identity = Binder.clearCallingIdentity();
6606 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006607 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006608 // may happen if the device does not support IMS.
6609 return false;
6610 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006611 Map<Integer, String> featureConfig = new HashMap<>();
6612 for (int featureType : featureTypes) {
6613 featureConfig.put(featureType, packageName);
6614 }
6615 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6616 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006617 } finally {
6618 Binder.restoreCallingIdentity(identity);
6619 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006620 }
6621
6622 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006623 * Clears any carrier ImsService overrides for the slot index specified that were previously
6624 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6625 *
6626 * This should only be used for testing.
6627 *
6628 * @param slotIndex the slot ID that the ImsService should bind for.
6629 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6630 */
6631 @Override
6632 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006633 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6634 "clearCarrierImsServiceOverride");
6635 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006636 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006637
6638 final long identity = Binder.clearCallingIdentity();
6639 try {
6640 if (mImsResolver == null) {
6641 // may happen if the device does not support IMS.
6642 return false;
6643 }
6644 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6645 } finally {
6646 Binder.restoreCallingIdentity(identity);
6647 }
6648 }
6649
6650 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006651 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006652 *
6653 * @param slotId The slot that the ImsService is associated with.
6654 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6655 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006656 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006657 * @return the package name of the ImsService configuration.
6658 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006659 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6660 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006661 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006662 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6663 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006664
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006665 final long identity = Binder.clearCallingIdentity();
6666 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006667 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006668 // may happen if the device does not support IMS.
6669 return "";
6670 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006671 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006672 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6673 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006674 } finally {
6675 Binder.restoreCallingIdentity(identity);
6676 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006677 }
6678
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006679 /**
6680 * Get the MmTelFeature state associated with the requested subscription id.
6681 * @param subId The subscription that the MmTelFeature is associated with.
6682 * @param callback A callback with an integer containing the
6683 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6684 */
6685 @Override
6686 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6687 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006688 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6689 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6690 "IMS not available on device.");
6691 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006692 final long token = Binder.clearCallingIdentity();
6693 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006694 int slotId = getSlotIndex(subId);
6695 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6696 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6697 + subId + "'");
6698 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6699 }
6700 verifyImsMmTelConfiguredOrThrow(slotId);
6701 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6702 try {
6703 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6704 } catch (RemoteException e) {
6705 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6706 + "Ignore");
6707 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006708 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006709 } catch (ImsException e) {
6710 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006711 } finally {
6712 Binder.restoreCallingIdentity(token);
6713 }
6714 }
6715
Daniel Brightbb5840b2021-01-12 15:48:18 -08006716 /**
6717 * Sets the ims registration state on all valid {@link Phone}s.
6718 */
6719 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006720 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006721
6722 final long identity = Binder.clearCallingIdentity();
6723 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006724 // NOTE: Before S, this method only set the default phone.
6725 for (final Phone phone : PhoneFactory.getPhones()) {
6726 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6727 phone.setImsRegistrationState(registered);
6728 }
6729 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006730 } finally {
6731 Binder.restoreCallingIdentity(identity);
6732 }
Wink Saville36469e72014-06-11 15:17:00 -07006733 }
6734
6735 /**
Stuart Scott54788802015-03-30 13:18:01 -07006736 * Set the network selection mode to automatic.
6737 *
6738 */
6739 @Override
6740 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006741 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6742 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006743
joonhunshin4ac60942023-11-15 15:23:39 +00006744 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6745 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic");
6746
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006747 final long identity = Binder.clearCallingIdentity();
6748 try {
shilufc958392020-01-20 11:36:01 -08006749 if (!isActiveSubscription(subId)) {
6750 return;
6751 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006752 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006753 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6754 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006755 } finally {
6756 Binder.restoreCallingIdentity(identity);
6757 }
Stuart Scott54788802015-03-30 13:18:01 -07006758 }
6759
Jack Yud10cdd42020-09-28 20:28:01 -07006760 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006761 * Ask the radio to connect to the input network and change selection mode to manual.
6762 *
6763 * @param subId the id of the subscription.
6764 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6765 * the operator to attach to.
6766 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6767 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6768 * normal network selection next time.
6769 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006770 */
6771 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006772 public boolean setNetworkSelectionModeManual(
6773 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006774 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6775 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006776
joonhunshin4ac60942023-11-15 15:23:39 +00006777 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6778 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual");
6779
Jack Yu285100e2022-12-02 22:48:35 -08006780 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006781 if (!isActiveSubscription(subId)) {
6782 return false;
6783 }
6784
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006785 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006786 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006787 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006788 if (DBG) {
6789 log("setNetworkSelectionModeManual: subId: " + subId
6790 + " operator: " + operatorInfo);
6791 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006792 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6793 } finally {
6794 Binder.restoreCallingIdentity(identity);
6795 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006796 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006797 /**
shilu84f6e8b2019-12-19 13:58:01 -08006798 * Get the manual network selection
6799 *
6800 * @param subId the id of the subscription.
6801 *
6802 * @return the previously saved user selected PLMN
6803 */
6804 @Override
6805 public String getManualNetworkSelectionPlmn(int subId) {
6806 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006807 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6808 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006809
joonhunshin4ac60942023-11-15 15:23:39 +00006810 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6811 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn");
6812
shilu84f6e8b2019-12-19 13:58:01 -08006813 final long identity = Binder.clearCallingIdentity();
6814 try {
6815 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006816 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006817 }
6818
6819 final Phone phone = getPhone(subId);
6820 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006821 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006822 }
6823 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6824 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006825 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006826 } finally {
6827 Binder.restoreCallingIdentity(identity);
6828 }
6829 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006830
6831 /**
6832 * Scans for available networks.
6833 */
6834 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006835 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6836 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006837 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6838 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006839 LocationAccessPolicy.LocationPermissionResult locationResult =
6840 LocationAccessPolicy.checkLocationPermission(mApp,
6841 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6842 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006843 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006844 .setCallingPid(Binder.getCallingPid())
6845 .setCallingUid(Binder.getCallingUid())
6846 .setMethod("getCellNetworkScanResults")
6847 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006848 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6849 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006850 .build());
6851 switch (locationResult) {
6852 case DENIED_HARD:
6853 throw new SecurityException("Not allowed to access scan results -- location");
6854 case DENIED_SOFT:
6855 return null;
6856 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006857
Pengquan Menga1bb6272018-09-06 09:59:22 -07006858 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006859 try {
6860 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006861 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006862 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006863 } finally {
6864 Binder.restoreCallingIdentity(identity);
6865 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006866 }
6867
6868 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006869 * Get the call forwarding info, given the call forwarding reason.
6870 */
6871 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006872 public void getCallForwarding(int subId, int callForwardingReason,
6873 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006874 enforceReadPrivilegedPermission("getCallForwarding");
joonhunshin4ac60942023-11-15 15:23:39 +00006875
6876 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6877 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding");
6878
Shuo Qian4a594052020-01-23 11:59:30 -08006879 long identity = Binder.clearCallingIdentity();
6880 try {
6881 if (DBG) {
6882 log("getCallForwarding: subId " + subId
6883 + " callForwardingReason" + callForwardingReason);
6884 }
Hall Liu27d24262020-09-18 19:04:59 -07006885
6886 Phone phone = getPhone(subId);
6887 if (phone == null) {
6888 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006889 callback.onError(
6890 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006891 } catch (RemoteException e) {
6892 // ignore
6893 }
6894 return;
6895 }
6896
6897 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6898 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6899 @Override
6900 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6901 try {
6902 callback.onCallForwardingInfoAvailable(info);
6903 } catch (RemoteException e) {
6904 // ignore
6905 }
6906 }
6907
6908 @Override
6909 public void onError(int error) {
6910 try {
6911 callback.onError(error);
6912 } catch (RemoteException e) {
6913 // ignore
6914 }
6915 }
6916 });
6917 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006918 } finally {
6919 Binder.restoreCallingIdentity(identity);
6920 }
6921 }
6922
6923 /**
6924 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6925 * reason, the number to forward, and the timeout before the forwarding is attempted.
6926 */
6927 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006928 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6929 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006930 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006931
6932 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6933 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding");
6934
Shuo Qian4a594052020-01-23 11:59:30 -08006935 long identity = Binder.clearCallingIdentity();
6936 try {
6937 if (DBG) {
6938 log("setCallForwarding: subId " + subId
6939 + " callForwardingInfo" + callForwardingInfo);
6940 }
Hall Liu27d24262020-09-18 19:04:59 -07006941
6942 Phone phone = getPhone(subId);
6943 if (phone == null) {
6944 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006945 callback.accept(
6946 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006947 } catch (RemoteException e) {
6948 // ignore
6949 }
6950 return;
6951 }
6952
6953 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6954 FunctionalUtils.ignoreRemoteException(callback::accept));
6955
6956 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006957 } finally {
6958 Binder.restoreCallingIdentity(identity);
6959 }
6960 }
6961
6962 /**
Hall Liu27d24262020-09-18 19:04:59 -07006963 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006964 */
6965 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006966 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006967 enforceReadPrivilegedPermission("getCallWaitingStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00006968
6969 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6970 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus");
6971
Shuo Qian4a594052020-01-23 11:59:30 -08006972 long identity = Binder.clearCallingIdentity();
6973 try {
Hall Liu27d24262020-09-18 19:04:59 -07006974 Phone phone = getPhone(subId);
6975 if (phone == null) {
6976 try {
6977 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6978 } catch (RemoteException e) {
6979 // ignore
6980 }
6981 return;
6982 }
SongFerngWang0e767992021-03-31 22:08:45 +08006983 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6984 PersistableBundle c = configManager.getConfigForSubId(subId);
6985 boolean requireUssd = c.getBoolean(
6986 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006987
Shuo Qian4a594052020-01-23 11:59:30 -08006988 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006989 if (requireUssd) {
6990 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6991 getSubscriptionCarrierId(subId));
6992 String newUssdCommand = "";
6993 try {
6994 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006995 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006996 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6997 } catch (NullPointerException e) {
6998 loge("Failed to generate USSD number" + e);
6999 }
7000 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7001 mMainThreadHandler, callback, carrierXmlParser,
7002 CarrierXmlParser.SsEntry.SSAction.QUERY);
7003 final String ussdCommand = newUssdCommand;
7004 Executors.newSingleThreadExecutor().execute(() -> {
7005 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7006 });
7007 } else {
7008 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
7009 callback::accept);
7010 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
7011 }
Shuo Qian4a594052020-01-23 11:59:30 -08007012 } finally {
7013 Binder.restoreCallingIdentity(identity);
7014 }
7015 }
7016
7017 /**
Hall Liu27d24262020-09-18 19:04:59 -07007018 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007019 */
7020 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007021 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007022 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007023
7024 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7025 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus");
7026
Shuo Qian4a594052020-01-23 11:59:30 -08007027 long identity = Binder.clearCallingIdentity();
7028 try {
Hall Liu27d24262020-09-18 19:04:59 -07007029 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
7030
7031 Phone phone = getPhone(subId);
7032 if (phone == null) {
7033 try {
7034 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7035 } catch (RemoteException e) {
7036 // ignore
7037 }
7038 return;
7039 }
7040
SongFerngWang0e767992021-03-31 22:08:45 +08007041 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7042 PersistableBundle c = configManager.getConfigForSubId(subId);
7043 boolean requireUssd = c.getBoolean(
7044 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007045
SongFerngWang0e767992021-03-31 22:08:45 +08007046 if (DBG) log("getCallWaitingStatus: subId " + subId);
7047 if (requireUssd) {
7048 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7049 getSubscriptionCarrierId(subId));
7050 CarrierXmlParser.SsEntry.SSAction ssAction =
7051 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
7052 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
7053 String newUssdCommand = "";
7054 try {
7055 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007056 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007057 .makeCommand(ssAction, null);
7058 } catch (NullPointerException e) {
7059 loge("Failed to generate USSD number" + e);
7060 }
7061 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7062 mMainThreadHandler, callback, carrierXmlParser, ssAction);
7063 final String ussdCommand = newUssdCommand;
7064 Executors.newSingleThreadExecutor().execute(() -> {
7065 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7066 });
7067 } else {
7068 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
7069 FunctionalUtils.ignoreRemoteException(callback::accept));
7070
7071 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
7072 }
Shuo Qian4a594052020-01-23 11:59:30 -08007073 } finally {
7074 Binder.restoreCallingIdentity(identity);
7075 }
7076 }
7077
7078 /**
yinxub1bed742017-04-17 11:45:04 -07007079 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07007080 *
yinxub1bed742017-04-17 11:45:04 -07007081 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007082 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
7083 * location related information which will be sent if the caller already possess
7084 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07007085 * @param request contains the radio access networks with bands/channels to scan
7086 * @param messenger callback messenger for scan results or errors
7087 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07007088 * @return the id of the requested scan which can be used to stop the scan.
7089 */
7090 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007091 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
7092 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007093 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007094 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7095 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08007096 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007097 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
7098 if (!renounceFineLocationAccess) {
7099 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007100 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7101 .setCallingPackage(callingPackage)
7102 .setCallingFeatureId(callingFeatureId)
7103 .setCallingPid(Binder.getCallingPid())
7104 .setCallingUid(Binder.getCallingUid())
7105 .setMethod("requestNetworkScan")
7106 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7107 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7108 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7109 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007110 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08007111 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07007112 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
7113 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08007114 if (e != null) {
7115 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
7116 throw e;
7117 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07007118 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08007119 return TelephonyScanManager.INVALID_SCAN_ID;
7120 }
7121 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007122 }
joonhunshin4ac60942023-11-15 15:23:39 +00007123
7124 enforceTelephonyFeatureWithException(callingPackage,
7125 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan");
7126
Hall Liu912dfd32019-04-25 14:02:26 -07007127 int callingUid = Binder.getCallingUid();
7128 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07007129 final long identity = Binder.clearCallingIdentity();
7130 try {
7131 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07007132 renounceFineLocationAccess, request, messenger, binder,
7133 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07007134 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07007135 } finally {
7136 Binder.restoreCallingIdentity(identity);
7137 }
yinxu504e1392017-04-12 16:03:22 -07007138 }
7139
Hall Liub2ac8ef2019-02-28 15:56:23 -08007140 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07007141 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00007142 boolean hasCarrierPriv;
7143 final long identity = Binder.clearCallingIdentity();
7144 try {
7145 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
7146 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
7147 } finally {
7148 Binder.restoreCallingIdentity(identity);
7149 }
Hall Liu558027f2019-05-15 19:14:05 -07007150 boolean hasNetworkScanPermission =
7151 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007152 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07007153
7154 if (!hasCarrierPriv && !hasNetworkScanPermission) {
7155 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
7156 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08007157 }
7158
7159 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
7160 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08007161 if (ras.getChannels() != null && ras.getChannels().length > 0) {
7162 return new SecurityException("Specific channels must not be"
7163 + " scanned without location access.");
7164 }
7165 }
7166 }
7167
Hall Liub2ac8ef2019-02-28 15:56:23 -08007168 return null;
7169 }
7170
yinxu504e1392017-04-12 16:03:22 -07007171 /**
7172 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07007173 *
7174 * @param subId id of the subscription
7175 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07007176 */
7177 @Override
7178 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007179 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7180 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007181
Hall Liu912dfd32019-04-25 14:02:26 -07007182 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007183 final long identity = Binder.clearCallingIdentity();
7184 try {
Hall Liu912dfd32019-04-25 14:02:26 -07007185 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007186 } finally {
7187 Binder.restoreCallingIdentity(identity);
7188 }
yinxu504e1392017-04-12 16:03:22 -07007189 }
7190
7191 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08007192 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07007193 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08007194 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07007195 */
7196 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08007197 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08007198 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007199 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08007200 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007201
joonhunshin4ac60942023-11-15 15:23:39 +00007202 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7203 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask");
7204
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007205 final long identity = Binder.clearCallingIdentity();
7206 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007207 if (DBG) log("getAllowedNetworkTypesBitmask");
7208 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
7209 int networkTypesBitmask = (result != null ? result[0] : -1);
7210 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
7211 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007212 } finally {
7213 Binder.restoreCallingIdentity(identity);
7214 }
Jake Hamby7c27be32014-03-03 13:25:59 -08007215 }
7216
7217 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007218 * Get the allowed network types for certain reason.
7219 *
7220 * @param subId the id of the subscription.
7221 * @param reason the reason the allowed network type change is taking place
7222 * @return the allowed network types.
7223 */
7224 @Override
7225 public long getAllowedNetworkTypesForReason(int subId,
7226 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07007227 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007228 mApp, subId, "getAllowedNetworkTypesForReason");
joonhunshin4ac60942023-11-15 15:23:39 +00007229
7230 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7231 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesForReason");
7232
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007233 final long identity = Binder.clearCallingIdentity();
7234 try {
Jack Yu7247ac82023-03-02 23:52:10 -08007235 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007236 } finally {
7237 Binder.restoreCallingIdentity(identity);
7238 }
7239 }
7240
7241 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07007242 * Enable/Disable E-UTRA-NR Dual Connectivity
7243 * @param subId subscription id of the sim card
7244 * @param nrDualConnectivityState expected NR dual connectivity state
7245 * This can be passed following states
7246 * <ol>
7247 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
7248 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
7249 * <li>Disable NR dual connectivity and force secondary cell to be released
7250 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
7251 * </ol>
7252 * @return operation result.
7253 */
7254 @Override
7255 public int setNrDualConnectivityState(int subId,
7256 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
7257 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7258 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007259 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007260 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7261 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
7262 }
7263
Sooraj Sasindran37444802020-08-11 10:40:43 -07007264 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7265 final long identity = Binder.clearCallingIdentity();
7266 try {
7267 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
7268 nrDualConnectivityState, subId,
7269 workSource);
7270 if (DBG) log("enableNRDualConnectivity result: " + result);
7271 return result;
7272 } finally {
7273 Binder.restoreCallingIdentity(identity);
7274 }
7275 }
7276
7277 /**
7278 * Is E-UTRA-NR Dual Connectivity enabled
7279 * @return true if dual connectivity is enabled else false
7280 */
7281 @Override
7282 public boolean isNrDualConnectivityEnabled(int subId) {
7283 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007284 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07007285 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007286 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007287 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7288 return false;
7289 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07007290 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7291 final long identity = Binder.clearCallingIdentity();
7292 try {
7293 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
7294 null, subId, workSource);
7295 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
7296 return isEnabled;
7297 } finally {
7298 Binder.restoreCallingIdentity(identity);
7299 }
7300 }
7301
7302 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007303 * Set the allowed network types of the device and
7304 * provide the reason triggering the allowed network change.
7305 *
7306 * @param subId the id of the subscription.
7307 * @param reason the reason the allowed network type change is taking place
7308 * @param allowedNetworkTypes the allowed network types.
7309 * @return true on success; false on any failure.
7310 */
7311 @Override
7312 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08007313 @TelephonyManager.AllowedNetworkTypesReason int reason,
7314 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007315 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7316 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007317 // If the caller only has carrier privileges, then they should not be able to override
7318 // any network types which were set for security reasons.
7319 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
7320 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007321 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007322 throw new SecurityException(
7323 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007324 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007325 }
joonhunshin4ac60942023-11-15 15:23:39 +00007326
7327 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7328 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason");
7329
SongFerngWang3ef3e072020-12-21 16:41:52 +08007330 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007331 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08007332 return false;
7333 }
7334 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
7335 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007336 return false;
7337 }
7338
Jack Yu5b494332023-01-23 18:18:04 +00007339 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
7340 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007341
Jack Yue37dd262022-12-16 11:53:37 -08007342 Phone phone = getPhone(subId);
7343 if (phone == null) {
7344 return false;
7345 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007346
Jack Yue37dd262022-12-16 11:53:37 -08007347 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007348 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007349 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08007350 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007351
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007352 final long identity = Binder.clearCallingIdentity();
7353 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007354 Boolean success = (Boolean) sendRequest(
7355 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
7356 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
7357
7358 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
7359 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007360 } finally {
7361 Binder.restoreCallingIdentity(identity);
7362 }
7363 }
7364
7365 /**
Miaoa84611c2019-03-15 09:21:10 +08007366 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08007367 *
Miaoa84611c2019-03-15 09:21:10 +08007368 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07007369 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08007370 * @hide
7371 */
7372 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08007373 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007374 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007375
7376 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7377 PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber");
7378
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007379 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08007380 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007381 try {
Miaoa84611c2019-03-15 09:21:10 +08007382 if (phone != null) {
7383 return phone.hasMatchedTetherApnSetting();
7384 } else {
7385 return false;
7386 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007387 } finally {
7388 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007389 }
Junda Liu475951f2014-11-07 16:45:03 -08007390 }
7391
7392 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007393 * Get the user enabled state of Mobile Data.
7394 *
7395 * TODO: remove and use isUserDataEnabled.
7396 * This can't be removed now because some vendor codes
7397 * calls through ITelephony directly while they should
7398 * use TelephonyManager.
7399 *
7400 * @return true on enabled
7401 */
7402 @Override
7403 public boolean getDataEnabled(int subId) {
7404 return isUserDataEnabled(subId);
7405 }
7406
7407 /**
7408 * Get whether mobile data is enabled per user setting.
7409 *
7410 * There are other factors deciding whether mobile data is actually enabled, but they are
7411 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007412 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007413 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7414 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007415 *
7416 * @return {@code true} if data is enabled else {@code false}
7417 */
7418 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007419 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007420 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007421 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007422 try {
7423 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7424 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007425 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007426 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7427 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007428 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007429 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007430 mApp, subId, functionName);
7431
Robert Greenwalt646120a2014-05-23 11:54:03 -07007432 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007433
7434 final long identity = Binder.clearCallingIdentity();
7435 try {
Jack Yu285100e2022-12-02 22:48:35 -08007436 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007437 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7438 Phone phone = PhoneFactory.getPhone(phoneId);
7439 if (phone != null) {
7440 boolean retVal = phone.isUserDataEnabled();
7441 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7442 return retVal;
7443 } else {
7444 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7445 return false;
7446 }
7447 } finally {
7448 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007449 }
7450 }
7451
7452 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007453 * Checks if the device is capable of mobile data by considering whether whether the
7454 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7455 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007456 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007457 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007458 */
7459 @Override
7460 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007461 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007462 try {
7463 try {
7464 mApp.enforceCallingOrSelfPermission(
7465 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007466 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007467 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007468 try {
7469 mApp.enforceCallingOrSelfPermission(
7470 android.Manifest.permission.READ_PHONE_STATE,
7471 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007472 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007473 mApp.enforceCallingOrSelfPermission(
7474 permission.READ_BASIC_PHONE_STATE, functionName);
7475 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007476 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007477 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007478 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007479 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007480
joonhunshin4ac60942023-11-15 15:23:39 +00007481 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7482 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled");
7483
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007484 final long identity = Binder.clearCallingIdentity();
7485 try {
Jack Yu285100e2022-12-02 22:48:35 -08007486 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007487 Phone phone = PhoneFactory.getPhone(phoneId);
7488 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007489 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007490 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007491 return retVal;
7492 } else {
7493 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7494 return false;
7495 }
7496 } finally {
7497 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007498 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007499 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007500
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007501 /**
7502 * Check if data is enabled for a specific reason
7503 * @param subId Subscription index
7504 * @param reason the reason the data enable change is taking place
7505 * @return {@code true} if the overall data is enabled; {@code false} if not.
7506 */
7507 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007508 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007509 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007510 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007511 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007512 try {
7513 mApp.enforceCallingOrSelfPermission(
7514 android.Manifest.permission.ACCESS_NETWORK_STATE,
7515 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007516 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007517 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7518 functionName);
7519 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007520 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007521 try {
7522 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007523 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007524 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007525 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007526 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007527 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007528 }
7529
joonhunshin4ac60942023-11-15 15:23:39 +00007530 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7531 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007532
7533 final long identity = Binder.clearCallingIdentity();
7534 try {
Jack Yu285100e2022-12-02 22:48:35 -08007535 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007536 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007537 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007538 + " reason=" + reason);
7539 }
7540 Phone phone = PhoneFactory.getPhone(phoneId);
7541 if (phone != null) {
7542 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007543 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007544 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007545 return retVal;
7546 } else {
7547 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007548 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007549 + subId + " retVal=false");
7550 }
7551 return false;
7552 }
7553 } finally {
7554 Binder.restoreCallingIdentity(identity);
7555 }
7556 }
7557
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007558 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007559 public int getCarrierPrivilegeStatus(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00007560 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7561 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus");
7562
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007563 // No permission needed; this only lets the caller inspect their own status.
7564 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007565 }
Junda Liu29340342014-07-10 15:23:27 -07007566
7567 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007568 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007569 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
joonhunshin4ac60942023-11-15 15:23:39 +00007570
7571 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7572 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatusForUid");
7573
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007574 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7575 }
7576
7577 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7578 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007579 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007580 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007581 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7582 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007583 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7584 if (cpt == null) {
7585 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007586 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7587 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007588 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007589 }
7590
7591 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007592 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007593 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
joonhunshin4ac60942023-11-15 15:23:39 +00007594
7595 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7596 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage");
7597
chen xuf7e9fe82019-05-09 19:31:02 -07007598 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007599 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007600 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007601 Phone phone = getPhone(subId);
7602 if (phone == null) {
7603 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7604 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7605 }
7606 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7607 if (cpt == null) {
7608 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007609 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7610 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007611 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007612 }
7613
7614 @Override
7615 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007616 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007617
7618 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7619 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7620 "checkCarrierPrivilegesForPackageAnyPhone");
7621
Rambo Wange7209ce2022-02-23 13:41:02 -08007622 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7623 }
7624
7625 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007626 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007627 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007628 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007629 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007630 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7631 Phone phone = PhoneFactory.getPhone(phoneId);
7632 if (phone == null) {
7633 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007634 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007635 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7636 if (cpt == null) {
7637 continue;
7638 }
7639 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007640 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7641 break;
7642 }
7643 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007644 return result;
Junda Liu29340342014-07-10 15:23:27 -07007645 }
Derek Tan89e89d42014-07-08 17:00:10 -07007646
7647 @Override
Junda Liue64de782015-04-16 17:19:16 -07007648 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007649 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007650
7651 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7652 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7653 "getCarrierPackageNamesForIntentAndPhone");
7654
Rambo Wang8a247eb2022-02-08 21:11:18 +00007655 Phone phone = PhoneFactory.getPhone(phoneId);
7656 if (phone == null) {
7657 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007658 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007659 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7660 if (cpt == null) {
7661 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007662 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007663 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007664 }
7665
Amith Yamasani6e118872016-02-19 12:53:51 -08007666 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007667 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007668 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007669 Phone phone = PhoneFactory.getPhone(phoneId);
7670 if (phone == null) {
7671 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007672 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007673 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7674 if (cpt == null) {
7675 return Collections.emptyList();
7676 }
7677 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007678 }
7679
chen xuf7e9fe82019-05-09 19:31:02 -07007680 @Override
7681 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007682 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
joonhunshin4ac60942023-11-15 15:23:39 +00007683
7684 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7685 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7686 "getPackagesWithCarrierPrivilegesForAllPhones");
7687
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007688 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007689 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007690 try {
7691 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7692 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7693 }
7694 } finally {
7695 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007696 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007697 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007698 }
7699
Rambo Wang6812ffb2022-03-15 16:54:17 -07007700 @Override
7701 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7702 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7703
joonhunshin4ac60942023-11-15 15:23:39 +00007704 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7705 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7706 "getCarrierServicePackageNameForLogicalSlot");
7707
Rambo Wang6812ffb2022-03-15 16:54:17 -07007708 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7709 if (phone == null) {
7710 return null;
7711 }
7712 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7713 if (cpt == null) {
7714 return null;
7715 }
7716 return cpt.getCarrierServicePackageName();
7717 }
7718
Wink Savilleb564aae2014-10-23 10:18:09 -07007719 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007720 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007721 UiccPort port = phone == null ? null : phone.getUiccPort();
7722 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007723 return null;
7724 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007725 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007726 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007727 return null;
7728 }
7729 return iccId;
7730 }
7731
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007732 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007733 public void setCallComposerStatus(int subId, int status) {
7734 enforceModifyPermission();
7735
joonhunshin4ac60942023-11-15 15:23:39 +00007736 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7737 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus");
7738
Shuo Qiane4e11672020-12-15 22:15:33 -08007739 final long identity = Binder.clearCallingIdentity();
7740 try {
7741 Phone phone = getPhone(subId);
7742 if (phone != null) {
7743 Phone defaultPhone = phone.getImsPhone();
7744 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7745 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7746 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007747 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7748 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007749 }
7750 }
Shuo Qian284ae752020-12-22 19:10:14 -08007751 } catch (ImsException e) {
7752 throw new ServiceSpecificException(e.getCode());
7753 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007754 Binder.restoreCallingIdentity(identity);
7755 }
7756 }
7757
7758 @Override
7759 public int getCallComposerStatus(int subId) {
7760 enforceReadPrivilegedPermission("getCallComposerStatus");
7761
joonhunshin4ac60942023-11-15 15:23:39 +00007762 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7763 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus");
7764
Shuo Qiane4e11672020-12-15 22:15:33 -08007765 final long identity = Binder.clearCallingIdentity();
7766 try {
7767 Phone phone = getPhone(subId);
7768 if (phone != null) {
7769 Phone defaultPhone = phone.getImsPhone();
7770 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7771 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7772 return imsPhone.getCallComposerStatus();
7773 }
7774 }
7775 } finally {
7776 Binder.restoreCallingIdentity(identity);
7777 }
7778 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7779 }
7780
7781 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007782 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7783 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007784 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007785 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007786
joonhunshin4ac60942023-11-15 15:23:39 +00007787 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7788 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7789 "setLine1NumberForDisplayForSubscriber");
7790
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007791 final long identity = Binder.clearCallingIdentity();
7792 try {
7793 final String iccId = getIccId(subId);
7794 final Phone phone = getPhone(subId);
7795 if (phone == null) {
7796 return false;
7797 }
7798 final String subscriberId = phone.getSubscriberId();
7799
7800 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007801 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007802 + subscriberId + " to " + number);
7803 }
7804
7805 if (TextUtils.isEmpty(iccId)) {
7806 return false;
7807 }
7808
7809 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7810
7811 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7812 if (alphaTag == null) {
7813 editor.remove(alphaTagPrefKey);
7814 } else {
7815 editor.putString(alphaTagPrefKey, alphaTag);
7816 }
7817
7818 // Record both the line number and IMSI for this ICCID, since we need to
7819 // track all merged IMSIs based on line number
7820 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7821 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7822 if (number == null) {
7823 editor.remove(numberPrefKey);
7824 editor.remove(subscriberPrefKey);
7825 } else {
7826 editor.putString(numberPrefKey, number);
7827 editor.putString(subscriberPrefKey, subscriberId);
7828 }
7829
7830 editor.commit();
7831 return true;
7832 } finally {
7833 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007834 }
Derek Tan7226c842014-07-02 17:42:23 -07007835 }
7836
7837 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007838 public String getLine1NumberForDisplay(int subId, String callingPackage,
7839 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007840 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007841 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007842 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007843 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007844 return null;
7845 }
Derek Tan97ebb422014-09-05 16:55:38 -07007846
joonhunshin4ac60942023-11-15 15:23:39 +00007847 enforceTelephonyFeatureWithException(callingPackage,
7848 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay");
7849
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007850 final long identity = Binder.clearCallingIdentity();
7851 try {
7852 String iccId = getIccId(subId);
7853 if (iccId != null) {
7854 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7855 if (DBG_MERGE) {
7856 log("getLine1NumberForDisplay returning "
7857 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7858 }
7859 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007860 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007861 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7862 return null;
7863 } finally {
7864 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007865 }
Derek Tan7226c842014-07-02 17:42:23 -07007866 }
7867
7868 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007869 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7870 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007871 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007872 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007873 return null;
7874 }
Derek Tan97ebb422014-09-05 16:55:38 -07007875
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007876 final long identity = Binder.clearCallingIdentity();
7877 try {
7878 String iccId = getIccId(subId);
7879 if (iccId != null) {
7880 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7881 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7882 }
7883 return null;
7884 } finally {
7885 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007886 }
Derek Tan7226c842014-07-02 17:42:23 -07007887 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007888
7889 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007890 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7891 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007892 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7893 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007894 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007895 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007896 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007897 return null;
7898 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007899
Jordan Liub49b04b2019-05-06 14:45:15 -07007900 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7901 // the process, where TelephonyManager was instantiated.
7902 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007903 final long identity = Binder.clearCallingIdentity();
7904 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007905 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007906 final TelephonyManager tele = TelephonyManager.from(context);
7907 final SubscriptionManager sub = SubscriptionManager.from(context);
7908
7909 // Figure out what subscribers are currently active
7910 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007911
Jordan Liub49b04b2019-05-06 14:45:15 -07007912 // Only consider subs which match the current subId
7913 // This logic can be simplified. See b/131189269 for progress.
7914 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007915 activeSubscriberIds.add(tele.getSubscriberId(subId));
7916 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007917
7918 // First pass, find a number override for an active subscriber
7919 String mergeNumber = null;
7920 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7921 for (String key : prefs.keySet()) {
7922 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7923 final String subscriberId = (String) prefs.get(key);
7924 if (activeSubscriberIds.contains(subscriberId)) {
7925 final String iccId = key.substring(
7926 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7927 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7928 mergeNumber = (String) prefs.get(numberKey);
7929 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007930 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007931 + " for active subscriber " + subscriberId);
7932 }
7933 if (!TextUtils.isEmpty(mergeNumber)) {
7934 break;
7935 }
7936 }
7937 }
7938 }
7939
7940 // Shortcut when no active merged subscribers
7941 if (TextUtils.isEmpty(mergeNumber)) {
7942 return null;
7943 }
7944
7945 // Second pass, find all subscribers under that line override
7946 final ArraySet<String> result = new ArraySet<>();
7947 for (String key : prefs.keySet()) {
7948 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7949 final String number = (String) prefs.get(key);
7950 if (mergeNumber.equals(number)) {
7951 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7952 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7953 final String subscriberId = (String) prefs.get(subscriberKey);
7954 if (!TextUtils.isEmpty(subscriberId)) {
7955 result.add(subscriberId);
7956 }
7957 }
7958 }
7959 }
7960
7961 final String[] resultArray = result.toArray(new String[result.size()]);
7962 Arrays.sort(resultArray);
7963 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007964 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007965 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7966 }
7967 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007968 } finally {
7969 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007970 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007971 }
7972
7973 @Override
zoey chen38003472019-12-13 17:16:31 +08007974 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7975 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007976
joonhunshin4ac60942023-11-15 15:23:39 +00007977 enforceTelephonyFeatureWithException(callingPackage,
7978 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup");
7979
Malcolm Chen6ca97372019-07-01 16:28:21 -07007980 final long identity = Binder.clearCallingIdentity();
7981 try {
7982 final TelephonyManager telephonyManager = mApp.getSystemService(
7983 TelephonyManager.class);
7984 String subscriberId = telephonyManager.getSubscriberId(subId);
7985 if (subscriberId == null) {
7986 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007987 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007988 + subId);
7989 }
7990 return null;
7991 }
7992
Jack Yu3beaf9d2023-04-14 09:17:27 -07007993 final SubscriptionInfo info = getSubscriptionManagerService()
7994 .getSubscriptionInfo(subId);
7995 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07007996 // If it doesn't belong to any group, return just subscriberId of itself.
7997 if (groupUuid == null) {
7998 return new String[]{subscriberId};
7999 }
8000
8001 // Get all subscriberIds from the group.
8002 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07008003 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
8004 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
8005 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07008006 for (SubscriptionInfo subInfo : groupInfos) {
8007 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
8008 if (subscriberId != null) {
8009 mergedSubscriberIds.add(subscriberId);
8010 }
8011 }
8012
8013 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
8014 } finally {
8015 Binder.restoreCallingIdentity(identity);
8016
8017 }
8018 }
8019
8020 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008021 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008022 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08008023 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008024
joonhunshin4ac60942023-11-15 15:23:39 +00008025 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8026 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride");
8027
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008028 final long identity = Binder.clearCallingIdentity();
8029 try {
8030 final Phone phone = getPhone(subId);
8031 return phone == null ? false : phone.setOperatorBrandOverride(brand);
8032 } finally {
8033 Binder.restoreCallingIdentity(identity);
8034 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07008035 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05008036
8037 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008038 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008039 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
8040 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008041 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
8042 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008043
8044 final long identity = Binder.clearCallingIdentity();
8045 try {
8046 final Phone phone = getPhone(subId);
8047 if (phone == null) {
8048 return false;
8049 }
8050 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
8051 cdmaNonRoamingList);
8052 } finally {
8053 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008054 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008055 }
8056
8057 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07008058 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008059 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08008060 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008061 if (phone == null) {
8062 return raf;
8063 }
8064
Shuo Qiandee53402020-05-29 14:08:15 -07008065 try {
8066 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008067 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07008068 mApp, phone.getSubId(), "getRadioAccessFamily");
8069 } catch (SecurityException e) {
8070 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
8071 throw e;
8072 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008073
joonhunshin4ac60942023-11-15 15:23:39 +00008074 enforceTelephonyFeatureWithException(callingPackage,
8075 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily");
8076
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008077 final long identity = Binder.clearCallingIdentity();
8078 try {
chen xub97461a2018-10-26 14:17:57 -07008079 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008080 } finally {
8081 Binder.restoreCallingIdentity(identity);
8082 }
chen xub97461a2018-10-26 14:17:57 -07008083 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07008084 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008085
8086 @Override
Hall Liu82694d52020-12-11 18:22:04 -08008087 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08008088 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08008089 try {
8090 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
8091 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008092 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008093 }
8094 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008095 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008096 }
joonhunshin4ac60942023-11-15 15:23:39 +00008097
8098 enforceTelephonyFeatureWithException(callingPackage,
8099 PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture");
8100
Hall Liu82694d52020-12-11 18:22:04 -08008101 RoleManager rm = mApp.getSystemService(RoleManager.class);
8102 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
8103 if (!dialerRoleHolders.contains(callingPackage)) {
8104 throw new SecurityException("App must be the dialer role holder to"
8105 + " upload a call composer pic");
8106 }
8107
8108 Executors.newSingleThreadExecutor().execute(() -> {
8109 ByteArrayOutputStream output = new ByteArrayOutputStream(
8110 (int) TelephonyManager.getMaximumCallComposerPictureSize());
8111 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
8112 boolean readUntilEnd = false;
8113 int totalBytesRead = 0;
8114 byte[] buffer = new byte[16 * 1024];
8115 while (true) {
8116 int numRead;
8117 try {
8118 numRead = input.read(buffer);
8119 } catch (IOException e) {
8120 try {
8121 fd.checkError();
8122 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
8123 null);
8124 } catch (IOException e1) {
8125 // This means that the other side closed explicitly with an error. If this
8126 // happens, log and ignore.
8127 loge("Remote end of call composer picture pipe closed: " + e1);
8128 }
8129 break;
8130 }
8131 if (numRead == -1) {
8132 readUntilEnd = true;
8133 break;
8134 }
8135 totalBytesRead += numRead;
8136 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
8137 loge("Too many bytes read for call composer picture: " + totalBytesRead);
8138 try {
8139 input.close();
8140 } catch (IOException e) {
8141 // ignore
8142 }
8143 break;
8144 }
8145 output.write(buffer, 0, numRead);
8146 }
8147 // Generally, the remote end will close the file descriptors. The only case where we
8148 // close is above, where the picture size is too big.
8149
8150 try {
8151 fd.checkError();
8152 } catch (IOException e) {
8153 loge("Remote end for call composer closed with an error: " + e);
8154 return;
8155 }
8156
Hall Liuaa4211e2021-01-20 15:43:39 -08008157 if (!readUntilEnd) {
8158 loge("Did not finish reading entire image; aborting");
8159 return;
8160 }
Hall Liu82694d52020-12-11 18:22:04 -08008161
Hall Liuaa4211e2021-01-20 15:43:39 -08008162 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
8163 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
8164 new CallComposerPictureTransfer.Factory() {},
8165 imageData,
8166 (result) -> {
8167 if (result.first != null) {
8168 ParcelUuid parcelUuid = new ParcelUuid(result.first);
8169 Bundle outputResult = new Bundle();
8170 outputResult.putParcelable(
8171 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
8172 callback.send(TelephonyManager.CallComposerException.SUCCESS,
8173 outputResult);
8174 } else {
8175 callback.send(result.second, null);
8176 }
8177 }
8178 );
Hall Liu82694d52020-12-11 18:22:04 -08008179 });
8180 }
8181
8182 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07008183 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008184 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07008185 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008186
joonhunshin4ac60942023-11-15 15:23:39 +00008187 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8188 PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling");
8189
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008190 final long identity = Binder.clearCallingIdentity();
8191 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008192 ImsManager.getInstance(defaultPhone.getContext(),
8193 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008194 } finally {
8195 Binder.restoreCallingIdentity(identity);
8196 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008197 }
8198
8199 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008200 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008201 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008202 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
8203 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00008204 return false;
8205 }
Svet Ganovb320e182015-04-16 12:30:10 -07008206
joonhunshin4ac60942023-11-15 15:23:39 +00008207 enforceTelephonyFeatureWithException(callingPackage,
8208 PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled");
8209
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008210 final long identity = Binder.clearCallingIdentity();
8211 try {
8212 // Check the user preference and the system-level IMS setting. Even if the user has
8213 // enabled video calling, if IMS is disabled we aren't able to support video calling.
8214 // In the long run, we may instead need to check if there exists a connection service
8215 // which can support video calling.
8216 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008217 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008218 return imsManager.isVtEnabledByPlatform()
8219 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
8220 && imsManager.isVtEnabledByUser();
8221 } finally {
8222 Binder.restoreCallingIdentity(identity);
8223 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008224 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06008225
Andrew Leea1239f22015-03-02 17:44:07 -08008226 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008227 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
8228 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008229 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008230 mApp, subId, callingPackage, callingFeatureId,
8231 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008232 return false;
8233 }
8234
joonhunshin4ac60942023-11-15 15:23:39 +00008235 enforceTelephonyFeatureWithException(callingPackage,
8236 PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength");
8237
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008238 final long identity = Binder.clearCallingIdentity();
8239 try {
8240 CarrierConfigManager configManager =
8241 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008242 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008243 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
8244 } finally {
8245 Binder.restoreCallingIdentity(identity);
8246 }
Andrew Leea1239f22015-03-02 17:44:07 -08008247 }
8248
8249 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008250 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008251 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008252 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008253 return false;
8254 }
8255
joonhunshin4ac60942023-11-15 15:23:39 +00008256 enforceTelephonyFeatureWithException(callingPackage,
8257 PackageManager.FEATURE_TELEPHONY, "isWorldPhone");
8258
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008259 final long identity = Binder.clearCallingIdentity();
8260 try {
8261 CarrierConfigManager configManager =
8262 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008263 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008264 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
8265 } finally {
8266 Binder.restoreCallingIdentity(identity);
8267 }
Andrew Leea1239f22015-03-02 17:44:07 -08008268 }
8269
Andrew Lee9431b832015-03-09 18:46:45 -07008270 @Override
8271 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008272 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08008273 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07008274 }
8275
8276 @Override
8277 public boolean isHearingAidCompatibilitySupported() {
joonhunshin4ac60942023-11-15 15:23:39 +00008278 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8279 PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported");
8280
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008281 final long identity = Binder.clearCallingIdentity();
8282 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008283 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008284 } finally {
8285 Binder.restoreCallingIdentity(identity);
8286 }
Andrew Lee9431b832015-03-09 18:46:45 -07008287 }
8288
Hall Liuf6668912018-10-31 17:05:23 -07008289 /**
8290 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
8291 * support for the feature and device firmware support.
8292 *
8293 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
8294 */
8295 @Override
8296 public boolean isRttSupported(int subscriptionId) {
joonhunshin4ac60942023-11-15 15:23:39 +00008297 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8298 PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported");
8299
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008300 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008301 final Phone phone = getPhone(subscriptionId);
8302 if (phone == null) {
8303 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
8304 return false;
8305 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008306 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008307 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008308 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
joonhunshin4ac60942023-11-15 15:23:39 +00008309 boolean isDeviceSupported = (phone.getContext().getResources() != null)
8310 ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt)
8311 : false;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008312 return isCarrierSupported && isDeviceSupported;
8313 } finally {
8314 Binder.restoreCallingIdentity(identity);
8315 }
Hall Liu98187582018-01-22 19:15:32 -08008316 }
8317
Hall Liuf6668912018-10-31 17:05:23 -07008318 /**
Hall Liuf2daa022019-07-23 18:39:00 -07008319 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
8320 * RTT setting, will return true if the device and carrier both support RTT.
8321 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07008322 */
8323 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008324 final long identity = Binder.clearCallingIdentity();
8325 try {
joonhunshin4ac60942023-11-15 15:23:39 +00008326 if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) {
8327 if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
8328 return false;
8329 }
8330 }
8331
Hall Liu5bab75c2019-12-11 23:58:20 +00008332 boolean isRttSupported = isRttSupported(subscriptionId);
8333 boolean isUserRttSettingOn = Settings.Secure.getInt(
8334 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
8335 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
8336 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
8337 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008338 } finally {
8339 Binder.restoreCallingIdentity(identity);
8340 }
Hall Liu3ad5f012018-04-06 16:23:39 -07008341 }
8342
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008343 @Deprecated
8344 @Override
8345 public String getDeviceId(String callingPackage) {
8346 return getDeviceIdWithFeature(callingPackage, null);
8347 }
8348
Sanket Padawe7310cc72015-01-14 09:53:20 -08008349 /**
8350 * Returns the unique device ID of phone, for example, the IMEI for
8351 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
8352 *
8353 * <p>Requires Permission:
8354 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
8355 */
8356 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008357 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07008358 try {
8359 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
8360 } catch (SecurityException se) {
8361 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
8362 throw new SecurityException("Package " + callingPackage + " does not belong to "
8363 + Binder.getCallingUid());
8364 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008365 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008366 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008367 return null;
8368 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008369 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008370 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008371 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008372 return null;
8373 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008374
8375 final long identity = Binder.clearCallingIdentity();
8376 try {
8377 return phone.getDeviceId();
8378 } finally {
8379 Binder.restoreCallingIdentity(identity);
8380 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008381 }
8382
Ping Sunc67b7c22016-03-02 19:16:45 +08008383 /**
8384 * {@hide}
8385 * Returns the IMS Registration Status on a particular subid
8386 *
8387 * @param subId
8388 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008389 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008390 Phone phone = getPhone(subId);
8391 if (phone != null) {
8392 return phone.isImsRegistered();
8393 } else {
8394 return false;
8395 }
8396 }
8397
Santos Cordon7a1885b2015-02-03 11:15:19 -08008398 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008399 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008400 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008401 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008402 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008403 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8404 }
8405 final long identity = Binder.clearCallingIdentity();
8406 try {
8407 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8408 } finally {
8409 Binder.restoreCallingIdentity(identity);
8410 }
8411 }
8412
8413 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008414 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008415 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008416 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008417 mApp,
8418 subscriptionId,
8419 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
8420 + subscriptionId);
joonhunshin4ac60942023-11-15 15:23:39 +00008421
8422 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8423 PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId");
8424
Tyler Gunnf70ed162019-04-03 15:28:53 -07008425 final long identity = Binder.clearCallingIdentity();
8426 try {
8427 Phone phone = getPhone(subscriptionId);
8428 if (phone == null) {
8429 return null;
8430 }
8431 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8432 } finally {
8433 Binder.restoreCallingIdentity(identity);
8434 }
8435 }
8436
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008437 /**
8438 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008439 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008440 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008441 final long identity = Binder.clearCallingIdentity();
8442 try {
8443 Phone phone = getPhone(subId);
8444 if (phone != null) {
8445 return phone.isWifiCallingEnabled();
8446 } else {
8447 return false;
8448 }
8449 } finally {
8450 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008451 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008452 }
8453
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008454 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008455 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008456 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008457 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008458 final long identity = Binder.clearCallingIdentity();
8459 try {
8460 Phone phone = getPhone(subId);
8461 if (phone != null) {
8462 return phone.isVideoEnabled();
8463 } else {
8464 return false;
8465 }
8466 } finally {
8467 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008468 }
8469 }
8470
8471 /**
8472 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8473 * defined in {@link ImsRegistrationImplBase}.
8474 */
8475 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008476 final long identity = Binder.clearCallingIdentity();
8477 try {
8478 Phone phone = getPhone(subId);
8479 if (phone != null) {
8480 return phone.getImsRegistrationTech();
8481 } else {
8482 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8483 }
8484 } finally {
8485 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008486 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008487 }
8488
Stuart Scott8eef64f2015-04-08 15:13:54 -07008489 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008490 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008491 enforceSettingsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008492
8493 enforceTelephonyFeatureWithException(callingPackage,
8494 PackageManager.FEATURE_TELEPHONY, "factoryReset");
8495
Stuart Scott981d8582015-04-21 14:09:50 -07008496 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8497 return;
8498 }
Kai Shif70f46f2021-03-03 13:59:46 -08008499 Phone defaultPhone = getDefaultPhone();
8500 if (defaultPhone != null) {
8501 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8502 mApp, getDefaultPhone().getSubId(), "factoryReset");
8503 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008504 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008505
Svet Ganovcc087f82015-05-12 20:35:54 -07008506 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008507 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8508 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008509 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008510 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008511 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008512 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008513 cleanUpAllowedNetworkTypes(phone, subId);
Rambo Wang71f6aa62024-02-23 20:16:22 +00008514 setDataRoamingEnabled(subId, phone == null ? false
8515 : phone.getDataSettingsManager().isDefaultDataRoamingEnabled());
Jordan Liu857e73a2021-03-05 16:24:04 -08008516 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008517 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008518 // There has been issues when Sms raw table somehow stores orphan
8519 // fragments. They lead to garbled message when new fragments come
8520 // in and combined with those stale ones. In case this happens again,
8521 // user can reset all network settings which will clean up this table.
8522 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008523 // Clean up IMS settings as well here.
8524 int slotId = getSlotIndex(subId);
8525 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
8526 ImsManager.getInstance(mApp, slotId).factoryReset();
8527 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008528
Kai Shif70f46f2021-03-03 13:59:46 -08008529 if (defaultPhone == null) {
8530 return;
8531 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008532 // Erase modem config if erase modem on network setting is enabled.
8533 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8534 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8535 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008536 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008537 }
Kai Shif70f46f2021-03-03 13:59:46 -08008538
8539 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008540 } finally {
8541 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008542 }
8543 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008544
SongFerngWangfd89b102021-05-27 22:44:54 +08008545 @VisibleForTesting
8546 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8547 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8548 return;
8549 }
8550 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8551 RILConstants.PREFERRED_NETWORK_MODE);
8552 SubscriptionManager.setSubscriptionProperty(subId,
8553 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8554 "user=" + defaultNetworkType);
8555 phone.loadAllowedNetworksFromSubscriptionDatabase();
8556 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8557 defaultNetworkType, null);
8558 }
8559
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008560 private void cleanUpSmsRawTable(Context context) {
8561 ContentResolver resolver = context.getContentResolver();
8562 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8563 resolver.delete(uri, null, null);
8564 }
8565
Narayan Kamath1c496c22015-04-16 14:40:19 +01008566 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008567 public String getSimLocaleForSubscriber(int subId) {
8568 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
joonhunshin4ac60942023-11-15 15:23:39 +00008569
8570 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8571 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber");
8572
chen xu5d3637b2019-01-21 23:31:38 -08008573 final Phone phone = getPhone(subId);
8574 if (phone == null) {
8575 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008576 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008577 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008578 final long identity = Binder.clearCallingIdentity();
8579 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008580 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
8581 phone.getContext().getOpPackageName(),
8582 phone.getContext().getAttributionTag());
8583 if (info == null) {
8584 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8585 return null;
chen xu6291c472019-02-04 12:55:53 -08008586 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008587 // Try and fetch the locale from the carrier properties or from the SIM language
8588 // preferences (EF-PL and EF-LI)...
8589 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008590 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008591 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8592 if (localeFromDefaultSim != null) {
8593 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8594 if (DBG) log("Using locale from subId: " + subId + " locale: "
8595 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008596 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008597 } else {
8598 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008599 }
8600 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008601
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008602 // The SIM language preferences only store a language (e.g. fr = French), not an
8603 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8604 // the SIM and carrier preferences does not include a country we add the country
8605 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008606 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008607 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008608 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008609 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008610 }
8611
8612 if (DBG) log("No locale found - returning null");
8613 return null;
8614 } finally {
8615 Binder.restoreCallingIdentity(identity);
8616 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008617 }
8618
tom hsu0b59d292022-09-29 23:49:21 +08008619 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008620 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008621 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008622 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008623 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008624 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8625 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008626 Locale.forLanguageTag(localeTag).getCountry())) {
8627 return localeTag;
8628 }
8629 }
8630 return inputLocale.toLanguageTag();
8631 }
8632
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008633 /**
8634 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8635 */
8636 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008637 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Ling Ma9fa67412023-11-13 14:13:19 -08008638 mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/);
Narayan Kamath1c496c22015-04-16 14:40:19 +01008639 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008640
Gary Jian3aa9a762022-01-24 16:41:19 +08008641 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8642 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008643
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008644 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008645 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8646 * representing the state of the modem.
8647 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008648 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8649 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008650 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008651 */
8652 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008653 public void requestModemActivityInfo(ResultReceiver result) {
8654 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008655
8656 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8657 PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo");
8658
vagdeviaf9a5b92018-08-15 16:01:53 -07008659 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008660
8661 final long identity = Binder.clearCallingIdentity();
8662 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008663 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008664 } finally {
8665 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008666 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008667 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008668
Gary Jian76280a42022-12-07 16:18:33 +08008669 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008670 // less than total activity duration.
8671 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8672 if (info == null) {
8673 return false;
8674 }
8675 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008676 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008677 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8678
Hall Liu49656c02020-10-09 19:00:11 -07008679 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8680
Siddharth Rayb8114062018-06-17 15:02:38 -07008681 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008682 && (info.getSleepTimeMillis() <= activityDurationMs)
8683 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008684 }
8685
Gary Jian3aa9a762022-01-24 16:41:19 +08008686 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8687 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8688 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8689 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8690
8691 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8692 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8693 }
8694
8695 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8696 mLastModemActivityInfo.setReceiveTimeMillis(
8697 rat,
8698 freq,
8699 info.getReceiveTimeMillis(rat, freq)
8700 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8701 }
8702
8703 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8704 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8705 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8706 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8707
8708 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8709 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8710 }
8711 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8712 mLastModemActivityInfo.setReceiveTimeMillis(
8713 rat,
8714 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8715 }
8716
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008717 /**
8718 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8719 * @param info recent ModemActivityInfo
8720 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008721 private void mergeModemActivityInfo(ModemActivityInfo info) {
8722 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008723 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008724 boolean matched;
8725 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8726 matched = false;
8727 int rat = info.getSpecificInfoRat(i);
8728 int freq = info.getSpecificInfoFrequencyRange(i);
8729 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8730 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8731 //if it already exists
8732 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8733 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8734 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8735 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8736 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8737 updateLastModemActivityInfo(info, rat, freq);
8738 matched = true;
8739 }
8740 } else {
8741 updateLastModemActivityInfo(info, rat);
8742 matched = true;
8743 }
8744 }
8745 }
8746
8747 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008748 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008749 new ActivityStatsTechSpecificInfo(
8750 rat,
8751 freq,
8752 info.getTransmitTimeMillis(rat, freq),
8753 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008754 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008755 }
8756 }
8757 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8758 mLastModemActivitySpecificInfo =
8759 new ActivityStatsTechSpecificInfo[merged.size()];
8760 merged.toArray(mLastModemActivitySpecificInfo);
8761
8762 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8763 mLastModemActivityInfo.setSleepTimeMillis(
8764 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008765 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008766 mLastModemActivityInfo.setIdleTimeMillis(
8767 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008768 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008769
8770 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008771 new ModemActivityInfo(
8772 mLastModemActivityInfo.getTimestampMillis(),
8773 mLastModemActivityInfo.getSleepTimeMillis(),
8774 mLastModemActivityInfo.getIdleTimeMillis(),
8775 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008776 }
8777
8778 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8779 ActivityStatsTechSpecificInfo[] info) {
8780 int infoSize = info.length;
8781 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8782 for (int i = 0; i < infoSize; i++) {
8783 ret[i] = new ActivityStatsTechSpecificInfo(
8784 info[i].getRat(), info[i].getFrequencyRange(),
8785 info[i].getTransmitTimeMillis(),
8786 (int) info[i].getReceiveTimeMillis());
8787 }
8788 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008789 }
8790
Jack Yu85bd38a2015-11-09 11:34:32 -08008791 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008792 * Returns the service state information on specified subscription.
8793 */
8794 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008795 public ServiceState getServiceStateForSubscriber(int subId,
8796 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8797 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008798 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008799 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008800 return null;
8801 }
8802
joonhunshin4ac60942023-11-15 15:23:39 +00008803 enforceTelephonyFeatureWithException(callingPackage,
8804 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber");
8805
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008806 boolean hasFinePermission = false;
8807 boolean hasCoarsePermission = false;
8808 if (!renounceFineLocationAccess) {
8809 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8810 LocationAccessPolicy.checkLocationPermission(mApp,
8811 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8812 .setCallingPackage(callingPackage)
8813 .setCallingFeatureId(callingFeatureId)
8814 .setCallingPid(Binder.getCallingPid())
8815 .setCallingUid(Binder.getCallingUid())
8816 .setMethod("getServiceStateForSubscriber")
8817 .setLogAsInfo(true)
8818 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8819 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8820 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8821 .build());
8822 hasFinePermission =
8823 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8824 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008825
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008826 if (!renounceCoarseLocationAccess) {
8827 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8828 LocationAccessPolicy.checkLocationPermission(mApp,
8829 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8830 .setCallingPackage(callingPackage)
8831 .setCallingFeatureId(callingFeatureId)
8832 .setCallingPid(Binder.getCallingPid())
8833 .setCallingUid(Binder.getCallingUid())
8834 .setMethod("getServiceStateForSubscriber")
8835 .setLogAsInfo(true)
8836 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8837 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8838 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8839 .build());
8840 hasCoarsePermission =
8841 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8842 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008843
Jack Yu479f40e2020-10-27 21:29:25 -07008844 final Phone phone = getPhone(subId);
8845 if (phone == null) {
8846 return null;
8847 }
8848
Jordan Liu0f2bc442020-11-18 16:47:37 -08008849 final long identity = Binder.clearCallingIdentity();
8850
Jack Yu479f40e2020-10-27 21:29:25 -07008851 boolean isCallingPackageDataService = phone.getDataServicePackages()
8852 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008853 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008854 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu3beaf9d2023-04-14 09:17:27 -07008855 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8856 .getSubscriptionInfoInternal(subId);
8857 if (subInfo == null || !subInfo.isActive()) {
8858 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8859 + "subId=" + subId);
8860 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008861 }
8862
Hall Liuf19c44f2018-11-27 14:38:17 -08008863 ServiceState ss = phone.getServiceState();
8864
8865 // Scrub out the location info in ServiceState depending on what level of access
8866 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008867 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008868 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8869 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008870 } finally {
8871 Binder.restoreCallingIdentity(identity);
8872 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008873 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008874
8875 /**
8876 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8877 *
8878 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8879 * voicemail ringtone.
8880 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8881 * PhoneAccount.
8882 */
8883 @Override
8884 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008885 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8886 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri");
8887
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008888 final long identity = Binder.clearCallingIdentity();
8889 try {
8890 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8891 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008892 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008893 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008894
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008895 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8896 } finally {
8897 Binder.restoreCallingIdentity(identity);
8898 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008899 }
8900
8901 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008902 * Sets the per-account voicemail ringtone.
8903 *
8904 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8905 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8906 *
8907 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8908 * voicemail ringtone.
8909 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8910 * PhoneAccount.
8911 */
8912 @Override
8913 public void setVoicemailRingtoneUri(String callingPackage,
8914 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008915 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008916 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008917 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8918 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008919 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8920 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8921 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008922 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008923
joonhunshin4ac60942023-11-15 15:23:39 +00008924 enforceTelephonyFeatureWithException(callingPackage,
8925 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri");
8926
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008927 final long identity = Binder.clearCallingIdentity();
8928 try {
8929 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8930 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008931 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008932 }
8933 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8934 } finally {
8935 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008936 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008937 }
8938
8939 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008940 * Returns whether vibration is set for voicemail notification in Phone settings.
8941 *
8942 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8943 * voicemail vibration setting.
8944 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8945 */
8946 @Override
8947 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008948 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8949 PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled");
8950
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008951 final long identity = Binder.clearCallingIdentity();
8952 try {
8953 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8954 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008955 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008956 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008957
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008958 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8959 } finally {
8960 Binder.restoreCallingIdentity(identity);
8961 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008962 }
8963
Youhan Wange64578a2016-05-02 15:32:42 -07008964 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008965 * Sets the per-account voicemail vibration.
8966 *
8967 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8968 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8969 *
8970 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8971 * voicemail vibration setting.
8972 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8973 * specific PhoneAccount.
8974 */
8975 @Override
8976 public void setVoicemailVibrationEnabled(String callingPackage,
8977 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008978 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008979 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008980 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8981 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008982 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8983 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8984 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008985 }
8986
joonhunshin4ac60942023-11-15 15:23:39 +00008987 enforceTelephonyFeatureWithException(callingPackage,
8988 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled");
8989
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008990 final long identity = Binder.clearCallingIdentity();
8991 try {
8992 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8993 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008994 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008995 }
8996 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8997 } finally {
8998 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008999 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009000 }
9001
9002 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009003 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
9004 *
9005 * @throws SecurityException if the caller does not have the required permission
9006 */
arunvoddud7401012022-12-15 16:08:12 +00009007 @VisibleForTesting
9008 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07009009 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07009010 message);
Youhan Wange64578a2016-05-02 15:32:42 -07009011 }
9012
9013 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009014 * Make sure either called from same process as self (phone) or IPC caller has send SMS
9015 * permission.
9016 *
9017 * @throws SecurityException if the caller does not have the required permission
9018 */
9019 private void enforceSendSmsPermission() {
9020 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
9021 }
9022
9023 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00009024 * Make sure either called from same process as self (phone) or IPC caller has interact across
9025 * users permission.
9026 *
9027 * @throws SecurityException if the caller does not have the required permission
9028 */
9029 private void enforceInteractAcrossUsersPermission(String message) {
9030 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
9031 }
9032
9033 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009034 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009035 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009036 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009037 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009038 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009039 final long identity = Binder.clearCallingIdentity();
9040 try {
9041 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009042 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009043 if (componentName == null) {
9044 throw new SecurityException(
9045 "Caller not current active visual voicemail package[null]");
9046 }
9047 String vvmPackage = componentName.getPackageName();
9048 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00009049 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009050 }
9051 } finally {
9052 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009053 }
9054 }
9055
9056 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009057 * Return the application ID for the app type.
9058 *
9059 * @param subId the subscription ID that this request applies to.
9060 * @param appType the uicc app type.
9061 * @return Application ID for specificied app type, or null if no uicc.
9062 */
9063 @Override
9064 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009065 enforceReadPrivilegedPermission("getAidForAppType");
joonhunshin4ac60942023-11-15 15:23:39 +00009066
9067 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9068 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType");
9069
Youhan Wange64578a2016-05-02 15:32:42 -07009070 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009071
9072 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07009073 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009074 if (phone == null) {
9075 return null;
9076 }
9077 String aid = null;
9078 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009079 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009080 .getApplicationByType(appType).getAid();
9081 } catch (Exception e) {
9082 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
9083 }
9084 return aid;
9085 } finally {
9086 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07009087 }
Youhan Wange64578a2016-05-02 15:32:42 -07009088 }
9089
Youhan Wang4001d252016-05-11 10:29:41 -07009090 /**
9091 * Return the Electronic Serial Number.
9092 *
9093 * @param subId the subscription ID that this request applies to.
9094 * @return ESN or null if error.
9095 */
9096 @Override
9097 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009098 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07009099 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009100
9101 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07009102 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009103 if (phone == null) {
9104 return null;
9105 }
9106 String esn = null;
9107 try {
9108 esn = phone.getEsn();
9109 } catch (Exception e) {
9110 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
9111 }
9112 return esn;
9113 } finally {
9114 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07009115 }
Youhan Wang4001d252016-05-11 10:29:41 -07009116 }
9117
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009118 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009119 * Return the Preferred Roaming List Version.
9120 *
9121 * @param subId the subscription ID that this request applies to.
9122 * @return PRLVersion or null if error.
9123 */
9124 @Override
9125 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009126 enforceReadPrivilegedPermission("getCdmaPrlVersion");
joonhunshin4ac60942023-11-15 15:23:39 +00009127
9128 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9129 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion");
9130
Youhan Wang66ad5d72016-07-18 17:56:58 -07009131 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009132
9133 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009134 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009135 if (phone == null) {
9136 return null;
9137 }
9138 String cdmaPrlVersion = null;
9139 try {
9140 cdmaPrlVersion = phone.getCdmaPrlVersion();
9141 } catch (Exception e) {
9142 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9143 }
9144 return cdmaPrlVersion;
9145 } finally {
9146 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009147 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009148 }
9149
9150 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009151 * Get snapshot of Telephony histograms
9152 * @return List of Telephony histograms
9153 * @hide
9154 */
9155 @Override
9156 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009157 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9158 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009159
9160 final long identity = Binder.clearCallingIdentity();
9161 try {
9162 return RIL.getTelephonyRILTimingHistograms();
9163 } finally {
9164 Binder.restoreCallingIdentity(identity);
9165 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009166 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009167
9168 /**
9169 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009170 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9171 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009172 * Require system privileges. In the future we may add this to carrier APIs.
9173 *
Michele Berionne482f8202018-11-27 18:57:59 -08009174 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009175 */
9176 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009177 @TelephonyManager.SetCarrierRestrictionResult
9178 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009179 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009180
9181 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9182 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers");
9183
vagdeviaf9a5b92018-08-15 16:01:53 -07009184 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009185
Michele Berionne482f8202018-11-27 18:57:59 -08009186 if (carrierRestrictionRules == null) {
9187 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009188 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009189
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009190 final long identity = Binder.clearCallingIdentity();
9191 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009192 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009193 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009194 } finally {
9195 Binder.restoreCallingIdentity(identity);
9196 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009197 }
9198
9199 /**
9200 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009201 * Get the allowed carrier list and the excluded carrier list, including the priority between
9202 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009203 * Require system privileges. In the future we may add this to carrier APIs.
9204 *
Michele Berionne482f8202018-11-27 18:57:59 -08009205 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009206 */
9207 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009208 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009209 enforceReadPrivilegedPermission("getAllowedCarriers");
joonhunshin4ac60942023-11-15 15:23:39 +00009210
9211 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9212 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers");
9213
vagdeviaf9a5b92018-08-15 16:01:53 -07009214 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009215
9216 final long identity = Binder.clearCallingIdentity();
9217 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009218 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9219 if (response instanceof CarrierRestrictionRules) {
9220 return (CarrierRestrictionRules) response;
9221 }
9222 // Response is an Exception of some kind,
9223 // which is signalled to the user as a NULL retval
9224 return null;
9225 } catch (Exception e) {
9226 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9227 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009228 } finally {
9229 Binder.restoreCallingIdentity(identity);
9230 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009231 }
9232
fionaxu59545b42016-05-25 15:53:37 -07009233 /**
arunvoddud7401012022-12-15 16:08:12 +00009234 * Fetches the carrier restriction status of the device and sends the status to the caller
9235 * through the callback.
9236 *
9237 * @param callback The callback that will be used to send the result.
9238 * @throws SecurityException if the caller does not have the required permission/privileges or
9239 * the caller is not allowlisted.
9240 */
9241 @Override
9242 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
9243 enforceReadPermission("getCarrierRestrictionStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00009244
9245 enforceTelephonyFeatureWithException(packageName,
9246 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierRestrictionStatus");
9247
Steve Statia28b7cb32024-03-11 23:58:50 +00009248 Set<Integer> carrierIds = validateCallerAndGetCarrierIds(packageName);
9249 if (carrierIds.contains(CarrierAllowListInfo.INVALID_CARRIER_ID)) {
arunvoddud7401012022-12-15 16:08:12 +00009250 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9251 throw new SecurityException("Not an authorized caller");
9252 }
9253 final long identity = Binder.clearCallingIdentity();
9254 try {
9255 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
Steve Statia28b7cb32024-03-11 23:58:50 +00009256 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierIds);
arunvoddud7401012022-12-15 16:08:12 +00009257 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9258 } finally {
9259 Binder.restoreCallingIdentity(identity);
9260 }
9261 }
9262
arunvoddu567f2b42023-04-25 17:22:00 +00009263 @Override
9264 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
9265 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
9266 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9267 return allowListInfo.getShaIdList(pkgName, carrierId);
9268 }
9269
arunvoddud7401012022-12-15 16:08:12 +00009270 @VisibleForTesting
Steve Statia28b7cb32024-03-11 23:58:50 +00009271 public Set<Integer> validateCallerAndGetCarrierIds(String packageName) {
arunvoddud7401012022-12-15 16:08:12 +00009272 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
Steve Statia28b7cb32024-03-11 23:58:50 +00009273 return allowListInfo.validateCallerAndGetCarrierIds(packageName);
arunvoddud7401012022-12-15 16:08:12 +00009274 }
9275
9276 /**
fionaxu59545b42016-05-25 15:53:37 -07009277 * Action set from carrier signalling broadcast receivers to enable/disable radio
9278 * @param subId the subscription ID that this action applies to.
9279 * @param enabled control enable or disable radio.
9280 * {@hide}
9281 */
9282 @Override
9283 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9284 enforceModifyPermission();
9285 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009286
9287 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009288 if (phone == null) {
9289 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9290 return;
9291 }
9292 try {
9293 phone.carrierActionSetRadioEnabled(enabled);
9294 } catch (Exception e) {
9295 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009296 } finally {
9297 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009298 }
9299 }
9300
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009301 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009302 * Enable or disable Voice over NR (VoNR)
9303 * @param subId the subscription ID that this action applies to.
9304 * @param enabled enable or disable VoNR.
9305 * @return operation result.
9306 */
9307 @Override
9308 public int setVoNrEnabled(int subId, boolean enabled) {
9309 enforceModifyPermission();
9310 final Phone phone = getPhone(subId);
9311
9312 final long identity = Binder.clearCallingIdentity();
9313 if (phone == null) {
9314 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9315 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9316 }
9317
9318 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9319 try {
9320 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9321 workSource);
9322 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009323
9324 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9325 if (DBG) {
9326 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9327 }
9328 SubscriptionManager.setSubscriptionProperty(
9329 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9330 (enabled ? "1" : "0"));
9331 }
9332
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009333 return result;
9334 } finally {
9335 Binder.restoreCallingIdentity(identity);
9336 }
9337 }
9338
9339 /**
9340 * Is voice over NR enabled
9341 * @return true if VoNR is enabled else false
9342 */
9343 @Override
9344 public boolean isVoNrEnabled(int subId) {
9345 enforceReadPrivilegedPermission("isVoNrEnabled");
9346 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9347 final long identity = Binder.clearCallingIdentity();
9348 try {
9349 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9350 null, subId, workSource);
9351 if (DBG) log("isVoNrEnabled: " + isEnabled);
9352 return isEnabled;
9353 } finally {
9354 Binder.restoreCallingIdentity(identity);
9355 }
9356 }
9357
9358 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009359 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9360 * network status based on which carrier apps could apply actions accordingly,
9361 * enable/disable default url handler for example.
9362 *
9363 * @param subId the subscription ID that this action applies to.
9364 * @param report control start/stop reporting the default network status.
9365 * {@hide}
9366 */
9367 @Override
9368 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9369 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009370
9371 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9372 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
9373 "carrierActionReportDefaultNetworkStatus");
9374
fionaxu8da9cb12017-05-23 15:02:46 -07009375 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009376
9377 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009378 if (phone == null) {
9379 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9380 return;
9381 }
9382 try {
9383 phone.carrierActionReportDefaultNetworkStatus(report);
9384 } catch (Exception e) {
9385 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009386 } finally {
9387 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009388 }
9389 }
9390
9391 /**
fionaxud9622282017-07-17 17:51:30 -07009392 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9393 * @param subId the subscription ID that this action applies to.
9394 * {@hide}
9395 */
9396 @Override
9397 public void carrierActionResetAll(int subId) {
9398 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009399
9400 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9401 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll");
9402
fionaxud9622282017-07-17 17:51:30 -07009403 final Phone phone = getPhone(subId);
9404 if (phone == null) {
9405 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9406 return;
9407 }
9408 try {
9409 phone.carrierActionResetAll();
9410 } catch (Exception e) {
9411 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9412 }
9413 }
9414
9415 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009416 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9417 * bug report is being generated.
9418 */
9419 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009420 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009421 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9422 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009423 writer.println("Permission Denial: can't dump Phone from pid="
9424 + Binder.getCallingPid()
9425 + ", uid=" + Binder.getCallingUid()
9426 + "without permission "
9427 + android.Manifest.permission.DUMP);
9428 return;
9429 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009430 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009431 }
Jack Yueb89b242016-06-22 13:27:47 -07009432
Brad Ebingerdac2f002018-04-03 15:17:52 -07009433 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009434 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9435 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9436 @NonNull String[] args) {
9437 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9438 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009439 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009440 }
9441
Jack Yueb89b242016-06-22 13:27:47 -07009442 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009443 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009444 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009445 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009446 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009447 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009448 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009449 */
9450 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009451 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009452 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009453 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9454 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9455 try {
9456 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009457 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009458 } catch (SecurityException se) {
9459 enforceModifyPermission();
9460 }
9461 } else {
9462 enforceModifyPermission();
9463 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009464
joonhunshin4ac60942023-11-15 15:23:39 +00009465 enforceTelephonyFeatureWithException(callingPackage,
9466 PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason");
9467
Nate Myren116695d2024-02-09 09:36:01 -08009468 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009469 final long identity = Binder.clearCallingIdentity();
9470 try {
Nate Myren116695d2024-02-09 09:36:01 -08009471 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
9472 && null != callingPackage && opEnableMobileDataByUser()) {
Nate Myren453c3472024-03-13 11:28:11 -07009473 mAppOps.noteOpNoThrow(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER,
Nate Myren116695d2024-02-09 09:36:01 -08009474 callingUid, callingPackage, null, null);
9475 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009476 Phone phone = getPhone(subId);
9477 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009478 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9479 phone.carrierActionSetMeteredApnsEnabled(enabled);
9480 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07009481 phone.getDataSettingsManager().setDataEnabled(
9482 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009483 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009484 }
9485 } finally {
9486 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009487 }
9488 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009489
9490 /**
9491 * Get Client request stats
9492 * @return List of Client Request Stats
9493 * @hide
9494 */
9495 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009496 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9497 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009498 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009499 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009500 return null;
9501 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009502 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009503
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009504 final long identity = Binder.clearCallingIdentity();
9505 try {
9506 if (phone != null) {
9507 return phone.getClientRequestStats();
9508 }
9509
9510 return null;
9511 } finally {
9512 Binder.restoreCallingIdentity(identity);
9513 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009514 }
9515
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009516 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009517 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009518 if (uid == Process.ROOT_UID && packageName == null) {
9519 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9520 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9521 // exception. ROOT_UID seems not to have a valid package name returned by
9522 // PackageManager, so just fake it here to avoid issues when running telephony shell
9523 // commands that plumb through the RIL as root, like so:
9524 // $ adb root
9525 // $ adb shell cmd phone ...
9526 packageName = "root";
9527 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009528 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009529 }
Jack Yueb4124c2017-02-16 15:32:43 -08009530
9531 /**
Grace Chen70990072017-03-24 17:21:30 -07009532 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009533 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009534 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009535 * @param state State of SIM (power down, power up, pass through)
9536 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9537 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9538 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009539 *
9540 **/
9541 @Override
Grace Chen70990072017-03-24 17:21:30 -07009542 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009543 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009544
9545 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9546 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot");
9547
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009548 Phone phone = PhoneFactory.getPhone(slotIndex);
9549
vagdeviaf9a5b92018-08-15 16:01:53 -07009550 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9551
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009552 final long identity = Binder.clearCallingIdentity();
9553 try {
9554 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009555 phone.setSimPowerState(state, null, workSource);
9556 }
9557 } finally {
9558 Binder.restoreCallingIdentity(identity);
9559 }
9560 }
9561
9562 /**
9563 * Set SIM card power state.
9564 *
9565 * @param slotIndex SIM slot id.
9566 * @param state State of SIM (power down, power up, pass through)
9567 * @param callback callback to trigger after success or failure
9568 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9569 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9570 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9571 *
9572 **/
9573 @Override
9574 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9575 IIntegerConsumer callback) {
9576 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009577
9578 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9579 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
9580 "setSimPowerStateForSlotWithCallback");
9581
Jordan Liu109698e2020-11-24 14:50:34 -08009582 Phone phone = PhoneFactory.getPhone(slotIndex);
9583
9584 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9585
9586 final long identity = Binder.clearCallingIdentity();
9587 try {
9588 if (phone != null) {
9589 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9590 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009591 }
9592 } finally {
9593 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009594 }
9595 }
Shuo Qiandd210312017-04-12 22:11:33 +00009596
Tyler Gunn65d45c22017-06-05 11:22:26 -07009597 private boolean isUssdApiAllowed(int subId) {
9598 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009599 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009600 if (configManager == null) {
9601 return false;
9602 }
9603 PersistableBundle pb = configManager.getConfigForSubId(subId);
9604 if (pb == null) {
9605 return false;
9606 }
9607 return pb.getBoolean(
9608 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9609 }
9610
Shuo Qiandd210312017-04-12 22:11:33 +00009611 /**
Ling Mac28f0212023-03-24 16:07:15 -07009612 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00009613 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07009614 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00009615 */
goneil9c5f4872017-12-05 14:07:56 -08009616 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009617 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009618 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
joonhunshin4ac60942023-11-15 15:23:39 +00009619
9620 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9621 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode");
9622
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009623 final long identity = Binder.clearCallingIdentity();
9624 try {
Ling Mac28f0212023-03-24 16:07:15 -07009625 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009626 } finally {
9627 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009628 }
9629 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009630
9631 /**
9632 * Get the current signal strength information for the given subscription.
9633 * Because this information is not updated when the device is in a low power state
9634 * it should not be relied-upon to be current.
9635 * @param subId Subscription index
9636 * @return the most recent cached signal strength info from the modem
9637 */
9638 @Override
9639 public SignalStrength getSignalStrength(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00009640 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9641 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength");
9642
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009643 final long identity = Binder.clearCallingIdentity();
9644 try {
9645 Phone p = getPhone(subId);
9646 if (p == null) {
9647 return null;
9648 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009649
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009650 return p.getSignalStrength();
9651 } finally {
9652 Binder.restoreCallingIdentity(identity);
9653 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009654 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009655
Pengquan Meng77b7f132018-08-22 14:49:57 -07009656 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009657 * Get the current modem radio state for the given slot.
9658 * @param slotIndex slot index.
9659 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009660 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009661 * @return the current radio power state from the modem
9662 */
9663 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009664 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009665 Phone phone = PhoneFactory.getPhone(slotIndex);
9666 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009667 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9668 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009669 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9670 }
9671
joonhunshin4ac60942023-11-15 15:23:39 +00009672 enforceTelephonyFeatureWithException(callingPackage,
9673 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState");
9674
Chen Xuf792fd62018-10-17 17:54:36 +00009675 final long identity = Binder.clearCallingIdentity();
9676 try {
9677 return phone.getRadioPowerState();
9678 } finally {
9679 Binder.restoreCallingIdentity(identity);
9680 }
9681 }
9682 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9683 }
9684
9685 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009686 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9687 *
9688 * <p>Requires one of the following permissions:
9689 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009690 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009691 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9692 * privileges.
9693 *
9694 * @param subId subscription id
9695 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9696 * {@code false}.
9697 */
9698 @Override
9699 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009700 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009701 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009702 try {
9703 mApp.enforceCallingOrSelfPermission(
9704 android.Manifest.permission.ACCESS_NETWORK_STATE,
9705 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009706 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009707 mApp.enforceCallingOrSelfPermission(
9708 permission.READ_BASIC_PHONE_STATE, functionName);
9709 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009710 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009711 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009712 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009713 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009714
joonhunshin4ac60942023-11-15 15:23:39 +00009715 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9716 PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled");
9717
Pengquan Menga1bb6272018-09-06 09:59:22 -07009718 boolean isEnabled = false;
9719 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009720 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009721 Phone phone = getPhone(subId);
9722 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009723 } finally {
9724 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009725 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009726 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009727 }
9728
9729
9730 /**
9731 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9732 *
9733 * <p> Requires permission:
9734 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9735 * privileges.
9736 *
9737 * @param subId subscription id
9738 * @param isEnabled {@code true} means enable, {@code false} means disable.
9739 */
9740 @Override
9741 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009742 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9743 mApp, subId, "setDataRoamingEnabled");
9744
joonhunshin4ac60942023-11-15 15:23:39 +00009745 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9746 PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled");
9747
Pengquan Menga1bb6272018-09-06 09:59:22 -07009748 final long identity = Binder.clearCallingIdentity();
9749 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009750 Phone phone = getPhone(subId);
9751 if (phone != null) {
9752 phone.setDataRoamingEnabled(isEnabled);
9753 }
9754 } finally {
9755 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009756 }
9757 }
9758
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009759 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009760 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009761 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009762 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009763 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009764
joonhunshin4ac60942023-11-15 15:23:39 +00009765 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9766 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed");
9767
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009768 boolean isAllowed = true;
9769 final long identity = Binder.clearCallingIdentity();
9770 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009771 Phone phone = getPhone(subId);
9772 if (phone != null) {
9773 isAllowed = phone.isCspPlmnEnabled();
9774 }
9775 } finally {
9776 Binder.restoreCallingIdentity(identity);
9777 }
9778 return isAllowed;
9779 }
9780
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009781 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9782 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009783 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009784 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009785 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009786 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9787 if (phone == null) {
9788 return false;
9789 }
9790 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9791 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9792 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009793 }
9794
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009795 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009796 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009797 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009798 mApp.getSystemService(AppOpsManager.class)
9799 .checkPackage(Binder.getCallingUid(), callingPackage);
9800
Jordan Liu1e142fc2019-04-22 15:10:43 -07009801 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009802 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009803 try {
9804 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009805 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009806 } catch (SecurityException e) {
9807 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9808 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009809 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009810 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009811 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009812 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009813 }
joonhunshin4ac60942023-11-15 15:23:39 +00009814
9815 enforceTelephonyFeatureWithException(callingPackage,
9816 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo");
9817
sandeepjsb6c87872021-09-27 15:34:44 +00009818 // checking compatibility, if calling app's target SDK is T and beyond.
9819 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9820 Binder.getCallingUid())) {
9821 isIccIdAccessRestricted = true;
9822 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009823 final long identity = Binder.clearCallingIdentity();
9824 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009825 UiccController uiccController = UiccController.getInstance();
9826 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009827 if (hasReadPermission) {
9828 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009829 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009830
9831 // Remove private info if the caller doesn't have access
9832 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9833 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009834 //setting the value after compatibility check
9835 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009836 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9837 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009838 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009839 if (card == null) {
9840 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009841 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009842 continue;
9843 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009844 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9845 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009846 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009847 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009848 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009849 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9850 for (UiccPortInfo portInfo : portInfos) {
9851 UiccPort port = uiccController.getUiccPortForSlot(
9852 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9853 if (port == null) {
9854 // assume no access if port is null
9855 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9856 continue;
9857 }
9858 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9859 uiccPortInfos.add(portInfo);
9860 } else {
9861 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9862 }
9863 }
9864 filteredInfos.add(new UiccCardInfo(
9865 cardInfo.isEuicc(),
9866 cardInfo.getCardId(),
9867 null,
9868 cardInfo.getPhysicalSlotIndex(),
9869 cardInfo.isRemovable(),
9870 cardInfo.isMultipleEnabledProfilesSupported(),
9871 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009872 }
9873 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009874 } finally {
9875 Binder.restoreCallingIdentity(identity);
9876 }
9877 }
9878
sandeepjsb6c87872021-09-27 15:34:44 +00009879 /**
9880 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9881 * generally private and require carrier privileges to view.
9882 *
9883 * @hide
9884 */
9885 @NonNull
9886 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9887 List<UiccPortInfo> portinfo = new ArrayList<>();
9888 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9889 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9890 }
9891 return new UiccCardInfo(
9892 cardInfo.isEuicc(),
9893 cardInfo.getCardId(),
9894 null,
9895 cardInfo.getPhysicalSlotIndex(),
9896 cardInfo.isRemovable(),
9897 cardInfo.isMultipleEnabledProfilesSupported(),
9898 portinfo
9899 );
9900 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009901
sandeepjsb6c87872021-09-27 15:34:44 +00009902 /**
9903 * @hide
9904 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9905 * These values are generally private and require carrier privileges to view.
9906 */
9907 @NonNull
9908 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9909 return new UiccPortInfo(
9910 UiccPortInfo.ICCID_REDACTED,
9911 portInfo.getPortIndex(),
9912 portInfo.getLogicalSlotIndex(),
9913 portInfo.isActive()
9914 );
9915 }
9916 @Override
9917 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009918 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009919 mApp.getSystemService(AppOpsManager.class)
9920 .checkPackage(Binder.getCallingUid(), callingPackage);
9921
sandeepjsb6c87872021-09-27 15:34:44 +00009922 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009923
Aman Guptaf3c90b32022-03-17 04:54:16 +00009924 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9925 // we are reading iccId which is PII data.
9926 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009927
joonhunshin4ac60942023-11-15 15:23:39 +00009928 enforceTelephonyFeatureWithException(callingPackage,
9929 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo");
9930
sandeepjsb6c87872021-09-27 15:34:44 +00009931 // checking compatibility, if calling app's target SDK is T and beyond.
9932 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9933 Binder.getCallingUid())) {
9934 isLogicalSlotAccessRestricted = true;
9935 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009936 final long identity = Binder.clearCallingIdentity();
9937 try {
9938 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009939 if (slots == null || slots.length == 0) {
9940 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009941 return null;
9942 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009943 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9944 for (int i = 0; i < slots.length; i++) {
9945 UiccSlot slot = slots[i];
9946 if (slot == null) {
9947 continue;
9948 }
9949
Jordan Liu7be7e652019-05-06 18:55:02 +00009950 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009951 UiccCard card = slot.getUiccCard();
9952 if (card != null) {
9953 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009954 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009955 cardId = slot.getEid();
9956 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009957 // If cardId is null, use iccId of default port as cardId.
9958 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009959 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009960 }
9961
Jordan Liu857451f2019-05-09 16:35:35 -07009962 if (cardId != null) {
9963 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9964 // if cardId is an EID, it's all digits so this is fine
9965 cardId = IccUtils.stripTrailingFs(cardId);
9966 }
9967
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009968 int cardState = 0;
9969 switch (slot.getCardState()) {
9970 case CARDSTATE_ABSENT:
9971 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9972 break;
9973 case CARDSTATE_PRESENT:
9974 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9975 break;
9976 case CARDSTATE_ERROR:
9977 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9978 break;
9979 case CARDSTATE_RESTRICTED:
9980 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9981 break;
9982 default:
9983 break;
9984
9985 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009986 List<UiccPortInfo> portInfos = new ArrayList<>();
9987 int[] portIndexes = slot.getPortList();
9988 for (int portIdx : portIndexes) {
9989 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009990 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009991 portInfos.add(new UiccPortInfo(iccId, portIdx,
9992 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009993 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009994 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009995 slot.isEuicc(),
9996 cardId,
9997 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009998 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009999 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +000010000 //setting the value after compatibility check
10001 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010002 }
10003 return infos;
10004 } finally {
10005 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -070010006 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010007 }
10008
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010009 /* Returns null if doesn't have read permission or carrier privilege access. */
10010 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
10011 boolean hasReadPermission) {
10012 String iccId = slot.getIccId(portIndex);
10013 if (hasReadPermission) { // if has read permission
10014 return iccId;
10015 } else {
10016 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
10017 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
10018 // if no read permission, checking carrier privilege access
10019 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
10020 return iccId;
10021 }
10022 }
10023 }
10024 // No read permission or carrier privilege access.
10025 return UiccPortInfo.ICCID_REDACTED;
10026 }
10027
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010028 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010029 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010030 public boolean switchSlots(int[] physicalSlots) {
10031 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010032
joonhunshin4ac60942023-11-15 15:23:39 +000010033 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10034 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots");
10035
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010036 final long identity = Binder.clearCallingIdentity();
10037 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010038 List<UiccSlotMapping> slotMappings = new ArrayList<>();
10039 for (int i = 0; i < physicalSlots.length; i++) {
10040 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
10041 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
10042 physicalSlots[i], i));
10043 }
10044 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010045 } finally {
10046 Binder.restoreCallingIdentity(identity);
10047 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010048 }
Jack Yu4c988042018-02-27 15:30:01 -080010049
10050 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010051 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
10052 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
10053 enforceModifyPermission();
10054
joonhunshin4ac60942023-11-15 15:23:39 +000010055 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10056 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping");
10057
sandeepjsb6c87872021-09-27 15:34:44 +000010058 final long identity = Binder.clearCallingIdentity();
10059 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010060 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +000010061 } finally {
10062 Binder.restoreCallingIdentity(identity);
10063 }
10064 }
10065
10066 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -080010067 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
joonhunshin4ac60942023-11-15 15:23:39 +000010068 enforceTelephonyFeatureWithException(callingPackage,
10069 PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc");
10070
Jordan Liu7de49fa2018-12-06 14:48:49 -080010071 final long identity = Binder.clearCallingIdentity();
10072 try {
10073 return UiccController.getInstance().getCardIdForDefaultEuicc();
10074 } finally {
10075 Binder.restoreCallingIdentity(identity);
10076 }
10077 }
10078
Pengquan Meng85728fb2018-03-12 16:31:21 -070010079 /**
goneil47ffb6e2018-04-06 15:40:58 -070010080 * A test API to reload the UICC profile.
10081 *
10082 * <p>Requires that the calling app has permission
10083 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
10084 * @hide
10085 */
10086 @Override
10087 public void refreshUiccProfile(int subId) {
10088 enforceModifyPermission();
10089
10090 final long identity = Binder.clearCallingIdentity();
10091 try {
10092 Phone phone = getPhone(subId);
10093 if (phone == null) {
10094 return;
10095 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010096 UiccPort uiccPort = phone.getUiccPort();
10097 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -070010098 return;
10099 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010100 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -070010101 if (uiccProfile == null) {
10102 return;
10103 }
10104 uiccProfile.refresh();
10105 } finally {
10106 Binder.restoreCallingIdentity(identity);
10107 }
10108 }
10109
10110 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010111 * Returns false if the mobile data is disabled by default, otherwise return true.
10112 */
10113 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010114 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010115 }
10116
10117 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010118 * Returns the default network type for the given {@code subId}, if the default network type is
10119 * not set, return {@link Phone#PREFERRED_NT_MODE}.
10120 */
10121 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010122 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -080010123 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +090010124 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
10125 return list.get(phoneId);
10126 }
10127 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -070010128 }
fionaxua13278b2018-03-21 00:08:13 -070010129
10130 @Override
10131 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -070010132 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -070010133 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010134
10135 final long identity = Binder.clearCallingIdentity();
10136 try {
10137 final Phone phone = getPhone(subId);
10138 if (phone == null) {
10139 loge("setCarrierTestOverride fails with invalid subId: " + subId);
10140 return;
10141 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -080010142 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10143 if (cpt != null) {
10144 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
10145 }
10146 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -070010147 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
10148 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -070010149 if (carrierPrivilegeRules == null) {
10150 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
10151 } else {
10152 mCarrierPrivilegeTestOverrideSubIds.add(subId);
10153 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010154 } finally {
10155 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010156 }
fionaxua13278b2018-03-21 00:08:13 -070010157 }
10158
10159 @Override
Benedict Wong66477622023-02-03 23:30:57 +000010160 public void setCarrierServicePackageOverride(
10161 int subId, String carrierServicePackage, String callingPackage) {
10162 TelephonyPermissions.enforceShellOnly(
10163 Binder.getCallingUid(), "setCarrierServicePackageOverride");
10164
Benedict Wong66477622023-02-03 23:30:57 +000010165 final long identity = Binder.clearCallingIdentity();
10166 try {
10167 final Phone phone = getPhone(subId);
10168 if (phone == null || phone.getSubId() != subId) {
10169 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
10170 throw new IllegalArgumentException("No phone for subid");
10171 }
10172 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10173 if (cpt == null) {
10174 loge("setCarrierServicePackageOverride failed with no CPT for phone");
10175 throw new IllegalStateException("No CPT for phone");
10176 }
10177 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
10178 } finally {
10179 Binder.restoreCallingIdentity(identity);
10180 }
10181 }
10182
10183 @Override
fionaxua13278b2018-03-21 00:08:13 -070010184 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -070010185 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010186
10187 final long identity = Binder.clearCallingIdentity();
10188 try {
10189 final Phone phone = getPhone(subId);
10190 if (phone == null) {
10191 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
10192 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
10193 }
10194 return phone.getCarrierIdListVersion();
10195 } finally {
10196 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010197 }
fionaxua13278b2018-03-21 00:08:13 -070010198 }
Malcolm Chen2c63d402018-08-14 16:00:53 -070010199
10200 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010201 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
10202 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010203 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010204 mApp, subId, callingPackage, callingFeatureId,
10205 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010206 return -1;
10207 }
10208
10209 final long identity = Binder.clearCallingIdentity();
10210 try {
10211 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10212 } finally {
10213 Binder.restoreCallingIdentity(identity);
10214 }
10215 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010216
10217 @Override
10218 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +080010219 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010220 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010221 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010222
joonhunshin4ac60942023-11-15 15:23:39 +000010223 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10224 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode");
10225
Pengquan Menga1bb6272018-09-06 09:59:22 -070010226 final long identity = Binder.clearCallingIdentity();
10227 try {
10228 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10229 } finally {
10230 Binder.restoreCallingIdentity(identity);
10231 }
10232 }
10233
10234 @Override
10235 public boolean setCdmaRoamingMode(int subId, int mode) {
10236 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10237 mApp, subId, "setCdmaRoamingMode");
10238
joonhunshin4ac60942023-11-15 15:23:39 +000010239 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10240 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode");
10241
Pengquan Menga1bb6272018-09-06 09:59:22 -070010242 final long identity = Binder.clearCallingIdentity();
10243 try {
10244 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10245 } finally {
10246 Binder.restoreCallingIdentity(identity);
10247 }
10248 }
10249
10250 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010251 public int getCdmaSubscriptionMode(int subId) {
10252 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010253 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010254 mApp, subId, "getCdmaSubscriptionMode");
10255
joonhunshin4ac60942023-11-15 15:23:39 +000010256 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10257 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode");
10258
Sarah Chinbaab1432020-10-28 13:46:24 -070010259 final long identity = Binder.clearCallingIdentity();
10260 try {
10261 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10262 } finally {
10263 Binder.restoreCallingIdentity(identity);
10264 }
10265 }
10266
10267 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010268 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10269 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10270 mApp, subId, "setCdmaSubscriptionMode");
10271
joonhunshin4ac60942023-11-15 15:23:39 +000010272 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10273 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode");
10274
Pengquan Menga1bb6272018-09-06 09:59:22 -070010275 final long identity = Binder.clearCallingIdentity();
10276 try {
10277 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10278 } finally {
10279 Binder.restoreCallingIdentity(identity);
10280 }
10281 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010282
sqianc5eccab2018-10-19 18:46:41 -070010283 @Override
sqian8c685422019-02-22 15:55:18 -080010284 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010285 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010286 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010287 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10288 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010289 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10290 }
joonhunshin4ac60942023-11-15 15:23:39 +000010291
10292 enforceTelephonyFeatureWithException(callingPackage,
10293 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList");
10294
sqian11b7a0e2018-12-05 18:48:28 -080010295 final long identity = Binder.clearCallingIdentity();
10296 try {
sqian854d44b2018-12-12 16:48:18 -080010297 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10298 for (Phone phone: PhoneFactory.getPhones()) {
10299 if (phone.getEmergencyNumberTracker() != null
10300 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10301 emergencyNumberListInternal.put(
10302 phone.getSubId(),
10303 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10304 }
sqian11b7a0e2018-12-05 18:48:28 -080010305 }
sqian854d44b2018-12-12 16:48:18 -080010306 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010307 } finally {
10308 Binder.restoreCallingIdentity(identity);
10309 }
sqianc5eccab2018-10-19 18:46:41 -070010310 }
10311
10312 @Override
sqian8c685422019-02-22 15:55:18 -080010313 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010314 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010315 if (!exactMatch) {
10316 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010317 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010318 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010319 }
joonhunshin4ac60942023-11-15 15:23:39 +000010320
10321 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10322 PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber");
10323
sqian11b7a0e2018-12-05 18:48:28 -080010324 final long identity = Binder.clearCallingIdentity();
10325 try {
sqian854d44b2018-12-12 16:48:18 -080010326 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010327 //Note: we ignore passed in param exactMatch. We can remove it once
10328 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010329 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010330 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010331 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010332 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010333 }
sqian11b7a0e2018-12-05 18:48:28 -080010334 }
10335 return false;
10336 } finally {
10337 Binder.restoreCallingIdentity(identity);
10338 }
10339 }
10340
sqianf4ca7ed2019-01-15 18:32:07 -080010341 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010342 * Start emergency callback mode for GsmCdmaPhone for testing.
10343 */
10344 @Override
10345 public void startEmergencyCallbackMode() {
10346 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10347 "startEmergencyCallbackMode");
10348 enforceModifyPermission();
10349 final long identity = Binder.clearCallingIdentity();
10350 try {
10351 for (Phone phone : PhoneFactory.getPhones()) {
10352 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10353 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10354 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10355 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10356 gsmCdmaPhone.obtainMessage(
10357 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10358 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10359 }
10360 }
10361 } finally {
10362 Binder.restoreCallingIdentity(identity);
10363 }
10364 }
10365
10366 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010367 * Update emergency number list for test mode.
10368 */
10369 @Override
10370 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10371 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10372 "updateEmergencyNumberListTestMode");
10373
10374 final long identity = Binder.clearCallingIdentity();
10375 try {
10376 for (Phone phone: PhoneFactory.getPhones()) {
10377 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10378 if (tracker != null) {
10379 tracker.executeEmergencyNumberTestModeCommand(action, num);
10380 }
10381 }
10382 } finally {
10383 Binder.restoreCallingIdentity(identity);
10384 }
10385 }
10386
10387 /**
10388 * Get the full emergency number list for test mode.
10389 */
10390 @Override
10391 public List<String> getEmergencyNumberListTestMode() {
10392 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10393 "getEmergencyNumberListTestMode");
10394
10395 final long identity = Binder.clearCallingIdentity();
10396 try {
10397 Set<String> emergencyNumbers = new HashSet<>();
10398 for (Phone phone: PhoneFactory.getPhones()) {
10399 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10400 if (tracker != null) {
10401 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10402 emergencyNumbers.add(num.getNumber());
10403 }
10404 }
10405 }
10406 return new ArrayList<>(emergencyNumbers);
10407 } finally {
10408 Binder.restoreCallingIdentity(identity);
10409 }
10410 }
10411
chen xud6b45bd2018-10-30 22:27:10 -070010412 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010413 public int getEmergencyNumberDbVersion(int subId) {
10414 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10415
joonhunshin4ac60942023-11-15 15:23:39 +000010416 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10417 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion");
10418
Shuo Qian3b6ee772019-11-13 17:43:31 -080010419 final long identity = Binder.clearCallingIdentity();
10420 try {
10421 final Phone phone = getPhone(subId);
10422 if (phone == null) {
10423 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10424 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10425 }
10426 return phone.getEmergencyNumberDbVersion();
10427 } finally {
10428 Binder.restoreCallingIdentity(identity);
10429 }
10430 }
10431
10432 @Override
10433 public void notifyOtaEmergencyNumberDbInstalled() {
10434 enforceModifyPermission();
10435
joonhunshin4ac60942023-11-15 15:23:39 +000010436 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10437 PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled");
10438
Shuo Qian3b6ee772019-11-13 17:43:31 -080010439 final long identity = Binder.clearCallingIdentity();
10440 try {
10441 for (Phone phone: PhoneFactory.getPhones()) {
10442 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10443 if (tracker != null) {
10444 tracker.updateOtaEmergencyNumberDatabase();
10445 }
10446 }
10447 } finally {
10448 Binder.restoreCallingIdentity(identity);
10449 }
10450 }
10451
10452 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010453 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010454 enforceActiveEmergencySessionPermission();
10455
joonhunshin4ac60942023-11-15 15:23:39 +000010456 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10457 PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath");
10458
Shuo Qian3b6ee772019-11-13 17:43:31 -080010459 final long identity = Binder.clearCallingIdentity();
10460 try {
10461 for (Phone phone: PhoneFactory.getPhones()) {
10462 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10463 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010464 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10465 }
10466 }
10467 } finally {
10468 Binder.restoreCallingIdentity(identity);
10469 }
10470 }
10471
10472 @Override
10473 public void resetOtaEmergencyNumberDbFilePath() {
10474 enforceActiveEmergencySessionPermission();
10475
joonhunshin4ac60942023-11-15 15:23:39 +000010476 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10477 PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath");
10478
Shuo Qianc373f112020-03-05 17:55:34 -080010479 final long identity = Binder.clearCallingIdentity();
10480 try {
10481 for (Phone phone: PhoneFactory.getPhones()) {
10482 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10483 if (tracker != null) {
10484 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010485 }
10486 }
10487 } finally {
10488 Binder.restoreCallingIdentity(identity);
10489 }
10490 }
10491
10492 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010493 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10494 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10495 Phone phone = getPhone(subId);
10496 if (phone == null) {
10497 return null;
10498 }
10499 final long identity = Binder.clearCallingIdentity();
10500 try {
10501 UiccProfile profile = UiccController.getInstance()
10502 .getUiccProfileForPhone(phone.getPhoneId());
10503 if (profile != null) {
10504 return profile.getCertsFromCarrierPrivilegeAccessRules();
10505 }
10506 } finally {
10507 Binder.restoreCallingIdentity(identity);
10508 }
10509 return null;
10510 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010511
10512 /**
10513 * Enable or disable a modem stack.
10514 */
10515 @Override
10516 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10517 enforceModifyPermission();
10518
joonhunshin4ac60942023-11-15 15:23:39 +000010519 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10520 PackageManager.FEATURE_TELEPHONY, "enableModemForSlot");
10521
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010522 final long identity = Binder.clearCallingIdentity();
10523 try {
10524 Phone phone = PhoneFactory.getPhone(slotIndex);
10525 if (phone == null) {
10526 return false;
10527 } else {
10528 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10529 }
10530 } finally {
10531 Binder.restoreCallingIdentity(identity);
10532 }
10533 }
Michelecea4cf22018-12-21 15:00:11 -080010534
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010535 /**
10536 * Whether a modem stack is enabled or not.
10537 */
10538 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010539 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10540 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010541 Phone phone = PhoneFactory.getPhone(slotIndex);
10542 if (phone == null) return false;
10543
10544 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010545 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10546 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010547 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10548 }
10549
joonhunshin4ac60942023-11-15 15:23:39 +000010550 enforceTelephonyFeatureWithException(callingPackage,
10551 PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot");
10552
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010553 final long identity = Binder.clearCallingIdentity();
10554 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010555 try {
10556 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10557 } catch (NoSuchElementException ex) {
10558 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10559 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010560 } finally {
10561 Binder.restoreCallingIdentity(identity);
10562 }
10563 }
10564
Michelecea4cf22018-12-21 15:00:11 -080010565 @Override
Michele0ea7d782019-03-19 14:58:42 -070010566 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010567 enforceModifyPermission();
10568
joonhunshin4ac60942023-11-15 15:23:39 +000010569 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10570 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction");
10571
Michelecea4cf22018-12-21 15:00:11 -080010572 final long identity = Binder.clearCallingIdentity();
10573 try {
10574 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010575 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010576 .commit();
10577 } finally {
10578 Binder.restoreCallingIdentity(identity);
10579 }
10580 }
10581
10582 @Override
Michele0ea7d782019-03-19 14:58:42 -070010583 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010584 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010585 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010586 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10587 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010588 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010589 }
Michelecea4cf22018-12-21 15:00:11 -080010590
joonhunshin4ac60942023-11-15 15:23:39 +000010591 enforceTelephonyFeatureWithException(callingPackage,
10592 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported");
10593
Michelecea4cf22018-12-21 15:00:11 -080010594 final long identity = Binder.clearCallingIdentity();
10595 try {
Michele0ea7d782019-03-19 14:58:42 -070010596 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010597 } finally {
10598 Binder.restoreCallingIdentity(identity);
10599 }
10600 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010601
Michele0ea7d782019-03-19 14:58:42 -070010602 @TelephonyManager.IsMultiSimSupportedResult
10603 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010604 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10605 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10606 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010607 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10608 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010609 }
10610 // Check if the hardware supports multisim functionality. If usage of multisim is not
10611 // supported by the modem, indicate that it is restricted.
10612 PhoneCapability staticCapability =
10613 mPhoneConfigurationManager.getStaticPhoneCapability();
10614 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010615 loge("isMultiSimSupportedInternal: no static configuration available");
10616 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010617 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010618 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010619 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10620 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010621 }
10622 // Check if support of multiple SIMs is restricted by carrier
10623 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010624 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010625 }
10626
Michele0ea7d782019-03-19 14:58:42 -070010627 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010628 }
10629
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010630 /**
10631 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010632 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10633 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10634 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010635 * @param numOfSims number of active sims we want to switch to
10636 */
10637 @Override
10638 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010639 if (numOfSims == 1) {
10640 enforceModifyPermission();
10641 } else {
10642 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10643 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10644 }
joonhunshin4ac60942023-11-15 15:23:39 +000010645
10646 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10647 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig");
10648
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010649 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010650
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010651 try {
Michele30b57b22019-03-01 12:01:14 -080010652 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010653 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010654 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10655 return;
10656 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010657 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10658 } finally {
10659 Binder.restoreCallingIdentity(identity);
10660 }
10661 }
10662
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010663 @Override
10664 public boolean isApplicationOnUicc(int subId, int appType) {
10665 enforceReadPrivilegedPermission("isApplicationOnUicc");
joonhunshin4ac60942023-11-15 15:23:39 +000010666
10667 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10668 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc");
10669
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010670 Phone phone = getPhone(subId);
10671 if (phone == null) {
10672 return false;
10673 }
10674 final long identity = Binder.clearCallingIdentity();
10675 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010676 UiccPort uiccPort = phone.getUiccPort();
10677 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010678 return false;
10679 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010680 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010681 if (uiccProfile == null) {
10682 return false;
10683 }
10684 if (TelephonyManager.APPTYPE_SIM <= appType
10685 && appType <= TelephonyManager.APPTYPE_ISIM) {
10686 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10687 }
10688 return false;
10689 } finally {
10690 Binder.restoreCallingIdentity(identity);
10691 }
10692 }
10693
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010694 /**
chen xub4baa772019-04-03 10:23:41 -070010695 * Get whether making changes to modem configurations will trigger reboot.
10696 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010697 */
10698 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010699 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10700 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010701 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010702 mApp, subId, callingPackage, callingFeatureId,
10703 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010704 return false;
10705 }
joonhunshin4ac60942023-11-15 15:23:39 +000010706
10707 enforceTelephonyFeatureWithException(callingPackage,
10708 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
10709 "doesSwitchMultiSimConfigTriggerReboot");
10710
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010711 final long identity = Binder.clearCallingIdentity();
10712 try {
10713 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10714 } finally {
10715 Binder.restoreCallingIdentity(identity);
10716 }
10717 }
10718
Nathan Harold29f5f052019-02-15 13:41:57 -080010719 private void updateModemStateMetrics() {
10720 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10721 // TODO: check the state for each modem if the api is ready.
10722 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10723 }
10724
Pengquan Meng3889a572019-01-23 11:16:29 -080010725 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010726 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010727 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010728 // Verify that the callingPackage belongs to the calling UID
10729 mApp.getSystemService(AppOpsManager.class)
10730 .checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000010731
10732 enforceTelephonyFeatureWithException(callingPackage,
10733 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping");
10734
Pengquan Meng3889a572019-01-23 11:16:29 -080010735 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010736 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010737 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010738 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10739 if (slotInfos != null) {
10740 for (int i = 0; i < slotInfos.length; i++) {
10741 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10742 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10743 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10744 portInfo.getLogicalSlotIndex()));
10745 }
10746 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010747 }
10748 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010749 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010750 } finally {
10751 Binder.restoreCallingIdentity(identity);
10752 }
10753 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010754
10755 /**
10756 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010757 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010758 */
jimsunf9ec1622022-09-13 21:18:43 +080010759 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010760 @Override
10761 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010762 return getHalVersion(HAL_SERVICE_RADIO);
10763 }
10764
10765 /**
10766 * Get the HAL Version of a specific service
10767 */
10768 @Override
10769 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010770 Phone phone = getDefaultPhone();
10771 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010772 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010773 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10774 return hv.major * 100 + hv.minor;
10775 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010776
10777 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010778 * Get the current calling package name.
sangyun097dcf72024-01-04 10:35:49 +090010779 *
10780 * @return the current calling package name, or null if there is no known package.
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010781 */
10782 @Override
sangyun097dcf72024-01-04 10:35:49 +090010783 public @Nullable String getCurrentPackageName() {
10784 PackageManager pm = mApp.getPackageManager();
10785 String[] packageNames = pm == null ? null : pm.getPackagesForUid(Binder.getCallingUid());
10786 return packageNames == null ? null : packageNames[0];
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010787 }
10788
10789 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010790 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10791 * corresponding network requests on a subId.
10792 *
10793 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010794 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010795 * 2) APN is un-metered for this subscription, or
10796 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010797 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010798 *
10799 * @return whether data is allowed for a apn type.
10800 *
10801 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010802 */
10803 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010804 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010805 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10806 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010807
joonhunshin4ac60942023-11-15 15:23:39 +000010808 enforceTelephonyFeatureWithException(callingPackage,
10809 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn");
10810
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010811 // Now that all security checks passes, perform the operation as ourselves.
10812 final long identity = Binder.clearCallingIdentity();
10813 try {
10814 Phone phone = getPhone(subId);
10815 if (phone == null) return false;
10816
Jack Yu27422a52022-03-21 10:38:05 -070010817 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010818 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010819 isMetered = phone.getDataNetworkController().getDataConfigManager()
10820 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10821 phone.getServiceState().getDataRoaming());
10822 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010823 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010824 } finally {
10825 Binder.restoreCallingIdentity(identity);
10826 }
10827 }
10828
10829 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010830 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010831 enforceReadPrivilegedPermission("isApnMetered");
10832
joonhunshin4ac60942023-11-15 15:23:39 +000010833 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10834 PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered");
10835
Malcolm Chene5ad5792019-04-18 13:51:02 -070010836 // Now that all security checks passes, perform the operation as ourselves.
10837 final long identity = Binder.clearCallingIdentity();
10838 try {
10839 Phone phone = getPhone(subId);
10840 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010841 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10842 DataUtils.apnTypeToNetworkCapability(apnType),
10843 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010844 } finally {
10845 Binder.restoreCallingIdentity(identity);
10846 }
10847 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010848
10849 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010850 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10851 int subscriptionId, IBooleanConsumer resultCallback) {
10852 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +000010853
10854 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10855 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels");
10856
Hall Liu73f5d362020-01-20 13:42:00 -080010857 long token = Binder.clearCallingIdentity();
10858 try {
10859 Phone phone = getPhone(subscriptionId);
10860 if (phone == null) {
10861 try {
10862 if (resultCallback != null) {
10863 resultCallback.accept(false);
10864 }
10865 } catch (RemoteException e) {
10866 // ignore
10867 }
10868 return;
10869 }
10870 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10871 Pair.create(specifiers, (x) -> {
10872 try {
10873 if (resultCallback != null) {
10874 resultCallback.accept(x);
10875 }
10876 } catch (RemoteException e) {
10877 // ignore
10878 }
10879 });
10880 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10881 } finally {
10882 Binder.restoreCallingIdentity(token);
10883 }
10884 }
10885
10886 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010887 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10888 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010889 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010890 mApp, subId, "getSystemSelectionChannels");
joonhunshin4ac60942023-11-15 15:23:39 +000010891
10892 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10893 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels");
10894
Sarah Chin679c08a2020-11-18 13:39:35 -080010895 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10896 final long identity = Binder.clearCallingIdentity();
10897 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010898 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10899 if (result instanceof IllegalStateException) {
10900 throw (IllegalStateException) result;
10901 }
10902 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010903 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10904 return specifiers;
10905 } finally {
10906 Binder.restoreCallingIdentity(identity);
10907 }
10908 }
10909
10910 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010911 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010912 enforceReadPrivilegedPermission("isMvnoMatched");
joonhunshin4ac60942023-11-15 15:23:39 +000010913
10914 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10915 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched");
10916
Jack Yu8b766fc2022-03-21 09:42:33 -070010917 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010918 }
10919
10920 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010921 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10922 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010923 if (callingPackage == null) {
10924 callingPackage = getCurrentPackageName();
10925 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010926 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10927 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010928 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10929 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010930 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10931 }
10932 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10933 Intent intent = new Intent();
10934 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10935 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10936 // Bring up choose default SMS subscription dialog right now
10937 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10938 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10939 mApp.startActivity(intent);
10940 }
chen xud5ca2d52019-05-28 15:20:57 -070010941
10942 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010943 public void showSwitchToManagedProfileDialog() {
10944 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000010945 try {
10946 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
10947 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
10948 // for work telephony.
10949 Intent intent = new Intent(Intent.ACTION_SENDTO);
10950 intent.setData(Uri.parse("smsto:"));
10951 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10952 mApp.startActivity(intent);
10953 } catch (ActivityNotFoundException e) {
10954 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
10955 Intent intent = new Intent();
10956 intent.setClass(mApp, ErrorDialogActivity.class);
10957 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10958 mApp.startActivity(intent);
10959 }
Ayush Sharma787854b2022-12-12 14:55:02 +000010960 }
10961
10962 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010963 public String getMmsUAProfUrl(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000010964 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10965 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl");
10966
chen xud5ca2d52019-05-28 15:20:57 -070010967 //TODO investigate if this API should require proper permission check in R b/133791609
10968 final long identity = Binder.clearCallingIdentity();
10969 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010970 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10971 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10972 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10973 return carrierUAProfUrl;
10974 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010975 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10976 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010977 } finally {
10978 Binder.restoreCallingIdentity(identity);
10979 }
10980 }
10981
10982 @Override
10983 public String getMmsUserAgent(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000010984 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10985 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent");
10986
chen xud5ca2d52019-05-28 15:20:57 -070010987 //TODO investigate if this API should require proper permission check in R b/133791609
10988 final long identity = Binder.clearCallingIdentity();
10989 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010990 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10991 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10992 if (!TextUtils.isEmpty(carrierUserAgent)) {
10993 return carrierUserAgent;
10994 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010995 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10996 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010997 } finally {
10998 Binder.restoreCallingIdentity(identity);
10999 }
11000 }
Jack Yub07d4972019-05-28 16:12:25 -070011001
11002 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070011003 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
11004 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070011005
joonhunshin4ac60942023-11-15 15:23:39 +000011006 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11007 PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled");
11008
Jack Yub07d4972019-05-28 16:12:25 -070011009 final long identity = Binder.clearCallingIdentity();
11010 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011011 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070011012 if (phone == null) return false;
11013
Ling Maf188d502022-09-16 15:22:36 -070011014 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070011015 } finally {
11016 Binder.restoreCallingIdentity(identity);
11017 }
11018 }
11019
11020 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080011021 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070011022 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080011023 enforceModifyPermission();
11024
joonhunshin4ac60942023-11-15 15:23:39 +000011025 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11026 PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled");
11027
changbettyd5c246e2019-12-24 15:40:37 +080011028 final long identity = Binder.clearCallingIdentity();
11029 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011030 Phone phone = getPhone(subscriptionId);
11031 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080011032
Ling Maf188d502022-09-16 15:22:36 -070011033 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080011034 } finally {
11035 Binder.restoreCallingIdentity(identity);
11036 }
11037 }
11038
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011039 /**
Hall Liu746e03c2020-09-25 11:13:49 -070011040 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011041 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
11042 * otherwise.
11043 */
11044 @Override
11045 public void setCepEnabled(boolean isCepEnabled) {
11046 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
11047
11048 final long identity = Binder.clearCallingIdentity();
11049 try {
11050 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
11051 for (Phone phone : PhoneFactory.getPhones()) {
11052 Phone defaultPhone = phone.getImsPhone();
11053 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
11054 ImsPhone imsPhone = (ImsPhone) defaultPhone;
11055 ImsPhoneCallTracker imsPhoneCallTracker =
11056 (ImsPhoneCallTracker) imsPhone.getCallTracker();
11057 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
11058 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
11059 + imsPhone.getMsisdn());
11060 }
11061 }
11062 } finally {
11063 Binder.restoreCallingIdentity(identity);
11064 }
11065 }
allenwtsu46dcc572020-01-08 18:24:03 +080011066
11067 /**
11068 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
11069 *
11070 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
11071 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
11072 * before being read.
11073 */
11074 @Override
11075 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
11076 isCompressed) {
11077 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11078 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011079 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11080 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11081 }
joonhunshin4ac60942023-11-15 15:23:39 +000011082
11083 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11084 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11085 Binder.getCallingUserHandle())) {
11086 if (!isImsAvailableOnDevice()) {
11087 // ProvisioningManager can not handle ServiceSpecificException.
11088 // Throw the IllegalStateException and annotate ProvisioningManager.
11089 throw new IllegalStateException("IMS not available on device.");
11090 }
11091 } else {
11092 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11093 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11094 "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011095 }
11096
11097 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080011098 try {
Hui Wang761a6682020-10-31 05:12:53 +000011099 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
11100 } finally {
11101 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080011102 }
11103 }
zoey chene02881a2019-12-30 16:11:23 +080011104
11105 @Override
11106 public boolean isIccLockEnabled(int subId) {
11107 enforceReadPrivilegedPermission("isIccLockEnabled");
11108
joonhunshin4ac60942023-11-15 15:23:39 +000011109 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11110 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled");
11111
zoey chene02881a2019-12-30 16:11:23 +080011112 // Now that all security checks passes, perform the operation as ourselves.
11113 final long identity = Binder.clearCallingIdentity();
11114 try {
11115 Phone phone = getPhone(subId);
11116 if (phone != null && phone.getIccCard() != null) {
11117 return phone.getIccCard().getIccLockEnabled();
11118 } else {
11119 return false;
11120 }
11121 } finally {
11122 Binder.restoreCallingIdentity(identity);
11123 }
11124 }
11125
11126 /**
11127 * Set the ICC pin lock enabled or disabled.
11128 *
11129 * @return an integer representing the status of IccLock enabled or disabled in the following
11130 * three cases:
11131 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
11132 * successfully.
11133 * - Positive number and zero for remaining password attempts.
11134 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11135 *
11136 */
11137 @Override
11138 public int setIccLockEnabled(int subId, boolean enabled, String password) {
11139 enforceModifyPermission();
11140
joonhunshin4ac60942023-11-15 15:23:39 +000011141 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11142 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled");
11143
zoey chene02881a2019-12-30 16:11:23 +080011144 Phone phone = getPhone(subId);
11145 if (phone == null) {
11146 return 0;
11147 }
11148 // Now that all security checks passes, perform the operation as ourselves.
11149 final long identity = Binder.clearCallingIdentity();
11150 try {
11151 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
11152 new Pair<Boolean, String>(enabled, password), phone, null);
11153 return attemptsRemaining;
11154
11155 } catch (Exception e) {
11156 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
11157 } finally {
11158 Binder.restoreCallingIdentity(identity);
11159 }
11160 return 0;
11161 }
11162
11163 /**
11164 * Change the ICC password used in ICC pin lock.
11165 *
11166 * @return an integer representing the status of IccLock changed in the following three cases:
11167 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
11168 * - Positive number and zero for remaining password attempts.
11169 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11170 *
11171 */
11172 @Override
11173 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
11174 enforceModifyPermission();
11175
joonhunshin4ac60942023-11-15 15:23:39 +000011176 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11177 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword");
11178
zoey chene02881a2019-12-30 16:11:23 +080011179 Phone phone = getPhone(subId);
11180 if (phone == null) {
11181 return 0;
11182 }
11183 // Now that all security checks passes, perform the operation as ourselves.
11184 final long identity = Binder.clearCallingIdentity();
11185 try {
11186 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
11187 new Pair<String, String>(oldPassword, newPassword), phone, null);
11188 return attemptsRemaining;
11189
11190 } catch (Exception e) {
11191 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
11192 } finally {
11193 Binder.restoreCallingIdentity(identity);
11194 }
11195 return 0;
11196 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080011197
11198 /**
11199 * Request for receiving user activity notification
11200 */
11201 @Override
11202 public void requestUserActivityNotification() {
11203 if (!mNotifyUserActivity.get()
11204 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
11205 mNotifyUserActivity.set(true);
11206 }
11207 }
11208
11209 /**
11210 * Called when userActivity is signalled in the power manager.
11211 * This is safe to call from any thread, with any window manager locks held or not.
11212 */
11213 @Override
11214 public void userActivity() {
11215 // ***************************************
11216 // * Inherited from PhoneWindowManager *
11217 // ***************************************
11218 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
11219 // WITH ITS LOCKS HELD.
11220 //
11221 // This code must be VERY careful about the locks
11222 // it acquires.
11223 // In fact, the current code acquires way too many,
11224 // and probably has lurking deadlocks.
11225
11226 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
11227 throw new SecurityException("Only the OS may call notifyUserActivity()");
11228 }
11229
11230 if (mNotifyUserActivity.getAndSet(false)) {
11231 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
11232 USER_ACTIVITY_NOTIFICATION_DELAY);
11233 }
11234 }
Malcolm Chen4639c562020-04-13 11:59:40 -070011235
11236 @Override
11237 public boolean canConnectTo5GInDsdsMode() {
11238 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
11239 }
Jack Yud10cdd42020-09-28 20:28:01 -070011240
11241 @Override
11242 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
11243 String callingFeatureId) {
11244 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
11245 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
11246 throw new SecurityException("Requires READ_PHONE_STATE permission.");
11247 }
11248
joonhunshin4ac60942023-11-15 15:23:39 +000011249 enforceTelephonyFeatureWithException(callingPackage,
11250 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns");
11251
Jack Yud10cdd42020-09-28 20:28:01 -070011252 Phone phone = getPhone(subId);
11253 if (phone == null) {
11254 throw new RuntimeException("phone is not available");
11255 }
11256 // Now that all security checks passes, perform the operation as ourselves.
11257 final long identity = Binder.clearCallingIdentity();
11258 try {
11259 return phone.getEquivalentHomePlmns();
11260 } finally {
11261 Binder.restoreCallingIdentity(identity);
11262 }
11263 }
Daniel Bright59e67312020-11-13 11:49:37 -080011264
11265 @Override
11266 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011267 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
joonhunshin4ac60942023-11-15 15:23:39 +000011268 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11269 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
11270 "isRadioInterfaceCapabilitySupported");
11271
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011272 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080011273 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080011274 if (radioInterfaceCapabilities == null) {
11275 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080011276 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011277 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080011278 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011279
Hui Wang641e81c2020-10-12 12:14:23 -070011280 @Override
11281 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
11282 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000011283 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
11284 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11285 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
11286 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11287 Manifest.permission.MODIFY_PHONE_STATE);
joonhunshin4ac60942023-11-15 15:23:39 +000011288
11289 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11290 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest");
11291
Hui Wang641e81c2020-10-12 12:14:23 -070011292 if (DBG) {
11293 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
11294 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
11295 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
11296 }
11297
11298 if (!SubscriptionManager.isValidSubscriptionId(subId)
11299 || appType < TelephonyManager.APPTYPE_UNKNOWN
11300 || appType > TelephonyManager.APPTYPE_ISIM
11301 || nafUrl == null || securityProtocol == null || callback == null) {
11302 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
11303 if (callback != null) {
11304 try {
11305 callback.onAuthenticationFailure(
11306 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
11307 } catch (RemoteException exception) {
11308 log("Fail to notify onAuthenticationFailure due to " + exception);
11309 }
11310 return;
11311 }
11312 }
11313
11314 final long token = Binder.clearCallingIdentity();
11315 try {
11316 getGbaManager(subId).bootstrapAuthenticationRequest(
11317 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011318 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070011319 } finally {
11320 Binder.restoreCallingIdentity(token);
11321 }
11322 }
11323
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011324 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011325 * Attempts to set the radio power state for all phones for thermal reason.
11326 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011327 * requested radio power state will actually be set. See {@link
11328 * PhoneInternalInterface#setRadioPowerForReason} for more details.
11329 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011330 * @param enable {@code true} if trying to turn radio on.
11331 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
11332 * false}.
11333 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011334 private boolean setRadioPowerForThermal(boolean enable) {
11335 boolean isPhoneAvailable = false;
11336 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
11337 Phone phone = PhoneFactory.getPhone(i);
11338 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011339 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011340 isPhoneAvailable = true;
11341 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011342 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011343
11344 // return true if successfully informed the phone object about the thermal radio power
11345 // request.
11346 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011347 }
11348
11349 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011350 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011351 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11352 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11353 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11354 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11355 throw new IllegalArgumentException("modem does not support data throttling");
11356 }
11357
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011358 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11359 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011360 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011361 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11362 }
11363
Sarah Chinecc78c42022-03-31 21:16:48 -070011364 setDataEnabledForReason(
11365 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011366
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011367 if (isDataThrottlingSupported) {
11368 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011369 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011370 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11371 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11372 } else if (thermalMitigationResult
11373 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011374 log("Modem likely does not support data throttling on secondary carrier. Data " +
11375 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11376 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011377 }
11378 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011379 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011380
11381 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011382 }
11383
Jack Nudelman644b91a2021-03-12 14:09:48 -080011384 private static List<String> getThermalMitigationAllowlist(Context context) {
11385 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11386 for (String pckg : context.getResources()
11387 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11388 sThermalMitigationAllowlistedPackages.add(pckg);
11389 }
11390 }
11391
11392 return sThermalMitigationAllowlistedPackages;
11393 }
11394
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011395 private boolean isAnyPhoneInEmergencyState() {
11396 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11397 if (tm.isInEmergencyCall()) {
11398 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11399 return true;
11400 }
11401 for (Phone phone : PhoneFactory.getPhones()) {
11402 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11403 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011404 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11405 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011406 return true;
11407 }
11408 }
11409
11410 return false;
11411 }
11412
Jack Nudelman644b91a2021-03-12 14:09:48 -080011413 /**
11414 * Used by shell commands to add an authorized package name for thermal mitigation.
11415 * @param packageName name of package to be allowlisted
11416 * @param context
11417 */
11418 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11419 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11420 sThermalMitigationAllowlistedPackages.add(packageName);
11421 }
11422
11423 /**
11424 * Used by shell commands to remove an authorized package name for thermal mitigation.
11425 * @param packageName name of package to remove from allowlist
11426 * @param context
11427 */
11428 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11429 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11430 sThermalMitigationAllowlistedPackages.remove(packageName);
11431 }
11432
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011433 /**
11434 * Thermal mitigation request to control functionalities at modem.
11435 *
11436 * @param subId the id of the subscription.
11437 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011438 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011439 *
11440 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11441 */
11442 @Override
11443 @ThermalMitigationResult
11444 public int sendThermalMitigationRequest(
11445 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011446 ThermalMitigationRequest thermalMitigationRequest,
11447 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011448 enforceModifyPermission();
11449
Jack Nudelman644b91a2021-03-12 14:09:48 -080011450 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000011451
11452 enforceTelephonyFeatureWithException(callingPackage,
11453 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest");
11454
Jack Nudelman644b91a2021-03-12 14:09:48 -080011455 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11456 .contains(callingPackage)) {
11457 throw new SecurityException("Calling package must be configured in the device config. "
11458 + "calling package: " + callingPackage);
11459 }
11460
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011461 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11462 final long identity = Binder.clearCallingIdentity();
11463
11464 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11465 try {
11466 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11467 switch (thermalMitigationAction) {
11468 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11469 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011470 handleDataThrottlingRequest(subId,
11471 thermalMitigationRequest.getDataThrottlingRequest(),
11472 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011473 break;
11474 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11475 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11476 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11477 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11478 }
11479
11480 // Ensure that radio is on. If not able to power on due to phone being
11481 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011482 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011483 thermalMitigationResult =
11484 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11485 break;
11486 }
11487
11488 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011489 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011490 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11491 break;
11492 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11493 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11494 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11495 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11496 }
11497
11498 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11499 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011500 Phone phone = getPhone(subId);
11501 if (phone == null) {
11502 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011503 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011504 break;
11505 }
11506
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011507 TelephonyConnectionService service =
11508 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011509 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011510 Log.e(LOG_TAG, "An emergency call is pending");
11511 thermalMitigationResult =
11512 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11513 break;
11514 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011515 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011516 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011517 break;
11518 }
11519 } else {
11520 thermalMitigationResult =
11521 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11522 break;
11523 }
11524
11525 // Turn radio off. If not able to power off due to phone being unavailable,
11526 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011527 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011528 thermalMitigationResult =
11529 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11530 break;
11531 }
11532 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011533 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011534 break;
11535 default:
11536 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11537 + "not exist. Requested action: " + thermalMitigationAction);
11538 }
11539 } catch (IllegalArgumentException e) {
11540 throw e;
11541 } catch (Exception e) {
11542 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11543 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11544 } finally {
11545 Binder.restoreCallingIdentity(identity);
11546 }
11547
11548 if (DBG) {
11549 log("thermalMitigationRequest returning with thermalMitigationResult: "
11550 + thermalMitigationResult);
11551 }
11552
11553 return thermalMitigationResult;
11554 }
Hui Wang641e81c2020-10-12 12:14:23 -070011555
11556 /**
11557 * Set the GbaService Package Name that Telephony will bind to.
11558 *
11559 * @param subId The sim that the GbaService is associated with.
11560 * @param packageName The name of the package to be replaced with.
11561 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11562 */
11563 @Override
11564 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11565 enforceModifyPermission();
11566
11567 final long identity = Binder.clearCallingIdentity();
11568 try {
11569 return getGbaManager(subId).overrideServicePackage(packageName);
11570 } finally {
11571 Binder.restoreCallingIdentity(identity);
11572 }
11573 }
11574
11575 /**
11576 * Return the package name of the currently bound GbaService.
11577 *
11578 * @param subId The sim that the GbaService is associated with.
11579 * @return the package name of the GbaService configuration, null if GBA is not supported.
11580 */
11581 @Override
11582 public String getBoundGbaService(int subId) {
11583 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11584
11585 final long identity = Binder.clearCallingIdentity();
11586 try {
11587 return getGbaManager(subId).getServicePackage();
11588 } finally {
11589 Binder.restoreCallingIdentity(identity);
11590 }
11591 }
11592
11593 /**
11594 * Set the release time for telephony to unbind GbaService.
11595 *
11596 * @param subId The sim that the GbaService is associated with.
11597 * @param interval The release time to unbind GbaService by millisecond.
11598 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11599 */
11600 @Override
11601 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11602 enforceModifyPermission();
11603
11604 final long identity = Binder.clearCallingIdentity();
11605 try {
11606 return getGbaManager(subId).overrideReleaseTime(interval);
11607 } finally {
11608 Binder.restoreCallingIdentity(identity);
11609 }
11610 }
11611
11612 /**
11613 * Return the release time for telephony to unbind GbaService.
11614 *
11615 * @param subId The sim that the GbaService is associated with.
11616 * @return The release time to unbind GbaService by millisecond.
11617 */
11618 @Override
11619 public int getGbaReleaseTime(int subId) {
11620 enforceReadPrivilegedPermission("getGbaReleaseTime");
11621
11622 final long identity = Binder.clearCallingIdentity();
11623 try {
11624 return getGbaManager(subId).getReleaseTime();
11625 } finally {
11626 Binder.restoreCallingIdentity(identity);
11627 }
11628 }
11629
11630 private GbaManager getGbaManager(int subId) {
11631 GbaManager instance = GbaManager.getInstance(subId);
11632 if (instance == null) {
11633 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11634 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11635 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11636 }
11637 return instance;
11638 }
Hui Wang761a6682020-10-31 05:12:53 +000011639
11640 /**
11641 * indicate whether the device and the carrier can support
11642 * RCS VoLTE single registration.
11643 */
11644 @Override
11645 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011646 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11647 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11648 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11649 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011650
11651 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11652 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11653 }
11654
11655 final long identity = Binder.clearCallingIdentity();
11656 try {
11657 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11658 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011659 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11660 if (isCapable != null) {
11661 return isCapable;
11662 }
Hui Wang761a6682020-10-31 05:12:53 +000011663 }
Hui Wang67af90e2021-06-04 16:57:15 -070011664 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11665 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011666 } finally {
11667 Binder.restoreCallingIdentity(identity);
11668 }
11669 }
11670
11671 /**
11672 * Register RCS provisioning callback.
11673 */
11674 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011675 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011676 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011677 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011678 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011679 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11680 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011681
11682 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11683 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11684 }
joonhunshin4ac60942023-11-15 15:23:39 +000011685 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11686 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11687 Binder.getCallingUserHandle())) {
11688 if (!isImsAvailableOnDevice()) {
11689 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11690 "IMS not available on device.");
11691 }
11692 } else {
11693 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11694 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011695 }
11696
11697 final long identity = Binder.clearCallingIdentity();
11698 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011699 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011700 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011701 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11702 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011703 }
Hui Wang761a6682020-10-31 05:12:53 +000011704 } finally {
11705 Binder.restoreCallingIdentity(identity);
11706 }
11707 }
11708
11709 /**
11710 * Unregister RCS provisioning callback.
11711 */
11712 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011713 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011714 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011715 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011716 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011717 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11718 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011719
11720 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11721 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11722 }
joonhunshin4ac60942023-11-15 15:23:39 +000011723
11724 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11725 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11726 Binder.getCallingUserHandle())) {
11727 if (!isImsAvailableOnDevice()) {
11728 // operation failed silently
11729 Rlog.w(LOG_TAG, "IMS not available on device.");
11730 return;
11731 }
11732 } else {
11733 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11734 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11735 "unregisterRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011736 }
11737
11738 final long identity = Binder.clearCallingIdentity();
11739 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011740 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011741 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011742 } finally {
11743 Binder.restoreCallingIdentity(identity);
11744 }
11745 }
11746
11747 /**
11748 * trigger RCS reconfiguration.
11749 */
11750 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011751 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11752 "triggerRcsReconfiguration",
11753 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011754
11755 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11756 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11757 }
joonhunshin4ac60942023-11-15 15:23:39 +000011758 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11759 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11760 Binder.getCallingUserHandle())) {
11761 if (!isImsAvailableOnDevice()) {
11762 // ProvisioningManager can not handle ServiceSpecificException.
11763 // Throw the IllegalStateException and annotate ProvisioningManager.
11764 throw new IllegalStateException("IMS not available on device.");
11765 }
11766 } else {
11767 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11768 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011769 }
11770
11771 final long identity = Binder.clearCallingIdentity();
11772 try {
11773 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11774 } finally {
11775 Binder.restoreCallingIdentity(identity);
11776 }
11777 }
11778
11779 /**
11780 * Provide the client configuration parameters of the RCS application.
11781 */
11782 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011783 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11784 "setRcsClientConfiguration",
11785 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011786
11787 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11788 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11789 }
joonhunshin4ac60942023-11-15 15:23:39 +000011790 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11791 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11792 Binder.getCallingUserHandle())) {
11793 if (!isImsAvailableOnDevice()) {
11794 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11795 "IMS not available on device.");
11796 }
11797 } else {
11798 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11799 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011800 }
11801
11802 final long identity = Binder.clearCallingIdentity();
11803
11804 try {
11805 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11806 if (configBinder == null) {
11807 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011808 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11809 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011810 } else {
11811 configBinder.setRcsClientConfiguration(rcc);
11812 }
joonhunshin3e154242021-09-17 06:33:39 +000011813
11814 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11815 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011816 } catch (RemoteException e) {
11817 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011818 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11819 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011820 } finally {
11821 Binder.restoreCallingIdentity(identity);
11822 }
11823 }
11824
11825 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011826 * Enables or disables the test mode for RCS VoLTE single registration.
11827 */
11828 @Override
11829 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11830 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11831 "setRcsSingleRegistrationTestModeEnabled");
11832
11833 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11834 }
11835
11836 /**
11837 * Gets the test mode for RCS VoLTE single registration.
11838 */
11839 @Override
11840 public boolean getRcsSingleRegistrationTestModeEnabled() {
11841 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11842 "getRcsSingleRegistrationTestModeEnabled");
11843
11844 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11845 }
11846
11847 /**
Hui Wang761a6682020-10-31 05:12:53 +000011848 * Overrides the config of RCS VoLTE single registration enabled for the device.
11849 */
11850 @Override
11851 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11852 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11853 "setDeviceSingleRegistrationEnabledOverride");
11854 enforceModifyPermission();
11855
11856 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11857 : Boolean.parseBoolean(enabledStr);
11858 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011859 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011860 }
11861
11862 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011863 * Sends a device to device communication message. Only usable via shell.
11864 * @param message message to send.
11865 * @param value message value.
11866 */
11867 @Override
11868 public void sendDeviceToDeviceMessage(int message, int value) {
11869 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011870 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011871 enforceModifyPermission();
11872
11873 final long identity = Binder.clearCallingIdentity();
11874 try {
11875 TelephonyConnectionService service =
11876 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11877 if (service == null) {
11878 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11879 return;
11880 }
11881 service.sendTestDeviceToDeviceMessage(message, value);
11882 } finally {
11883 Binder.restoreCallingIdentity(identity);
11884 }
11885 }
11886
Tyler Gunnbabbda02021-02-10 11:05:02 -080011887 /**
11888 * Sets the specified device to device transport active.
11889 * @param transport The transport to set active.
11890 */
11891 @Override
11892 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11893 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11894 "setActiveDeviceToDeviceTransport");
11895 enforceModifyPermission();
11896
11897 final long identity = Binder.clearCallingIdentity();
11898 try {
11899 TelephonyConnectionService service =
11900 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11901 if (service == null) {
11902 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11903 return;
11904 }
11905 service.setActiveDeviceToDeviceTransport(transport);
11906 } finally {
11907 Binder.restoreCallingIdentity(identity);
11908 }
11909 }
Tyler Gunn92479152021-01-20 16:30:10 -080011910
Tyler Gunnd4339262021-05-03 14:46:49 -070011911 @Override
11912 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11913 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11914 "setDeviceToDeviceForceEnabled");
11915
11916 final long identity = Binder.clearCallingIdentity();
11917 try {
11918 Arrays.stream(PhoneFactory.getPhones()).forEach(
11919 p -> {
11920 Phone thePhone = p.getImsPhone();
11921 if (thePhone != null && thePhone instanceof ImsPhone) {
11922 ImsPhone imsPhone = (ImsPhone) thePhone;
11923 CallTracker tracker = imsPhone.getCallTracker();
11924 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11925 ImsPhoneCallTracker imsPhoneCallTracker =
11926 (ImsPhoneCallTracker) tracker;
11927 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11928 }
11929 }
11930 }
11931 );
11932 } finally {
11933 Binder.restoreCallingIdentity(identity);
11934 }
11935 }
11936
Tyler Gunn92479152021-01-20 16:30:10 -080011937 /**
Hui Wang761a6682020-10-31 05:12:53 +000011938 * Gets the config of RCS VoLTE single registration enabled for the device.
11939 */
11940 @Override
11941 public boolean getDeviceSingleRegistrationEnabled() {
11942 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11943 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11944 }
11945
11946 /**
11947 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11948 */
11949 @Override
11950 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11951 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11952 "setCarrierSingleRegistrationEnabledOverride");
11953 enforceModifyPermission();
11954
11955 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11956 : Boolean.parseBoolean(enabledStr);
11957 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11958 subId, enabled);
11959 }
11960
11961 /**
11962 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11963 */
11964 @Override
11965 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11966 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11967 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11968 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011969
11970 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011971 * Overrides the ims feature validation result
11972 */
11973 @Override
11974 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11975 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11976 "setImsFeatureValidationOverride");
11977
11978 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11979 : Boolean.parseBoolean(enabledStr);
11980 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11981 subId, enabled);
11982 }
11983
11984 /**
11985 * Gets the ims feature validation override value
11986 */
11987 @Override
11988 public boolean getImsFeatureValidationOverride(int subId) {
11989 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11990 "getImsFeatureValidationOverride");
11991 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11992 }
11993
11994 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011995 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11996 * their mobile plan.
11997 */
11998 @Override
11999 public String getMobileProvisioningUrl() {
12000 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
12001 final long identity = Binder.clearCallingIdentity();
12002 try {
12003 return getDefaultPhone().getMobileProvisioningUrl();
12004 } finally {
12005 Binder.restoreCallingIdentity(identity);
12006 }
12007 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012008
James.cf Linbcdf8b32021-01-14 16:44:13 +080012009 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080012010 * Get the EAB contact from the EAB database.
12011 */
12012 @Override
12013 public String getContactFromEab(String contact) {
12014 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
12015 enforceModifyPermission();
12016 final long identity = Binder.clearCallingIdentity();
12017 try {
12018 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
12019 } finally {
12020 Binder.restoreCallingIdentity(identity);
12021 }
12022 }
12023
12024 /**
Calvin Pana1434322021-07-01 19:27:01 +080012025 * Get the EAB capability from the EAB database.
12026 */
12027 @Override
12028 public String getCapabilityFromEab(String contact) {
12029 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
12030 enforceModifyPermission();
12031 final long identity = Binder.clearCallingIdentity();
12032 try {
12033 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
12034 } finally {
12035 Binder.restoreCallingIdentity(identity);
12036 }
12037 }
12038
12039 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080012040 * Remove the EAB contacts from the EAB database.
12041 */
12042 @Override
12043 public int removeContactFromEab(int subId, String contacts) {
12044 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
12045 enforceModifyPermission();
12046 final long identity = Binder.clearCallingIdentity();
12047 try {
12048 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
12049 } finally {
12050 Binder.restoreCallingIdentity(identity);
12051 }
12052 }
12053
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012054 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080012055 public boolean getDeviceUceEnabled() {
12056 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
12057 final long identity = Binder.clearCallingIdentity();
12058 try {
12059 return mApp.getDeviceUceEnabled();
12060 } finally {
12061 Binder.restoreCallingIdentity(identity);
12062 }
12063 }
12064
12065 @Override
12066 public void setDeviceUceEnabled(boolean isEnabled) {
12067 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
12068 final long identity = Binder.clearCallingIdentity();
12069 try {
12070 mApp.setDeviceUceEnabled(isEnabled);
12071 } finally {
12072 Binder.restoreCallingIdentity(identity);
12073 }
12074 }
12075
Brad Ebinger14d467f2021-02-12 06:18:28 +000012076 /**
12077 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
12078 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12079 */
12080 // Used for SHELL command only right now.
12081 @Override
12082 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
12083 List<String> featureTags) {
12084 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12085 "addUceRegistrationOverrideShell");
12086 final long identity = Binder.clearCallingIdentity();
12087 try {
12088 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
12089 new ArraySet<>(featureTags));
12090 } catch (ImsException e) {
12091 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12092 } finally {
12093 Binder.restoreCallingIdentity(identity);
12094 }
12095 }
12096
12097 /**
12098 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
12099 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12100 */
12101 // Used for SHELL command only right now.
12102 @Override
12103 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
12104 List<String> featureTags) {
12105 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12106 "removeUceRegistrationOverrideShell");
12107 final long identity = Binder.clearCallingIdentity();
12108 try {
12109 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
12110 new ArraySet<>(featureTags));
12111 } catch (ImsException e) {
12112 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12113 } finally {
12114 Binder.restoreCallingIdentity(identity);
12115 }
12116 }
12117
12118 /**
12119 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
12120 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12121 */
12122 // Used for SHELL command only right now.
12123 @Override
12124 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
12125 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12126 "clearUceRegistrationOverrideShell");
12127 final long identity = Binder.clearCallingIdentity();
12128 try {
12129 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
12130 } catch (ImsException e) {
12131 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12132 } finally {
12133 Binder.restoreCallingIdentity(identity);
12134 }
12135 }
12136
12137 /**
12138 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12139 */
12140 // Used for SHELL command only right now.
12141 @Override
12142 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
12143 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12144 "getLatestRcsContactUceCapabilityShell");
12145 final long identity = Binder.clearCallingIdentity();
12146 try {
12147 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
12148 } catch (ImsException e) {
12149 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12150 } finally {
12151 Binder.restoreCallingIdentity(identity);
12152 }
12153 }
12154
12155 /**
12156 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
12157 * device does not have an active PUBLISH.
12158 */
12159 // Used for SHELL command only right now.
12160 @Override
12161 public String getLastUcePidfXmlShell(int subId) {
12162 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
12163 final long identity = Binder.clearCallingIdentity();
12164 try {
12165 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
12166 } catch (ImsException e) {
12167 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12168 } finally {
12169 Binder.restoreCallingIdentity(identity);
12170 }
12171 }
12172
James.cf Line8713a42021-04-29 16:04:26 +080012173 /**
12174 * Remove UCE requests cannot be sent to the network status.
12175 */
12176 // Used for SHELL command only right now.
12177 @Override
12178 public boolean removeUceRequestDisallowedStatus(int subId) {
12179 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
12180 final long identity = Binder.clearCallingIdentity();
12181 try {
12182 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
12183 } catch (ImsException e) {
12184 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12185 } finally {
12186 Binder.restoreCallingIdentity(identity);
12187 }
12188 }
12189
James.cf Lin18bb9002021-05-25 01:37:38 +080012190 /**
12191 * Remove UCE requests cannot be sent to the network status.
12192 */
12193 // Used for SHELL command only.
12194 @Override
12195 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
12196 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
12197 final long identity = Binder.clearCallingIdentity();
12198 try {
12199 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
12200 } catch (ImsException e) {
12201 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12202 } finally {
12203 Binder.restoreCallingIdentity(identity);
12204 }
12205 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000012206
James.cf Lin4b784aa2021-01-31 03:25:15 +080012207 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012208 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12209 String callingPackage) {
12210 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12211 mApp, subId, "setSignalStrengthUpdateRequest");
12212
joonhunshin4ac60942023-11-15 15:23:39 +000012213 enforceTelephonyFeatureWithException(callingPackage,
12214 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest");
12215
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012216 final int callingUid = Binder.getCallingUid();
12217 // Verify that tha callingPackage belongs to the calling UID
12218 mApp.getSystemService(AppOpsManager.class)
12219 .checkPackage(callingUid, callingPackage);
12220
Rambo Wang3607f502021-02-01 21:51:40 -080012221 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012222
12223 final long identity = Binder.clearCallingIdentity();
12224 try {
12225 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
12226 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12227
12228 if (result instanceof IllegalStateException) {
12229 throw (IllegalStateException) result;
12230 }
12231 } finally {
12232 Binder.restoreCallingIdentity(identity);
12233 }
12234 }
12235
12236 @Override
12237 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12238 String callingPackage) {
12239 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12240 mApp, subId, "clearSignalStrengthUpdateRequest");
12241
joonhunshin4ac60942023-11-15 15:23:39 +000012242 enforceTelephonyFeatureWithException(callingPackage,
12243 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest");
12244
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012245 final int callingUid = Binder.getCallingUid();
12246 // Verify that tha callingPackage belongs to the calling UID
12247 mApp.getSystemService(AppOpsManager.class)
12248 .checkPackage(callingUid, callingPackage);
12249
12250 final long identity = Binder.clearCallingIdentity();
12251 try {
12252 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
12253 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12254
12255 if (result instanceof IllegalStateException) {
12256 throw (IllegalStateException) result;
12257 }
12258 } finally {
12259 Binder.restoreCallingIdentity(identity);
12260 }
12261 }
12262
Rambo Wang3607f502021-02-01 21:51:40 -080012263 private static void validateSignalStrengthUpdateRequest(Context context,
12264 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012265 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
12266 // phone/system process do not have further restriction on request
12267 return;
12268 }
12269
12270 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080012271 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012272 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080012273 context.enforceCallingOrSelfPermission(
12274 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
12275 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012276 }
12277
12278 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000012279 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012280 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012281 || info.isEnabled()) {
12282 throw new IllegalArgumentException(
12283 "Only system can set hide fields in SignalThresholdInfo");
12284 }
12285
12286 // Thresholds length for each RAN need in range. This has been validated in
12287 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
12288 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
12289 final int[] thresholds = info.getThresholds();
12290 Objects.requireNonNull(thresholds);
12291 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
12292 || thresholds.length
12293 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
12294 throw new IllegalArgumentException(
12295 "thresholds length is out of range: " + thresholds.length);
12296 }
12297 }
12298 }
SongFerngWang8236caa2021-01-17 21:51:44 +080012299
12300 /**
12301 * Gets the current phone capability.
12302 *
12303 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
12304 * @return the PhoneCapability which describes the data connection capability of modem.
12305 * It's used to evaluate possible phone config change, for example from single
12306 * SIM device to multi-SIM device.
12307 */
12308 @Override
12309 public PhoneCapability getPhoneCapability() {
12310 enforceReadPrivilegedPermission("getPhoneCapability");
joonhunshin4ac60942023-11-15 15:23:39 +000012311
12312 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12313 PackageManager.FEATURE_TELEPHONY, "getPhoneCapability");
12314
SongFerngWang8236caa2021-01-17 21:51:44 +080012315 final long identity = Binder.clearCallingIdentity();
12316 try {
12317 return mPhoneConfigurationManager.getCurrentPhoneCapability();
12318 } finally {
12319 Binder.restoreCallingIdentity(identity);
12320 }
12321 }
Michele Berionne5e411512020-11-13 02:36:59 +000012322
12323 /**
12324 * Prepare TelephonyManager for an unattended reboot. The reboot is
12325 * required to be done shortly after the API is invoked.
12326 */
12327 @Override
12328 @TelephonyManager.PrepareUnattendedRebootResult
12329 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012330 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000012331 enforceRebootPermission();
12332
joonhunshin4ac60942023-11-15 15:23:39 +000012333 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12334 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot");
12335
Michele Berionne5e411512020-11-13 02:36:59 +000012336 final long identity = Binder.clearCallingIdentity();
12337 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012338 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000012339 } finally {
12340 Binder.restoreCallingIdentity(identity);
12341 }
12342 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012343
12344 /**
12345 * Request to get the current slicing configuration including URSP rules and
12346 * NSSAIs (configured, allowed and rejected).
12347 *
12348 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
12349 */
12350 @Override
12351 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000012352 TelephonyPermissions
12353 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
12354 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012355
joonhunshin4ac60942023-11-15 15:23:39 +000012356 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12357 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
12358 "getSlicingConfig");
12359
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012360 final long identity = Binder.clearCallingIdentity();
12361 try {
12362 Phone phone = getDefaultPhone();
12363 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
12364 } finally {
12365 Binder.restoreCallingIdentity(identity);
12366 }
12367 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012368
12369 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070012370 * Check whether the given premium capability is available for purchase from the carrier.
12371 *
12372 * @param capability The premium capability to check.
12373 * @param subId The subId to check the premium capability for.
12374 *
12375 * @return Whether the given premium capability is available to purchase.
12376 */
12377 @Override
12378 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
12379 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12380 mApp, "isPremiumCapabilityAvailableForPurchase")) {
12381 log("Premium capability "
12382 + TelephonyManager.convertPremiumCapabilityToString(capability)
12383 + " is not available for purchase due to missing permissions.");
12384 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
12385 + "permission READ_BASIC_PHONE_STATE.");
12386 }
12387
joonhunshin4ac60942023-11-15 15:23:39 +000012388 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12389 PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase");
12390
Sarah Chin2ec39f62022-08-31 17:03:26 -070012391 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080012392 if (phone == null) {
12393 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12394 return false;
12395 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012396 final long identity = Binder.clearCallingIdentity();
12397 try {
Sarah Chincc5446f2023-10-23 17:57:19 -070012398 return SlicePurchaseController.getInstance(phone, mFeatureFlags)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012399 .isPremiumCapabilityAvailableForPurchase(capability);
12400 } finally {
12401 Binder.restoreCallingIdentity(identity);
12402 }
12403 }
12404
12405 /**
12406 * Purchase the given premium capability from the carrier.
12407 *
12408 * @param capability The premium capability to purchase.
12409 * @param callback The result of the purchase request.
12410 * @param subId The subId to purchase the premium capability for.
12411 */
12412 @Override
12413 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12414 log("purchasePremiumCapability: capability="
12415 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12416 + getCurrentPackageName());
12417
12418 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12419 mApp, "purchasePremiumCapability")) {
12420 log("purchasePremiumCapability "
12421 + TelephonyManager.convertPremiumCapabilityToString(capability)
12422 + " failed due to missing permissions.");
12423 throw new SecurityException("purchasePremiumCapability requires permission "
12424 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012425 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12426 mApp, "purchasePremiumCapability")) {
12427 log("purchasePremiumCapability "
12428 + TelephonyManager.convertPremiumCapabilityToString(capability)
12429 + " failed due to missing permissions.");
12430 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012431 }
12432
joonhunshin4ac60942023-11-15 15:23:39 +000012433 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12434 PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability");
12435
Sarah Chin2ec39f62022-08-31 17:03:26 -070012436 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012437 if (phone == null) {
12438 try {
12439 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12440 callback.accept(result);
12441 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12442 } catch (RemoteException e) {
12443 String logStr = "Purchase premium capability "
12444 + TelephonyManager.convertPremiumCapabilityToString(capability)
12445 + " failed due to RemoteException handling null phone: " + e;
12446 if (DBG) log(logStr);
12447 AnomalyReporter.reportAnomaly(
12448 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12449 }
12450 return;
12451 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012452
12453 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012454 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012455 callingProcess = mApp.getPackageManager().getApplicationInfo(
12456 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070012457 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012458 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012459 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012460
12461 boolean isVisible = false;
12462 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12463 if (am != null) {
12464 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12465 if (processes != null) {
12466 for (ActivityManager.RunningAppProcessInfo process : processes) {
12467 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070012468 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080012469 if (process.processName.equals(callingProcess) && process.importance
12470 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12471 isVisible = true;
12472 break;
12473 }
12474 }
12475 }
12476 }
12477
12478 if (!isVisible) {
12479 try {
12480 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12481 callback.accept(result);
12482 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12483 } catch (RemoteException e) {
12484 String logStr = "Purchase premium capability "
12485 + TelephonyManager.convertPremiumCapabilityToString(capability)
12486 + " failed due to RemoteException handling background application: " + e;
12487 if (DBG) log(logStr);
12488 AnomalyReporter.reportAnomaly(
12489 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12490 }
12491 return;
12492 }
12493
Sarah Chin71b3a852022-09-28 15:54:19 -070012494 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012495 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012496 }
12497
12498 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012499 * Register an IMS connection state callback
12500 */
12501 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012502 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12503 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012504 if (feature == ImsFeature.FEATURE_MMTEL) {
12505 // ImsMmTelManager
12506 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12507 TelephonyPermissions
12508 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12509 mApp, subId, "registerImsStateCallback");
12510 } else if (feature == ImsFeature.FEATURE_RCS) {
12511 // ImsRcsManager or SipDelegateManager
12512 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12513 Binder.getCallingUid(), "registerImsStateCallback",
12514 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12515 Manifest.permission.READ_PRECISE_PHONE_STATE,
12516 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12517 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12518 }
12519
12520 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12521 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12522 "IMS not available on device.");
12523 }
12524
12525 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12526 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12527 }
12528
12529 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12530 if (controller == null) {
12531 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12532 "IMS not available on device.");
12533 }
12534
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012535 if (callingPackage == null) {
12536 callingPackage = getCurrentPackageName();
12537 }
12538
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012539 final long token = Binder.clearCallingIdentity();
12540 try {
12541 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012542 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012543 } catch (ImsException e) {
12544 throw new ServiceSpecificException(e.getCode());
12545 } finally {
12546 Binder.restoreCallingIdentity(token);
12547 }
12548 }
12549
12550 /**
12551 * Unregister an IMS connection state callback
12552 */
12553 @Override
12554 public void unregisterImsStateCallback(IImsStateCallback cb) {
12555 final long token = Binder.clearCallingIdentity();
12556 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12557 if (controller == null) {
12558 return;
12559 }
12560 try {
12561 controller.unregisterImsStateCallback(cb);
12562 } finally {
12563 Binder.restoreCallingIdentity(token);
12564 }
12565 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012566
12567 /**
12568 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12569 *
12570 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012571 * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012572 * SecurityException.
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012573 *
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012574 * If there is current registered network this value will be same as the registered cell
12575 * identity. If the device goes out of service the previous cell identity is cached and
12576 * will be returned. If the cache age of the Cell identity is more than 24 hours
12577 * it will be cleared and null will be returned.
12578 *
12579 */
12580 @Override
12581 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12582 String callingFeatureId) {
12583 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12584 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12585 LocationAccessPolicy.checkLocationPermission(mApp,
12586 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12587 .setCallingPackage(callingPackage)
12588 .setCallingFeatureId(callingFeatureId)
12589 .setCallingPid(Binder.getCallingPid())
12590 .setCallingUid(Binder.getCallingUid())
12591 .setMethod("getLastKnownCellIdentity")
12592 .setLogAsInfo(true)
12593 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12594 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12595 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12596 .build());
12597
12598 boolean hasFinePermission =
12599 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12600 if (!hasFinePermission
12601 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12602 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012603 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012604 }
12605
12606 final long identity = Binder.clearCallingIdentity();
12607 try {
Ling Mac28f0212023-03-24 16:07:15 -070012608 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012609 if (sst == null) return null;
12610 return sst.getLastKnownCellIdentity();
12611 } finally {
12612 Binder.restoreCallingIdentity(identity);
12613 }
12614 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012615
jimsun3b9ccac2021-10-26 15:01:23 +080012616 /**
12617 * Sets the modem service class Name that Telephony will bind to.
12618 *
12619 * @param serviceName The class name of the modem service.
12620 * @return true if the operation is succeed, otherwise false.
12621 */
12622 public boolean setModemService(String serviceName) {
12623 Log.d(LOG_TAG, "setModemService - " + serviceName);
12624 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12625 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012626 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12627 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012628 return mPhoneConfigurationManager.setModemService(serviceName);
12629 }
12630
12631 /**
12632 * Return the class name of the currently bounded modem service.
12633 *
12634 * @return the class name of the modem service.
12635 */
12636 public String getModemService() {
12637 String result;
12638 Log.d(LOG_TAG, "getModemService");
12639 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12640 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012641 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012642 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12643 "getModemService");
12644 result = mPhoneConfigurationManager.getModemService();
12645 Log.d(LOG_TAG, "result = " + result);
12646 return result;
12647 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012648
Hakjun Choi3ee81112023-12-19 15:40:58 +000012649 /**
12650 * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources,
12651 * including carrier config, entitlement server, and config update.
12652 *
12653 * @param subId subId The subscription ID of the carrier.
12654 *
12655 * @return List of plmns for carrier satellite service. If no plmn is available, empty list will
12656 * be returned.
12657 *
12658 * @throws SecurityException if the caller doesn't have the required permission.
12659 */
Hakjun Choi74c16be2024-01-19 08:18:09 +000012660 @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) {
12661 enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier");
Hakjun Choi3ee81112023-12-19 15:40:58 +000012662 final long identity = Binder.clearCallingIdentity();
12663 try {
Hakjun Choi74c16be2024-01-19 08:18:09 +000012664 return mSatelliteController.getSatellitePlmnsForCarrier(subId);
Hakjun Choi3ee81112023-12-19 15:40:58 +000012665 } finally {
12666 Binder.restoreCallingIdentity(identity);
12667 }
12668 }
12669
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012670 @Override
12671 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12672 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12673 mApp.enforceCallingOrSelfPermission(
12674 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12675 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12676
12677 final long identity = Binder.clearCallingIdentity();
12678 try {
12679 Phone phone = getPhone(subId);
12680 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012681 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12682 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012683 phone.setVoiceServiceStateOverride(hasService);
12684 } finally {
12685 Binder.restoreCallingIdentity(identity);
12686 }
12687 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012688
12689 /**
12690 * set removable eSIM as default eUICC.
12691 *
12692 * @hide
12693 */
12694 @Override
12695 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12696 enforceModifyPermission();
12697 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12698
12699 final long identity = Binder.clearCallingIdentity();
12700 try {
12701 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12702 } finally {
12703 Binder.restoreCallingIdentity(identity);
12704 }
12705 }
12706
12707 /**
12708 * Returns whether the removable eSIM is default eUICC or not.
12709 *
12710 * @hide
12711 */
12712 @Override
12713 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12714 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12715 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12716
12717 final long identity = Binder.clearCallingIdentity();
12718 try {
12719 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12720 } finally {
12721 Binder.restoreCallingIdentity(identity);
12722 }
12723 }
12724
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012725 /**
12726 * Get the component name of the default app to direct respond-via-message intent for the
12727 * user associated with this subscription, update the cache if there is no respond-via-message
12728 * application currently configured for this user.
12729 * @return component name of the app and class to direct Respond Via Message intent to, or
12730 * {@code null} if the functionality is not supported.
12731 * @hide
12732 */
12733 @Override
12734 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12735 boolean updateIfNeeded) {
12736 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012737
joonhunshin4ac60942023-11-15 15:23:39 +000012738 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12739 PackageManager.FEATURE_TELEPHONY_MESSAGING,
12740 "getDefaultRespondViaMessageApplication");
12741
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012742 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12743
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012744 UserHandle userHandle = null;
12745 final long identity = Binder.clearCallingIdentity();
12746 try {
12747 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12748 } finally {
12749 Binder.restoreCallingIdentity(identity);
12750 }
12751 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12752 updateIfNeeded, userHandle);
12753 }
Jack Yuf5badd92022-12-08 00:50:53 -080012754
12755 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012756 * Set whether the device is able to connect with null ciphering or integrity
12757 * algorithms. This is a global setting and will apply to all active subscriptions
12758 * and all new subscriptions after this.
12759 *
12760 * @param enabled when true, null cipher and integrity algorithms are allowed.
12761 * @hide
12762 */
12763 @Override
12764 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12765 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12766 enforceModifyPermission();
12767 checkForNullCipherAndIntegritySupport();
12768
12769 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12770 // for listening to these preference changes and applying them immediately.
12771 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12772 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12773 editor.apply();
12774
12775 for (Phone phone: PhoneFactory.getPhones()) {
12776 phone.handleNullCipherEnabledChange();
12777 }
12778 }
12779
12780
12781 /**
12782 * Get whether the device is able to connect with null ciphering or integrity
12783 * algorithms. Note that this retrieves the phone-global preference and not
12784 * the state of the radio.
12785 *
12786 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12787 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12788 * version for this feature.
12789 * @hide
12790 */
12791 @Override
12792 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12793 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12794 enforceReadPermission();
12795 checkForNullCipherAndIntegritySupport();
12796 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12797 }
12798
12799 private void checkForNullCipherAndIntegritySupport() {
12800 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12801 throw new UnsupportedOperationException(
12802 "Null cipher and integrity operations require HAL 2.1 or above");
12803 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012804 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12805 throw new UnsupportedOperationException(
12806 "Null cipher and integrity operations unsupported by modem");
12807 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012808 }
12809
Gil Cukierman06403e12023-11-29 16:33:03 +000012810 private void checkForIdentifierDisclosureNotificationSupport() {
12811 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) {
12812 throw new UnsupportedOperationException(
12813 "Cellular identifier disclosure transparency operations require HAL 2.2 or "
12814 + "above");
12815 }
12816 if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) {
12817 throw new UnsupportedOperationException(
12818 "Cellular identifier disclosure transparency operations unsupported by modem");
12819 }
12820 }
12821
Michael Groover826b71d2023-12-21 22:08:06 -060012822 private void checkForNullCipherNotificationSupport() {
12823 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) {
12824 throw new UnsupportedOperationException(
12825 "Null cipher notification operations require HAL 2.2 or above");
12826 }
12827 if (!getDefaultPhone().isNullCipherNotificationSupported()) {
12828 throw new UnsupportedOperationException(
12829 "Null cipher notification operations unsupported by modem");
12830 }
12831 }
12832
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012833 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012834 * Get the SIM state for the slot index.
12835 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12836 *
12837 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12838 */
12839 @Override
12840 @SimState
12841 public int getSimStateForSlotIndex(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +000012842 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12843 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex");
12844
Jack Yuf5badd92022-12-08 00:50:53 -080012845 IccCardConstants.State simState;
12846 if (slotIndex < 0) {
12847 simState = IccCardConstants.State.UNKNOWN;
12848 } else {
12849 Phone phone = null;
12850 try {
12851 phone = PhoneFactory.getPhone(slotIndex);
12852 } catch (IllegalStateException e) {
12853 // ignore
12854 }
12855 if (phone == null) {
12856 simState = IccCardConstants.State.UNKNOWN;
12857 } else {
12858 IccCard icc = phone.getIccCard();
12859 if (icc == null) {
12860 simState = IccCardConstants.State.UNKNOWN;
12861 } else {
12862 simState = icc.getState();
12863 }
12864 }
12865 }
12866 return simState.ordinal();
12867 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012868
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012869 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
12870 boolean enableLogcat,
12871 long logcatStartTimestampMillis, boolean enableTelecomDump,
12872 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012873 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012874 TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder =
12875 new TelephonyManager.EmergencyCallDiagnosticData.Builder();
12876 ecdDataBuilder
12877 .setTelecomDumpsysCollectionEnabled(enableTelecomDump)
12878 .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012879 if (enableLogcat) {
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012880 ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012881 }
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012882 TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build();
12883 Log.d(LOG_TAG, "persisting with Params " + ecdData.toString());
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012884 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
12885 Executors.newCachedThreadPool(), db,
12886 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012887 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012888 }
12889
12890 /**
12891 * Request telephony to persist state for debugging emergency call failures.
12892 *
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012893 * @param dropboxTag Tag to use when persisting data to dropbox service.
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012894 * @param enableLogcat whether to collect logcat output
12895 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
12896 * @param enableTelecomDump whether to collect telecom dumpsys
12897 * @param enableTelephonyDump whether to collect telephony dumpsys
12898 */
12899 @Override
12900 @RequiresPermission(android.Manifest.permission.DUMP)
12901 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
12902 long logcatStartTimestampMillis, boolean enableTelecomDump,
12903 boolean enableTelephonyDump) {
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -080012904 // Verify that the caller has READ_DROPBOX_DATA permission.
12905 if (mTelecomFeatureFlags.telecomResolveHiddenDependencies()
12906 && Flags.enableReadDropboxPermission()) {
12907 mApp.enforceCallingPermission(permission.READ_DROPBOX_DATA,
12908 "persistEmergencyCallDiagnosticData");
12909 } else {
12910 // Otherwise, enforce legacy permission.
12911 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
12912 "persistEmergencyCallDiagnosticData");
12913 }
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012914 final long identity = Binder.clearCallingIdentity();
12915 try {
12916 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
12917 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
12918
12919 } finally {
12920 Binder.restoreCallingIdentity(identity);
12921 }
12922 }
12923
Hui Wang9b5793a2022-12-05 14:38:06 -060012924 /**
12925 * Get current cell broadcast ranges.
12926 */
12927 @Override
12928 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12929 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12930 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12931 "getCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012932
12933 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12934 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges");
12935
Hui Wang9b5793a2022-12-05 14:38:06 -060012936 final long identity = Binder.clearCallingIdentity();
12937 try {
12938 return getPhone(subId).getCellBroadcastIdRanges();
12939 } finally {
12940 Binder.restoreCallingIdentity(identity);
12941 }
12942 }
12943
12944 /**
12945 * Set reception of cell broadcast messages with the list of the given ranges
12946 *
12947 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12948 */
12949 @Override
12950 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12951 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12952 @Nullable IIntegerConsumer callback) {
12953 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12954 "setCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012955
12956 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12957 PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges");
12958
Hui Wang9b5793a2022-12-05 14:38:06 -060012959 final long identity = Binder.clearCallingIdentity();
12960 try {
12961 Phone phone = getPhoneFromSubId(subId);
12962 if (DBG) {
12963 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12964 }
12965 phone.setCellBroadcastIdRanges(ranges, result -> {
12966 if (callback != null) {
12967 try {
12968 callback.accept(result);
12969 } catch (RemoteException e) {
12970 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12971 }
12972 }
12973 });
12974 } finally {
12975 Binder.restoreCallingIdentity(identity);
12976 }
12977 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012978
12979 /**
12980 * Returns whether the device supports the domain selection service.
12981 *
12982 * @return {@code true} if the device supports the domain selection service.
12983 */
12984 @Override
12985 public boolean isDomainSelectionSupported() {
12986 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12987 "isDomainSelectionSupported");
12988
12989 final long identity = Binder.clearCallingIdentity();
12990 try {
12991 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12992 } finally {
12993 Binder.restoreCallingIdentity(identity);
12994 }
12995 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012996
12997 /**
Hunsuk Choi9c69a802024-04-11 20:39:23 +000012998 * Returns whether the AOSP domain selection service is supported.
12999 *
13000 * @return {@code true} if the AOSP domain selection service is supported,
13001 * {@code false} otherwise.
13002 */
13003 @Override
13004 public boolean isAospDomainSelectionService() {
13005 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
13006 "isAospDomainSelectionService");
13007
13008 final long identity = Binder.clearCallingIdentity();
13009 try {
13010 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13011 String dssComponentName = mApp.getResources().getString(
13012 R.string.config_domain_selection_service_component_name);
13013 ComponentName componentName = ComponentName.createRelative(mApp.getPackageName(),
13014 TelephonyDomainSelectionService.class.getName());
13015 Log.i(LOG_TAG, "isAospDomainSelectionService dss=" + dssComponentName
13016 + ", aosp=" + componentName.flattenToString());
13017 return TextUtils.equals(componentName.flattenToString(), dssComponentName);
13018 }
13019 } finally {
13020 Binder.restoreCallingIdentity(identity);
13021 }
13022 return false;
13023 }
13024
13025 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013026 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
13027 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
13028 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080013029 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013030 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chinabf081b2023-03-09 23:00:57 -080013031 * @param enableSatellite {@code true} to enable the satellite modem and
13032 * {@code false} to disable.
13033 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
Thomas Nguyena8062672024-02-05 14:18:19 -080013034 * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise.
Sarah Chinabf081b2023-03-09 23:00:57 -080013035 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080013036 *
13037 * @throws SecurityException if the caller doesn't have the required permission.
13038 */
13039 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013040 public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode,
Thomas Nguyena8062672024-02-05 14:18:19 -080013041 boolean isEmergency, @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013042 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013043 if (enableSatellite) {
13044 ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) {
13045 @Override
13046 protected void onReceiveResult(int resultCode, Bundle resultData) {
13047 Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode
13048 + ", resultData=" + resultData);
13049 boolean isAllowed = false;
13050 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(
13051 callback::accept);
13052 if (resultCode == SATELLITE_RESULT_SUCCESS) {
13053 if (resultData != null
13054 && resultData.containsKey(KEY_SATELLITE_COMMUNICATION_ALLOWED)) {
13055 isAllowed = resultData.getBoolean(KEY_SATELLITE_COMMUNICATION_ALLOWED);
13056 } else {
13057 loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist.");
13058 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013059 } else {
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013060 result.accept(resultCode);
13061 return;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013062 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013063 if (isAllowed) {
13064 mSatelliteController.requestSatelliteEnabled(
Hyosun Kimab304792024-03-29 09:18:03 +000013065 subId, enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013066 } else {
13067 result.accept(SATELLITE_RESULT_ACCESS_BARRED);
13068 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013069 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013070 };
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013071 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013072 subId, resultReceiver);
13073 } else {
13074 // No need to check if satellite is allowed at current location when disabling satellite
13075 mSatelliteController.requestSatelliteEnabled(
Hyosun Kimab304792024-03-29 09:18:03 +000013076 subId, enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013077 }
Sarah Chin503828c2023-02-01 23:54:20 -080013078 }
13079
13080 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013081 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080013082 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013083 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013084 * @param result The result receiver that returns whether the satellite modem is enabled
13085 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013086 *
13087 * @throws SecurityException if the caller doesn't have the required permission.
13088 */
13089 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013090 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
13091 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013092 mSatelliteController.requestIsSatelliteEnabled(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013093 }
13094
13095 /**
Sarah Chin43457982023-02-15 17:50:38 -080013096 * Request to get whether the satellite service demo mode is enabled.
13097 *
13098 * @param subId The subId of the subscription to check whether the satellite demo mode
13099 * is enabled for.
13100 * @param result The result receiver that returns whether the satellite demo mode is enabled
13101 * if the request is successful or an error code if the request failed.
13102 *
13103 * @throws SecurityException if the caller doesn't have the required permission.
13104 */
13105 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013106 public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
13107 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
13108 mSatelliteController.requestIsDemoModeEnabled(subId, result);
Sarah Chin43457982023-02-15 17:50:38 -080013109 }
13110
13111 /**
Thomas Nguyena8062672024-02-05 14:18:19 -080013112 * Request to get whether the satellite service is enabled with emergency mode.
13113 *
13114 * @param subId The subId of the subscription to check whether the satellite demo mode
13115 * is enabled for.
13116 * @param result The result receiver that returns whether the satellite emergency mode is
13117 * enabled if the request is successful or an error code if the request failed.
13118 *
13119 * @throws SecurityException if the caller doesn't have the required permission.
13120 */
13121 @Override
13122 public void requestIsEmergencyModeEnabled(int subId, @NonNull ResultReceiver result) {
13123 enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled");
13124 result.send(SATELLITE_RESULT_REQUEST_NOT_SUPPORTED, null);
13125 }
13126
13127 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013128 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080013129 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013130 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013131 * @param result The result receiver that returns whether the satellite service is supported on
13132 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013133 */
13134 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013135 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013136 mSatelliteController.requestIsSatelliteSupported(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013137 }
13138
13139 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013140 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080013141 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013142 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013143 * @param result The result receiver that returns the {@link SatelliteCapabilities}
13144 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013145 *
13146 * @throws SecurityException if the caller doesn't have required permission.
13147 */
13148 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013149 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
13150 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013151 mSatelliteController.requestSatelliteCapabilities(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013152 }
13153
13154 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013155 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013156 * This can be called by the pointing UI when the user starts pointing to the satellite.
13157 * Modem should continue to report the pointing input as the device or satellite moves.
13158 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013159 * @param subId The subId of the subscription to start satellite transmission updates for.
13160 * @param resultCallback The callback to get the result of the request.
13161 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080013162 *
13163 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013164 */
13165 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013166 public void startSatelliteTransmissionUpdates(int subId,
13167 @NonNull IIntegerConsumer resultCallback,
13168 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13169 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
13170 mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080013171 }
13172
13173 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013174 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013175 * This can be called by the pointing UI when the user stops pointing to the satellite.
13176 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013177 * @param subId The subId of the subscription to stop satellite transmission updates for.
13178 * @param resultCallback The callback to get the result of the request.
13179 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
13180 * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080013181 *
13182 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013183 */
13184 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013185 public void stopSatelliteTransmissionUpdates(int subId,
13186 @NonNull IIntegerConsumer resultCallback,
13187 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13188 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
13189 mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013190 }
13191
13192 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013193 * Register the subscription with a satellite provider.
13194 * This is needed to register the subscription if the provider allows dynamic registration.
13195 *
13196 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013197 * @param token The token to be used as a unique identifier for provisioning with satellite
13198 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013199 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080013200 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013201 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013202 * @return The signal transport used by the caller to cancel the provision request,
13203 * or {@code null} if the request failed.
13204 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013205 * @throws SecurityException if the caller doesn't have the required permission.
13206 */
13207 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013208 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013209 @NonNull String token, @NonNull byte[] provisionData,
13210 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013211 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013212 return mSatelliteController.provisionSatelliteService(subId, token, provisionData,
13213 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013214 }
13215
13216 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013217 * Unregister the device/subscription with the satellite provider.
13218 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013219 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013220 * should report as deprovisioned.
13221 *
13222 * @param subId The subId of the subscription to be deprovisioned.
13223 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080013224 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013225 *
13226 * @throws SecurityException if the caller doesn't have the required permission.
13227 */
13228 @Override
13229 public void deprovisionSatelliteService(int subId,
13230 @NonNull String token, @NonNull IIntegerConsumer callback) {
13231 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013232 mSatelliteController.deprovisionSatelliteService(subId, token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013233 }
13234
13235 /**
Sarah Chin43457982023-02-15 17:50:38 -080013236 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013237 *
Sarah Chin43457982023-02-15 17:50:38 -080013238 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013239 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013240 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013241 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013242 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013243 * @throws SecurityException if the caller doesn't have the required permission.
13244 */
13245 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013246 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
13247 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013248 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013249 return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013250 }
13251
13252 /**
Sarah Chin43457982023-02-15 17:50:38 -080013253 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013254 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013255 *
Sarah Chin43457982023-02-15 17:50:38 -080013256 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013257 * @param callback The callback that was passed to
13258 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013259 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013260 * @throws SecurityException if the caller doesn't have the required permission.
13261 */
13262 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013263 public void unregisterForSatelliteProvisionStateChanged(
13264 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013265 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013266 mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013267 }
13268
13269 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013270 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013271 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013272 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013273 * @param result The result receiver that returns whether the device is provisioned with a
13274 * satellite provider if the request is successful or an error code if the
13275 * request failed.
13276 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013277 * @throws SecurityException if the caller doesn't have the required permission.
13278 */
13279 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013280 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
13281 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013282 mSatelliteController.requestIsSatelliteProvisioned(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013283 }
13284
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013285 /**
Sarah Chin43457982023-02-15 17:50:38 -080013286 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013287 *
Sarah Chin43457982023-02-15 17:50:38 -080013288 * @param subId The subId of the subscription to register for satellite modem state changed.
13289 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080013290 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013291 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013292 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013293 * @throws SecurityException if the caller doesn't have the required permission.
13294 */
13295 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013296 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013297 @NonNull ISatelliteModemStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080013298 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013299 return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013300 }
13301
13302 /**
Sarah Chin43457982023-02-15 17:50:38 -080013303 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013304 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013305 *
Sarah Chin43457982023-02-15 17:50:38 -080013306 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080013307 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013308 * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013309 *
13310 * @throws SecurityException if the caller doesn't have the required permission.
13311 */
13312 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013313 public void unregisterForModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013314 @NonNull ISatelliteModemStateCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013315 enforceSatelliteCommunicationPermission("unregisterForModemStateChanged");
13316 mSatelliteController.unregisterForModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013317 }
13318
13319 /**
13320 * Register to receive incoming datagrams over satellite.
13321 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013322 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Sarah Chindf715ec2023-02-13 13:46:24 -080013323 * @param callback The callback to handle incoming datagrams over satellite.
13324 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013325 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013326 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013327 * @throws SecurityException if the caller doesn't have the required permission.
13328 */
13329 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013330 @SatelliteManager.SatelliteResult public int registerForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013331 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013332 enforceSatelliteCommunicationPermission("registerForIncomingDatagram");
13333 return mSatelliteController.registerForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013334 }
13335
13336 /**
13337 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013338 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013339 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013340 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
13341 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013342 * {@link #registerForIncomingDatagram(int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013343 *
13344 * @throws SecurityException if the caller doesn't have the required permission.
13345 */
13346 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013347 public void unregisterForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013348 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013349 enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram");
13350 mSatelliteController.unregisterForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013351 }
13352
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013353 /**
13354 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013355 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013356 * This method requests modem to check if there are any pending datagrams to be received over
13357 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000013358 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080013359 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013360 * @param subId The subId of the subscription used for receiving datagrams.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013361 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013362 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013363 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013364 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013365 public void pollPendingDatagrams(int subId, IIntegerConsumer callback) {
13366 enforceSatelliteCommunicationPermission("pollPendingDatagrams");
13367 mSatelliteController.pollPendingDatagrams(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013368 }
13369
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013370 /**
13371 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013372 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013373 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
13374 * input to this method. Datagram received here will be passed down to modem without any
13375 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080013376 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013377 * @param subId The subId of the subscription to send satellite datagrams for.
13378 * @param datagramType datagram type indicating whether the datagram is of type
13379 * SOS_SMS or LOCATION_SHARING.
13380 * @param datagram encoded gateway datagram which is encrypted by the caller.
13381 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000013382 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
13383 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013384 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013385 *
13386 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013387 */
13388 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013389 public void sendDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000013390 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
13391 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013392 enforceSatelliteCommunicationPermission("sendDatagram");
13393 mSatelliteController.sendDatagram(subId, datagramType, datagram, needFullScreenPointingUI,
13394 callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013395 }
13396
Sarah Chindf715ec2023-02-13 13:46:24 -080013397 /**
13398 * Request to get whether satellite communication is allowed for the current location.
13399 *
13400 * @param subId The subId of the subscription to check whether satellite communication is
13401 * allowed for the current location for.
13402 * @param result The result receiver that returns whether satellite communication is allowed
13403 * for the current location if the request is successful or an error code
13404 * if the request failed.
13405 *
13406 * @throws SecurityException if the caller doesn't have the required permission.
13407 */
13408 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013409 public void requestIsCommunicationAllowedForCurrentLocation(int subId,
Sarah Chindf715ec2023-02-13 13:46:24 -080013410 @NonNull ResultReceiver result) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013411 enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation");
13412 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(subId,
13413 result);
Sarah Chindf715ec2023-02-13 13:46:24 -080013414 }
13415
13416 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013417 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080013418 *
Sarah Chin5f57c582023-02-14 04:16:10 -080013419 * @param subId The subId to get the time after which the satellite will be visible for.
13420 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080013421 * be visible if the request is successful or an error code if the request failed.
13422 *
13423 * @throws SecurityException if the caller doesn't have the required permission.
13424 */
13425 @Override
13426 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
13427 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013428 mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013429 }
13430
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013431 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013432 * Inform that Device is aligned to satellite for demo mode.
13433 *
13434 * @param subId The subId to get the time after which the satellite will be visible for.
13435 * @param isAligned {@code true} Device is aligned with the satellite for demo mode
13436 * {@code false} Device fails to align with the satellite for demo mode.
13437 *
13438 * @throws SecurityException if the caller doesn't have required permission.
13439 */
13440 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
13441
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013442 public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) {
Hakjun Choiae365972023-04-25 11:00:31 +000013443 enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite");
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013444 mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned);
Hakjun Choiae365972023-04-25 11:00:31 +000013445 }
13446
13447 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000013448 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
13449 * by modem.
13450 *
13451 * @param subId The subId of the subscription to request for.
13452 * @param reason Reason for disallowing satellite communication for carrier.
Hakjun Choif92ac752024-03-18 19:34:29 +000013453 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013454 * operation.
13455 *
13456 * @throws SecurityException if the caller doesn't have required permission.
13457 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013458 public void addAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013459 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13460 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013461 enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013462 final long identity = Binder.clearCallingIdentity();
13463 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013464 mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013465 } finally {
13466 Binder.restoreCallingIdentity(identity);
13467 }
13468 }
13469
13470 /**
13471 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
13472 * by modem.
13473 *
13474 * @param subId The subId of the subscription to request for.
13475 * @param reason Reason for disallowing satellite communication.
Hakjun Choif92ac752024-03-18 19:34:29 +000013476 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013477 * operation.
13478 *
13479 * @throws SecurityException if the caller doesn't have required permission.
13480 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013481 public void removeAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013482 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13483 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013484 enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013485 final long identity = Binder.clearCallingIdentity();
13486 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013487 mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013488 } finally {
13489 Binder.restoreCallingIdentity(identity);
13490 }
13491 }
13492
13493 /**
13494 * Get reasons for disallowing satellite communication, as requested by
Hakjun Choif92ac752024-03-18 19:34:29 +000013495 * {@link #addAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
Hakjun Choicb39db92023-07-14 15:51:12 +000013496 *
13497 * @param subId The subId of the subscription to request for.
13498 *
13499 * @return Integer array of reasons for disallowing satellite communication.
13500 *
13501 * @throws SecurityException if the caller doesn't have the required permission.
13502 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013503 public @NonNull int[] getAttachRestrictionReasonsForCarrier(
Hakjun Choicb39db92023-07-14 15:51:12 +000013504 int subId) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013505 enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013506 final long identity = Binder.clearCallingIdentity();
13507 try {
13508 Set<Integer> reasonSet =
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013509 mSatelliteController.getAttachRestrictionReasonsForCarrier(subId);
Hakjun Choicb39db92023-07-14 15:51:12 +000013510 return reasonSet.stream().mapToInt(i->i).toArray();
13511 } finally {
13512 Binder.restoreCallingIdentity(identity);
13513 }
13514 }
13515
13516 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000013517 * Request to get the signal strength of the satellite connection.
13518 *
13519 * @param subId The subId of the subscription to request for.
13520 * @param result Result receiver to get the error code of the request and the current signal
13521 * strength of the satellite connection.
13522 *
13523 * @throws SecurityException if the caller doesn't have required permission.
13524 */
13525 @Override
13526 public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) {
13527 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
13528 final long identity = Binder.clearCallingIdentity();
13529 try {
13530 mSatelliteController.requestNtnSignalStrength(subId, result);
13531 } finally {
13532 Binder.restoreCallingIdentity(identity);
13533 }
13534 }
13535
13536 /**
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013537 * Registers for NTN signal strength changed from satellite modem. If the registration operation
13538 * is not successful, a {@link ServiceSpecificException} that contains
13539 * {@link SatelliteManager.SatelliteResult} will be thrown.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013540 *
13541 * @param subId The subId of the subscription to request for.
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013542 * @param callback The callback to handle the NTN signal strength changed event. If the
13543 * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged(
13544 * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of
13545 * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial
13546 * network has changed.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013547 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013548 * @throws SecurityException If the caller doesn't have the required permission.
13549 * @throws ServiceSpecificException If the callback registration operation fails.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013550 */
13551 @Override
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013552 public void registerForNtnSignalStrengthChanged(int subId,
13553 @NonNull INtnSignalStrengthCallback callback) throws RemoteException {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013554 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
13555 final long identity = Binder.clearCallingIdentity();
13556 try {
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013557 mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013558 } finally {
13559 Binder.restoreCallingIdentity(identity);
13560 }
13561 }
13562
13563 /**
13564 * Unregisters for NTN signal strength changed from satellite modem.
13565 * If callback was not registered before, the request will be ignored.
13566 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013567 * @param subId The subId of the subscription to unregister for listening NTN signal strength
13568 * changed event.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013569 * @param callback The callback that was passed to
13570 * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)}
13571 *
13572 * @throws SecurityException if the caller doesn't have the required permission.
13573 */
13574 @Override
13575 public void unregisterForNtnSignalStrengthChanged(
13576 int subId, @NonNull INtnSignalStrengthCallback callback) {
13577 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
13578 final long identity = Binder.clearCallingIdentity();
13579 try {
13580 mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback);
13581 } finally {
13582 Binder.restoreCallingIdentity(identity);
13583 }
13584 }
13585
13586 /**
Hakjun Choi8d96a562023-10-26 15:01:40 +000013587 * Registers for satellite capabilities change event from the satellite service.
13588 *
13589 * @param subId The subId of the subscription to request for.
13590 * @param callback The callback to handle the satellite capabilities changed event.
13591 *
13592 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13593 *
13594 * @throws SecurityException if the caller doesn't have required permission.
13595 */
13596 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013597 @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged(
Hakjun Choi8d96a562023-10-26 15:01:40 +000013598 int subId, @NonNull ISatelliteCapabilitiesCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013599 enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013600 final long identity = Binder.clearCallingIdentity();
13601 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013602 return mSatelliteController.registerForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013603 } finally {
13604 Binder.restoreCallingIdentity(identity);
13605 }
13606 }
13607
13608 /**
13609 * Unregisters for satellite capabilities change event from the satellite service.
13610 * If callback was not registered before, the request will be ignored.
13611 *
13612 * @param subId The subId of the subscription to unregister for satellite capabilities change.
13613 * @param callback The callback that was passed to.
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013614 * {@link #registerForCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}.
Hakjun Choi8d96a562023-10-26 15:01:40 +000013615 *
13616 * @throws SecurityException if the caller doesn't have required permission.
13617 */
13618 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013619 public void unregisterForCapabilitiesChanged(int subId,
13620 @NonNull ISatelliteCapabilitiesCallback callback) {
13621 enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013622 final long identity = Binder.clearCallingIdentity();
13623 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013624 mSatelliteController.unregisterForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013625 } finally {
13626 Binder.restoreCallingIdentity(identity);
13627 }
13628 }
13629
13630 /**
Hakjun Choif92ac752024-03-18 19:34:29 +000013631 * Registers for the satellite supported state changed.
13632 *
13633 * @param subId The subId of the subscription to register for supported state changed.
13634 * @param callback The callback to handle the satellite supported state changed event.
13635 *
13636 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13637 *
13638 * @throws SecurityException if the caller doesn't have the required permission.
13639 */
13640 @Override
13641 @SatelliteManager.SatelliteResult public int registerForSatelliteSupportedStateChanged(
13642 int subId, @NonNull ISatelliteSupportedStateCallback callback) {
13643 enforceSatelliteCommunicationPermission("registerForSatelliteSupportedStateChanged");
13644 return mSatelliteController.registerForSatelliteSupportedStateChanged(subId, callback);
13645 }
13646
13647 /**
13648 * Unregisters for the satellite supported state changed.
13649 * If callback was not registered before, the request will be ignored.
13650 *
13651 * @param subId The subId of the subscription to unregister for supported state changed.
13652 * @param callback The callback that was passed to
13653 * {@link #registerForSatelliteSupportedStateChanged(int, ISatelliteSupportedStateCallback)}.
13654 *
13655 * @throws SecurityException if the caller doesn't have the required permission.
13656 */
13657 @Override
13658 public void unregisterForSatelliteSupportedStateChanged(
13659 int subId, @NonNull ISatelliteSupportedStateCallback callback) {
13660 enforceSatelliteCommunicationPermission("unregisterForSatelliteSupportedStateChanged");
13661 mSatelliteController.unregisterForSatelliteSupportedStateChanged(subId, callback);
13662 }
13663
13664 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013665 * This API can be used by only CTS to update satellite vendor service package name.
13666 *
13667 * @param servicePackageName The package name of the satellite vendor service.
13668 * @return {@code true} if the satellite vendor service is set successfully,
13669 * {@code false} otherwise.
13670 */
13671 public boolean setSatelliteServicePackageName(String servicePackageName) {
13672 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName);
13673 TelephonyPermissions.enforceShellOnly(
13674 Binder.getCallingUid(), "setSatelliteServicePackageName");
13675 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13676 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13677 "setSatelliteServicePackageName");
13678 return mSatelliteController.setSatelliteServicePackageName(servicePackageName);
13679 }
13680
13681 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070013682 * This API can be used by only CTS to update satellite gateway service package name.
13683 *
13684 * @param servicePackageName The package name of the satellite gateway service.
13685 * @return {@code true} if the satellite gateway service is set successfully,
13686 * {@code false} otherwise.
13687 */
13688 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
13689 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
13690 TelephonyPermissions.enforceShellOnly(
13691 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
13692 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13693 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13694 "setSatelliteGatewayServicePackageName");
13695 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
13696 }
13697
13698 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070013699 * This API can be used by only CTS to update satellite pointing UI app package and class names.
13700 *
13701 * @param packageName The package name of the satellite pointing UI app.
13702 * @param className The class name of the satellite pointing UI app.
13703 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
13704 * {@code false} otherwise.
13705 */
13706 public boolean setSatellitePointingUiClassName(
13707 @Nullable String packageName, @Nullable String className) {
13708 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
13709 + ", className=" + className);
13710 TelephonyPermissions.enforceShellOnly(
13711 Binder.getCallingUid(), "setSatellitePointingUiClassName");
13712 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13713 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13714 "setSatelliteGatewayServicePackageName");
13715 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
13716 }
13717
13718 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070013719 * This API can be used by only CTS to update the timeout duration in milliseconds that
13720 * satellite should stay at listening mode to wait for the next incoming page before disabling
13721 * listening mode.
13722 *
13723 * @param timeoutMillis The timeout duration in millisecond.
13724 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13725 */
13726 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
13727 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
13728 TelephonyPermissions.enforceShellOnly(
13729 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
13730 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13731 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13732 "setSatelliteListeningTimeoutDuration");
13733 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
13734 }
13735
13736 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013737 * This API can be used by only CTS to override the timeout durations used by the
13738 * DatagramController module.
Hakjun Choiae365972023-04-25 11:00:31 +000013739 *
13740 * @param timeoutMillis The timeout duration in millisecond.
13741 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13742 */
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013743 public boolean setDatagramControllerTimeoutDuration(
13744 boolean reset, int timeoutType, long timeoutMillis) {
13745 Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset="
13746 + reset + ", timeoutMillis=" + timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013747 TelephonyPermissions.enforceShellOnly(
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013748 Binder.getCallingUid(), "setDatagramControllerTimeoutDuration");
Hakjun Choiae365972023-04-25 11:00:31 +000013749 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13750 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013751 "setDatagramControllerTimeoutDuration");
13752 return mSatelliteController.setDatagramControllerTimeoutDuration(
13753 reset, timeoutType, timeoutMillis);
13754 }
13755
13756 /**
13757 * This API can be used by only CTS to override the timeout durations used by the
13758 * SatelliteController module.
13759 *
13760 * @param timeoutMillis The timeout duration in millisecond.
13761 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13762 */
13763 public boolean setSatelliteControllerTimeoutDuration(
13764 boolean reset, int timeoutType, long timeoutMillis) {
13765 Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset="
13766 + reset + ", timeoutMillis=" + timeoutMillis);
13767 TelephonyPermissions.enforceShellOnly(
13768 Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration");
13769 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13770 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13771 "setSatelliteControllerTimeoutDuration");
13772 return mSatelliteController.setSatelliteControllerTimeoutDuration(
13773 reset, timeoutType, timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013774 }
13775
13776 /**
Thomas Nguyen11a051f2023-10-25 10:14:55 -070013777 * This API can be used in only testing to override connectivity status in monitoring emergency
13778 * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.
13779 *
13780 * @param handoverType The type of handover from emergency call to satellite messaging. Use one
13781 * of the following values to enable the override:
13782 * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS
13783 * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911
13784 * To disable the override, use -1 for handoverType.
13785 * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer
13786 * delaySeconds after the emergency call starts.
13787 * @return {@code true} if the handover type is set successfully, {@code false} otherwise.
13788 */
13789 public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) {
13790 Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType);
13791 TelephonyPermissions.enforceShellOnly(
13792 Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType");
13793 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13794 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13795 "setEmergencyCallToSatelliteHandoverType");
13796 return mSatelliteController.setEmergencyCallToSatelliteHandoverType(
13797 handoverType, delaySeconds);
13798 }
13799
13800 /**
Thomas Nguyen3d602742024-01-19 11:29:35 -080013801 * This API can be used in only testing to override oem-enabled satellite provision status.
13802 *
13803 * @param reset {@code true} mean the overriding status should not be used, {@code false}
13804 * otherwise.
13805 * @param isProvisioned The overriding provision status.
13806 * @return {@code true} if the provision status is set successfully, {@code false} otherwise.
13807 */
13808 public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) {
13809 Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset
13810 + ", isProvisioned=" + isProvisioned);
13811 TelephonyPermissions.enforceShellOnly(
13812 Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus");
13813 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13814 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13815 "setOemEnabledSatelliteProvisionStatus");
13816 return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned);
13817 }
13818
13819 /**
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013820 * This API should be used by only CTS tests to forcefully set telephony country codes.
13821 *
13822 * @return {@code true} if the country code is set successfully, {@code false} otherwise.
13823 */
13824 public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes,
13825 Map cachedNetworkCountryCodes, String locationCountryCode,
13826 long locationCountryCodeTimestampNanos) {
13827 Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes="
13828 + String.join(", ", currentNetworkCountryCodes)
13829 + ", locationCountryCode=" + locationCountryCode
13830 + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos
13831 + ", reset=" + reset + ", cachedNetworkCountryCodes="
13832 + String.join(", ", cachedNetworkCountryCodes.keySet()));
13833 TelephonyPermissions.enforceShellOnly(
13834 Binder.getCallingUid(), "setCachedLocationCountryCode");
13835 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13836 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13837 "setCachedLocationCountryCode");
13838 return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext()).setCountryCodes(
13839 reset, currentNetworkCountryCodes, cachedNetworkCountryCodes, locationCountryCode,
13840 locationCountryCodeTimestampNanos);
13841 }
13842
13843 /**
13844 * This API should be used by only CTS tests to override the overlay configs of satellite
13845 * access controller.
13846 *
13847 * @param reset {@code true} mean the overridden configs should not be used, {@code false}
13848 * otherwise.
13849 * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise.
13850 */
13851 public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed,
13852 String s2CellFile, long locationFreshDurationNanos,
13853 List<String> satelliteCountryCodes) {
13854 Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset
13855 + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile
13856 + ", locationFreshDurationNanos=" + locationFreshDurationNanos
13857 + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null)
13858 ? String.join(", ", satelliteCountryCodes) : null));
13859 TelephonyPermissions.enforceShellOnly(
13860 Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs");
13861 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13862 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13863 "setSatelliteAccessControlOverlayConfigs");
13864 return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset, isAllowed,
13865 s2CellFile, locationFreshDurationNanos, satelliteCountryCodes);
13866 }
13867
13868 /**
Hakjun Choibc6ce992023-11-07 16:04:33 +000013869 * This API can be used by only CTS to override the cached value for the device overlay config
13870 * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether
13871 * outgoing satellite datagrams should be sent to modem in demo mode.
13872 *
13873 * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to
13874 * satellite modem or not.
13875 *
13876 * @return {@code true} if the operation is successful, {@code false} otherwise.
13877 */
13878 public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) {
13879 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
13880 Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is "
13881 + "disabled");
13882 return false;
13883 }
13884 Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode");
13885 TelephonyPermissions.enforceShellOnly(
13886 Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode");
13887 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13888 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13889 "setShouldSendDatagramToModemInDemoMode");
13890 return mSatelliteController.setShouldSendDatagramToModemInDemoMode(
13891 shouldSendToModemInDemoMode);
13892 }
13893
13894 /**
Hunsuk Choi13078be2023-09-13 10:55:21 +000013895 * Sets the service defined in ComponentName to be bound.
13896 *
13897 * This should only be used for testing.
13898 * @return {@code true} if the DomainSelectionService to bind to was set,
13899 * {@code false} otherwise.
13900 */
13901 @Override
13902 public boolean setDomainSelectionServiceOverride(ComponentName componentName) {
13903 Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName);
13904
13905 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
13906 "setDomainSelectionServiceOverride");
13907 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13908 getDefaultSubscription(), "setDomainSelectionServiceOverride");
13909
13910 final long identity = Binder.clearCallingIdentity();
13911 try {
13912 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13913 return DomainSelectionResolver.getInstance()
13914 .setDomainSelectionServiceOverride(componentName);
13915 }
13916 } finally {
13917 Binder.restoreCallingIdentity(identity);
13918 }
13919 return false;
13920 }
13921
13922 /**
13923 * Clears the DomainSelectionService override.
13924 *
13925 * This should only be used for testing.
13926 * @return {@code true} if the DomainSelectionService override was cleared,
13927 * {@code false} otherwise.
13928 */
13929 @Override
13930 public boolean clearDomainSelectionServiceOverride() {
13931 Log.i(LOG_TAG, "clearDomainSelectionServiceOverride");
13932
13933 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
13934 "clearDomainSelectionServiceOverride");
13935 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13936 getDefaultSubscription(), "clearDomainSelectionServiceOverride");
13937
13938 final long identity = Binder.clearCallingIdentity();
13939 try {
13940 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13941 return DomainSelectionResolver.getInstance()
13942 .clearDomainSelectionServiceOverride();
13943 }
13944 } finally {
13945 Binder.restoreCallingIdentity(identity);
13946 }
13947 return false;
13948 }
13949
13950 /**
Gil Cukierman06403e12023-11-29 16:33:03 +000013951 * Enable or disable notifications sent for cellular identifier disclosure events.
13952 *
13953 * Disclosure events are defined as instances where a device has sent a cellular identifier
13954 * on the Non-access stratum (NAS) before a security context is established. As a result the
13955 * identifier is sent in the clear, which has privacy implications for the user.
13956 *
13957 * @param enable if notifications about disclosure events should be enabled
13958 * @throws SecurityException if the caller does not have the required privileges
13959 * @throws UnsupportedOperationException if the modem does not support this feature.
13960 */
13961 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000013962 public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) {
Gil Cukierman06403e12023-11-29 16:33:03 +000013963 enforceModifyPermission();
13964 checkForIdentifierDisclosureNotificationSupport();
13965
13966 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
13967 editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable);
13968 editor.apply();
13969
13970 // Each phone instance is responsible for updating its respective modem immediately
13971 // after we've made a preference change.
13972 for (Phone phone : PhoneFactory.getPhones()) {
13973 phone.handleIdentifierDisclosureNotificationPreferenceChange();
13974 }
13975 }
13976
13977 /**
13978 * Get whether or not cellular identifier disclosure notifications are enabled.
13979 *
13980 * @throws SecurityException if the caller does not have the required privileges
13981 * @throws UnsupportedOperationException if the modem does not support this feature.
13982 */
13983 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000013984 public boolean isCellularIdentifierDisclosureNotificationsEnabled() {
Gil Cukierman06403e12023-11-29 16:33:03 +000013985 enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled");
13986 checkForIdentifierDisclosureNotificationSupport();
13987 return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled();
13988 }
13989
13990 /**
Michael Groover826b71d2023-12-21 22:08:06 -060013991 * Enables or disables notifications sent when cellular null cipher or integrity algorithms
13992 * are in use by the cellular modem.
13993 *
13994 * @throws IllegalStateException if the Telephony process is not currently available
13995 * @throws SecurityException if the caller does not have the required privileges
13996 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
13997 * and integrity algorithms in use
13998 * @hide
13999 */
14000 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Michael Grooverae447b22024-01-24 22:35:46 -060014001 public void setNullCipherNotificationsEnabled(boolean enable) {
Michael Groover826b71d2023-12-21 22:08:06 -060014002 enforceModifyPermission();
14003 checkForNullCipherNotificationSupport();
14004
14005 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
14006 editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable);
14007 editor.apply();
14008
14009 // Each phone instance is responsible for updating its respective modem immediately
14010 // after a preference change.
14011 for (Phone phone : PhoneFactory.getPhones()) {
14012 phone.handleNullCipherNotificationPreferenceChanged();
14013 }
14014 }
14015
14016 /**
14017 * Get whether notifications are enabled for null cipher or integrity algorithms in use by the
14018 * cellular modem.
14019 *
14020 * @throws IllegalStateException if the Telephony process is not currently available
14021 * @throws SecurityException if the caller does not have the required privileges
14022 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14023 * and integrity algorithms in use
14024 * @hide
14025 */
14026 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
14027 public boolean isNullCipherNotificationsEnabled() {
14028 enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled");
14029 checkForNullCipherNotificationSupport();
14030 return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled();
14031 }
14032
14033 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000014034 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
14035 *
14036 * <p>This method behaves in one of the following ways:
14037 * <ul>
14038 * <li>return true : if the calling package has the appop permission {@link
14039 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
14040 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
14041 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
14042 * Owner device identifier access check, or the calling package has carrier privileges</>
14043 * <li>throw SecurityException: if the caller does not meet any of the requirements.
14044 * </ul>
14045 */
14046 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
14047 String callingPackage, @Nullable String callingFeatureId, String message) {
14048 for (Phone phone : PhoneFactory.getPhones()) {
14049 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
14050 phone.getSubId(), callingPackage, callingFeatureId, message)) {
14051 return true;
14052 }
14053 }
14054 return false;
14055 }
arunvoddud7401012022-12-15 16:08:12 +000014056
14057 /**
Jack Yufa8ed012023-02-11 15:42:28 -080014058 * @return The subscription manager service instance.
14059 */
14060 public SubscriptionManagerService getSubscriptionManagerService() {
14061 return SubscriptionManagerService.getInstance();
14062 }
14063
14064 /**
arunvoddud7401012022-12-15 16:08:12 +000014065 * Class binds the consumer[callback] and carrierId.
14066 */
14067 private static class CallerCallbackInfo {
14068 private final Consumer<Integer> mConsumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014069 private final Set<Integer> mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014070
Steve Statia28b7cb32024-03-11 23:58:50 +000014071 public CallerCallbackInfo(Consumer<Integer> consumer, Set<Integer> carrierIds) {
arunvoddud7401012022-12-15 16:08:12 +000014072 mConsumer = consumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014073 mCarrierIds = carrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014074 }
14075
14076 public Consumer<Integer> getConsumer() {
14077 return mConsumer;
14078 }
14079
Steve Statia28b7cb32024-03-11 23:58:50 +000014080 public Set<Integer> getCarrierIds() {
14081 return mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014082 }
14083 }
joonhunshin4ac60942023-11-15 15:23:39 +000014084
14085 /*
14086 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14087 * But the context that is passed in is unused if the phone app is already alive.
14088 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14089 */
14090 @VisibleForTesting
14091 public void setPackageManager(PackageManager packageManager) {
14092 mPackageManager = packageManager;
14093 }
14094
14095 /*
Nate Myren453c3472024-03-13 11:28:11 -070014096 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14097 * But the context that is passed in is unused if the phone app is already alive.
14098 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14099 */
14100 @VisibleForTesting
14101 public void setAppOpsManager(AppOpsManager appOps) {
14102 mAppOps = appOps;
14103 }
14104
14105 /*
joonhunshin4ac60942023-11-15 15:23:39 +000014106 * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags.
14107 * But the FeatureFlags that is passed in is unused if the phone app is already alive.
14108 * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test.
14109 */
14110 @VisibleForTesting
14111 public void setFeatureFlags(FeatureFlags featureFlags) {
14112 mFeatureFlags = featureFlags;
14113 }
14114
14115 /**
14116 * Make sure the device has required telephony feature
14117 *
14118 * @throws UnsupportedOperationException if the device does not have required telephony feature
14119 */
14120 private void enforceTelephonyFeatureWithException(@Nullable String callingPackage,
14121 @NonNull String telephonyFeature, @NonNull String methodName) {
14122 if (callingPackage == null || mPackageManager == null) {
14123 return;
14124 }
14125
14126 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
14127 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage,
14128 Binder.getCallingUserHandle())) {
14129 return;
14130 }
14131
14132 if (!mPackageManager.hasSystemFeature(telephonyFeature)) {
14133 throw new UnsupportedOperationException(
14134 methodName + " is unsupported without " + telephonyFeature);
14135 }
14136 }
Jack Yufa8ed012023-02-11 15:42:28 -080014137}