blob: 9e5461cce5f575937524f65befa09656ef7f951c [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
joonhunshin4ac60942023-11-15 15:23:39 +000019import static android.content.pm.PackageManager.FEATURE_TELEPHONY_IMS;
20import static android.content.pm.PackageManager.FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION;
Hall Liud892bec2018-11-30 14:51:45 -080021import static android.content.pm.PackageManager.PERMISSION_GRANTED;
Nate Myrenae97d192023-06-09 15:22:31 -070022import static android.permission.flags.Flags.opEnableMobileDataByUser;
joonhunshin4ac60942023-11-15 15:23:39 +000023import static android.telephony.TelephonyManager.ENABLE_FEATURE_MAPPING;
Gil Cukierman1c0eb932022-12-06 22:28:24 +000024import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK;
jimsunf9ec1622022-09-13 21:18:43 +080025import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080026import static android.telephony.satellite.SatelliteManager.KEY_SATELLITE_COMMUNICATION_ALLOWED;
27import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_ACCESS_BARRED;
Thomas Nguyena8062672024-02-05 14:18:19 -080028import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_REQUEST_NOT_SUPPORTED;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080029import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_SUCCESS;
Hall Liud892bec2018-11-30 14:51:45 -080030
Shuo Qianccbaf742021-02-22 18:32:21 -080031import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
32import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070033import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070034import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000035import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070036
Brad Ebinger34c09a52021-02-17 23:23:21 +000037import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080038import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080039import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070040import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000041import android.annotation.RequiresPermission;
Sarah Chin532d6bb2022-12-28 22:50:43 -080042import android.app.ActivityManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070043import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080044import android.app.PendingIntent;
Tyler Gunn64144d92022-03-17 14:16:41 -070045import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000046import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080047import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000048import android.compat.annotation.ChangeId;
49import android.compat.annotation.EnabledSince;
Anthony Alridge70ba5572023-05-02 12:14:14 +000050import android.content.ActivityNotFoundException;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070051import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070052import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.content.Context;
54import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070055import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070056import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070057import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070058import android.net.Uri;
59import android.os.AsyncResult;
60import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080061import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070062import android.os.Bundle;
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080063import android.os.DropBoxManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070065import android.os.IBinder;
Thomas Nguyen8ee49682023-02-01 11:46:09 -080066import android.os.ICancellationSignal;
tom hsu0b59d292022-09-29 23:49:21 +080067import android.os.LocaleList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070068import android.os.Looper;
69import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070070import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080071import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070072import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070073import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080074import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080075import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070076import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070077import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080078import android.os.SystemClock;
joonhunshinf624b2a2024-04-18 04:42:12 +000079import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070080import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070081import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070082import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070083import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070084import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080085import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070086import android.provider.Telephony;
arunvoddud7401012022-12-15 16:08:12 +000087import android.service.carrier.CarrierIdentifier;
Inseob Kim14bb3d02018-12-13 17:11:34 +090088import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080089import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080090import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070091import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080092import android.telephony.AccessNetworkConstants;
93import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070094import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070095import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080096import android.telephony.Annotation.ThermalMitigationResult;
Sarah Chin2ec39f62022-08-31 17:03:26 -070097import android.telephony.AnomalyReporter;
Shuo Qian4a594052020-01-23 11:59:30 -080098import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070099import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -0800100import android.telephony.CarrierRestrictionRules;
Hui Wang9b5793a2022-12-05 14:38:06 -0600101import android.telephony.CellBroadcastIdRange;
yincheng zhao2737e882019-09-06 17:06:54 -0700102import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -0800103import android.telephony.CellIdentityCdma;
104import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700105import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -0700106import android.telephony.CellInfoGsm;
107import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700108import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800109import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -0700110import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700111import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700112import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -0800113import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700114import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -0800115import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -0700116import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -0800117import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800118import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700119import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800120import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700121import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800122import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800123import android.telephony.SignalStrengthUpdateRequest;
124import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800125import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800126import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800127import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700128import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700129import android.telephony.TelephonyManager;
Jack Yuf5badd92022-12-08 00:50:53 -0800130import android.telephony.TelephonyManager.SimState;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800131import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800132import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800133import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000134import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000135import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000136import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700137import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700138import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800139import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800140import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700141import android.telephony.gba.GbaAuthRequest;
142import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700143import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800144import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000145import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000146import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700147import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000148import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700149import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800150import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700151import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800152import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700153import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000154import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700155import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800156import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800157import android.telephony.ims.stub.ImsRegistrationImplBase;
Hakjun Choifa3e6172023-09-22 03:56:34 +0000158import android.telephony.satellite.INtnSignalStrengthCallback;
Hakjun Choi8d96a562023-10-26 15:01:40 +0000159import android.telephony.satellite.ISatelliteCapabilitiesCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800160import android.telephony.satellite.ISatelliteDatagramCallback;
Hakjun Choid4a52a22023-12-13 09:48:24 +0000161import android.telephony.satellite.ISatelliteModemStateCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800162import android.telephony.satellite.ISatelliteProvisionStateCallback;
Hakjun Choif92ac752024-03-18 19:34:29 +0000163import android.telephony.satellite.ISatelliteSupportedStateCallback;
Sarah Chinabf081b2023-03-09 23:00:57 -0800164import android.telephony.satellite.ISatelliteTransmissionUpdateCallback;
Hakjun Choi4c3668a2023-12-05 11:55:36 +0000165import android.telephony.satellite.NtnSignalStrength;
166import android.telephony.satellite.NtnSignalStrengthCallback;
Sarah Chin503828c2023-02-01 23:54:20 -0800167import android.telephony.satellite.SatelliteCapabilities;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000168import android.telephony.satellite.SatelliteDatagram;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800169import android.telephony.satellite.SatelliteDatagramCallback;
Sarah Chineccfbd12023-01-20 19:00:35 -0800170import android.telephony.satellite.SatelliteManager;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800171import android.telephony.satellite.SatelliteProvisionStateCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700172import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800173import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700174import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700175import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800176import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800177
Andrew Lee312e8172014-10-23 17:01:36 -0700178import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800179import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800180import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800181import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800182import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700183import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700184import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700185import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800186import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800187import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700188import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700189import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800190import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700191import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800192import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800193import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800194import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700195import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000196import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700197import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800198import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700199import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800200import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800201import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800202import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700203import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700204import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700205import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700206import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700207import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800208import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700209import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700210import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700211import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700212import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800213import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800214import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700215import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000216import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700217import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700218import com.android.internal.telephony.SmsPermissions;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800219import com.android.internal.telephony.TelephonyCountryDetector;
Peter Wang59571be2020-01-27 12:35:15 +0800220import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800221import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700222import com.android.internal.telephony.data.DataUtils;
Hunsuk Choi42cc62a2022-10-16 06:03:40 +0000223import com.android.internal.telephony.domainselection.DomainSelectionResolver;
sqianf4ca7ed2019-01-15 18:32:07 -0800224import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700225import com.android.internal.telephony.euicc.EuiccConnector;
Sarah Chincc5446f2023-10-23 17:57:19 -0700226import com.android.internal.telephony.flags.FeatureFlags;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800227import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700228import com.android.internal.telephony.imsphone.ImsPhone;
229import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000230import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800231import com.android.internal.telephony.metrics.TelephonyMetrics;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000232import com.android.internal.telephony.satellite.SatelliteController;
Jack Yu285100e2022-12-02 22:48:35 -0800233import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
234import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700235import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700236import com.android.internal.telephony.uicc.IccIoResult;
237import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800238import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700239import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800240import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700241import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000242import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800243import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000244import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800245import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000246import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700247import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700248import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800249import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800250import com.android.phone.callcomposer.CallComposerPictureManager;
251import com.android.phone.callcomposer.CallComposerPictureTransfer;
252import com.android.phone.callcomposer.ImageData;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800253import com.android.phone.satellite.accesscontrol.SatelliteAccessController;
Hyosun Kim240214a2023-11-02 13:30:15 +0000254import com.android.phone.satellite.entitlement.SatelliteEntitlementController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700255import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700256import com.android.phone.slice.SlicePurchaseController;
arunvoddud7401012022-12-15 16:08:12 +0000257import com.android.phone.utils.CarrierAllowListInfo;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700258import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800259import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700260import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700261import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -0800262import com.android.server.feature.flags.Flags;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800263import com.android.services.telephony.TelecomAccountRegistry;
264import com.android.services.telephony.TelephonyConnectionService;
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;
joonhunshinf624b2a2024-04-18 04:42:12 +0000441 private final int mVendorApiLevel;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700442
Peter Wangdafb9ac2020-01-15 14:13:38 -0800443 /** User Activity */
Sarah Chin4beb2b72023-02-14 14:47:54 -0800444 private final AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800445 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800446 private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800447
Derek Tan97ebb422014-09-05 16:55:38 -0700448 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
449 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800450 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800451 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700452
Michelecea4cf22018-12-21 15:00:11 -0800453 // String to store multi SIM allowed
454 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
455
Derek Tan740e1672017-06-27 14:56:27 -0700456 // The AID of ISD-R.
457 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
458
yinxub1bed742017-04-17 11:45:04 -0700459 private NetworkScanRequestTracker mNetworkScanRequestTracker;
460
David Kelly5e06a7f2018-03-12 14:10:59 +0000461 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
462 private static final int MANUFACTURER_CODE_LENGTH = 8;
463
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800464 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800465 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800466
Sarah Chin2ec39f62022-08-31 17:03:26 -0700467 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
468 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
469
Derek Tan89e89d42014-07-08 17:00:10 -0700470 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700471 * Experiment flag to enable erase modem config on reset network, default value is false
472 */
473 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
474 "reset_network_erase_modem_config_enabled";
475
Rambo Wang0f050d82021-02-12 11:43:36 -0800476 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800477
Gary Jian76280a42022-12-07 16:18:33 +0800478 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
479
sandeepjsb6c87872021-09-27 15:34:44 +0000480 /**
481 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
482 * one ICCID active at the same time.
483 * Apps should use below API signatures if targeting SDK is T and beyond.
484 *
485 * @hide
486 */
487 @ChangeId
488 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
489 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800490
Naina Nallurid63128d2019-09-17 14:10:30 -0700491 /**
Chen Xu540470b2021-12-14 17:15:47 -0800492 * Apps targeting on Android T and beyond will get exception whenever icc close channel
493 * operation fails.
494 */
495 @ChangeId
496 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
497 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
498
499 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700500 * A request object to use for transmitting data to an ICC.
501 */
502 private static final class IccAPDUArgument {
503 public int channel, cla, command, p1, p2, p3;
504 public String data;
505
506 public IccAPDUArgument(int channel, int cla, int command,
507 int p1, int p2, int p3, String data) {
508 this.channel = channel;
509 this.cla = cla;
510 this.command = command;
511 this.p1 = p1;
512 this.p2 = p2;
513 this.p3 = p3;
514 this.data = data;
515 }
516 }
517
518 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700519 * A request object to use for transmitting data to an ICC.
520 */
521 private static final class ManualNetworkSelectionArgument {
522 public OperatorInfo operatorInfo;
523 public boolean persistSelection;
524
525 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
526 this.operatorInfo = operatorInfo;
527 this.persistSelection = persistSelection;
528 }
529 }
530
Sarah Chin71b3a852022-09-28 15:54:19 -0700531 private static final class PurchasePremiumCapabilityArgument {
532 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700533 public @NonNull IIntegerConsumer callback;
534
535 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800536 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700537 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700538 this.callback = callback;
539 }
540 }
541
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700542 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700543 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
544 * request after sending. The main thread will notify the request when it is complete.
545 */
546 private static final class MainThreadRequest {
547 /** The argument to use for the request */
548 public Object argument;
549 /** The result of the request that is run on the main thread */
550 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800551 // The subscriber id that this request applies to. Defaults to
552 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
553 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700554
Nathan Harold92bed182018-10-12 18:16:49 -0700555 // In cases where subId is unavailable, the caller needs to specify the phone.
556 public Phone phone;
557
vagdeviaf9a5b92018-08-15 16:01:53 -0700558 public WorkSource workSource;
559
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700560 public MainThreadRequest(Object argument) {
561 this.argument = argument;
562 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800563
Nathan Harold92bed182018-10-12 18:16:49 -0700564 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
565 this.argument = argument;
566 if (phone != null) {
567 this.phone = phone;
568 }
569 this.workSource = workSource;
570 }
571
vagdeviaf9a5b92018-08-15 16:01:53 -0700572 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800573 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800574 if (subId != null) {
575 this.subId = subId;
576 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700577 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800578 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700579 }
580
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800581 private static final class IncomingThirdPartyCallArgs {
582 public final ComponentName component;
583 public final String callId;
584 public final String callerDisplayName;
585
586 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
587 String callerDisplayName) {
588 this.component = component;
589 this.callId = callId;
590 this.callerDisplayName = callerDisplayName;
591 }
592 }
593
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700594 /**
595 * A handler that processes messages on the main thread in the phone process. Since many
596 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
597 * inbound binder threads to the main thread in the phone process. The Binder thread
598 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
599 * on, which will be notified when the operation completes and will contain the result of the
600 * request.
601 *
602 * <p>If a MainThreadRequest object is provided in the msg.obj field,
603 * note that request.result must be set to something non-null for the calling thread to
604 * unblock.
605 */
606 private final class MainThreadHandler extends Handler {
607 @Override
608 public void handleMessage(Message msg) {
609 MainThreadRequest request;
610 Message onCompleted;
611 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000612 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700613 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800614 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700615
616 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700617 case CMD_HANDLE_USSD_REQUEST: {
618 request = (MainThreadRequest) msg.obj;
619 final Phone phone = getPhoneFromRequest(request);
620 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800621 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700622 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700623
Pengquan Menga1bb6272018-09-06 09:59:22 -0700624 if (!isUssdApiAllowed(request.subId)) {
625 // Carrier does not support use of this API, return failure.
626 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
627 UssdResponse response = new UssdResponse(ussdRequest, null);
628 Bundle returnData = new Bundle();
629 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
630 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700631
Pengquan Menga1bb6272018-09-06 09:59:22 -0700632 request.result = true;
633 notifyRequester(request);
634 return;
635 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700636
Pengquan Menga1bb6272018-09-06 09:59:22 -0700637 try {
638 request.result = phone != null
639 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
640 } catch (CallStateException cse) {
641 request.result = false;
642 }
643 // Wake up the requesting thread
644 notifyRequester(request);
645 break;
pkanwar32d516d2016-10-14 19:37:38 -0700646 }
647
Yorke Lee716f67e2015-06-17 15:39:16 -0700648 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700649 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700650 final Phone phone = getPhoneFromRequest(request);
651 request.result = phone != null ?
652 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
653 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700654 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700655 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700656 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700657 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700658
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700659 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700660 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700661 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000662 uiccPort = getUiccPortFromRequest(request);
663 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700664 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800665 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700666 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700667 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700668 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800669 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000670 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800671 iccArgument.channel, iccArgument.cla, iccArgument.command,
672 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
673 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700674 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700675 break;
676
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700677 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700678 ar = (AsyncResult) msg.obj;
679 request = (MainThreadRequest) ar.userObj;
680 if (ar.exception == null && ar.result != null) {
681 request.result = ar.result;
682 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800683 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700684 if (ar.result == null) {
685 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800686 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700687 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800688 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700689 } else {
690 loge("iccTransmitApduLogicalChannel: Unknown exception");
691 }
692 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700693 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700694 break;
695
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700696 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
697 request = (MainThreadRequest) msg.obj;
698 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000699 uiccPort = getUiccPortFromRequest(request);
700 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700701 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800702 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700703 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700704 } else {
705 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800706 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000707 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800708 iccArgument.cla, iccArgument.command, iccArgument.p1,
709 iccArgument.p2,
710 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700711 }
712 break;
713
714 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
715 ar = (AsyncResult) msg.obj;
716 request = (MainThreadRequest) ar.userObj;
717 if (ar.exception == null && ar.result != null) {
718 request.result = ar.result;
719 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800720 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700721 if (ar.result == null) {
722 loge("iccTransmitApduBasicChannel: Empty response");
723 } else if (ar.exception instanceof CommandException) {
724 loge("iccTransmitApduBasicChannel: CommandException: " +
725 ar.exception);
726 } else {
727 loge("iccTransmitApduBasicChannel: Unknown exception");
728 }
729 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700730 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700731 break;
732
733 case CMD_EXCHANGE_SIM_IO:
734 request = (MainThreadRequest) msg.obj;
735 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000736 uiccPort = getUiccPortFromRequest(request);
737 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700738 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800739 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700740 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700741 } else {
742 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
743 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000744 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700745 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
746 iccArgument.data, onCompleted);
747 }
748 break;
749
750 case EVENT_EXCHANGE_SIM_IO_DONE:
751 ar = (AsyncResult) msg.obj;
752 request = (MainThreadRequest) ar.userObj;
753 if (ar.exception == null && ar.result != null) {
754 request.result = ar.result;
755 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800756 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700757 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700758 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700759 break;
760
Derek Tan4d5e5c12014-02-04 11:54:58 -0800761 case CMD_SEND_ENVELOPE:
762 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000763 uiccPort = getUiccPortFromRequest(request);
764 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700765 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800766 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700767 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700768 } else {
769 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800770 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700771 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800772 break;
773
774 case EVENT_SEND_ENVELOPE_DONE:
775 ar = (AsyncResult) msg.obj;
776 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700777 if (ar.exception == null && ar.result != null) {
778 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800779 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800780 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700781 if (ar.result == null) {
782 loge("sendEnvelopeWithStatus: Empty response");
783 } else if (ar.exception instanceof CommandException) {
784 loge("sendEnvelopeWithStatus: CommandException: " +
785 ar.exception);
786 } else {
787 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
788 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800789 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700790 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800791 break;
792
Shishir Agrawal566b7612013-10-28 14:41:00 -0700793 case CMD_OPEN_CHANNEL:
794 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000795 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800796 IccLogicalChannelRequest openChannelRequest =
797 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000798 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700799 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800800 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800801 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700802 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700803 } else {
804 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800805 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
806 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700807 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700808 break;
809
810 case EVENT_OPEN_CHANNEL_DONE:
811 ar = (AsyncResult) msg.obj;
812 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700813 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700814 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700815 int[] result = (int[]) ar.result;
816 int channelId = result[0];
817 byte[] selectResponse = null;
818 if (result.length > 1) {
819 selectResponse = new byte[result.length - 1];
820 for (int i = 1; i < result.length; ++i) {
821 selectResponse[i - 1] = (byte) result[i];
822 }
823 }
824 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800825 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800826
827 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700828 if (uiccPort == null) {
829 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
830 } else {
831 IccLogicalChannelRequest channelRequest =
832 (IccLogicalChannelRequest) request.argument;
833 channelRequest.channel = channelId;
834 uiccPort.onLogicalChannelOpened(channelRequest);
835 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700836 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700837 if (ar.result == null) {
838 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700839 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700840 if (ar.exception != null) {
841 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
842 }
843
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700844 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700845 if (ar.exception instanceof CommandException) {
846 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800847 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700848 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700849 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700850 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700851 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700852 }
853 }
854 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800855 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700856 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700857 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700858 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700859 break;
860
861 case CMD_CLOSE_CHANNEL:
862 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000863 uiccPort = getUiccPortFromRequest(request);
864 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700865 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800866 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800867 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800868 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700869 } else {
870 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000871 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700872 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700873 break;
874
875 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800876 ar = (AsyncResult) msg.obj;
877 request = (MainThreadRequest) ar.userObj;
878 if (ar.exception == null) {
879 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800880 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700881 if (uiccPort == null) {
882 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
883 } else {
884 final int channelId = (Integer) request.argument;
885 uiccPort.onLogicalChannelClosed(channelId);
886 }
Chen Xu540470b2021-12-14 17:15:47 -0800887 } else {
888 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800889 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800890 if (ar.exception instanceof CommandException) {
891 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
892 CommandException.Error error =
893 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800894 if (error == CommandException.Error.INVALID_ARGUMENTS) {
895 // should only throw exceptions from the binder threads.
896 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800897 "iccCloseLogicalChannel: invalid argument ");
898 }
899 } else {
900 loge("iccCloseLogicalChannel: Unknown exception");
901 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800902 request.result = (exception != null) ? exception :
903 new IllegalStateException(
904 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800905 }
906 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800907 break;
908
909 case CMD_NV_READ_ITEM:
910 request = (MainThreadRequest) msg.obj;
911 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800912 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
913 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800914 break;
915
916 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700917 ar = (AsyncResult) msg.obj;
918 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800919 if (ar.exception == null && ar.result != null) {
920 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700921 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800922 request.result = "";
923 if (ar.result == null) {
924 loge("nvReadItem: Empty response");
925 } else if (ar.exception instanceof CommandException) {
926 loge("nvReadItem: CommandException: " +
927 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700928 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800929 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700930 }
931 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700932 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700933 break;
934
Jake Hambye994d462014-02-03 13:10:13 -0800935 case CMD_NV_WRITE_ITEM:
936 request = (MainThreadRequest) msg.obj;
937 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
938 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800939 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700940 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800941 break;
942
943 case EVENT_NV_WRITE_ITEM_DONE:
944 handleNullReturnEvent(msg, "nvWriteItem");
945 break;
946
947 case CMD_NV_WRITE_CDMA_PRL:
948 request = (MainThreadRequest) msg.obj;
949 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800950 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800951 break;
952
953 case EVENT_NV_WRITE_CDMA_PRL_DONE:
954 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
955 break;
956
chen xu6dac5ab2018-10-26 17:39:23 -0700957 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800958 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700959 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800960 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800961 break;
962
chen xu6dac5ab2018-10-26 17:39:23 -0700963 case EVENT_RESET_MODEM_CONFIG_DONE:
964 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800965 break;
966
Sooraj Sasindran37444802020-08-11 10:40:43 -0700967 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
968 request = (MainThreadRequest) msg.obj;
969 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
970 request);
971 Phone phone = getPhoneFromRequest(request);
972 if (phone != null) {
973 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
974 } else {
975 loge("isNRDualConnectivityEnabled: No phone object");
976 request.result = false;
977 notifyRequester(request);
978 }
979 break;
980 }
981
982 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
983 ar = (AsyncResult) msg.obj;
984 request = (MainThreadRequest) ar.userObj;
985 if (ar.exception == null && ar.result != null) {
986 request.result = ar.result;
987 } else {
988 // request.result must be set to something non-null
989 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700990 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700991 request.result = ar.result;
992 } else {
993 request.result = false;
994 }
995 if (ar.result == null) {
996 loge("isNRDualConnectivityEnabled: Empty response");
997 } else if (ar.exception instanceof CommandException) {
998 loge("isNRDualConnectivityEnabled: CommandException: "
999 + ar.exception);
1000 } else {
1001 loge("isNRDualConnectivityEnabled: Unknown exception");
1002 }
1003 }
1004 notifyRequester(request);
1005 break;
1006
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001007 case CMD_IS_VONR_ENABLED: {
1008 request = (MainThreadRequest) msg.obj;
1009 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
1010 request);
1011 Phone phone = getPhoneFromRequest(request);
1012 if (phone != null) {
1013 phone.isVoNrEnabled(onCompleted, request.workSource);
1014 } else {
1015 loge("isVoNrEnabled: No phone object");
1016 request.result = false;
1017 notifyRequester(request);
1018 }
1019 break;
1020 }
1021
1022 case EVENT_IS_VONR_ENABLED_DONE:
1023 ar = (AsyncResult) msg.obj;
1024 request = (MainThreadRequest) ar.userObj;
1025 if (ar.exception == null && ar.result != null) {
1026 request.result = ar.result;
1027 } else {
1028 // request.result must be set to something non-null
1029 // for the calling thread to unblock
1030 if (ar.result != null) {
1031 request.result = ar.result;
1032 } else {
1033 request.result = false;
1034 }
1035 if (ar.result == null) {
1036 loge("isVoNrEnabled: Empty response");
1037 } else if (ar.exception instanceof CommandException) {
1038 loge("isVoNrEnabled: CommandException: "
1039 + ar.exception);
1040 } else {
1041 loge("isVoNrEnabled: Unknown exception");
1042 }
1043 }
1044 notifyRequester(request);
1045 break;
1046
Sooraj Sasindran37444802020-08-11 10:40:43 -07001047 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1048 request = (MainThreadRequest) msg.obj;
1049 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1050 Phone phone = getPhoneFromRequest(request);
1051 if (phone != null) {
1052 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1053 request.workSource);
1054 } else {
1055 loge("enableNrDualConnectivity: No phone object");
1056 request.result =
1057 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1058 notifyRequester(request);
1059 }
1060 break;
1061 }
1062
1063 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1064 ar = (AsyncResult) msg.obj;
1065 request = (MainThreadRequest) ar.userObj;
1066 if (ar.exception == null) {
1067 request.result =
1068 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1069 } else {
1070 request.result =
1071 TelephonyManager
1072 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1073 if (ar.exception instanceof CommandException) {
1074 CommandException.Error error =
1075 ((CommandException) (ar.exception)).getCommandError();
1076 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1077 request.result =
1078 TelephonyManager
1079 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001080 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1081 request.result =
1082 TelephonyManager
1083 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001084 }
1085 loge("enableNrDualConnectivity" + ": CommandException: "
1086 + ar.exception);
1087 } else {
1088 loge("enableNrDualConnectivity" + ": Unknown exception");
1089 }
1090 }
1091 notifyRequester(request);
1092 break;
1093 }
1094
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001095 case CMD_ENABLE_VONR: {
1096 request = (MainThreadRequest) msg.obj;
1097 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1098 Phone phone = getPhoneFromRequest(request);
1099 if (phone != null) {
1100 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1101 request.workSource);
1102 } else {
1103 loge("setVoNrEnabled: No phone object");
1104 request.result =
1105 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1106 notifyRequester(request);
1107 }
1108 break;
1109 }
1110
1111 case EVENT_ENABLE_VONR_DONE: {
1112 ar = (AsyncResult) msg.obj;
1113 request = (MainThreadRequest) ar.userObj;
1114 if (ar.exception == null) {
1115 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1116 } else {
1117 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1118 if (ar.exception instanceof CommandException) {
1119 CommandException.Error error =
1120 ((CommandException) (ar.exception)).getCommandError();
1121 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1122 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1123 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1124 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1125 } else {
1126 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1127 }
1128 loge("setVoNrEnabled" + ": CommandException: "
1129 + ar.exception);
1130 } else {
1131 loge("setVoNrEnabled" + ": Unknown exception");
1132 }
1133 }
1134 notifyRequester(request);
1135 break;
1136 }
1137
SongFerngWang3ef3e072020-12-21 16:41:52 +08001138 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001139 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001140 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1141 request);
1142 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001143 break;
1144
SongFerngWang3ef3e072020-12-21 16:41:52 +08001145 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001146 ar = (AsyncResult) msg.obj;
1147 request = (MainThreadRequest) ar.userObj;
1148 if (ar.exception == null && ar.result != null) {
1149 request.result = ar.result; // Integer
1150 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301151 // request.result must be set to something non-null
1152 // for the calling thread to unblock
1153 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001154 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001155 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001156 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001157 loge("getAllowedNetworkTypesBitmask: CommandException: "
1158 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001159 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001160 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001161 }
1162 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001163 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001164 break;
1165
SongFerngWang3ef3e072020-12-21 16:41:52 +08001166 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001167 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001168 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1169 request);
1170 Pair<Integer, Long> reasonWithNetworkTypes =
1171 (Pair<Integer, Long>) request.argument;
1172 getPhoneFromRequest(request).setAllowedNetworkTypes(
1173 reasonWithNetworkTypes.first,
1174 reasonWithNetworkTypes.second,
1175 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001176 break;
1177
SongFerngWang3ef3e072020-12-21 16:41:52 +08001178 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1179 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001180 break;
1181
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001182 case CMD_SET_VOICEMAIL_NUMBER:
1183 request = (MainThreadRequest) msg.obj;
1184 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1185 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001186 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1187 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001188 break;
1189
1190 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1191 handleNullReturnEvent(msg, "setVoicemailNumber");
1192 break;
1193
Stuart Scott54788802015-03-30 13:18:01 -07001194 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1195 request = (MainThreadRequest) msg.obj;
1196 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1197 request);
1198 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1199 break;
1200
1201 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1202 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1203 break;
1204
Shishir Agrawal302c8692015-06-19 13:49:39 -07001205 case CMD_PERFORM_NETWORK_SCAN:
1206 request = (MainThreadRequest) msg.obj;
1207 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1208 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1209 break;
1210
Hall Liu27d24262020-09-18 19:04:59 -07001211 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001212 request = (MainThreadRequest) msg.obj;
1213 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001214 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1215 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1216 request.argument;
1217 int callForwardingReason = args.first;
1218 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001219 break;
Hall Liu27d24262020-09-18 19:04:59 -07001220 }
1221 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001222 ar = (AsyncResult) msg.obj;
1223 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001224 TelephonyManager.CallForwardingInfoCallback callback =
1225 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1226 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001227 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001228 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001229 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1230 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1231 // Service Class is a bit mask per 3gpp 27.007. Search for
1232 // any service for voice call.
1233 if ((callForwardInfo.serviceClass
1234 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001235 callForwardingInfo = new CallForwardingInfo(
1236 callForwardInfo.status
1237 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001238 callForwardInfo.reason,
1239 callForwardInfo.number,
1240 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001241 break;
1242 }
1243 }
1244 // Didn't find a call forward info for voice call.
1245 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001246 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1247 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001248 }
Hall Liu27d24262020-09-18 19:04:59 -07001249 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001250 } else {
1251 if (ar.result == null) {
1252 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1253 }
1254 if (ar.exception != null) {
1255 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1256 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001257 int errorCode = TelephonyManager
1258 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001259 if (ar.exception instanceof CommandException) {
1260 CommandException.Error error =
1261 ((CommandException) (ar.exception)).getCommandError();
1262 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001263 errorCode = TelephonyManager
1264 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001265 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001266 errorCode = TelephonyManager
1267 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001268 }
1269 }
Hall Liu27d24262020-09-18 19:04:59 -07001270 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001271 }
Shuo Qian4a594052020-01-23 11:59:30 -08001272 break;
Hall Liu27d24262020-09-18 19:04:59 -07001273 }
Shuo Qian4a594052020-01-23 11:59:30 -08001274
Hall Liu27d24262020-09-18 19:04:59 -07001275 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001276 request = (MainThreadRequest) msg.obj;
1277 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001278 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001279 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001280 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1281 request.argument).first;
1282 request.phone.setCallForwardingOption(
1283 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001284 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001285 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001286 callForwardingInfoToSet.getReason(),
1287 callForwardingInfoToSet.getNumber(),
1288 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1289 break;
Hall Liu27d24262020-09-18 19:04:59 -07001290 }
Shuo Qian4a594052020-01-23 11:59:30 -08001291
Hall Liu27d24262020-09-18 19:04:59 -07001292 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001293 ar = (AsyncResult) msg.obj;
1294 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001295 Consumer<Integer> callback =
1296 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1297 request.argument).second;
1298 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001299 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001300 int errorCode = TelephonyManager.CallForwardingInfoCallback
1301 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001302 if (ar.exception instanceof CommandException) {
1303 CommandException.Error error =
1304 ((CommandException) (ar.exception)).getCommandError();
1305 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001306 errorCode = TelephonyManager.CallForwardingInfoCallback
1307 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001308 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001309 errorCode = TelephonyManager.CallForwardingInfoCallback
1310 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001311 }
1312 }
1313 callback.accept(errorCode);
1314 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001315 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001316 }
Shuo Qian4a594052020-01-23 11:59:30 -08001317 break;
Hall Liu27d24262020-09-18 19:04:59 -07001318 }
Shuo Qian4a594052020-01-23 11:59:30 -08001319
Hall Liu27d24262020-09-18 19:04:59 -07001320 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001321 request = (MainThreadRequest) msg.obj;
1322 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1323 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1324 break;
Hall Liu27d24262020-09-18 19:04:59 -07001325 }
Shuo Qian4a594052020-01-23 11:59:30 -08001326
Hall Liu27d24262020-09-18 19:04:59 -07001327 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001328 ar = (AsyncResult) msg.obj;
1329 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001330 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001331 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001332 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001333 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001334 // Service Class is a bit mask per 3gpp 27.007.
1335 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001336 if (callForwardResults.length > 1
1337 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001338 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001339 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001340 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1341 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001342 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001343 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001344 }
1345 } else {
1346 if (ar.result == null) {
1347 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1348 }
1349 if (ar.exception != null) {
1350 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1351 }
1352 if (ar.exception instanceof CommandException) {
1353 CommandException.Error error =
1354 ((CommandException) (ar.exception)).getCommandError();
1355 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001356 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001357 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001358 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1359 callWaitingStatus =
1360 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001361 }
1362 }
1363 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001364 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001365 break;
Hall Liu27d24262020-09-18 19:04:59 -07001366 }
Shuo Qian4a594052020-01-23 11:59:30 -08001367
Hall Liu27d24262020-09-18 19:04:59 -07001368 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001369 request = (MainThreadRequest) msg.obj;
1370 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001371 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1372 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001373 break;
Hall Liu27d24262020-09-18 19:04:59 -07001374 }
Shuo Qian4a594052020-01-23 11:59:30 -08001375
Hall Liu27d24262020-09-18 19:04:59 -07001376 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001377 ar = (AsyncResult) msg.obj;
1378 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001379 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1380 Consumer<Integer> callback =
1381 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1382 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001383 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001384 if (ar.exception instanceof CommandException) {
1385 CommandException.Error error =
1386 ((CommandException) (ar.exception)).getCommandError();
1387 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1388 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001389 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1390 callback.accept(
1391 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001392 } else {
1393 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1394 }
1395 } else {
1396 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1397 }
1398 } else {
1399 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1400 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001401 }
Shuo Qian4a594052020-01-23 11:59:30 -08001402 break;
Hall Liu27d24262020-09-18 19:04:59 -07001403 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001404 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1405 ar = (AsyncResult) msg.obj;
1406 request = (MainThreadRequest) ar.userObj;
1407 CellNetworkScanResult cellScanResult;
1408 if (ar.exception == null && ar.result != null) {
1409 cellScanResult = new CellNetworkScanResult(
1410 CellNetworkScanResult.STATUS_SUCCESS,
1411 (List<OperatorInfo>) ar.result);
1412 } else {
1413 if (ar.result == null) {
1414 loge("getCellNetworkScanResults: Empty response");
1415 }
1416 if (ar.exception != null) {
1417 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1418 }
1419 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1420 if (ar.exception instanceof CommandException) {
1421 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001422 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001423 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1424 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1425 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1426 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1427 }
1428 }
1429 cellScanResult = new CellNetworkScanResult(errorCode, null);
1430 }
1431 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001432 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001433 break;
1434
1435 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1436 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001437 ManualNetworkSelectionArgument selArg =
1438 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001439 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1440 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001441 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1442 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001443 break;
1444
1445 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001446 ar = (AsyncResult) msg.obj;
1447 request = (MainThreadRequest) ar.userObj;
1448 if (ar.exception == null) {
1449 request.result = true;
1450 } else {
1451 request.result = false;
1452 loge("setNetworkSelectionModeManual " + ar.exception);
1453 }
1454 notifyRequester(request);
1455 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001456 break;
1457
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001458 case CMD_GET_MODEM_ACTIVITY_INFO:
1459 request = (MainThreadRequest) msg.obj;
1460 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001461 if (defaultPhone != null) {
1462 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001463 } else {
1464 ResultReceiver result = (ResultReceiver) request.argument;
1465 Bundle bundle = new Bundle();
1466 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001467 new ModemActivityInfo(0, 0, 0,
1468 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001469 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001470 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001471 break;
1472
Hall Liud0f208c2020-10-14 16:54:44 -07001473 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001474 ar = (AsyncResult) msg.obj;
1475 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001476 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001477 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001478 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001479 if (mLastModemActivityInfo == null) {
1480 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1481 mLastModemActivitySpecificInfo[0] =
1482 new ActivityStatsTechSpecificInfo(
1483 0,
1484 0,
1485 new int[ModemActivityInfo.getNumTxPowerLevels()],
1486 0);
1487 mLastModemActivityInfo =
1488 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1489 }
1490
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001491 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001492 // Update the last modem activity info and the result of the request.
1493 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1494 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001495 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001496 } else {
1497 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001498 }
Kai Shi917fdc62022-11-28 14:01:02 -08001499 // This is needed to decouple ret from mLastModemActivityInfo
1500 // We don't want to return mLastModemActivityInfo which is updated
1501 // inside mergeModemActivityInfo()
1502 ret = new ModemActivityInfo(
1503 mLastModemActivityInfo.getTimestampMillis(),
1504 mLastModemActivityInfo.getSleepTimeMillis(),
1505 mLastModemActivityInfo.getIdleTimeMillis(),
1506 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001507
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001508 } else {
1509 if (ar.result == null) {
1510 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001511 error = TelephonyManager.ModemActivityInfoException
1512 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001513 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001514 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001515 error = TelephonyManager.ModemActivityInfoException
1516 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001517 } else {
1518 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001519 error = TelephonyManager.ModemActivityInfoException
1520 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001521 }
1522 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001523 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001524 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001525 bundle.putParcelable(
1526 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001527 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001528 } else {
1529 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1530 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001531 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001532 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001533 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001534 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001535
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001536 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001537 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001538 CarrierRestrictionRules argument =
1539 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001540 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001541 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001542 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001543 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001544
1545 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1546 ar = (AsyncResult) msg.obj;
1547 request = (MainThreadRequest) ar.userObj;
1548 if (ar.exception == null && ar.result != null) {
1549 request.result = ar.result;
1550 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001551 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1552 if (ar.exception instanceof CommandException) {
1553 loge("setAllowedCarriers: CommandException: " + ar.exception);
1554 CommandException.Error error =
1555 ((CommandException) (ar.exception)).getCommandError();
1556 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1557 request.result =
1558 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1559 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001560 } else {
1561 loge("setAllowedCarriers: Unknown exception");
1562 }
1563 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001564 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001565 break;
1566
1567 case CMD_GET_ALLOWED_CARRIERS:
1568 request = (MainThreadRequest) msg.obj;
1569 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001570 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001571 break;
1572
1573 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1574 ar = (AsyncResult) msg.obj;
1575 request = (MainThreadRequest) ar.userObj;
1576 if (ar.exception == null && ar.result != null) {
1577 request.result = ar.result;
1578 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001579 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001580 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001581 if (ar.result == null) {
1582 loge("getAllowedCarriers: Empty response");
1583 } else if (ar.exception instanceof CommandException) {
1584 loge("getAllowedCarriers: CommandException: " +
1585 ar.exception);
1586 } else {
1587 loge("getAllowedCarriers: Unknown exception");
1588 }
1589 }
arunvoddud7401012022-12-15 16:08:12 +00001590 if (request.argument != null) {
1591 // This is for the implementation of carrierRestrictionStatus.
1592 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1593 Consumer<Integer> callback = callbackInfo.getConsumer();
Steve Statia28b7cb32024-03-11 23:58:50 +00001594 Set<Integer> callerCarrierIds = callbackInfo.getCarrierIds();
arunvoddud7401012022-12-15 16:08:12 +00001595 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1596 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1597 CarrierRestrictionRules carrierRestrictionRules =
1598 (CarrierRestrictionRules) ar.result;
1599 int carrierId = -1;
1600 try {
1601 CarrierIdentifier carrierIdentifier =
1602 carrierRestrictionRules.getAllowedCarriers().get(0);
1603 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1604 carrierIdentifier);
1605 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1606 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1607 }
1608 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
Steve Statia28b7cb32024-03-11 23:58:50 +00001609 int restrictedStatus =
1610 TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED;
1611 if (carrierId != -1 && callerCarrierIds.contains(carrierId) &&
1612 lockStatus == restrictedStatus) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001613 lockStatus = TelephonyManager
1614 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001615 }
1616 } else {
1617 Rlog.e(LOG_TAG,
1618 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1619 }
1620 callback.accept(lockStatus);
1621 } else {
1622 // This is for the implementation of getAllowedCarriers.
1623 notifyRequester(request);
1624 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001625 break;
1626
Nathan Haroldb3014052017-01-25 15:57:32 -08001627 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1628 ar = (AsyncResult) msg.obj;
1629 request = (MainThreadRequest) ar.userObj;
1630 if (ar.exception == null && ar.result != null) {
1631 request.result = ar.result;
1632 } else {
1633 request.result = new IllegalArgumentException(
1634 "Failed to retrieve Forbidden Plmns");
1635 if (ar.result == null) {
1636 loge("getForbiddenPlmns: Empty response");
1637 } else {
1638 loge("getForbiddenPlmns: Unknown exception");
1639 }
1640 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001641 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001642 break;
1643
1644 case CMD_GET_FORBIDDEN_PLMNS:
1645 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001646 uiccPort = getUiccPortFromRequest(request);
1647 if (uiccPort == null) {
1648 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001649 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001650 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001651 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001652 break;
1653 }
1654 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001655 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001656 if (uiccApp == null) {
1657 loge("getForbiddenPlmns() no app with specified type -- "
1658 + appType);
1659 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001660 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001661 break;
1662 } else {
1663 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1664 + " specified type -- " + appType);
1665 }
1666 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1667 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001668 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001669 break;
1670
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001671 case CMD_SWITCH_SLOTS:
1672 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001673 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001674 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001675 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001676 break;
1677
1678 case EVENT_SWITCH_SLOTS_DONE:
1679 ar = (AsyncResult) msg.obj;
1680 request = (MainThreadRequest) ar.userObj;
1681 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001682 notifyRequester(request);
1683 break;
1684 case CMD_GET_NETWORK_SELECTION_MODE:
1685 request = (MainThreadRequest) msg.obj;
1686 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1687 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1688 break;
1689
1690 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1691 ar = (AsyncResult) msg.obj;
1692 request = (MainThreadRequest) ar.userObj;
1693 if (ar.exception != null) {
1694 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1695 } else {
1696 int mode = ((int[]) ar.result)[0];
1697 if (mode == 0) {
1698 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1699 } else {
1700 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1701 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001702 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001703 notifyRequester(request);
1704 break;
1705 case CMD_GET_CDMA_ROAMING_MODE:
1706 request = (MainThreadRequest) msg.obj;
1707 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1708 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1709 break;
1710 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1711 ar = (AsyncResult) msg.obj;
1712 request = (MainThreadRequest) ar.userObj;
1713 if (ar.exception != null) {
1714 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1715 } else {
1716 request.result = ((int[]) ar.result)[0];
1717 }
1718 notifyRequester(request);
1719 break;
1720 case CMD_SET_CDMA_ROAMING_MODE:
1721 request = (MainThreadRequest) msg.obj;
1722 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1723 int mode = (int) request.argument;
1724 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1725 break;
1726 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1727 ar = (AsyncResult) msg.obj;
1728 request = (MainThreadRequest) ar.userObj;
1729 request.result = ar.exception == null;
1730 notifyRequester(request);
1731 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001732 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1733 request = (MainThreadRequest) msg.obj;
1734 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1735 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1736 break;
1737 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1738 ar = (AsyncResult) msg.obj;
1739 request = (MainThreadRequest) ar.userObj;
1740 if (ar.exception != null) {
1741 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1742 } else {
1743 request.result = ((int[]) ar.result)[0];
1744 }
1745 notifyRequester(request);
1746 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001747 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1748 request = (MainThreadRequest) msg.obj;
1749 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1750 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001751 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1752 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001753 break;
1754 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1755 ar = (AsyncResult) msg.obj;
1756 request = (MainThreadRequest) ar.userObj;
1757 request.result = ar.exception == null;
1758 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001759 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001760 case CMD_GET_ALL_CELL_INFO:
1761 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001762 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001763 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001764 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001765 case EVENT_GET_ALL_CELL_INFO_DONE:
1766 ar = (AsyncResult) msg.obj;
1767 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001768 // If a timeout occurs, the response will be null
1769 request.result = (ar.exception == null && ar.result != null)
1770 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001771 synchronized (request) {
1772 request.notifyAll();
1773 }
1774 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001775 case CMD_REQUEST_CELL_INFO_UPDATE:
1776 request = (MainThreadRequest) msg.obj;
1777 request.phone.requestCellInfoUpdate(request.workSource,
1778 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1779 break;
1780 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1781 ar = (AsyncResult) msg.obj;
1782 request = (MainThreadRequest) ar.userObj;
1783 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1784 try {
1785 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001786 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001787 cb.onError(
1788 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1789 ar.exception.getClass().getName(),
1790 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001791 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001792 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001793 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001794 } else {
1795 // use the result as returned
1796 cb.onCellInfo((List<CellInfo>) ar.result);
1797 }
1798 } catch (RemoteException re) {
1799 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1800 }
1801 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001802 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001803 request = (MainThreadRequest) msg.obj;
1804 WorkSource ws = (WorkSource) request.argument;
1805 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001806 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001807 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001808 }
1809 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001810 ar = (AsyncResult) msg.obj;
1811 request = (MainThreadRequest) ar.userObj;
1812 if (ar.exception == null) {
1813 request.result = ar.result;
1814 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001815 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001816 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001817 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001818 }
1819
1820 synchronized (request) {
1821 request.notifyAll();
1822 }
1823 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001824 }
chen xu6dac5ab2018-10-26 17:39:23 -07001825 case CMD_MODEM_REBOOT:
1826 request = (MainThreadRequest) msg.obj;
1827 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001828 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001829 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001830 case EVENT_CMD_MODEM_REBOOT_DONE:
1831 handleNullReturnEvent(msg, "rebootModem");
1832 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001833 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001834 request = (MainThreadRequest) msg.obj;
1835 boolean enable = (boolean) request.argument;
1836 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001837 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001838 PhoneConfigurationManager.getInstance()
1839 .enablePhone(request.phone, enable, onCompleted);
1840 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001841 }
Michele Berionne5e411512020-11-13 02:36:59 +00001842 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001843 ar = (AsyncResult) msg.obj;
1844 request = (MainThreadRequest) ar.userObj;
1845 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001846 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001847 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001848 if ((boolean) request.result) {
1849 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1850 updateModemStateMetrics();
1851 } else {
1852 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1853 + ar.exception);
1854 }
1855 notifyRequester(request);
1856 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001857 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001858 case CMD_GET_MODEM_STATUS:
1859 request = (MainThreadRequest) msg.obj;
1860 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1861 PhoneConfigurationManager.getInstance()
1862 .getPhoneStatusFromModem(request.phone, onCompleted);
1863 break;
1864 case EVENT_GET_MODEM_STATUS_DONE:
1865 ar = (AsyncResult) msg.obj;
1866 request = (MainThreadRequest) ar.userObj;
1867 int id = request.phone.getPhoneId();
1868 if (ar.exception == null && ar.result != null) {
1869 request.result = ar.result;
1870 //update the cache as modem status has changed
1871 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1872 (boolean) request.result);
1873 } else {
1874 // Return true if modem status cannot be retrieved. For most cases,
1875 // modem status is on. And for older version modems, GET_MODEM_STATUS
1876 // and disable modem are not supported. Modem is always on.
1877 // TODO: this should be fixed in R to support a third
1878 // status UNKNOWN b/131631629
1879 request.result = true;
1880 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1881 + ar.exception);
1882 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001883 notifyRequester(request);
1884 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001885 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1886 request = (MainThreadRequest) msg.obj;
1887 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1888 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1889 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1890 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1891 break;
1892 }
1893 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1894 ar = (AsyncResult) msg.obj;
1895 request = (MainThreadRequest) ar.userObj;
1896 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1897 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1898 args.second.accept(ar.exception == null);
1899 notifyRequester(request);
1900 break;
1901 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001902 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1903 request = (MainThreadRequest) msg.obj;
1904 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1905 Phone phone = getPhoneFromRequest(request);
1906 if (phone != null) {
1907 phone.getSystemSelectionChannels(onCompleted);
1908 } else {
1909 loge("getSystemSelectionChannels: No phone object");
1910 request.result = new ArrayList<RadioAccessSpecifier>();
1911 notifyRequester(request);
1912 }
1913 break;
1914 }
1915 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1916 ar = (AsyncResult) msg.obj;
1917 request = (MainThreadRequest) ar.userObj;
1918 if (ar.exception == null && ar.result != null) {
1919 request.result = ar.result;
1920 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001921 request.result = new IllegalStateException(
1922 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001923 if (ar.result == null) {
1924 loge("getSystemSelectionChannels: Empty response");
1925 } else {
1926 loge("getSystemSelectionChannels: Unknown exception");
1927 }
1928 }
1929 notifyRequester(request);
1930 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001931 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1932 ar = (AsyncResult) msg.obj;
1933 request = (MainThreadRequest) ar.userObj;
1934 if (ar.exception == null && ar.result != null) {
1935 request.result = ar.result;
1936 } else {
1937 request.result = -1;
1938 loge("Failed to set Forbidden Plmns");
1939 if (ar.result == null) {
1940 loge("setForbidenPlmns: Empty response");
1941 } else if (ar.exception != null) {
1942 loge("setForbiddenPlmns: Exception: " + ar.exception);
1943 request.result = -1;
1944 } else {
1945 loge("setForbiddenPlmns: Unknown exception");
1946 }
1947 }
1948 notifyRequester(request);
1949 break;
1950 case CMD_SET_FORBIDDEN_PLMNS:
1951 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001952 uiccPort = getUiccPortFromRequest(request);
1953 if (uiccPort == null) {
1954 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001955 request.result = -1;
1956 notifyRequester(request);
1957 break;
1958 }
1959 Pair<Integer, List<String>> setFplmnsArgs =
1960 (Pair<Integer, List<String>>) request.argument;
1961 appType = setFplmnsArgs.first;
1962 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001963 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001964 if (uiccApp == null) {
1965 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1966 request.result = -1;
1967 loge("Failed to get UICC App");
1968 notifyRequester(request);
1969 } else {
1970 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1971 ((SIMRecords) uiccApp.getIccRecords())
1972 .setForbiddenPlmns(onCompleted, fplmns);
1973 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001974 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001975 case CMD_ERASE_MODEM_CONFIG:
1976 request = (MainThreadRequest) msg.obj;
1977 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1978 defaultPhone.eraseModemConfig(onCompleted);
1979 break;
1980 case EVENT_ERASE_MODEM_CONFIG_DONE:
1981 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001982 break;
zoey chene02881a2019-12-30 16:11:23 +08001983
Kai Shif70f46f2021-03-03 13:59:46 -08001984 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1985 request = (MainThreadRequest) msg.obj;
1986 request.result = defaultPhone.eraseDataInSharedPreferences();
1987 notifyRequester(request);
1988 break;
1989
zoey chene02881a2019-12-30 16:11:23 +08001990 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1991 request = (MainThreadRequest) msg.obj;
1992 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1993 Pair<String, String> changed = (Pair<String, String>) request.argument;
1994 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1995 changed.first, changed.second, onCompleted);
1996 break;
1997 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1998 ar = (AsyncResult) msg.obj;
1999 request = (MainThreadRequest) ar.userObj;
2000 if (ar.exception == null) {
2001 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002002 // If the operation is successful, update the PIN storage
2003 Pair<String, String> passwords = (Pair<String, String>) request.argument;
2004 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00002005 UiccController.getInstance().getPinStorage()
2006 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08002007 } else {
2008 request.result = msg.arg1;
2009 }
2010 notifyRequester(request);
2011 break;
2012
Michele Berionne5e411512020-11-13 02:36:59 +00002013 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08002014 request = (MainThreadRequest) msg.obj;
2015 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
2016 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2017 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2018 enabled.first, enabled.second, onCompleted);
2019 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002020 }
zoey chene02881a2019-12-30 16:11:23 +08002021 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2022 ar = (AsyncResult) msg.obj;
2023 request = (MainThreadRequest) ar.userObj;
2024 if (ar.exception == null) {
2025 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002026 // If the operation is successful, update the PIN storage
2027 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2028 int phoneId = getPhoneFromRequest(request).getPhoneId();
2029 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002030 UiccController.getInstance().getPinStorage()
2031 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002032 } else {
2033 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2034 }
zoey chene02881a2019-12-30 16:11:23 +08002035 } else {
2036 request.result = msg.arg1;
2037 }
Michele Berionne5e411512020-11-13 02:36:59 +00002038
2039
zoey chene02881a2019-12-30 16:11:23 +08002040 notifyRequester(request);
2041 break;
2042
Peter Wangdafb9ac2020-01-15 14:13:38 -08002043 case MSG_NOTIFY_USER_ACTIVITY:
2044 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002045 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002046 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2047 getDefaultPhone().getContext().sendBroadcastAsUser(
2048 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2049 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002050
2051 case CMD_SET_DATA_THROTTLING: {
2052 request = (MainThreadRequest) msg.obj;
2053 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2054 DataThrottlingRequest dataThrottlingRequest =
2055 (DataThrottlingRequest) request.argument;
2056 Phone phone = getPhoneFromRequest(request);
2057 if (phone != null) {
2058 phone.setDataThrottling(onCompleted,
2059 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2060 dataThrottlingRequest.getCompletionDurationMillis());
2061 } else {
2062 loge("setDataThrottling: No phone object");
2063 request.result =
2064 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2065 notifyRequester(request);
2066 }
2067
2068 break;
2069 }
2070 case EVENT_SET_DATA_THROTTLING_DONE:
2071 ar = (AsyncResult) msg.obj;
2072 request = (MainThreadRequest) ar.userObj;
2073
2074 if (ar.exception == null) {
2075 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2076 } else if (ar.exception instanceof CommandException) {
2077 loge("setDataThrottling: CommandException: " + ar.exception);
2078 CommandException.Error error =
2079 ((CommandException) (ar.exception)).getCommandError();
2080
2081 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2082 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002083 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002084 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2085 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002086 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2087 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002088 } else {
2089 request.result =
2090 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2091 }
2092 } else {
2093 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2094 }
2095 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2096 notifyRequester(request);
2097 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002098
2099 case CMD_SET_SIM_POWER: {
2100 request = (MainThreadRequest) msg.obj;
2101 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2102 request = (MainThreadRequest) msg.obj;
2103 int stateToSet =
2104 ((Pair<Integer, IIntegerConsumer>)
2105 request.argument).first;
2106 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2107 break;
2108 }
2109 case EVENT_SET_SIM_POWER_DONE: {
2110 ar = (AsyncResult) msg.obj;
2111 request = (MainThreadRequest) ar.userObj;
2112 IIntegerConsumer callback =
2113 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2114 if (ar.exception != null) {
2115 loge("setSimPower exception: " + ar.exception);
2116 int errorCode = TelephonyManager.CallForwardingInfoCallback
2117 .RESULT_ERROR_UNKNOWN;
2118 if (ar.exception instanceof CommandException) {
2119 CommandException.Error error =
2120 ((CommandException) (ar.exception)).getCommandError();
2121 if (error == CommandException.Error.SIM_ERR) {
2122 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2123 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2124 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2125 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2126 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2127 } else {
2128 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2129 }
2130 }
2131 try {
2132 callback.accept(errorCode);
2133 } catch (RemoteException e) {
2134 // Ignore if the remote process is no longer available to call back.
2135 Log.w(LOG_TAG, "setSimPower: callback not available.");
2136 }
2137 } else {
2138 try {
2139 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2140 } catch (RemoteException e) {
2141 // Ignore if the remote process is no longer available to call back.
2142 Log.w(LOG_TAG, "setSimPower: callback not available.");
2143 }
2144 }
2145 break;
2146 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002147 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2148 request = (MainThreadRequest) msg.obj;
2149
2150 final Phone phone = getPhoneFromRequest(request);
2151 if (phone == null || phone.getServiceStateTracker() == null) {
2152 request.result = new IllegalStateException("Phone or SST is null");
2153 notifyRequester(request);
2154 break;
2155 }
2156
2157 Pair<Integer, SignalStrengthUpdateRequest> pair =
2158 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2159 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2160 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002161 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002162 request.subId, pair.first /*callingUid*/,
2163 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002164 break;
2165 }
2166 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2167 ar = (AsyncResult) msg.obj;
2168 request = (MainThreadRequest) ar.userObj;
2169 // request.result will be the exception of ar if present, true otherwise.
2170 // Be cautious not to leave result null which will wait() forever
2171 request.result = ar.exception != null ? ar.exception : true;
2172 notifyRequester(request);
2173 break;
2174 }
2175 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2176 request = (MainThreadRequest) msg.obj;
2177
2178 Phone phone = getPhoneFromRequest(request);
2179 if (phone == null || phone.getServiceStateTracker() == null) {
2180 request.result = new IllegalStateException("Phone or SST is null");
2181 notifyRequester(request);
2182 break;
2183 }
2184
2185 Pair<Integer, SignalStrengthUpdateRequest> pair =
2186 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2187 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2188 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002189 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002190 request.subId, pair.first /*callingUid*/,
2191 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002192 break;
2193 }
2194 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2195 ar = (AsyncResult) msg.obj;
2196 request = (MainThreadRequest) ar.userObj;
2197 request.result = ar.exception != null ? ar.exception : true;
2198 notifyRequester(request);
2199 break;
2200 }
Jordan Liu109698e2020-11-24 14:50:34 -08002201
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002202 case CMD_GET_SLICING_CONFIG: {
2203 request = (MainThreadRequest) msg.obj;
2204 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2205 request.phone.getSlicingConfig(onCompleted);
2206 break;
2207 }
2208 case EVENT_GET_SLICING_CONFIG_DONE: {
2209 ar = (AsyncResult) msg.obj;
2210 request = (MainThreadRequest) ar.userObj;
2211 ResultReceiver result = (ResultReceiver) request.argument;
2212
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002213 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002214 Bundle bundle = new Bundle();
2215 int resultCode = 0;
2216 if (ar.exception != null) {
2217 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2218 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002219 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002220 } else if (ar.result == null) {
2221 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002222 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002223 } else {
2224 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002225 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2226 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002227 }
2228
2229 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002230 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002231 }
2232 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2233 result.send(resultCode, bundle);
2234 notifyRequester(request);
2235 break;
2236 }
2237
Sarah Chin71b3a852022-09-28 15:54:19 -07002238 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002239 request = (MainThreadRequest) msg.obj;
2240 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002241 PurchasePremiumCapabilityArgument arg =
2242 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chincc5446f2023-10-23 17:57:19 -07002243 SlicePurchaseController.getInstance(request.phone, mFeatureFlags)
2244 .purchasePremiumCapability(arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002245 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002246 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002247
Sarah Chin71b3a852022-09-28 15:54:19 -07002248 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002249 ar = (AsyncResult) msg.obj;
2250 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002251 PurchasePremiumCapabilityArgument arg =
2252 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002253 try {
2254 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002255 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002256 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002257 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chinff8b1802023-04-11 14:22:14 -07002258 + ", result="
Sarah Chin2ec39f62022-08-31 17:03:26 -07002259 + TelephonyManager.convertPurchaseResultToString(result));
2260 } catch (RemoteException e) {
2261 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002262 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002263 + " failed: " + e;
2264 if (DBG) log(logStr);
2265 AnomalyReporter.reportAnomaly(
2266 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2267 }
2268 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002269 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002270
Michele Berionne5e411512020-11-13 02:36:59 +00002271 case CMD_PREPARE_UNATTENDED_REBOOT:
2272 request = (MainThreadRequest) msg.obj;
2273 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002274 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002275 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002276 notifyRequester(request);
2277 break;
2278
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002279 default:
2280 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2281 break;
2282 }
2283 }
Jake Hambye994d462014-02-03 13:10:13 -08002284
Pengquan Menga1bb6272018-09-06 09:59:22 -07002285 private void notifyRequester(MainThreadRequest request) {
2286 synchronized (request) {
2287 request.notifyAll();
2288 }
2289 }
2290
Jake Hambye994d462014-02-03 13:10:13 -08002291 private void handleNullReturnEvent(Message msg, String command) {
2292 AsyncResult ar = (AsyncResult) msg.obj;
2293 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2294 if (ar.exception == null) {
2295 request.result = true;
2296 } else {
2297 request.result = false;
2298 if (ar.exception instanceof CommandException) {
2299 loge(command + ": CommandException: " + ar.exception);
2300 } else {
2301 loge(command + ": Unknown exception");
2302 }
2303 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002304 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002305 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002306 }
2307
2308 /**
2309 * Posts the specified command to be executed on the main thread,
2310 * waits for the request to complete, and returns the result.
2311 * @see #sendRequestAsync
2312 */
2313 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002314 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2315 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002316 }
2317
2318 /**
2319 * Posts the specified command to be executed on the main thread,
2320 * waits for the request to complete, and returns the result.
2321 * @see #sendRequestAsync
2322 */
2323 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2324 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002325 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002326 }
2327
2328 /**
2329 * Posts the specified command to be executed on the main thread,
2330 * waits for the request to complete, and returns the result.
2331 * @see #sendRequestAsync
2332 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002333 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002334 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2335 }
2336
2337 /**
2338 * Posts the specified command to be executed on the main thread,
2339 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2340 * if not timeout or null otherwise.
2341 * @see #sendRequestAsync
2342 */
2343 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2344 long timeoutInMs) {
2345 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002346 }
2347
2348 /**
2349 * Posts the specified command to be executed on the main thread,
2350 * waits for the request to complete, and returns the result.
2351 * @see #sendRequestAsync
2352 */
Nathan Harold92bed182018-10-12 18:16:49 -07002353 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002354 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002355 }
2356
2357 /**
2358 * Posts the specified command to be executed on the main thread,
2359 * waits for the request to complete, and returns the result.
2360 * @see #sendRequestAsync
2361 */
2362 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002363 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2364 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002365 }
2366
2367 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002368 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2369 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2370 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002371 * @see #sendRequestAsync
2372 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002373 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2374 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002375 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2376 throw new RuntimeException("This method will deadlock if called from the main thread.");
2377 }
2378
Nathan Harold92bed182018-10-12 18:16:49 -07002379 MainThreadRequest request = null;
2380 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2381 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2382 } else if (phone != null) {
2383 request = new MainThreadRequest(argument, phone, workSource);
2384 } else {
2385 request = new MainThreadRequest(argument, subId, workSource);
2386 }
2387
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002388 Message msg = mMainThreadHandler.obtainMessage(command, request);
2389 msg.sendToTarget();
2390
Rambo Wang0f050d82021-02-12 11:43:36 -08002391
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002392 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002393 if (timeoutInMs >= 0) {
2394 // Wait for at least timeoutInMs before returning null request result
2395 long now = SystemClock.elapsedRealtime();
2396 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002397 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002398 try {
2399 request.wait(deadline - now);
2400 } catch (InterruptedException e) {
2401 // Do nothing, go back and check if request is completed or timeout
2402 } finally {
2403 now = SystemClock.elapsedRealtime();
2404 }
2405 }
2406 } else {
2407 // Wait for the request to complete
2408 while (request.result == null) {
2409 try {
2410 request.wait();
2411 } catch (InterruptedException e) {
2412 // Do nothing, go back and wait until the request is complete
2413 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002414 }
2415 }
2416 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002417 if (request.result == null) {
2418 Log.wtf(LOG_TAG,
2419 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2420 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002421 return request.result;
2422 }
2423
2424 /**
2425 * Asynchronous ("fire and forget") version of sendRequest():
2426 * Posts the specified command to be executed on the main thread, and
2427 * returns immediately.
2428 * @see #sendRequest
2429 */
2430 private void sendRequestAsync(int command) {
2431 mMainThreadHandler.sendEmptyMessage(command);
2432 }
2433
2434 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002435 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002436 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002437 */
2438 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002439 sendRequestAsync(command, argument, null, null);
2440 }
2441
2442 /**
2443 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2444 * @see {@link #sendRequest(int,Object)}
2445 */
2446 private void sendRequestAsync(
2447 int command, Object argument, Phone phone, WorkSource workSource) {
2448 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002449 Message msg = mMainThreadHandler.obtainMessage(command, request);
2450 msg.sendToTarget();
2451 }
2452
2453 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002454 * Initialize the singleton PhoneInterfaceManager instance.
2455 * This is only done once, at startup, from PhoneApp.onCreate().
2456 */
Sarah Chincc5446f2023-10-23 17:57:19 -07002457 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002458 synchronized (PhoneInterfaceManager.class) {
2459 if (sInstance == null) {
Sarah Chincc5446f2023-10-23 17:57:19 -07002460 sInstance = new PhoneInterfaceManager(app, featureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002461 } else {
2462 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2463 }
2464 return sInstance;
2465 }
2466 }
2467
2468 /** Private constructor; @see init() */
Sarah Chincc5446f2023-10-23 17:57:19 -07002469 private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002470 mApp = app;
Sarah Chincc5446f2023-10-23 17:57:19 -07002471 mFeatureFlags = featureFlags;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -08002472 mTelecomFeatureFlags = new com.android.server.telecom.flags.FeatureFlagsImpl();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002473 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002474 mImsResolver = ImsResolver.getInstance();
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +00002475 mSatelliteController = SatelliteController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002476 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002477 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2478 mMainThreadHandler = new MainThreadHandler();
Sarah Chin4beb2b72023-02-14 14:47:54 -08002479 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002480 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002481 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002482 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002483 mNotifyUserActivity = new AtomicBoolean(false);
joonhunshin4ac60942023-11-15 15:23:39 +00002484 mPackageManager = app.getPackageManager();
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -08002485 mSatelliteAccessController = SatelliteAccessController.getOrCreateInstance(
2486 getDefaultPhone().getContext(), featureFlags);
joonhunshinf624b2a2024-04-18 04:42:12 +00002487 mVendorApiLevel = SystemProperties.getInt(
2488 "ro.vendor.api_level", Build.VERSION.DEVICE_INITIAL_SDK_INT);
2489
Tyler Gunn64144d92022-03-17 14:16:41 -07002490 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002491 publish();
arunvoddud7401012022-12-15 16:08:12 +00002492 CarrierAllowListInfo.loadInstance(mApp);
Hyosun Kim240214a2023-11-02 13:30:15 +00002493
2494 // Create the SatelliteEntitlementController singleton, for using the get the
2495 // entitlementStatus for satellite service.
2496 SatelliteEntitlementController.make(mApp, mFeatureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002497 }
2498
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002499 @VisibleForTesting
2500 public SharedPreferences getSharedPreferences() {
2501 return mTelephonySharedPreferences;
2502 }
2503
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002504 /**
2505 * Get the default phone for this device.
2506 */
2507 @VisibleForTesting
2508 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002509 Phone thePhone = getPhone(getDefaultSubscription());
2510 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2511 }
2512
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002513 private void publish() {
2514 if (DBG) log("publish: " + this);
2515
Peter Wangc035ce42020-01-08 21:00:22 -08002516 TelephonyFrameworkInitializer
2517 .getTelephonyServiceManager()
2518 .getTelephonyServiceRegisterer()
2519 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002520 }
2521
Stuart Scott584921c2015-01-15 17:10:34 -08002522 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002523 if (request.phone != null) {
2524 return request.phone;
2525 } else {
2526 return getPhoneFromSubId(request.subId);
2527 }
2528 }
2529
2530 private Phone getPhoneFromSubId(int subId) {
2531 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2532 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002533 }
2534
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002535 /**
2536 * Get phone object associated with a subscription.
2537 * Return default phone if phone object associated with subscription is null
2538 * @param subId - subscriptionId
2539 * @return phone object associated with a subscription or default phone if null.
2540 */
Ling Mac28f0212023-03-24 16:07:15 -07002541 private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) {
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002542 Phone phone = getPhoneFromSubId(subId);
2543 if (phone == null) {
Ling Mac28f0212023-03-24 16:07:15 -07002544 loge("Called with invalid subId: " + subId + ". Retrying with default phone.");
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002545 phone = getDefaultPhone();
2546 }
2547 return phone;
2548 }
2549
Rambo Wange53e07d2022-05-10 13:01:13 -07002550 @Nullable
2551 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002552 Phone phone = getPhoneFromRequest(request);
2553 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002554 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002555 }
2556
Ling Mac28f0212023-03-24 16:07:15 -07002557 /**
2558 * @param subId The sub Id that associates the phone. If the device has no active SIM, passing
2559 * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <=
2560 * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}.
2561 * @return The Phone associated the sub Id
2562 */
2563 private @Nullable Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002564 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002565 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002566
Kai Shif70f46f2021-03-03 13:59:46 -08002567 private void sendEraseModemConfig(@NonNull Phone phone) {
2568 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2569 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2570 }
2571
2572 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2573 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2574 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002575 }
2576
Peter Wang44b186e2020-01-13 23:33:09 -08002577 private boolean isImsAvailableOnDevice() {
2578 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2579 if (pm == null) {
2580 // For some reason package manger is not available.. This will fail internally anyway,
2581 // so do not throw error and allow.
2582 return true;
2583 }
2584 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2585 }
2586
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002587 public void dial(String number) {
joonhunshin4ac60942023-11-15 15:23:39 +00002588 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2589 PackageManager.FEATURE_TELEPHONY_CALLING, "dial");
2590
Wink Savilleadd7cc52014-09-08 14:23:09 -07002591 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002592 }
2593
Wink Savilleb564aae2014-10-23 10:18:09 -07002594 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002595 if (DBG) log("dial: " + number);
2596 // No permission check needed here: This is just a wrapper around the
2597 // ACTION_DIAL intent, which is available to any app since it puts up
2598 // the UI before it does anything.
2599
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002600 final long identity = Binder.clearCallingIdentity();
2601 try {
2602 String url = createTelUrl(number);
2603 if (url == null) {
2604 return;
2605 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002606
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002607 // PENDING: should we just silently fail if phone is offhook or ringing?
2608 PhoneConstants.State state = mCM.getState(subId);
2609 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2610 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2611 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2612 mApp.startActivity(intent);
2613 }
2614 } finally {
2615 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002616 }
2617 }
2618
2619 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002620 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002621 }
2622
Wink Savilleb564aae2014-10-23 10:18:09 -07002623 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002624 if (DBG) log("call: " + number);
2625
2626 // This is just a wrapper around the ACTION_CALL intent, but we still
2627 // need to do a permission check since we're calling startActivity()
2628 // from the context of the phone app.
2629 enforceCallPermission();
2630
Jordan Liu1617b712019-07-10 15:06:26 -07002631 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002632 != AppOpsManager.MODE_ALLOWED) {
2633 return;
2634 }
2635
joonhunshin4ac60942023-11-15 15:23:39 +00002636 enforceTelephonyFeatureWithException(callingPackage,
2637 PackageManager.FEATURE_TELEPHONY_CALLING, "call");
2638
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002639 final long identity = Binder.clearCallingIdentity();
2640 try {
2641 String url = createTelUrl(number);
2642 if (url == null) {
2643 return;
2644 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002645
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002646 boolean isValid = false;
2647 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2648 if (slist != null) {
2649 for (SubscriptionInfo subInfoRecord : slist) {
2650 if (subInfoRecord.getSubscriptionId() == subId) {
2651 isValid = true;
2652 break;
2653 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002654 }
Wink Saville08874612014-08-31 19:19:58 -07002655 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002656 if (!isValid) {
2657 return;
2658 }
Wink Saville08874612014-08-31 19:19:58 -07002659
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002660 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2661 intent.putExtra(SUBSCRIPTION_KEY, subId);
2662 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2663 mApp.startActivity(intent);
2664 } finally {
2665 Binder.restoreCallingIdentity(identity);
2666 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002667 }
2668
Wink Savilleb564aae2014-10-23 10:18:09 -07002669 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002670 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002671 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2672 }
2673
Wink Savilleb564aae2014-10-23 10:18:09 -07002674 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002675 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002676 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2677 }
2678
Wink Savilleb564aae2014-10-23 10:18:09 -07002679 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002680 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002681
joonhunshin4ac60942023-11-15 15:23:39 +00002682 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2683 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
2684 "supplyPinReportResultForSubscriber");
2685
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002686 final long identity = Binder.clearCallingIdentity();
2687 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002688 Phone phone = getPhone(subId);
2689 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002690 checkSimPin.start();
2691 return checkSimPin.unlockSim(null, pin);
2692 } finally {
2693 Binder.restoreCallingIdentity(identity);
2694 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002695 }
2696
Wink Savilleb564aae2014-10-23 10:18:09 -07002697 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002698 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002699
joonhunshin4ac60942023-11-15 15:23:39 +00002700 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2701 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "supplyPukForSubscriber");
2702
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002703 final long identity = Binder.clearCallingIdentity();
2704 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002705 Phone phone = getPhone(subId);
2706 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002707 checkSimPuk.start();
2708 return checkSimPuk.unlockSim(puk, pin);
2709 } finally {
2710 Binder.restoreCallingIdentity(identity);
2711 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002712 }
2713
2714 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002715 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002716 * a synchronous one.
2717 */
2718 private static class UnlockSim extends Thread {
2719
2720 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002721 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002722
2723 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002724 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2725 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002726
2727 // For replies from SimCard interface
2728 private Handler mHandler;
2729
2730 // For async handler to identify request type
2731 private static final int SUPPLY_PIN_COMPLETE = 100;
2732
Michele Berionne5e411512020-11-13 02:36:59 +00002733 UnlockSim(int phoneId, IccCard simCard) {
2734 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002735 mSimCard = simCard;
2736 }
2737
2738 @Override
2739 public void run() {
2740 Looper.prepare();
2741 synchronized (UnlockSim.this) {
2742 mHandler = new Handler() {
2743 @Override
2744 public void handleMessage(Message msg) {
2745 AsyncResult ar = (AsyncResult) msg.obj;
2746 switch (msg.what) {
2747 case SUPPLY_PIN_COMPLETE:
2748 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2749 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002750 mRetryCount = msg.arg1;
2751 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002752 CommandException.Error error = null;
2753 if (ar.exception instanceof CommandException) {
2754 error = ((CommandException) (ar.exception))
2755 .getCommandError();
2756 }
2757 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07002758 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002759 } else if (error == CommandException.Error.ABORTED) {
2760 /* When UiccCardApp dispose, handle message and return
2761 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08002762 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002763 } else {
2764 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2765 }
2766 } else {
2767 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2768 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002769 mDone = true;
2770 UnlockSim.this.notifyAll();
2771 }
2772 break;
2773 }
2774 }
2775 };
2776 UnlockSim.this.notifyAll();
2777 }
2778 Looper.loop();
2779 }
2780
2781 /*
2782 * Use PIN or PUK to unlock SIM card
2783 *
2784 * If PUK is null, unlock SIM card with PIN
2785 *
2786 * If PUK is not null, unlock SIM card with PUK and set PIN code
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302787 *
2788 * Besides, since it is reused in class level, the thread's looper will be stopped to avoid
2789 * its thread leak.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002790 */
Wink Saville9de0f752013-10-22 19:04:03 -07002791 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002792
2793 while (mHandler == null) {
2794 try {
2795 wait();
2796 } catch (InterruptedException e) {
2797 Thread.currentThread().interrupt();
2798 }
2799 }
2800 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2801
2802 if (puk == null) {
2803 mSimCard.supplyPin(pin, callback);
2804 } else {
2805 mSimCard.supplyPuk(puk, pin, callback);
2806 }
2807
2808 while (!mDone) {
2809 try {
2810 Log.d(LOG_TAG, "wait for done");
2811 wait();
2812 } catch (InterruptedException e) {
2813 // Restore the interrupted status
2814 Thread.currentThread().interrupt();
2815 }
2816 }
2817 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002818 int[] resultArray = new int[2];
2819 resultArray[0] = mResult;
2820 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002821
2822 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002823 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002824 }
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302825 // This instance is no longer reused, so quit its thread's looper.
2826 mHandler.getLooper().quitSafely();
Michele Berionne5e411512020-11-13 02:36:59 +00002827
Wink Saville9de0f752013-10-22 19:04:03 -07002828 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002829 }
2830 }
2831
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002832 /**
2833 * This method has been removed due to privacy and stability concerns.
2834 */
2835 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002836 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002837 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2838 return;
Wink Saville36469e72014-06-11 15:17:00 -07002839 }
2840
Nathan Harold1f889d82020-06-04 17:05:26 -07002841 @Override
2842 public void updateServiceLocationWithPackageName(String callingPackage) {
2843 mApp.getSystemService(AppOpsManager.class)
2844 .checkPackage(Binder.getCallingUid(), callingPackage);
2845
Nathan Haroldf096d982020-11-18 17:18:06 -08002846 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002847 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2848 // Callers targeting S have no business invoking this method.
2849 return;
2850 }
2851
2852 LocationAccessPolicy.LocationPermissionResult locationResult =
2853 LocationAccessPolicy.checkLocationPermission(mApp,
2854 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2855 .setCallingPackage(callingPackage)
2856 .setCallingFeatureId(null)
2857 .setCallingPid(Binder.getCallingPid())
2858 .setCallingUid(Binder.getCallingUid())
2859 .setMethod("updateServiceLocation")
2860 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2861 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2862 .build());
2863 // Apps that lack location permission have no business calling this method;
2864 // however, because no permission was declared in the public API, denials must
2865 // all be "soft".
2866 switch (locationResult) {
2867 case DENIED_HARD: /* fall through */
2868 case DENIED_SOFT:
2869 return;
2870 }
2871
2872 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002873 final long identity = Binder.clearCallingIdentity();
2874 try {
Ling Mac28f0212023-03-24 16:07:15 -07002875 getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002876 } finally {
2877 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002878 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002879 }
2880
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002881 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002882 @Override
2883 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002884 return isRadioOnWithFeature(callingPackage, null);
2885 }
2886
2887
2888 @Override
2889 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2890 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2891 callingFeatureId);
2892 }
2893
2894 @Deprecated
2895 @Override
2896 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2897 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002898 }
2899
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002900 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002901 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2902 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002903 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002904 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002905 return false;
2906 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002907
joonhunshin4ac60942023-11-15 15:23:39 +00002908 enforceTelephonyFeatureWithException(callingPackage,
2909 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isRadioOnWithFeature");
2910
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002911 final long identity = Binder.clearCallingIdentity();
2912 try {
2913 return isRadioOnForSubscriber(subId);
2914 } finally {
2915 Binder.restoreCallingIdentity(identity);
2916 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002917 }
2918
2919 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002920 final long identity = Binder.clearCallingIdentity();
2921 try {
2922 final Phone phone = getPhone(subId);
2923 if (phone != null) {
2924 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2925 } else {
2926 return false;
2927 }
2928 } finally {
2929 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002930 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002931 }
2932
2933 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002934 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002935 }
Wink Saville36469e72014-06-11 15:17:00 -07002936
Wink Savilleb564aae2014-10-23 10:18:09 -07002937 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002938 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002939
joonhunshin4ac60942023-11-15 15:23:39 +00002940 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2941 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "toggleRadioOnOffForSubscriber");
2942
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002943 final long identity = Binder.clearCallingIdentity();
2944 try {
2945 final Phone phone = getPhone(subId);
2946 if (phone != null) {
2947 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2948 }
2949 } finally {
2950 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002951 }
Wink Saville36469e72014-06-11 15:17:00 -07002952 }
2953
2954 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002955 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002956 }
2957
Wink Savilleb564aae2014-10-23 10:18:09 -07002958 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002959 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002960
2961 final long identity = Binder.clearCallingIdentity();
2962 try {
2963 final Phone phone = getPhone(subId);
2964 if (phone == null) {
2965 return false;
2966 }
2967 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2968 toggleRadioOnOffForSubscriber(subId);
2969 }
2970 return true;
2971 } finally {
2972 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002973 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002974 }
Wink Saville36469e72014-06-11 15:17:00 -07002975
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002976 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002977 enforceReadPrivilegedPermission("needMobileRadioShutdown");
joonhunshin4ac60942023-11-15 15:23:39 +00002978
2979 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2980 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needMobileRadioShutdown");
2981
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002982 /*
2983 * If any of the Radios are available, it will need to be
2984 * shutdown. So return true if any Radio is available.
2985 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002986 final long identity = Binder.clearCallingIdentity();
2987 try {
2988 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2989 Phone phone = PhoneFactory.getPhone(i);
2990 if (phone != null && phone.isRadioAvailable()) return true;
2991 }
2992 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2993 return false;
2994 } finally {
2995 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002996 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002997 }
2998
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002999 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003000 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003001 enforceModifyPermission();
3002
joonhunshin4ac60942023-11-15 15:23:39 +00003003 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3004 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "shutdownMobileRadios");
3005
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003006 final long identity = Binder.clearCallingIdentity();
3007 try {
3008 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3009 logv("Shutting down Phone " + i);
3010 shutdownRadioUsingPhoneId(i);
3011 }
3012 } finally {
3013 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003014 }
3015 }
3016
3017 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003018 Phone phone = PhoneFactory.getPhone(phoneId);
3019 if (phone != null && phone.isRadioAvailable()) {
3020 phone.shutdownRadio();
3021 }
3022 }
3023
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003024 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07003025 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003026
Ling Ma83dc5ea2023-01-12 15:06:04 -08003027 if (!turnOn) {
3028 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
3029 }
3030
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003031 final long identity = Binder.clearCallingIdentity();
3032 try {
3033 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
3034 if (defaultPhone != null) {
3035 defaultPhone.setRadioPower(turnOn);
3036 return true;
3037 } else {
3038 loge("There's no default phone.");
3039 return false;
3040 }
3041 } finally {
3042 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07003043 }
Wink Saville36469e72014-06-11 15:17:00 -07003044 }
3045
Wink Savilleb564aae2014-10-23 10:18:09 -07003046 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003047 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003048
Ling Ma83dc5ea2023-01-12 15:06:04 -08003049 if (!turnOn) {
3050 log("setRadioPowerForSubscriber off: subId=" + subId
3051 + ",callingPackage=" + getCurrentPackageName());
3052 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003053 final long identity = Binder.clearCallingIdentity();
3054 try {
3055 final Phone phone = getPhone(subId);
3056 if (phone != null) {
3057 phone.setRadioPower(turnOn);
3058 return true;
3059 } else {
3060 return false;
3061 }
3062 } finally {
3063 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003064 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003065 }
3066
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003067 /**
3068 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3069 * no reason to power it off. When any of the voters want to power it off, it will be turned
3070 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3071 * powering it off, and these radio off votes will be cleared.
3072 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3073 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3074 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3075 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3076 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3077 * check its vote.
3078 *
3079 * @param subId The subscription ID.
3080 * @param reason The reason for powering off radio.
3081 * @return true on success and false on failure.
3082 */
3083 public boolean requestRadioPowerOffForReason(int subId,
3084 @TelephonyManager.RadioPowerReason int reason) {
3085 enforceModifyPermission();
3086
joonhunshin4ac60942023-11-15 15:23:39 +00003087 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3088 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestRadioPowerOffForReason");
3089
Ling Ma83dc5ea2023-01-12 15:06:04 -08003090 log("requestRadioPowerOffForReason: subId=" + subId
3091 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003092 final long identity = Binder.clearCallingIdentity();
3093 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003094 boolean result = false;
3095 for (Phone phone : PhoneFactory.getPhones()) {
3096 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003097 phone.setRadioPowerForReason(false, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003098 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003099 if (!result) {
3100 loge("requestRadioPowerOffForReason: no phone exists");
3101 }
3102 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003103 } finally {
3104 Binder.restoreCallingIdentity(identity);
3105 }
3106 }
3107
3108 /**
3109 * Remove the vote on powering off the radio for a reason, as requested by
3110 * {@link requestRadioPowerOffForReason}.
3111 *
3112 * @param subId The subscription ID.
3113 * @param reason The reason for powering off radio.
3114 * @return true on success and false on failure.
3115 */
3116 public boolean clearRadioPowerOffForReason(int subId,
3117 @TelephonyManager.RadioPowerReason int reason) {
3118 enforceModifyPermission();
3119
joonhunshin4ac60942023-11-15 15:23:39 +00003120 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3121 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearRadioPowerOffForReason");
3122
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003123 final long identity = Binder.clearCallingIdentity();
3124 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003125 boolean result = false;
3126 for (Phone phone : PhoneFactory.getPhones()) {
3127 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003128 phone.setRadioPowerForReason(true, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003129 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003130 if (!result) {
3131 loge("clearRadioPowerOffForReason: no phone exists");
3132 }
3133 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003134 } finally {
3135 Binder.restoreCallingIdentity(identity);
3136 }
3137 }
3138
3139 /**
3140 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3141 *
3142 * @param subId The subscription ID.
3143 * @param callingPackage The package making the call.
3144 * @param callingFeatureId The feature in the package.
3145 * @return List of reasons for powering off radio.
3146 */
3147 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3148 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3149
joonhunshin4ac60942023-11-15 15:23:39 +00003150 enforceTelephonyFeatureWithException(callingPackage,
3151 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerOffReasons");
3152
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003153 final long identity = Binder.clearCallingIdentity();
3154 List result = new ArrayList();
3155 try {
3156 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3157 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3158 return result;
3159 }
3160
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003161 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003162 if (phone != null) {
3163 result.addAll(phone.getRadioPowerOffReasons());
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003164 } else {
3165 loge("getRadioPowerOffReasons: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003166 }
3167 } finally {
3168 Binder.restoreCallingIdentity(identity);
3169 }
3170 return result;
3171 }
3172
Wink Saville36469e72014-06-11 15:17:00 -07003173 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003174 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003175 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003176 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003177
joonhunshin4ac60942023-11-15 15:23:39 +00003178 enforceTelephonyFeatureWithException(callingPackage,
3179 PackageManager.FEATURE_TELEPHONY_DATA, "enableDataConnectivity");
3180
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003181 final long identity = Binder.clearCallingIdentity();
3182 try {
Jack Yu285100e2022-12-02 22:48:35 -08003183 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003184 final Phone phone = getPhone(subId);
3185 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003186 phone.getDataSettingsManager().setDataEnabled(
3187 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003188 return true;
3189 } else {
3190 return false;
3191 }
3192 } finally {
3193 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003194 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003195 }
3196
Wink Saville36469e72014-06-11 15:17:00 -07003197 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003198 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003199 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003200 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003201
joonhunshin4ac60942023-11-15 15:23:39 +00003202 enforceTelephonyFeatureWithException(callingPackage,
3203 PackageManager.FEATURE_TELEPHONY_DATA, "disableDataConnectivity");
3204
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003205 final long identity = Binder.clearCallingIdentity();
3206 try {
Jack Yu285100e2022-12-02 22:48:35 -08003207 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003208 final Phone phone = getPhone(subId);
3209 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003210 phone.getDataSettingsManager().setDataEnabled(
3211 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003212 return true;
3213 } else {
3214 return false;
3215 }
3216 } finally {
3217 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003218 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003219 }
3220
Sanket Padawe356d7632015-06-22 14:03:32 -07003221 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003222 public boolean isDataConnectivityPossible(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003223 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3224 PackageManager.FEATURE_TELEPHONY_DATA, "isDataConnectivityPossible");
3225
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003226 final long identity = Binder.clearCallingIdentity();
3227 try {
3228 final Phone phone = getPhone(subId);
3229 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003230 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003231 } else {
3232 return false;
3233 }
3234 } finally {
3235 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003236 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003237 }
3238
3239 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003240 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003241 }
3242
pkanwarae03a6b2016-11-06 20:37:09 -08003243 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003244 enforceCallPermission();
3245
joonhunshin4ac60942023-11-15 15:23:39 +00003246 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3247 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "handleUssdRequest");
3248
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003249 final long identity = Binder.clearCallingIdentity();
3250 try {
3251 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3252 return;
3253 }
3254 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3255 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3256 } finally {
3257 Binder.restoreCallingIdentity(identity);
3258 }
pkanwar32d516d2016-10-14 19:37:38 -07003259 };
3260
Wink Savilleb564aae2014-10-23 10:18:09 -07003261 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003262 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003263
joonhunshin4ac60942023-11-15 15:23:39 +00003264 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3265 PackageManager.FEATURE_TELEPHONY_CALLING, "handlePinMmiForSubscriber");
3266
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003267 final long identity = Binder.clearCallingIdentity();
3268 try {
3269 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3270 return false;
3271 }
3272 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3273 } finally {
3274 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003275 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003276 }
3277
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003278 /**
3279 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3280 * tag on getCallState Binder call.
3281 */
3282 @Deprecated
3283 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003284 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003285 if (CompatChanges.isChangeEnabled(
3286 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3287 Binder.getCallingUid())) {
3288 // Do not allow this API to be called on API version 31+, it should only be
3289 // called on old apps using this Binder call directly.
3290 throw new SecurityException("This method can only be used for applications "
3291 + "targeting API version 30 or less.");
3292 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003293 final long identity = Binder.clearCallingIdentity();
3294 try {
Ling Mac28f0212023-03-24 16:07:15 -07003295 Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription());
3296 return PhoneConstantConversions.convertCallState(phone.getState());
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003297 } finally {
3298 Binder.restoreCallingIdentity(identity);
3299 }
3300 }
3301
3302 @Override
3303 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3304 if (CompatChanges.isChangeEnabled(
3305 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3306 Binder.getCallingUid())) {
3307 // Check READ_PHONE_STATE for API version 31+
3308 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3309 featureId, "getCallStateForSubscription")) {
3310 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3311 + "targeting API level 31+.");
3312 }
3313 }
joonhunshin4ac60942023-11-15 15:23:39 +00003314
3315 enforceTelephonyFeatureWithException(callingPackage,
3316 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallStateForSubscription");
3317
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003318 final long identity = Binder.clearCallingIdentity();
3319 try {
3320 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003321 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3322 PhoneConstantConversions.convertCallState(phone.getState());
3323 } finally {
3324 Binder.restoreCallingIdentity(identity);
3325 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003326 }
3327
Sanket Padawe356d7632015-06-22 14:03:32 -07003328 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003329 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003330 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003331 }
3332
3333 @Override
3334 public int getDataStateForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003335 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3336 PackageManager.FEATURE_TELEPHONY_DATA, "getDataStateForSubId");
3337
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003338 final long identity = Binder.clearCallingIdentity();
3339 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003340 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003341 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003342 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003343 } else {
3344 return PhoneConstantConversions.convertDataState(
3345 PhoneConstants.DataState.DISCONNECTED);
3346 }
3347 } finally {
3348 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003349 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003350 }
3351
Sanket Padawe356d7632015-06-22 14:03:32 -07003352 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003353 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003354 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003355 }
3356
3357 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003358 public @DataActivityType int getDataActivityForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003359 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3360 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivityForSubId");
3361
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003362 final long identity = Binder.clearCallingIdentity();
3363 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003364 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003365 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003366 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003367 } else {
3368 return TelephonyManager.DATA_ACTIVITY_NONE;
3369 }
3370 } finally {
3371 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003372 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003373 }
3374
3375 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003376 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003377 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003378 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003379
3380 LocationAccessPolicy.LocationPermissionResult locationResult =
3381 LocationAccessPolicy.checkLocationPermission(mApp,
3382 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3383 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003384 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003385 .setCallingPid(Binder.getCallingPid())
3386 .setCallingUid(Binder.getCallingUid())
3387 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003388 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003389 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3390 .build());
3391 switch (locationResult) {
3392 case DENIED_HARD:
3393 throw new SecurityException("Not allowed to access cell location");
3394 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003395 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3396 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003397 }
3398
joonhunshin4ac60942023-11-15 15:23:39 +00003399 enforceTelephonyFeatureWithException(callingPackage,
3400 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getCellLocation");
3401
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003402 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003403 final long identity = Binder.clearCallingIdentity();
3404 try {
3405 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003406 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003407 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003408 } finally {
3409 Binder.restoreCallingIdentity(identity);
3410 }
Svetoslav64fad262015-04-14 14:35:21 -07003411 }
3412
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003413 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003414 public String getNetworkCountryIsoForPhone(int phoneId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003415 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3416 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkCountryIsoForPhone");
3417
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003418 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3419 // registered cell info, so return a NULL country instead.
3420 final long identity = Binder.clearCallingIdentity();
3421 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003422 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3423 // Get default phone in this case.
3424 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3425 }
Jack Yu285100e2022-12-02 22:48:35 -08003426 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003427 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003428 if (phone == null) return "";
3429 ServiceStateTracker sst = phone.getServiceStateTracker();
3430 if (sst == null) return "";
3431 LocaleTracker lt = sst.getLocaleTracker();
3432 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003433 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003434 } finally {
3435 Binder.restoreCallingIdentity(identity);
3436 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003437 }
3438
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003439 /**
3440 * This method was removed due to potential issues caused by performing partial
3441 * updates of service state, and lack of a credible use case.
3442 *
3443 * This has the ability to break the telephony implementation by disabling notification of
3444 * changes in device connectivity. DO NOT USE THIS!
3445 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003446 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003447 public void enableLocationUpdates() {
3448 mApp.enforceCallingOrSelfPermission(
3449 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003450 }
3451
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003452 /**
3453 * This method was removed due to potential issues caused by performing partial
3454 * updates of service state, and lack of a credible use case.
3455 *
3456 * This has the ability to break the telephony implementation by disabling notification of
3457 * changes in device connectivity. DO NOT USE THIS!
3458 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003459 @Override
3460 public void disableLocationUpdates() {
3461 mApp.enforceCallingOrSelfPermission(
3462 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003463 }
3464
3465 @Override
3466 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003467 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3468 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003469 try {
3470 mApp.getSystemService(AppOpsManager.class)
3471 .checkPackage(Binder.getCallingUid(), callingPackage);
3472 } catch (SecurityException e) {
3473 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3474 throw e;
3475 }
3476
Nathan Haroldf096d982020-11-18 17:18:06 -08003477 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003478 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3479 throw new SecurityException(
3480 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3481 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003482
Jordan Liu1617b712019-07-10 15:06:26 -07003483 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003484 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3485 return null;
3486 }
Svetoslav64fad262015-04-14 14:35:21 -07003487
joonhunshin4ac60942023-11-15 15:23:39 +00003488 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3489 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNeighboringCellInfo");
3490
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003491 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003492
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003493 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003494 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003495
Nathan Haroldf180aac2018-06-01 18:43:55 -07003496 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3497 for (CellInfo ci : info) {
3498 if (ci instanceof CellInfoGsm) {
3499 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3500 } else if (ci instanceof CellInfoWcdma) {
3501 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3502 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003503 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003504 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003505 }
3506
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003507 private List<CellInfo> getCachedCellInfo() {
3508 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3509 for (Phone phone : PhoneFactory.getPhones()) {
3510 List<CellInfo> info = phone.getAllCellInfo();
3511 if (info != null) cellInfos.addAll(info);
3512 }
3513 return cellInfos;
3514 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003515
3516 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003517 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003518 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003519 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003520
3521 LocationAccessPolicy.LocationPermissionResult locationResult =
3522 LocationAccessPolicy.checkLocationPermission(mApp,
3523 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3524 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003525 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003526 .setCallingPid(Binder.getCallingPid())
3527 .setCallingUid(Binder.getCallingUid())
3528 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003529 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003530 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3531 .build());
3532 switch (locationResult) {
3533 case DENIED_HARD:
3534 throw new SecurityException("Not allowed to access cell info");
3535 case DENIED_SOFT:
3536 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003537 }
3538
Nathan Haroldf096d982020-11-18 17:18:06 -08003539 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003540 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3541 return getCachedCellInfo();
3542 }
3543
joonhunshin4ac60942023-11-15 15:23:39 +00003544 enforceTelephonyFeatureWithException(callingPackage,
3545 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllCellInfo");
3546
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003547 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003548 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003549 final long identity = Binder.clearCallingIdentity();
3550 try {
3551 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3552 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003553 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003554 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003555 if (info != null) cellInfos.addAll(info);
3556 }
3557 return cellInfos;
3558 } finally {
3559 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003560 }
3561 }
3562
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003563 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003564 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3565 String callingFeatureId) {
3566 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3567 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003568 }
3569
3570 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003571 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3572 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003573 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003574 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003575 }
3576
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003577 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3578 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003579 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003580 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003581
3582 LocationAccessPolicy.LocationPermissionResult locationResult =
3583 LocationAccessPolicy.checkLocationPermission(mApp,
3584 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3585 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003586 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003587 .setCallingPid(Binder.getCallingPid())
3588 .setCallingUid(Binder.getCallingUid())
3589 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003590 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3591 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003592 .build());
3593 switch (locationResult) {
3594 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003595 if (TelephonyPermissions
3596 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003597 // Safetynet logging for b/154934934
3598 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3599 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003600 throw new SecurityException("Not allowed to access cell info");
3601 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003602 if (TelephonyPermissions
3603 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003604 // Safetynet logging for b/154934934
3605 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3606 }
Nathan Harold5320c422019-05-09 10:26:08 -07003607 try {
3608 cb.onCellInfo(new ArrayList<CellInfo>());
3609 } catch (RemoteException re) {
3610 // Drop without consequences
3611 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003612 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003613 }
3614
joonhunshin4ac60942023-11-15 15:23:39 +00003615 enforceTelephonyFeatureWithException(callingPackage,
3616 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestCellInfoUpdateInternal");
Nathan Harolda939a962019-05-09 10:13:47 -07003617
3618 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003619 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3620
3621 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3622 }
3623
3624 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003625 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003626 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003627 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003628
3629 final long identity = Binder.clearCallingIdentity();
3630 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003631 Phone phone = getPhone(subId);
3632 if (phone == null) {
3633 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3634 } else {
3635 phone.setCellInfoListRate(rateInMillis, workSource);
3636 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003637 } finally {
3638 Binder.restoreCallingIdentity(identity);
3639 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003640 }
3641
Shishir Agrawala9f32182016-04-12 12:00:16 -07003642 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003643 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003644 Phone phone = PhoneFactory.getPhone(slotIndex);
3645 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003646 return null;
3647 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003648 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003649 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003650 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003651 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003652 return null;
3653 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003654
joonhunshin4ac60942023-11-15 15:23:39 +00003655 enforceTelephonyFeatureWithException(callingPackage,
3656 PackageManager.FEATURE_TELEPHONY_GSM, "getImeiForSlot");
3657
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003658 final long identity = Binder.clearCallingIdentity();
3659 try {
3660 return phone.getImei();
3661 } finally {
3662 Binder.restoreCallingIdentity(identity);
3663 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003664 }
3665
3666 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003667 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3668 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3669 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3670 callingFeatureId, "getPrimaryImei")) {
3671 throw new SecurityException("Caller does not have permission");
3672 }
joonhunshin4ac60942023-11-15 15:23:39 +00003673
3674 enforceTelephonyFeatureWithException(callingPackage,
3675 PackageManager.FEATURE_TELEPHONY_GSM, "getPrimaryImei");
3676
arunvoddud5c6ce02022-12-11 06:03:12 +00003677 final long identity = Binder.clearCallingIdentity();
3678 try {
3679 for (Phone phone : PhoneFactory.getPhones()) {
3680 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3681 return phone.getImei();
3682 }
3683 }
3684 throw new UnsupportedOperationException("Operation not supported");
3685 } finally {
3686 Binder.restoreCallingIdentity(identity);
3687 }
3688 }
3689
3690 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003691 public String getTypeAllocationCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003692 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3693 PackageManager.FEATURE_TELEPHONY_GSM, "getTypeAllocationCodeForSlot");
3694
David Kelly5e06a7f2018-03-12 14:10:59 +00003695 Phone phone = PhoneFactory.getPhone(slotIndex);
3696 String tac = null;
3697 if (phone != null) {
3698 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003699 try {
3700 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3701 } catch (IndexOutOfBoundsException e) {
3702 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3703 return null;
3704 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003705 }
3706 return tac;
3707 }
3708
3709 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003710 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003711 try {
3712 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3713 } catch (SecurityException se) {
3714 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3715 throw new SecurityException("Package " + callingPackage + " does not belong to "
3716 + Binder.getCallingUid());
3717 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003718 Phone phone = PhoneFactory.getPhone(slotIndex);
3719 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003720 return null;
3721 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003722
Jeff Davidson913390f2018-02-23 17:11:49 -08003723 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003724 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003725 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003726 return null;
3727 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003728
joonhunshin4ac60942023-11-15 15:23:39 +00003729 enforceTelephonyFeatureWithException(callingPackage,
3730 PackageManager.FEATURE_TELEPHONY_CDMA, "getMeidForSlot");
3731
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003732 final long identity = Binder.clearCallingIdentity();
3733 try {
3734 return phone.getMeid();
3735 } finally {
3736 Binder.restoreCallingIdentity(identity);
3737 }
Jack Yu2af8d712017-03-15 17:14:14 -07003738 }
3739
3740 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003741 public String getManufacturerCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003742 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3743 PackageManager.FEATURE_TELEPHONY_CDMA, "getManufacturerCodeForSlot");
3744
David Kelly5e06a7f2018-03-12 14:10:59 +00003745 Phone phone = PhoneFactory.getPhone(slotIndex);
3746 String manufacturerCode = null;
3747 if (phone != null) {
3748 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003749 try {
3750 manufacturerCode =
3751 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3752 } catch (IndexOutOfBoundsException e) {
3753 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3754 return null;
3755 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003756 }
3757 return manufacturerCode;
3758 }
3759
3760 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003761 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3762 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003763 Phone phone = PhoneFactory.getPhone(slotIndex);
3764 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003765 return null;
3766 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003767 int subId = phone.getSubId();
3768 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003769 mApp, subId, callingPackage, callingFeatureId,
3770 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003771 return null;
3772 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003773
joonhunshin4ac60942023-11-15 15:23:39 +00003774 enforceTelephonyFeatureWithException(callingPackage,
3775 PackageManager.FEATURE_TELEPHONY, "getDeviceSoftwareVersionForSlot");
3776
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003777 final long identity = Binder.clearCallingIdentity();
3778 try {
3779 return phone.getDeviceSvn();
3780 } finally {
3781 Binder.restoreCallingIdentity(identity);
3782 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003783 }
3784
fionaxu43304da2017-11-27 22:51:16 -08003785 @Override
3786 public int getSubscriptionCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003787 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3788 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierId");
3789
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003790 final long identity = Binder.clearCallingIdentity();
3791 try {
3792 final Phone phone = getPhone(subId);
3793 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3794 } finally {
3795 Binder.restoreCallingIdentity(identity);
3796 }
fionaxu43304da2017-11-27 22:51:16 -08003797 }
3798
3799 @Override
3800 public String getSubscriptionCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003801 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3802 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierName");
3803
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003804 final long identity = Binder.clearCallingIdentity();
3805 try {
3806 final Phone phone = getPhone(subId);
3807 return phone == null ? null : phone.getCarrierName();
3808 } finally {
3809 Binder.restoreCallingIdentity(identity);
3810 }
fionaxu43304da2017-11-27 22:51:16 -08003811 }
3812
calvinpanffe225e2018-11-01 19:43:06 +08003813 @Override
chen xu0026ca62019-03-06 15:28:50 -08003814 public int getSubscriptionSpecificCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003815 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3816 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionSpecificCarrierId");
3817
chen xu25637222018-11-04 17:17:00 -08003818 final long identity = Binder.clearCallingIdentity();
3819 try {
3820 final Phone phone = getPhone(subId);
3821 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003822 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003823 } finally {
3824 Binder.restoreCallingIdentity(identity);
3825 }
3826 }
3827
3828 @Override
chen xu0026ca62019-03-06 15:28:50 -08003829 public String getSubscriptionSpecificCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003830 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3831 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
3832 "getSubscriptionSpecificCarrierName");
3833
chen xu25637222018-11-04 17:17:00 -08003834 final long identity = Binder.clearCallingIdentity();
3835 try {
3836 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003837 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003838 } finally {
3839 Binder.restoreCallingIdentity(identity);
3840 }
3841 }
3842
chen xu651eec72018-11-11 19:03:44 -08003843 @Override
chen xu864e11c2018-12-06 22:10:03 -08003844 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3845 if (!isSubscriptionMccMnc) {
3846 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3847 }
chen xu651eec72018-11-11 19:03:44 -08003848 final Phone phone = PhoneFactory.getPhone(slotIndex);
3849 if (phone == null) {
3850 return TelephonyManager.UNKNOWN_CARRIER_ID;
3851 }
joonhunshin4ac60942023-11-15 15:23:39 +00003852
3853 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3854 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromMccMnc");
3855
chen xu651eec72018-11-11 19:03:44 -08003856 final long identity = Binder.clearCallingIdentity();
3857 try {
3858 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3859 } finally {
3860 Binder.restoreCallingIdentity(identity);
3861 }
3862 }
3863
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003864 //
3865 // Internal helper methods.
3866 //
3867
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003868 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003869 * Make sure the caller is the calling package itself
3870 *
3871 * @throws SecurityException if the caller is not the calling package
3872 */
3873 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3874 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003875 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3876 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003877 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003878 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003879 } catch (PackageManager.NameNotFoundException e) {
3880 // packageUid is -1
3881 }
3882 if (packageUid != callingUid) {
3883 throw new SecurityException(message + ": Package " + callingPackage
3884 + " does not belong to " + callingUid);
3885 }
3886 }
3887
3888 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003889 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3890 *
3891 * @throws SecurityException if the caller does not have the required permission
3892 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003893 @VisibleForTesting
3894 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003895 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3896 }
3897
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003898 /**
arunvoddud7401012022-12-15 16:08:12 +00003899 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003900 *
3901 * @throws SecurityException if the caller does not have the required permission
3902 */
3903 @VisibleForTesting
3904 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003905 enforceReadPermission(null);
3906 }
3907
3908 /**
3909 * Make sure the caller has the READ_PHONE_STATE permissions.
3910 *
3911 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3912 */
3913 @VisibleForTesting
3914 public void enforceReadPermission(String msg) {
3915 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003916 }
3917
Shuo Qian3b6ee772019-11-13 17:43:31 -08003918 private void enforceActiveEmergencySessionPermission() {
3919 mApp.enforceCallingOrSelfPermission(
3920 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3921 }
3922
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003923 /**
3924 * Make sure the caller has the CALL_PHONE permission.
3925 *
3926 * @throws SecurityException if the caller does not have the required permission
3927 */
3928 private void enforceCallPermission() {
3929 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3930 }
3931
paulhu5a773602019-08-23 19:17:33 +08003932 private void enforceSettingsPermission() {
3933 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003934 }
3935
Michele Berionne5e411512020-11-13 02:36:59 +00003936 private void enforceRebootPermission() {
3937 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3938 }
3939
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003940 /**
3941 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3942 * @param message - log message to print.
3943 * @throws SecurityException if the caller does not have the required permission
3944 */
3945 private void enforceSatelliteCommunicationPermission(String message) {
3946 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3947 }
3948
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003949 private String createTelUrl(String number) {
3950 if (TextUtils.isEmpty(number)) {
3951 return null;
3952 }
3953
Jake Hambye994d462014-02-03 13:10:13 -08003954 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003955 }
3956
Ihab Awadf9e92732013-12-05 18:02:52 -08003957 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003958 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003959 }
3960
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003961 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003962 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003963 }
3964
Ihab Awadf9e92732013-12-05 18:02:52 -08003965 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003966 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003967 }
3968
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003969 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003970 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003971 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003972 }
3973
Sanket Padawe356d7632015-06-22 14:03:32 -07003974 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003975 public int getActivePhoneTypeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003976 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3977 PackageManager.FEATURE_TELEPHONY, "getActivePhoneTypeForSlot");
3978
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003979 final long identity = Binder.clearCallingIdentity();
3980 try {
3981 final Phone phone = PhoneFactory.getPhone(slotIndex);
3982 if (phone == null) {
3983 return PhoneConstants.PHONE_TYPE_NONE;
3984 } else {
3985 return phone.getPhoneType();
3986 }
3987 } finally {
3988 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003989 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003990 }
3991
3992 /**
3993 * Returns the CDMA ERI icon index to display
3994 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003995 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003996 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3997 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3998 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003999 }
4000
Sanket Padawe356d7632015-06-22 14:03:32 -07004001 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004002 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
4003 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004004 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004005 mApp, subId, callingPackage, callingFeatureId,
4006 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004007 return -1;
4008 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004009
joonhunshin4ac60942023-11-15 15:23:39 +00004010 enforceTelephonyFeatureWithException(callingPackage,
4011 PackageManager.FEATURE_TELEPHONY_CDMA,
4012 "getCdmaEriIconIndexForSubscriber");
4013
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004014 final long identity = Binder.clearCallingIdentity();
4015 try {
4016 final Phone phone = getPhone(subId);
4017 if (phone != null) {
4018 return phone.getCdmaEriIconIndex();
4019 } else {
4020 return -1;
4021 }
4022 } finally {
4023 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004024 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004025 }
4026
4027 /**
4028 * Returns the CDMA ERI icon mode,
4029 * 0 - ON
4030 * 1 - FLASHING
4031 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004032 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004033 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
4034 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
4035 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004036 }
4037
Sanket Padawe356d7632015-06-22 14:03:32 -07004038 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004039 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
4040 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004041 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004042 mApp, subId, callingPackage, callingFeatureId,
4043 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004044 return -1;
4045 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004046
4047 final long identity = Binder.clearCallingIdentity();
4048 try {
4049 final Phone phone = getPhone(subId);
4050 if (phone != null) {
4051 return phone.getCdmaEriIconMode();
4052 } else {
4053 return -1;
4054 }
4055 } finally {
4056 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004057 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004058 }
4059
4060 /**
4061 * Returns the CDMA ERI text,
4062 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004063 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004064 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
4065 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
4066 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004067 }
4068
Sanket Padawe356d7632015-06-22 14:03:32 -07004069 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004070 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
4071 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004072 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004073 mApp, subId, callingPackage, callingFeatureId,
4074 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004075 return null;
4076 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004077
4078 final long identity = Binder.clearCallingIdentity();
4079 try {
4080 final Phone phone = getPhone(subId);
4081 if (phone != null) {
4082 return phone.getCdmaEriText();
4083 } else {
4084 return null;
4085 }
4086 } finally {
4087 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004088 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004089 }
4090
4091 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07004092 * Returns the CDMA MDN.
4093 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004094 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004095 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004096 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4097 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004098
joonhunshin4ac60942023-11-15 15:23:39 +00004099 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4100 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMdn");
4101
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004102 final long identity = Binder.clearCallingIdentity();
4103 try {
4104 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004105 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004106 return phone.getLine1Number();
4107 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004108 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004109 return null;
4110 }
4111 } finally {
4112 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004113 }
4114 }
4115
4116 /**
4117 * Returns the CDMA MIN.
4118 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004119 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004120 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004121 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4122 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004123
joonhunshin4ac60942023-11-15 15:23:39 +00004124 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4125 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMin");
4126
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004127 final long identity = Binder.clearCallingIdentity();
4128 try {
4129 final Phone phone = getPhone(subId);
4130 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
4131 return phone.getCdmaMin();
4132 } else {
4133 return null;
4134 }
4135 } finally {
4136 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004137 }
4138 }
4139
Hall Liud892bec2018-11-30 14:51:45 -08004140 @Override
4141 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
4142 INumberVerificationCallback callback, String callingPackage) {
4143 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
4144 != PERMISSION_GRANTED) {
4145 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
4146 }
4147 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4148
4149 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
4150 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08004151 throw new SecurityException("Calling package must be configured in the device config: "
4152 + "calling package: " + callingPackage
4153 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004154 }
4155
joonhunshin4ac60942023-11-15 15:23:39 +00004156 enforceTelephonyFeatureWithException(callingPackage,
4157 PackageManager.FEATURE_TELEPHONY_CALLING, "requestNumberVerification");
4158
Hall Liud892bec2018-11-30 14:51:45 -08004159 if (range == null) {
4160 throw new NullPointerException("Range must be non-null");
4161 }
4162
4163 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004164 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004165
4166 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4167 }
4168
Junda Liuca05d5d2014-08-14 22:36:34 -07004169 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004170 * Returns true if CDMA provisioning needs to run.
4171 */
4172 public boolean needsOtaServiceProvisioning() {
joonhunshin4ac60942023-11-15 15:23:39 +00004173 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4174 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needsOtaServiceProvisioning");
4175
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004176 final long identity = Binder.clearCallingIdentity();
4177 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004178 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004179 } finally {
4180 Binder.restoreCallingIdentity(identity);
4181 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004182 }
4183
4184 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004185 * Sets the voice mail number of a given subId.
4186 */
4187 @Override
4188 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004189 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4190 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004191
joonhunshin4ac60942023-11-15 15:23:39 +00004192 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4193 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceMailNumber");
4194
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004195 final long identity = Binder.clearCallingIdentity();
4196 try {
4197 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4198 new Pair<String, String>(alphaTag, number), new Integer(subId));
4199 return success;
4200 } finally {
4201 Binder.restoreCallingIdentity(identity);
4202 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004203 }
4204
Ta-wei Yen87c49842016-05-13 21:19:52 -07004205 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004206 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4207 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004208 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4209 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004210 if (!TextUtils.equals(callingPackage, systemDialer)) {
4211 throw new SecurityException("caller must be system dialer");
4212 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004213
joonhunshin4ac60942023-11-15 15:23:39 +00004214 enforceTelephonyFeatureWithException(callingPackage,
4215 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailSettings");
4216
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004217 final long identity = Binder.clearCallingIdentity();
4218 try {
4219 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4220 if (phoneAccountHandle == null) {
4221 return null;
4222 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004223 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004224 } finally {
4225 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004226 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004227 }
4228
4229 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004230 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4231 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004232 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004233 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004234 mApp, subId, callingPackage, callingFeatureId,
4235 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004236 return null;
4237 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004238
joonhunshin4ac60942023-11-15 15:23:39 +00004239 enforceTelephonyFeatureWithException(callingPackage,
4240 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailPackageName");
4241
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004242 final long identity = Binder.clearCallingIdentity();
4243 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004244 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004245 } finally {
4246 Binder.restoreCallingIdentity(identity);
4247 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004248 }
4249
4250 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004251 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4252 VisualVoicemailSmsFilterSettings settings) {
4253 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004254
joonhunshin4ac60942023-11-15 15:23:39 +00004255 enforceTelephonyFeatureWithException(callingPackage,
4256 PackageManager.FEATURE_TELEPHONY_CALLING, "enableVisualVoicemailSmsFilter");
4257
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004258 final long identity = Binder.clearCallingIdentity();
4259 try {
4260 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004261 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004262 } finally {
4263 Binder.restoreCallingIdentity(identity);
4264 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004265 }
4266
4267 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004268 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4269 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004270
joonhunshin4ac60942023-11-15 15:23:39 +00004271 enforceTelephonyFeatureWithException(callingPackage,
4272 PackageManager.FEATURE_TELEPHONY_CALLING, "disableVisualVoicemailSmsFilter");
4273
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004274 final long identity = Binder.clearCallingIdentity();
4275 try {
4276 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004277 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004278 } finally {
4279 Binder.restoreCallingIdentity(identity);
4280 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004281 }
4282
4283 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004284 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4285 String callingPackage, int subId) {
4286 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004287
4288 final long identity = Binder.clearCallingIdentity();
4289 try {
4290 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004291 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004292 } finally {
4293 Binder.restoreCallingIdentity(identity);
4294 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004295 }
4296
4297 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004298 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004299 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004300
4301 final long identity = Binder.clearCallingIdentity();
4302 try {
4303 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004304 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004305 } finally {
4306 Binder.restoreCallingIdentity(identity);
4307 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004308 }
4309
4310 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004311 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4312 String callingAttributionTag, int subId, String number, int port, String text,
4313 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004314 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004315 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004316 enforceSendSmsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00004317
4318 enforceTelephonyFeatureWithException(callingPackage,
4319 PackageManager.FEATURE_TELEPHONY_CALLING, "sendVisualVoicemailSmsForSubscriber");
4320
Amit Mahajandccb3f12019-05-13 13:48:32 -07004321 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004322 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4323 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004324 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004325
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004326 /**
fionaxu0152e512016-11-14 13:36:14 -08004327 * Sets the voice activation state of a given subId.
4328 */
4329 @Override
4330 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004331 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4332 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004333
joonhunshin4ac60942023-11-15 15:23:39 +00004334 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4335 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState");
4336
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004337 final long identity = Binder.clearCallingIdentity();
4338 try {
4339 final Phone phone = getPhone(subId);
4340 if (phone != null) {
4341 phone.setVoiceActivationState(activationState);
4342 } else {
4343 loge("setVoiceActivationState fails with invalid subId: " + subId);
4344 }
4345 } finally {
4346 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004347 }
4348 }
4349
4350 /**
4351 * Sets the data activation state of a given subId.
4352 */
4353 @Override
4354 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004355 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4356 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004357
joonhunshin4ac60942023-11-15 15:23:39 +00004358 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4359 PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState");
4360
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004361 final long identity = Binder.clearCallingIdentity();
4362 try {
4363 final Phone phone = getPhone(subId);
4364 if (phone != null) {
4365 phone.setDataActivationState(activationState);
4366 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004367 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004368 }
4369 } finally {
4370 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004371 }
4372 }
4373
4374 /**
4375 * Returns the voice activation state of a given subId.
4376 */
4377 @Override
4378 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004379 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004380
joonhunshin4ac60942023-11-15 15:23:39 +00004381 enforceTelephonyFeatureWithException(callingPackage,
4382 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState");
4383
fionaxu0152e512016-11-14 13:36:14 -08004384 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004385 final long identity = Binder.clearCallingIdentity();
4386 try {
4387 if (phone != null) {
4388 return phone.getVoiceActivationState();
4389 } else {
4390 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4391 }
4392 } finally {
4393 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004394 }
4395 }
4396
4397 /**
4398 * Returns the data activation state of a given subId.
4399 */
4400 @Override
4401 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004402 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004403
joonhunshin4ac60942023-11-15 15:23:39 +00004404 enforceTelephonyFeatureWithException(callingPackage,
4405 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState");
4406
fionaxu0152e512016-11-14 13:36:14 -08004407 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004408 final long identity = Binder.clearCallingIdentity();
4409 try {
4410 if (phone != null) {
4411 return phone.getDataActivationState();
4412 } else {
4413 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4414 }
4415 } finally {
4416 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004417 }
4418 }
4419
4420 /**
Wink Saville36469e72014-06-11 15:17:00 -07004421 * Returns the unread count of voicemails for a subId
4422 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004423 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004424 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4425 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004426 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004427 mApp, subId, callingPackage, callingFeatureId,
4428 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004429 return 0;
4430 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004431 final long identity = Binder.clearCallingIdentity();
4432 try {
4433 final Phone phone = getPhone(subId);
4434 if (phone != null) {
4435 return phone.getVoiceMessageCount();
4436 } else {
4437 return 0;
4438 }
4439 } finally {
4440 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004441 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004442 }
4443
4444 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004445 * returns true, if the device is in a state where both voice and data
4446 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004447 */
4448 @Override
4449 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00004450 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4451 PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed");
4452
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004453 final long identity = Binder.clearCallingIdentity();
4454 try {
Ling Mac28f0212023-03-24 16:07:15 -07004455 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004456 } finally {
4457 Binder.restoreCallingIdentity(identity);
4458 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004459 }
4460
4461 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004462 * Send the dialer code if called from the current default dialer or the caller has
4463 * carrier privilege.
4464 * @param inputCode The dialer code to send
4465 */
4466 @Override
4467 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004468 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004469 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004470 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4471 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004472 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004473 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004474 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004475 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004476
joonhunshin4ac60942023-11-15 15:23:39 +00004477 enforceTelephonyFeatureWithException(callingPackage,
4478 PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode");
4479
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004480 final long identity = Binder.clearCallingIdentity();
4481 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004482 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004483 } finally {
4484 Binder.restoreCallingIdentity(identity);
4485 }
fionaxu235cc5e2017-03-06 22:25:57 -08004486 }
4487
Pengquan Menga1bb6272018-09-06 09:59:22 -07004488 @Override
4489 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004490 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004491 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4492 mApp, subId, "getNetworkSelectionMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004493
4494 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4495 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode");
4496
shilufc958392020-01-20 11:36:01 -08004497 final long identity = Binder.clearCallingIdentity();
4498 try {
4499 if (!isActiveSubscription(subId)) {
4500 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4501 }
4502 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4503 } finally {
4504 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004505 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004506 }
4507
Brad Ebinger35c841c2018-10-01 10:40:55 -07004508 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004509 public boolean isInEmergencySmsMode() {
4510 enforceReadPrivilegedPermission("isInEmergencySmsMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004511
4512 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4513 PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode");
4514
Brad Ebingerb2b65522019-03-15 13:48:47 -07004515 final long identity = Binder.clearCallingIdentity();
4516 try {
4517 for (Phone phone : PhoneFactory.getPhones()) {
4518 if (phone.isInEmergencySmsMode()) {
4519 return true;
4520 }
4521 }
4522 } finally {
4523 Binder.restoreCallingIdentity(identity);
4524 }
4525 return false;
4526 }
4527
shilu366312e2019-12-17 09:28:10 -08004528 /**
4529 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4530 * @param subId The subscription to use to check the configuration.
4531 * @param c The callback that will be used to send the result.
4532 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004533 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004534 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4535 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004536 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004537 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004538
4539 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4540 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4541 "IMS not available on device.");
4542 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004543 final long token = Binder.clearCallingIdentity();
4544 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004545 int slotId = getSlotIndexOrException(subId);
4546 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004547
4548 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4549 if (controller != null) {
4550 ImsManager imsManager = controller.getImsManager(subId);
4551 if (imsManager != null) {
4552 imsManager.addRegistrationCallbackForSubscription(c, subId);
4553 } else {
4554 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4555 }
4556 } else {
4557 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4558 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004559 } catch (ImsException e) {
4560 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004561 } finally {
4562 Binder.restoreCallingIdentity(token);
4563 }
4564 }
4565
shilu366312e2019-12-17 09:28:10 -08004566 /**
4567 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4568 * @param subId The subscription to use to check the configuration.
4569 * @param c The callback that will be used to send the result.
4570 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004571 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004572 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004573 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004574 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004575 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4576 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4577 }
Meng Wangafbc5852019-09-19 17:37:13 -07004578 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004579
Meng Wangafbc5852019-09-19 17:37:13 -07004580 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004581 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4582 if (controller != null) {
4583 ImsManager imsManager = controller.getImsManager(subId);
4584 if (imsManager != null) {
4585 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4586 } else {
4587 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4588 + "is inactive, ignoring unregister.");
4589 // If the ImsManager is not valid, just return, since the callback
4590 // will already have been removed internally.
4591 }
4592 }
Meng Wangafbc5852019-09-19 17:37:13 -07004593 } finally {
4594 Binder.restoreCallingIdentity(token);
4595 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004596 }
4597
Brad Ebingera34a6c22019-10-22 17:36:18 -07004598 /**
Hidayat Khan99ea48f2023-12-11 04:37:45 +00004599 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4600 * @param subId The subscription to use to check the configuration.
4601 * @param c The callback that will be used to send the result.
4602 */
4603 @Override
4604 public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c)
4605 throws RemoteException {
4606 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4607 mApp, subId, "registerImsEmergencyRegistrationCallback");
4608
4609 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4610 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4611 "IMS not available on device.");
4612 }
4613 final long token = Binder.clearCallingIdentity();
4614 try {
4615 int slotId = getSlotIndexOrException(subId);
4616 verifyImsMmTelConfiguredOrThrow(slotId);
4617
4618 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4619 if (controller != null) {
4620 ImsManager imsManager = controller.getImsManager(subId);
4621 if (imsManager != null) {
4622 imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId);
4623 } else {
4624 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4625 }
4626 } else {
4627 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4628 }
4629 } catch (ImsException e) {
4630 throw new ServiceSpecificException(e.getCode());
4631 } finally {
4632 Binder.restoreCallingIdentity(token);
4633 }
4634 }
4635
4636 /**
4637 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4638 * @param subId The subscription to use to check the configuration.
4639 * @param c The callback that will be used to send the result.
4640 */
4641 @Override
4642 public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) {
4643 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4644 mApp, subId, "unregisterImsEmergencyRegistrationCallback");
4645 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4646 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4647 }
4648 final long token = Binder.clearCallingIdentity();
4649
4650 try {
4651 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4652 if (controller != null) {
4653 ImsManager imsManager = controller.getImsManager(subId);
4654 if (imsManager != null) {
4655 imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId);
4656 } else {
4657 Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId
4658 + "is inactive, ignoring unregister.");
4659 // If the ImsManager is not valid, just return, since the callback
4660 // will already have been removed internally.
4661 }
4662 }
4663 } finally {
4664 Binder.restoreCallingIdentity(token);
4665 }
4666 }
4667
4668 /**
Brad Ebingera34a6c22019-10-22 17:36:18 -07004669 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4670 */
4671 @Override
4672 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4673 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4674 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4675 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4676 "IMS not available on device.");
4677 }
4678 final long token = Binder.clearCallingIdentity();
4679 try {
4680 Phone phone = getPhone(subId);
4681 if (phone == null) {
4682 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4683 + subId + "'");
4684 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4685 }
4686 phone.getImsRegistrationState(regState -> {
4687 try {
4688 consumer.accept((regState == null)
4689 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4690 } catch (RemoteException e) {
4691 // Ignore if the remote process is no longer available to call back.
4692 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4693 }
4694 });
4695 } finally {
4696 Binder.restoreCallingIdentity(token);
4697 }
4698 }
4699
4700 /**
4701 * Get the transport type for the IMS service registration state.
4702 */
4703 @Override
4704 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004705 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004706 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004707 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4708 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4709 "IMS not available on device.");
4710 }
4711 final long token = Binder.clearCallingIdentity();
4712 try {
4713 Phone phone = getPhone(subId);
4714 if (phone == null) {
4715 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4716 + subId + "'");
4717 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4718 }
4719 phone.getImsRegistrationTech(regTech -> {
4720 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4721 int regTechConverted = (regTech == null)
4722 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4723 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4724 regTechConverted);
4725 try {
4726 consumer.accept(regTechConverted);
4727 } catch (RemoteException e) {
4728 // Ignore if the remote process is no longer available to call back.
4729 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4730 }
4731 });
4732 } finally {
4733 Binder.restoreCallingIdentity(token);
4734 }
4735 }
4736
shilu366312e2019-12-17 09:28:10 -08004737 /**
4738 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4739 * @param subId The subscription to use to check the configuration.
4740 * @param c The callback that will be used to send the result.
4741 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004742 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004743 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4744 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004745 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004746 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004747 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4748 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4749 "IMS not available on device.");
4750 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004751 final long token = Binder.clearCallingIdentity();
4752 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004753 int slotId = getSlotIndexOrException(subId);
4754 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004755
4756 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4757 if (controller != null) {
4758 ImsManager imsManager = controller.getImsManager(subId);
4759 if (imsManager != null) {
4760 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4761 } else {
4762 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4763 }
4764 } else {
4765 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4766 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004767 } catch (ImsException e) {
4768 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004769 } finally {
4770 Binder.restoreCallingIdentity(token);
4771 }
4772 }
4773
shilu366312e2019-12-17 09:28:10 -08004774 /**
4775 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4776 * @param subId The subscription to use to check the configuration.
4777 * @param c The callback that will be used to send the result.
4778 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004779 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004780 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004781 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004782 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004783 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4784 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4785 }
Meng Wangafbc5852019-09-19 17:37:13 -07004786
4787 final long token = Binder.clearCallingIdentity();
4788 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004789 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4790 if (controller != null) {
4791 ImsManager imsManager = controller.getImsManager(subId);
4792 if (imsManager != null) {
4793 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4794 } else {
4795 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4796 + " is inactive, ignoring unregister.");
4797 // If the ImsManager is not valid, just return, since the callback
4798 // will already have been removed internally.
4799 }
4800 }
Meng Wangafbc5852019-09-19 17:37:13 -07004801 } finally {
4802 Binder.restoreCallingIdentity(token);
4803 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004804 }
4805
4806 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004807 public boolean isCapable(int subId, int capability, int regTech) {
4808 enforceReadPrivilegedPermission("isCapable");
joonhunshin4ac60942023-11-15 15:23:39 +00004809
4810 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4811 FEATURE_TELEPHONY_IMS, "isCapable");
4812
Brad Ebinger35c841c2018-10-01 10:40:55 -07004813 final long token = Binder.clearCallingIdentity();
4814 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004815 int slotId = getSlotIndexOrException(subId);
4816 verifyImsMmTelConfiguredOrThrow(slotId);
4817 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4818 } catch (com.android.ims.ImsException e) {
4819 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4820 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004821 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004822 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4823 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004824 } finally {
4825 Binder.restoreCallingIdentity(token);
4826 }
4827 }
4828
4829 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004830 public boolean isAvailable(int subId, int capability, int regTech) {
4831 enforceReadPrivilegedPermission("isAvailable");
joonhunshin4ac60942023-11-15 15:23:39 +00004832
4833 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4834 FEATURE_TELEPHONY_IMS, "isAvailable");
4835
Brad Ebinger35c841c2018-10-01 10:40:55 -07004836 final long token = Binder.clearCallingIdentity();
4837 try {
4838 Phone phone = getPhone(subId);
4839 if (phone == null) return false;
4840 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004841 } catch (com.android.ims.ImsException e) {
4842 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4843 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004844 } finally {
4845 Binder.restoreCallingIdentity(token);
4846 }
4847 }
4848
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004849 /**
4850 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4851 * subscription.
4852 * @param subId The subscription to use to check the configuration.
4853 * @param callback The callback that will be used to send the result.
4854 * @param capability The MmTelFeature capability that will be used to send the result.
4855 * @param transportType The transport type of the MmTelFeature capability.
4856 */
4857 @Override
4858 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4859 int transportType) {
4860 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004861 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4862 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4863 "IMS not available on device.");
4864 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004865 final long token = Binder.clearCallingIdentity();
4866 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004867 int slotId = getSlotIndex(subId);
4868 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4869 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4870 + subId + "'");
4871 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4872 }
4873 verifyImsMmTelConfiguredOrThrow(slotId);
4874 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4875 transportType, aBoolean -> {
4876 try {
4877 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4878 } catch (RemoteException e) {
4879 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4880 + "running. Ignore");
4881 }
4882 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004883 } catch (ImsException e) {
4884 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004885 } finally {
4886 Binder.restoreCallingIdentity(token);
4887 }
4888 }
4889
shilu366312e2019-12-17 09:28:10 -08004890 /**
4891 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4892 * @param subId The subscription to use to check the configuration.
4893 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004894 @Override
4895 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004896 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004897 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004898
joonhunshin4ac60942023-11-15 15:23:39 +00004899 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4900 FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled");
4901
Brad Ebinger35c841c2018-10-01 10:40:55 -07004902 final long token = Binder.clearCallingIdentity();
4903 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004904 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004905 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004906 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004907 } catch (ImsException e) {
4908 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004909 } finally {
4910 Binder.restoreCallingIdentity(token);
4911 }
4912 }
4913
4914 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004915 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004916 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004917 "setAdvancedCallingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004918
4919 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4920 FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled");
4921
Brad Ebinger35c841c2018-10-01 10:40:55 -07004922 final long identity = Binder.clearCallingIdentity();
4923 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004924 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004925 // This setting doesn't require an active ImsService connection, so do not verify. The
4926 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004927 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004928 } catch (ImsException e) {
4929 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004930 } finally {
4931 Binder.restoreCallingIdentity(identity);
4932 }
4933 }
4934
shilu366312e2019-12-17 09:28:10 -08004935 /**
4936 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4937 * @param subId The subscription to use to check the configuration.
4938 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004939 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004940 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004941 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004942 mApp, subId, "isVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004943
4944 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4945 FEATURE_TELEPHONY_IMS, "isVtSettingEnabled");
4946
Brad Ebinger35c841c2018-10-01 10:40:55 -07004947 final long identity = Binder.clearCallingIdentity();
4948 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004949 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004950 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004951 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004952 } catch (ImsException e) {
4953 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004954 } finally {
4955 Binder.restoreCallingIdentity(identity);
4956 }
4957 }
4958
4959 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004960 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004961 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004962 "setVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004963
4964 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4965 FEATURE_TELEPHONY_IMS, "setVtSettingEnabled");
4966
Brad Ebinger35c841c2018-10-01 10:40:55 -07004967 final long identity = Binder.clearCallingIdentity();
4968 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004969 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004970 // This setting doesn't require an active ImsService connection, so do not verify. The
4971 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004972 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004973 } catch (ImsException e) {
4974 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004975 } finally {
4976 Binder.restoreCallingIdentity(identity);
4977 }
4978 }
4979
shilu366312e2019-12-17 09:28:10 -08004980 /**
4981 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4982 * @param subId The subscription to use to check the configuration.
4983 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004984 @Override
4985 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004986 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004987 mApp, subId, "isVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004988
4989 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4990 FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled");
4991
Brad Ebinger35c841c2018-10-01 10:40:55 -07004992 final long identity = Binder.clearCallingIdentity();
4993 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004994 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004995 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004996 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004997 } catch (ImsException e) {
4998 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004999 } finally {
5000 Binder.restoreCallingIdentity(identity);
5001 }
5002 }
5003
5004 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005005 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005006 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005007 "setVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005008
5009 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5010 FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled");
5011
Brad Ebinger35c841c2018-10-01 10:40:55 -07005012 final long identity = Binder.clearCallingIdentity();
5013 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005014 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005015 // This setting doesn't require an active ImsService connection, so do not verify. The
5016 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005017 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005018 } catch (ImsException e) {
5019 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005020 } finally {
5021 Binder.restoreCallingIdentity(identity);
5022 }
5023 }
5024
shilu366312e2019-12-17 09:28:10 -08005025 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005026 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
5027 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5028 * @param subId The subscription to use to check the configuration.
5029 */
5030 @Override
5031 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005032 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005033 mApp, subId, "isCrossSimCallingEnabledByUser");
joonhunshin4ac60942023-11-15 15:23:39 +00005034
5035 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5036 FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser");
5037
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005038 final long identity = Binder.clearCallingIdentity();
5039 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005040 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005041 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005042 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005043 } catch (ImsException e) {
5044 throw new ServiceSpecificException(e.getCode());
5045 } finally {
5046 Binder.restoreCallingIdentity(identity);
5047 }
5048 }
5049
5050 /**
5051 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
5052 * Requires MODIFY_PHONE_STATE permission.
5053 * @param subId The subscription to use to check the configuration.
5054 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
5055 * false otherwise
5056 */
5057 @Override
5058 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
5059 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5060 "setCrossSimCallingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005061
5062 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5063 FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled");
5064
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005065 final long identity = Binder.clearCallingIdentity();
5066 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005067 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005068 // This setting doesn't require an active ImsService connection, so do not verify. The
5069 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005070 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005071 } catch (ImsException e) {
5072 throw new ServiceSpecificException(e.getCode());
5073 } finally {
5074 Binder.restoreCallingIdentity(identity);
5075 }
5076 }
5077
5078 /**
shilu366312e2019-12-17 09:28:10 -08005079 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5080 * @param subId The subscription to use to check the configuration.
5081 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005082 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07005083
Brad Ebinger35c841c2018-10-01 10:40:55 -07005084 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005085 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005086 mApp, subId, "isVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005087
5088 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5089 FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled");
5090
Brad Ebinger35c841c2018-10-01 10:40:55 -07005091 final long identity = Binder.clearCallingIdentity();
5092 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005093 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005094 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005095 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005096 } catch (ImsException e) {
5097 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005098 } finally {
5099 Binder.restoreCallingIdentity(identity);
5100 }
5101 }
5102
5103 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005104 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005105 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005106 "setVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005107
5108 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5109 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled");
5110
Brad Ebinger35c841c2018-10-01 10:40:55 -07005111 final long identity = Binder.clearCallingIdentity();
5112 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005113 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005114 // This setting doesn't require an active ImsService connection, so do not verify. The
5115 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005116 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005117 } catch (ImsException e) {
5118 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005119 } finally {
5120 Binder.restoreCallingIdentity(identity);
5121 }
5122 }
5123
5124 @Override
5125 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
5126 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5127 "setVoWiFiNonPersistent");
joonhunshin4ac60942023-11-15 15:23:39 +00005128
5129 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5130 FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent");
5131
Brad Ebinger35c841c2018-10-01 10:40:55 -07005132 final long identity = Binder.clearCallingIdentity();
5133 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005134 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005135 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005136 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005137 } catch (ImsException e) {
5138 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005139 } finally {
5140 Binder.restoreCallingIdentity(identity);
5141 }
5142 }
5143
shilu366312e2019-12-17 09:28:10 -08005144 /**
5145 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5146 * @param subId The subscription to use to check the configuration.
5147 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005148 @Override
5149 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005150 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005151 mApp, subId, "getVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005152
5153 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5154 FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting");
5155
Brad Ebinger35c841c2018-10-01 10:40:55 -07005156 final long identity = Binder.clearCallingIdentity();
5157 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005158 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005159 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005160 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005161 } catch (ImsException e) {
5162 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005163 } finally {
5164 Binder.restoreCallingIdentity(identity);
5165 }
5166 }
5167
5168 @Override
5169 public void setVoWiFiModeSetting(int subId, int mode) {
5170 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5171 "setVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005172
5173 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5174 FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting");
5175
Brad Ebinger35c841c2018-10-01 10:40:55 -07005176 final long identity = Binder.clearCallingIdentity();
5177 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005178 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005179 // This setting doesn't require an active ImsService connection, so do not verify. The
5180 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005181 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005182 } catch (ImsException e) {
5183 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005184 } finally {
5185 Binder.restoreCallingIdentity(identity);
5186 }
5187 }
5188
5189 @Override
5190 public int getVoWiFiRoamingModeSetting(int subId) {
5191 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005192
5193 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5194 FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting");
5195
Brad Ebinger35c841c2018-10-01 10:40:55 -07005196 final long identity = Binder.clearCallingIdentity();
5197 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005198 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005199 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005200 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005201 } catch (ImsException e) {
5202 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005203 } finally {
5204 Binder.restoreCallingIdentity(identity);
5205 }
5206 }
5207
5208 @Override
5209 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
5210 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5211 "setVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005212
5213 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5214 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting");
5215
Brad Ebinger35c841c2018-10-01 10:40:55 -07005216 final long identity = Binder.clearCallingIdentity();
5217 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005218 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005219 // This setting doesn't require an active ImsService connection, so do not verify. The
5220 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005221 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005222 } catch (ImsException e) {
5223 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005224 } finally {
5225 Binder.restoreCallingIdentity(identity);
5226 }
5227 }
5228
5229 @Override
5230 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
5231 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5232 "setRttCapabilityEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005233
5234 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5235 FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting");
5236
Brad Ebinger35c841c2018-10-01 10:40:55 -07005237 final long identity = Binder.clearCallingIdentity();
5238 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005239 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005240 // This setting doesn't require an active ImsService connection, so do not verify. The
5241 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005242 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005243 } catch (ImsException e) {
5244 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005245 } finally {
5246 Binder.restoreCallingIdentity(identity);
5247 }
5248 }
5249
shilu366312e2019-12-17 09:28:10 -08005250 /**
5251 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5252 * @param subId The subscription to use to check the configuration.
5253 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005254 @Override
5255 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005256 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005257 mApp, subId, "isTtyOverVolteEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005258
5259 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5260 FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled");
5261
Brad Ebinger35c841c2018-10-01 10:40:55 -07005262 final long identity = Binder.clearCallingIdentity();
5263 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005264 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005265 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005266 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005267 } catch (ImsException e) {
5268 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005269 } finally {
5270 Binder.restoreCallingIdentity(identity);
5271 }
5272 }
5273
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005274 @Override
5275 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5276 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005277
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005278 final long identity = Binder.clearCallingIdentity();
5279 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005280 if (!isImsAvailableOnDevice()) {
5281 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5282 "IMS not available on device.");
5283 }
5284 int slotId = getSlotIndexOrException(subId);
5285 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005286
5287 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5288 if (controller != null) {
5289 ImsManager imsManager = controller.getImsManager(subId);
5290 if (imsManager != null) {
5291 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5292 } else {
5293 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5294 }
5295 } else {
5296 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5297 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005298 } catch (ImsException e) {
5299 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005300 } finally {
5301 Binder.restoreCallingIdentity(identity);
5302 }
5303 }
5304
5305 @Override
5306 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5307 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005308
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005309 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005310 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5311 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5312 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005313 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005314 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5315 if (controller != null) {
5316 ImsManager imsManager = controller.getImsManager(subId);
5317 if (imsManager != null) {
5318 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5319 } else {
5320 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5321 + " is inactive, ignoring unregister.");
5322 // If the ImsManager is not valid, just return, since the callback will already
5323 // have been removed internally.
5324 }
5325 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005326 } finally {
5327 Binder.restoreCallingIdentity(identity);
5328 }
5329 }
5330
joonhunshincffb7fc2021-11-28 07:32:01 +00005331 @Override
5332 public void registerFeatureProvisioningChangedCallback(int subId,
5333 IFeatureProvisioningCallback callback) {
5334 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5335 mApp, subId, "registerFeatureProvisioningChangedCallback");
5336
5337 final long identity = Binder.clearCallingIdentity();
5338 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5339 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5340 }
5341
joonhunshin91bc1952022-04-29 08:47:15 +00005342 try {
5343 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5344 if (controller == null) {
5345 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5346 "Device does not support IMS");
5347 }
5348 controller.addFeatureProvisioningChangedCallback(subId, callback);
5349 } finally {
5350 Binder.restoreCallingIdentity(identity);
5351 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005352 }
5353
5354 @Override
5355 public void unregisterFeatureProvisioningChangedCallback(int subId,
5356 IFeatureProvisioningCallback callback) {
5357 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5358 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5359
5360 final long identity = Binder.clearCallingIdentity();
5361 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5362 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5363 }
5364
joonhunshin91bc1952022-04-29 08:47:15 +00005365 try {
5366 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5367 if (controller == null) {
5368 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5369 return;
5370 }
5371 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5372 } finally {
5373 Binder.restoreCallingIdentity(identity);
5374 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005375 }
allenwtsu99c623b2020-01-03 18:24:23 +08005376
5377 private void checkModifyPhoneStatePermission(int subId, String message) {
5378 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5379 message);
5380 }
5381
allenwtsu99c623b2020-01-03 18:24:23 +08005382 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005383 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005384 boolean isProvisioned) {
5385 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5386
joonhunshin4ac60942023-11-15 15:23:39 +00005387 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5388 FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability");
5389
allenwtsu99c623b2020-01-03 18:24:23 +08005390 final long identity = Binder.clearCallingIdentity();
5391 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005392 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5393 if (controller == null) {
5394 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5395 return;
5396 }
5397 controller.setRcsProvisioningStatusForCapability(
5398 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005399 } finally {
5400 Binder.restoreCallingIdentity(identity);
5401 }
allenwtsu99c623b2020-01-03 18:24:23 +08005402 }
5403
5404
5405 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005406 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5407 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5408 mApp, subId, "getRcsProvisioningStatusForCapability");
5409
joonhunshin4ac60942023-11-15 15:23:39 +00005410 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5411 FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability");
5412
allenwtsu99c623b2020-01-03 18:24:23 +08005413 final long identity = Binder.clearCallingIdentity();
5414 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005415 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5416 if (controller == null) {
5417 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5418
5419 // device does not support IMS, this method will return true always.
5420 return true;
5421 }
5422 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005423 } finally {
5424 Binder.restoreCallingIdentity(identity);
5425 }
5426 }
5427
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005428 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005429 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5430 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005431 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005432
joonhunshin4ac60942023-11-15 15:23:39 +00005433 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5434 FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability");
5435
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005436 final long identity = Binder.clearCallingIdentity();
5437 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005438 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5439 if (controller == null) {
5440 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5441 return;
5442 }
5443 controller.setImsProvisioningStatusForCapability(
5444 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005445 } finally {
5446 Binder.restoreCallingIdentity(identity);
5447 }
5448 }
5449
5450 @Override
5451 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005452 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5453 mApp, subId, "getProvisioningStatusForCapability");
5454
joonhunshin4ac60942023-11-15 15:23:39 +00005455 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5456 FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability");
5457
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005458 final long identity = Binder.clearCallingIdentity();
5459 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005460 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5461 if (controller == null) {
5462 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005463
joonhunshin91bc1952022-04-29 08:47:15 +00005464 // device does not support IMS, this method will return true always.
5465 return true;
5466 }
5467 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005468 } finally {
5469 Binder.restoreCallingIdentity(identity);
5470 }
5471 }
5472
5473 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005474 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5475 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5476 mApp, subId, "isProvisioningRequiredForCapability");
5477
joonhunshin4ac60942023-11-15 15:23:39 +00005478 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5479 FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability");
5480
joonhunshincffb7fc2021-11-28 07:32:01 +00005481 final long identity = Binder.clearCallingIdentity();
5482 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005483 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5484 if (controller == null) {
5485 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5486
5487 // device does not support IMS, this method will return false
5488 return false;
5489 }
5490 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005491 } finally {
5492 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005493 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005494 }
5495
5496 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005497 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5498 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5499 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005500
joonhunshin4ac60942023-11-15 15:23:39 +00005501 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5502 FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability");
5503
joonhunshincffb7fc2021-11-28 07:32:01 +00005504 final long identity = Binder.clearCallingIdentity();
5505 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005506 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5507 if (controller == null) {
5508 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5509
5510 // device does not support IMS, this method will return false
5511 return false;
5512 }
5513 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005514 } finally {
5515 Binder.restoreCallingIdentity(identity);
5516 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005517 }
5518
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005519 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005520 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005521 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5522 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5523 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005524 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5525 mApp, subId, "getImsProvisioningInt");
5526
joonhunshin4ac60942023-11-15 15:23:39 +00005527 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5528 FEATURE_TELEPHONY_IMS, "getImsProvisioningInt");
5529
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005530 final long identity = Binder.clearCallingIdentity();
5531 try {
5532 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005533 int slotId = getSlotIndex(subId);
5534 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5535 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5536 + subId + "' for key:" + key);
5537 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5538 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005539
joonhunshin91bc1952022-04-29 08:47:15 +00005540 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5541 if (controller == null) {
5542 loge("getImsProvisioningInt: Device does not support IMS");
5543
5544 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5545 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5546 }
5547 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005548 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5549 return retVal;
5550 }
5551
calvinpanb5a34062021-02-08 19:59:36 +08005552 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005553 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005554 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5555 + subId + "' for key:" + key);
5556 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005557 } finally {
5558 Binder.restoreCallingIdentity(identity);
5559 }
5560 }
5561
5562 @Override
5563 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005564 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5565 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5566 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005567 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5568 mApp, subId, "getImsProvisioningString");
5569
joonhunshin4ac60942023-11-15 15:23:39 +00005570 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5571 FEATURE_TELEPHONY_IMS, "getImsProvisioningString");
5572
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005573 final long identity = Binder.clearCallingIdentity();
5574 try {
5575 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005576 int slotId = getSlotIndex(subId);
5577 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5578 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5579 + subId + "' for key:" + key);
5580 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5581 }
calvinpanb5a34062021-02-08 19:59:36 +08005582 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005583 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005584 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5585 + subId + "' for key:" + key);
5586 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005587 } finally {
5588 Binder.restoreCallingIdentity(identity);
5589 }
5590 }
5591
5592 @Override
5593 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005594 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5595 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5596 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005597 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5598 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005599
joonhunshin4ac60942023-11-15 15:23:39 +00005600 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5601 FEATURE_TELEPHONY_IMS, "setImsProvisioningInt");
5602
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005603 final long identity = Binder.clearCallingIdentity();
5604 try {
5605 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005606 int slotId = getSlotIndex(subId);
5607 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5608 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5609 + subId + "' for key:" + key);
5610 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5611 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005612
joonhunshin91bc1952022-04-29 08:47:15 +00005613 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5614 if (controller == null) {
5615 loge("setImsProvisioningInt: Device does not support IMS");
5616
5617 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5618 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5619 }
5620 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005621 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5622 return retVal;
5623 }
5624
calvinpanb5a34062021-02-08 19:59:36 +08005625 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5626 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005627 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005628 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005629 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005630 } finally {
5631 Binder.restoreCallingIdentity(identity);
5632 }
5633 }
5634
5635 @Override
5636 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005637 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5638 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5639 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005640 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5641 "setImsProvisioningString");
joonhunshin4ac60942023-11-15 15:23:39 +00005642
5643 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5644 FEATURE_TELEPHONY_IMS, "setImsProvisioningString");
5645
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005646 final long identity = Binder.clearCallingIdentity();
5647 try {
5648 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005649 int slotId = getSlotIndex(subId);
5650 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5651 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5652 + subId + "' for key:" + key);
5653 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5654 }
calvinpanb5a34062021-02-08 19:59:36 +08005655 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5656 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005657 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005658 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005659 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005660 } finally {
5661 Binder.restoreCallingIdentity(identity);
5662 }
5663 }
5664
Brad Ebinger919631e2021-06-02 17:46:35 -07005665 /**
5666 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5667 * for the given slot ID or no ImsResolver instance has been created.
5668 * @param slotId The slot ID that the IMS service is created for.
5669 * @throws ImsException If there is no ImsService configured for this slot.
5670 */
5671 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5672 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5673 ImsFeature.FEATURE_MMTEL)) {
5674 throw new ImsException("This subscription does not support MMTEL over IMS",
5675 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5676 }
5677 }
5678
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005679 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005680 int slotId = SubscriptionManager.getSlotIndex(subId);
5681 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005682 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5683 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005684 }
5685 return slotId;
5686 }
5687
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005688 private int getSlotIndex(int subId) {
5689 int slotId = SubscriptionManager.getSlotIndex(subId);
5690 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5691 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5692 }
5693 return slotId;
5694 }
5695
Wink Saville36469e72014-06-11 15:17:00 -07005696 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005697 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005698 */
5699 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005700 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5701 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005702 try {
5703 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5704 } catch (SecurityException se) {
5705 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5706 throw new SecurityException("Package " + callingPackage + " does not belong to "
5707 + Binder.getCallingUid());
5708 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005709 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005710 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005711 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005712 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005713 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005714 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005715 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005716 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5717 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005718
joonhunshin4ac60942023-11-15 15:23:39 +00005719 enforceTelephonyFeatureWithException(callingPackage,
5720 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber");
5721
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005722 final long identity = Binder.clearCallingIdentity();
5723 try {
5724 final Phone phone = getPhone(subId);
5725 if (phone != null) {
5726 return phone.getServiceState().getDataNetworkType();
5727 } else {
5728 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5729 }
5730 } finally {
5731 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005732 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005733 }
5734
5735 /**
5736 * Returns the data network type
5737 */
5738 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005739 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005740 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005741 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005742 }
5743
5744 /**
5745 * Returns the data network type for a subId
5746 */
5747 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005748 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5749 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005750 String functionName = "getDataNetworkTypeForSubscriber";
5751 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5752 mApp, functionName)) {
5753 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5754 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5755 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5756 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005757 }
5758
joonhunshin4ac60942023-11-15 15:23:39 +00005759 enforceTelephonyFeatureWithException(callingPackage,
5760 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber");
5761
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005762 final long identity = Binder.clearCallingIdentity();
5763 try {
5764 final Phone phone = getPhone(subId);
5765 if (phone != null) {
5766 return phone.getServiceState().getDataNetworkType();
5767 } else {
5768 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5769 }
5770 } finally {
5771 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005772 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005773 }
5774
5775 /**
Wink Saville36469e72014-06-11 15:17:00 -07005776 * Returns the Voice network type for a subId
5777 */
5778 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005779 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5780 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005781 String functionName = "getVoiceNetworkTypeForSubscriber";
5782 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5783 mApp, functionName)) {
5784 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5785 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5786 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5787 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005788 }
5789
joonhunshin4ac60942023-11-15 15:23:39 +00005790 enforceTelephonyFeatureWithException(callingPackage,
5791 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber");
5792
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005793 final long identity = Binder.clearCallingIdentity();
5794 try {
5795 final Phone phone = getPhone(subId);
5796 if (phone != null) {
5797 return phone.getServiceState().getVoiceNetworkType();
5798 } else {
5799 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5800 }
5801 } finally {
5802 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005803 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005804 }
5805
5806 /**
5807 * @return true if a ICC card is present
5808 */
5809 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005810 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005811 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005812 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005813 }
5814
5815 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005816 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005817 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005818 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005819 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00005820 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5821 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex");
5822
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005823 final long identity = Binder.clearCallingIdentity();
5824 try {
5825 final Phone phone = PhoneFactory.getPhone(slotIndex);
5826 if (phone != null) {
5827 return phone.getIccCard().hasIccCard();
5828 } else {
5829 return false;
5830 }
5831 } finally {
5832 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005833 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005834 }
5835
5836 /**
5837 * Return if the current radio is LTE on CDMA. This
5838 * is a tri-state return value as for a period of time
5839 * the mode may be unknown.
5840 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005841 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005842 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005843 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005844 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005845 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005846 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5847 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5848 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005849 }
5850
Sanket Padawe356d7632015-06-22 14:03:32 -07005851 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005852 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5853 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005854 try {
5855 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5856 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005857 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5858 }
5859
joonhunshin4ac60942023-11-15 15:23:39 +00005860 enforceTelephonyFeatureWithException(callingPackage,
5861 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber");
5862
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005863 final long identity = Binder.clearCallingIdentity();
5864 try {
5865 final Phone phone = getPhone(subId);
5866 if (phone == null) {
5867 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5868 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005869 return TelephonyProperties.lte_on_cdma_device()
5870 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005871 }
5872 } finally {
5873 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005874 }
Wink Saville36469e72014-06-11 15:17:00 -07005875 }
5876
Wink Saville36469e72014-06-11 15:17:00 -07005877 /**
5878 * {@hide}
5879 * Returns Default subId, 0 in the case of single standby.
5880 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005881 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005882 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005883 }
5884
Shishir Agrawala9f32182016-04-12 12:00:16 -07005885 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005886 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005887 }
5888
Wink Savilleb564aae2014-10-23 10:18:09 -07005889 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005890 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005891 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005892
Pengquan Menge92a50d2018-09-21 15:54:48 -07005893 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005894 return getSubscriptionManagerService().isActiveSubId(subId,
5895 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005896 }
5897
Ihab Awadf2177b72013-11-25 13:33:23 -08005898 /**
5899 * @see android.telephony.TelephonyManager.WifiCallingChoices
5900 */
5901 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005902 final long identity = Binder.clearCallingIdentity();
5903 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005904 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005905 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5906 getWhenToMakeWifiCallsDefaultPreference());
5907 } finally {
5908 Binder.restoreCallingIdentity(identity);
5909 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005910 }
5911
5912 /**
5913 * @see android.telephony.TelephonyManager.WifiCallingChoices
5914 */
5915 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005916 final long identity = Binder.clearCallingIdentity();
5917 try {
5918 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005919 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005920 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5921 } finally {
5922 Binder.restoreCallingIdentity(identity);
5923 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005924 }
5925
Sailesh Nepald1e68152013-12-12 19:08:02 -08005926 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005927 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005928 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005929 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005930
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005931 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5932 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5933 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005934 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005935 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005936 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005937 }
5938 return PhoneFactory.getPhone(phoneId);
5939 }
5940
Shishir Agrawal566b7612013-10-28 14:41:00 -07005941 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005942 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005943 @NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00005944
Rambo Wanga1782702021-11-10 20:15:19 -08005945 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5946 /*message=*/ "iccOpenLogicalChannel");
5947
5948 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5949 // Verify that the callingPackage in the request belongs to the calling UID
5950 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5951
joonhunshin4ac60942023-11-15 15:23:39 +00005952 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5953 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel");
5954
Rambo Wanga1782702021-11-10 20:15:19 -08005955 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005956 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005957
Rambo Wanga1782702021-11-10 20:15:19 -08005958 private Phone getPhoneFromValidIccLogicalChannelRequest(
5959 @NonNull IccLogicalChannelRequest request, String message) {
5960 Phone phone;
5961 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5962 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5963 mApp, request.subId, message);
5964 phone = getPhoneFromSubId(request.subId);
5965 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5966 enforceModifyPermission();
5967 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5968 } else {
5969 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005970 }
Rambo Wanga1782702021-11-10 20:15:19 -08005971 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005972 }
5973
5974 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005975 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005976 final long identity = Binder.clearCallingIdentity();
5977 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005978 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005979 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005980 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5981 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005982 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5983 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005984 loge("The calling package is not allowed to access ISD-R.");
5985 throw new SecurityException(
5986 "The calling package is not allowed to access ISD-R.");
5987 }
Derek Tan740e1672017-06-27 14:56:27 -07005988 }
Derek Tan740e1672017-06-27 14:56:27 -07005989
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005990 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005991 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5992 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005993 return response;
5994 } finally {
5995 Binder.restoreCallingIdentity(identity);
5996 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005997 }
5998
5999 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08006000 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00006001 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6002 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel");
6003
Rambo Wanga1782702021-11-10 20:15:19 -08006004 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
6005 /*message=*/"iccCloseLogicalChannel");
6006
6007 if (DBG) log("iccCloseLogicalChannel: request=" + request);
6008
6009 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006010 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006011
Rambo Wanga1782702021-11-10 20:15:19 -08006012 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
6013 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08006014 // before this feature is enabled, this API should only return false if
6015 // the operation fails instead of throwing runtime exception for
6016 // backward-compatibility.
6017 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
6018 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006019 final long identity = Binder.clearCallingIdentity();
6020 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006021 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08006022 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006023 }
Chen Xue9d737e2022-01-01 23:41:31 -08006024 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08006025 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08006026 Boolean success = false;
6027 if (result instanceof RuntimeException) {
6028 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08006029 if (shouldThrowExceptionOnFailure) {
6030 throw (RuntimeException) result;
6031 } else {
6032 return false;
6033 }
Chen Xue9d737e2022-01-01 23:41:31 -08006034 } else if (result instanceof Boolean) {
6035 success = (Boolean) result;
6036 } else {
6037 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
6038 }
Rambo Wanga1782702021-11-10 20:15:19 -08006039 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006040 return success;
6041 } finally {
6042 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006043 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006044 }
6045
6046 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006047 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07006048 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006049 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6050 mApp, subId, "iccTransmitApduLogicalChannel");
joonhunshin4ac60942023-11-15 15:23:39 +00006051
6052 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6053 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel");
6054
Jordan Liu4c733742019-02-28 12:03:40 -08006055 if (DBG) {
6056 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
6057 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
6058 + p3 + " data=" + data);
6059 }
6060 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
6061 command, p1, p2, p3, data);
6062 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006063
Jordan Liu4c733742019-02-28 12:03:40 -08006064 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006065 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006066 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006067 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006068
6069 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6070 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
6071 "iccTransmitApduLogicalChannelBySlot");
6072
Jordan Liu4c733742019-02-28 12:03:40 -08006073 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006074 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006075 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
6076 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006077 }
6078 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006079 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
6080 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006081 }
6082
6083 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
6084 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006085 final long identity = Binder.clearCallingIdentity();
6086 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07006087 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006088 return "";
6089 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006090
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006091 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006092 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
6093 null /* workSource */);
6094 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006095
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006096 // Append the returned status code to the end of the response payload.
6097 String s = Integer.toHexString(
6098 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6099 if (response.payload != null) {
6100 s = IccUtils.bytesToHexString(response.payload) + s;
6101 }
6102 return s;
6103 } finally {
6104 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006105 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006106 }
Jake Hambye994d462014-02-03 13:10:13 -08006107
Evan Charltonc66da362014-05-16 14:06:40 -07006108 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006109 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
6110 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006111 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6112 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006113 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006114
6115 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6116 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel");
6117
Jordan Liu4c733742019-02-28 12:03:40 -08006118 if (DBG) {
6119 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
6120 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
6121 }
6122 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
6123 cla, command, p1, p2, p3, data);
6124 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006125
Jordan Liu4c733742019-02-28 12:03:40 -08006126 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006127 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006128 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006129 enforceModifyPermission();
6130 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006131
6132 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6133 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot");
6134
Jordan Liu4c733742019-02-28 12:03:40 -08006135 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006136 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006137 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
6138 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006139 }
6140
6141 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006142 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
6143 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006144 }
6145
6146 // open APDU basic channel assuming the caller has sufficient permissions
6147 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
6148 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006149 final long identity = Binder.clearCallingIdentity();
6150 try {
6151 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
6152 && TextUtils.equals(ISDR_AID, data)) {
6153 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006154 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6155 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006156 if (bestComponent == null
6157 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
6158 loge("The calling package is not allowed to select ISD-R.");
6159 throw new SecurityException(
6160 "The calling package is not allowed to select ISD-R.");
6161 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006162 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006163
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006164 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006165 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
6166 null /* workSource */);
6167 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006168
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006169 // Append the returned status code to the end of the response payload.
6170 String s = Integer.toHexString(
6171 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6172 if (response.payload != null) {
6173 s = IccUtils.bytesToHexString(response.payload) + s;
6174 }
6175 return s;
6176 } finally {
6177 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006178 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006179 }
6180
6181 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006182 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006183 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006184 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6185 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006186
joonhunshin4ac60942023-11-15 15:23:39 +00006187 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6188 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO");
6189
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006190 final long identity = Binder.clearCallingIdentity();
6191 try {
6192 if (DBG) {
6193 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
6194 + p1 + " " + p2 + " " + p3 + ":" + filePath);
6195 }
6196
6197 IccIoResult response =
6198 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
6199 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
6200 subId);
6201
6202 if (DBG) {
6203 log("Exchange SIM_IO [R]" + response);
6204 }
6205
6206 byte[] result = null;
6207 int length = 2;
6208 if (response.payload != null) {
6209 length = 2 + response.payload.length;
6210 result = new byte[length];
6211 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
6212 } else {
6213 result = new byte[length];
6214 }
6215
6216 result[length - 1] = (byte) response.sw2;
6217 result[length - 2] = (byte) response.sw1;
6218 return result;
6219 } finally {
6220 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006221 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006222 }
6223
Nathan Haroldb3014052017-01-25 15:57:32 -08006224 /**
6225 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
6226 * on a particular subscription
6227 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006228 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
6229 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07006230 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006231 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07006232 return null;
6233 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006234
joonhunshin4ac60942023-11-15 15:23:39 +00006235 enforceTelephonyFeatureWithException(callingPackage,
6236 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns");
6237
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006238 final long identity = Binder.clearCallingIdentity();
6239 try {
6240 if (appType != TelephonyManager.APPTYPE_USIM
6241 && appType != TelephonyManager.APPTYPE_SIM) {
6242 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
6243 return null;
6244 }
6245 Object response = sendRequest(
6246 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
6247 if (response instanceof String[]) {
6248 return (String[]) response;
6249 }
yincheng zhao2737e882019-09-06 17:06:54 -07006250 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006251 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08006252 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006253 } finally {
6254 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08006255 }
Nathan Haroldb3014052017-01-25 15:57:32 -08006256 }
6257
yincheng zhao2737e882019-09-06 17:06:54 -07006258 /**
6259 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
6260 * subscription.
6261 *
6262 * @param subId the id of the subscription.
6263 * @param appType the uicc app type, must be USIM or SIM.
6264 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
6265 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006266 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07006267 * @return number of fplmns that is successfully written to the SIM.
6268 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006269 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
6270 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07006271 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6272 mApp, subId, "setForbiddenPlmns");
6273
joonhunshin4ac60942023-11-15 15:23:39 +00006274 enforceTelephonyFeatureWithException(callingPackage,
6275 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns");
6276
yincheng zhao2737e882019-09-06 17:06:54 -07006277 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
6278 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
6279 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
6280 }
6281 if (fplmns == null) {
6282 throw new IllegalArgumentException("Fplmn List provided is null");
6283 }
6284 for (String fplmn : fplmns) {
6285 if (!CellIdentity.isValidPlmn(fplmn)) {
6286 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
6287 }
6288 }
6289 final long identity = Binder.clearCallingIdentity();
6290 try {
6291 Object response = sendRequest(
6292 CMD_SET_FORBIDDEN_PLMNS,
6293 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
6294 subId);
6295 return (int) response;
6296 } finally {
6297 Binder.restoreCallingIdentity(identity);
6298 }
6299 }
6300
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006301 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006302 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006303 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6304 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07006305
joonhunshin4ac60942023-11-15 15:23:39 +00006306 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6307 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus");
6308
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006309 final long identity = Binder.clearCallingIdentity();
6310 try {
6311 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
6312 if (response.payload == null) {
6313 return "";
6314 }
Evan Charltonc66da362014-05-16 14:06:40 -07006315
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006316 // Append the returned status code to the end of the response payload.
6317 String s = Integer.toHexString(
6318 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6319 s = IccUtils.bytesToHexString(response.payload) + s;
6320 return s;
6321 } finally {
6322 Binder.restoreCallingIdentity(identity);
6323 }
Evan Charltonc66da362014-05-16 14:06:40 -07006324 }
6325
Jake Hambye994d462014-02-03 13:10:13 -08006326 /**
6327 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6328 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6329 *
6330 * @param itemID the ID of the item to read
6331 * @return the NV item as a String, or null on error.
6332 */
6333 @Override
6334 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006335 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006336 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6337 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006338
6339 final long identity = Binder.clearCallingIdentity();
6340 try {
6341 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07006342 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006343 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
6344 return value;
6345 } finally {
6346 Binder.restoreCallingIdentity(identity);
6347 }
Jake Hambye994d462014-02-03 13:10:13 -08006348 }
6349
6350 /**
6351 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6352 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6353 *
6354 * @param itemID the ID of the item to read
6355 * @param itemValue the value to write, as a String
6356 * @return true on success; false on any failure
6357 */
6358 @Override
6359 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006360 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006361 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6362 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006363
6364 final long identity = Binder.clearCallingIdentity();
6365 try {
6366 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6367 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006368 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006369 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6370 return success;
6371 } finally {
6372 Binder.restoreCallingIdentity(identity);
6373 }
Jake Hambye994d462014-02-03 13:10:13 -08006374 }
6375
6376 /**
6377 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6378 * Used for device configuration by some CDMA operators.
6379 *
6380 * @param preferredRoamingList byte array containing the new PRL
6381 * @return true on success; false on any failure
6382 */
6383 @Override
6384 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006385 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6386 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006387
6388 final long identity = Binder.clearCallingIdentity();
6389 try {
6390 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6391 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6392 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6393 return success;
6394 } finally {
6395 Binder.restoreCallingIdentity(identity);
6396 }
Jake Hambye994d462014-02-03 13:10:13 -08006397 }
6398
6399 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006400 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006401 * Used for device configuration by some CDMA operators.
6402 *
chen xu6dac5ab2018-10-26 17:39:23 -07006403 * @param slotIndex - device slot.
6404 *
Jake Hambye994d462014-02-03 13:10:13 -08006405 * @return true on success; false on any failure
6406 */
6407 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006408 public boolean resetModemConfig(int slotIndex) {
6409 Phone phone = PhoneFactory.getPhone(slotIndex);
6410 if (phone != null) {
6411 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6412 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006413
joonhunshin4ac60942023-11-15 15:23:39 +00006414 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6415 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig");
6416
chen xu6dac5ab2018-10-26 17:39:23 -07006417 final long identity = Binder.clearCallingIdentity();
6418 try {
6419 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6420 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6421 return success;
6422 } finally {
6423 Binder.restoreCallingIdentity(identity);
6424 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006425 }
chen xu6dac5ab2018-10-26 17:39:23 -07006426 return false;
6427 }
6428
6429 /**
6430 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6431 *
6432 * @param slotIndex - device slot.
6433 *
6434 * @return true on success; false on any failure
6435 */
6436 @Override
6437 public boolean rebootModem(int slotIndex) {
6438 Phone phone = PhoneFactory.getPhone(slotIndex);
6439 if (phone != null) {
6440 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6441 mApp, phone.getSubId(), "rebootModem");
6442
joonhunshin4ac60942023-11-15 15:23:39 +00006443 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6444 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem");
6445
chen xu6dac5ab2018-10-26 17:39:23 -07006446 final long identity = Binder.clearCallingIdentity();
6447 try {
6448 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6449 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6450 return success;
6451 } finally {
6452 Binder.restoreCallingIdentity(identity);
6453 }
6454 }
6455 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006456 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006457
Brad Ebinger51f743a2017-01-23 13:50:20 -08006458 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006459 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6460 * {@link #disableIms(int)}.
6461 * @param slotIndex device slot.
6462 */
6463 public void resetIms(int slotIndex) {
6464 enforceModifyPermission();
6465
joonhunshin4ac60942023-11-15 15:23:39 +00006466 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6467 PackageManager.FEATURE_TELEPHONY_IMS, "resetIms");
6468
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006469 final long identity = Binder.clearCallingIdentity();
6470 try {
6471 if (mImsResolver == null) {
6472 // may happen if the does not support IMS.
6473 return;
6474 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006475 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006476 } finally {
6477 Binder.restoreCallingIdentity(identity);
6478 }
6479 }
6480
6481 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006482 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6483 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006484 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006485 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006486 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006487
6488 final long identity = Binder.clearCallingIdentity();
6489 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006490 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006491 // may happen if the device does not support IMS.
6492 return;
6493 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006494 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006495 } finally {
6496 Binder.restoreCallingIdentity(identity);
6497 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006498 }
6499
6500 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006501 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6502 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006503 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006504 public void disableIms(int slotId) {
6505 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006506
6507 final long identity = Binder.clearCallingIdentity();
6508 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006509 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006510 // may happen if the device does not support IMS.
6511 return;
6512 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006513 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006514 } finally {
6515 Binder.restoreCallingIdentity(identity);
6516 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006517 }
6518
6519 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006520 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6521 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006522 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006523 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006524 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006525 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006526
6527 final long identity = Binder.clearCallingIdentity();
6528 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006529 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006530 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6531 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006532 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006533 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006534 } finally {
6535 Binder.restoreCallingIdentity(identity);
6536 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006537 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006538 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006539 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6540 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006541 @Override
6542 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006543 enforceModifyPermission();
6544
6545 final long identity = Binder.clearCallingIdentity();
6546 try {
6547 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006548 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006549 } finally {
6550 Binder.restoreCallingIdentity(identity);
6551 }
6552 }
6553
6554 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006555 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006556 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006557 */
6558 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6559 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006560
6561 final long identity = Binder.clearCallingIdentity();
6562 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006563 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006564 // may happen if the device does not support IMS.
6565 return null;
6566 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006567 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006568 } finally {
6569 Binder.restoreCallingIdentity(identity);
6570 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006571 }
6572
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006573 /**
6574 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006575 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006576 */
6577 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6578 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006579
6580 final long identity = Binder.clearCallingIdentity();
6581 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006582 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006583 // may happen if the device does not support IMS.
6584 return null;
6585 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006586 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006587 } finally {
6588 Binder.restoreCallingIdentity(identity);
6589 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006590 }
6591
Brad Ebinger884c07b2018-02-15 16:17:40 -08006592 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006593 * Sets the ImsService Package Name that Telephony will bind to.
6594 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006595 * @param slotIndex the slot ID that the ImsService should bind for.
6596 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006597 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006598 * @param featureTypes An integer array of feature types associated with a packageName.
6599 * @param packageName The name of the package that the current configuration will be replaced
6600 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006601 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006602 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006603 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6604 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006605 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006606 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006607 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006608
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006609 final long identity = Binder.clearCallingIdentity();
6610 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006611 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006612 // may happen if the device does not support IMS.
6613 return false;
6614 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006615 Map<Integer, String> featureConfig = new HashMap<>();
6616 for (int featureType : featureTypes) {
6617 featureConfig.put(featureType, packageName);
6618 }
6619 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6620 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006621 } finally {
6622 Binder.restoreCallingIdentity(identity);
6623 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006624 }
6625
6626 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006627 * Clears any carrier ImsService overrides for the slot index specified that were previously
6628 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6629 *
6630 * This should only be used for testing.
6631 *
6632 * @param slotIndex the slot ID that the ImsService should bind for.
6633 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6634 */
6635 @Override
6636 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006637 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6638 "clearCarrierImsServiceOverride");
6639 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006640 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006641
6642 final long identity = Binder.clearCallingIdentity();
6643 try {
6644 if (mImsResolver == null) {
6645 // may happen if the device does not support IMS.
6646 return false;
6647 }
6648 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6649 } finally {
6650 Binder.restoreCallingIdentity(identity);
6651 }
6652 }
6653
6654 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006655 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006656 *
6657 * @param slotId The slot that the ImsService is associated with.
6658 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6659 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006660 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006661 * @return the package name of the ImsService configuration.
6662 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006663 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6664 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006665 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006666 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6667 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006668
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006669 final long identity = Binder.clearCallingIdentity();
6670 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006671 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006672 // may happen if the device does not support IMS.
6673 return "";
6674 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006675 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006676 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6677 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006678 } finally {
6679 Binder.restoreCallingIdentity(identity);
6680 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006681 }
6682
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006683 /**
6684 * Get the MmTelFeature state associated with the requested subscription id.
6685 * @param subId The subscription that the MmTelFeature is associated with.
6686 * @param callback A callback with an integer containing the
6687 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6688 */
6689 @Override
6690 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6691 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006692 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6693 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6694 "IMS not available on device.");
6695 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006696 final long token = Binder.clearCallingIdentity();
6697 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006698 int slotId = getSlotIndex(subId);
6699 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6700 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6701 + subId + "'");
6702 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6703 }
6704 verifyImsMmTelConfiguredOrThrow(slotId);
6705 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6706 try {
6707 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6708 } catch (RemoteException e) {
6709 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6710 + "Ignore");
6711 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006712 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006713 } catch (ImsException e) {
6714 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006715 } finally {
6716 Binder.restoreCallingIdentity(token);
6717 }
6718 }
6719
Daniel Brightbb5840b2021-01-12 15:48:18 -08006720 /**
6721 * Sets the ims registration state on all valid {@link Phone}s.
6722 */
6723 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006724 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006725
6726 final long identity = Binder.clearCallingIdentity();
6727 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006728 // NOTE: Before S, this method only set the default phone.
6729 for (final Phone phone : PhoneFactory.getPhones()) {
6730 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6731 phone.setImsRegistrationState(registered);
6732 }
6733 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006734 } finally {
6735 Binder.restoreCallingIdentity(identity);
6736 }
Wink Saville36469e72014-06-11 15:17:00 -07006737 }
6738
6739 /**
Stuart Scott54788802015-03-30 13:18:01 -07006740 * Set the network selection mode to automatic.
6741 *
6742 */
6743 @Override
6744 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006745 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6746 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006747
joonhunshin4ac60942023-11-15 15:23:39 +00006748 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6749 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic");
6750
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006751 final long identity = Binder.clearCallingIdentity();
6752 try {
shilufc958392020-01-20 11:36:01 -08006753 if (!isActiveSubscription(subId)) {
6754 return;
6755 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006756 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006757 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6758 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006759 } finally {
6760 Binder.restoreCallingIdentity(identity);
6761 }
Stuart Scott54788802015-03-30 13:18:01 -07006762 }
6763
Jack Yud10cdd42020-09-28 20:28:01 -07006764 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006765 * Ask the radio to connect to the input network and change selection mode to manual.
6766 *
6767 * @param subId the id of the subscription.
6768 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6769 * the operator to attach to.
6770 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6771 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6772 * normal network selection next time.
6773 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006774 */
6775 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006776 public boolean setNetworkSelectionModeManual(
6777 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006778 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6779 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006780
joonhunshin4ac60942023-11-15 15:23:39 +00006781 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6782 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual");
6783
Jack Yu285100e2022-12-02 22:48:35 -08006784 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006785 if (!isActiveSubscription(subId)) {
6786 return false;
6787 }
6788
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006789 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006790 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006791 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006792 if (DBG) {
6793 log("setNetworkSelectionModeManual: subId: " + subId
6794 + " operator: " + operatorInfo);
6795 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006796 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6797 } finally {
6798 Binder.restoreCallingIdentity(identity);
6799 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006800 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006801 /**
shilu84f6e8b2019-12-19 13:58:01 -08006802 * Get the manual network selection
6803 *
6804 * @param subId the id of the subscription.
6805 *
6806 * @return the previously saved user selected PLMN
6807 */
6808 @Override
6809 public String getManualNetworkSelectionPlmn(int subId) {
6810 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006811 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6812 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006813
joonhunshin4ac60942023-11-15 15:23:39 +00006814 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6815 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn");
6816
shilu84f6e8b2019-12-19 13:58:01 -08006817 final long identity = Binder.clearCallingIdentity();
6818 try {
6819 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006820 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006821 }
6822
6823 final Phone phone = getPhone(subId);
6824 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006825 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006826 }
6827 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6828 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006829 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006830 } finally {
6831 Binder.restoreCallingIdentity(identity);
6832 }
6833 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006834
6835 /**
6836 * Scans for available networks.
6837 */
6838 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006839 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6840 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006841 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6842 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006843 LocationAccessPolicy.LocationPermissionResult locationResult =
6844 LocationAccessPolicy.checkLocationPermission(mApp,
6845 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6846 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006847 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006848 .setCallingPid(Binder.getCallingPid())
6849 .setCallingUid(Binder.getCallingUid())
6850 .setMethod("getCellNetworkScanResults")
6851 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006852 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6853 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006854 .build());
6855 switch (locationResult) {
6856 case DENIED_HARD:
6857 throw new SecurityException("Not allowed to access scan results -- location");
6858 case DENIED_SOFT:
6859 return null;
6860 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006861
Pengquan Menga1bb6272018-09-06 09:59:22 -07006862 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006863 try {
6864 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006865 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006866 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006867 } finally {
6868 Binder.restoreCallingIdentity(identity);
6869 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006870 }
6871
6872 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006873 * Get the call forwarding info, given the call forwarding reason.
6874 */
6875 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006876 public void getCallForwarding(int subId, int callForwardingReason,
6877 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006878 enforceReadPrivilegedPermission("getCallForwarding");
joonhunshin4ac60942023-11-15 15:23:39 +00006879
6880 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6881 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding");
6882
Shuo Qian4a594052020-01-23 11:59:30 -08006883 long identity = Binder.clearCallingIdentity();
6884 try {
6885 if (DBG) {
6886 log("getCallForwarding: subId " + subId
6887 + " callForwardingReason" + callForwardingReason);
6888 }
Hall Liu27d24262020-09-18 19:04:59 -07006889
6890 Phone phone = getPhone(subId);
6891 if (phone == null) {
6892 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006893 callback.onError(
6894 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006895 } catch (RemoteException e) {
6896 // ignore
6897 }
6898 return;
6899 }
6900
6901 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6902 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6903 @Override
6904 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6905 try {
6906 callback.onCallForwardingInfoAvailable(info);
6907 } catch (RemoteException e) {
6908 // ignore
6909 }
6910 }
6911
6912 @Override
6913 public void onError(int error) {
6914 try {
6915 callback.onError(error);
6916 } catch (RemoteException e) {
6917 // ignore
6918 }
6919 }
6920 });
6921 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006922 } finally {
6923 Binder.restoreCallingIdentity(identity);
6924 }
6925 }
6926
6927 /**
6928 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6929 * reason, the number to forward, and the timeout before the forwarding is attempted.
6930 */
6931 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006932 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6933 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006934 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006935
6936 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6937 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding");
6938
Shuo Qian4a594052020-01-23 11:59:30 -08006939 long identity = Binder.clearCallingIdentity();
6940 try {
6941 if (DBG) {
6942 log("setCallForwarding: subId " + subId
6943 + " callForwardingInfo" + callForwardingInfo);
6944 }
Hall Liu27d24262020-09-18 19:04:59 -07006945
6946 Phone phone = getPhone(subId);
6947 if (phone == null) {
6948 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006949 callback.accept(
6950 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006951 } catch (RemoteException e) {
6952 // ignore
6953 }
6954 return;
6955 }
6956
6957 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6958 FunctionalUtils.ignoreRemoteException(callback::accept));
6959
6960 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006961 } finally {
6962 Binder.restoreCallingIdentity(identity);
6963 }
6964 }
6965
6966 /**
Hall Liu27d24262020-09-18 19:04:59 -07006967 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006968 */
6969 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006970 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006971 enforceReadPrivilegedPermission("getCallWaitingStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00006972
6973 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6974 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus");
6975
Shuo Qian4a594052020-01-23 11:59:30 -08006976 long identity = Binder.clearCallingIdentity();
6977 try {
Hall Liu27d24262020-09-18 19:04:59 -07006978 Phone phone = getPhone(subId);
6979 if (phone == null) {
6980 try {
6981 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6982 } catch (RemoteException e) {
6983 // ignore
6984 }
6985 return;
6986 }
SongFerngWang0e767992021-03-31 22:08:45 +08006987 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6988 PersistableBundle c = configManager.getConfigForSubId(subId);
6989 boolean requireUssd = c.getBoolean(
6990 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006991
Shuo Qian4a594052020-01-23 11:59:30 -08006992 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006993 if (requireUssd) {
6994 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6995 getSubscriptionCarrierId(subId));
6996 String newUssdCommand = "";
6997 try {
6998 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006999 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007000 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
7001 } catch (NullPointerException e) {
7002 loge("Failed to generate USSD number" + e);
7003 }
7004 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7005 mMainThreadHandler, callback, carrierXmlParser,
7006 CarrierXmlParser.SsEntry.SSAction.QUERY);
7007 final String ussdCommand = newUssdCommand;
7008 Executors.newSingleThreadExecutor().execute(() -> {
7009 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7010 });
7011 } else {
7012 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
7013 callback::accept);
7014 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
7015 }
Shuo Qian4a594052020-01-23 11:59:30 -08007016 } finally {
7017 Binder.restoreCallingIdentity(identity);
7018 }
7019 }
7020
7021 /**
Hall Liu27d24262020-09-18 19:04:59 -07007022 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007023 */
7024 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007025 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007026 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007027
7028 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7029 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus");
7030
Shuo Qian4a594052020-01-23 11:59:30 -08007031 long identity = Binder.clearCallingIdentity();
7032 try {
Hall Liu27d24262020-09-18 19:04:59 -07007033 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
7034
7035 Phone phone = getPhone(subId);
7036 if (phone == null) {
7037 try {
7038 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7039 } catch (RemoteException e) {
7040 // ignore
7041 }
7042 return;
7043 }
7044
SongFerngWang0e767992021-03-31 22:08:45 +08007045 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7046 PersistableBundle c = configManager.getConfigForSubId(subId);
7047 boolean requireUssd = c.getBoolean(
7048 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007049
SongFerngWang0e767992021-03-31 22:08:45 +08007050 if (DBG) log("getCallWaitingStatus: subId " + subId);
7051 if (requireUssd) {
7052 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7053 getSubscriptionCarrierId(subId));
7054 CarrierXmlParser.SsEntry.SSAction ssAction =
7055 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
7056 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
7057 String newUssdCommand = "";
7058 try {
7059 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007060 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007061 .makeCommand(ssAction, null);
7062 } catch (NullPointerException e) {
7063 loge("Failed to generate USSD number" + e);
7064 }
7065 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7066 mMainThreadHandler, callback, carrierXmlParser, ssAction);
7067 final String ussdCommand = newUssdCommand;
7068 Executors.newSingleThreadExecutor().execute(() -> {
7069 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7070 });
7071 } else {
7072 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
7073 FunctionalUtils.ignoreRemoteException(callback::accept));
7074
7075 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
7076 }
Shuo Qian4a594052020-01-23 11:59:30 -08007077 } finally {
7078 Binder.restoreCallingIdentity(identity);
7079 }
7080 }
7081
7082 /**
yinxub1bed742017-04-17 11:45:04 -07007083 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07007084 *
yinxub1bed742017-04-17 11:45:04 -07007085 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007086 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
7087 * location related information which will be sent if the caller already possess
7088 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07007089 * @param request contains the radio access networks with bands/channels to scan
7090 * @param messenger callback messenger for scan results or errors
7091 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07007092 * @return the id of the requested scan which can be used to stop the scan.
7093 */
7094 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007095 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
7096 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007097 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007098 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7099 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08007100 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007101 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
7102 if (!renounceFineLocationAccess) {
7103 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007104 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7105 .setCallingPackage(callingPackage)
7106 .setCallingFeatureId(callingFeatureId)
7107 .setCallingPid(Binder.getCallingPid())
7108 .setCallingUid(Binder.getCallingUid())
7109 .setMethod("requestNetworkScan")
7110 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7111 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7112 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7113 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007114 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08007115 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07007116 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
7117 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08007118 if (e != null) {
7119 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
7120 throw e;
7121 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07007122 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08007123 return TelephonyScanManager.INVALID_SCAN_ID;
7124 }
7125 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007126 }
joonhunshin4ac60942023-11-15 15:23:39 +00007127
7128 enforceTelephonyFeatureWithException(callingPackage,
7129 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan");
7130
Hall Liu912dfd32019-04-25 14:02:26 -07007131 int callingUid = Binder.getCallingUid();
7132 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07007133 final long identity = Binder.clearCallingIdentity();
7134 try {
7135 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07007136 renounceFineLocationAccess, request, messenger, binder,
7137 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07007138 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07007139 } finally {
7140 Binder.restoreCallingIdentity(identity);
7141 }
yinxu504e1392017-04-12 16:03:22 -07007142 }
7143
Hall Liub2ac8ef2019-02-28 15:56:23 -08007144 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07007145 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00007146 boolean hasCarrierPriv;
7147 final long identity = Binder.clearCallingIdentity();
7148 try {
7149 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
7150 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
7151 } finally {
7152 Binder.restoreCallingIdentity(identity);
7153 }
Hall Liu558027f2019-05-15 19:14:05 -07007154 boolean hasNetworkScanPermission =
7155 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007156 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07007157
7158 if (!hasCarrierPriv && !hasNetworkScanPermission) {
7159 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
7160 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08007161 }
7162
7163 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
7164 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08007165 if (ras.getChannels() != null && ras.getChannels().length > 0) {
7166 return new SecurityException("Specific channels must not be"
7167 + " scanned without location access.");
7168 }
7169 }
7170 }
7171
Hall Liub2ac8ef2019-02-28 15:56:23 -08007172 return null;
7173 }
7174
yinxu504e1392017-04-12 16:03:22 -07007175 /**
7176 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07007177 *
7178 * @param subId id of the subscription
7179 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07007180 */
7181 @Override
7182 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007183 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7184 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007185
Hall Liu912dfd32019-04-25 14:02:26 -07007186 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007187 final long identity = Binder.clearCallingIdentity();
7188 try {
Hall Liu912dfd32019-04-25 14:02:26 -07007189 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007190 } finally {
7191 Binder.restoreCallingIdentity(identity);
7192 }
yinxu504e1392017-04-12 16:03:22 -07007193 }
7194
7195 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08007196 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07007197 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08007198 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07007199 */
7200 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08007201 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08007202 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007203 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08007204 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007205
joonhunshin4ac60942023-11-15 15:23:39 +00007206 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7207 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask");
7208
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007209 final long identity = Binder.clearCallingIdentity();
7210 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007211 if (DBG) log("getAllowedNetworkTypesBitmask");
7212 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
7213 int networkTypesBitmask = (result != null ? result[0] : -1);
7214 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
7215 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007216 } finally {
7217 Binder.restoreCallingIdentity(identity);
7218 }
Jake Hamby7c27be32014-03-03 13:25:59 -08007219 }
7220
7221 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007222 * Get the allowed network types for certain reason.
7223 *
7224 * @param subId the id of the subscription.
7225 * @param reason the reason the allowed network type change is taking place
7226 * @return the allowed network types.
7227 */
7228 @Override
7229 public long getAllowedNetworkTypesForReason(int subId,
7230 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07007231 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007232 mApp, subId, "getAllowedNetworkTypesForReason");
joonhunshin4ac60942023-11-15 15:23:39 +00007233
7234 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7235 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesForReason");
7236
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007237 final long identity = Binder.clearCallingIdentity();
7238 try {
Jack Yu7247ac82023-03-02 23:52:10 -08007239 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007240 } finally {
7241 Binder.restoreCallingIdentity(identity);
7242 }
7243 }
7244
7245 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07007246 * Enable/Disable E-UTRA-NR Dual Connectivity
7247 * @param subId subscription id of the sim card
7248 * @param nrDualConnectivityState expected NR dual connectivity state
7249 * This can be passed following states
7250 * <ol>
7251 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
7252 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
7253 * <li>Disable NR dual connectivity and force secondary cell to be released
7254 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
7255 * </ol>
7256 * @return operation result.
7257 */
7258 @Override
7259 public int setNrDualConnectivityState(int subId,
7260 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
7261 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7262 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007263 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007264 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7265 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
7266 }
7267
Sooraj Sasindran37444802020-08-11 10:40:43 -07007268 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7269 final long identity = Binder.clearCallingIdentity();
7270 try {
7271 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
7272 nrDualConnectivityState, subId,
7273 workSource);
7274 if (DBG) log("enableNRDualConnectivity result: " + result);
7275 return result;
7276 } finally {
7277 Binder.restoreCallingIdentity(identity);
7278 }
7279 }
7280
7281 /**
7282 * Is E-UTRA-NR Dual Connectivity enabled
7283 * @return true if dual connectivity is enabled else false
7284 */
7285 @Override
7286 public boolean isNrDualConnectivityEnabled(int subId) {
7287 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007288 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07007289 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007290 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007291 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7292 return false;
7293 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07007294 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7295 final long identity = Binder.clearCallingIdentity();
7296 try {
7297 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
7298 null, subId, workSource);
7299 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
7300 return isEnabled;
7301 } finally {
7302 Binder.restoreCallingIdentity(identity);
7303 }
7304 }
7305
7306 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007307 * Set the allowed network types of the device and
7308 * provide the reason triggering the allowed network change.
7309 *
7310 * @param subId the id of the subscription.
7311 * @param reason the reason the allowed network type change is taking place
7312 * @param allowedNetworkTypes the allowed network types.
7313 * @return true on success; false on any failure.
7314 */
7315 @Override
7316 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08007317 @TelephonyManager.AllowedNetworkTypesReason int reason,
7318 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007319 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7320 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007321 // If the caller only has carrier privileges, then they should not be able to override
7322 // any network types which were set for security reasons.
7323 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
7324 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007325 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007326 throw new SecurityException(
7327 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007328 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007329 }
joonhunshin4ac60942023-11-15 15:23:39 +00007330
7331 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7332 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason");
7333
SongFerngWang3ef3e072020-12-21 16:41:52 +08007334 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007335 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08007336 return false;
7337 }
7338 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
7339 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007340 return false;
7341 }
7342
Jack Yu5b494332023-01-23 18:18:04 +00007343 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
7344 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007345
Jack Yue37dd262022-12-16 11:53:37 -08007346 Phone phone = getPhone(subId);
7347 if (phone == null) {
7348 return false;
7349 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007350
Jack Yue37dd262022-12-16 11:53:37 -08007351 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007352 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007353 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08007354 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007355
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007356 final long identity = Binder.clearCallingIdentity();
7357 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007358 Boolean success = (Boolean) sendRequest(
7359 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
7360 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
7361
7362 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
7363 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007364 } finally {
7365 Binder.restoreCallingIdentity(identity);
7366 }
7367 }
7368
7369 /**
Miaoa84611c2019-03-15 09:21:10 +08007370 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08007371 *
Miaoa84611c2019-03-15 09:21:10 +08007372 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07007373 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08007374 * @hide
7375 */
7376 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08007377 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007378 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007379
7380 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7381 PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber");
7382
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007383 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08007384 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007385 try {
Miaoa84611c2019-03-15 09:21:10 +08007386 if (phone != null) {
7387 return phone.hasMatchedTetherApnSetting();
7388 } else {
7389 return false;
7390 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007391 } finally {
7392 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007393 }
Junda Liu475951f2014-11-07 16:45:03 -08007394 }
7395
7396 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007397 * Get the user enabled state of Mobile Data.
7398 *
7399 * TODO: remove and use isUserDataEnabled.
7400 * This can't be removed now because some vendor codes
7401 * calls through ITelephony directly while they should
7402 * use TelephonyManager.
7403 *
7404 * @return true on enabled
7405 */
7406 @Override
7407 public boolean getDataEnabled(int subId) {
7408 return isUserDataEnabled(subId);
7409 }
7410
7411 /**
7412 * Get whether mobile data is enabled per user setting.
7413 *
7414 * There are other factors deciding whether mobile data is actually enabled, but they are
7415 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007416 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007417 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7418 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007419 *
7420 * @return {@code true} if data is enabled else {@code false}
7421 */
7422 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007423 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007424 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007425 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007426 try {
7427 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7428 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007429 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007430 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7431 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007432 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007433 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007434 mApp, subId, functionName);
7435
Robert Greenwalt646120a2014-05-23 11:54:03 -07007436 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007437
7438 final long identity = Binder.clearCallingIdentity();
7439 try {
Jack Yu285100e2022-12-02 22:48:35 -08007440 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007441 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7442 Phone phone = PhoneFactory.getPhone(phoneId);
7443 if (phone != null) {
7444 boolean retVal = phone.isUserDataEnabled();
7445 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7446 return retVal;
7447 } else {
7448 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7449 return false;
7450 }
7451 } finally {
7452 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007453 }
7454 }
7455
7456 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007457 * Checks if the device is capable of mobile data by considering whether whether the
7458 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7459 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007460 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007461 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007462 */
7463 @Override
7464 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007465 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007466 try {
7467 try {
7468 mApp.enforceCallingOrSelfPermission(
7469 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007470 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007471 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007472 try {
7473 mApp.enforceCallingOrSelfPermission(
7474 android.Manifest.permission.READ_PHONE_STATE,
7475 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007476 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007477 mApp.enforceCallingOrSelfPermission(
7478 permission.READ_BASIC_PHONE_STATE, functionName);
7479 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007480 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007481 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007482 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007483 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007484
joonhunshin4ac60942023-11-15 15:23:39 +00007485 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7486 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled");
7487
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007488 final long identity = Binder.clearCallingIdentity();
7489 try {
Jack Yu285100e2022-12-02 22:48:35 -08007490 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007491 Phone phone = PhoneFactory.getPhone(phoneId);
7492 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007493 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007494 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007495 return retVal;
7496 } else {
7497 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7498 return false;
7499 }
7500 } finally {
7501 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007502 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007503 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007504
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007505 /**
7506 * Check if data is enabled for a specific reason
7507 * @param subId Subscription index
7508 * @param reason the reason the data enable change is taking place
7509 * @return {@code true} if the overall data is enabled; {@code false} if not.
7510 */
7511 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007512 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007513 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007514 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007515 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007516 try {
7517 mApp.enforceCallingOrSelfPermission(
7518 android.Manifest.permission.ACCESS_NETWORK_STATE,
7519 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007520 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007521 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7522 functionName);
7523 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007524 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007525 try {
7526 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007527 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007528 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007529 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007530 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007531 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007532 }
7533
joonhunshin4ac60942023-11-15 15:23:39 +00007534 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7535 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007536
7537 final long identity = Binder.clearCallingIdentity();
7538 try {
Jack Yu285100e2022-12-02 22:48:35 -08007539 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007540 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007541 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007542 + " reason=" + reason);
7543 }
7544 Phone phone = PhoneFactory.getPhone(phoneId);
7545 if (phone != null) {
7546 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007547 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007548 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007549 return retVal;
7550 } else {
7551 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007552 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007553 + subId + " retVal=false");
7554 }
7555 return false;
7556 }
7557 } finally {
7558 Binder.restoreCallingIdentity(identity);
7559 }
7560 }
7561
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007562 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007563 public int getCarrierPrivilegeStatus(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00007564 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7565 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus");
7566
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007567 // No permission needed; this only lets the caller inspect their own status.
7568 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007569 }
Junda Liu29340342014-07-10 15:23:27 -07007570
7571 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007572 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007573 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
joonhunshin4ac60942023-11-15 15:23:39 +00007574
7575 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7576 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatusForUid");
7577
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007578 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7579 }
7580
7581 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7582 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007583 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007584 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007585 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7586 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007587 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7588 if (cpt == null) {
7589 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007590 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7591 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007592 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007593 }
7594
7595 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007596 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007597 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
joonhunshin4ac60942023-11-15 15:23:39 +00007598
7599 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7600 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage");
7601
chen xuf7e9fe82019-05-09 19:31:02 -07007602 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007603 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007604 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007605 Phone phone = getPhone(subId);
7606 if (phone == null) {
7607 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7608 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7609 }
7610 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7611 if (cpt == null) {
7612 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007613 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7614 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007615 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007616 }
7617
7618 @Override
7619 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007620 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007621
7622 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7623 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7624 "checkCarrierPrivilegesForPackageAnyPhone");
7625
Rambo Wange7209ce2022-02-23 13:41:02 -08007626 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7627 }
7628
7629 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007630 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007631 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007632 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007633 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007634 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7635 Phone phone = PhoneFactory.getPhone(phoneId);
7636 if (phone == null) {
7637 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007638 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007639 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7640 if (cpt == null) {
7641 continue;
7642 }
7643 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007644 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7645 break;
7646 }
7647 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007648 return result;
Junda Liu29340342014-07-10 15:23:27 -07007649 }
Derek Tan89e89d42014-07-08 17:00:10 -07007650
7651 @Override
Junda Liue64de782015-04-16 17:19:16 -07007652 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007653 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007654
7655 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7656 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7657 "getCarrierPackageNamesForIntentAndPhone");
7658
Rambo Wang8a247eb2022-02-08 21:11:18 +00007659 Phone phone = PhoneFactory.getPhone(phoneId);
7660 if (phone == null) {
7661 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007662 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007663 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7664 if (cpt == null) {
7665 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007666 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007667 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007668 }
7669
Amith Yamasani6e118872016-02-19 12:53:51 -08007670 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007671 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007672 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007673 Phone phone = PhoneFactory.getPhone(phoneId);
7674 if (phone == null) {
7675 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007676 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007677 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7678 if (cpt == null) {
7679 return Collections.emptyList();
7680 }
7681 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007682 }
7683
chen xuf7e9fe82019-05-09 19:31:02 -07007684 @Override
7685 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007686 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
joonhunshin4ac60942023-11-15 15:23:39 +00007687
7688 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7689 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7690 "getPackagesWithCarrierPrivilegesForAllPhones");
7691
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007692 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007693 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007694 try {
7695 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7696 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7697 }
7698 } finally {
7699 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007700 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007701 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007702 }
7703
Rambo Wang6812ffb2022-03-15 16:54:17 -07007704 @Override
7705 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7706 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7707
joonhunshin4ac60942023-11-15 15:23:39 +00007708 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7709 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7710 "getCarrierServicePackageNameForLogicalSlot");
7711
Rambo Wang6812ffb2022-03-15 16:54:17 -07007712 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7713 if (phone == null) {
7714 return null;
7715 }
7716 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7717 if (cpt == null) {
7718 return null;
7719 }
7720 return cpt.getCarrierServicePackageName();
7721 }
7722
Wink Savilleb564aae2014-10-23 10:18:09 -07007723 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007724 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007725 UiccPort port = phone == null ? null : phone.getUiccPort();
7726 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007727 return null;
7728 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007729 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007730 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007731 return null;
7732 }
7733 return iccId;
7734 }
7735
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007736 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007737 public void setCallComposerStatus(int subId, int status) {
7738 enforceModifyPermission();
7739
joonhunshin4ac60942023-11-15 15:23:39 +00007740 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7741 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus");
7742
Shuo Qiane4e11672020-12-15 22:15:33 -08007743 final long identity = Binder.clearCallingIdentity();
7744 try {
7745 Phone phone = getPhone(subId);
7746 if (phone != null) {
7747 Phone defaultPhone = phone.getImsPhone();
7748 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7749 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7750 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007751 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7752 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007753 }
7754 }
Shuo Qian284ae752020-12-22 19:10:14 -08007755 } catch (ImsException e) {
7756 throw new ServiceSpecificException(e.getCode());
7757 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007758 Binder.restoreCallingIdentity(identity);
7759 }
7760 }
7761
7762 @Override
7763 public int getCallComposerStatus(int subId) {
7764 enforceReadPrivilegedPermission("getCallComposerStatus");
7765
joonhunshin4ac60942023-11-15 15:23:39 +00007766 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7767 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus");
7768
Shuo Qiane4e11672020-12-15 22:15:33 -08007769 final long identity = Binder.clearCallingIdentity();
7770 try {
7771 Phone phone = getPhone(subId);
7772 if (phone != null) {
7773 Phone defaultPhone = phone.getImsPhone();
7774 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7775 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7776 return imsPhone.getCallComposerStatus();
7777 }
7778 }
7779 } finally {
7780 Binder.restoreCallingIdentity(identity);
7781 }
7782 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7783 }
7784
7785 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007786 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7787 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007788 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007789 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007790
joonhunshin4ac60942023-11-15 15:23:39 +00007791 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7792 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7793 "setLine1NumberForDisplayForSubscriber");
7794
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007795 final long identity = Binder.clearCallingIdentity();
7796 try {
7797 final String iccId = getIccId(subId);
7798 final Phone phone = getPhone(subId);
7799 if (phone == null) {
7800 return false;
7801 }
7802 final String subscriberId = phone.getSubscriberId();
7803
7804 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007805 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007806 + subscriberId + " to " + number);
7807 }
7808
7809 if (TextUtils.isEmpty(iccId)) {
7810 return false;
7811 }
7812
7813 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7814
7815 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7816 if (alphaTag == null) {
7817 editor.remove(alphaTagPrefKey);
7818 } else {
7819 editor.putString(alphaTagPrefKey, alphaTag);
7820 }
7821
7822 // Record both the line number and IMSI for this ICCID, since we need to
7823 // track all merged IMSIs based on line number
7824 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7825 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7826 if (number == null) {
7827 editor.remove(numberPrefKey);
7828 editor.remove(subscriberPrefKey);
7829 } else {
7830 editor.putString(numberPrefKey, number);
7831 editor.putString(subscriberPrefKey, subscriberId);
7832 }
7833
7834 editor.commit();
7835 return true;
7836 } finally {
7837 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007838 }
Derek Tan7226c842014-07-02 17:42:23 -07007839 }
7840
7841 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007842 public String getLine1NumberForDisplay(int subId, String callingPackage,
7843 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007844 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007845 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007846 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007847 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007848 return null;
7849 }
Derek Tan97ebb422014-09-05 16:55:38 -07007850
joonhunshin4ac60942023-11-15 15:23:39 +00007851 enforceTelephonyFeatureWithException(callingPackage,
7852 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay");
7853
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007854 final long identity = Binder.clearCallingIdentity();
7855 try {
7856 String iccId = getIccId(subId);
7857 if (iccId != null) {
7858 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7859 if (DBG_MERGE) {
7860 log("getLine1NumberForDisplay returning "
7861 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7862 }
7863 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007864 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007865 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7866 return null;
7867 } finally {
7868 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007869 }
Derek Tan7226c842014-07-02 17:42:23 -07007870 }
7871
7872 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007873 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7874 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007875 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007876 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007877 return null;
7878 }
Derek Tan97ebb422014-09-05 16:55:38 -07007879
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007880 final long identity = Binder.clearCallingIdentity();
7881 try {
7882 String iccId = getIccId(subId);
7883 if (iccId != null) {
7884 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7885 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7886 }
7887 return null;
7888 } finally {
7889 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007890 }
Derek Tan7226c842014-07-02 17:42:23 -07007891 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007892
7893 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007894 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7895 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007896 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7897 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007898 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007899 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007900 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007901 return null;
7902 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007903
Jordan Liub49b04b2019-05-06 14:45:15 -07007904 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7905 // the process, where TelephonyManager was instantiated.
7906 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007907 final long identity = Binder.clearCallingIdentity();
7908 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007909 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007910 final TelephonyManager tele = TelephonyManager.from(context);
7911 final SubscriptionManager sub = SubscriptionManager.from(context);
7912
7913 // Figure out what subscribers are currently active
7914 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007915
Jordan Liub49b04b2019-05-06 14:45:15 -07007916 // Only consider subs which match the current subId
7917 // This logic can be simplified. See b/131189269 for progress.
7918 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007919 activeSubscriberIds.add(tele.getSubscriberId(subId));
7920 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007921
7922 // First pass, find a number override for an active subscriber
7923 String mergeNumber = null;
7924 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7925 for (String key : prefs.keySet()) {
7926 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7927 final String subscriberId = (String) prefs.get(key);
7928 if (activeSubscriberIds.contains(subscriberId)) {
7929 final String iccId = key.substring(
7930 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7931 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7932 mergeNumber = (String) prefs.get(numberKey);
7933 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007934 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007935 + " for active subscriber " + subscriberId);
7936 }
7937 if (!TextUtils.isEmpty(mergeNumber)) {
7938 break;
7939 }
7940 }
7941 }
7942 }
7943
7944 // Shortcut when no active merged subscribers
7945 if (TextUtils.isEmpty(mergeNumber)) {
7946 return null;
7947 }
7948
7949 // Second pass, find all subscribers under that line override
7950 final ArraySet<String> result = new ArraySet<>();
7951 for (String key : prefs.keySet()) {
7952 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7953 final String number = (String) prefs.get(key);
7954 if (mergeNumber.equals(number)) {
7955 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7956 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7957 final String subscriberId = (String) prefs.get(subscriberKey);
7958 if (!TextUtils.isEmpty(subscriberId)) {
7959 result.add(subscriberId);
7960 }
7961 }
7962 }
7963 }
7964
7965 final String[] resultArray = result.toArray(new String[result.size()]);
7966 Arrays.sort(resultArray);
7967 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007968 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007969 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7970 }
7971 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007972 } finally {
7973 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007974 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007975 }
7976
7977 @Override
zoey chen38003472019-12-13 17:16:31 +08007978 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7979 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007980
joonhunshin4ac60942023-11-15 15:23:39 +00007981 enforceTelephonyFeatureWithException(callingPackage,
7982 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup");
7983
Malcolm Chen6ca97372019-07-01 16:28:21 -07007984 final long identity = Binder.clearCallingIdentity();
7985 try {
7986 final TelephonyManager telephonyManager = mApp.getSystemService(
7987 TelephonyManager.class);
7988 String subscriberId = telephonyManager.getSubscriberId(subId);
7989 if (subscriberId == null) {
7990 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007991 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007992 + subId);
7993 }
7994 return null;
7995 }
7996
Jack Yu3beaf9d2023-04-14 09:17:27 -07007997 final SubscriptionInfo info = getSubscriptionManagerService()
7998 .getSubscriptionInfo(subId);
7999 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07008000 // If it doesn't belong to any group, return just subscriberId of itself.
8001 if (groupUuid == null) {
8002 return new String[]{subscriberId};
8003 }
8004
8005 // Get all subscriberIds from the group.
8006 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07008007 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
8008 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
8009 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07008010 for (SubscriptionInfo subInfo : groupInfos) {
8011 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
8012 if (subscriberId != null) {
8013 mergedSubscriberIds.add(subscriberId);
8014 }
8015 }
8016
8017 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
8018 } finally {
8019 Binder.restoreCallingIdentity(identity);
8020
8021 }
8022 }
8023
8024 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008025 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008026 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08008027 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008028
joonhunshin4ac60942023-11-15 15:23:39 +00008029 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8030 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride");
8031
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008032 final long identity = Binder.clearCallingIdentity();
8033 try {
8034 final Phone phone = getPhone(subId);
8035 return phone == null ? false : phone.setOperatorBrandOverride(brand);
8036 } finally {
8037 Binder.restoreCallingIdentity(identity);
8038 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07008039 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05008040
8041 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008042 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008043 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
8044 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008045 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
8046 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008047
8048 final long identity = Binder.clearCallingIdentity();
8049 try {
8050 final Phone phone = getPhone(subId);
8051 if (phone == null) {
8052 return false;
8053 }
8054 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
8055 cdmaNonRoamingList);
8056 } finally {
8057 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008058 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008059 }
8060
8061 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07008062 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008063 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08008064 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008065 if (phone == null) {
8066 return raf;
8067 }
8068
Shuo Qiandee53402020-05-29 14:08:15 -07008069 try {
8070 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008071 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07008072 mApp, phone.getSubId(), "getRadioAccessFamily");
8073 } catch (SecurityException e) {
8074 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
8075 throw e;
8076 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008077
joonhunshin4ac60942023-11-15 15:23:39 +00008078 enforceTelephonyFeatureWithException(callingPackage,
8079 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily");
8080
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008081 final long identity = Binder.clearCallingIdentity();
8082 try {
chen xub97461a2018-10-26 14:17:57 -07008083 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008084 } finally {
8085 Binder.restoreCallingIdentity(identity);
8086 }
chen xub97461a2018-10-26 14:17:57 -07008087 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07008088 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008089
8090 @Override
Hall Liu82694d52020-12-11 18:22:04 -08008091 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08008092 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08008093 try {
8094 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
8095 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008096 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008097 }
8098 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008099 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008100 }
joonhunshin4ac60942023-11-15 15:23:39 +00008101
8102 enforceTelephonyFeatureWithException(callingPackage,
8103 PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture");
8104
Hall Liu82694d52020-12-11 18:22:04 -08008105 RoleManager rm = mApp.getSystemService(RoleManager.class);
8106 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
8107 if (!dialerRoleHolders.contains(callingPackage)) {
8108 throw new SecurityException("App must be the dialer role holder to"
8109 + " upload a call composer pic");
8110 }
8111
8112 Executors.newSingleThreadExecutor().execute(() -> {
8113 ByteArrayOutputStream output = new ByteArrayOutputStream(
8114 (int) TelephonyManager.getMaximumCallComposerPictureSize());
8115 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
8116 boolean readUntilEnd = false;
8117 int totalBytesRead = 0;
8118 byte[] buffer = new byte[16 * 1024];
8119 while (true) {
8120 int numRead;
8121 try {
8122 numRead = input.read(buffer);
8123 } catch (IOException e) {
8124 try {
8125 fd.checkError();
8126 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
8127 null);
8128 } catch (IOException e1) {
8129 // This means that the other side closed explicitly with an error. If this
8130 // happens, log and ignore.
8131 loge("Remote end of call composer picture pipe closed: " + e1);
8132 }
8133 break;
8134 }
8135 if (numRead == -1) {
8136 readUntilEnd = true;
8137 break;
8138 }
8139 totalBytesRead += numRead;
8140 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
8141 loge("Too many bytes read for call composer picture: " + totalBytesRead);
8142 try {
8143 input.close();
8144 } catch (IOException e) {
8145 // ignore
8146 }
8147 break;
8148 }
8149 output.write(buffer, 0, numRead);
8150 }
8151 // Generally, the remote end will close the file descriptors. The only case where we
8152 // close is above, where the picture size is too big.
8153
8154 try {
8155 fd.checkError();
8156 } catch (IOException e) {
8157 loge("Remote end for call composer closed with an error: " + e);
8158 return;
8159 }
8160
Hall Liuaa4211e2021-01-20 15:43:39 -08008161 if (!readUntilEnd) {
8162 loge("Did not finish reading entire image; aborting");
8163 return;
8164 }
Hall Liu82694d52020-12-11 18:22:04 -08008165
Hall Liuaa4211e2021-01-20 15:43:39 -08008166 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
8167 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
8168 new CallComposerPictureTransfer.Factory() {},
8169 imageData,
8170 (result) -> {
8171 if (result.first != null) {
8172 ParcelUuid parcelUuid = new ParcelUuid(result.first);
8173 Bundle outputResult = new Bundle();
8174 outputResult.putParcelable(
8175 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
8176 callback.send(TelephonyManager.CallComposerException.SUCCESS,
8177 outputResult);
8178 } else {
8179 callback.send(result.second, null);
8180 }
8181 }
8182 );
Hall Liu82694d52020-12-11 18:22:04 -08008183 });
8184 }
8185
8186 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07008187 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008188 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07008189 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008190
joonhunshin4ac60942023-11-15 15:23:39 +00008191 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8192 PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling");
8193
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008194 final long identity = Binder.clearCallingIdentity();
8195 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008196 ImsManager.getInstance(defaultPhone.getContext(),
8197 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008198 } finally {
8199 Binder.restoreCallingIdentity(identity);
8200 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008201 }
8202
8203 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008204 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008205 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008206 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
8207 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00008208 return false;
8209 }
Svet Ganovb320e182015-04-16 12:30:10 -07008210
joonhunshin4ac60942023-11-15 15:23:39 +00008211 enforceTelephonyFeatureWithException(callingPackage,
8212 PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled");
8213
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008214 final long identity = Binder.clearCallingIdentity();
8215 try {
8216 // Check the user preference and the system-level IMS setting. Even if the user has
8217 // enabled video calling, if IMS is disabled we aren't able to support video calling.
8218 // In the long run, we may instead need to check if there exists a connection service
8219 // which can support video calling.
8220 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008221 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008222 return imsManager.isVtEnabledByPlatform()
8223 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
8224 && imsManager.isVtEnabledByUser();
8225 } finally {
8226 Binder.restoreCallingIdentity(identity);
8227 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008228 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06008229
Andrew Leea1239f22015-03-02 17:44:07 -08008230 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008231 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
8232 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008233 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008234 mApp, subId, callingPackage, callingFeatureId,
8235 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008236 return false;
8237 }
8238
joonhunshin4ac60942023-11-15 15:23:39 +00008239 enforceTelephonyFeatureWithException(callingPackage,
8240 PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength");
8241
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008242 final long identity = Binder.clearCallingIdentity();
8243 try {
8244 CarrierConfigManager configManager =
8245 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008246 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008247 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
8248 } finally {
8249 Binder.restoreCallingIdentity(identity);
8250 }
Andrew Leea1239f22015-03-02 17:44:07 -08008251 }
8252
8253 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008254 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008255 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008256 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008257 return false;
8258 }
8259
joonhunshin4ac60942023-11-15 15:23:39 +00008260 enforceTelephonyFeatureWithException(callingPackage,
8261 PackageManager.FEATURE_TELEPHONY, "isWorldPhone");
8262
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008263 final long identity = Binder.clearCallingIdentity();
8264 try {
8265 CarrierConfigManager configManager =
8266 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008267 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008268 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
8269 } finally {
8270 Binder.restoreCallingIdentity(identity);
8271 }
Andrew Leea1239f22015-03-02 17:44:07 -08008272 }
8273
Andrew Lee9431b832015-03-09 18:46:45 -07008274 @Override
8275 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008276 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08008277 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07008278 }
8279
8280 @Override
8281 public boolean isHearingAidCompatibilitySupported() {
joonhunshin4ac60942023-11-15 15:23:39 +00008282 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8283 PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported");
8284
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008285 final long identity = Binder.clearCallingIdentity();
8286 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008287 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008288 } finally {
8289 Binder.restoreCallingIdentity(identity);
8290 }
Andrew Lee9431b832015-03-09 18:46:45 -07008291 }
8292
Hall Liuf6668912018-10-31 17:05:23 -07008293 /**
8294 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
8295 * support for the feature and device firmware support.
8296 *
8297 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
8298 */
8299 @Override
8300 public boolean isRttSupported(int subscriptionId) {
joonhunshin4ac60942023-11-15 15:23:39 +00008301 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8302 PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported");
8303
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008304 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008305 final Phone phone = getPhone(subscriptionId);
8306 if (phone == null) {
8307 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
8308 return false;
8309 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008310 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008311 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008312 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
joonhunshin4ac60942023-11-15 15:23:39 +00008313 boolean isDeviceSupported = (phone.getContext().getResources() != null)
8314 ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt)
8315 : false;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008316 return isCarrierSupported && isDeviceSupported;
8317 } finally {
8318 Binder.restoreCallingIdentity(identity);
8319 }
Hall Liu98187582018-01-22 19:15:32 -08008320 }
8321
Hall Liuf6668912018-10-31 17:05:23 -07008322 /**
Hall Liuf2daa022019-07-23 18:39:00 -07008323 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
8324 * RTT setting, will return true if the device and carrier both support RTT.
8325 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07008326 */
8327 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008328 final long identity = Binder.clearCallingIdentity();
8329 try {
joonhunshin4ac60942023-11-15 15:23:39 +00008330 if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) {
8331 if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
8332 return false;
8333 }
8334 }
8335
Hall Liu5bab75c2019-12-11 23:58:20 +00008336 boolean isRttSupported = isRttSupported(subscriptionId);
8337 boolean isUserRttSettingOn = Settings.Secure.getInt(
8338 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
8339 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
8340 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
8341 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008342 } finally {
8343 Binder.restoreCallingIdentity(identity);
8344 }
Hall Liu3ad5f012018-04-06 16:23:39 -07008345 }
8346
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008347 @Deprecated
8348 @Override
8349 public String getDeviceId(String callingPackage) {
8350 return getDeviceIdWithFeature(callingPackage, null);
8351 }
8352
Sanket Padawe7310cc72015-01-14 09:53:20 -08008353 /**
8354 * Returns the unique device ID of phone, for example, the IMEI for
8355 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
8356 *
8357 * <p>Requires Permission:
8358 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
8359 */
8360 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008361 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07008362 try {
8363 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
8364 } catch (SecurityException se) {
8365 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
8366 throw new SecurityException("Package " + callingPackage + " does not belong to "
8367 + Binder.getCallingUid());
8368 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008369 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008370 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008371 return null;
8372 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008373 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008374 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008375 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008376 return null;
8377 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008378
8379 final long identity = Binder.clearCallingIdentity();
8380 try {
8381 return phone.getDeviceId();
8382 } finally {
8383 Binder.restoreCallingIdentity(identity);
8384 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008385 }
8386
Ping Sunc67b7c22016-03-02 19:16:45 +08008387 /**
8388 * {@hide}
8389 * Returns the IMS Registration Status on a particular subid
8390 *
8391 * @param subId
8392 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008393 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008394 Phone phone = getPhone(subId);
8395 if (phone != null) {
8396 return phone.isImsRegistered();
8397 } else {
8398 return false;
8399 }
8400 }
8401
Santos Cordon7a1885b2015-02-03 11:15:19 -08008402 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008403 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008404 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008405 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008406 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008407 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8408 }
8409 final long identity = Binder.clearCallingIdentity();
8410 try {
8411 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8412 } finally {
8413 Binder.restoreCallingIdentity(identity);
8414 }
8415 }
8416
8417 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008418 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008419 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008420 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008421 mApp,
8422 subscriptionId,
8423 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
8424 + subscriptionId);
joonhunshin4ac60942023-11-15 15:23:39 +00008425
8426 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8427 PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId");
8428
Tyler Gunnf70ed162019-04-03 15:28:53 -07008429 final long identity = Binder.clearCallingIdentity();
8430 try {
8431 Phone phone = getPhone(subscriptionId);
8432 if (phone == null) {
8433 return null;
8434 }
8435 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8436 } finally {
8437 Binder.restoreCallingIdentity(identity);
8438 }
8439 }
8440
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008441 /**
8442 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008443 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008444 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008445 final long identity = Binder.clearCallingIdentity();
8446 try {
8447 Phone phone = getPhone(subId);
8448 if (phone != null) {
8449 return phone.isWifiCallingEnabled();
8450 } else {
8451 return false;
8452 }
8453 } finally {
8454 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008455 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008456 }
8457
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008458 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008459 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008460 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008461 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008462 final long identity = Binder.clearCallingIdentity();
8463 try {
8464 Phone phone = getPhone(subId);
8465 if (phone != null) {
8466 return phone.isVideoEnabled();
8467 } else {
8468 return false;
8469 }
8470 } finally {
8471 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008472 }
8473 }
8474
8475 /**
8476 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8477 * defined in {@link ImsRegistrationImplBase}.
8478 */
8479 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008480 final long identity = Binder.clearCallingIdentity();
8481 try {
8482 Phone phone = getPhone(subId);
8483 if (phone != null) {
8484 return phone.getImsRegistrationTech();
8485 } else {
8486 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8487 }
8488 } finally {
8489 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008490 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008491 }
8492
Stuart Scott8eef64f2015-04-08 15:13:54 -07008493 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008494 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008495 enforceSettingsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008496
8497 enforceTelephonyFeatureWithException(callingPackage,
8498 PackageManager.FEATURE_TELEPHONY, "factoryReset");
8499
Stuart Scott981d8582015-04-21 14:09:50 -07008500 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8501 return;
8502 }
Kai Shif70f46f2021-03-03 13:59:46 -08008503 Phone defaultPhone = getDefaultPhone();
8504 if (defaultPhone != null) {
8505 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8506 mApp, getDefaultPhone().getSubId(), "factoryReset");
8507 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008508 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008509
Svet Ganovcc087f82015-05-12 20:35:54 -07008510 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008511 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8512 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008513 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008514 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008515 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008516 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008517 cleanUpAllowedNetworkTypes(phone, subId);
Rambo Wang71f6aa62024-02-23 20:16:22 +00008518 setDataRoamingEnabled(subId, phone == null ? false
8519 : phone.getDataSettingsManager().isDefaultDataRoamingEnabled());
Jordan Liu857e73a2021-03-05 16:24:04 -08008520 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008521 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008522 // There has been issues when Sms raw table somehow stores orphan
8523 // fragments. They lead to garbled message when new fragments come
8524 // in and combined with those stale ones. In case this happens again,
8525 // user can reset all network settings which will clean up this table.
8526 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008527 // Clean up IMS settings as well here.
8528 int slotId = getSlotIndex(subId);
8529 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
8530 ImsManager.getInstance(mApp, slotId).factoryReset();
8531 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008532
Kai Shif70f46f2021-03-03 13:59:46 -08008533 if (defaultPhone == null) {
8534 return;
8535 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008536 // Erase modem config if erase modem on network setting is enabled.
8537 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8538 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8539 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008540 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008541 }
Kai Shif70f46f2021-03-03 13:59:46 -08008542
8543 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008544 } finally {
8545 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008546 }
8547 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008548
SongFerngWangfd89b102021-05-27 22:44:54 +08008549 @VisibleForTesting
8550 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8551 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8552 return;
8553 }
8554 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8555 RILConstants.PREFERRED_NETWORK_MODE);
8556 SubscriptionManager.setSubscriptionProperty(subId,
8557 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8558 "user=" + defaultNetworkType);
8559 phone.loadAllowedNetworksFromSubscriptionDatabase();
8560 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8561 defaultNetworkType, null);
8562 }
8563
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008564 private void cleanUpSmsRawTable(Context context) {
8565 ContentResolver resolver = context.getContentResolver();
8566 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8567 resolver.delete(uri, null, null);
8568 }
8569
Narayan Kamath1c496c22015-04-16 14:40:19 +01008570 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008571 public String getSimLocaleForSubscriber(int subId) {
8572 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
joonhunshin4ac60942023-11-15 15:23:39 +00008573
8574 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8575 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber");
8576
chen xu5d3637b2019-01-21 23:31:38 -08008577 final Phone phone = getPhone(subId);
8578 if (phone == null) {
8579 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008580 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008581 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008582 final long identity = Binder.clearCallingIdentity();
8583 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008584 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
8585 phone.getContext().getOpPackageName(),
8586 phone.getContext().getAttributionTag());
8587 if (info == null) {
8588 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8589 return null;
chen xu6291c472019-02-04 12:55:53 -08008590 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008591 // Try and fetch the locale from the carrier properties or from the SIM language
8592 // preferences (EF-PL and EF-LI)...
8593 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008594 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008595 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8596 if (localeFromDefaultSim != null) {
8597 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8598 if (DBG) log("Using locale from subId: " + subId + " locale: "
8599 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008600 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008601 } else {
8602 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008603 }
8604 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008605
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008606 // The SIM language preferences only store a language (e.g. fr = French), not an
8607 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8608 // the SIM and carrier preferences does not include a country we add the country
8609 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008610 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008611 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008612 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008613 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008614 }
8615
8616 if (DBG) log("No locale found - returning null");
8617 return null;
8618 } finally {
8619 Binder.restoreCallingIdentity(identity);
8620 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008621 }
8622
tom hsu0b59d292022-09-29 23:49:21 +08008623 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008624 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008625 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008626 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008627 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008628 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8629 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008630 Locale.forLanguageTag(localeTag).getCountry())) {
8631 return localeTag;
8632 }
8633 }
8634 return inputLocale.toLanguageTag();
8635 }
8636
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008637 /**
8638 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8639 */
8640 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008641 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Ling Ma9fa67412023-11-13 14:13:19 -08008642 mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/);
Narayan Kamath1c496c22015-04-16 14:40:19 +01008643 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008644
Gary Jian3aa9a762022-01-24 16:41:19 +08008645 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8646 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008647
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008648 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008649 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8650 * representing the state of the modem.
8651 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008652 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8653 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008654 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008655 */
8656 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008657 public void requestModemActivityInfo(ResultReceiver result) {
8658 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008659
8660 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8661 PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo");
8662
vagdeviaf9a5b92018-08-15 16:01:53 -07008663 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008664
8665 final long identity = Binder.clearCallingIdentity();
8666 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008667 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008668 } finally {
8669 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008670 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008671 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008672
Gary Jian76280a42022-12-07 16:18:33 +08008673 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008674 // less than total activity duration.
8675 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8676 if (info == null) {
8677 return false;
8678 }
8679 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008680 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008681 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8682
Hall Liu49656c02020-10-09 19:00:11 -07008683 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8684
Siddharth Rayb8114062018-06-17 15:02:38 -07008685 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008686 && (info.getSleepTimeMillis() <= activityDurationMs)
8687 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008688 }
8689
Gary Jian3aa9a762022-01-24 16:41:19 +08008690 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8691 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8692 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8693 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8694
8695 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8696 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8697 }
8698
8699 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8700 mLastModemActivityInfo.setReceiveTimeMillis(
8701 rat,
8702 freq,
8703 info.getReceiveTimeMillis(rat, freq)
8704 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8705 }
8706
8707 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8708 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8709 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8710 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8711
8712 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8713 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8714 }
8715 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8716 mLastModemActivityInfo.setReceiveTimeMillis(
8717 rat,
8718 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8719 }
8720
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008721 /**
8722 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8723 * @param info recent ModemActivityInfo
8724 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008725 private void mergeModemActivityInfo(ModemActivityInfo info) {
8726 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008727 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008728 boolean matched;
8729 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8730 matched = false;
8731 int rat = info.getSpecificInfoRat(i);
8732 int freq = info.getSpecificInfoFrequencyRange(i);
8733 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8734 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8735 //if it already exists
8736 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8737 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8738 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8739 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8740 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8741 updateLastModemActivityInfo(info, rat, freq);
8742 matched = true;
8743 }
8744 } else {
8745 updateLastModemActivityInfo(info, rat);
8746 matched = true;
8747 }
8748 }
8749 }
8750
8751 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008752 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008753 new ActivityStatsTechSpecificInfo(
8754 rat,
8755 freq,
8756 info.getTransmitTimeMillis(rat, freq),
8757 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008758 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008759 }
8760 }
8761 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8762 mLastModemActivitySpecificInfo =
8763 new ActivityStatsTechSpecificInfo[merged.size()];
8764 merged.toArray(mLastModemActivitySpecificInfo);
8765
8766 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8767 mLastModemActivityInfo.setSleepTimeMillis(
8768 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008769 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008770 mLastModemActivityInfo.setIdleTimeMillis(
8771 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008772 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008773
8774 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008775 new ModemActivityInfo(
8776 mLastModemActivityInfo.getTimestampMillis(),
8777 mLastModemActivityInfo.getSleepTimeMillis(),
8778 mLastModemActivityInfo.getIdleTimeMillis(),
8779 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008780 }
8781
8782 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8783 ActivityStatsTechSpecificInfo[] info) {
8784 int infoSize = info.length;
8785 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8786 for (int i = 0; i < infoSize; i++) {
8787 ret[i] = new ActivityStatsTechSpecificInfo(
8788 info[i].getRat(), info[i].getFrequencyRange(),
8789 info[i].getTransmitTimeMillis(),
8790 (int) info[i].getReceiveTimeMillis());
8791 }
8792 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008793 }
8794
Jack Yu85bd38a2015-11-09 11:34:32 -08008795 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008796 * Returns the service state information on specified subscription.
8797 */
8798 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008799 public ServiceState getServiceStateForSubscriber(int subId,
8800 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8801 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008802 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008803 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008804 return null;
8805 }
8806
joonhunshin4ac60942023-11-15 15:23:39 +00008807 enforceTelephonyFeatureWithException(callingPackage,
8808 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber");
8809
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008810 boolean hasFinePermission = false;
8811 boolean hasCoarsePermission = false;
8812 if (!renounceFineLocationAccess) {
8813 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8814 LocationAccessPolicy.checkLocationPermission(mApp,
8815 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8816 .setCallingPackage(callingPackage)
8817 .setCallingFeatureId(callingFeatureId)
8818 .setCallingPid(Binder.getCallingPid())
8819 .setCallingUid(Binder.getCallingUid())
8820 .setMethod("getServiceStateForSubscriber")
8821 .setLogAsInfo(true)
8822 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8823 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8824 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8825 .build());
8826 hasFinePermission =
8827 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8828 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008829
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008830 if (!renounceCoarseLocationAccess) {
8831 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8832 LocationAccessPolicy.checkLocationPermission(mApp,
8833 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8834 .setCallingPackage(callingPackage)
8835 .setCallingFeatureId(callingFeatureId)
8836 .setCallingPid(Binder.getCallingPid())
8837 .setCallingUid(Binder.getCallingUid())
8838 .setMethod("getServiceStateForSubscriber")
8839 .setLogAsInfo(true)
8840 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8841 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8842 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8843 .build());
8844 hasCoarsePermission =
8845 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8846 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008847
Jack Yu479f40e2020-10-27 21:29:25 -07008848 final Phone phone = getPhone(subId);
8849 if (phone == null) {
8850 return null;
8851 }
8852
Jordan Liu0f2bc442020-11-18 16:47:37 -08008853 final long identity = Binder.clearCallingIdentity();
8854
Jack Yu479f40e2020-10-27 21:29:25 -07008855 boolean isCallingPackageDataService = phone.getDataServicePackages()
8856 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008857 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008858 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu3beaf9d2023-04-14 09:17:27 -07008859 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8860 .getSubscriptionInfoInternal(subId);
8861 if (subInfo == null || !subInfo.isActive()) {
8862 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8863 + "subId=" + subId);
8864 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008865 }
8866
Hall Liuf19c44f2018-11-27 14:38:17 -08008867 ServiceState ss = phone.getServiceState();
8868
8869 // Scrub out the location info in ServiceState depending on what level of access
8870 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008871 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008872 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8873 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008874 } finally {
8875 Binder.restoreCallingIdentity(identity);
8876 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008877 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008878
8879 /**
8880 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8881 *
8882 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8883 * voicemail ringtone.
8884 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8885 * PhoneAccount.
8886 */
8887 @Override
8888 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008889 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8890 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri");
8891
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008892 final long identity = Binder.clearCallingIdentity();
8893 try {
8894 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8895 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008896 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008897 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008898
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008899 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8900 } finally {
8901 Binder.restoreCallingIdentity(identity);
8902 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008903 }
8904
8905 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008906 * Sets the per-account voicemail ringtone.
8907 *
8908 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8909 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8910 *
8911 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8912 * voicemail ringtone.
8913 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8914 * PhoneAccount.
8915 */
8916 @Override
8917 public void setVoicemailRingtoneUri(String callingPackage,
8918 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008919 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008920 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008921 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8922 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008923 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8924 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8925 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008926 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008927
joonhunshin4ac60942023-11-15 15:23:39 +00008928 enforceTelephonyFeatureWithException(callingPackage,
8929 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri");
8930
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008931 final long identity = Binder.clearCallingIdentity();
8932 try {
8933 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8934 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008935 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008936 }
8937 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8938 } finally {
8939 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008940 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008941 }
8942
8943 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008944 * Returns whether vibration is set for voicemail notification in Phone settings.
8945 *
8946 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8947 * voicemail vibration setting.
8948 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8949 */
8950 @Override
8951 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008952 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8953 PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled");
8954
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008955 final long identity = Binder.clearCallingIdentity();
8956 try {
8957 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8958 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008959 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008960 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008961
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008962 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8963 } finally {
8964 Binder.restoreCallingIdentity(identity);
8965 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008966 }
8967
Youhan Wange64578a2016-05-02 15:32:42 -07008968 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008969 * Sets the per-account voicemail vibration.
8970 *
8971 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8972 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8973 *
8974 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8975 * voicemail vibration setting.
8976 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8977 * specific PhoneAccount.
8978 */
8979 @Override
8980 public void setVoicemailVibrationEnabled(String callingPackage,
8981 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008982 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008983 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008984 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8985 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008986 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8987 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8988 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008989 }
8990
joonhunshin4ac60942023-11-15 15:23:39 +00008991 enforceTelephonyFeatureWithException(callingPackage,
8992 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled");
8993
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008994 final long identity = Binder.clearCallingIdentity();
8995 try {
8996 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8997 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008998 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008999 }
9000 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
9001 } finally {
9002 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009003 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009004 }
9005
9006 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009007 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
9008 *
9009 * @throws SecurityException if the caller does not have the required permission
9010 */
arunvoddud7401012022-12-15 16:08:12 +00009011 @VisibleForTesting
9012 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07009013 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07009014 message);
Youhan Wange64578a2016-05-02 15:32:42 -07009015 }
9016
9017 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009018 * Make sure either called from same process as self (phone) or IPC caller has send SMS
9019 * permission.
9020 *
9021 * @throws SecurityException if the caller does not have the required permission
9022 */
9023 private void enforceSendSmsPermission() {
9024 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
9025 }
9026
9027 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00009028 * Make sure either called from same process as self (phone) or IPC caller has interact across
9029 * users permission.
9030 *
9031 * @throws SecurityException if the caller does not have the required permission
9032 */
9033 private void enforceInteractAcrossUsersPermission(String message) {
9034 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
9035 }
9036
9037 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009038 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009039 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009040 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009041 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009042 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009043 final long identity = Binder.clearCallingIdentity();
9044 try {
9045 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009046 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009047 if (componentName == null) {
9048 throw new SecurityException(
9049 "Caller not current active visual voicemail package[null]");
9050 }
9051 String vvmPackage = componentName.getPackageName();
9052 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00009053 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009054 }
9055 } finally {
9056 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009057 }
9058 }
9059
9060 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009061 * Return the application ID for the app type.
9062 *
9063 * @param subId the subscription ID that this request applies to.
9064 * @param appType the uicc app type.
9065 * @return Application ID for specificied app type, or null if no uicc.
9066 */
9067 @Override
9068 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009069 enforceReadPrivilegedPermission("getAidForAppType");
joonhunshin4ac60942023-11-15 15:23:39 +00009070
9071 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9072 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType");
9073
Youhan Wange64578a2016-05-02 15:32:42 -07009074 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009075
9076 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07009077 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009078 if (phone == null) {
9079 return null;
9080 }
9081 String aid = null;
9082 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009083 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009084 .getApplicationByType(appType).getAid();
9085 } catch (Exception e) {
9086 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
9087 }
9088 return aid;
9089 } finally {
9090 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07009091 }
Youhan Wange64578a2016-05-02 15:32:42 -07009092 }
9093
Youhan Wang4001d252016-05-11 10:29:41 -07009094 /**
9095 * Return the Electronic Serial Number.
9096 *
9097 * @param subId the subscription ID that this request applies to.
9098 * @return ESN or null if error.
9099 */
9100 @Override
9101 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009102 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07009103 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009104
9105 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07009106 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009107 if (phone == null) {
9108 return null;
9109 }
9110 String esn = null;
9111 try {
9112 esn = phone.getEsn();
9113 } catch (Exception e) {
9114 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
9115 }
9116 return esn;
9117 } finally {
9118 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07009119 }
Youhan Wang4001d252016-05-11 10:29:41 -07009120 }
9121
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009122 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009123 * Return the Preferred Roaming List Version.
9124 *
9125 * @param subId the subscription ID that this request applies to.
9126 * @return PRLVersion or null if error.
9127 */
9128 @Override
9129 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009130 enforceReadPrivilegedPermission("getCdmaPrlVersion");
joonhunshin4ac60942023-11-15 15:23:39 +00009131
9132 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9133 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion");
9134
Youhan Wang66ad5d72016-07-18 17:56:58 -07009135 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009136
9137 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009138 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009139 if (phone == null) {
9140 return null;
9141 }
9142 String cdmaPrlVersion = null;
9143 try {
9144 cdmaPrlVersion = phone.getCdmaPrlVersion();
9145 } catch (Exception e) {
9146 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9147 }
9148 return cdmaPrlVersion;
9149 } finally {
9150 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009151 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009152 }
9153
9154 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009155 * Get snapshot of Telephony histograms
9156 * @return List of Telephony histograms
9157 * @hide
9158 */
9159 @Override
9160 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009161 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9162 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009163
9164 final long identity = Binder.clearCallingIdentity();
9165 try {
9166 return RIL.getTelephonyRILTimingHistograms();
9167 } finally {
9168 Binder.restoreCallingIdentity(identity);
9169 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009170 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009171
9172 /**
9173 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009174 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9175 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009176 * Require system privileges. In the future we may add this to carrier APIs.
9177 *
Michele Berionne482f8202018-11-27 18:57:59 -08009178 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009179 */
9180 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009181 @TelephonyManager.SetCarrierRestrictionResult
9182 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009183 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009184
9185 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9186 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers");
9187
vagdeviaf9a5b92018-08-15 16:01:53 -07009188 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009189
Michele Berionne482f8202018-11-27 18:57:59 -08009190 if (carrierRestrictionRules == null) {
9191 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009192 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009193
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009194 final long identity = Binder.clearCallingIdentity();
9195 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009196 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009197 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009198 } finally {
9199 Binder.restoreCallingIdentity(identity);
9200 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009201 }
9202
9203 /**
9204 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009205 * Get the allowed carrier list and the excluded carrier list, including the priority between
9206 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009207 * Require system privileges. In the future we may add this to carrier APIs.
9208 *
Michele Berionne482f8202018-11-27 18:57:59 -08009209 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009210 */
9211 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009212 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009213 enforceReadPrivilegedPermission("getAllowedCarriers");
joonhunshin4ac60942023-11-15 15:23:39 +00009214
9215 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9216 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers");
9217
vagdeviaf9a5b92018-08-15 16:01:53 -07009218 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009219
9220 final long identity = Binder.clearCallingIdentity();
9221 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009222 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9223 if (response instanceof CarrierRestrictionRules) {
9224 return (CarrierRestrictionRules) response;
9225 }
9226 // Response is an Exception of some kind,
9227 // which is signalled to the user as a NULL retval
9228 return null;
9229 } catch (Exception e) {
9230 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9231 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009232 } finally {
9233 Binder.restoreCallingIdentity(identity);
9234 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009235 }
9236
fionaxu59545b42016-05-25 15:53:37 -07009237 /**
arunvoddud7401012022-12-15 16:08:12 +00009238 * Fetches the carrier restriction status of the device and sends the status to the caller
9239 * through the callback.
9240 *
9241 * @param callback The callback that will be used to send the result.
9242 * @throws SecurityException if the caller does not have the required permission/privileges or
9243 * the caller is not allowlisted.
9244 */
9245 @Override
9246 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
9247 enforceReadPermission("getCarrierRestrictionStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00009248
9249 enforceTelephonyFeatureWithException(packageName,
9250 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierRestrictionStatus");
9251
Steve Statia28b7cb32024-03-11 23:58:50 +00009252 Set<Integer> carrierIds = validateCallerAndGetCarrierIds(packageName);
9253 if (carrierIds.contains(CarrierAllowListInfo.INVALID_CARRIER_ID)) {
arunvoddud7401012022-12-15 16:08:12 +00009254 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9255 throw new SecurityException("Not an authorized caller");
9256 }
9257 final long identity = Binder.clearCallingIdentity();
9258 try {
9259 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
Steve Statia28b7cb32024-03-11 23:58:50 +00009260 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierIds);
arunvoddud7401012022-12-15 16:08:12 +00009261 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9262 } finally {
9263 Binder.restoreCallingIdentity(identity);
9264 }
9265 }
9266
arunvoddu567f2b42023-04-25 17:22:00 +00009267 @Override
9268 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
9269 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
9270 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9271 return allowListInfo.getShaIdList(pkgName, carrierId);
9272 }
9273
arunvoddud7401012022-12-15 16:08:12 +00009274 @VisibleForTesting
Steve Statia28b7cb32024-03-11 23:58:50 +00009275 public Set<Integer> validateCallerAndGetCarrierIds(String packageName) {
arunvoddud7401012022-12-15 16:08:12 +00009276 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
Steve Statia28b7cb32024-03-11 23:58:50 +00009277 return allowListInfo.validateCallerAndGetCarrierIds(packageName);
arunvoddud7401012022-12-15 16:08:12 +00009278 }
9279
9280 /**
fionaxu59545b42016-05-25 15:53:37 -07009281 * Action set from carrier signalling broadcast receivers to enable/disable radio
9282 * @param subId the subscription ID that this action applies to.
9283 * @param enabled control enable or disable radio.
9284 * {@hide}
9285 */
9286 @Override
9287 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9288 enforceModifyPermission();
9289 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009290
9291 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009292 if (phone == null) {
9293 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9294 return;
9295 }
9296 try {
9297 phone.carrierActionSetRadioEnabled(enabled);
9298 } catch (Exception e) {
9299 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009300 } finally {
9301 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009302 }
9303 }
9304
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009305 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009306 * Enable or disable Voice over NR (VoNR)
9307 * @param subId the subscription ID that this action applies to.
9308 * @param enabled enable or disable VoNR.
9309 * @return operation result.
9310 */
9311 @Override
9312 public int setVoNrEnabled(int subId, boolean enabled) {
9313 enforceModifyPermission();
9314 final Phone phone = getPhone(subId);
9315
9316 final long identity = Binder.clearCallingIdentity();
9317 if (phone == null) {
9318 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9319 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9320 }
9321
9322 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9323 try {
9324 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9325 workSource);
9326 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009327
9328 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9329 if (DBG) {
9330 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9331 }
9332 SubscriptionManager.setSubscriptionProperty(
9333 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9334 (enabled ? "1" : "0"));
9335 }
9336
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009337 return result;
9338 } finally {
9339 Binder.restoreCallingIdentity(identity);
9340 }
9341 }
9342
9343 /**
9344 * Is voice over NR enabled
9345 * @return true if VoNR is enabled else false
9346 */
9347 @Override
9348 public boolean isVoNrEnabled(int subId) {
9349 enforceReadPrivilegedPermission("isVoNrEnabled");
9350 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9351 final long identity = Binder.clearCallingIdentity();
9352 try {
9353 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9354 null, subId, workSource);
9355 if (DBG) log("isVoNrEnabled: " + isEnabled);
9356 return isEnabled;
9357 } finally {
9358 Binder.restoreCallingIdentity(identity);
9359 }
9360 }
9361
9362 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009363 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9364 * network status based on which carrier apps could apply actions accordingly,
9365 * enable/disable default url handler for example.
9366 *
9367 * @param subId the subscription ID that this action applies to.
9368 * @param report control start/stop reporting the default network status.
9369 * {@hide}
9370 */
9371 @Override
9372 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9373 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009374
9375 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9376 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
9377 "carrierActionReportDefaultNetworkStatus");
9378
fionaxu8da9cb12017-05-23 15:02:46 -07009379 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009380
9381 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009382 if (phone == null) {
9383 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9384 return;
9385 }
9386 try {
9387 phone.carrierActionReportDefaultNetworkStatus(report);
9388 } catch (Exception e) {
9389 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009390 } finally {
9391 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009392 }
9393 }
9394
9395 /**
fionaxud9622282017-07-17 17:51:30 -07009396 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9397 * @param subId the subscription ID that this action applies to.
9398 * {@hide}
9399 */
9400 @Override
9401 public void carrierActionResetAll(int subId) {
9402 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009403
9404 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9405 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll");
9406
fionaxud9622282017-07-17 17:51:30 -07009407 final Phone phone = getPhone(subId);
9408 if (phone == null) {
9409 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9410 return;
9411 }
9412 try {
9413 phone.carrierActionResetAll();
9414 } catch (Exception e) {
9415 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9416 }
9417 }
9418
9419 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009420 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9421 * bug report is being generated.
9422 */
9423 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009424 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009425 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9426 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009427 writer.println("Permission Denial: can't dump Phone from pid="
9428 + Binder.getCallingPid()
9429 + ", uid=" + Binder.getCallingUid()
9430 + "without permission "
9431 + android.Manifest.permission.DUMP);
9432 return;
9433 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009434 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009435 }
Jack Yueb89b242016-06-22 13:27:47 -07009436
Brad Ebingerdac2f002018-04-03 15:17:52 -07009437 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009438 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9439 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9440 @NonNull String[] args) {
9441 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9442 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009443 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009444 }
9445
Jack Yueb89b242016-06-22 13:27:47 -07009446 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009447 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009448 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009449 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009450 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009451 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009452 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009453 */
9454 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009455 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009456 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009457 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9458 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9459 try {
9460 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009461 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009462 } catch (SecurityException se) {
9463 enforceModifyPermission();
9464 }
9465 } else {
9466 enforceModifyPermission();
9467 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009468
joonhunshin4ac60942023-11-15 15:23:39 +00009469 enforceTelephonyFeatureWithException(callingPackage,
9470 PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason");
9471
Nate Myren116695d2024-02-09 09:36:01 -08009472 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009473 final long identity = Binder.clearCallingIdentity();
9474 try {
Nate Myren116695d2024-02-09 09:36:01 -08009475 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
9476 && null != callingPackage && opEnableMobileDataByUser()) {
Nate Myren453c3472024-03-13 11:28:11 -07009477 mAppOps.noteOpNoThrow(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER,
Nate Myren116695d2024-02-09 09:36:01 -08009478 callingUid, callingPackage, null, null);
9479 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009480 Phone phone = getPhone(subId);
9481 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009482 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9483 phone.carrierActionSetMeteredApnsEnabled(enabled);
9484 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07009485 phone.getDataSettingsManager().setDataEnabled(
9486 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009487 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009488 }
9489 } finally {
9490 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009491 }
9492 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009493
9494 /**
9495 * Get Client request stats
9496 * @return List of Client Request Stats
9497 * @hide
9498 */
9499 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009500 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9501 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009502 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009503 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009504 return null;
9505 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009506 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009507
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009508 final long identity = Binder.clearCallingIdentity();
9509 try {
9510 if (phone != null) {
9511 return phone.getClientRequestStats();
9512 }
9513
9514 return null;
9515 } finally {
9516 Binder.restoreCallingIdentity(identity);
9517 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009518 }
9519
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009520 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009521 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009522 if (uid == Process.ROOT_UID && packageName == null) {
9523 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9524 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9525 // exception. ROOT_UID seems not to have a valid package name returned by
9526 // PackageManager, so just fake it here to avoid issues when running telephony shell
9527 // commands that plumb through the RIL as root, like so:
9528 // $ adb root
9529 // $ adb shell cmd phone ...
9530 packageName = "root";
9531 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009532 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009533 }
Jack Yueb4124c2017-02-16 15:32:43 -08009534
9535 /**
Grace Chen70990072017-03-24 17:21:30 -07009536 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009537 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009538 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009539 * @param state State of SIM (power down, power up, pass through)
9540 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9541 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9542 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009543 *
9544 **/
9545 @Override
Grace Chen70990072017-03-24 17:21:30 -07009546 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009547 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009548
9549 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9550 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot");
9551
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009552 Phone phone = PhoneFactory.getPhone(slotIndex);
9553
vagdeviaf9a5b92018-08-15 16:01:53 -07009554 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9555
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009556 final long identity = Binder.clearCallingIdentity();
9557 try {
9558 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009559 phone.setSimPowerState(state, null, workSource);
9560 }
9561 } finally {
9562 Binder.restoreCallingIdentity(identity);
9563 }
9564 }
9565
9566 /**
9567 * Set SIM card power state.
9568 *
9569 * @param slotIndex SIM slot id.
9570 * @param state State of SIM (power down, power up, pass through)
9571 * @param callback callback to trigger after success or failure
9572 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9573 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9574 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9575 *
9576 **/
9577 @Override
9578 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9579 IIntegerConsumer callback) {
9580 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009581
9582 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9583 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
9584 "setSimPowerStateForSlotWithCallback");
9585
Jordan Liu109698e2020-11-24 14:50:34 -08009586 Phone phone = PhoneFactory.getPhone(slotIndex);
9587
9588 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9589
9590 final long identity = Binder.clearCallingIdentity();
9591 try {
9592 if (phone != null) {
9593 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9594 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009595 }
9596 } finally {
9597 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009598 }
9599 }
Shuo Qiandd210312017-04-12 22:11:33 +00009600
Tyler Gunn65d45c22017-06-05 11:22:26 -07009601 private boolean isUssdApiAllowed(int subId) {
9602 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009603 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009604 if (configManager == null) {
9605 return false;
9606 }
9607 PersistableBundle pb = configManager.getConfigForSubId(subId);
9608 if (pb == null) {
9609 return false;
9610 }
9611 return pb.getBoolean(
9612 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9613 }
9614
Shuo Qiandd210312017-04-12 22:11:33 +00009615 /**
Ling Mac28f0212023-03-24 16:07:15 -07009616 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00009617 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07009618 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00009619 */
goneil9c5f4872017-12-05 14:07:56 -08009620 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009621 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009622 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
joonhunshin4ac60942023-11-15 15:23:39 +00009623
9624 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9625 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode");
9626
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009627 final long identity = Binder.clearCallingIdentity();
9628 try {
Ling Mac28f0212023-03-24 16:07:15 -07009629 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009630 } finally {
9631 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009632 }
9633 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009634
9635 /**
9636 * Get the current signal strength information for the given subscription.
9637 * Because this information is not updated when the device is in a low power state
9638 * it should not be relied-upon to be current.
9639 * @param subId Subscription index
9640 * @return the most recent cached signal strength info from the modem
9641 */
9642 @Override
9643 public SignalStrength getSignalStrength(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00009644 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9645 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength");
9646
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009647 final long identity = Binder.clearCallingIdentity();
9648 try {
9649 Phone p = getPhone(subId);
9650 if (p == null) {
9651 return null;
9652 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009653
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009654 return p.getSignalStrength();
9655 } finally {
9656 Binder.restoreCallingIdentity(identity);
9657 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009658 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009659
Pengquan Meng77b7f132018-08-22 14:49:57 -07009660 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009661 * Get the current modem radio state for the given slot.
9662 * @param slotIndex slot index.
9663 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009664 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009665 * @return the current radio power state from the modem
9666 */
9667 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009668 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009669 Phone phone = PhoneFactory.getPhone(slotIndex);
9670 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009671 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9672 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009673 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9674 }
9675
joonhunshin4ac60942023-11-15 15:23:39 +00009676 enforceTelephonyFeatureWithException(callingPackage,
9677 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState");
9678
Chen Xuf792fd62018-10-17 17:54:36 +00009679 final long identity = Binder.clearCallingIdentity();
9680 try {
9681 return phone.getRadioPowerState();
9682 } finally {
9683 Binder.restoreCallingIdentity(identity);
9684 }
9685 }
9686 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9687 }
9688
9689 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009690 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9691 *
9692 * <p>Requires one of the following permissions:
9693 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009694 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009695 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9696 * privileges.
9697 *
9698 * @param subId subscription id
9699 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9700 * {@code false}.
9701 */
9702 @Override
9703 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009704 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009705 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009706 try {
9707 mApp.enforceCallingOrSelfPermission(
9708 android.Manifest.permission.ACCESS_NETWORK_STATE,
9709 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009710 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009711 mApp.enforceCallingOrSelfPermission(
9712 permission.READ_BASIC_PHONE_STATE, functionName);
9713 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009714 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009715 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009716 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009717 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009718
joonhunshin4ac60942023-11-15 15:23:39 +00009719 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9720 PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled");
9721
Pengquan Menga1bb6272018-09-06 09:59:22 -07009722 boolean isEnabled = false;
9723 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009724 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009725 Phone phone = getPhone(subId);
9726 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009727 } finally {
9728 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009729 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009730 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009731 }
9732
9733
9734 /**
9735 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9736 *
9737 * <p> Requires permission:
9738 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9739 * privileges.
9740 *
9741 * @param subId subscription id
9742 * @param isEnabled {@code true} means enable, {@code false} means disable.
9743 */
9744 @Override
9745 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009746 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9747 mApp, subId, "setDataRoamingEnabled");
9748
joonhunshin4ac60942023-11-15 15:23:39 +00009749 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9750 PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled");
9751
Pengquan Menga1bb6272018-09-06 09:59:22 -07009752 final long identity = Binder.clearCallingIdentity();
9753 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009754 Phone phone = getPhone(subId);
9755 if (phone != null) {
9756 phone.setDataRoamingEnabled(isEnabled);
9757 }
9758 } finally {
9759 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009760 }
9761 }
9762
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009763 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009764 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009765 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009766 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009767 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009768
joonhunshin4ac60942023-11-15 15:23:39 +00009769 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9770 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed");
9771
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009772 boolean isAllowed = true;
9773 final long identity = Binder.clearCallingIdentity();
9774 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009775 Phone phone = getPhone(subId);
9776 if (phone != null) {
9777 isAllowed = phone.isCspPlmnEnabled();
9778 }
9779 } finally {
9780 Binder.restoreCallingIdentity(identity);
9781 }
9782 return isAllowed;
9783 }
9784
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009785 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9786 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009787 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009788 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009789 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009790 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9791 if (phone == null) {
9792 return false;
9793 }
9794 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9795 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9796 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009797 }
9798
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009799 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009800 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009801 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009802 mApp.getSystemService(AppOpsManager.class)
9803 .checkPackage(Binder.getCallingUid(), callingPackage);
9804
Jordan Liu1e142fc2019-04-22 15:10:43 -07009805 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009806 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009807 try {
9808 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009809 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009810 } catch (SecurityException e) {
9811 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9812 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009813 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009814 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009815 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009816 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009817 }
joonhunshin4ac60942023-11-15 15:23:39 +00009818
9819 enforceTelephonyFeatureWithException(callingPackage,
9820 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo");
9821
sandeepjsb6c87872021-09-27 15:34:44 +00009822 // checking compatibility, if calling app's target SDK is T and beyond.
9823 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9824 Binder.getCallingUid())) {
9825 isIccIdAccessRestricted = true;
9826 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009827 final long identity = Binder.clearCallingIdentity();
9828 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009829 UiccController uiccController = UiccController.getInstance();
9830 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009831 if (hasReadPermission) {
9832 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009833 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009834
9835 // Remove private info if the caller doesn't have access
9836 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9837 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009838 //setting the value after compatibility check
9839 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009840 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9841 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009842 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009843 if (card == null) {
9844 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009845 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009846 continue;
9847 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009848 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9849 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009850 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009851 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009852 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009853 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9854 for (UiccPortInfo portInfo : portInfos) {
9855 UiccPort port = uiccController.getUiccPortForSlot(
9856 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9857 if (port == null) {
9858 // assume no access if port is null
9859 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9860 continue;
9861 }
9862 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9863 uiccPortInfos.add(portInfo);
9864 } else {
9865 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9866 }
9867 }
9868 filteredInfos.add(new UiccCardInfo(
9869 cardInfo.isEuicc(),
9870 cardInfo.getCardId(),
9871 null,
9872 cardInfo.getPhysicalSlotIndex(),
9873 cardInfo.isRemovable(),
9874 cardInfo.isMultipleEnabledProfilesSupported(),
9875 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009876 }
9877 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009878 } finally {
9879 Binder.restoreCallingIdentity(identity);
9880 }
9881 }
9882
sandeepjsb6c87872021-09-27 15:34:44 +00009883 /**
9884 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9885 * generally private and require carrier privileges to view.
9886 *
9887 * @hide
9888 */
9889 @NonNull
9890 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9891 List<UiccPortInfo> portinfo = new ArrayList<>();
9892 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9893 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9894 }
9895 return new UiccCardInfo(
9896 cardInfo.isEuicc(),
9897 cardInfo.getCardId(),
9898 null,
9899 cardInfo.getPhysicalSlotIndex(),
9900 cardInfo.isRemovable(),
9901 cardInfo.isMultipleEnabledProfilesSupported(),
9902 portinfo
9903 );
9904 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009905
sandeepjsb6c87872021-09-27 15:34:44 +00009906 /**
9907 * @hide
9908 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9909 * These values are generally private and require carrier privileges to view.
9910 */
9911 @NonNull
9912 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9913 return new UiccPortInfo(
9914 UiccPortInfo.ICCID_REDACTED,
9915 portInfo.getPortIndex(),
9916 portInfo.getLogicalSlotIndex(),
9917 portInfo.isActive()
9918 );
9919 }
9920 @Override
9921 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009922 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009923 mApp.getSystemService(AppOpsManager.class)
9924 .checkPackage(Binder.getCallingUid(), callingPackage);
9925
sandeepjsb6c87872021-09-27 15:34:44 +00009926 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009927
Aman Guptaf3c90b32022-03-17 04:54:16 +00009928 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9929 // we are reading iccId which is PII data.
9930 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009931
joonhunshin4ac60942023-11-15 15:23:39 +00009932 enforceTelephonyFeatureWithException(callingPackage,
9933 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo");
9934
sandeepjsb6c87872021-09-27 15:34:44 +00009935 // checking compatibility, if calling app's target SDK is T and beyond.
9936 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9937 Binder.getCallingUid())) {
9938 isLogicalSlotAccessRestricted = true;
9939 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009940 final long identity = Binder.clearCallingIdentity();
9941 try {
9942 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009943 if (slots == null || slots.length == 0) {
9944 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009945 return null;
9946 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009947 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9948 for (int i = 0; i < slots.length; i++) {
9949 UiccSlot slot = slots[i];
9950 if (slot == null) {
9951 continue;
9952 }
9953
Jordan Liu7be7e652019-05-06 18:55:02 +00009954 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009955 UiccCard card = slot.getUiccCard();
9956 if (card != null) {
9957 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009958 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009959 cardId = slot.getEid();
9960 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009961 // If cardId is null, use iccId of default port as cardId.
9962 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009963 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009964 }
9965
Jordan Liu857451f2019-05-09 16:35:35 -07009966 if (cardId != null) {
9967 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9968 // if cardId is an EID, it's all digits so this is fine
9969 cardId = IccUtils.stripTrailingFs(cardId);
9970 }
9971
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009972 int cardState = 0;
9973 switch (slot.getCardState()) {
9974 case CARDSTATE_ABSENT:
9975 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9976 break;
9977 case CARDSTATE_PRESENT:
9978 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9979 break;
9980 case CARDSTATE_ERROR:
9981 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9982 break;
9983 case CARDSTATE_RESTRICTED:
9984 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9985 break;
9986 default:
9987 break;
9988
9989 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009990 List<UiccPortInfo> portInfos = new ArrayList<>();
9991 int[] portIndexes = slot.getPortList();
9992 for (int portIdx : portIndexes) {
9993 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009994 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009995 portInfos.add(new UiccPortInfo(iccId, portIdx,
9996 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009997 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009998 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009999 slot.isEuicc(),
10000 cardId,
10001 cardState,
Jordan Liua2619582019-02-14 12:56:40 -080010002 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010003 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +000010004 //setting the value after compatibility check
10005 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010006 }
10007 return infos;
10008 } finally {
10009 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -070010010 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010011 }
10012
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010013 /* Returns null if doesn't have read permission or carrier privilege access. */
10014 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
10015 boolean hasReadPermission) {
10016 String iccId = slot.getIccId(portIndex);
10017 if (hasReadPermission) { // if has read permission
10018 return iccId;
10019 } else {
10020 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
10021 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
10022 // if no read permission, checking carrier privilege access
10023 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
10024 return iccId;
10025 }
10026 }
10027 }
10028 // No read permission or carrier privilege access.
10029 return UiccPortInfo.ICCID_REDACTED;
10030 }
10031
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010032 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010033 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010034 public boolean switchSlots(int[] physicalSlots) {
10035 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010036
joonhunshin4ac60942023-11-15 15:23:39 +000010037 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10038 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots");
10039
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010040 final long identity = Binder.clearCallingIdentity();
10041 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010042 List<UiccSlotMapping> slotMappings = new ArrayList<>();
10043 for (int i = 0; i < physicalSlots.length; i++) {
10044 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
10045 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
10046 physicalSlots[i], i));
10047 }
10048 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010049 } finally {
10050 Binder.restoreCallingIdentity(identity);
10051 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010052 }
Jack Yu4c988042018-02-27 15:30:01 -080010053
10054 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010055 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
10056 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
10057 enforceModifyPermission();
10058
joonhunshin4ac60942023-11-15 15:23:39 +000010059 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10060 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping");
10061
sandeepjsb6c87872021-09-27 15:34:44 +000010062 final long identity = Binder.clearCallingIdentity();
10063 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010064 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +000010065 } finally {
10066 Binder.restoreCallingIdentity(identity);
10067 }
10068 }
10069
10070 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -080010071 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
joonhunshin4ac60942023-11-15 15:23:39 +000010072 enforceTelephonyFeatureWithException(callingPackage,
10073 PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc");
10074
Jordan Liu7de49fa2018-12-06 14:48:49 -080010075 final long identity = Binder.clearCallingIdentity();
10076 try {
10077 return UiccController.getInstance().getCardIdForDefaultEuicc();
10078 } finally {
10079 Binder.restoreCallingIdentity(identity);
10080 }
10081 }
10082
Pengquan Meng85728fb2018-03-12 16:31:21 -070010083 /**
goneil47ffb6e2018-04-06 15:40:58 -070010084 * A test API to reload the UICC profile.
10085 *
10086 * <p>Requires that the calling app has permission
10087 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
10088 * @hide
10089 */
10090 @Override
10091 public void refreshUiccProfile(int subId) {
10092 enforceModifyPermission();
10093
10094 final long identity = Binder.clearCallingIdentity();
10095 try {
10096 Phone phone = getPhone(subId);
10097 if (phone == null) {
10098 return;
10099 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010100 UiccPort uiccPort = phone.getUiccPort();
10101 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -070010102 return;
10103 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010104 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -070010105 if (uiccProfile == null) {
10106 return;
10107 }
10108 uiccProfile.refresh();
10109 } finally {
10110 Binder.restoreCallingIdentity(identity);
10111 }
10112 }
10113
10114 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010115 * Returns false if the mobile data is disabled by default, otherwise return true.
10116 */
10117 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010118 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010119 }
10120
10121 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010122 * Returns the default network type for the given {@code subId}, if the default network type is
10123 * not set, return {@link Phone#PREFERRED_NT_MODE}.
10124 */
10125 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010126 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -080010127 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +090010128 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
10129 return list.get(phoneId);
10130 }
10131 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -070010132 }
fionaxua13278b2018-03-21 00:08:13 -070010133
10134 @Override
10135 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -070010136 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -070010137 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010138
10139 final long identity = Binder.clearCallingIdentity();
10140 try {
10141 final Phone phone = getPhone(subId);
10142 if (phone == null) {
10143 loge("setCarrierTestOverride fails with invalid subId: " + subId);
10144 return;
10145 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -080010146 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10147 if (cpt != null) {
10148 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
10149 }
10150 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -070010151 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
10152 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -070010153 if (carrierPrivilegeRules == null) {
10154 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
10155 } else {
10156 mCarrierPrivilegeTestOverrideSubIds.add(subId);
10157 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010158 } finally {
10159 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010160 }
fionaxua13278b2018-03-21 00:08:13 -070010161 }
10162
10163 @Override
Benedict Wong66477622023-02-03 23:30:57 +000010164 public void setCarrierServicePackageOverride(
10165 int subId, String carrierServicePackage, String callingPackage) {
10166 TelephonyPermissions.enforceShellOnly(
10167 Binder.getCallingUid(), "setCarrierServicePackageOverride");
10168
Benedict Wong66477622023-02-03 23:30:57 +000010169 final long identity = Binder.clearCallingIdentity();
10170 try {
10171 final Phone phone = getPhone(subId);
10172 if (phone == null || phone.getSubId() != subId) {
10173 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
10174 throw new IllegalArgumentException("No phone for subid");
10175 }
10176 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10177 if (cpt == null) {
10178 loge("setCarrierServicePackageOverride failed with no CPT for phone");
10179 throw new IllegalStateException("No CPT for phone");
10180 }
10181 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
10182 } finally {
10183 Binder.restoreCallingIdentity(identity);
10184 }
10185 }
10186
10187 @Override
fionaxua13278b2018-03-21 00:08:13 -070010188 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -070010189 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010190
10191 final long identity = Binder.clearCallingIdentity();
10192 try {
10193 final Phone phone = getPhone(subId);
10194 if (phone == null) {
10195 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
10196 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
10197 }
10198 return phone.getCarrierIdListVersion();
10199 } finally {
10200 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010201 }
fionaxua13278b2018-03-21 00:08:13 -070010202 }
Malcolm Chen2c63d402018-08-14 16:00:53 -070010203
10204 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010205 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
10206 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010207 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010208 mApp, subId, callingPackage, callingFeatureId,
10209 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010210 return -1;
10211 }
10212
10213 final long identity = Binder.clearCallingIdentity();
10214 try {
10215 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10216 } finally {
10217 Binder.restoreCallingIdentity(identity);
10218 }
10219 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010220
10221 @Override
10222 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +080010223 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010224 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010225 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010226
joonhunshin4ac60942023-11-15 15:23:39 +000010227 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10228 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode");
10229
Pengquan Menga1bb6272018-09-06 09:59:22 -070010230 final long identity = Binder.clearCallingIdentity();
10231 try {
10232 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10233 } finally {
10234 Binder.restoreCallingIdentity(identity);
10235 }
10236 }
10237
10238 @Override
10239 public boolean setCdmaRoamingMode(int subId, int mode) {
10240 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10241 mApp, subId, "setCdmaRoamingMode");
10242
joonhunshin4ac60942023-11-15 15:23:39 +000010243 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10244 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode");
10245
Pengquan Menga1bb6272018-09-06 09:59:22 -070010246 final long identity = Binder.clearCallingIdentity();
10247 try {
10248 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10249 } finally {
10250 Binder.restoreCallingIdentity(identity);
10251 }
10252 }
10253
10254 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010255 public int getCdmaSubscriptionMode(int subId) {
10256 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010257 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010258 mApp, subId, "getCdmaSubscriptionMode");
10259
joonhunshin4ac60942023-11-15 15:23:39 +000010260 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10261 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode");
10262
Sarah Chinbaab1432020-10-28 13:46:24 -070010263 final long identity = Binder.clearCallingIdentity();
10264 try {
10265 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10266 } finally {
10267 Binder.restoreCallingIdentity(identity);
10268 }
10269 }
10270
10271 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010272 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10273 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10274 mApp, subId, "setCdmaSubscriptionMode");
10275
joonhunshin4ac60942023-11-15 15:23:39 +000010276 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10277 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode");
10278
Pengquan Menga1bb6272018-09-06 09:59:22 -070010279 final long identity = Binder.clearCallingIdentity();
10280 try {
10281 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10282 } finally {
10283 Binder.restoreCallingIdentity(identity);
10284 }
10285 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010286
sqianc5eccab2018-10-19 18:46:41 -070010287 @Override
sqian8c685422019-02-22 15:55:18 -080010288 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010289 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010290 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010291 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10292 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010293 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10294 }
joonhunshin4ac60942023-11-15 15:23:39 +000010295
10296 enforceTelephonyFeatureWithException(callingPackage,
10297 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList");
10298
sqian11b7a0e2018-12-05 18:48:28 -080010299 final long identity = Binder.clearCallingIdentity();
10300 try {
sqian854d44b2018-12-12 16:48:18 -080010301 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10302 for (Phone phone: PhoneFactory.getPhones()) {
10303 if (phone.getEmergencyNumberTracker() != null
10304 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10305 emergencyNumberListInternal.put(
10306 phone.getSubId(),
10307 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10308 }
sqian11b7a0e2018-12-05 18:48:28 -080010309 }
sqian854d44b2018-12-12 16:48:18 -080010310 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010311 } finally {
10312 Binder.restoreCallingIdentity(identity);
10313 }
sqianc5eccab2018-10-19 18:46:41 -070010314 }
10315
10316 @Override
sqian8c685422019-02-22 15:55:18 -080010317 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010318 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010319 if (!exactMatch) {
10320 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010321 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010322 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010323 }
joonhunshin4ac60942023-11-15 15:23:39 +000010324
10325 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10326 PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber");
10327
sqian11b7a0e2018-12-05 18:48:28 -080010328 final long identity = Binder.clearCallingIdentity();
10329 try {
sqian854d44b2018-12-12 16:48:18 -080010330 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010331 //Note: we ignore passed in param exactMatch. We can remove it once
10332 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010333 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010334 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010335 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010336 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010337 }
sqian11b7a0e2018-12-05 18:48:28 -080010338 }
10339 return false;
10340 } finally {
10341 Binder.restoreCallingIdentity(identity);
10342 }
10343 }
10344
sqianf4ca7ed2019-01-15 18:32:07 -080010345 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010346 * Start emergency callback mode for GsmCdmaPhone for testing.
10347 */
10348 @Override
10349 public void startEmergencyCallbackMode() {
10350 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10351 "startEmergencyCallbackMode");
10352 enforceModifyPermission();
10353 final long identity = Binder.clearCallingIdentity();
10354 try {
10355 for (Phone phone : PhoneFactory.getPhones()) {
10356 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10357 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10358 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10359 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10360 gsmCdmaPhone.obtainMessage(
10361 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10362 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10363 }
10364 }
10365 } finally {
10366 Binder.restoreCallingIdentity(identity);
10367 }
10368 }
10369
10370 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010371 * Update emergency number list for test mode.
10372 */
10373 @Override
10374 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10375 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10376 "updateEmergencyNumberListTestMode");
10377
10378 final long identity = Binder.clearCallingIdentity();
10379 try {
10380 for (Phone phone: PhoneFactory.getPhones()) {
10381 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10382 if (tracker != null) {
10383 tracker.executeEmergencyNumberTestModeCommand(action, num);
10384 }
10385 }
10386 } finally {
10387 Binder.restoreCallingIdentity(identity);
10388 }
10389 }
10390
10391 /**
10392 * Get the full emergency number list for test mode.
10393 */
10394 @Override
10395 public List<String> getEmergencyNumberListTestMode() {
10396 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10397 "getEmergencyNumberListTestMode");
10398
10399 final long identity = Binder.clearCallingIdentity();
10400 try {
10401 Set<String> emergencyNumbers = new HashSet<>();
10402 for (Phone phone: PhoneFactory.getPhones()) {
10403 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10404 if (tracker != null) {
10405 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10406 emergencyNumbers.add(num.getNumber());
10407 }
10408 }
10409 }
10410 return new ArrayList<>(emergencyNumbers);
10411 } finally {
10412 Binder.restoreCallingIdentity(identity);
10413 }
10414 }
10415
chen xud6b45bd2018-10-30 22:27:10 -070010416 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010417 public int getEmergencyNumberDbVersion(int subId) {
10418 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10419
joonhunshin4ac60942023-11-15 15:23:39 +000010420 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10421 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion");
10422
Shuo Qian3b6ee772019-11-13 17:43:31 -080010423 final long identity = Binder.clearCallingIdentity();
10424 try {
10425 final Phone phone = getPhone(subId);
10426 if (phone == null) {
10427 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10428 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10429 }
10430 return phone.getEmergencyNumberDbVersion();
10431 } finally {
10432 Binder.restoreCallingIdentity(identity);
10433 }
10434 }
10435
10436 @Override
10437 public void notifyOtaEmergencyNumberDbInstalled() {
10438 enforceModifyPermission();
10439
joonhunshin4ac60942023-11-15 15:23:39 +000010440 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10441 PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled");
10442
Shuo Qian3b6ee772019-11-13 17:43:31 -080010443 final long identity = Binder.clearCallingIdentity();
10444 try {
10445 for (Phone phone: PhoneFactory.getPhones()) {
10446 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10447 if (tracker != null) {
10448 tracker.updateOtaEmergencyNumberDatabase();
10449 }
10450 }
10451 } finally {
10452 Binder.restoreCallingIdentity(identity);
10453 }
10454 }
10455
10456 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010457 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010458 enforceActiveEmergencySessionPermission();
10459
joonhunshin4ac60942023-11-15 15:23:39 +000010460 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10461 PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath");
10462
Shuo Qian3b6ee772019-11-13 17:43:31 -080010463 final long identity = Binder.clearCallingIdentity();
10464 try {
10465 for (Phone phone: PhoneFactory.getPhones()) {
10466 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10467 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010468 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10469 }
10470 }
10471 } finally {
10472 Binder.restoreCallingIdentity(identity);
10473 }
10474 }
10475
10476 @Override
10477 public void resetOtaEmergencyNumberDbFilePath() {
10478 enforceActiveEmergencySessionPermission();
10479
joonhunshin4ac60942023-11-15 15:23:39 +000010480 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10481 PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath");
10482
Shuo Qianc373f112020-03-05 17:55:34 -080010483 final long identity = Binder.clearCallingIdentity();
10484 try {
10485 for (Phone phone: PhoneFactory.getPhones()) {
10486 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10487 if (tracker != null) {
10488 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010489 }
10490 }
10491 } finally {
10492 Binder.restoreCallingIdentity(identity);
10493 }
10494 }
10495
10496 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010497 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10498 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10499 Phone phone = getPhone(subId);
10500 if (phone == null) {
10501 return null;
10502 }
10503 final long identity = Binder.clearCallingIdentity();
10504 try {
10505 UiccProfile profile = UiccController.getInstance()
10506 .getUiccProfileForPhone(phone.getPhoneId());
10507 if (profile != null) {
10508 return profile.getCertsFromCarrierPrivilegeAccessRules();
10509 }
10510 } finally {
10511 Binder.restoreCallingIdentity(identity);
10512 }
10513 return null;
10514 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010515
10516 /**
10517 * Enable or disable a modem stack.
10518 */
10519 @Override
10520 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10521 enforceModifyPermission();
10522
joonhunshin4ac60942023-11-15 15:23:39 +000010523 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10524 PackageManager.FEATURE_TELEPHONY, "enableModemForSlot");
10525
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010526 final long identity = Binder.clearCallingIdentity();
10527 try {
10528 Phone phone = PhoneFactory.getPhone(slotIndex);
10529 if (phone == null) {
10530 return false;
10531 } else {
10532 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10533 }
10534 } finally {
10535 Binder.restoreCallingIdentity(identity);
10536 }
10537 }
Michelecea4cf22018-12-21 15:00:11 -080010538
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010539 /**
10540 * Whether a modem stack is enabled or not.
10541 */
10542 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010543 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10544 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010545 Phone phone = PhoneFactory.getPhone(slotIndex);
10546 if (phone == null) return false;
10547
10548 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010549 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10550 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010551 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10552 }
10553
joonhunshin4ac60942023-11-15 15:23:39 +000010554 enforceTelephonyFeatureWithException(callingPackage,
10555 PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot");
10556
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010557 final long identity = Binder.clearCallingIdentity();
10558 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010559 try {
10560 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10561 } catch (NoSuchElementException ex) {
10562 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10563 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010564 } finally {
10565 Binder.restoreCallingIdentity(identity);
10566 }
10567 }
10568
Michelecea4cf22018-12-21 15:00:11 -080010569 @Override
Michele0ea7d782019-03-19 14:58:42 -070010570 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010571 enforceModifyPermission();
10572
joonhunshin4ac60942023-11-15 15:23:39 +000010573 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10574 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction");
10575
Michelecea4cf22018-12-21 15:00:11 -080010576 final long identity = Binder.clearCallingIdentity();
10577 try {
10578 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010579 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010580 .commit();
10581 } finally {
10582 Binder.restoreCallingIdentity(identity);
10583 }
10584 }
10585
10586 @Override
Michele0ea7d782019-03-19 14:58:42 -070010587 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010588 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010589 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010590 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10591 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010592 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010593 }
Michelecea4cf22018-12-21 15:00:11 -080010594
joonhunshin4ac60942023-11-15 15:23:39 +000010595 enforceTelephonyFeatureWithException(callingPackage,
10596 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported");
10597
Michelecea4cf22018-12-21 15:00:11 -080010598 final long identity = Binder.clearCallingIdentity();
10599 try {
Michele0ea7d782019-03-19 14:58:42 -070010600 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010601 } finally {
10602 Binder.restoreCallingIdentity(identity);
10603 }
10604 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010605
Michele0ea7d782019-03-19 14:58:42 -070010606 @TelephonyManager.IsMultiSimSupportedResult
10607 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010608 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10609 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10610 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010611 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10612 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010613 }
10614 // Check if the hardware supports multisim functionality. If usage of multisim is not
10615 // supported by the modem, indicate that it is restricted.
10616 PhoneCapability staticCapability =
10617 mPhoneConfigurationManager.getStaticPhoneCapability();
10618 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010619 loge("isMultiSimSupportedInternal: no static configuration available");
10620 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010621 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010622 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010623 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10624 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010625 }
10626 // Check if support of multiple SIMs is restricted by carrier
10627 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010628 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010629 }
10630
Michele0ea7d782019-03-19 14:58:42 -070010631 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010632 }
10633
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010634 /**
10635 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010636 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10637 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10638 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010639 * @param numOfSims number of active sims we want to switch to
10640 */
10641 @Override
10642 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010643 if (numOfSims == 1) {
10644 enforceModifyPermission();
10645 } else {
10646 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10647 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10648 }
joonhunshin4ac60942023-11-15 15:23:39 +000010649
10650 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10651 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig");
10652
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010653 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010654
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010655 try {
Michele30b57b22019-03-01 12:01:14 -080010656 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010657 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010658 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10659 return;
10660 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010661 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10662 } finally {
10663 Binder.restoreCallingIdentity(identity);
10664 }
10665 }
10666
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010667 @Override
10668 public boolean isApplicationOnUicc(int subId, int appType) {
10669 enforceReadPrivilegedPermission("isApplicationOnUicc");
joonhunshin4ac60942023-11-15 15:23:39 +000010670
10671 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10672 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc");
10673
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010674 Phone phone = getPhone(subId);
10675 if (phone == null) {
10676 return false;
10677 }
10678 final long identity = Binder.clearCallingIdentity();
10679 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010680 UiccPort uiccPort = phone.getUiccPort();
10681 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010682 return false;
10683 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010684 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010685 if (uiccProfile == null) {
10686 return false;
10687 }
10688 if (TelephonyManager.APPTYPE_SIM <= appType
10689 && appType <= TelephonyManager.APPTYPE_ISIM) {
10690 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10691 }
10692 return false;
10693 } finally {
10694 Binder.restoreCallingIdentity(identity);
10695 }
10696 }
10697
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010698 /**
chen xub4baa772019-04-03 10:23:41 -070010699 * Get whether making changes to modem configurations will trigger reboot.
10700 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010701 */
10702 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010703 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10704 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010705 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010706 mApp, subId, callingPackage, callingFeatureId,
10707 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010708 return false;
10709 }
joonhunshin4ac60942023-11-15 15:23:39 +000010710
10711 enforceTelephonyFeatureWithException(callingPackage,
10712 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
10713 "doesSwitchMultiSimConfigTriggerReboot");
10714
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010715 final long identity = Binder.clearCallingIdentity();
10716 try {
10717 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10718 } finally {
10719 Binder.restoreCallingIdentity(identity);
10720 }
10721 }
10722
Nathan Harold29f5f052019-02-15 13:41:57 -080010723 private void updateModemStateMetrics() {
10724 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10725 // TODO: check the state for each modem if the api is ready.
10726 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10727 }
10728
Pengquan Meng3889a572019-01-23 11:16:29 -080010729 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010730 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010731 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010732 // Verify that the callingPackage belongs to the calling UID
10733 mApp.getSystemService(AppOpsManager.class)
10734 .checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000010735
10736 enforceTelephonyFeatureWithException(callingPackage,
10737 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping");
10738
Pengquan Meng3889a572019-01-23 11:16:29 -080010739 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010740 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010741 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010742 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10743 if (slotInfos != null) {
10744 for (int i = 0; i < slotInfos.length; i++) {
10745 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10746 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10747 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10748 portInfo.getLogicalSlotIndex()));
10749 }
10750 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010751 }
10752 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010753 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010754 } finally {
10755 Binder.restoreCallingIdentity(identity);
10756 }
10757 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010758
10759 /**
10760 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010761 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010762 */
jimsunf9ec1622022-09-13 21:18:43 +080010763 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010764 @Override
10765 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010766 return getHalVersion(HAL_SERVICE_RADIO);
10767 }
10768
10769 /**
10770 * Get the HAL Version of a specific service
10771 */
10772 @Override
10773 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010774 Phone phone = getDefaultPhone();
10775 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010776 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010777 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10778 return hv.major * 100 + hv.minor;
10779 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010780
10781 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010782 * Get the current calling package name.
sangyun097dcf72024-01-04 10:35:49 +090010783 *
10784 * @return the current calling package name, or null if there is no known package.
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010785 */
10786 @Override
sangyun097dcf72024-01-04 10:35:49 +090010787 public @Nullable String getCurrentPackageName() {
10788 PackageManager pm = mApp.getPackageManager();
10789 String[] packageNames = pm == null ? null : pm.getPackagesForUid(Binder.getCallingUid());
10790 return packageNames == null ? null : packageNames[0];
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010791 }
10792
10793 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010794 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10795 * corresponding network requests on a subId.
10796 *
10797 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010798 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010799 * 2) APN is un-metered for this subscription, or
10800 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010801 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010802 *
10803 * @return whether data is allowed for a apn type.
10804 *
10805 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010806 */
10807 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010808 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010809 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10810 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010811
joonhunshin4ac60942023-11-15 15:23:39 +000010812 enforceTelephonyFeatureWithException(callingPackage,
10813 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn");
10814
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010815 // Now that all security checks passes, perform the operation as ourselves.
10816 final long identity = Binder.clearCallingIdentity();
10817 try {
10818 Phone phone = getPhone(subId);
10819 if (phone == null) return false;
10820
Jack Yu27422a52022-03-21 10:38:05 -070010821 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010822 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010823 isMetered = phone.getDataNetworkController().getDataConfigManager()
10824 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10825 phone.getServiceState().getDataRoaming());
10826 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010827 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010828 } finally {
10829 Binder.restoreCallingIdentity(identity);
10830 }
10831 }
10832
10833 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010834 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010835 enforceReadPrivilegedPermission("isApnMetered");
10836
joonhunshin4ac60942023-11-15 15:23:39 +000010837 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10838 PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered");
10839
Malcolm Chene5ad5792019-04-18 13:51:02 -070010840 // Now that all security checks passes, perform the operation as ourselves.
10841 final long identity = Binder.clearCallingIdentity();
10842 try {
10843 Phone phone = getPhone(subId);
10844 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010845 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10846 DataUtils.apnTypeToNetworkCapability(apnType),
10847 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010848 } finally {
10849 Binder.restoreCallingIdentity(identity);
10850 }
10851 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010852
10853 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010854 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10855 int subscriptionId, IBooleanConsumer resultCallback) {
10856 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +000010857
10858 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10859 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels");
10860
Hall Liu73f5d362020-01-20 13:42:00 -080010861 long token = Binder.clearCallingIdentity();
10862 try {
10863 Phone phone = getPhone(subscriptionId);
10864 if (phone == null) {
10865 try {
10866 if (resultCallback != null) {
10867 resultCallback.accept(false);
10868 }
10869 } catch (RemoteException e) {
10870 // ignore
10871 }
10872 return;
10873 }
10874 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10875 Pair.create(specifiers, (x) -> {
10876 try {
10877 if (resultCallback != null) {
10878 resultCallback.accept(x);
10879 }
10880 } catch (RemoteException e) {
10881 // ignore
10882 }
10883 });
10884 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10885 } finally {
10886 Binder.restoreCallingIdentity(token);
10887 }
10888 }
10889
10890 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010891 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10892 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010893 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010894 mApp, subId, "getSystemSelectionChannels");
joonhunshin4ac60942023-11-15 15:23:39 +000010895
10896 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10897 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels");
10898
Sarah Chin679c08a2020-11-18 13:39:35 -080010899 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10900 final long identity = Binder.clearCallingIdentity();
10901 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010902 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10903 if (result instanceof IllegalStateException) {
10904 throw (IllegalStateException) result;
10905 }
10906 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010907 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10908 return specifiers;
10909 } finally {
10910 Binder.restoreCallingIdentity(identity);
10911 }
10912 }
10913
10914 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010915 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010916 enforceReadPrivilegedPermission("isMvnoMatched");
joonhunshin4ac60942023-11-15 15:23:39 +000010917
10918 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10919 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched");
10920
Jack Yu8b766fc2022-03-21 09:42:33 -070010921 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010922 }
10923
10924 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010925 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10926 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010927 if (callingPackage == null) {
10928 callingPackage = getCurrentPackageName();
10929 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010930 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10931 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010932 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10933 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010934 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10935 }
10936 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10937 Intent intent = new Intent();
10938 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10939 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10940 // Bring up choose default SMS subscription dialog right now
10941 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10942 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10943 mApp.startActivity(intent);
10944 }
chen xud5ca2d52019-05-28 15:20:57 -070010945
10946 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010947 public void showSwitchToManagedProfileDialog() {
10948 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000010949 try {
10950 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
10951 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
10952 // for work telephony.
10953 Intent intent = new Intent(Intent.ACTION_SENDTO);
10954 intent.setData(Uri.parse("smsto:"));
10955 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10956 mApp.startActivity(intent);
10957 } catch (ActivityNotFoundException e) {
10958 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
10959 Intent intent = new Intent();
10960 intent.setClass(mApp, ErrorDialogActivity.class);
10961 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10962 mApp.startActivity(intent);
10963 }
Ayush Sharma787854b2022-12-12 14:55:02 +000010964 }
10965
10966 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010967 public String getMmsUAProfUrl(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000010968 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10969 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl");
10970
chen xud5ca2d52019-05-28 15:20:57 -070010971 //TODO investigate if this API should require proper permission check in R b/133791609
10972 final long identity = Binder.clearCallingIdentity();
10973 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010974 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10975 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10976 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10977 return carrierUAProfUrl;
10978 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010979 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10980 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010981 } finally {
10982 Binder.restoreCallingIdentity(identity);
10983 }
10984 }
10985
10986 @Override
10987 public String getMmsUserAgent(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000010988 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10989 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent");
10990
chen xud5ca2d52019-05-28 15:20:57 -070010991 //TODO investigate if this API should require proper permission check in R b/133791609
10992 final long identity = Binder.clearCallingIdentity();
10993 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010994 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10995 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10996 if (!TextUtils.isEmpty(carrierUserAgent)) {
10997 return carrierUserAgent;
10998 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010999 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11000 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070011001 } finally {
11002 Binder.restoreCallingIdentity(identity);
11003 }
11004 }
Jack Yub07d4972019-05-28 16:12:25 -070011005
11006 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070011007 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
11008 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070011009
joonhunshin4ac60942023-11-15 15:23:39 +000011010 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11011 PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled");
11012
Jack Yub07d4972019-05-28 16:12:25 -070011013 final long identity = Binder.clearCallingIdentity();
11014 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011015 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070011016 if (phone == null) return false;
11017
Ling Maf188d502022-09-16 15:22:36 -070011018 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070011019 } finally {
11020 Binder.restoreCallingIdentity(identity);
11021 }
11022 }
11023
11024 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080011025 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070011026 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080011027 enforceModifyPermission();
11028
joonhunshin4ac60942023-11-15 15:23:39 +000011029 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11030 PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled");
11031
changbettyd5c246e2019-12-24 15:40:37 +080011032 final long identity = Binder.clearCallingIdentity();
11033 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011034 Phone phone = getPhone(subscriptionId);
11035 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080011036
Ling Maf188d502022-09-16 15:22:36 -070011037 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080011038 } finally {
11039 Binder.restoreCallingIdentity(identity);
11040 }
11041 }
11042
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011043 /**
Hall Liu746e03c2020-09-25 11:13:49 -070011044 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011045 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
11046 * otherwise.
11047 */
11048 @Override
11049 public void setCepEnabled(boolean isCepEnabled) {
11050 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
11051
11052 final long identity = Binder.clearCallingIdentity();
11053 try {
11054 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
11055 for (Phone phone : PhoneFactory.getPhones()) {
11056 Phone defaultPhone = phone.getImsPhone();
11057 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
11058 ImsPhone imsPhone = (ImsPhone) defaultPhone;
11059 ImsPhoneCallTracker imsPhoneCallTracker =
11060 (ImsPhoneCallTracker) imsPhone.getCallTracker();
11061 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
11062 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
11063 + imsPhone.getMsisdn());
11064 }
11065 }
11066 } finally {
11067 Binder.restoreCallingIdentity(identity);
11068 }
11069 }
allenwtsu46dcc572020-01-08 18:24:03 +080011070
11071 /**
11072 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
11073 *
11074 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
11075 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
11076 * before being read.
11077 */
11078 @Override
11079 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
11080 isCompressed) {
11081 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11082 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011083 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11084 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11085 }
joonhunshin4ac60942023-11-15 15:23:39 +000011086
11087 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11088 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11089 Binder.getCallingUserHandle())) {
11090 if (!isImsAvailableOnDevice()) {
11091 // ProvisioningManager can not handle ServiceSpecificException.
11092 // Throw the IllegalStateException and annotate ProvisioningManager.
11093 throw new IllegalStateException("IMS not available on device.");
11094 }
11095 } else {
11096 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11097 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11098 "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011099 }
11100
11101 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080011102 try {
Hui Wang761a6682020-10-31 05:12:53 +000011103 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
11104 } finally {
11105 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080011106 }
11107 }
zoey chene02881a2019-12-30 16:11:23 +080011108
11109 @Override
11110 public boolean isIccLockEnabled(int subId) {
11111 enforceReadPrivilegedPermission("isIccLockEnabled");
11112
joonhunshin4ac60942023-11-15 15:23:39 +000011113 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11114 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled");
11115
zoey chene02881a2019-12-30 16:11:23 +080011116 // Now that all security checks passes, perform the operation as ourselves.
11117 final long identity = Binder.clearCallingIdentity();
11118 try {
11119 Phone phone = getPhone(subId);
11120 if (phone != null && phone.getIccCard() != null) {
11121 return phone.getIccCard().getIccLockEnabled();
11122 } else {
11123 return false;
11124 }
11125 } finally {
11126 Binder.restoreCallingIdentity(identity);
11127 }
11128 }
11129
11130 /**
11131 * Set the ICC pin lock enabled or disabled.
11132 *
11133 * @return an integer representing the status of IccLock enabled or disabled in the following
11134 * three cases:
11135 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
11136 * successfully.
11137 * - Positive number and zero for remaining password attempts.
11138 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11139 *
11140 */
11141 @Override
11142 public int setIccLockEnabled(int subId, boolean enabled, String password) {
11143 enforceModifyPermission();
11144
joonhunshin4ac60942023-11-15 15:23:39 +000011145 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11146 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled");
11147
zoey chene02881a2019-12-30 16:11:23 +080011148 Phone phone = getPhone(subId);
11149 if (phone == null) {
11150 return 0;
11151 }
11152 // Now that all security checks passes, perform the operation as ourselves.
11153 final long identity = Binder.clearCallingIdentity();
11154 try {
11155 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
11156 new Pair<Boolean, String>(enabled, password), phone, null);
11157 return attemptsRemaining;
11158
11159 } catch (Exception e) {
11160 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
11161 } finally {
11162 Binder.restoreCallingIdentity(identity);
11163 }
11164 return 0;
11165 }
11166
11167 /**
11168 * Change the ICC password used in ICC pin lock.
11169 *
11170 * @return an integer representing the status of IccLock changed in the following three cases:
11171 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
11172 * - Positive number and zero for remaining password attempts.
11173 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11174 *
11175 */
11176 @Override
11177 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
11178 enforceModifyPermission();
11179
joonhunshin4ac60942023-11-15 15:23:39 +000011180 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11181 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword");
11182
zoey chene02881a2019-12-30 16:11:23 +080011183 Phone phone = getPhone(subId);
11184 if (phone == null) {
11185 return 0;
11186 }
11187 // Now that all security checks passes, perform the operation as ourselves.
11188 final long identity = Binder.clearCallingIdentity();
11189 try {
11190 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
11191 new Pair<String, String>(oldPassword, newPassword), phone, null);
11192 return attemptsRemaining;
11193
11194 } catch (Exception e) {
11195 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
11196 } finally {
11197 Binder.restoreCallingIdentity(identity);
11198 }
11199 return 0;
11200 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080011201
11202 /**
11203 * Request for receiving user activity notification
11204 */
11205 @Override
11206 public void requestUserActivityNotification() {
11207 if (!mNotifyUserActivity.get()
11208 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
11209 mNotifyUserActivity.set(true);
11210 }
11211 }
11212
11213 /**
11214 * Called when userActivity is signalled in the power manager.
11215 * This is safe to call from any thread, with any window manager locks held or not.
11216 */
11217 @Override
11218 public void userActivity() {
11219 // ***************************************
11220 // * Inherited from PhoneWindowManager *
11221 // ***************************************
11222 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
11223 // WITH ITS LOCKS HELD.
11224 //
11225 // This code must be VERY careful about the locks
11226 // it acquires.
11227 // In fact, the current code acquires way too many,
11228 // and probably has lurking deadlocks.
11229
11230 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
11231 throw new SecurityException("Only the OS may call notifyUserActivity()");
11232 }
11233
11234 if (mNotifyUserActivity.getAndSet(false)) {
11235 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
11236 USER_ACTIVITY_NOTIFICATION_DELAY);
11237 }
11238 }
Malcolm Chen4639c562020-04-13 11:59:40 -070011239
11240 @Override
11241 public boolean canConnectTo5GInDsdsMode() {
11242 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
11243 }
Jack Yud10cdd42020-09-28 20:28:01 -070011244
11245 @Override
11246 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
11247 String callingFeatureId) {
11248 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
11249 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
11250 throw new SecurityException("Requires READ_PHONE_STATE permission.");
11251 }
11252
joonhunshin4ac60942023-11-15 15:23:39 +000011253 enforceTelephonyFeatureWithException(callingPackage,
11254 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns");
11255
Jack Yud10cdd42020-09-28 20:28:01 -070011256 Phone phone = getPhone(subId);
11257 if (phone == null) {
11258 throw new RuntimeException("phone is not available");
11259 }
11260 // Now that all security checks passes, perform the operation as ourselves.
11261 final long identity = Binder.clearCallingIdentity();
11262 try {
11263 return phone.getEquivalentHomePlmns();
11264 } finally {
11265 Binder.restoreCallingIdentity(identity);
11266 }
11267 }
Daniel Bright59e67312020-11-13 11:49:37 -080011268
11269 @Override
11270 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011271 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
joonhunshin4ac60942023-11-15 15:23:39 +000011272 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11273 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
11274 "isRadioInterfaceCapabilitySupported");
11275
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011276 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080011277 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080011278 if (radioInterfaceCapabilities == null) {
11279 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080011280 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011281 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080011282 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011283
Hui Wang641e81c2020-10-12 12:14:23 -070011284 @Override
11285 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
11286 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000011287 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
11288 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11289 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
11290 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11291 Manifest.permission.MODIFY_PHONE_STATE);
joonhunshin4ac60942023-11-15 15:23:39 +000011292
11293 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11294 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest");
11295
Hui Wang641e81c2020-10-12 12:14:23 -070011296 if (DBG) {
11297 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
11298 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
11299 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
11300 }
11301
11302 if (!SubscriptionManager.isValidSubscriptionId(subId)
11303 || appType < TelephonyManager.APPTYPE_UNKNOWN
11304 || appType > TelephonyManager.APPTYPE_ISIM
11305 || nafUrl == null || securityProtocol == null || callback == null) {
11306 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
11307 if (callback != null) {
11308 try {
11309 callback.onAuthenticationFailure(
11310 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
11311 } catch (RemoteException exception) {
11312 log("Fail to notify onAuthenticationFailure due to " + exception);
11313 }
11314 return;
11315 }
11316 }
11317
11318 final long token = Binder.clearCallingIdentity();
11319 try {
11320 getGbaManager(subId).bootstrapAuthenticationRequest(
11321 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011322 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070011323 } finally {
11324 Binder.restoreCallingIdentity(token);
11325 }
11326 }
11327
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011328 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011329 * Attempts to set the radio power state for all phones for thermal reason.
11330 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011331 * requested radio power state will actually be set. See {@link
11332 * PhoneInternalInterface#setRadioPowerForReason} for more details.
11333 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011334 * @param enable {@code true} if trying to turn radio on.
11335 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
11336 * false}.
11337 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011338 private boolean setRadioPowerForThermal(boolean enable) {
11339 boolean isPhoneAvailable = false;
11340 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
11341 Phone phone = PhoneFactory.getPhone(i);
11342 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011343 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011344 isPhoneAvailable = true;
11345 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011346 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011347
11348 // return true if successfully informed the phone object about the thermal radio power
11349 // request.
11350 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011351 }
11352
11353 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011354 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011355 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11356 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11357 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11358 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11359 throw new IllegalArgumentException("modem does not support data throttling");
11360 }
11361
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011362 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11363 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011364 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011365 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11366 }
11367
Sarah Chinecc78c42022-03-31 21:16:48 -070011368 setDataEnabledForReason(
11369 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011370
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011371 if (isDataThrottlingSupported) {
11372 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011373 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011374 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11375 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11376 } else if (thermalMitigationResult
11377 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011378 log("Modem likely does not support data throttling on secondary carrier. Data " +
11379 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11380 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011381 }
11382 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011383 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011384
11385 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011386 }
11387
Jack Nudelman644b91a2021-03-12 14:09:48 -080011388 private static List<String> getThermalMitigationAllowlist(Context context) {
11389 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11390 for (String pckg : context.getResources()
11391 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11392 sThermalMitigationAllowlistedPackages.add(pckg);
11393 }
11394 }
11395
11396 return sThermalMitigationAllowlistedPackages;
11397 }
11398
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011399 private boolean isAnyPhoneInEmergencyState() {
11400 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11401 if (tm.isInEmergencyCall()) {
11402 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11403 return true;
11404 }
11405 for (Phone phone : PhoneFactory.getPhones()) {
11406 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11407 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011408 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11409 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011410 return true;
11411 }
11412 }
11413
11414 return false;
11415 }
11416
Jack Nudelman644b91a2021-03-12 14:09:48 -080011417 /**
11418 * Used by shell commands to add an authorized package name for thermal mitigation.
11419 * @param packageName name of package to be allowlisted
11420 * @param context
11421 */
11422 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11423 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11424 sThermalMitigationAllowlistedPackages.add(packageName);
11425 }
11426
11427 /**
11428 * Used by shell commands to remove an authorized package name for thermal mitigation.
11429 * @param packageName name of package to remove from allowlist
11430 * @param context
11431 */
11432 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11433 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11434 sThermalMitigationAllowlistedPackages.remove(packageName);
11435 }
11436
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011437 /**
11438 * Thermal mitigation request to control functionalities at modem.
11439 *
11440 * @param subId the id of the subscription.
11441 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011442 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011443 *
11444 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11445 */
11446 @Override
11447 @ThermalMitigationResult
11448 public int sendThermalMitigationRequest(
11449 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011450 ThermalMitigationRequest thermalMitigationRequest,
11451 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011452 enforceModifyPermission();
11453
Jack Nudelman644b91a2021-03-12 14:09:48 -080011454 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000011455
11456 enforceTelephonyFeatureWithException(callingPackage,
11457 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest");
11458
Jack Nudelman644b91a2021-03-12 14:09:48 -080011459 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11460 .contains(callingPackage)) {
11461 throw new SecurityException("Calling package must be configured in the device config. "
11462 + "calling package: " + callingPackage);
11463 }
11464
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011465 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11466 final long identity = Binder.clearCallingIdentity();
11467
11468 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11469 try {
11470 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11471 switch (thermalMitigationAction) {
11472 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11473 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011474 handleDataThrottlingRequest(subId,
11475 thermalMitigationRequest.getDataThrottlingRequest(),
11476 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011477 break;
11478 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11479 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11480 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11481 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11482 }
11483
11484 // Ensure that radio is on. If not able to power on due to phone being
11485 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011486 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011487 thermalMitigationResult =
11488 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11489 break;
11490 }
11491
11492 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011493 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011494 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11495 break;
11496 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11497 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11498 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11499 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11500 }
11501
11502 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11503 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011504 Phone phone = getPhone(subId);
11505 if (phone == null) {
11506 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011507 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011508 break;
11509 }
11510
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011511 TelephonyConnectionService service =
11512 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011513 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011514 Log.e(LOG_TAG, "An emergency call is pending");
11515 thermalMitigationResult =
11516 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11517 break;
11518 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011519 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011520 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011521 break;
11522 }
11523 } else {
11524 thermalMitigationResult =
11525 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11526 break;
11527 }
11528
11529 // Turn radio off. If not able to power off due to phone being unavailable,
11530 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011531 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011532 thermalMitigationResult =
11533 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11534 break;
11535 }
11536 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011537 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011538 break;
11539 default:
11540 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11541 + "not exist. Requested action: " + thermalMitigationAction);
11542 }
11543 } catch (IllegalArgumentException e) {
11544 throw e;
11545 } catch (Exception e) {
11546 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11547 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11548 } finally {
11549 Binder.restoreCallingIdentity(identity);
11550 }
11551
11552 if (DBG) {
11553 log("thermalMitigationRequest returning with thermalMitigationResult: "
11554 + thermalMitigationResult);
11555 }
11556
11557 return thermalMitigationResult;
11558 }
Hui Wang641e81c2020-10-12 12:14:23 -070011559
11560 /**
11561 * Set the GbaService Package Name that Telephony will bind to.
11562 *
11563 * @param subId The sim that the GbaService is associated with.
11564 * @param packageName The name of the package to be replaced with.
11565 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11566 */
11567 @Override
11568 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11569 enforceModifyPermission();
11570
11571 final long identity = Binder.clearCallingIdentity();
11572 try {
11573 return getGbaManager(subId).overrideServicePackage(packageName);
11574 } finally {
11575 Binder.restoreCallingIdentity(identity);
11576 }
11577 }
11578
11579 /**
11580 * Return the package name of the currently bound GbaService.
11581 *
11582 * @param subId The sim that the GbaService is associated with.
11583 * @return the package name of the GbaService configuration, null if GBA is not supported.
11584 */
11585 @Override
11586 public String getBoundGbaService(int subId) {
11587 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11588
11589 final long identity = Binder.clearCallingIdentity();
11590 try {
11591 return getGbaManager(subId).getServicePackage();
11592 } finally {
11593 Binder.restoreCallingIdentity(identity);
11594 }
11595 }
11596
11597 /**
11598 * Set the release time for telephony to unbind GbaService.
11599 *
11600 * @param subId The sim that the GbaService is associated with.
11601 * @param interval The release time to unbind GbaService by millisecond.
11602 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11603 */
11604 @Override
11605 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11606 enforceModifyPermission();
11607
11608 final long identity = Binder.clearCallingIdentity();
11609 try {
11610 return getGbaManager(subId).overrideReleaseTime(interval);
11611 } finally {
11612 Binder.restoreCallingIdentity(identity);
11613 }
11614 }
11615
11616 /**
11617 * Return the release time for telephony to unbind GbaService.
11618 *
11619 * @param subId The sim that the GbaService is associated with.
11620 * @return The release time to unbind GbaService by millisecond.
11621 */
11622 @Override
11623 public int getGbaReleaseTime(int subId) {
11624 enforceReadPrivilegedPermission("getGbaReleaseTime");
11625
11626 final long identity = Binder.clearCallingIdentity();
11627 try {
11628 return getGbaManager(subId).getReleaseTime();
11629 } finally {
11630 Binder.restoreCallingIdentity(identity);
11631 }
11632 }
11633
11634 private GbaManager getGbaManager(int subId) {
11635 GbaManager instance = GbaManager.getInstance(subId);
11636 if (instance == null) {
11637 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11638 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11639 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11640 }
11641 return instance;
11642 }
Hui Wang761a6682020-10-31 05:12:53 +000011643
11644 /**
11645 * indicate whether the device and the carrier can support
11646 * RCS VoLTE single registration.
11647 */
11648 @Override
11649 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011650 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11651 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11652 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11653 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011654
11655 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11656 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11657 }
11658
11659 final long identity = Binder.clearCallingIdentity();
11660 try {
11661 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11662 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011663 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11664 if (isCapable != null) {
11665 return isCapable;
11666 }
Hui Wang761a6682020-10-31 05:12:53 +000011667 }
Hui Wang67af90e2021-06-04 16:57:15 -070011668 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11669 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011670 } finally {
11671 Binder.restoreCallingIdentity(identity);
11672 }
11673 }
11674
11675 /**
11676 * Register RCS provisioning callback.
11677 */
11678 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011679 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011680 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011681 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011682 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011683 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11684 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011685
11686 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11687 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11688 }
joonhunshin4ac60942023-11-15 15:23:39 +000011689 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11690 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11691 Binder.getCallingUserHandle())) {
11692 if (!isImsAvailableOnDevice()) {
11693 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11694 "IMS not available on device.");
11695 }
11696 } else {
11697 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11698 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011699 }
11700
11701 final long identity = Binder.clearCallingIdentity();
11702 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011703 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011704 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011705 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11706 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011707 }
Hui Wang761a6682020-10-31 05:12:53 +000011708 } finally {
11709 Binder.restoreCallingIdentity(identity);
11710 }
11711 }
11712
11713 /**
11714 * Unregister RCS provisioning callback.
11715 */
11716 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011717 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011718 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011719 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011720 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011721 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11722 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011723
11724 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11725 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11726 }
joonhunshin4ac60942023-11-15 15:23:39 +000011727
11728 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11729 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11730 Binder.getCallingUserHandle())) {
11731 if (!isImsAvailableOnDevice()) {
11732 // operation failed silently
11733 Rlog.w(LOG_TAG, "IMS not available on device.");
11734 return;
11735 }
11736 } else {
11737 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11738 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11739 "unregisterRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011740 }
11741
11742 final long identity = Binder.clearCallingIdentity();
11743 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011744 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011745 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011746 } finally {
11747 Binder.restoreCallingIdentity(identity);
11748 }
11749 }
11750
11751 /**
11752 * trigger RCS reconfiguration.
11753 */
11754 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011755 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11756 "triggerRcsReconfiguration",
11757 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011758
11759 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11760 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11761 }
joonhunshin4ac60942023-11-15 15:23:39 +000011762 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11763 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11764 Binder.getCallingUserHandle())) {
11765 if (!isImsAvailableOnDevice()) {
11766 // ProvisioningManager can not handle ServiceSpecificException.
11767 // Throw the IllegalStateException and annotate ProvisioningManager.
11768 throw new IllegalStateException("IMS not available on device.");
11769 }
11770 } else {
11771 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11772 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011773 }
11774
11775 final long identity = Binder.clearCallingIdentity();
11776 try {
11777 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11778 } finally {
11779 Binder.restoreCallingIdentity(identity);
11780 }
11781 }
11782
11783 /**
11784 * Provide the client configuration parameters of the RCS application.
11785 */
11786 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011787 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11788 "setRcsClientConfiguration",
11789 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011790
11791 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11792 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11793 }
joonhunshin4ac60942023-11-15 15:23:39 +000011794 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11795 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11796 Binder.getCallingUserHandle())) {
11797 if (!isImsAvailableOnDevice()) {
11798 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11799 "IMS not available on device.");
11800 }
11801 } else {
11802 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11803 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011804 }
11805
11806 final long identity = Binder.clearCallingIdentity();
11807
11808 try {
11809 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11810 if (configBinder == null) {
11811 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011812 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11813 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011814 } else {
11815 configBinder.setRcsClientConfiguration(rcc);
11816 }
joonhunshin3e154242021-09-17 06:33:39 +000011817
11818 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11819 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011820 } catch (RemoteException e) {
11821 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011822 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11823 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011824 } finally {
11825 Binder.restoreCallingIdentity(identity);
11826 }
11827 }
11828
11829 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011830 * Enables or disables the test mode for RCS VoLTE single registration.
11831 */
11832 @Override
11833 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11834 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11835 "setRcsSingleRegistrationTestModeEnabled");
11836
11837 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11838 }
11839
11840 /**
11841 * Gets the test mode for RCS VoLTE single registration.
11842 */
11843 @Override
11844 public boolean getRcsSingleRegistrationTestModeEnabled() {
11845 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11846 "getRcsSingleRegistrationTestModeEnabled");
11847
11848 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11849 }
11850
11851 /**
Hui Wang761a6682020-10-31 05:12:53 +000011852 * Overrides the config of RCS VoLTE single registration enabled for the device.
11853 */
11854 @Override
11855 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11856 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11857 "setDeviceSingleRegistrationEnabledOverride");
11858 enforceModifyPermission();
11859
11860 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11861 : Boolean.parseBoolean(enabledStr);
11862 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011863 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011864 }
11865
11866 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011867 * Sends a device to device communication message. Only usable via shell.
11868 * @param message message to send.
11869 * @param value message value.
11870 */
11871 @Override
11872 public void sendDeviceToDeviceMessage(int message, int value) {
11873 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011874 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011875 enforceModifyPermission();
11876
11877 final long identity = Binder.clearCallingIdentity();
11878 try {
11879 TelephonyConnectionService service =
11880 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11881 if (service == null) {
11882 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11883 return;
11884 }
11885 service.sendTestDeviceToDeviceMessage(message, value);
11886 } finally {
11887 Binder.restoreCallingIdentity(identity);
11888 }
11889 }
11890
Tyler Gunnbabbda02021-02-10 11:05:02 -080011891 /**
11892 * Sets the specified device to device transport active.
11893 * @param transport The transport to set active.
11894 */
11895 @Override
11896 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11897 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11898 "setActiveDeviceToDeviceTransport");
11899 enforceModifyPermission();
11900
11901 final long identity = Binder.clearCallingIdentity();
11902 try {
11903 TelephonyConnectionService service =
11904 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11905 if (service == null) {
11906 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11907 return;
11908 }
11909 service.setActiveDeviceToDeviceTransport(transport);
11910 } finally {
11911 Binder.restoreCallingIdentity(identity);
11912 }
11913 }
Tyler Gunn92479152021-01-20 16:30:10 -080011914
Tyler Gunnd4339262021-05-03 14:46:49 -070011915 @Override
11916 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11917 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11918 "setDeviceToDeviceForceEnabled");
11919
11920 final long identity = Binder.clearCallingIdentity();
11921 try {
11922 Arrays.stream(PhoneFactory.getPhones()).forEach(
11923 p -> {
11924 Phone thePhone = p.getImsPhone();
11925 if (thePhone != null && thePhone instanceof ImsPhone) {
11926 ImsPhone imsPhone = (ImsPhone) thePhone;
11927 CallTracker tracker = imsPhone.getCallTracker();
11928 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11929 ImsPhoneCallTracker imsPhoneCallTracker =
11930 (ImsPhoneCallTracker) tracker;
11931 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11932 }
11933 }
11934 }
11935 );
11936 } finally {
11937 Binder.restoreCallingIdentity(identity);
11938 }
11939 }
11940
Tyler Gunn92479152021-01-20 16:30:10 -080011941 /**
Hui Wang761a6682020-10-31 05:12:53 +000011942 * Gets the config of RCS VoLTE single registration enabled for the device.
11943 */
11944 @Override
11945 public boolean getDeviceSingleRegistrationEnabled() {
11946 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11947 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11948 }
11949
11950 /**
11951 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11952 */
11953 @Override
11954 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11955 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11956 "setCarrierSingleRegistrationEnabledOverride");
11957 enforceModifyPermission();
11958
11959 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11960 : Boolean.parseBoolean(enabledStr);
11961 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11962 subId, enabled);
11963 }
11964
11965 /**
11966 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11967 */
11968 @Override
11969 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11970 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11971 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11972 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011973
11974 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011975 * Overrides the ims feature validation result
11976 */
11977 @Override
11978 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11979 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11980 "setImsFeatureValidationOverride");
11981
11982 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11983 : Boolean.parseBoolean(enabledStr);
11984 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11985 subId, enabled);
11986 }
11987
11988 /**
11989 * Gets the ims feature validation override value
11990 */
11991 @Override
11992 public boolean getImsFeatureValidationOverride(int subId) {
11993 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11994 "getImsFeatureValidationOverride");
11995 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11996 }
11997
11998 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011999 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
12000 * their mobile plan.
12001 */
12002 @Override
12003 public String getMobileProvisioningUrl() {
12004 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
12005 final long identity = Binder.clearCallingIdentity();
12006 try {
12007 return getDefaultPhone().getMobileProvisioningUrl();
12008 } finally {
12009 Binder.restoreCallingIdentity(identity);
12010 }
12011 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012012
James.cf Linbcdf8b32021-01-14 16:44:13 +080012013 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080012014 * Get the EAB contact from the EAB database.
12015 */
12016 @Override
12017 public String getContactFromEab(String contact) {
12018 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
12019 enforceModifyPermission();
12020 final long identity = Binder.clearCallingIdentity();
12021 try {
12022 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
12023 } finally {
12024 Binder.restoreCallingIdentity(identity);
12025 }
12026 }
12027
12028 /**
Calvin Pana1434322021-07-01 19:27:01 +080012029 * Get the EAB capability from the EAB database.
12030 */
12031 @Override
12032 public String getCapabilityFromEab(String contact) {
12033 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
12034 enforceModifyPermission();
12035 final long identity = Binder.clearCallingIdentity();
12036 try {
12037 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
12038 } finally {
12039 Binder.restoreCallingIdentity(identity);
12040 }
12041 }
12042
12043 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080012044 * Remove the EAB contacts from the EAB database.
12045 */
12046 @Override
12047 public int removeContactFromEab(int subId, String contacts) {
12048 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
12049 enforceModifyPermission();
12050 final long identity = Binder.clearCallingIdentity();
12051 try {
12052 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
12053 } finally {
12054 Binder.restoreCallingIdentity(identity);
12055 }
12056 }
12057
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012058 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080012059 public boolean getDeviceUceEnabled() {
12060 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
12061 final long identity = Binder.clearCallingIdentity();
12062 try {
12063 return mApp.getDeviceUceEnabled();
12064 } finally {
12065 Binder.restoreCallingIdentity(identity);
12066 }
12067 }
12068
12069 @Override
12070 public void setDeviceUceEnabled(boolean isEnabled) {
12071 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
12072 final long identity = Binder.clearCallingIdentity();
12073 try {
12074 mApp.setDeviceUceEnabled(isEnabled);
12075 } finally {
12076 Binder.restoreCallingIdentity(identity);
12077 }
12078 }
12079
Brad Ebinger14d467f2021-02-12 06:18:28 +000012080 /**
12081 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
12082 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12083 */
12084 // Used for SHELL command only right now.
12085 @Override
12086 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
12087 List<String> featureTags) {
12088 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12089 "addUceRegistrationOverrideShell");
12090 final long identity = Binder.clearCallingIdentity();
12091 try {
12092 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
12093 new ArraySet<>(featureTags));
12094 } catch (ImsException e) {
12095 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12096 } finally {
12097 Binder.restoreCallingIdentity(identity);
12098 }
12099 }
12100
12101 /**
12102 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
12103 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12104 */
12105 // Used for SHELL command only right now.
12106 @Override
12107 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
12108 List<String> featureTags) {
12109 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12110 "removeUceRegistrationOverrideShell");
12111 final long identity = Binder.clearCallingIdentity();
12112 try {
12113 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
12114 new ArraySet<>(featureTags));
12115 } catch (ImsException e) {
12116 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12117 } finally {
12118 Binder.restoreCallingIdentity(identity);
12119 }
12120 }
12121
12122 /**
12123 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
12124 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12125 */
12126 // Used for SHELL command only right now.
12127 @Override
12128 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
12129 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12130 "clearUceRegistrationOverrideShell");
12131 final long identity = Binder.clearCallingIdentity();
12132 try {
12133 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
12134 } catch (ImsException e) {
12135 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12136 } finally {
12137 Binder.restoreCallingIdentity(identity);
12138 }
12139 }
12140
12141 /**
12142 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12143 */
12144 // Used for SHELL command only right now.
12145 @Override
12146 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
12147 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12148 "getLatestRcsContactUceCapabilityShell");
12149 final long identity = Binder.clearCallingIdentity();
12150 try {
12151 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
12152 } catch (ImsException e) {
12153 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12154 } finally {
12155 Binder.restoreCallingIdentity(identity);
12156 }
12157 }
12158
12159 /**
12160 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
12161 * device does not have an active PUBLISH.
12162 */
12163 // Used for SHELL command only right now.
12164 @Override
12165 public String getLastUcePidfXmlShell(int subId) {
12166 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
12167 final long identity = Binder.clearCallingIdentity();
12168 try {
12169 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
12170 } catch (ImsException e) {
12171 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12172 } finally {
12173 Binder.restoreCallingIdentity(identity);
12174 }
12175 }
12176
James.cf Line8713a42021-04-29 16:04:26 +080012177 /**
12178 * Remove UCE requests cannot be sent to the network status.
12179 */
12180 // Used for SHELL command only right now.
12181 @Override
12182 public boolean removeUceRequestDisallowedStatus(int subId) {
12183 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
12184 final long identity = Binder.clearCallingIdentity();
12185 try {
12186 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
12187 } catch (ImsException e) {
12188 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12189 } finally {
12190 Binder.restoreCallingIdentity(identity);
12191 }
12192 }
12193
James.cf Lin18bb9002021-05-25 01:37:38 +080012194 /**
12195 * Remove UCE requests cannot be sent to the network status.
12196 */
12197 // Used for SHELL command only.
12198 @Override
12199 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
12200 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
12201 final long identity = Binder.clearCallingIdentity();
12202 try {
12203 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
12204 } catch (ImsException e) {
12205 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12206 } finally {
12207 Binder.restoreCallingIdentity(identity);
12208 }
12209 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000012210
James.cf Lin4b784aa2021-01-31 03:25:15 +080012211 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012212 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12213 String callingPackage) {
12214 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12215 mApp, subId, "setSignalStrengthUpdateRequest");
12216
joonhunshin4ac60942023-11-15 15:23:39 +000012217 enforceTelephonyFeatureWithException(callingPackage,
12218 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest");
12219
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012220 final int callingUid = Binder.getCallingUid();
12221 // Verify that tha callingPackage belongs to the calling UID
12222 mApp.getSystemService(AppOpsManager.class)
12223 .checkPackage(callingUid, callingPackage);
12224
Rambo Wang3607f502021-02-01 21:51:40 -080012225 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012226
12227 final long identity = Binder.clearCallingIdentity();
12228 try {
12229 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
12230 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12231
12232 if (result instanceof IllegalStateException) {
12233 throw (IllegalStateException) result;
12234 }
12235 } finally {
12236 Binder.restoreCallingIdentity(identity);
12237 }
12238 }
12239
12240 @Override
12241 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12242 String callingPackage) {
12243 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12244 mApp, subId, "clearSignalStrengthUpdateRequest");
12245
joonhunshin4ac60942023-11-15 15:23:39 +000012246 enforceTelephonyFeatureWithException(callingPackage,
12247 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest");
12248
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012249 final int callingUid = Binder.getCallingUid();
12250 // Verify that tha callingPackage belongs to the calling UID
12251 mApp.getSystemService(AppOpsManager.class)
12252 .checkPackage(callingUid, callingPackage);
12253
12254 final long identity = Binder.clearCallingIdentity();
12255 try {
12256 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
12257 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12258
12259 if (result instanceof IllegalStateException) {
12260 throw (IllegalStateException) result;
12261 }
12262 } finally {
12263 Binder.restoreCallingIdentity(identity);
12264 }
12265 }
12266
Rambo Wang3607f502021-02-01 21:51:40 -080012267 private static void validateSignalStrengthUpdateRequest(Context context,
12268 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012269 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
12270 // phone/system process do not have further restriction on request
12271 return;
12272 }
12273
12274 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080012275 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012276 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080012277 context.enforceCallingOrSelfPermission(
12278 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
12279 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012280 }
12281
12282 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000012283 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012284 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012285 || info.isEnabled()) {
12286 throw new IllegalArgumentException(
12287 "Only system can set hide fields in SignalThresholdInfo");
12288 }
12289
12290 // Thresholds length for each RAN need in range. This has been validated in
12291 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
12292 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
12293 final int[] thresholds = info.getThresholds();
12294 Objects.requireNonNull(thresholds);
12295 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
12296 || thresholds.length
12297 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
12298 throw new IllegalArgumentException(
12299 "thresholds length is out of range: " + thresholds.length);
12300 }
12301 }
12302 }
SongFerngWang8236caa2021-01-17 21:51:44 +080012303
12304 /**
12305 * Gets the current phone capability.
12306 *
12307 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
12308 * @return the PhoneCapability which describes the data connection capability of modem.
12309 * It's used to evaluate possible phone config change, for example from single
12310 * SIM device to multi-SIM device.
12311 */
12312 @Override
12313 public PhoneCapability getPhoneCapability() {
12314 enforceReadPrivilegedPermission("getPhoneCapability");
joonhunshin4ac60942023-11-15 15:23:39 +000012315
12316 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12317 PackageManager.FEATURE_TELEPHONY, "getPhoneCapability");
12318
SongFerngWang8236caa2021-01-17 21:51:44 +080012319 final long identity = Binder.clearCallingIdentity();
12320 try {
12321 return mPhoneConfigurationManager.getCurrentPhoneCapability();
12322 } finally {
12323 Binder.restoreCallingIdentity(identity);
12324 }
12325 }
Michele Berionne5e411512020-11-13 02:36:59 +000012326
12327 /**
12328 * Prepare TelephonyManager for an unattended reboot. The reboot is
12329 * required to be done shortly after the API is invoked.
12330 */
12331 @Override
12332 @TelephonyManager.PrepareUnattendedRebootResult
12333 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012334 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000012335 enforceRebootPermission();
12336
joonhunshin4ac60942023-11-15 15:23:39 +000012337 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12338 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot");
12339
Michele Berionne5e411512020-11-13 02:36:59 +000012340 final long identity = Binder.clearCallingIdentity();
12341 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012342 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000012343 } finally {
12344 Binder.restoreCallingIdentity(identity);
12345 }
12346 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012347
12348 /**
12349 * Request to get the current slicing configuration including URSP rules and
12350 * NSSAIs (configured, allowed and rejected).
12351 *
12352 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
12353 */
12354 @Override
12355 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000012356 TelephonyPermissions
12357 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
12358 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012359
joonhunshin4ac60942023-11-15 15:23:39 +000012360 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12361 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
12362 "getSlicingConfig");
12363
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012364 final long identity = Binder.clearCallingIdentity();
12365 try {
12366 Phone phone = getDefaultPhone();
12367 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
12368 } finally {
12369 Binder.restoreCallingIdentity(identity);
12370 }
12371 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012372
12373 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070012374 * Check whether the given premium capability is available for purchase from the carrier.
12375 *
12376 * @param capability The premium capability to check.
12377 * @param subId The subId to check the premium capability for.
12378 *
12379 * @return Whether the given premium capability is available to purchase.
12380 */
12381 @Override
12382 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
12383 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12384 mApp, "isPremiumCapabilityAvailableForPurchase")) {
12385 log("Premium capability "
12386 + TelephonyManager.convertPremiumCapabilityToString(capability)
12387 + " is not available for purchase due to missing permissions.");
12388 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
12389 + "permission READ_BASIC_PHONE_STATE.");
12390 }
12391
joonhunshin4ac60942023-11-15 15:23:39 +000012392 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12393 PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase");
12394
Sarah Chin2ec39f62022-08-31 17:03:26 -070012395 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080012396 if (phone == null) {
12397 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12398 return false;
12399 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012400 final long identity = Binder.clearCallingIdentity();
12401 try {
Sarah Chincc5446f2023-10-23 17:57:19 -070012402 return SlicePurchaseController.getInstance(phone, mFeatureFlags)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012403 .isPremiumCapabilityAvailableForPurchase(capability);
12404 } finally {
12405 Binder.restoreCallingIdentity(identity);
12406 }
12407 }
12408
12409 /**
12410 * Purchase the given premium capability from the carrier.
12411 *
12412 * @param capability The premium capability to purchase.
12413 * @param callback The result of the purchase request.
12414 * @param subId The subId to purchase the premium capability for.
12415 */
12416 @Override
12417 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12418 log("purchasePremiumCapability: capability="
12419 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12420 + getCurrentPackageName());
12421
12422 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12423 mApp, "purchasePremiumCapability")) {
12424 log("purchasePremiumCapability "
12425 + TelephonyManager.convertPremiumCapabilityToString(capability)
12426 + " failed due to missing permissions.");
12427 throw new SecurityException("purchasePremiumCapability requires permission "
12428 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012429 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12430 mApp, "purchasePremiumCapability")) {
12431 log("purchasePremiumCapability "
12432 + TelephonyManager.convertPremiumCapabilityToString(capability)
12433 + " failed due to missing permissions.");
12434 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012435 }
12436
joonhunshin4ac60942023-11-15 15:23:39 +000012437 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12438 PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability");
12439
Sarah Chin2ec39f62022-08-31 17:03:26 -070012440 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012441 if (phone == null) {
12442 try {
12443 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12444 callback.accept(result);
12445 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12446 } catch (RemoteException e) {
12447 String logStr = "Purchase premium capability "
12448 + TelephonyManager.convertPremiumCapabilityToString(capability)
12449 + " failed due to RemoteException handling null phone: " + e;
12450 if (DBG) log(logStr);
12451 AnomalyReporter.reportAnomaly(
12452 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12453 }
12454 return;
12455 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012456
12457 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012458 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012459 callingProcess = mApp.getPackageManager().getApplicationInfo(
12460 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070012461 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012462 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012463 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012464
12465 boolean isVisible = false;
12466 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12467 if (am != null) {
12468 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12469 if (processes != null) {
12470 for (ActivityManager.RunningAppProcessInfo process : processes) {
12471 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070012472 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080012473 if (process.processName.equals(callingProcess) && process.importance
12474 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12475 isVisible = true;
12476 break;
12477 }
12478 }
12479 }
12480 }
12481
12482 if (!isVisible) {
12483 try {
12484 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12485 callback.accept(result);
12486 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12487 } catch (RemoteException e) {
12488 String logStr = "Purchase premium capability "
12489 + TelephonyManager.convertPremiumCapabilityToString(capability)
12490 + " failed due to RemoteException handling background application: " + e;
12491 if (DBG) log(logStr);
12492 AnomalyReporter.reportAnomaly(
12493 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12494 }
12495 return;
12496 }
12497
Sarah Chin71b3a852022-09-28 15:54:19 -070012498 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012499 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012500 }
12501
12502 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012503 * Register an IMS connection state callback
12504 */
12505 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012506 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12507 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012508 if (feature == ImsFeature.FEATURE_MMTEL) {
12509 // ImsMmTelManager
12510 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12511 TelephonyPermissions
12512 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12513 mApp, subId, "registerImsStateCallback");
12514 } else if (feature == ImsFeature.FEATURE_RCS) {
12515 // ImsRcsManager or SipDelegateManager
12516 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12517 Binder.getCallingUid(), "registerImsStateCallback",
12518 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12519 Manifest.permission.READ_PRECISE_PHONE_STATE,
12520 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12521 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12522 }
12523
12524 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12525 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12526 "IMS not available on device.");
12527 }
12528
12529 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12530 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12531 }
12532
12533 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12534 if (controller == null) {
12535 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12536 "IMS not available on device.");
12537 }
12538
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012539 if (callingPackage == null) {
12540 callingPackage = getCurrentPackageName();
12541 }
12542
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012543 final long token = Binder.clearCallingIdentity();
12544 try {
12545 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012546 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012547 } catch (ImsException e) {
12548 throw new ServiceSpecificException(e.getCode());
12549 } finally {
12550 Binder.restoreCallingIdentity(token);
12551 }
12552 }
12553
12554 /**
12555 * Unregister an IMS connection state callback
12556 */
12557 @Override
12558 public void unregisterImsStateCallback(IImsStateCallback cb) {
12559 final long token = Binder.clearCallingIdentity();
12560 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12561 if (controller == null) {
12562 return;
12563 }
12564 try {
12565 controller.unregisterImsStateCallback(cb);
12566 } finally {
12567 Binder.restoreCallingIdentity(token);
12568 }
12569 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012570
12571 /**
12572 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12573 *
12574 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012575 * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012576 * SecurityException.
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012577 *
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012578 * If there is current registered network this value will be same as the registered cell
12579 * identity. If the device goes out of service the previous cell identity is cached and
12580 * will be returned. If the cache age of the Cell identity is more than 24 hours
12581 * it will be cleared and null will be returned.
12582 *
12583 */
12584 @Override
12585 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12586 String callingFeatureId) {
12587 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12588 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12589 LocationAccessPolicy.checkLocationPermission(mApp,
12590 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12591 .setCallingPackage(callingPackage)
12592 .setCallingFeatureId(callingFeatureId)
12593 .setCallingPid(Binder.getCallingPid())
12594 .setCallingUid(Binder.getCallingUid())
12595 .setMethod("getLastKnownCellIdentity")
12596 .setLogAsInfo(true)
12597 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12598 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12599 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12600 .build());
12601
12602 boolean hasFinePermission =
12603 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12604 if (!hasFinePermission
12605 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12606 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012607 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012608 }
12609
12610 final long identity = Binder.clearCallingIdentity();
12611 try {
Ling Mac28f0212023-03-24 16:07:15 -070012612 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012613 if (sst == null) return null;
12614 return sst.getLastKnownCellIdentity();
12615 } finally {
12616 Binder.restoreCallingIdentity(identity);
12617 }
12618 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012619
jimsun3b9ccac2021-10-26 15:01:23 +080012620 /**
12621 * Sets the modem service class Name that Telephony will bind to.
12622 *
12623 * @param serviceName The class name of the modem service.
12624 * @return true if the operation is succeed, otherwise false.
12625 */
12626 public boolean setModemService(String serviceName) {
12627 Log.d(LOG_TAG, "setModemService - " + serviceName);
12628 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12629 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012630 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12631 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012632 return mPhoneConfigurationManager.setModemService(serviceName);
12633 }
12634
12635 /**
12636 * Return the class name of the currently bounded modem service.
12637 *
12638 * @return the class name of the modem service.
12639 */
12640 public String getModemService() {
12641 String result;
12642 Log.d(LOG_TAG, "getModemService");
12643 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12644 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012645 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012646 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12647 "getModemService");
12648 result = mPhoneConfigurationManager.getModemService();
12649 Log.d(LOG_TAG, "result = " + result);
12650 return result;
12651 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012652
Hakjun Choi3ee81112023-12-19 15:40:58 +000012653 /**
12654 * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources,
12655 * including carrier config, entitlement server, and config update.
12656 *
12657 * @param subId subId The subscription ID of the carrier.
12658 *
12659 * @return List of plmns for carrier satellite service. If no plmn is available, empty list will
12660 * be returned.
12661 *
12662 * @throws SecurityException if the caller doesn't have the required permission.
12663 */
Hakjun Choi74c16be2024-01-19 08:18:09 +000012664 @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) {
12665 enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier");
Hakjun Choi3ee81112023-12-19 15:40:58 +000012666 final long identity = Binder.clearCallingIdentity();
12667 try {
Hakjun Choi74c16be2024-01-19 08:18:09 +000012668 return mSatelliteController.getSatellitePlmnsForCarrier(subId);
Hakjun Choi3ee81112023-12-19 15:40:58 +000012669 } finally {
12670 Binder.restoreCallingIdentity(identity);
12671 }
12672 }
12673
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012674 @Override
12675 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12676 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12677 mApp.enforceCallingOrSelfPermission(
12678 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12679 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12680
12681 final long identity = Binder.clearCallingIdentity();
12682 try {
12683 Phone phone = getPhone(subId);
12684 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012685 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12686 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012687 phone.setVoiceServiceStateOverride(hasService);
12688 } finally {
12689 Binder.restoreCallingIdentity(identity);
12690 }
12691 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012692
12693 /**
12694 * set removable eSIM as default eUICC.
12695 *
12696 * @hide
12697 */
12698 @Override
12699 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12700 enforceModifyPermission();
12701 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12702
12703 final long identity = Binder.clearCallingIdentity();
12704 try {
12705 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12706 } finally {
12707 Binder.restoreCallingIdentity(identity);
12708 }
12709 }
12710
12711 /**
12712 * Returns whether the removable eSIM is default eUICC or not.
12713 *
12714 * @hide
12715 */
12716 @Override
12717 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12718 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12719 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12720
12721 final long identity = Binder.clearCallingIdentity();
12722 try {
12723 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12724 } finally {
12725 Binder.restoreCallingIdentity(identity);
12726 }
12727 }
12728
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012729 /**
12730 * Get the component name of the default app to direct respond-via-message intent for the
12731 * user associated with this subscription, update the cache if there is no respond-via-message
12732 * application currently configured for this user.
12733 * @return component name of the app and class to direct Respond Via Message intent to, or
12734 * {@code null} if the functionality is not supported.
12735 * @hide
12736 */
12737 @Override
12738 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12739 boolean updateIfNeeded) {
12740 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012741
joonhunshin4ac60942023-11-15 15:23:39 +000012742 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12743 PackageManager.FEATURE_TELEPHONY_MESSAGING,
12744 "getDefaultRespondViaMessageApplication");
12745
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012746 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12747
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012748 UserHandle userHandle = null;
12749 final long identity = Binder.clearCallingIdentity();
12750 try {
12751 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12752 } finally {
12753 Binder.restoreCallingIdentity(identity);
12754 }
12755 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12756 updateIfNeeded, userHandle);
12757 }
Jack Yuf5badd92022-12-08 00:50:53 -080012758
12759 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012760 * Set whether the device is able to connect with null ciphering or integrity
12761 * algorithms. This is a global setting and will apply to all active subscriptions
12762 * and all new subscriptions after this.
12763 *
12764 * @param enabled when true, null cipher and integrity algorithms are allowed.
12765 * @hide
12766 */
12767 @Override
12768 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12769 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12770 enforceModifyPermission();
12771 checkForNullCipherAndIntegritySupport();
12772
12773 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12774 // for listening to these preference changes and applying them immediately.
12775 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12776 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12777 editor.apply();
12778
12779 for (Phone phone: PhoneFactory.getPhones()) {
12780 phone.handleNullCipherEnabledChange();
12781 }
12782 }
12783
12784
12785 /**
12786 * Get whether the device is able to connect with null ciphering or integrity
12787 * algorithms. Note that this retrieves the phone-global preference and not
12788 * the state of the radio.
12789 *
12790 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12791 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12792 * version for this feature.
12793 * @hide
12794 */
12795 @Override
12796 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12797 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12798 enforceReadPermission();
12799 checkForNullCipherAndIntegritySupport();
12800 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12801 }
12802
12803 private void checkForNullCipherAndIntegritySupport() {
12804 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12805 throw new UnsupportedOperationException(
12806 "Null cipher and integrity operations require HAL 2.1 or above");
12807 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012808 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12809 throw new UnsupportedOperationException(
12810 "Null cipher and integrity operations unsupported by modem");
12811 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012812 }
12813
Gil Cukierman06403e12023-11-29 16:33:03 +000012814 private void checkForIdentifierDisclosureNotificationSupport() {
12815 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) {
12816 throw new UnsupportedOperationException(
12817 "Cellular identifier disclosure transparency operations require HAL 2.2 or "
12818 + "above");
12819 }
12820 if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) {
12821 throw new UnsupportedOperationException(
12822 "Cellular identifier disclosure transparency operations unsupported by modem");
12823 }
12824 }
12825
Michael Groover826b71d2023-12-21 22:08:06 -060012826 private void checkForNullCipherNotificationSupport() {
12827 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) {
12828 throw new UnsupportedOperationException(
12829 "Null cipher notification operations require HAL 2.2 or above");
12830 }
12831 if (!getDefaultPhone().isNullCipherNotificationSupported()) {
12832 throw new UnsupportedOperationException(
12833 "Null cipher notification operations unsupported by modem");
12834 }
12835 }
12836
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012837 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012838 * Get the SIM state for the slot index.
12839 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12840 *
12841 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12842 */
12843 @Override
12844 @SimState
12845 public int getSimStateForSlotIndex(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +000012846 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12847 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex");
12848
Jack Yuf5badd92022-12-08 00:50:53 -080012849 IccCardConstants.State simState;
12850 if (slotIndex < 0) {
12851 simState = IccCardConstants.State.UNKNOWN;
12852 } else {
12853 Phone phone = null;
12854 try {
12855 phone = PhoneFactory.getPhone(slotIndex);
12856 } catch (IllegalStateException e) {
12857 // ignore
12858 }
12859 if (phone == null) {
12860 simState = IccCardConstants.State.UNKNOWN;
12861 } else {
12862 IccCard icc = phone.getIccCard();
12863 if (icc == null) {
12864 simState = IccCardConstants.State.UNKNOWN;
12865 } else {
12866 simState = icc.getState();
12867 }
12868 }
12869 }
12870 return simState.ordinal();
12871 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012872
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012873 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
12874 boolean enableLogcat,
12875 long logcatStartTimestampMillis, boolean enableTelecomDump,
12876 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012877 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012878 TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder =
12879 new TelephonyManager.EmergencyCallDiagnosticData.Builder();
12880 ecdDataBuilder
12881 .setTelecomDumpsysCollectionEnabled(enableTelecomDump)
12882 .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012883 if (enableLogcat) {
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012884 ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012885 }
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012886 TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build();
12887 Log.d(LOG_TAG, "persisting with Params " + ecdData.toString());
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012888 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
12889 Executors.newCachedThreadPool(), db,
12890 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012891 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012892 }
12893
12894 /**
12895 * Request telephony to persist state for debugging emergency call failures.
12896 *
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012897 * @param dropboxTag Tag to use when persisting data to dropbox service.
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012898 * @param enableLogcat whether to collect logcat output
12899 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
12900 * @param enableTelecomDump whether to collect telecom dumpsys
12901 * @param enableTelephonyDump whether to collect telephony dumpsys
12902 */
12903 @Override
12904 @RequiresPermission(android.Manifest.permission.DUMP)
12905 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
12906 long logcatStartTimestampMillis, boolean enableTelecomDump,
12907 boolean enableTelephonyDump) {
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -080012908 // Verify that the caller has READ_DROPBOX_DATA permission.
12909 if (mTelecomFeatureFlags.telecomResolveHiddenDependencies()
12910 && Flags.enableReadDropboxPermission()) {
12911 mApp.enforceCallingPermission(permission.READ_DROPBOX_DATA,
12912 "persistEmergencyCallDiagnosticData");
12913 } else {
12914 // Otherwise, enforce legacy permission.
12915 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
12916 "persistEmergencyCallDiagnosticData");
12917 }
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012918 final long identity = Binder.clearCallingIdentity();
12919 try {
12920 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
12921 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
12922
12923 } finally {
12924 Binder.restoreCallingIdentity(identity);
12925 }
12926 }
12927
Hui Wang9b5793a2022-12-05 14:38:06 -060012928 /**
12929 * Get current cell broadcast ranges.
12930 */
12931 @Override
12932 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12933 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12934 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12935 "getCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012936
12937 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12938 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges");
12939
Hui Wang9b5793a2022-12-05 14:38:06 -060012940 final long identity = Binder.clearCallingIdentity();
12941 try {
12942 return getPhone(subId).getCellBroadcastIdRanges();
12943 } finally {
12944 Binder.restoreCallingIdentity(identity);
12945 }
12946 }
12947
12948 /**
12949 * Set reception of cell broadcast messages with the list of the given ranges
12950 *
12951 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12952 */
12953 @Override
12954 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12955 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12956 @Nullable IIntegerConsumer callback) {
12957 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12958 "setCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012959
12960 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12961 PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges");
12962
Hui Wang9b5793a2022-12-05 14:38:06 -060012963 final long identity = Binder.clearCallingIdentity();
12964 try {
12965 Phone phone = getPhoneFromSubId(subId);
12966 if (DBG) {
12967 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12968 }
12969 phone.setCellBroadcastIdRanges(ranges, result -> {
12970 if (callback != null) {
12971 try {
12972 callback.accept(result);
12973 } catch (RemoteException e) {
12974 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12975 }
12976 }
12977 });
12978 } finally {
12979 Binder.restoreCallingIdentity(identity);
12980 }
12981 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012982
12983 /**
12984 * Returns whether the device supports the domain selection service.
12985 *
12986 * @return {@code true} if the device supports the domain selection service.
12987 */
12988 @Override
12989 public boolean isDomainSelectionSupported() {
12990 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12991 "isDomainSelectionSupported");
12992
12993 final long identity = Binder.clearCallingIdentity();
12994 try {
12995 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12996 } finally {
12997 Binder.restoreCallingIdentity(identity);
12998 }
12999 }
arunvoddud5c6ce02022-12-11 06:03:12 +000013000
13001 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013002 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
13003 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
13004 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080013005 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013006 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chinabf081b2023-03-09 23:00:57 -080013007 * @param enableSatellite {@code true} to enable the satellite modem and
13008 * {@code false} to disable.
13009 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
Thomas Nguyena8062672024-02-05 14:18:19 -080013010 * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise.
Sarah Chinabf081b2023-03-09 23:00:57 -080013011 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080013012 *
13013 * @throws SecurityException if the caller doesn't have the required permission.
13014 */
13015 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013016 public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode,
Thomas Nguyena8062672024-02-05 14:18:19 -080013017 boolean isEmergency, @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013018 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013019 if (enableSatellite) {
13020 ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) {
13021 @Override
13022 protected void onReceiveResult(int resultCode, Bundle resultData) {
13023 Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode
13024 + ", resultData=" + resultData);
13025 boolean isAllowed = false;
13026 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(
13027 callback::accept);
13028 if (resultCode == SATELLITE_RESULT_SUCCESS) {
13029 if (resultData != null
13030 && resultData.containsKey(KEY_SATELLITE_COMMUNICATION_ALLOWED)) {
13031 isAllowed = resultData.getBoolean(KEY_SATELLITE_COMMUNICATION_ALLOWED);
13032 } else {
13033 loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist.");
13034 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013035 } else {
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013036 result.accept(resultCode);
13037 return;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013038 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013039 if (isAllowed) {
13040 mSatelliteController.requestSatelliteEnabled(
Hyosun Kimab304792024-03-29 09:18:03 +000013041 subId, enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013042 } else {
13043 result.accept(SATELLITE_RESULT_ACCESS_BARRED);
13044 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013045 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013046 };
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013047 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013048 subId, resultReceiver);
13049 } else {
13050 // No need to check if satellite is allowed at current location when disabling satellite
13051 mSatelliteController.requestSatelliteEnabled(
Hyosun Kimab304792024-03-29 09:18:03 +000013052 subId, enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013053 }
Sarah Chin503828c2023-02-01 23:54:20 -080013054 }
13055
13056 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013057 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080013058 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013059 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013060 * @param result The result receiver that returns whether the satellite modem is enabled
13061 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013062 *
13063 * @throws SecurityException if the caller doesn't have the required permission.
13064 */
13065 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013066 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
13067 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013068 mSatelliteController.requestIsSatelliteEnabled(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013069 }
13070
13071 /**
Sarah Chin43457982023-02-15 17:50:38 -080013072 * Request to get whether the satellite service demo mode is enabled.
13073 *
13074 * @param subId The subId of the subscription to check whether the satellite demo mode
13075 * is enabled for.
13076 * @param result The result receiver that returns whether the satellite demo mode is enabled
13077 * if the request is successful or an error code if the request failed.
13078 *
13079 * @throws SecurityException if the caller doesn't have the required permission.
13080 */
13081 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013082 public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
13083 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
13084 mSatelliteController.requestIsDemoModeEnabled(subId, result);
Sarah Chin43457982023-02-15 17:50:38 -080013085 }
13086
13087 /**
Thomas Nguyena8062672024-02-05 14:18:19 -080013088 * Request to get whether the satellite service is enabled with emergency mode.
13089 *
13090 * @param subId The subId of the subscription to check whether the satellite demo mode
13091 * is enabled for.
13092 * @param result The result receiver that returns whether the satellite emergency mode is
13093 * enabled if the request is successful or an error code if the request failed.
13094 *
13095 * @throws SecurityException if the caller doesn't have the required permission.
13096 */
13097 @Override
13098 public void requestIsEmergencyModeEnabled(int subId, @NonNull ResultReceiver result) {
13099 enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled");
13100 result.send(SATELLITE_RESULT_REQUEST_NOT_SUPPORTED, null);
13101 }
13102
13103 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013104 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080013105 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013106 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013107 * @param result The result receiver that returns whether the satellite service is supported on
13108 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013109 */
13110 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013111 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013112 mSatelliteController.requestIsSatelliteSupported(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013113 }
13114
13115 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013116 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080013117 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013118 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013119 * @param result The result receiver that returns the {@link SatelliteCapabilities}
13120 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013121 *
13122 * @throws SecurityException if the caller doesn't have required permission.
13123 */
13124 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013125 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
13126 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013127 mSatelliteController.requestSatelliteCapabilities(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013128 }
13129
13130 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013131 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013132 * This can be called by the pointing UI when the user starts pointing to the satellite.
13133 * Modem should continue to report the pointing input as the device or satellite moves.
13134 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013135 * @param subId The subId of the subscription to start satellite transmission updates for.
13136 * @param resultCallback The callback to get the result of the request.
13137 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080013138 *
13139 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013140 */
13141 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013142 public void startSatelliteTransmissionUpdates(int subId,
13143 @NonNull IIntegerConsumer resultCallback,
13144 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13145 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
13146 mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080013147 }
13148
13149 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013150 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013151 * This can be called by the pointing UI when the user stops pointing to the satellite.
13152 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013153 * @param subId The subId of the subscription to stop satellite transmission updates for.
13154 * @param resultCallback The callback to get the result of the request.
13155 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
13156 * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080013157 *
13158 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013159 */
13160 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013161 public void stopSatelliteTransmissionUpdates(int subId,
13162 @NonNull IIntegerConsumer resultCallback,
13163 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13164 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
13165 mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013166 }
13167
13168 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013169 * Register the subscription with a satellite provider.
13170 * This is needed to register the subscription if the provider allows dynamic registration.
13171 *
13172 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013173 * @param token The token to be used as a unique identifier for provisioning with satellite
13174 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013175 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080013176 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013177 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013178 * @return The signal transport used by the caller to cancel the provision request,
13179 * or {@code null} if the request failed.
13180 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013181 * @throws SecurityException if the caller doesn't have the required permission.
13182 */
13183 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013184 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013185 @NonNull String token, @NonNull byte[] provisionData,
13186 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013187 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013188 return mSatelliteController.provisionSatelliteService(subId, token, provisionData,
13189 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013190 }
13191
13192 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013193 * Unregister the device/subscription with the satellite provider.
13194 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013195 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013196 * should report as deprovisioned.
13197 *
13198 * @param subId The subId of the subscription to be deprovisioned.
13199 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080013200 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013201 *
13202 * @throws SecurityException if the caller doesn't have the required permission.
13203 */
13204 @Override
13205 public void deprovisionSatelliteService(int subId,
13206 @NonNull String token, @NonNull IIntegerConsumer callback) {
13207 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013208 mSatelliteController.deprovisionSatelliteService(subId, token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013209 }
13210
13211 /**
Sarah Chin43457982023-02-15 17:50:38 -080013212 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013213 *
Sarah Chin43457982023-02-15 17:50:38 -080013214 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013215 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013216 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013217 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013218 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013219 * @throws SecurityException if the caller doesn't have the required permission.
13220 */
13221 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013222 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
13223 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013224 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013225 return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013226 }
13227
13228 /**
Sarah Chin43457982023-02-15 17:50:38 -080013229 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013230 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013231 *
Sarah Chin43457982023-02-15 17:50:38 -080013232 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013233 * @param callback The callback that was passed to
13234 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013235 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013236 * @throws SecurityException if the caller doesn't have the required permission.
13237 */
13238 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013239 public void unregisterForSatelliteProvisionStateChanged(
13240 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013241 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013242 mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013243 }
13244
13245 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013246 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013247 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013248 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013249 * @param result The result receiver that returns whether the device is provisioned with a
13250 * satellite provider if the request is successful or an error code if the
13251 * request failed.
13252 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013253 * @throws SecurityException if the caller doesn't have the required permission.
13254 */
13255 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013256 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
13257 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013258 mSatelliteController.requestIsSatelliteProvisioned(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013259 }
13260
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013261 /**
Sarah Chin43457982023-02-15 17:50:38 -080013262 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013263 *
Sarah Chin43457982023-02-15 17:50:38 -080013264 * @param subId The subId of the subscription to register for satellite modem state changed.
13265 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080013266 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013267 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013268 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013269 * @throws SecurityException if the caller doesn't have the required permission.
13270 */
13271 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013272 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013273 @NonNull ISatelliteModemStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080013274 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013275 return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013276 }
13277
13278 /**
Sarah Chin43457982023-02-15 17:50:38 -080013279 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013280 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013281 *
Sarah Chin43457982023-02-15 17:50:38 -080013282 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080013283 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013284 * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013285 *
13286 * @throws SecurityException if the caller doesn't have the required permission.
13287 */
13288 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013289 public void unregisterForModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013290 @NonNull ISatelliteModemStateCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013291 enforceSatelliteCommunicationPermission("unregisterForModemStateChanged");
13292 mSatelliteController.unregisterForModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013293 }
13294
13295 /**
13296 * Register to receive incoming datagrams over satellite.
13297 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013298 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Sarah Chindf715ec2023-02-13 13:46:24 -080013299 * @param callback The callback to handle incoming datagrams over satellite.
13300 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013301 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013302 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013303 * @throws SecurityException if the caller doesn't have the required permission.
13304 */
13305 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013306 @SatelliteManager.SatelliteResult public int registerForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013307 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013308 enforceSatelliteCommunicationPermission("registerForIncomingDatagram");
13309 return mSatelliteController.registerForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013310 }
13311
13312 /**
13313 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013314 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013315 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013316 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
13317 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013318 * {@link #registerForIncomingDatagram(int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013319 *
13320 * @throws SecurityException if the caller doesn't have the required permission.
13321 */
13322 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013323 public void unregisterForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013324 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013325 enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram");
13326 mSatelliteController.unregisterForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013327 }
13328
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013329 /**
13330 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013331 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013332 * This method requests modem to check if there are any pending datagrams to be received over
13333 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000013334 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080013335 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013336 * @param subId The subId of the subscription used for receiving datagrams.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013337 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013338 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013339 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013340 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013341 public void pollPendingDatagrams(int subId, IIntegerConsumer callback) {
13342 enforceSatelliteCommunicationPermission("pollPendingDatagrams");
13343 mSatelliteController.pollPendingDatagrams(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013344 }
13345
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013346 /**
13347 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013348 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013349 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
13350 * input to this method. Datagram received here will be passed down to modem without any
13351 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080013352 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013353 * @param subId The subId of the subscription to send satellite datagrams for.
13354 * @param datagramType datagram type indicating whether the datagram is of type
13355 * SOS_SMS or LOCATION_SHARING.
13356 * @param datagram encoded gateway datagram which is encrypted by the caller.
13357 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000013358 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
13359 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013360 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013361 *
13362 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013363 */
13364 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013365 public void sendDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000013366 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
13367 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013368 enforceSatelliteCommunicationPermission("sendDatagram");
13369 mSatelliteController.sendDatagram(subId, datagramType, datagram, needFullScreenPointingUI,
13370 callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013371 }
13372
Sarah Chindf715ec2023-02-13 13:46:24 -080013373 /**
13374 * Request to get whether satellite communication is allowed for the current location.
13375 *
13376 * @param subId The subId of the subscription to check whether satellite communication is
13377 * allowed for the current location for.
13378 * @param result The result receiver that returns whether satellite communication is allowed
13379 * for the current location if the request is successful or an error code
13380 * if the request failed.
13381 *
13382 * @throws SecurityException if the caller doesn't have the required permission.
13383 */
13384 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013385 public void requestIsCommunicationAllowedForCurrentLocation(int subId,
Sarah Chindf715ec2023-02-13 13:46:24 -080013386 @NonNull ResultReceiver result) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013387 enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation");
13388 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(subId,
13389 result);
Sarah Chindf715ec2023-02-13 13:46:24 -080013390 }
13391
13392 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013393 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080013394 *
Sarah Chin5f57c582023-02-14 04:16:10 -080013395 * @param subId The subId to get the time after which the satellite will be visible for.
13396 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080013397 * be visible if the request is successful or an error code if the request failed.
13398 *
13399 * @throws SecurityException if the caller doesn't have the required permission.
13400 */
13401 @Override
13402 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
13403 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013404 mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013405 }
13406
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013407 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013408 * Inform that Device is aligned to satellite for demo mode.
13409 *
13410 * @param subId The subId to get the time after which the satellite will be visible for.
13411 * @param isAligned {@code true} Device is aligned with the satellite for demo mode
13412 * {@code false} Device fails to align with the satellite for demo mode.
13413 *
13414 * @throws SecurityException if the caller doesn't have required permission.
13415 */
13416 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
13417
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013418 public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) {
Hakjun Choiae365972023-04-25 11:00:31 +000013419 enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite");
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013420 mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned);
Hakjun Choiae365972023-04-25 11:00:31 +000013421 }
13422
13423 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000013424 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
13425 * by modem.
13426 *
13427 * @param subId The subId of the subscription to request for.
13428 * @param reason Reason for disallowing satellite communication for carrier.
Hakjun Choif92ac752024-03-18 19:34:29 +000013429 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013430 * operation.
13431 *
13432 * @throws SecurityException if the caller doesn't have required permission.
13433 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013434 public void addAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013435 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13436 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013437 enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013438 final long identity = Binder.clearCallingIdentity();
13439 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013440 mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013441 } finally {
13442 Binder.restoreCallingIdentity(identity);
13443 }
13444 }
13445
13446 /**
13447 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
13448 * by modem.
13449 *
13450 * @param subId The subId of the subscription to request for.
13451 * @param reason Reason for disallowing satellite communication.
Hakjun Choif92ac752024-03-18 19:34:29 +000013452 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013453 * operation.
13454 *
13455 * @throws SecurityException if the caller doesn't have required permission.
13456 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013457 public void removeAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013458 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13459 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013460 enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013461 final long identity = Binder.clearCallingIdentity();
13462 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013463 mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013464 } finally {
13465 Binder.restoreCallingIdentity(identity);
13466 }
13467 }
13468
13469 /**
13470 * Get reasons for disallowing satellite communication, as requested by
Hakjun Choif92ac752024-03-18 19:34:29 +000013471 * {@link #addAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
Hakjun Choicb39db92023-07-14 15:51:12 +000013472 *
13473 * @param subId The subId of the subscription to request for.
13474 *
13475 * @return Integer array of reasons for disallowing satellite communication.
13476 *
13477 * @throws SecurityException if the caller doesn't have the required permission.
13478 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013479 public @NonNull int[] getAttachRestrictionReasonsForCarrier(
Hakjun Choicb39db92023-07-14 15:51:12 +000013480 int subId) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013481 enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013482 final long identity = Binder.clearCallingIdentity();
13483 try {
13484 Set<Integer> reasonSet =
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013485 mSatelliteController.getAttachRestrictionReasonsForCarrier(subId);
Hakjun Choicb39db92023-07-14 15:51:12 +000013486 return reasonSet.stream().mapToInt(i->i).toArray();
13487 } finally {
13488 Binder.restoreCallingIdentity(identity);
13489 }
13490 }
13491
13492 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000013493 * Request to get the signal strength of the satellite connection.
13494 *
13495 * @param subId The subId of the subscription to request for.
13496 * @param result Result receiver to get the error code of the request and the current signal
13497 * strength of the satellite connection.
13498 *
13499 * @throws SecurityException if the caller doesn't have required permission.
13500 */
13501 @Override
13502 public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) {
13503 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
13504 final long identity = Binder.clearCallingIdentity();
13505 try {
13506 mSatelliteController.requestNtnSignalStrength(subId, result);
13507 } finally {
13508 Binder.restoreCallingIdentity(identity);
13509 }
13510 }
13511
13512 /**
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013513 * Registers for NTN signal strength changed from satellite modem. If the registration operation
13514 * is not successful, a {@link ServiceSpecificException} that contains
13515 * {@link SatelliteManager.SatelliteResult} will be thrown.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013516 *
13517 * @param subId The subId of the subscription to request for.
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013518 * @param callback The callback to handle the NTN signal strength changed event. If the
13519 * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged(
13520 * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of
13521 * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial
13522 * network has changed.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013523 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013524 * @throws SecurityException If the caller doesn't have the required permission.
13525 * @throws ServiceSpecificException If the callback registration operation fails.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013526 */
13527 @Override
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013528 public void registerForNtnSignalStrengthChanged(int subId,
13529 @NonNull INtnSignalStrengthCallback callback) throws RemoteException {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013530 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
13531 final long identity = Binder.clearCallingIdentity();
13532 try {
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013533 mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013534 } finally {
13535 Binder.restoreCallingIdentity(identity);
13536 }
13537 }
13538
13539 /**
13540 * Unregisters for NTN signal strength changed from satellite modem.
13541 * If callback was not registered before, the request will be ignored.
13542 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013543 * @param subId The subId of the subscription to unregister for listening NTN signal strength
13544 * changed event.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013545 * @param callback The callback that was passed to
13546 * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)}
13547 *
13548 * @throws SecurityException if the caller doesn't have the required permission.
13549 */
13550 @Override
13551 public void unregisterForNtnSignalStrengthChanged(
13552 int subId, @NonNull INtnSignalStrengthCallback callback) {
13553 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
13554 final long identity = Binder.clearCallingIdentity();
13555 try {
13556 mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback);
13557 } finally {
13558 Binder.restoreCallingIdentity(identity);
13559 }
13560 }
13561
13562 /**
Hakjun Choi8d96a562023-10-26 15:01:40 +000013563 * Registers for satellite capabilities change event from the satellite service.
13564 *
13565 * @param subId The subId of the subscription to request for.
13566 * @param callback The callback to handle the satellite capabilities changed event.
13567 *
13568 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13569 *
13570 * @throws SecurityException if the caller doesn't have required permission.
13571 */
13572 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013573 @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged(
Hakjun Choi8d96a562023-10-26 15:01:40 +000013574 int subId, @NonNull ISatelliteCapabilitiesCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013575 enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013576 final long identity = Binder.clearCallingIdentity();
13577 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013578 return mSatelliteController.registerForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013579 } finally {
13580 Binder.restoreCallingIdentity(identity);
13581 }
13582 }
13583
13584 /**
13585 * Unregisters for satellite capabilities change event from the satellite service.
13586 * If callback was not registered before, the request will be ignored.
13587 *
13588 * @param subId The subId of the subscription to unregister for satellite capabilities change.
13589 * @param callback The callback that was passed to.
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013590 * {@link #registerForCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}.
Hakjun Choi8d96a562023-10-26 15:01:40 +000013591 *
13592 * @throws SecurityException if the caller doesn't have required permission.
13593 */
13594 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013595 public void unregisterForCapabilitiesChanged(int subId,
13596 @NonNull ISatelliteCapabilitiesCallback callback) {
13597 enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013598 final long identity = Binder.clearCallingIdentity();
13599 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013600 mSatelliteController.unregisterForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013601 } finally {
13602 Binder.restoreCallingIdentity(identity);
13603 }
13604 }
13605
13606 /**
Hakjun Choif92ac752024-03-18 19:34:29 +000013607 * Registers for the satellite supported state changed.
13608 *
13609 * @param subId The subId of the subscription to register for supported state changed.
13610 * @param callback The callback to handle the satellite supported state changed event.
13611 *
13612 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13613 *
13614 * @throws SecurityException if the caller doesn't have the required permission.
13615 */
13616 @Override
13617 @SatelliteManager.SatelliteResult public int registerForSatelliteSupportedStateChanged(
13618 int subId, @NonNull ISatelliteSupportedStateCallback callback) {
13619 enforceSatelliteCommunicationPermission("registerForSatelliteSupportedStateChanged");
13620 return mSatelliteController.registerForSatelliteSupportedStateChanged(subId, callback);
13621 }
13622
13623 /**
13624 * Unregisters for the satellite supported state changed.
13625 * If callback was not registered before, the request will be ignored.
13626 *
13627 * @param subId The subId of the subscription to unregister for supported state changed.
13628 * @param callback The callback that was passed to
13629 * {@link #registerForSatelliteSupportedStateChanged(int, ISatelliteSupportedStateCallback)}.
13630 *
13631 * @throws SecurityException if the caller doesn't have the required permission.
13632 */
13633 @Override
13634 public void unregisterForSatelliteSupportedStateChanged(
13635 int subId, @NonNull ISatelliteSupportedStateCallback callback) {
13636 enforceSatelliteCommunicationPermission("unregisterForSatelliteSupportedStateChanged");
13637 mSatelliteController.unregisterForSatelliteSupportedStateChanged(subId, callback);
13638 }
13639
13640 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013641 * This API can be used by only CTS to update satellite vendor service package name.
13642 *
13643 * @param servicePackageName The package name of the satellite vendor service.
13644 * @return {@code true} if the satellite vendor service is set successfully,
13645 * {@code false} otherwise.
13646 */
13647 public boolean setSatelliteServicePackageName(String servicePackageName) {
13648 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName);
13649 TelephonyPermissions.enforceShellOnly(
13650 Binder.getCallingUid(), "setSatelliteServicePackageName");
13651 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13652 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13653 "setSatelliteServicePackageName");
13654 return mSatelliteController.setSatelliteServicePackageName(servicePackageName);
13655 }
13656
13657 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070013658 * This API can be used by only CTS to update satellite gateway service package name.
13659 *
13660 * @param servicePackageName The package name of the satellite gateway service.
13661 * @return {@code true} if the satellite gateway service is set successfully,
13662 * {@code false} otherwise.
13663 */
13664 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
13665 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
13666 TelephonyPermissions.enforceShellOnly(
13667 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
13668 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13669 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13670 "setSatelliteGatewayServicePackageName");
13671 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
13672 }
13673
13674 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070013675 * This API can be used by only CTS to update satellite pointing UI app package and class names.
13676 *
13677 * @param packageName The package name of the satellite pointing UI app.
13678 * @param className The class name of the satellite pointing UI app.
13679 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
13680 * {@code false} otherwise.
13681 */
13682 public boolean setSatellitePointingUiClassName(
13683 @Nullable String packageName, @Nullable String className) {
13684 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
13685 + ", className=" + className);
13686 TelephonyPermissions.enforceShellOnly(
13687 Binder.getCallingUid(), "setSatellitePointingUiClassName");
13688 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13689 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13690 "setSatelliteGatewayServicePackageName");
13691 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
13692 }
13693
13694 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070013695 * This API can be used by only CTS to update the timeout duration in milliseconds that
13696 * satellite should stay at listening mode to wait for the next incoming page before disabling
13697 * listening mode.
13698 *
13699 * @param timeoutMillis The timeout duration in millisecond.
13700 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13701 */
13702 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
13703 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
13704 TelephonyPermissions.enforceShellOnly(
13705 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
13706 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13707 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13708 "setSatelliteListeningTimeoutDuration");
13709 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
13710 }
13711
13712 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013713 * This API can be used by only CTS to override the timeout durations used by the
13714 * DatagramController module.
Hakjun Choiae365972023-04-25 11:00:31 +000013715 *
13716 * @param timeoutMillis The timeout duration in millisecond.
13717 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13718 */
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013719 public boolean setDatagramControllerTimeoutDuration(
13720 boolean reset, int timeoutType, long timeoutMillis) {
13721 Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset="
13722 + reset + ", timeoutMillis=" + timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013723 TelephonyPermissions.enforceShellOnly(
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013724 Binder.getCallingUid(), "setDatagramControllerTimeoutDuration");
Hakjun Choiae365972023-04-25 11:00:31 +000013725 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13726 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013727 "setDatagramControllerTimeoutDuration");
13728 return mSatelliteController.setDatagramControllerTimeoutDuration(
13729 reset, timeoutType, timeoutMillis);
13730 }
13731
13732 /**
13733 * This API can be used by only CTS to override the timeout durations used by the
13734 * SatelliteController module.
13735 *
13736 * @param timeoutMillis The timeout duration in millisecond.
13737 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13738 */
13739 public boolean setSatelliteControllerTimeoutDuration(
13740 boolean reset, int timeoutType, long timeoutMillis) {
13741 Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset="
13742 + reset + ", timeoutMillis=" + timeoutMillis);
13743 TelephonyPermissions.enforceShellOnly(
13744 Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration");
13745 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13746 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13747 "setSatelliteControllerTimeoutDuration");
13748 return mSatelliteController.setSatelliteControllerTimeoutDuration(
13749 reset, timeoutType, timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013750 }
13751
13752 /**
Thomas Nguyen11a051f2023-10-25 10:14:55 -070013753 * This API can be used in only testing to override connectivity status in monitoring emergency
13754 * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.
13755 *
13756 * @param handoverType The type of handover from emergency call to satellite messaging. Use one
13757 * of the following values to enable the override:
13758 * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS
13759 * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911
13760 * To disable the override, use -1 for handoverType.
13761 * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer
13762 * delaySeconds after the emergency call starts.
13763 * @return {@code true} if the handover type is set successfully, {@code false} otherwise.
13764 */
13765 public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) {
13766 Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType);
13767 TelephonyPermissions.enforceShellOnly(
13768 Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType");
13769 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13770 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13771 "setEmergencyCallToSatelliteHandoverType");
13772 return mSatelliteController.setEmergencyCallToSatelliteHandoverType(
13773 handoverType, delaySeconds);
13774 }
13775
13776 /**
Thomas Nguyen3d602742024-01-19 11:29:35 -080013777 * This API can be used in only testing to override oem-enabled satellite provision status.
13778 *
13779 * @param reset {@code true} mean the overriding status should not be used, {@code false}
13780 * otherwise.
13781 * @param isProvisioned The overriding provision status.
13782 * @return {@code true} if the provision status is set successfully, {@code false} otherwise.
13783 */
13784 public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) {
13785 Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset
13786 + ", isProvisioned=" + isProvisioned);
13787 TelephonyPermissions.enforceShellOnly(
13788 Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus");
13789 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13790 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13791 "setOemEnabledSatelliteProvisionStatus");
13792 return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned);
13793 }
13794
13795 /**
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013796 * This API should be used by only CTS tests to forcefully set telephony country codes.
13797 *
13798 * @return {@code true} if the country code is set successfully, {@code false} otherwise.
13799 */
13800 public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes,
13801 Map cachedNetworkCountryCodes, String locationCountryCode,
13802 long locationCountryCodeTimestampNanos) {
13803 Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes="
13804 + String.join(", ", currentNetworkCountryCodes)
13805 + ", locationCountryCode=" + locationCountryCode
13806 + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos
13807 + ", reset=" + reset + ", cachedNetworkCountryCodes="
13808 + String.join(", ", cachedNetworkCountryCodes.keySet()));
13809 TelephonyPermissions.enforceShellOnly(
13810 Binder.getCallingUid(), "setCachedLocationCountryCode");
13811 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13812 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13813 "setCachedLocationCountryCode");
13814 return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext()).setCountryCodes(
13815 reset, currentNetworkCountryCodes, cachedNetworkCountryCodes, locationCountryCode,
13816 locationCountryCodeTimestampNanos);
13817 }
13818
13819 /**
13820 * This API should be used by only CTS tests to override the overlay configs of satellite
13821 * access controller.
13822 *
13823 * @param reset {@code true} mean the overridden configs should not be used, {@code false}
13824 * otherwise.
13825 * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise.
13826 */
13827 public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed,
13828 String s2CellFile, long locationFreshDurationNanos,
13829 List<String> satelliteCountryCodes) {
13830 Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset
13831 + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile
13832 + ", locationFreshDurationNanos=" + locationFreshDurationNanos
13833 + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null)
13834 ? String.join(", ", satelliteCountryCodes) : null));
13835 TelephonyPermissions.enforceShellOnly(
13836 Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs");
13837 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13838 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13839 "setSatelliteAccessControlOverlayConfigs");
13840 return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset, isAllowed,
13841 s2CellFile, locationFreshDurationNanos, satelliteCountryCodes);
13842 }
13843
13844 /**
Hakjun Choibc6ce992023-11-07 16:04:33 +000013845 * This API can be used by only CTS to override the cached value for the device overlay config
13846 * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether
13847 * outgoing satellite datagrams should be sent to modem in demo mode.
13848 *
13849 * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to
13850 * satellite modem or not.
13851 *
13852 * @return {@code true} if the operation is successful, {@code false} otherwise.
13853 */
13854 public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) {
13855 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
13856 Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is "
13857 + "disabled");
13858 return false;
13859 }
13860 Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode");
13861 TelephonyPermissions.enforceShellOnly(
13862 Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode");
13863 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13864 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13865 "setShouldSendDatagramToModemInDemoMode");
13866 return mSatelliteController.setShouldSendDatagramToModemInDemoMode(
13867 shouldSendToModemInDemoMode);
13868 }
13869
13870 /**
Hunsuk Choi13078be2023-09-13 10:55:21 +000013871 * Sets the service defined in ComponentName to be bound.
13872 *
13873 * This should only be used for testing.
13874 * @return {@code true} if the DomainSelectionService to bind to was set,
13875 * {@code false} otherwise.
13876 */
13877 @Override
13878 public boolean setDomainSelectionServiceOverride(ComponentName componentName) {
13879 Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName);
13880
13881 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
13882 "setDomainSelectionServiceOverride");
13883 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13884 getDefaultSubscription(), "setDomainSelectionServiceOverride");
13885
13886 final long identity = Binder.clearCallingIdentity();
13887 try {
13888 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13889 return DomainSelectionResolver.getInstance()
13890 .setDomainSelectionServiceOverride(componentName);
13891 }
13892 } finally {
13893 Binder.restoreCallingIdentity(identity);
13894 }
13895 return false;
13896 }
13897
13898 /**
13899 * Clears the DomainSelectionService override.
13900 *
13901 * This should only be used for testing.
13902 * @return {@code true} if the DomainSelectionService override was cleared,
13903 * {@code false} otherwise.
13904 */
13905 @Override
13906 public boolean clearDomainSelectionServiceOverride() {
13907 Log.i(LOG_TAG, "clearDomainSelectionServiceOverride");
13908
13909 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
13910 "clearDomainSelectionServiceOverride");
13911 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13912 getDefaultSubscription(), "clearDomainSelectionServiceOverride");
13913
13914 final long identity = Binder.clearCallingIdentity();
13915 try {
13916 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13917 return DomainSelectionResolver.getInstance()
13918 .clearDomainSelectionServiceOverride();
13919 }
13920 } finally {
13921 Binder.restoreCallingIdentity(identity);
13922 }
13923 return false;
13924 }
13925
13926 /**
Gil Cukierman06403e12023-11-29 16:33:03 +000013927 * Enable or disable notifications sent for cellular identifier disclosure events.
13928 *
13929 * Disclosure events are defined as instances where a device has sent a cellular identifier
13930 * on the Non-access stratum (NAS) before a security context is established. As a result the
13931 * identifier is sent in the clear, which has privacy implications for the user.
13932 *
13933 * @param enable if notifications about disclosure events should be enabled
13934 * @throws SecurityException if the caller does not have the required privileges
13935 * @throws UnsupportedOperationException if the modem does not support this feature.
13936 */
13937 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000013938 public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) {
Gil Cukierman06403e12023-11-29 16:33:03 +000013939 enforceModifyPermission();
13940 checkForIdentifierDisclosureNotificationSupport();
13941
13942 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
13943 editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable);
13944 editor.apply();
13945
13946 // Each phone instance is responsible for updating its respective modem immediately
13947 // after we've made a preference change.
13948 for (Phone phone : PhoneFactory.getPhones()) {
13949 phone.handleIdentifierDisclosureNotificationPreferenceChange();
13950 }
13951 }
13952
13953 /**
13954 * Get whether or not cellular identifier disclosure notifications are enabled.
13955 *
13956 * @throws SecurityException if the caller does not have the required privileges
13957 * @throws UnsupportedOperationException if the modem does not support this feature.
13958 */
13959 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000013960 public boolean isCellularIdentifierDisclosureNotificationsEnabled() {
Gil Cukierman06403e12023-11-29 16:33:03 +000013961 enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled");
13962 checkForIdentifierDisclosureNotificationSupport();
13963 return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled();
13964 }
13965
13966 /**
Michael Groover826b71d2023-12-21 22:08:06 -060013967 * Enables or disables notifications sent when cellular null cipher or integrity algorithms
13968 * are in use by the cellular modem.
13969 *
13970 * @throws IllegalStateException if the Telephony process is not currently available
13971 * @throws SecurityException if the caller does not have the required privileges
13972 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
13973 * and integrity algorithms in use
13974 * @hide
13975 */
13976 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Michael Grooverae447b22024-01-24 22:35:46 -060013977 public void setNullCipherNotificationsEnabled(boolean enable) {
Michael Groover826b71d2023-12-21 22:08:06 -060013978 enforceModifyPermission();
13979 checkForNullCipherNotificationSupport();
13980
13981 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
13982 editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable);
13983 editor.apply();
13984
13985 // Each phone instance is responsible for updating its respective modem immediately
13986 // after a preference change.
13987 for (Phone phone : PhoneFactory.getPhones()) {
13988 phone.handleNullCipherNotificationPreferenceChanged();
13989 }
13990 }
13991
13992 /**
13993 * Get whether notifications are enabled for null cipher or integrity algorithms in use by the
13994 * cellular modem.
13995 *
13996 * @throws IllegalStateException if the Telephony process is not currently available
13997 * @throws SecurityException if the caller does not have the required privileges
13998 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
13999 * and integrity algorithms in use
14000 * @hide
14001 */
14002 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
14003 public boolean isNullCipherNotificationsEnabled() {
14004 enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled");
14005 checkForNullCipherNotificationSupport();
14006 return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled();
14007 }
14008
14009 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000014010 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
14011 *
14012 * <p>This method behaves in one of the following ways:
14013 * <ul>
14014 * <li>return true : if the calling package has the appop permission {@link
14015 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
14016 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
14017 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
14018 * Owner device identifier access check, or the calling package has carrier privileges</>
14019 * <li>throw SecurityException: if the caller does not meet any of the requirements.
14020 * </ul>
14021 */
14022 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
14023 String callingPackage, @Nullable String callingFeatureId, String message) {
14024 for (Phone phone : PhoneFactory.getPhones()) {
14025 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
14026 phone.getSubId(), callingPackage, callingFeatureId, message)) {
14027 return true;
14028 }
14029 }
14030 return false;
14031 }
arunvoddud7401012022-12-15 16:08:12 +000014032
14033 /**
Jack Yufa8ed012023-02-11 15:42:28 -080014034 * @return The subscription manager service instance.
14035 */
14036 public SubscriptionManagerService getSubscriptionManagerService() {
14037 return SubscriptionManagerService.getInstance();
14038 }
14039
14040 /**
arunvoddud7401012022-12-15 16:08:12 +000014041 * Class binds the consumer[callback] and carrierId.
14042 */
14043 private static class CallerCallbackInfo {
14044 private final Consumer<Integer> mConsumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014045 private final Set<Integer> mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014046
Steve Statia28b7cb32024-03-11 23:58:50 +000014047 public CallerCallbackInfo(Consumer<Integer> consumer, Set<Integer> carrierIds) {
arunvoddud7401012022-12-15 16:08:12 +000014048 mConsumer = consumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014049 mCarrierIds = carrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014050 }
14051
14052 public Consumer<Integer> getConsumer() {
14053 return mConsumer;
14054 }
14055
Steve Statia28b7cb32024-03-11 23:58:50 +000014056 public Set<Integer> getCarrierIds() {
14057 return mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014058 }
14059 }
joonhunshin4ac60942023-11-15 15:23:39 +000014060
14061 /*
14062 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14063 * But the context that is passed in is unused if the phone app is already alive.
14064 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14065 */
14066 @VisibleForTesting
14067 public void setPackageManager(PackageManager packageManager) {
14068 mPackageManager = packageManager;
14069 }
14070
14071 /*
Nate Myren453c3472024-03-13 11:28:11 -070014072 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14073 * But the context that is passed in is unused if the phone app is already alive.
14074 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14075 */
14076 @VisibleForTesting
14077 public void setAppOpsManager(AppOpsManager appOps) {
14078 mAppOps = appOps;
14079 }
14080
14081 /*
joonhunshin4ac60942023-11-15 15:23:39 +000014082 * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags.
14083 * But the FeatureFlags that is passed in is unused if the phone app is already alive.
14084 * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test.
14085 */
14086 @VisibleForTesting
14087 public void setFeatureFlags(FeatureFlags featureFlags) {
14088 mFeatureFlags = featureFlags;
14089 }
14090
14091 /**
14092 * Make sure the device has required telephony feature
14093 *
14094 * @throws UnsupportedOperationException if the device does not have required telephony feature
14095 */
14096 private void enforceTelephonyFeatureWithException(@Nullable String callingPackage,
14097 @NonNull String telephonyFeature, @NonNull String methodName) {
14098 if (callingPackage == null || mPackageManager == null) {
14099 return;
14100 }
14101
14102 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
14103 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage,
joonhunshinf624b2a2024-04-18 04:42:12 +000014104 Binder.getCallingUserHandle())
14105 || mVendorApiLevel < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
14106 // Skip to check associated telephony feature,
14107 // if compatibility change is not enabled for the current process or
14108 // the SDK version of vendor partition is less than Android V.
joonhunshin4ac60942023-11-15 15:23:39 +000014109 return;
14110 }
14111
14112 if (!mPackageManager.hasSystemFeature(telephonyFeature)) {
14113 throw new UnsupportedOperationException(
14114 methodName + " is unsupported without " + telephonyFeature);
14115 }
14116 }
Jack Yufa8ed012023-02-11 15:42:28 -080014117}