blob: 8de8ae15740c0fb3592a4e77c9799384d4faba45 [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;
youngtaecha5d483d52024-04-29 17:05:45 +0000160import android.telephony.satellite.ISatelliteCommunicationAllowedStateCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800161import android.telephony.satellite.ISatelliteDatagramCallback;
Hakjun Choid4a52a22023-12-13 09:48:24 +0000162import android.telephony.satellite.ISatelliteModemStateCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800163import android.telephony.satellite.ISatelliteProvisionStateCallback;
Hakjun Choif92ac752024-03-18 19:34:29 +0000164import android.telephony.satellite.ISatelliteSupportedStateCallback;
Sarah Chinabf081b2023-03-09 23:00:57 -0800165import android.telephony.satellite.ISatelliteTransmissionUpdateCallback;
Hakjun Choi4c3668a2023-12-05 11:55:36 +0000166import android.telephony.satellite.NtnSignalStrength;
167import android.telephony.satellite.NtnSignalStrengthCallback;
Sarah Chin503828c2023-02-01 23:54:20 -0800168import android.telephony.satellite.SatelliteCapabilities;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000169import android.telephony.satellite.SatelliteDatagram;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800170import android.telephony.satellite.SatelliteDatagramCallback;
Sarah Chineccfbd12023-01-20 19:00:35 -0800171import android.telephony.satellite.SatelliteManager;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800172import android.telephony.satellite.SatelliteProvisionStateCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700173import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800174import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700175import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700176import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800177import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800178
Andrew Lee312e8172014-10-23 17:01:36 -0700179import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800180import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800181import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800182import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800183import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700184import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700185import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700186import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800187import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800188import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700189import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700190import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800191import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700192import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800193import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800194import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800195import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700196import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000197import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700198import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800199import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700200import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800201import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800202import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800203import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700204import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700205import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700206import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700207import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700208import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800209import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700210import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700211import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700212import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700213import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800214import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800215import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700216import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000217import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700218import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700219import com.android.internal.telephony.SmsPermissions;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800220import com.android.internal.telephony.TelephonyCountryDetector;
Peter Wang59571be2020-01-27 12:35:15 +0800221import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800222import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700223import com.android.internal.telephony.data.DataUtils;
Hunsuk Choi42cc62a2022-10-16 06:03:40 +0000224import com.android.internal.telephony.domainselection.DomainSelectionResolver;
sqianf4ca7ed2019-01-15 18:32:07 -0800225import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700226import com.android.internal.telephony.euicc.EuiccConnector;
Sarah Chincc5446f2023-10-23 17:57:19 -0700227import com.android.internal.telephony.flags.FeatureFlags;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800228import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700229import com.android.internal.telephony.imsphone.ImsPhone;
230import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000231import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800232import com.android.internal.telephony.metrics.TelephonyMetrics;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000233import com.android.internal.telephony.satellite.SatelliteController;
Jack Yu285100e2022-12-02 22:48:35 -0800234import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
235import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700236import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700237import com.android.internal.telephony.uicc.IccIoResult;
238import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800239import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700240import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800241import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700242import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000243import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800244import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000245import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800246import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000247import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700248import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700249import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800250import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800251import com.android.phone.callcomposer.CallComposerPictureManager;
252import com.android.phone.callcomposer.CallComposerPictureTransfer;
253import com.android.phone.callcomposer.ImageData;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800254import com.android.phone.satellite.accesscontrol.SatelliteAccessController;
Hyosun Kim240214a2023-11-02 13:30:15 +0000255import com.android.phone.satellite.entitlement.SatelliteEntitlementController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700256import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700257import com.android.phone.slice.SlicePurchaseController;
arunvoddud7401012022-12-15 16:08:12 +0000258import com.android.phone.utils.CarrierAllowListInfo;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700259import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800260import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700261import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700262import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -0800263import com.android.server.feature.flags.Flags;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800264import com.android.services.telephony.TelecomAccountRegistry;
265import com.android.services.telephony.TelephonyConnectionService;
Hunsuk Choi9c69a802024-04-11 20:39:23 +0000266import com.android.services.telephony.domainselection.TelephonyDomainSelectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800267import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800268
Hall Liu82694d52020-12-11 18:22:04 -0800269import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700270import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800271import java.io.IOException;
272import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700273import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700274import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800275import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000276import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800277import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800278import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800279import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800280import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100281import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800282import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700283import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800284import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800285import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700286import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800287import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800288import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800289import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700290
291/**
292 * Implementation of the ITelephony interface.
293 */
Santos Cordon117fee72014-05-16 17:56:12 -0700294public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700295 private static final String LOG_TAG = "PhoneInterfaceManager";
296 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
297 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800298 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700299
300 // Message codes used with mMainThreadHandler
301 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700302 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
303 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700304 private static final int CMD_OPEN_CHANNEL = 9;
305 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
306 private static final int CMD_CLOSE_CHANNEL = 11;
307 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800308 private static final int CMD_NV_READ_ITEM = 13;
309 private static final int EVENT_NV_READ_ITEM_DONE = 14;
310 private static final int CMD_NV_WRITE_ITEM = 15;
311 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
312 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
313 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700314 private static final int CMD_RESET_MODEM_CONFIG = 19;
315 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800316 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
317 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800318 private static final int CMD_SEND_ENVELOPE = 25;
319 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700320 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
321 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
322 private static final int CMD_EXCHANGE_SIM_IO = 31;
323 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800324 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
325 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700326 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
327 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700328 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
329 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700330 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
331 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
332 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
333 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700334 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
335 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
336 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
337 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700338 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800339 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
340 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000341 private static final int CMD_SWITCH_SLOTS = 50;
342 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700343 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
344 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
345 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
346 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
347 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
348 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
349 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
350 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700351 private static final int CMD_GET_ALL_CELL_INFO = 60;
352 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
353 private static final int CMD_GET_CELL_LOCATION = 62;
354 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700355 private static final int CMD_MODEM_REBOOT = 64;
356 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700357 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
358 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800359 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
360 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700361 private static final int CMD_GET_MODEM_STATUS = 70;
362 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700363 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
364 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700365 private static final int CMD_ERASE_MODEM_CONFIG = 74;
366 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800367 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
368 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
369 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
370 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800371 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
372 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800373 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800374 private static final int CMD_GET_CALL_FORWARDING = 83;
375 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
376 private static final int CMD_SET_CALL_FORWARDING = 85;
377 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
378 private static final int CMD_GET_CALL_WAITING = 87;
379 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
380 private static final int CMD_SET_CALL_WAITING = 89;
381 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700382 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
383 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
384 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
385 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700386 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
387 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800388 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
389 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800390 private static final int CMD_SET_DATA_THROTTLING = 99;
391 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800392 private static final int CMD_SET_SIM_POWER = 101;
393 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800394 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
395 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
396 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
397 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800398 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
399 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000400 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800401 private static final int CMD_GET_SLICING_CONFIG = 110;
402 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800403 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700404 private static final int CMD_ENABLE_VONR = 113;
405 private static final int EVENT_ENABLE_VONR_DONE = 114;
406 private static final int CMD_IS_VONR_ENABLED = 115;
407 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700408 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
409 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000410
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800411 // Parameters of select command.
412 private static final int SELECT_COMMAND = 0xA4;
413 private static final int SELECT_P1 = 0x04;
414 private static final int SELECT_P2 = 0;
415 private static final int SELECT_P3 = 0x10;
416
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000417 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
418 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
Gil Cukierman06403e12023-11-29 16:33:03 +0000419 // Cellular identifier disclosure transparency was added in IRadioNetwork 2.2
420 private static final int MIN_IDENTIFIER_DISCLOSURE_VERSION = 202;
Michael Groover826b71d2023-12-21 22:08:06 -0600421 // Null cipher notification support was added in IRadioNetwork 2.2
422 private static final int MIN_NULL_CIPHER_NOTIFICATION_VERSION = 202;
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000423
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700424 /** The singleton instance. */
425 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800426 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700427
Sarah Chin4beb2b72023-02-14 14:47:54 -0800428 private final PhoneGlobals mApp;
joonhunshin4ac60942023-11-15 15:23:39 +0000429 private FeatureFlags mFeatureFlags;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -0800430 private com.android.server.telecom.flags.FeatureFlags mTelecomFeatureFlags;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800431 private final CallManager mCM;
432 private final ImsResolver mImsResolver;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000433
434 private final SatelliteController mSatelliteController;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800435 private final SatelliteAccessController mSatelliteAccessController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800436 private final UserManager mUserManager;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800437 private final MainThreadHandler mMainThreadHandler;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800438 private final SharedPreferences mTelephonySharedPreferences;
439 private final PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800440 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Nate Myren453c3472024-03-13 11:28:11 -0700441 private AppOpsManager mAppOps;
joonhunshin4ac60942023-11-15 15:23:39 +0000442 private PackageManager mPackageManager;
joonhunshinf624b2a2024-04-18 04:42:12 +0000443 private final int mVendorApiLevel;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700444
Peter Wangdafb9ac2020-01-15 14:13:38 -0800445 /** User Activity */
Sarah Chin4beb2b72023-02-14 14:47:54 -0800446 private final AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800447 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800448 private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800449
Derek Tan97ebb422014-09-05 16:55:38 -0700450 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
451 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800452 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800453 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700454
Michelecea4cf22018-12-21 15:00:11 -0800455 // String to store multi SIM allowed
456 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
457
Derek Tan740e1672017-06-27 14:56:27 -0700458 // The AID of ISD-R.
459 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
460
yinxub1bed742017-04-17 11:45:04 -0700461 private NetworkScanRequestTracker mNetworkScanRequestTracker;
462
David Kelly5e06a7f2018-03-12 14:10:59 +0000463 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
464 private static final int MANUFACTURER_CODE_LENGTH = 8;
465
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800466 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800467 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800468
Sarah Chin2ec39f62022-08-31 17:03:26 -0700469 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
470 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
471
Derek Tan89e89d42014-07-08 17:00:10 -0700472 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700473 * Experiment flag to enable erase modem config on reset network, default value is false
474 */
475 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
476 "reset_network_erase_modem_config_enabled";
477
Rambo Wang0f050d82021-02-12 11:43:36 -0800478 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800479
Gary Jian76280a42022-12-07 16:18:33 +0800480 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
481
sandeepjsb6c87872021-09-27 15:34:44 +0000482 /**
483 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
484 * one ICCID active at the same time.
485 * Apps should use below API signatures if targeting SDK is T and beyond.
486 *
487 * @hide
488 */
489 @ChangeId
490 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
491 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800492
Naina Nallurid63128d2019-09-17 14:10:30 -0700493 /**
Chen Xu540470b2021-12-14 17:15:47 -0800494 * Apps targeting on Android T and beyond will get exception whenever icc close channel
495 * operation fails.
496 */
497 @ChangeId
498 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
499 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
500
501 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700502 * A request object to use for transmitting data to an ICC.
503 */
504 private static final class IccAPDUArgument {
505 public int channel, cla, command, p1, p2, p3;
506 public String data;
507
508 public IccAPDUArgument(int channel, int cla, int command,
509 int p1, int p2, int p3, String data) {
510 this.channel = channel;
511 this.cla = cla;
512 this.command = command;
513 this.p1 = p1;
514 this.p2 = p2;
515 this.p3 = p3;
516 this.data = data;
517 }
518 }
519
520 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700521 * A request object to use for transmitting data to an ICC.
522 */
523 private static final class ManualNetworkSelectionArgument {
524 public OperatorInfo operatorInfo;
525 public boolean persistSelection;
526
527 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
528 this.operatorInfo = operatorInfo;
529 this.persistSelection = persistSelection;
530 }
531 }
532
Sarah Chin71b3a852022-09-28 15:54:19 -0700533 private static final class PurchasePremiumCapabilityArgument {
534 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700535 public @NonNull IIntegerConsumer callback;
536
537 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800538 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700539 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700540 this.callback = callback;
541 }
542 }
543
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700544 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700545 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
546 * request after sending. The main thread will notify the request when it is complete.
547 */
548 private static final class MainThreadRequest {
549 /** The argument to use for the request */
550 public Object argument;
551 /** The result of the request that is run on the main thread */
552 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800553 // The subscriber id that this request applies to. Defaults to
554 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
555 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700556
Nathan Harold92bed182018-10-12 18:16:49 -0700557 // In cases where subId is unavailable, the caller needs to specify the phone.
558 public Phone phone;
559
vagdeviaf9a5b92018-08-15 16:01:53 -0700560 public WorkSource workSource;
561
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700562 public MainThreadRequest(Object argument) {
563 this.argument = argument;
564 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800565
Nathan Harold92bed182018-10-12 18:16:49 -0700566 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
567 this.argument = argument;
568 if (phone != null) {
569 this.phone = phone;
570 }
571 this.workSource = workSource;
572 }
573
vagdeviaf9a5b92018-08-15 16:01:53 -0700574 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800575 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800576 if (subId != null) {
577 this.subId = subId;
578 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700579 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800580 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700581 }
582
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800583 private static final class IncomingThirdPartyCallArgs {
584 public final ComponentName component;
585 public final String callId;
586 public final String callerDisplayName;
587
588 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
589 String callerDisplayName) {
590 this.component = component;
591 this.callId = callId;
592 this.callerDisplayName = callerDisplayName;
593 }
594 }
595
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700596 /**
597 * A handler that processes messages on the main thread in the phone process. Since many
598 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
599 * inbound binder threads to the main thread in the phone process. The Binder thread
600 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
601 * on, which will be notified when the operation completes and will contain the result of the
602 * request.
603 *
604 * <p>If a MainThreadRequest object is provided in the msg.obj field,
605 * note that request.result must be set to something non-null for the calling thread to
606 * unblock.
607 */
608 private final class MainThreadHandler extends Handler {
609 @Override
610 public void handleMessage(Message msg) {
611 MainThreadRequest request;
612 Message onCompleted;
613 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000614 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700615 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800616 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700617
618 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700619 case CMD_HANDLE_USSD_REQUEST: {
620 request = (MainThreadRequest) msg.obj;
621 final Phone phone = getPhoneFromRequest(request);
622 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800623 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700624 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700625
Pengquan Menga1bb6272018-09-06 09:59:22 -0700626 if (!isUssdApiAllowed(request.subId)) {
627 // Carrier does not support use of this API, return failure.
628 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
629 UssdResponse response = new UssdResponse(ussdRequest, null);
630 Bundle returnData = new Bundle();
631 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
632 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700633
Pengquan Menga1bb6272018-09-06 09:59:22 -0700634 request.result = true;
635 notifyRequester(request);
636 return;
637 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700638
Pengquan Menga1bb6272018-09-06 09:59:22 -0700639 try {
640 request.result = phone != null
641 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
642 } catch (CallStateException cse) {
643 request.result = false;
644 }
645 // Wake up the requesting thread
646 notifyRequester(request);
647 break;
pkanwar32d516d2016-10-14 19:37:38 -0700648 }
649
Yorke Lee716f67e2015-06-17 15:39:16 -0700650 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700651 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700652 final Phone phone = getPhoneFromRequest(request);
653 request.result = phone != null ?
654 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
655 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700656 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700657 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700658 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700659 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700660
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700661 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700662 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700663 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000664 uiccPort = getUiccPortFromRequest(request);
665 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700666 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800667 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700668 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700669 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700670 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800671 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000672 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800673 iccArgument.channel, iccArgument.cla, iccArgument.command,
674 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
675 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700676 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700677 break;
678
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700679 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700680 ar = (AsyncResult) msg.obj;
681 request = (MainThreadRequest) ar.userObj;
682 if (ar.exception == null && ar.result != null) {
683 request.result = ar.result;
684 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800685 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700686 if (ar.result == null) {
687 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800688 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700689 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800690 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700691 } else {
692 loge("iccTransmitApduLogicalChannel: Unknown exception");
693 }
694 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700695 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700696 break;
697
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700698 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
699 request = (MainThreadRequest) msg.obj;
700 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000701 uiccPort = getUiccPortFromRequest(request);
702 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700703 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800704 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700705 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700706 } else {
707 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800708 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000709 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800710 iccArgument.cla, iccArgument.command, iccArgument.p1,
711 iccArgument.p2,
712 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700713 }
714 break;
715
716 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
717 ar = (AsyncResult) msg.obj;
718 request = (MainThreadRequest) ar.userObj;
719 if (ar.exception == null && ar.result != null) {
720 request.result = ar.result;
721 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800722 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700723 if (ar.result == null) {
724 loge("iccTransmitApduBasicChannel: Empty response");
725 } else if (ar.exception instanceof CommandException) {
726 loge("iccTransmitApduBasicChannel: CommandException: " +
727 ar.exception);
728 } else {
729 loge("iccTransmitApduBasicChannel: Unknown exception");
730 }
731 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700732 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700733 break;
734
735 case CMD_EXCHANGE_SIM_IO:
736 request = (MainThreadRequest) msg.obj;
737 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000738 uiccPort = getUiccPortFromRequest(request);
739 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700740 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800741 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700742 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700743 } else {
744 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
745 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000746 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700747 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
748 iccArgument.data, onCompleted);
749 }
750 break;
751
752 case EVENT_EXCHANGE_SIM_IO_DONE:
753 ar = (AsyncResult) msg.obj;
754 request = (MainThreadRequest) ar.userObj;
755 if (ar.exception == null && ar.result != null) {
756 request.result = ar.result;
757 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800758 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700759 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700760 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700761 break;
762
Derek Tan4d5e5c12014-02-04 11:54:58 -0800763 case CMD_SEND_ENVELOPE:
764 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000765 uiccPort = getUiccPortFromRequest(request);
766 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700767 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800768 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700769 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700770 } else {
771 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800772 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700773 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800774 break;
775
776 case EVENT_SEND_ENVELOPE_DONE:
777 ar = (AsyncResult) msg.obj;
778 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700779 if (ar.exception == null && ar.result != null) {
780 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800781 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800782 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700783 if (ar.result == null) {
784 loge("sendEnvelopeWithStatus: Empty response");
785 } else if (ar.exception instanceof CommandException) {
786 loge("sendEnvelopeWithStatus: CommandException: " +
787 ar.exception);
788 } else {
789 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
790 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800791 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700792 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800793 break;
794
Shishir Agrawal566b7612013-10-28 14:41:00 -0700795 case CMD_OPEN_CHANNEL:
796 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000797 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800798 IccLogicalChannelRequest openChannelRequest =
799 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000800 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700801 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800802 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800803 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700804 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700805 } else {
806 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800807 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
808 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700809 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700810 break;
811
812 case EVENT_OPEN_CHANNEL_DONE:
813 ar = (AsyncResult) msg.obj;
814 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700815 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700816 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700817 int[] result = (int[]) ar.result;
818 int channelId = result[0];
819 byte[] selectResponse = null;
820 if (result.length > 1) {
821 selectResponse = new byte[result.length - 1];
822 for (int i = 1; i < result.length; ++i) {
823 selectResponse[i - 1] = (byte) result[i];
824 }
825 }
826 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800827 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800828
829 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700830 if (uiccPort == null) {
831 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
832 } else {
833 IccLogicalChannelRequest channelRequest =
834 (IccLogicalChannelRequest) request.argument;
835 channelRequest.channel = channelId;
836 uiccPort.onLogicalChannelOpened(channelRequest);
837 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700838 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700839 if (ar.result == null) {
840 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700841 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700842 if (ar.exception != null) {
843 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
844 }
845
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700846 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700847 if (ar.exception instanceof CommandException) {
848 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800849 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700850 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700851 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700852 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700853 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700854 }
855 }
856 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800857 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700858 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700859 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700860 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700861 break;
862
863 case CMD_CLOSE_CHANNEL:
864 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000865 uiccPort = getUiccPortFromRequest(request);
866 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700867 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800868 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800869 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800870 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700871 } else {
872 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000873 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700874 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700875 break;
876
877 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800878 ar = (AsyncResult) msg.obj;
879 request = (MainThreadRequest) ar.userObj;
880 if (ar.exception == null) {
881 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800882 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700883 if (uiccPort == null) {
884 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
885 } else {
886 final int channelId = (Integer) request.argument;
887 uiccPort.onLogicalChannelClosed(channelId);
888 }
Chen Xu540470b2021-12-14 17:15:47 -0800889 } else {
890 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800891 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800892 if (ar.exception instanceof CommandException) {
893 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
894 CommandException.Error error =
895 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800896 if (error == CommandException.Error.INVALID_ARGUMENTS) {
897 // should only throw exceptions from the binder threads.
898 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800899 "iccCloseLogicalChannel: invalid argument ");
900 }
901 } else {
902 loge("iccCloseLogicalChannel: Unknown exception");
903 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800904 request.result = (exception != null) ? exception :
905 new IllegalStateException(
906 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800907 }
908 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800909 break;
910
911 case CMD_NV_READ_ITEM:
912 request = (MainThreadRequest) msg.obj;
913 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800914 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
915 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800916 break;
917
918 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700919 ar = (AsyncResult) msg.obj;
920 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800921 if (ar.exception == null && ar.result != null) {
922 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700923 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800924 request.result = "";
925 if (ar.result == null) {
926 loge("nvReadItem: Empty response");
927 } else if (ar.exception instanceof CommandException) {
928 loge("nvReadItem: CommandException: " +
929 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700930 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800931 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700932 }
933 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700934 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700935 break;
936
Jake Hambye994d462014-02-03 13:10:13 -0800937 case CMD_NV_WRITE_ITEM:
938 request = (MainThreadRequest) msg.obj;
939 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
940 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800941 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700942 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800943 break;
944
945 case EVENT_NV_WRITE_ITEM_DONE:
946 handleNullReturnEvent(msg, "nvWriteItem");
947 break;
948
949 case CMD_NV_WRITE_CDMA_PRL:
950 request = (MainThreadRequest) msg.obj;
951 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800952 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800953 break;
954
955 case EVENT_NV_WRITE_CDMA_PRL_DONE:
956 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
957 break;
958
chen xu6dac5ab2018-10-26 17:39:23 -0700959 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800960 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700961 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800962 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800963 break;
964
chen xu6dac5ab2018-10-26 17:39:23 -0700965 case EVENT_RESET_MODEM_CONFIG_DONE:
966 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800967 break;
968
Sooraj Sasindran37444802020-08-11 10:40:43 -0700969 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
970 request = (MainThreadRequest) msg.obj;
971 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
972 request);
973 Phone phone = getPhoneFromRequest(request);
974 if (phone != null) {
975 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
976 } else {
977 loge("isNRDualConnectivityEnabled: No phone object");
978 request.result = false;
979 notifyRequester(request);
980 }
981 break;
982 }
983
984 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
985 ar = (AsyncResult) msg.obj;
986 request = (MainThreadRequest) ar.userObj;
987 if (ar.exception == null && ar.result != null) {
988 request.result = ar.result;
989 } else {
990 // request.result must be set to something non-null
991 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700992 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700993 request.result = ar.result;
994 } else {
995 request.result = false;
996 }
997 if (ar.result == null) {
998 loge("isNRDualConnectivityEnabled: Empty response");
999 } else if (ar.exception instanceof CommandException) {
1000 loge("isNRDualConnectivityEnabled: CommandException: "
1001 + ar.exception);
1002 } else {
1003 loge("isNRDualConnectivityEnabled: Unknown exception");
1004 }
1005 }
1006 notifyRequester(request);
1007 break;
1008
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001009 case CMD_IS_VONR_ENABLED: {
1010 request = (MainThreadRequest) msg.obj;
1011 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
1012 request);
1013 Phone phone = getPhoneFromRequest(request);
1014 if (phone != null) {
1015 phone.isVoNrEnabled(onCompleted, request.workSource);
1016 } else {
1017 loge("isVoNrEnabled: No phone object");
1018 request.result = false;
1019 notifyRequester(request);
1020 }
1021 break;
1022 }
1023
1024 case EVENT_IS_VONR_ENABLED_DONE:
1025 ar = (AsyncResult) msg.obj;
1026 request = (MainThreadRequest) ar.userObj;
1027 if (ar.exception == null && ar.result != null) {
1028 request.result = ar.result;
1029 } else {
1030 // request.result must be set to something non-null
1031 // for the calling thread to unblock
1032 if (ar.result != null) {
1033 request.result = ar.result;
1034 } else {
1035 request.result = false;
1036 }
1037 if (ar.result == null) {
1038 loge("isVoNrEnabled: Empty response");
1039 } else if (ar.exception instanceof CommandException) {
1040 loge("isVoNrEnabled: CommandException: "
1041 + ar.exception);
1042 } else {
1043 loge("isVoNrEnabled: Unknown exception");
1044 }
1045 }
1046 notifyRequester(request);
1047 break;
1048
Sooraj Sasindran37444802020-08-11 10:40:43 -07001049 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1050 request = (MainThreadRequest) msg.obj;
1051 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1052 Phone phone = getPhoneFromRequest(request);
1053 if (phone != null) {
1054 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1055 request.workSource);
1056 } else {
1057 loge("enableNrDualConnectivity: No phone object");
1058 request.result =
1059 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1060 notifyRequester(request);
1061 }
1062 break;
1063 }
1064
1065 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1066 ar = (AsyncResult) msg.obj;
1067 request = (MainThreadRequest) ar.userObj;
1068 if (ar.exception == null) {
1069 request.result =
1070 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1071 } else {
1072 request.result =
1073 TelephonyManager
1074 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1075 if (ar.exception instanceof CommandException) {
1076 CommandException.Error error =
1077 ((CommandException) (ar.exception)).getCommandError();
1078 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1079 request.result =
1080 TelephonyManager
1081 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001082 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1083 request.result =
1084 TelephonyManager
1085 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001086 }
1087 loge("enableNrDualConnectivity" + ": CommandException: "
1088 + ar.exception);
1089 } else {
1090 loge("enableNrDualConnectivity" + ": Unknown exception");
1091 }
1092 }
1093 notifyRequester(request);
1094 break;
1095 }
1096
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001097 case CMD_ENABLE_VONR: {
1098 request = (MainThreadRequest) msg.obj;
1099 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1100 Phone phone = getPhoneFromRequest(request);
1101 if (phone != null) {
1102 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1103 request.workSource);
1104 } else {
1105 loge("setVoNrEnabled: No phone object");
1106 request.result =
1107 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1108 notifyRequester(request);
1109 }
1110 break;
1111 }
1112
1113 case EVENT_ENABLE_VONR_DONE: {
1114 ar = (AsyncResult) msg.obj;
1115 request = (MainThreadRequest) ar.userObj;
1116 if (ar.exception == null) {
1117 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1118 } else {
1119 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1120 if (ar.exception instanceof CommandException) {
1121 CommandException.Error error =
1122 ((CommandException) (ar.exception)).getCommandError();
1123 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1124 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1125 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1126 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1127 } else {
1128 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1129 }
1130 loge("setVoNrEnabled" + ": CommandException: "
1131 + ar.exception);
1132 } else {
1133 loge("setVoNrEnabled" + ": Unknown exception");
1134 }
1135 }
1136 notifyRequester(request);
1137 break;
1138 }
1139
SongFerngWang3ef3e072020-12-21 16:41:52 +08001140 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001141 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001142 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1143 request);
1144 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001145 break;
1146
SongFerngWang3ef3e072020-12-21 16:41:52 +08001147 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001148 ar = (AsyncResult) msg.obj;
1149 request = (MainThreadRequest) ar.userObj;
1150 if (ar.exception == null && ar.result != null) {
1151 request.result = ar.result; // Integer
1152 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301153 // request.result must be set to something non-null
1154 // for the calling thread to unblock
1155 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001156 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001157 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001158 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001159 loge("getAllowedNetworkTypesBitmask: CommandException: "
1160 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001161 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001162 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001163 }
1164 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001165 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001166 break;
1167
SongFerngWang3ef3e072020-12-21 16:41:52 +08001168 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001169 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001170 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1171 request);
1172 Pair<Integer, Long> reasonWithNetworkTypes =
1173 (Pair<Integer, Long>) request.argument;
1174 getPhoneFromRequest(request).setAllowedNetworkTypes(
1175 reasonWithNetworkTypes.first,
1176 reasonWithNetworkTypes.second,
1177 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001178 break;
1179
SongFerngWang3ef3e072020-12-21 16:41:52 +08001180 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1181 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001182 break;
1183
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001184 case CMD_SET_VOICEMAIL_NUMBER:
1185 request = (MainThreadRequest) msg.obj;
1186 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1187 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001188 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1189 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001190 break;
1191
1192 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1193 handleNullReturnEvent(msg, "setVoicemailNumber");
1194 break;
1195
Stuart Scott54788802015-03-30 13:18:01 -07001196 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1197 request = (MainThreadRequest) msg.obj;
1198 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1199 request);
1200 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1201 break;
1202
1203 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1204 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1205 break;
1206
Shishir Agrawal302c8692015-06-19 13:49:39 -07001207 case CMD_PERFORM_NETWORK_SCAN:
1208 request = (MainThreadRequest) msg.obj;
1209 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1210 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1211 break;
1212
Hall Liu27d24262020-09-18 19:04:59 -07001213 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001214 request = (MainThreadRequest) msg.obj;
1215 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001216 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1217 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1218 request.argument;
1219 int callForwardingReason = args.first;
1220 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001221 break;
Hall Liu27d24262020-09-18 19:04:59 -07001222 }
1223 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001224 ar = (AsyncResult) msg.obj;
1225 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001226 TelephonyManager.CallForwardingInfoCallback callback =
1227 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1228 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001229 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001230 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001231 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1232 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1233 // Service Class is a bit mask per 3gpp 27.007. Search for
1234 // any service for voice call.
1235 if ((callForwardInfo.serviceClass
1236 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001237 callForwardingInfo = new CallForwardingInfo(
1238 callForwardInfo.status
1239 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001240 callForwardInfo.reason,
1241 callForwardInfo.number,
1242 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001243 break;
1244 }
1245 }
1246 // Didn't find a call forward info for voice call.
1247 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001248 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1249 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001250 }
Hall Liu27d24262020-09-18 19:04:59 -07001251 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001252 } else {
1253 if (ar.result == null) {
1254 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1255 }
1256 if (ar.exception != null) {
1257 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1258 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001259 int errorCode = TelephonyManager
1260 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001261 if (ar.exception instanceof CommandException) {
1262 CommandException.Error error =
1263 ((CommandException) (ar.exception)).getCommandError();
1264 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001265 errorCode = TelephonyManager
1266 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001267 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001268 errorCode = TelephonyManager
1269 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001270 }
1271 }
Hall Liu27d24262020-09-18 19:04:59 -07001272 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001273 }
Shuo Qian4a594052020-01-23 11:59:30 -08001274 break;
Hall Liu27d24262020-09-18 19:04:59 -07001275 }
Shuo Qian4a594052020-01-23 11:59:30 -08001276
Hall Liu27d24262020-09-18 19:04:59 -07001277 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001278 request = (MainThreadRequest) msg.obj;
1279 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001280 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001281 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001282 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1283 request.argument).first;
1284 request.phone.setCallForwardingOption(
1285 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001286 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001287 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001288 callForwardingInfoToSet.getReason(),
1289 callForwardingInfoToSet.getNumber(),
1290 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1291 break;
Hall Liu27d24262020-09-18 19:04:59 -07001292 }
Shuo Qian4a594052020-01-23 11:59:30 -08001293
Hall Liu27d24262020-09-18 19:04:59 -07001294 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001295 ar = (AsyncResult) msg.obj;
1296 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001297 Consumer<Integer> callback =
1298 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1299 request.argument).second;
1300 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001301 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001302 int errorCode = TelephonyManager.CallForwardingInfoCallback
1303 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001304 if (ar.exception instanceof CommandException) {
1305 CommandException.Error error =
1306 ((CommandException) (ar.exception)).getCommandError();
1307 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001308 errorCode = TelephonyManager.CallForwardingInfoCallback
1309 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001310 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001311 errorCode = TelephonyManager.CallForwardingInfoCallback
1312 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001313 }
1314 }
1315 callback.accept(errorCode);
1316 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001317 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001318 }
Shuo Qian4a594052020-01-23 11:59:30 -08001319 break;
Hall Liu27d24262020-09-18 19:04:59 -07001320 }
Shuo Qian4a594052020-01-23 11:59:30 -08001321
Hall Liu27d24262020-09-18 19:04:59 -07001322 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001323 request = (MainThreadRequest) msg.obj;
1324 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1325 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1326 break;
Hall Liu27d24262020-09-18 19:04:59 -07001327 }
Shuo Qian4a594052020-01-23 11:59:30 -08001328
Hall Liu27d24262020-09-18 19:04:59 -07001329 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001330 ar = (AsyncResult) msg.obj;
1331 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001332 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001333 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001334 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001335 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001336 // Service Class is a bit mask per 3gpp 27.007.
1337 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001338 if (callForwardResults.length > 1
1339 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001340 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001341 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001342 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1343 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001344 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001345 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001346 }
1347 } else {
1348 if (ar.result == null) {
1349 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1350 }
1351 if (ar.exception != null) {
1352 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1353 }
1354 if (ar.exception instanceof CommandException) {
1355 CommandException.Error error =
1356 ((CommandException) (ar.exception)).getCommandError();
1357 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001358 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001359 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001360 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1361 callWaitingStatus =
1362 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001363 }
1364 }
1365 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001366 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001367 break;
Hall Liu27d24262020-09-18 19:04:59 -07001368 }
Shuo Qian4a594052020-01-23 11:59:30 -08001369
Hall Liu27d24262020-09-18 19:04:59 -07001370 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001371 request = (MainThreadRequest) msg.obj;
1372 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001373 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1374 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001375 break;
Hall Liu27d24262020-09-18 19:04:59 -07001376 }
Shuo Qian4a594052020-01-23 11:59:30 -08001377
Hall Liu27d24262020-09-18 19:04:59 -07001378 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001379 ar = (AsyncResult) msg.obj;
1380 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001381 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1382 Consumer<Integer> callback =
1383 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1384 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001385 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001386 if (ar.exception instanceof CommandException) {
1387 CommandException.Error error =
1388 ((CommandException) (ar.exception)).getCommandError();
1389 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1390 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001391 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1392 callback.accept(
1393 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001394 } else {
1395 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1396 }
1397 } else {
1398 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1399 }
1400 } else {
1401 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1402 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001403 }
Shuo Qian4a594052020-01-23 11:59:30 -08001404 break;
Hall Liu27d24262020-09-18 19:04:59 -07001405 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001406 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1407 ar = (AsyncResult) msg.obj;
1408 request = (MainThreadRequest) ar.userObj;
1409 CellNetworkScanResult cellScanResult;
1410 if (ar.exception == null && ar.result != null) {
1411 cellScanResult = new CellNetworkScanResult(
1412 CellNetworkScanResult.STATUS_SUCCESS,
1413 (List<OperatorInfo>) ar.result);
1414 } else {
1415 if (ar.result == null) {
1416 loge("getCellNetworkScanResults: Empty response");
1417 }
1418 if (ar.exception != null) {
1419 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1420 }
1421 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1422 if (ar.exception instanceof CommandException) {
1423 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001424 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001425 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1426 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1427 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1428 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1429 }
1430 }
1431 cellScanResult = new CellNetworkScanResult(errorCode, null);
1432 }
1433 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001434 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001435 break;
1436
1437 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1438 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001439 ManualNetworkSelectionArgument selArg =
1440 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001441 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1442 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001443 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1444 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001445 break;
1446
1447 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001448 ar = (AsyncResult) msg.obj;
1449 request = (MainThreadRequest) ar.userObj;
1450 if (ar.exception == null) {
1451 request.result = true;
1452 } else {
1453 request.result = false;
1454 loge("setNetworkSelectionModeManual " + ar.exception);
1455 }
1456 notifyRequester(request);
1457 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001458 break;
1459
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001460 case CMD_GET_MODEM_ACTIVITY_INFO:
1461 request = (MainThreadRequest) msg.obj;
1462 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001463 if (defaultPhone != null) {
1464 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001465 } else {
1466 ResultReceiver result = (ResultReceiver) request.argument;
1467 Bundle bundle = new Bundle();
1468 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001469 new ModemActivityInfo(0, 0, 0,
1470 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001471 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001472 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001473 break;
1474
Hall Liud0f208c2020-10-14 16:54:44 -07001475 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001476 ar = (AsyncResult) msg.obj;
1477 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001478 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001479 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001480 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001481 if (mLastModemActivityInfo == null) {
1482 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1483 mLastModemActivitySpecificInfo[0] =
1484 new ActivityStatsTechSpecificInfo(
1485 0,
1486 0,
1487 new int[ModemActivityInfo.getNumTxPowerLevels()],
1488 0);
1489 mLastModemActivityInfo =
1490 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1491 }
1492
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001493 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001494 // Update the last modem activity info and the result of the request.
1495 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1496 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001497 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001498 } else {
1499 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001500 }
Kai Shi917fdc62022-11-28 14:01:02 -08001501 // This is needed to decouple ret from mLastModemActivityInfo
1502 // We don't want to return mLastModemActivityInfo which is updated
1503 // inside mergeModemActivityInfo()
1504 ret = new ModemActivityInfo(
1505 mLastModemActivityInfo.getTimestampMillis(),
1506 mLastModemActivityInfo.getSleepTimeMillis(),
1507 mLastModemActivityInfo.getIdleTimeMillis(),
1508 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001509
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001510 } else {
1511 if (ar.result == null) {
1512 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001513 error = TelephonyManager.ModemActivityInfoException
1514 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001515 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001516 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001517 error = TelephonyManager.ModemActivityInfoException
1518 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001519 } else {
1520 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001521 error = TelephonyManager.ModemActivityInfoException
1522 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001523 }
1524 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001525 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001526 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001527 bundle.putParcelable(
1528 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001529 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001530 } else {
1531 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1532 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001533 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001534 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001535 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001536 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001537
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001538 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001539 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001540 CarrierRestrictionRules argument =
1541 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001542 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001543 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001544 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001545 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001546
1547 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1548 ar = (AsyncResult) msg.obj;
1549 request = (MainThreadRequest) ar.userObj;
1550 if (ar.exception == null && ar.result != null) {
1551 request.result = ar.result;
1552 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001553 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1554 if (ar.exception instanceof CommandException) {
1555 loge("setAllowedCarriers: CommandException: " + ar.exception);
1556 CommandException.Error error =
1557 ((CommandException) (ar.exception)).getCommandError();
1558 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1559 request.result =
1560 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1561 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001562 } else {
1563 loge("setAllowedCarriers: Unknown exception");
1564 }
1565 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001566 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001567 break;
1568
1569 case CMD_GET_ALLOWED_CARRIERS:
1570 request = (MainThreadRequest) msg.obj;
1571 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001572 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001573 break;
1574
1575 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1576 ar = (AsyncResult) msg.obj;
1577 request = (MainThreadRequest) ar.userObj;
1578 if (ar.exception == null && ar.result != null) {
1579 request.result = ar.result;
1580 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001581 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001582 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001583 if (ar.result == null) {
1584 loge("getAllowedCarriers: Empty response");
1585 } else if (ar.exception instanceof CommandException) {
1586 loge("getAllowedCarriers: CommandException: " +
1587 ar.exception);
1588 } else {
1589 loge("getAllowedCarriers: Unknown exception");
1590 }
1591 }
arunvoddud7401012022-12-15 16:08:12 +00001592 if (request.argument != null) {
1593 // This is for the implementation of carrierRestrictionStatus.
1594 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1595 Consumer<Integer> callback = callbackInfo.getConsumer();
Steve Statia28b7cb32024-03-11 23:58:50 +00001596 Set<Integer> callerCarrierIds = callbackInfo.getCarrierIds();
arunvoddud7401012022-12-15 16:08:12 +00001597 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1598 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1599 CarrierRestrictionRules carrierRestrictionRules =
1600 (CarrierRestrictionRules) ar.result;
1601 int carrierId = -1;
1602 try {
1603 CarrierIdentifier carrierIdentifier =
1604 carrierRestrictionRules.getAllowedCarriers().get(0);
1605 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1606 carrierIdentifier);
1607 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1608 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1609 }
1610 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
Steve Statia28b7cb32024-03-11 23:58:50 +00001611 int restrictedStatus =
1612 TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED;
1613 if (carrierId != -1 && callerCarrierIds.contains(carrierId) &&
1614 lockStatus == restrictedStatus) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001615 lockStatus = TelephonyManager
1616 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001617 }
1618 } else {
1619 Rlog.e(LOG_TAG,
1620 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1621 }
1622 callback.accept(lockStatus);
1623 } else {
1624 // This is for the implementation of getAllowedCarriers.
1625 notifyRequester(request);
1626 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001627 break;
1628
Nathan Haroldb3014052017-01-25 15:57:32 -08001629 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1630 ar = (AsyncResult) msg.obj;
1631 request = (MainThreadRequest) ar.userObj;
1632 if (ar.exception == null && ar.result != null) {
1633 request.result = ar.result;
1634 } else {
1635 request.result = new IllegalArgumentException(
1636 "Failed to retrieve Forbidden Plmns");
1637 if (ar.result == null) {
1638 loge("getForbiddenPlmns: Empty response");
1639 } else {
1640 loge("getForbiddenPlmns: Unknown exception");
1641 }
1642 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001643 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001644 break;
1645
1646 case CMD_GET_FORBIDDEN_PLMNS:
1647 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001648 uiccPort = getUiccPortFromRequest(request);
1649 if (uiccPort == null) {
1650 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001651 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001652 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001653 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001654 break;
1655 }
1656 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001657 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001658 if (uiccApp == null) {
1659 loge("getForbiddenPlmns() no app with specified type -- "
1660 + appType);
1661 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001662 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001663 break;
1664 } else {
1665 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1666 + " specified type -- " + appType);
1667 }
1668 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1669 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001670 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001671 break;
1672
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001673 case CMD_SWITCH_SLOTS:
1674 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001675 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001676 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001677 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001678 break;
1679
1680 case EVENT_SWITCH_SLOTS_DONE:
1681 ar = (AsyncResult) msg.obj;
1682 request = (MainThreadRequest) ar.userObj;
1683 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001684 notifyRequester(request);
1685 break;
1686 case CMD_GET_NETWORK_SELECTION_MODE:
1687 request = (MainThreadRequest) msg.obj;
1688 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1689 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1690 break;
1691
1692 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1693 ar = (AsyncResult) msg.obj;
1694 request = (MainThreadRequest) ar.userObj;
1695 if (ar.exception != null) {
1696 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1697 } else {
1698 int mode = ((int[]) ar.result)[0];
1699 if (mode == 0) {
1700 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1701 } else {
1702 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1703 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001704 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001705 notifyRequester(request);
1706 break;
1707 case CMD_GET_CDMA_ROAMING_MODE:
1708 request = (MainThreadRequest) msg.obj;
1709 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1710 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1711 break;
1712 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1713 ar = (AsyncResult) msg.obj;
1714 request = (MainThreadRequest) ar.userObj;
1715 if (ar.exception != null) {
1716 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1717 } else {
1718 request.result = ((int[]) ar.result)[0];
1719 }
1720 notifyRequester(request);
1721 break;
1722 case CMD_SET_CDMA_ROAMING_MODE:
1723 request = (MainThreadRequest) msg.obj;
1724 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1725 int mode = (int) request.argument;
1726 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1727 break;
1728 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1729 ar = (AsyncResult) msg.obj;
1730 request = (MainThreadRequest) ar.userObj;
1731 request.result = ar.exception == null;
1732 notifyRequester(request);
1733 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001734 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1735 request = (MainThreadRequest) msg.obj;
1736 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1737 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1738 break;
1739 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1740 ar = (AsyncResult) msg.obj;
1741 request = (MainThreadRequest) ar.userObj;
1742 if (ar.exception != null) {
1743 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1744 } else {
1745 request.result = ((int[]) ar.result)[0];
1746 }
1747 notifyRequester(request);
1748 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001749 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1750 request = (MainThreadRequest) msg.obj;
1751 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1752 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001753 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1754 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001755 break;
1756 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1757 ar = (AsyncResult) msg.obj;
1758 request = (MainThreadRequest) ar.userObj;
1759 request.result = ar.exception == null;
1760 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001761 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001762 case CMD_GET_ALL_CELL_INFO:
1763 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001764 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001765 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001766 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001767 case EVENT_GET_ALL_CELL_INFO_DONE:
1768 ar = (AsyncResult) msg.obj;
1769 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001770 // If a timeout occurs, the response will be null
1771 request.result = (ar.exception == null && ar.result != null)
1772 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001773 synchronized (request) {
1774 request.notifyAll();
1775 }
1776 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001777 case CMD_REQUEST_CELL_INFO_UPDATE:
1778 request = (MainThreadRequest) msg.obj;
1779 request.phone.requestCellInfoUpdate(request.workSource,
1780 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1781 break;
1782 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1783 ar = (AsyncResult) msg.obj;
1784 request = (MainThreadRequest) ar.userObj;
1785 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1786 try {
1787 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001788 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001789 cb.onError(
1790 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1791 ar.exception.getClass().getName(),
1792 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001793 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001794 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001795 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001796 } else {
1797 // use the result as returned
1798 cb.onCellInfo((List<CellInfo>) ar.result);
1799 }
1800 } catch (RemoteException re) {
1801 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1802 }
1803 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001804 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001805 request = (MainThreadRequest) msg.obj;
1806 WorkSource ws = (WorkSource) request.argument;
1807 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001808 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001809 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001810 }
1811 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001812 ar = (AsyncResult) msg.obj;
1813 request = (MainThreadRequest) ar.userObj;
1814 if (ar.exception == null) {
1815 request.result = ar.result;
1816 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001817 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001818 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001819 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001820 }
1821
1822 synchronized (request) {
1823 request.notifyAll();
1824 }
1825 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001826 }
chen xu6dac5ab2018-10-26 17:39:23 -07001827 case CMD_MODEM_REBOOT:
1828 request = (MainThreadRequest) msg.obj;
1829 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001830 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001831 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001832 case EVENT_CMD_MODEM_REBOOT_DONE:
1833 handleNullReturnEvent(msg, "rebootModem");
1834 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001835 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001836 request = (MainThreadRequest) msg.obj;
1837 boolean enable = (boolean) request.argument;
1838 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001839 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001840 PhoneConfigurationManager.getInstance()
1841 .enablePhone(request.phone, enable, onCompleted);
1842 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001843 }
Michele Berionne5e411512020-11-13 02:36:59 +00001844 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001845 ar = (AsyncResult) msg.obj;
1846 request = (MainThreadRequest) ar.userObj;
1847 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001848 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001849 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001850 if ((boolean) request.result) {
1851 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1852 updateModemStateMetrics();
1853 } else {
1854 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1855 + ar.exception);
1856 }
1857 notifyRequester(request);
1858 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001859 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001860 case CMD_GET_MODEM_STATUS:
1861 request = (MainThreadRequest) msg.obj;
1862 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1863 PhoneConfigurationManager.getInstance()
1864 .getPhoneStatusFromModem(request.phone, onCompleted);
1865 break;
1866 case EVENT_GET_MODEM_STATUS_DONE:
1867 ar = (AsyncResult) msg.obj;
1868 request = (MainThreadRequest) ar.userObj;
1869 int id = request.phone.getPhoneId();
1870 if (ar.exception == null && ar.result != null) {
1871 request.result = ar.result;
1872 //update the cache as modem status has changed
1873 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1874 (boolean) request.result);
1875 } else {
1876 // Return true if modem status cannot be retrieved. For most cases,
1877 // modem status is on. And for older version modems, GET_MODEM_STATUS
1878 // and disable modem are not supported. Modem is always on.
1879 // TODO: this should be fixed in R to support a third
1880 // status UNKNOWN b/131631629
1881 request.result = true;
1882 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1883 + ar.exception);
1884 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001885 notifyRequester(request);
1886 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001887 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1888 request = (MainThreadRequest) msg.obj;
1889 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1890 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1891 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1892 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1893 break;
1894 }
1895 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1896 ar = (AsyncResult) msg.obj;
1897 request = (MainThreadRequest) ar.userObj;
1898 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1899 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1900 args.second.accept(ar.exception == null);
1901 notifyRequester(request);
1902 break;
1903 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001904 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1905 request = (MainThreadRequest) msg.obj;
1906 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1907 Phone phone = getPhoneFromRequest(request);
1908 if (phone != null) {
1909 phone.getSystemSelectionChannels(onCompleted);
1910 } else {
1911 loge("getSystemSelectionChannels: No phone object");
1912 request.result = new ArrayList<RadioAccessSpecifier>();
1913 notifyRequester(request);
1914 }
1915 break;
1916 }
1917 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1918 ar = (AsyncResult) msg.obj;
1919 request = (MainThreadRequest) ar.userObj;
1920 if (ar.exception == null && ar.result != null) {
1921 request.result = ar.result;
1922 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001923 request.result = new IllegalStateException(
1924 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001925 if (ar.result == null) {
1926 loge("getSystemSelectionChannels: Empty response");
1927 } else {
1928 loge("getSystemSelectionChannels: Unknown exception");
1929 }
1930 }
1931 notifyRequester(request);
1932 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001933 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1934 ar = (AsyncResult) msg.obj;
1935 request = (MainThreadRequest) ar.userObj;
1936 if (ar.exception == null && ar.result != null) {
1937 request.result = ar.result;
1938 } else {
1939 request.result = -1;
1940 loge("Failed to set Forbidden Plmns");
1941 if (ar.result == null) {
1942 loge("setForbidenPlmns: Empty response");
1943 } else if (ar.exception != null) {
1944 loge("setForbiddenPlmns: Exception: " + ar.exception);
1945 request.result = -1;
1946 } else {
1947 loge("setForbiddenPlmns: Unknown exception");
1948 }
1949 }
1950 notifyRequester(request);
1951 break;
1952 case CMD_SET_FORBIDDEN_PLMNS:
1953 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001954 uiccPort = getUiccPortFromRequest(request);
1955 if (uiccPort == null) {
1956 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001957 request.result = -1;
1958 notifyRequester(request);
1959 break;
1960 }
1961 Pair<Integer, List<String>> setFplmnsArgs =
1962 (Pair<Integer, List<String>>) request.argument;
1963 appType = setFplmnsArgs.first;
1964 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001965 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001966 if (uiccApp == null) {
1967 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1968 request.result = -1;
1969 loge("Failed to get UICC App");
1970 notifyRequester(request);
1971 } else {
1972 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1973 ((SIMRecords) uiccApp.getIccRecords())
1974 .setForbiddenPlmns(onCompleted, fplmns);
1975 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001976 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001977 case CMD_ERASE_MODEM_CONFIG:
1978 request = (MainThreadRequest) msg.obj;
1979 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1980 defaultPhone.eraseModemConfig(onCompleted);
1981 break;
1982 case EVENT_ERASE_MODEM_CONFIG_DONE:
1983 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001984 break;
zoey chene02881a2019-12-30 16:11:23 +08001985
Kai Shif70f46f2021-03-03 13:59:46 -08001986 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1987 request = (MainThreadRequest) msg.obj;
1988 request.result = defaultPhone.eraseDataInSharedPreferences();
1989 notifyRequester(request);
1990 break;
1991
zoey chene02881a2019-12-30 16:11:23 +08001992 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1993 request = (MainThreadRequest) msg.obj;
1994 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1995 Pair<String, String> changed = (Pair<String, String>) request.argument;
1996 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1997 changed.first, changed.second, onCompleted);
1998 break;
1999 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
2000 ar = (AsyncResult) msg.obj;
2001 request = (MainThreadRequest) ar.userObj;
2002 if (ar.exception == null) {
2003 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002004 // If the operation is successful, update the PIN storage
2005 Pair<String, String> passwords = (Pair<String, String>) request.argument;
2006 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00002007 UiccController.getInstance().getPinStorage()
2008 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08002009 } else {
2010 request.result = msg.arg1;
2011 }
2012 notifyRequester(request);
2013 break;
2014
Michele Berionne5e411512020-11-13 02:36:59 +00002015 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08002016 request = (MainThreadRequest) msg.obj;
2017 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
2018 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2019 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2020 enabled.first, enabled.second, onCompleted);
2021 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002022 }
zoey chene02881a2019-12-30 16:11:23 +08002023 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2024 ar = (AsyncResult) msg.obj;
2025 request = (MainThreadRequest) ar.userObj;
2026 if (ar.exception == null) {
2027 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002028 // If the operation is successful, update the PIN storage
2029 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2030 int phoneId = getPhoneFromRequest(request).getPhoneId();
2031 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002032 UiccController.getInstance().getPinStorage()
2033 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002034 } else {
2035 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2036 }
zoey chene02881a2019-12-30 16:11:23 +08002037 } else {
2038 request.result = msg.arg1;
2039 }
Michele Berionne5e411512020-11-13 02:36:59 +00002040
2041
zoey chene02881a2019-12-30 16:11:23 +08002042 notifyRequester(request);
2043 break;
2044
Peter Wangdafb9ac2020-01-15 14:13:38 -08002045 case MSG_NOTIFY_USER_ACTIVITY:
2046 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002047 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002048 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2049 getDefaultPhone().getContext().sendBroadcastAsUser(
2050 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2051 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002052
2053 case CMD_SET_DATA_THROTTLING: {
2054 request = (MainThreadRequest) msg.obj;
2055 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2056 DataThrottlingRequest dataThrottlingRequest =
2057 (DataThrottlingRequest) request.argument;
2058 Phone phone = getPhoneFromRequest(request);
2059 if (phone != null) {
2060 phone.setDataThrottling(onCompleted,
2061 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2062 dataThrottlingRequest.getCompletionDurationMillis());
2063 } else {
2064 loge("setDataThrottling: No phone object");
2065 request.result =
2066 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2067 notifyRequester(request);
2068 }
2069
2070 break;
2071 }
2072 case EVENT_SET_DATA_THROTTLING_DONE:
2073 ar = (AsyncResult) msg.obj;
2074 request = (MainThreadRequest) ar.userObj;
2075
2076 if (ar.exception == null) {
2077 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2078 } else if (ar.exception instanceof CommandException) {
2079 loge("setDataThrottling: CommandException: " + ar.exception);
2080 CommandException.Error error =
2081 ((CommandException) (ar.exception)).getCommandError();
2082
2083 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2084 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002085 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002086 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2087 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002088 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2089 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002090 } else {
2091 request.result =
2092 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2093 }
2094 } else {
2095 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2096 }
2097 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2098 notifyRequester(request);
2099 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002100
2101 case CMD_SET_SIM_POWER: {
2102 request = (MainThreadRequest) msg.obj;
2103 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2104 request = (MainThreadRequest) msg.obj;
2105 int stateToSet =
2106 ((Pair<Integer, IIntegerConsumer>)
2107 request.argument).first;
2108 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2109 break;
2110 }
2111 case EVENT_SET_SIM_POWER_DONE: {
2112 ar = (AsyncResult) msg.obj;
2113 request = (MainThreadRequest) ar.userObj;
2114 IIntegerConsumer callback =
2115 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2116 if (ar.exception != null) {
2117 loge("setSimPower exception: " + ar.exception);
2118 int errorCode = TelephonyManager.CallForwardingInfoCallback
2119 .RESULT_ERROR_UNKNOWN;
2120 if (ar.exception instanceof CommandException) {
2121 CommandException.Error error =
2122 ((CommandException) (ar.exception)).getCommandError();
2123 if (error == CommandException.Error.SIM_ERR) {
2124 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2125 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2126 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2127 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2128 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2129 } else {
2130 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2131 }
2132 }
2133 try {
2134 callback.accept(errorCode);
2135 } catch (RemoteException e) {
2136 // Ignore if the remote process is no longer available to call back.
2137 Log.w(LOG_TAG, "setSimPower: callback not available.");
2138 }
2139 } else {
2140 try {
2141 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2142 } catch (RemoteException e) {
2143 // Ignore if the remote process is no longer available to call back.
2144 Log.w(LOG_TAG, "setSimPower: callback not available.");
2145 }
2146 }
2147 break;
2148 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002149 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2150 request = (MainThreadRequest) msg.obj;
2151
2152 final Phone phone = getPhoneFromRequest(request);
2153 if (phone == null || phone.getServiceStateTracker() == null) {
2154 request.result = new IllegalStateException("Phone or SST is null");
2155 notifyRequester(request);
2156 break;
2157 }
2158
2159 Pair<Integer, SignalStrengthUpdateRequest> pair =
2160 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2161 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2162 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002163 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002164 request.subId, pair.first /*callingUid*/,
2165 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002166 break;
2167 }
2168 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2169 ar = (AsyncResult) msg.obj;
2170 request = (MainThreadRequest) ar.userObj;
2171 // request.result will be the exception of ar if present, true otherwise.
2172 // Be cautious not to leave result null which will wait() forever
2173 request.result = ar.exception != null ? ar.exception : true;
2174 notifyRequester(request);
2175 break;
2176 }
2177 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2178 request = (MainThreadRequest) msg.obj;
2179
2180 Phone phone = getPhoneFromRequest(request);
2181 if (phone == null || phone.getServiceStateTracker() == null) {
2182 request.result = new IllegalStateException("Phone or SST is null");
2183 notifyRequester(request);
2184 break;
2185 }
2186
2187 Pair<Integer, SignalStrengthUpdateRequest> pair =
2188 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2189 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2190 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002191 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002192 request.subId, pair.first /*callingUid*/,
2193 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002194 break;
2195 }
2196 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2197 ar = (AsyncResult) msg.obj;
2198 request = (MainThreadRequest) ar.userObj;
2199 request.result = ar.exception != null ? ar.exception : true;
2200 notifyRequester(request);
2201 break;
2202 }
Jordan Liu109698e2020-11-24 14:50:34 -08002203
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002204 case CMD_GET_SLICING_CONFIG: {
2205 request = (MainThreadRequest) msg.obj;
2206 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2207 request.phone.getSlicingConfig(onCompleted);
2208 break;
2209 }
2210 case EVENT_GET_SLICING_CONFIG_DONE: {
2211 ar = (AsyncResult) msg.obj;
2212 request = (MainThreadRequest) ar.userObj;
2213 ResultReceiver result = (ResultReceiver) request.argument;
2214
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002215 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002216 Bundle bundle = new Bundle();
2217 int resultCode = 0;
2218 if (ar.exception != null) {
2219 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2220 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002221 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002222 } else if (ar.result == null) {
2223 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002224 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002225 } else {
2226 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002227 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2228 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002229 }
2230
2231 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002232 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002233 }
2234 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2235 result.send(resultCode, bundle);
2236 notifyRequester(request);
2237 break;
2238 }
2239
Sarah Chin71b3a852022-09-28 15:54:19 -07002240 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002241 request = (MainThreadRequest) msg.obj;
2242 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002243 PurchasePremiumCapabilityArgument arg =
2244 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chincc5446f2023-10-23 17:57:19 -07002245 SlicePurchaseController.getInstance(request.phone, mFeatureFlags)
2246 .purchasePremiumCapability(arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002247 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002248 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002249
Sarah Chin71b3a852022-09-28 15:54:19 -07002250 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002251 ar = (AsyncResult) msg.obj;
2252 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002253 PurchasePremiumCapabilityArgument arg =
2254 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002255 try {
2256 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002257 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002258 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002259 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chinff8b1802023-04-11 14:22:14 -07002260 + ", result="
Sarah Chin2ec39f62022-08-31 17:03:26 -07002261 + TelephonyManager.convertPurchaseResultToString(result));
2262 } catch (RemoteException e) {
2263 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002264 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002265 + " failed: " + e;
2266 if (DBG) log(logStr);
2267 AnomalyReporter.reportAnomaly(
2268 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2269 }
2270 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002271 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002272
Michele Berionne5e411512020-11-13 02:36:59 +00002273 case CMD_PREPARE_UNATTENDED_REBOOT:
2274 request = (MainThreadRequest) msg.obj;
2275 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002276 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002277 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002278 notifyRequester(request);
2279 break;
2280
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002281 default:
2282 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2283 break;
2284 }
2285 }
Jake Hambye994d462014-02-03 13:10:13 -08002286
Pengquan Menga1bb6272018-09-06 09:59:22 -07002287 private void notifyRequester(MainThreadRequest request) {
2288 synchronized (request) {
2289 request.notifyAll();
2290 }
2291 }
2292
Jake Hambye994d462014-02-03 13:10:13 -08002293 private void handleNullReturnEvent(Message msg, String command) {
2294 AsyncResult ar = (AsyncResult) msg.obj;
2295 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2296 if (ar.exception == null) {
2297 request.result = true;
2298 } else {
2299 request.result = false;
2300 if (ar.exception instanceof CommandException) {
2301 loge(command + ": CommandException: " + ar.exception);
2302 } else {
2303 loge(command + ": Unknown exception");
2304 }
2305 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002306 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002307 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002308 }
2309
2310 /**
2311 * Posts the specified command to be executed on the main thread,
2312 * waits for the request to complete, and returns the result.
2313 * @see #sendRequestAsync
2314 */
2315 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002316 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2317 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002318 }
2319
2320 /**
2321 * Posts the specified command to be executed on the main thread,
2322 * waits for the request to complete, and returns the result.
2323 * @see #sendRequestAsync
2324 */
2325 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2326 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002327 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002328 }
2329
2330 /**
2331 * Posts the specified command to be executed on the main thread,
2332 * waits for the request to complete, and returns the result.
2333 * @see #sendRequestAsync
2334 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002335 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002336 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2337 }
2338
2339 /**
2340 * Posts the specified command to be executed on the main thread,
2341 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2342 * if not timeout or null otherwise.
2343 * @see #sendRequestAsync
2344 */
2345 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2346 long timeoutInMs) {
2347 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002348 }
2349
2350 /**
2351 * Posts the specified command to be executed on the main thread,
2352 * waits for the request to complete, and returns the result.
2353 * @see #sendRequestAsync
2354 */
Nathan Harold92bed182018-10-12 18:16:49 -07002355 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002356 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002357 }
2358
2359 /**
2360 * Posts the specified command to be executed on the main thread,
2361 * waits for the request to complete, and returns the result.
2362 * @see #sendRequestAsync
2363 */
2364 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002365 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2366 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002367 }
2368
2369 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002370 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2371 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2372 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002373 * @see #sendRequestAsync
2374 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002375 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2376 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002377 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2378 throw new RuntimeException("This method will deadlock if called from the main thread.");
2379 }
2380
Nathan Harold92bed182018-10-12 18:16:49 -07002381 MainThreadRequest request = null;
2382 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2383 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2384 } else if (phone != null) {
2385 request = new MainThreadRequest(argument, phone, workSource);
2386 } else {
2387 request = new MainThreadRequest(argument, subId, workSource);
2388 }
2389
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002390 Message msg = mMainThreadHandler.obtainMessage(command, request);
2391 msg.sendToTarget();
2392
Rambo Wang0f050d82021-02-12 11:43:36 -08002393
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002394 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002395 if (timeoutInMs >= 0) {
2396 // Wait for at least timeoutInMs before returning null request result
2397 long now = SystemClock.elapsedRealtime();
2398 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002399 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002400 try {
2401 request.wait(deadline - now);
2402 } catch (InterruptedException e) {
2403 // Do nothing, go back and check if request is completed or timeout
2404 } finally {
2405 now = SystemClock.elapsedRealtime();
2406 }
2407 }
2408 } else {
2409 // Wait for the request to complete
2410 while (request.result == null) {
2411 try {
2412 request.wait();
2413 } catch (InterruptedException e) {
2414 // Do nothing, go back and wait until the request is complete
2415 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002416 }
2417 }
2418 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002419 if (request.result == null) {
2420 Log.wtf(LOG_TAG,
2421 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2422 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002423 return request.result;
2424 }
2425
2426 /**
2427 * Asynchronous ("fire and forget") version of sendRequest():
2428 * Posts the specified command to be executed on the main thread, and
2429 * returns immediately.
2430 * @see #sendRequest
2431 */
2432 private void sendRequestAsync(int command) {
2433 mMainThreadHandler.sendEmptyMessage(command);
2434 }
2435
2436 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002437 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002438 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002439 */
2440 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002441 sendRequestAsync(command, argument, null, null);
2442 }
2443
2444 /**
2445 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2446 * @see {@link #sendRequest(int,Object)}
2447 */
2448 private void sendRequestAsync(
2449 int command, Object argument, Phone phone, WorkSource workSource) {
2450 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002451 Message msg = mMainThreadHandler.obtainMessage(command, request);
2452 msg.sendToTarget();
2453 }
2454
2455 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002456 * Initialize the singleton PhoneInterfaceManager instance.
2457 * This is only done once, at startup, from PhoneApp.onCreate().
2458 */
Sarah Chincc5446f2023-10-23 17:57:19 -07002459 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002460 synchronized (PhoneInterfaceManager.class) {
2461 if (sInstance == null) {
Sarah Chincc5446f2023-10-23 17:57:19 -07002462 sInstance = new PhoneInterfaceManager(app, featureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002463 } else {
2464 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2465 }
2466 return sInstance;
2467 }
2468 }
2469
2470 /** Private constructor; @see init() */
Sarah Chincc5446f2023-10-23 17:57:19 -07002471 private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002472 mApp = app;
Sarah Chincc5446f2023-10-23 17:57:19 -07002473 mFeatureFlags = featureFlags;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -08002474 mTelecomFeatureFlags = new com.android.server.telecom.flags.FeatureFlagsImpl();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002475 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002476 mImsResolver = ImsResolver.getInstance();
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +00002477 mSatelliteController = SatelliteController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002478 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002479 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2480 mMainThreadHandler = new MainThreadHandler();
Sarah Chin4beb2b72023-02-14 14:47:54 -08002481 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002482 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002483 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002484 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002485 mNotifyUserActivity = new AtomicBoolean(false);
joonhunshin4ac60942023-11-15 15:23:39 +00002486 mPackageManager = app.getPackageManager();
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -08002487 mSatelliteAccessController = SatelliteAccessController.getOrCreateInstance(
2488 getDefaultPhone().getContext(), featureFlags);
joonhunshinf624b2a2024-04-18 04:42:12 +00002489 mVendorApiLevel = SystemProperties.getInt(
2490 "ro.vendor.api_level", Build.VERSION.DEVICE_INITIAL_SDK_INT);
2491
Tyler Gunn64144d92022-03-17 14:16:41 -07002492 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002493 publish();
arunvoddud7401012022-12-15 16:08:12 +00002494 CarrierAllowListInfo.loadInstance(mApp);
Hyosun Kim240214a2023-11-02 13:30:15 +00002495
2496 // Create the SatelliteEntitlementController singleton, for using the get the
2497 // entitlementStatus for satellite service.
2498 SatelliteEntitlementController.make(mApp, mFeatureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002499 }
2500
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002501 @VisibleForTesting
2502 public SharedPreferences getSharedPreferences() {
2503 return mTelephonySharedPreferences;
2504 }
2505
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002506 /**
2507 * Get the default phone for this device.
2508 */
2509 @VisibleForTesting
2510 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002511 Phone thePhone = getPhone(getDefaultSubscription());
2512 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2513 }
2514
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002515 private void publish() {
2516 if (DBG) log("publish: " + this);
2517
Peter Wangc035ce42020-01-08 21:00:22 -08002518 TelephonyFrameworkInitializer
2519 .getTelephonyServiceManager()
2520 .getTelephonyServiceRegisterer()
2521 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002522 }
2523
Stuart Scott584921c2015-01-15 17:10:34 -08002524 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002525 if (request.phone != null) {
2526 return request.phone;
2527 } else {
2528 return getPhoneFromSubId(request.subId);
2529 }
2530 }
2531
2532 private Phone getPhoneFromSubId(int subId) {
2533 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2534 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002535 }
2536
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002537 /**
2538 * Get phone object associated with a subscription.
2539 * Return default phone if phone object associated with subscription is null
2540 * @param subId - subscriptionId
2541 * @return phone object associated with a subscription or default phone if null.
2542 */
Ling Mac28f0212023-03-24 16:07:15 -07002543 private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) {
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002544 Phone phone = getPhoneFromSubId(subId);
2545 if (phone == null) {
Ling Mac28f0212023-03-24 16:07:15 -07002546 loge("Called with invalid subId: " + subId + ". Retrying with default phone.");
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002547 phone = getDefaultPhone();
2548 }
2549 return phone;
2550 }
2551
Rambo Wange53e07d2022-05-10 13:01:13 -07002552 @Nullable
2553 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002554 Phone phone = getPhoneFromRequest(request);
2555 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002556 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002557 }
2558
Ling Mac28f0212023-03-24 16:07:15 -07002559 /**
2560 * @param subId The sub Id that associates the phone. If the device has no active SIM, passing
2561 * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <=
2562 * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}.
2563 * @return The Phone associated the sub Id
2564 */
2565 private @Nullable Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002566 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002567 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002568
Kai Shif70f46f2021-03-03 13:59:46 -08002569 private void sendEraseModemConfig(@NonNull Phone phone) {
2570 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2571 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2572 }
2573
2574 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2575 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2576 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002577 }
2578
Peter Wang44b186e2020-01-13 23:33:09 -08002579 private boolean isImsAvailableOnDevice() {
2580 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2581 if (pm == null) {
2582 // For some reason package manger is not available.. This will fail internally anyway,
2583 // so do not throw error and allow.
2584 return true;
2585 }
2586 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2587 }
2588
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002589 public void dial(String number) {
joonhunshin4ac60942023-11-15 15:23:39 +00002590 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2591 PackageManager.FEATURE_TELEPHONY_CALLING, "dial");
2592
Wink Savilleadd7cc52014-09-08 14:23:09 -07002593 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002594 }
2595
Wink Savilleb564aae2014-10-23 10:18:09 -07002596 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002597 if (DBG) log("dial: " + number);
2598 // No permission check needed here: This is just a wrapper around the
2599 // ACTION_DIAL intent, which is available to any app since it puts up
2600 // the UI before it does anything.
2601
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002602 final long identity = Binder.clearCallingIdentity();
2603 try {
2604 String url = createTelUrl(number);
2605 if (url == null) {
2606 return;
2607 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002608
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002609 // PENDING: should we just silently fail if phone is offhook or ringing?
2610 PhoneConstants.State state = mCM.getState(subId);
2611 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2612 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2613 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2614 mApp.startActivity(intent);
2615 }
2616 } finally {
2617 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002618 }
2619 }
2620
2621 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002622 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002623 }
2624
Wink Savilleb564aae2014-10-23 10:18:09 -07002625 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002626 if (DBG) log("call: " + number);
2627
2628 // This is just a wrapper around the ACTION_CALL intent, but we still
2629 // need to do a permission check since we're calling startActivity()
2630 // from the context of the phone app.
2631 enforceCallPermission();
2632
Jordan Liu1617b712019-07-10 15:06:26 -07002633 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002634 != AppOpsManager.MODE_ALLOWED) {
2635 return;
2636 }
2637
joonhunshin4ac60942023-11-15 15:23:39 +00002638 enforceTelephonyFeatureWithException(callingPackage,
2639 PackageManager.FEATURE_TELEPHONY_CALLING, "call");
2640
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002641 final long identity = Binder.clearCallingIdentity();
2642 try {
2643 String url = createTelUrl(number);
2644 if (url == null) {
2645 return;
2646 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002647
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002648 boolean isValid = false;
2649 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2650 if (slist != null) {
2651 for (SubscriptionInfo subInfoRecord : slist) {
2652 if (subInfoRecord.getSubscriptionId() == subId) {
2653 isValid = true;
2654 break;
2655 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002656 }
Wink Saville08874612014-08-31 19:19:58 -07002657 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002658 if (!isValid) {
2659 return;
2660 }
Wink Saville08874612014-08-31 19:19:58 -07002661
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002662 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2663 intent.putExtra(SUBSCRIPTION_KEY, subId);
2664 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2665 mApp.startActivity(intent);
2666 } finally {
2667 Binder.restoreCallingIdentity(identity);
2668 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002669 }
2670
Wink Savilleb564aae2014-10-23 10:18:09 -07002671 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002672 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002673 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2674 }
2675
Wink Savilleb564aae2014-10-23 10:18:09 -07002676 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002677 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002678 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2679 }
2680
Wink Savilleb564aae2014-10-23 10:18:09 -07002681 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002682 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002683
joonhunshin4ac60942023-11-15 15:23:39 +00002684 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2685 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
2686 "supplyPinReportResultForSubscriber");
2687
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002688 final long identity = Binder.clearCallingIdentity();
2689 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002690 Phone phone = getPhone(subId);
2691 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002692 checkSimPin.start();
2693 return checkSimPin.unlockSim(null, pin);
2694 } finally {
2695 Binder.restoreCallingIdentity(identity);
2696 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002697 }
2698
Wink Savilleb564aae2014-10-23 10:18:09 -07002699 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002700 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002701
joonhunshin4ac60942023-11-15 15:23:39 +00002702 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2703 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "supplyPukForSubscriber");
2704
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002705 final long identity = Binder.clearCallingIdentity();
2706 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002707 Phone phone = getPhone(subId);
2708 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002709 checkSimPuk.start();
2710 return checkSimPuk.unlockSim(puk, pin);
2711 } finally {
2712 Binder.restoreCallingIdentity(identity);
2713 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002714 }
2715
2716 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002717 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002718 * a synchronous one.
2719 */
2720 private static class UnlockSim extends Thread {
2721
2722 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002723 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002724
2725 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002726 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2727 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002728
2729 // For replies from SimCard interface
2730 private Handler mHandler;
2731
2732 // For async handler to identify request type
2733 private static final int SUPPLY_PIN_COMPLETE = 100;
2734
Michele Berionne5e411512020-11-13 02:36:59 +00002735 UnlockSim(int phoneId, IccCard simCard) {
2736 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002737 mSimCard = simCard;
2738 }
2739
2740 @Override
2741 public void run() {
2742 Looper.prepare();
2743 synchronized (UnlockSim.this) {
2744 mHandler = new Handler() {
2745 @Override
2746 public void handleMessage(Message msg) {
2747 AsyncResult ar = (AsyncResult) msg.obj;
2748 switch (msg.what) {
2749 case SUPPLY_PIN_COMPLETE:
2750 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2751 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002752 mRetryCount = msg.arg1;
2753 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002754 CommandException.Error error = null;
2755 if (ar.exception instanceof CommandException) {
2756 error = ((CommandException) (ar.exception))
2757 .getCommandError();
2758 }
2759 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07002760 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002761 } else if (error == CommandException.Error.ABORTED) {
2762 /* When UiccCardApp dispose, handle message and return
2763 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08002764 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002765 } else {
2766 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2767 }
2768 } else {
2769 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2770 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002771 mDone = true;
2772 UnlockSim.this.notifyAll();
2773 }
2774 break;
2775 }
2776 }
2777 };
2778 UnlockSim.this.notifyAll();
2779 }
2780 Looper.loop();
2781 }
2782
2783 /*
2784 * Use PIN or PUK to unlock SIM card
2785 *
2786 * If PUK is null, unlock SIM card with PIN
2787 *
2788 * If PUK is not null, unlock SIM card with PUK and set PIN code
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302789 *
2790 * Besides, since it is reused in class level, the thread's looper will be stopped to avoid
2791 * its thread leak.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002792 */
Wink Saville9de0f752013-10-22 19:04:03 -07002793 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002794
2795 while (mHandler == null) {
2796 try {
2797 wait();
2798 } catch (InterruptedException e) {
2799 Thread.currentThread().interrupt();
2800 }
2801 }
2802 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2803
2804 if (puk == null) {
2805 mSimCard.supplyPin(pin, callback);
2806 } else {
2807 mSimCard.supplyPuk(puk, pin, callback);
2808 }
2809
2810 while (!mDone) {
2811 try {
2812 Log.d(LOG_TAG, "wait for done");
2813 wait();
2814 } catch (InterruptedException e) {
2815 // Restore the interrupted status
2816 Thread.currentThread().interrupt();
2817 }
2818 }
2819 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002820 int[] resultArray = new int[2];
2821 resultArray[0] = mResult;
2822 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002823
2824 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002825 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002826 }
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302827 // This instance is no longer reused, so quit its thread's looper.
2828 mHandler.getLooper().quitSafely();
Michele Berionne5e411512020-11-13 02:36:59 +00002829
Wink Saville9de0f752013-10-22 19:04:03 -07002830 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002831 }
2832 }
2833
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002834 /**
2835 * This method has been removed due to privacy and stability concerns.
2836 */
2837 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002838 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002839 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2840 return;
Wink Saville36469e72014-06-11 15:17:00 -07002841 }
2842
Nathan Harold1f889d82020-06-04 17:05:26 -07002843 @Override
2844 public void updateServiceLocationWithPackageName(String callingPackage) {
2845 mApp.getSystemService(AppOpsManager.class)
2846 .checkPackage(Binder.getCallingUid(), callingPackage);
2847
Nathan Haroldf096d982020-11-18 17:18:06 -08002848 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002849 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2850 // Callers targeting S have no business invoking this method.
2851 return;
2852 }
2853
2854 LocationAccessPolicy.LocationPermissionResult locationResult =
2855 LocationAccessPolicy.checkLocationPermission(mApp,
2856 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2857 .setCallingPackage(callingPackage)
2858 .setCallingFeatureId(null)
2859 .setCallingPid(Binder.getCallingPid())
2860 .setCallingUid(Binder.getCallingUid())
2861 .setMethod("updateServiceLocation")
2862 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2863 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2864 .build());
2865 // Apps that lack location permission have no business calling this method;
2866 // however, because no permission was declared in the public API, denials must
2867 // all be "soft".
2868 switch (locationResult) {
2869 case DENIED_HARD: /* fall through */
2870 case DENIED_SOFT:
2871 return;
2872 }
2873
2874 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002875 final long identity = Binder.clearCallingIdentity();
2876 try {
Ling Mac28f0212023-03-24 16:07:15 -07002877 getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002878 } finally {
2879 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002880 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002881 }
2882
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002883 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002884 @Override
2885 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002886 return isRadioOnWithFeature(callingPackage, null);
2887 }
2888
2889
2890 @Override
2891 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2892 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2893 callingFeatureId);
2894 }
2895
2896 @Deprecated
2897 @Override
2898 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2899 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002900 }
2901
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002902 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002903 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2904 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002905 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002906 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002907 return false;
2908 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002909
joonhunshin4ac60942023-11-15 15:23:39 +00002910 enforceTelephonyFeatureWithException(callingPackage,
2911 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isRadioOnWithFeature");
2912
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002913 final long identity = Binder.clearCallingIdentity();
2914 try {
2915 return isRadioOnForSubscriber(subId);
2916 } finally {
2917 Binder.restoreCallingIdentity(identity);
2918 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002919 }
2920
2921 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002922 final long identity = Binder.clearCallingIdentity();
2923 try {
2924 final Phone phone = getPhone(subId);
2925 if (phone != null) {
2926 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2927 } else {
2928 return false;
2929 }
2930 } finally {
2931 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002932 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002933 }
2934
2935 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002936 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002937 }
Wink Saville36469e72014-06-11 15:17:00 -07002938
Wink Savilleb564aae2014-10-23 10:18:09 -07002939 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002940 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002941
joonhunshin4ac60942023-11-15 15:23:39 +00002942 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2943 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "toggleRadioOnOffForSubscriber");
2944
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002945 final long identity = Binder.clearCallingIdentity();
2946 try {
2947 final Phone phone = getPhone(subId);
2948 if (phone != null) {
2949 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2950 }
2951 } finally {
2952 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002953 }
Wink Saville36469e72014-06-11 15:17:00 -07002954 }
2955
2956 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002957 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002958 }
2959
Wink Savilleb564aae2014-10-23 10:18:09 -07002960 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002961 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002962
2963 final long identity = Binder.clearCallingIdentity();
2964 try {
2965 final Phone phone = getPhone(subId);
2966 if (phone == null) {
2967 return false;
2968 }
2969 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2970 toggleRadioOnOffForSubscriber(subId);
2971 }
2972 return true;
2973 } finally {
2974 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002975 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002976 }
Wink Saville36469e72014-06-11 15:17:00 -07002977
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002978 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002979 enforceReadPrivilegedPermission("needMobileRadioShutdown");
joonhunshin4ac60942023-11-15 15:23:39 +00002980
2981 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2982 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needMobileRadioShutdown");
2983
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002984 /*
2985 * If any of the Radios are available, it will need to be
2986 * shutdown. So return true if any Radio is available.
2987 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002988 final long identity = Binder.clearCallingIdentity();
2989 try {
2990 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2991 Phone phone = PhoneFactory.getPhone(i);
2992 if (phone != null && phone.isRadioAvailable()) return true;
2993 }
2994 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2995 return false;
2996 } finally {
2997 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002998 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002999 }
3000
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003001 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003002 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003003 enforceModifyPermission();
3004
joonhunshin4ac60942023-11-15 15:23:39 +00003005 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3006 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "shutdownMobileRadios");
3007
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003008 final long identity = Binder.clearCallingIdentity();
3009 try {
3010 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3011 logv("Shutting down Phone " + i);
3012 shutdownRadioUsingPhoneId(i);
3013 }
3014 } finally {
3015 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003016 }
3017 }
3018
3019 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003020 Phone phone = PhoneFactory.getPhone(phoneId);
3021 if (phone != null && phone.isRadioAvailable()) {
3022 phone.shutdownRadio();
3023 }
3024 }
3025
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003026 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07003027 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003028
Ling Ma83dc5ea2023-01-12 15:06:04 -08003029 if (!turnOn) {
3030 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
3031 }
3032
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003033 final long identity = Binder.clearCallingIdentity();
3034 try {
3035 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
3036 if (defaultPhone != null) {
3037 defaultPhone.setRadioPower(turnOn);
3038 return true;
3039 } else {
3040 loge("There's no default phone.");
3041 return false;
3042 }
3043 } finally {
3044 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07003045 }
Wink Saville36469e72014-06-11 15:17:00 -07003046 }
3047
Wink Savilleb564aae2014-10-23 10:18:09 -07003048 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003049 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003050
Ling Ma83dc5ea2023-01-12 15:06:04 -08003051 if (!turnOn) {
3052 log("setRadioPowerForSubscriber off: subId=" + subId
3053 + ",callingPackage=" + getCurrentPackageName());
3054 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003055 final long identity = Binder.clearCallingIdentity();
3056 try {
3057 final Phone phone = getPhone(subId);
3058 if (phone != null) {
3059 phone.setRadioPower(turnOn);
3060 return true;
3061 } else {
3062 return false;
3063 }
3064 } finally {
3065 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003066 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003067 }
3068
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003069 /**
3070 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3071 * no reason to power it off. When any of the voters want to power it off, it will be turned
3072 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3073 * powering it off, and these radio off votes will be cleared.
3074 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3075 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3076 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3077 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3078 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3079 * check its vote.
3080 *
3081 * @param subId The subscription ID.
3082 * @param reason The reason for powering off radio.
3083 * @return true on success and false on failure.
3084 */
3085 public boolean requestRadioPowerOffForReason(int subId,
3086 @TelephonyManager.RadioPowerReason int reason) {
3087 enforceModifyPermission();
3088
joonhunshin4ac60942023-11-15 15:23:39 +00003089 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3090 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestRadioPowerOffForReason");
3091
Ling Ma83dc5ea2023-01-12 15:06:04 -08003092 log("requestRadioPowerOffForReason: subId=" + subId
3093 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003094 final long identity = Binder.clearCallingIdentity();
3095 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003096 boolean result = false;
3097 for (Phone phone : PhoneFactory.getPhones()) {
3098 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003099 phone.setRadioPowerForReason(false, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003100 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003101 if (!result) {
3102 loge("requestRadioPowerOffForReason: no phone exists");
3103 }
3104 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003105 } finally {
3106 Binder.restoreCallingIdentity(identity);
3107 }
3108 }
3109
3110 /**
3111 * Remove the vote on powering off the radio for a reason, as requested by
3112 * {@link requestRadioPowerOffForReason}.
3113 *
3114 * @param subId The subscription ID.
3115 * @param reason The reason for powering off radio.
3116 * @return true on success and false on failure.
3117 */
3118 public boolean clearRadioPowerOffForReason(int subId,
3119 @TelephonyManager.RadioPowerReason int reason) {
3120 enforceModifyPermission();
3121
joonhunshin4ac60942023-11-15 15:23:39 +00003122 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3123 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearRadioPowerOffForReason");
3124
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003125 final long identity = Binder.clearCallingIdentity();
3126 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003127 boolean result = false;
3128 for (Phone phone : PhoneFactory.getPhones()) {
3129 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003130 phone.setRadioPowerForReason(true, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003131 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003132 if (!result) {
3133 loge("clearRadioPowerOffForReason: no phone exists");
3134 }
3135 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003136 } finally {
3137 Binder.restoreCallingIdentity(identity);
3138 }
3139 }
3140
3141 /**
3142 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3143 *
3144 * @param subId The subscription ID.
3145 * @param callingPackage The package making the call.
3146 * @param callingFeatureId The feature in the package.
3147 * @return List of reasons for powering off radio.
3148 */
3149 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3150 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3151
joonhunshin4ac60942023-11-15 15:23:39 +00003152 enforceTelephonyFeatureWithException(callingPackage,
3153 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerOffReasons");
3154
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003155 final long identity = Binder.clearCallingIdentity();
3156 List result = new ArrayList();
3157 try {
3158 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3159 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3160 return result;
3161 }
3162
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003163 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003164 if (phone != null) {
3165 result.addAll(phone.getRadioPowerOffReasons());
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003166 } else {
3167 loge("getRadioPowerOffReasons: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003168 }
3169 } finally {
3170 Binder.restoreCallingIdentity(identity);
3171 }
3172 return result;
3173 }
3174
Wink Saville36469e72014-06-11 15:17:00 -07003175 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003176 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003177 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003178 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003179
joonhunshin4ac60942023-11-15 15:23:39 +00003180 enforceTelephonyFeatureWithException(callingPackage,
3181 PackageManager.FEATURE_TELEPHONY_DATA, "enableDataConnectivity");
3182
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003183 final long identity = Binder.clearCallingIdentity();
3184 try {
Jack Yu285100e2022-12-02 22:48:35 -08003185 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003186 final Phone phone = getPhone(subId);
3187 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003188 phone.getDataSettingsManager().setDataEnabled(
3189 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003190 return true;
3191 } else {
3192 return false;
3193 }
3194 } finally {
3195 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003196 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003197 }
3198
Wink Saville36469e72014-06-11 15:17:00 -07003199 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003200 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003201 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003202 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003203
joonhunshin4ac60942023-11-15 15:23:39 +00003204 enforceTelephonyFeatureWithException(callingPackage,
3205 PackageManager.FEATURE_TELEPHONY_DATA, "disableDataConnectivity");
3206
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003207 final long identity = Binder.clearCallingIdentity();
3208 try {
Jack Yu285100e2022-12-02 22:48:35 -08003209 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003210 final Phone phone = getPhone(subId);
3211 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003212 phone.getDataSettingsManager().setDataEnabled(
3213 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003214 return true;
3215 } else {
3216 return false;
3217 }
3218 } finally {
3219 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003220 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003221 }
3222
Sanket Padawe356d7632015-06-22 14:03:32 -07003223 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003224 public boolean isDataConnectivityPossible(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003225 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3226 PackageManager.FEATURE_TELEPHONY_DATA, "isDataConnectivityPossible");
3227
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003228 final long identity = Binder.clearCallingIdentity();
3229 try {
3230 final Phone phone = getPhone(subId);
3231 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003232 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003233 } else {
3234 return false;
3235 }
3236 } finally {
3237 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003238 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003239 }
3240
3241 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003242 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003243 }
3244
pkanwarae03a6b2016-11-06 20:37:09 -08003245 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003246 enforceCallPermission();
3247
joonhunshin4ac60942023-11-15 15:23:39 +00003248 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3249 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "handleUssdRequest");
3250
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003251 final long identity = Binder.clearCallingIdentity();
3252 try {
3253 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3254 return;
3255 }
3256 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3257 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3258 } finally {
3259 Binder.restoreCallingIdentity(identity);
3260 }
pkanwar32d516d2016-10-14 19:37:38 -07003261 };
3262
Wink Savilleb564aae2014-10-23 10:18:09 -07003263 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003264 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003265
joonhunshin4ac60942023-11-15 15:23:39 +00003266 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3267 PackageManager.FEATURE_TELEPHONY_CALLING, "handlePinMmiForSubscriber");
3268
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003269 final long identity = Binder.clearCallingIdentity();
3270 try {
3271 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3272 return false;
3273 }
3274 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3275 } finally {
3276 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003277 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003278 }
3279
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003280 /**
3281 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3282 * tag on getCallState Binder call.
3283 */
3284 @Deprecated
3285 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003286 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003287 if (CompatChanges.isChangeEnabled(
3288 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3289 Binder.getCallingUid())) {
3290 // Do not allow this API to be called on API version 31+, it should only be
3291 // called on old apps using this Binder call directly.
3292 throw new SecurityException("This method can only be used for applications "
3293 + "targeting API version 30 or less.");
3294 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003295 final long identity = Binder.clearCallingIdentity();
3296 try {
Ling Mac28f0212023-03-24 16:07:15 -07003297 Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription());
3298 return PhoneConstantConversions.convertCallState(phone.getState());
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003299 } finally {
3300 Binder.restoreCallingIdentity(identity);
3301 }
3302 }
3303
3304 @Override
3305 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3306 if (CompatChanges.isChangeEnabled(
3307 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3308 Binder.getCallingUid())) {
3309 // Check READ_PHONE_STATE for API version 31+
3310 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3311 featureId, "getCallStateForSubscription")) {
3312 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3313 + "targeting API level 31+.");
3314 }
3315 }
joonhunshin4ac60942023-11-15 15:23:39 +00003316
3317 enforceTelephonyFeatureWithException(callingPackage,
3318 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallStateForSubscription");
3319
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003320 final long identity = Binder.clearCallingIdentity();
3321 try {
3322 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003323 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3324 PhoneConstantConversions.convertCallState(phone.getState());
3325 } finally {
3326 Binder.restoreCallingIdentity(identity);
3327 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003328 }
3329
Sanket Padawe356d7632015-06-22 14:03:32 -07003330 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003331 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003332 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003333 }
3334
3335 @Override
3336 public int getDataStateForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003337 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3338 PackageManager.FEATURE_TELEPHONY_DATA, "getDataStateForSubId");
3339
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003340 final long identity = Binder.clearCallingIdentity();
3341 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003342 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003343 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003344 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003345 } else {
3346 return PhoneConstantConversions.convertDataState(
3347 PhoneConstants.DataState.DISCONNECTED);
3348 }
3349 } finally {
3350 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003351 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003352 }
3353
Sanket Padawe356d7632015-06-22 14:03:32 -07003354 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003355 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003356 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003357 }
3358
3359 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003360 public @DataActivityType int getDataActivityForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003361 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3362 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivityForSubId");
3363
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003364 final long identity = Binder.clearCallingIdentity();
3365 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003366 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003367 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003368 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003369 } else {
3370 return TelephonyManager.DATA_ACTIVITY_NONE;
3371 }
3372 } finally {
3373 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003374 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003375 }
3376
3377 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003378 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003379 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003380 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003381
3382 LocationAccessPolicy.LocationPermissionResult locationResult =
3383 LocationAccessPolicy.checkLocationPermission(mApp,
3384 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3385 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003386 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003387 .setCallingPid(Binder.getCallingPid())
3388 .setCallingUid(Binder.getCallingUid())
3389 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003390 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003391 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3392 .build());
3393 switch (locationResult) {
3394 case DENIED_HARD:
3395 throw new SecurityException("Not allowed to access cell location");
3396 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003397 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3398 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003399 }
3400
joonhunshin4ac60942023-11-15 15:23:39 +00003401 enforceTelephonyFeatureWithException(callingPackage,
3402 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getCellLocation");
3403
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003404 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003405 final long identity = Binder.clearCallingIdentity();
3406 try {
3407 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003408 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003409 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003410 } finally {
3411 Binder.restoreCallingIdentity(identity);
3412 }
Svetoslav64fad262015-04-14 14:35:21 -07003413 }
3414
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003415 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003416 public String getNetworkCountryIsoForPhone(int phoneId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003417 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3418 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkCountryIsoForPhone");
3419
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003420 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3421 // registered cell info, so return a NULL country instead.
3422 final long identity = Binder.clearCallingIdentity();
3423 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003424 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3425 // Get default phone in this case.
3426 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3427 }
Jack Yu285100e2022-12-02 22:48:35 -08003428 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003429 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003430 if (phone == null) return "";
3431 ServiceStateTracker sst = phone.getServiceStateTracker();
3432 if (sst == null) return "";
3433 LocaleTracker lt = sst.getLocaleTracker();
3434 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003435 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003436 } finally {
3437 Binder.restoreCallingIdentity(identity);
3438 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003439 }
3440
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003441 /**
3442 * This method was removed due to potential issues caused by performing partial
3443 * updates of service state, and lack of a credible use case.
3444 *
3445 * This has the ability to break the telephony implementation by disabling notification of
3446 * changes in device connectivity. DO NOT USE THIS!
3447 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003448 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003449 public void enableLocationUpdates() {
3450 mApp.enforceCallingOrSelfPermission(
3451 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003452 }
3453
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003454 /**
3455 * This method was removed due to potential issues caused by performing partial
3456 * updates of service state, and lack of a credible use case.
3457 *
3458 * This has the ability to break the telephony implementation by disabling notification of
3459 * changes in device connectivity. DO NOT USE THIS!
3460 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003461 @Override
3462 public void disableLocationUpdates() {
3463 mApp.enforceCallingOrSelfPermission(
3464 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003465 }
3466
3467 @Override
3468 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003469 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3470 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003471 try {
3472 mApp.getSystemService(AppOpsManager.class)
3473 .checkPackage(Binder.getCallingUid(), callingPackage);
3474 } catch (SecurityException e) {
3475 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3476 throw e;
3477 }
3478
Nathan Haroldf096d982020-11-18 17:18:06 -08003479 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003480 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3481 throw new SecurityException(
3482 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3483 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003484
Jordan Liu1617b712019-07-10 15:06:26 -07003485 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003486 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3487 return null;
3488 }
Svetoslav64fad262015-04-14 14:35:21 -07003489
joonhunshin4ac60942023-11-15 15:23:39 +00003490 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3491 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNeighboringCellInfo");
3492
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003493 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003494
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003495 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003496 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003497
Nathan Haroldf180aac2018-06-01 18:43:55 -07003498 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3499 for (CellInfo ci : info) {
3500 if (ci instanceof CellInfoGsm) {
3501 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3502 } else if (ci instanceof CellInfoWcdma) {
3503 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3504 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003505 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003506 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003507 }
3508
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003509 private List<CellInfo> getCachedCellInfo() {
3510 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3511 for (Phone phone : PhoneFactory.getPhones()) {
3512 List<CellInfo> info = phone.getAllCellInfo();
3513 if (info != null) cellInfos.addAll(info);
3514 }
3515 return cellInfos;
3516 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003517
3518 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003519 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003520 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003521 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003522
3523 LocationAccessPolicy.LocationPermissionResult locationResult =
3524 LocationAccessPolicy.checkLocationPermission(mApp,
3525 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3526 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003527 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003528 .setCallingPid(Binder.getCallingPid())
3529 .setCallingUid(Binder.getCallingUid())
3530 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003531 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003532 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3533 .build());
3534 switch (locationResult) {
3535 case DENIED_HARD:
3536 throw new SecurityException("Not allowed to access cell info");
3537 case DENIED_SOFT:
3538 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003539 }
3540
Nathan Haroldf096d982020-11-18 17:18:06 -08003541 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003542 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3543 return getCachedCellInfo();
3544 }
3545
joonhunshin4ac60942023-11-15 15:23:39 +00003546 enforceTelephonyFeatureWithException(callingPackage,
3547 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllCellInfo");
3548
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003549 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003550 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003551 final long identity = Binder.clearCallingIdentity();
3552 try {
3553 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3554 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003555 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003556 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003557 if (info != null) cellInfos.addAll(info);
3558 }
3559 return cellInfos;
3560 } finally {
3561 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003562 }
3563 }
3564
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003565 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003566 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3567 String callingFeatureId) {
3568 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3569 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003570 }
3571
3572 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003573 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3574 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003575 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003576 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003577 }
3578
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003579 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3580 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003581 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003582 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003583
3584 LocationAccessPolicy.LocationPermissionResult locationResult =
3585 LocationAccessPolicy.checkLocationPermission(mApp,
3586 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3587 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003588 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003589 .setCallingPid(Binder.getCallingPid())
3590 .setCallingUid(Binder.getCallingUid())
3591 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003592 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3593 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003594 .build());
3595 switch (locationResult) {
3596 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003597 if (TelephonyPermissions
3598 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003599 // Safetynet logging for b/154934934
3600 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3601 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003602 throw new SecurityException("Not allowed to access cell info");
3603 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003604 if (TelephonyPermissions
3605 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003606 // Safetynet logging for b/154934934
3607 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3608 }
Nathan Harold5320c422019-05-09 10:26:08 -07003609 try {
3610 cb.onCellInfo(new ArrayList<CellInfo>());
3611 } catch (RemoteException re) {
3612 // Drop without consequences
3613 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003614 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003615 }
3616
joonhunshin4ac60942023-11-15 15:23:39 +00003617 enforceTelephonyFeatureWithException(callingPackage,
3618 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestCellInfoUpdateInternal");
Nathan Harolda939a962019-05-09 10:13:47 -07003619
3620 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003621 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3622
3623 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3624 }
3625
3626 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003627 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003628 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003629 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003630
3631 final long identity = Binder.clearCallingIdentity();
3632 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003633 Phone phone = getPhone(subId);
3634 if (phone == null) {
3635 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3636 } else {
3637 phone.setCellInfoListRate(rateInMillis, workSource);
3638 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003639 } finally {
3640 Binder.restoreCallingIdentity(identity);
3641 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003642 }
3643
Shishir Agrawala9f32182016-04-12 12:00:16 -07003644 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003645 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003646 Phone phone = PhoneFactory.getPhone(slotIndex);
3647 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003648 return null;
3649 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003650 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003651 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003652 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003653 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003654 return null;
3655 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003656
joonhunshin4ac60942023-11-15 15:23:39 +00003657 enforceTelephonyFeatureWithException(callingPackage,
3658 PackageManager.FEATURE_TELEPHONY_GSM, "getImeiForSlot");
3659
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003660 final long identity = Binder.clearCallingIdentity();
3661 try {
3662 return phone.getImei();
3663 } finally {
3664 Binder.restoreCallingIdentity(identity);
3665 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003666 }
3667
3668 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003669 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3670 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3671 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3672 callingFeatureId, "getPrimaryImei")) {
3673 throw new SecurityException("Caller does not have permission");
3674 }
joonhunshin4ac60942023-11-15 15:23:39 +00003675
3676 enforceTelephonyFeatureWithException(callingPackage,
3677 PackageManager.FEATURE_TELEPHONY_GSM, "getPrimaryImei");
3678
arunvoddud5c6ce02022-12-11 06:03:12 +00003679 final long identity = Binder.clearCallingIdentity();
3680 try {
3681 for (Phone phone : PhoneFactory.getPhones()) {
3682 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3683 return phone.getImei();
3684 }
3685 }
3686 throw new UnsupportedOperationException("Operation not supported");
3687 } finally {
3688 Binder.restoreCallingIdentity(identity);
3689 }
3690 }
3691
3692 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003693 public String getTypeAllocationCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003694 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3695 PackageManager.FEATURE_TELEPHONY_GSM, "getTypeAllocationCodeForSlot");
3696
David Kelly5e06a7f2018-03-12 14:10:59 +00003697 Phone phone = PhoneFactory.getPhone(slotIndex);
3698 String tac = null;
3699 if (phone != null) {
3700 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003701 try {
3702 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3703 } catch (IndexOutOfBoundsException e) {
3704 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3705 return null;
3706 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003707 }
3708 return tac;
3709 }
3710
3711 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003712 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003713 try {
3714 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3715 } catch (SecurityException se) {
3716 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3717 throw new SecurityException("Package " + callingPackage + " does not belong to "
3718 + Binder.getCallingUid());
3719 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003720 Phone phone = PhoneFactory.getPhone(slotIndex);
3721 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003722 return null;
3723 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003724
Jeff Davidson913390f2018-02-23 17:11:49 -08003725 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003726 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003727 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003728 return null;
3729 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003730
joonhunshin4ac60942023-11-15 15:23:39 +00003731 enforceTelephonyFeatureWithException(callingPackage,
3732 PackageManager.FEATURE_TELEPHONY_CDMA, "getMeidForSlot");
3733
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003734 final long identity = Binder.clearCallingIdentity();
3735 try {
3736 return phone.getMeid();
3737 } finally {
3738 Binder.restoreCallingIdentity(identity);
3739 }
Jack Yu2af8d712017-03-15 17:14:14 -07003740 }
3741
3742 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003743 public String getManufacturerCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003744 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3745 PackageManager.FEATURE_TELEPHONY_CDMA, "getManufacturerCodeForSlot");
3746
David Kelly5e06a7f2018-03-12 14:10:59 +00003747 Phone phone = PhoneFactory.getPhone(slotIndex);
3748 String manufacturerCode = null;
3749 if (phone != null) {
3750 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003751 try {
3752 manufacturerCode =
3753 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3754 } catch (IndexOutOfBoundsException e) {
3755 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3756 return null;
3757 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003758 }
3759 return manufacturerCode;
3760 }
3761
3762 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003763 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3764 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003765 Phone phone = PhoneFactory.getPhone(slotIndex);
3766 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003767 return null;
3768 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003769 int subId = phone.getSubId();
3770 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003771 mApp, subId, callingPackage, callingFeatureId,
3772 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003773 return null;
3774 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003775
joonhunshin4ac60942023-11-15 15:23:39 +00003776 enforceTelephonyFeatureWithException(callingPackage,
3777 PackageManager.FEATURE_TELEPHONY, "getDeviceSoftwareVersionForSlot");
3778
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003779 final long identity = Binder.clearCallingIdentity();
3780 try {
3781 return phone.getDeviceSvn();
3782 } finally {
3783 Binder.restoreCallingIdentity(identity);
3784 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003785 }
3786
fionaxu43304da2017-11-27 22:51:16 -08003787 @Override
3788 public int getSubscriptionCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003789 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3790 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierId");
3791
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003792 final long identity = Binder.clearCallingIdentity();
3793 try {
3794 final Phone phone = getPhone(subId);
3795 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3796 } finally {
3797 Binder.restoreCallingIdentity(identity);
3798 }
fionaxu43304da2017-11-27 22:51:16 -08003799 }
3800
3801 @Override
3802 public String getSubscriptionCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003803 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3804 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierName");
3805
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003806 final long identity = Binder.clearCallingIdentity();
3807 try {
3808 final Phone phone = getPhone(subId);
3809 return phone == null ? null : phone.getCarrierName();
3810 } finally {
3811 Binder.restoreCallingIdentity(identity);
3812 }
fionaxu43304da2017-11-27 22:51:16 -08003813 }
3814
calvinpanffe225e2018-11-01 19:43:06 +08003815 @Override
chen xu0026ca62019-03-06 15:28:50 -08003816 public int getSubscriptionSpecificCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003817 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3818 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionSpecificCarrierId");
3819
chen xu25637222018-11-04 17:17:00 -08003820 final long identity = Binder.clearCallingIdentity();
3821 try {
3822 final Phone phone = getPhone(subId);
3823 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003824 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003825 } finally {
3826 Binder.restoreCallingIdentity(identity);
3827 }
3828 }
3829
3830 @Override
chen xu0026ca62019-03-06 15:28:50 -08003831 public String getSubscriptionSpecificCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003832 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3833 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
3834 "getSubscriptionSpecificCarrierName");
3835
chen xu25637222018-11-04 17:17:00 -08003836 final long identity = Binder.clearCallingIdentity();
3837 try {
3838 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003839 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003840 } finally {
3841 Binder.restoreCallingIdentity(identity);
3842 }
3843 }
3844
chen xu651eec72018-11-11 19:03:44 -08003845 @Override
chen xu864e11c2018-12-06 22:10:03 -08003846 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3847 if (!isSubscriptionMccMnc) {
3848 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3849 }
chen xu651eec72018-11-11 19:03:44 -08003850 final Phone phone = PhoneFactory.getPhone(slotIndex);
3851 if (phone == null) {
3852 return TelephonyManager.UNKNOWN_CARRIER_ID;
3853 }
joonhunshin4ac60942023-11-15 15:23:39 +00003854
3855 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3856 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromMccMnc");
3857
chen xu651eec72018-11-11 19:03:44 -08003858 final long identity = Binder.clearCallingIdentity();
3859 try {
3860 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3861 } finally {
3862 Binder.restoreCallingIdentity(identity);
3863 }
3864 }
3865
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003866 //
3867 // Internal helper methods.
3868 //
3869
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003870 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003871 * Make sure the caller is the calling package itself
3872 *
3873 * @throws SecurityException if the caller is not the calling package
3874 */
3875 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3876 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003877 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3878 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003879 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003880 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003881 } catch (PackageManager.NameNotFoundException e) {
3882 // packageUid is -1
3883 }
3884 if (packageUid != callingUid) {
3885 throw new SecurityException(message + ": Package " + callingPackage
3886 + " does not belong to " + callingUid);
3887 }
3888 }
3889
3890 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003891 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3892 *
3893 * @throws SecurityException if the caller does not have the required permission
3894 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003895 @VisibleForTesting
3896 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003897 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3898 }
3899
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003900 /**
arunvoddud7401012022-12-15 16:08:12 +00003901 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003902 *
3903 * @throws SecurityException if the caller does not have the required permission
3904 */
3905 @VisibleForTesting
3906 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003907 enforceReadPermission(null);
3908 }
3909
3910 /**
3911 * Make sure the caller has the READ_PHONE_STATE permissions.
3912 *
3913 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3914 */
3915 @VisibleForTesting
3916 public void enforceReadPermission(String msg) {
3917 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003918 }
3919
Shuo Qian3b6ee772019-11-13 17:43:31 -08003920 private void enforceActiveEmergencySessionPermission() {
3921 mApp.enforceCallingOrSelfPermission(
3922 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3923 }
3924
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003925 /**
3926 * Make sure the caller has the CALL_PHONE permission.
3927 *
3928 * @throws SecurityException if the caller does not have the required permission
3929 */
3930 private void enforceCallPermission() {
3931 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3932 }
3933
paulhu5a773602019-08-23 19:17:33 +08003934 private void enforceSettingsPermission() {
3935 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003936 }
3937
Michele Berionne5e411512020-11-13 02:36:59 +00003938 private void enforceRebootPermission() {
3939 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3940 }
3941
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003942 /**
3943 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3944 * @param message - log message to print.
3945 * @throws SecurityException if the caller does not have the required permission
3946 */
3947 private void enforceSatelliteCommunicationPermission(String message) {
3948 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3949 }
3950
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003951 private String createTelUrl(String number) {
3952 if (TextUtils.isEmpty(number)) {
3953 return null;
3954 }
3955
Jake Hambye994d462014-02-03 13:10:13 -08003956 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003957 }
3958
Ihab Awadf9e92732013-12-05 18:02:52 -08003959 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003960 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003961 }
3962
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003963 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003964 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003965 }
3966
Ihab Awadf9e92732013-12-05 18:02:52 -08003967 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003968 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003969 }
3970
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003971 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003972 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003973 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003974 }
3975
Sanket Padawe356d7632015-06-22 14:03:32 -07003976 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003977 public int getActivePhoneTypeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003978 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3979 PackageManager.FEATURE_TELEPHONY, "getActivePhoneTypeForSlot");
3980
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003981 final long identity = Binder.clearCallingIdentity();
3982 try {
3983 final Phone phone = PhoneFactory.getPhone(slotIndex);
3984 if (phone == null) {
3985 return PhoneConstants.PHONE_TYPE_NONE;
3986 } else {
3987 return phone.getPhoneType();
3988 }
3989 } finally {
3990 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003991 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003992 }
3993
3994 /**
3995 * Returns the CDMA ERI icon index to display
3996 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003997 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003998 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3999 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
4000 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004001 }
4002
Sanket Padawe356d7632015-06-22 14:03:32 -07004003 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004004 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
4005 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004006 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004007 mApp, subId, callingPackage, callingFeatureId,
4008 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004009 return -1;
4010 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004011
joonhunshin4ac60942023-11-15 15:23:39 +00004012 enforceTelephonyFeatureWithException(callingPackage,
4013 PackageManager.FEATURE_TELEPHONY_CDMA,
4014 "getCdmaEriIconIndexForSubscriber");
4015
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004016 final long identity = Binder.clearCallingIdentity();
4017 try {
4018 final Phone phone = getPhone(subId);
4019 if (phone != null) {
4020 return phone.getCdmaEriIconIndex();
4021 } else {
4022 return -1;
4023 }
4024 } finally {
4025 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004026 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004027 }
4028
4029 /**
4030 * Returns the CDMA ERI icon mode,
4031 * 0 - ON
4032 * 1 - FLASHING
4033 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004034 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004035 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
4036 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
4037 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004038 }
4039
Sanket Padawe356d7632015-06-22 14:03:32 -07004040 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004041 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
4042 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004043 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004044 mApp, subId, callingPackage, callingFeatureId,
4045 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004046 return -1;
4047 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004048
4049 final long identity = Binder.clearCallingIdentity();
4050 try {
4051 final Phone phone = getPhone(subId);
4052 if (phone != null) {
4053 return phone.getCdmaEriIconMode();
4054 } else {
4055 return -1;
4056 }
4057 } finally {
4058 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004059 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004060 }
4061
4062 /**
4063 * Returns the CDMA ERI text,
4064 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004065 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004066 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
4067 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
4068 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004069 }
4070
Sanket Padawe356d7632015-06-22 14:03:32 -07004071 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004072 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
4073 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004074 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004075 mApp, subId, callingPackage, callingFeatureId,
4076 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004077 return null;
4078 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004079
4080 final long identity = Binder.clearCallingIdentity();
4081 try {
4082 final Phone phone = getPhone(subId);
4083 if (phone != null) {
4084 return phone.getCdmaEriText();
4085 } else {
4086 return null;
4087 }
4088 } finally {
4089 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004090 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004091 }
4092
4093 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07004094 * Returns the CDMA MDN.
4095 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004096 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004097 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004098 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4099 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004100
joonhunshin4ac60942023-11-15 15:23:39 +00004101 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4102 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMdn");
4103
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004104 final long identity = Binder.clearCallingIdentity();
4105 try {
4106 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004107 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004108 return phone.getLine1Number();
4109 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004110 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004111 return null;
4112 }
4113 } finally {
4114 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004115 }
4116 }
4117
4118 /**
4119 * Returns the CDMA MIN.
4120 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004121 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004122 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004123 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4124 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004125
joonhunshin4ac60942023-11-15 15:23:39 +00004126 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4127 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMin");
4128
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004129 final long identity = Binder.clearCallingIdentity();
4130 try {
4131 final Phone phone = getPhone(subId);
4132 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
4133 return phone.getCdmaMin();
4134 } else {
4135 return null;
4136 }
4137 } finally {
4138 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004139 }
4140 }
4141
Hall Liud892bec2018-11-30 14:51:45 -08004142 @Override
4143 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
4144 INumberVerificationCallback callback, String callingPackage) {
4145 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
4146 != PERMISSION_GRANTED) {
4147 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
4148 }
4149 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4150
4151 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
4152 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08004153 throw new SecurityException("Calling package must be configured in the device config: "
4154 + "calling package: " + callingPackage
4155 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004156 }
4157
joonhunshin4ac60942023-11-15 15:23:39 +00004158 enforceTelephonyFeatureWithException(callingPackage,
4159 PackageManager.FEATURE_TELEPHONY_CALLING, "requestNumberVerification");
4160
Hall Liud892bec2018-11-30 14:51:45 -08004161 if (range == null) {
4162 throw new NullPointerException("Range must be non-null");
4163 }
4164
4165 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004166 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004167
4168 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4169 }
4170
Junda Liuca05d5d2014-08-14 22:36:34 -07004171 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004172 * Returns true if CDMA provisioning needs to run.
4173 */
4174 public boolean needsOtaServiceProvisioning() {
joonhunshin4ac60942023-11-15 15:23:39 +00004175 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4176 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needsOtaServiceProvisioning");
4177
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004178 final long identity = Binder.clearCallingIdentity();
4179 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004180 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004181 } finally {
4182 Binder.restoreCallingIdentity(identity);
4183 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004184 }
4185
4186 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004187 * Sets the voice mail number of a given subId.
4188 */
4189 @Override
4190 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004191 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4192 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004193
joonhunshin4ac60942023-11-15 15:23:39 +00004194 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4195 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceMailNumber");
4196
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004197 final long identity = Binder.clearCallingIdentity();
4198 try {
4199 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4200 new Pair<String, String>(alphaTag, number), new Integer(subId));
4201 return success;
4202 } finally {
4203 Binder.restoreCallingIdentity(identity);
4204 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004205 }
4206
Ta-wei Yen87c49842016-05-13 21:19:52 -07004207 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004208 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4209 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004210 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4211 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004212 if (!TextUtils.equals(callingPackage, systemDialer)) {
4213 throw new SecurityException("caller must be system dialer");
4214 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004215
joonhunshin4ac60942023-11-15 15:23:39 +00004216 enforceTelephonyFeatureWithException(callingPackage,
4217 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailSettings");
4218
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004219 final long identity = Binder.clearCallingIdentity();
4220 try {
4221 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4222 if (phoneAccountHandle == null) {
4223 return null;
4224 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004225 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004226 } finally {
4227 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004228 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004229 }
4230
4231 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004232 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4233 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004234 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004235 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004236 mApp, subId, callingPackage, callingFeatureId,
4237 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004238 return null;
4239 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004240
joonhunshin4ac60942023-11-15 15:23:39 +00004241 enforceTelephonyFeatureWithException(callingPackage,
4242 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailPackageName");
4243
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004244 final long identity = Binder.clearCallingIdentity();
4245 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004246 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004247 } finally {
4248 Binder.restoreCallingIdentity(identity);
4249 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004250 }
4251
4252 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004253 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4254 VisualVoicemailSmsFilterSettings settings) {
4255 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004256
joonhunshin4ac60942023-11-15 15:23:39 +00004257 enforceTelephonyFeatureWithException(callingPackage,
4258 PackageManager.FEATURE_TELEPHONY_CALLING, "enableVisualVoicemailSmsFilter");
4259
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004260 final long identity = Binder.clearCallingIdentity();
4261 try {
4262 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004263 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004264 } finally {
4265 Binder.restoreCallingIdentity(identity);
4266 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004267 }
4268
4269 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004270 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4271 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004272
joonhunshin4ac60942023-11-15 15:23:39 +00004273 enforceTelephonyFeatureWithException(callingPackage,
4274 PackageManager.FEATURE_TELEPHONY_CALLING, "disableVisualVoicemailSmsFilter");
4275
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004276 final long identity = Binder.clearCallingIdentity();
4277 try {
4278 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004279 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004280 } finally {
4281 Binder.restoreCallingIdentity(identity);
4282 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004283 }
4284
4285 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004286 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4287 String callingPackage, int subId) {
4288 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004289
4290 final long identity = Binder.clearCallingIdentity();
4291 try {
4292 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004293 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004294 } finally {
4295 Binder.restoreCallingIdentity(identity);
4296 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004297 }
4298
4299 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004300 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004301 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004302
4303 final long identity = Binder.clearCallingIdentity();
4304 try {
4305 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004306 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004307 } finally {
4308 Binder.restoreCallingIdentity(identity);
4309 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004310 }
4311
4312 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004313 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4314 String callingAttributionTag, int subId, String number, int port, String text,
4315 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004316 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004317 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004318 enforceSendSmsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00004319
4320 enforceTelephonyFeatureWithException(callingPackage,
4321 PackageManager.FEATURE_TELEPHONY_CALLING, "sendVisualVoicemailSmsForSubscriber");
4322
Amit Mahajandccb3f12019-05-13 13:48:32 -07004323 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004324 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4325 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004326 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004327
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004328 /**
fionaxu0152e512016-11-14 13:36:14 -08004329 * Sets the voice activation state of a given subId.
4330 */
4331 @Override
4332 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004333 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4334 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004335
joonhunshin4ac60942023-11-15 15:23:39 +00004336 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4337 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState");
4338
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004339 final long identity = Binder.clearCallingIdentity();
4340 try {
4341 final Phone phone = getPhone(subId);
4342 if (phone != null) {
4343 phone.setVoiceActivationState(activationState);
4344 } else {
4345 loge("setVoiceActivationState fails with invalid subId: " + subId);
4346 }
4347 } finally {
4348 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004349 }
4350 }
4351
4352 /**
4353 * Sets the data activation state of a given subId.
4354 */
4355 @Override
4356 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004357 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4358 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004359
joonhunshin4ac60942023-11-15 15:23:39 +00004360 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4361 PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState");
4362
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004363 final long identity = Binder.clearCallingIdentity();
4364 try {
4365 final Phone phone = getPhone(subId);
4366 if (phone != null) {
4367 phone.setDataActivationState(activationState);
4368 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004369 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004370 }
4371 } finally {
4372 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004373 }
4374 }
4375
4376 /**
4377 * Returns the voice activation state of a given subId.
4378 */
4379 @Override
4380 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004381 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004382
joonhunshin4ac60942023-11-15 15:23:39 +00004383 enforceTelephonyFeatureWithException(callingPackage,
4384 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState");
4385
fionaxu0152e512016-11-14 13:36:14 -08004386 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004387 final long identity = Binder.clearCallingIdentity();
4388 try {
4389 if (phone != null) {
4390 return phone.getVoiceActivationState();
4391 } else {
4392 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4393 }
4394 } finally {
4395 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004396 }
4397 }
4398
4399 /**
4400 * Returns the data activation state of a given subId.
4401 */
4402 @Override
4403 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004404 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004405
joonhunshin4ac60942023-11-15 15:23:39 +00004406 enforceTelephonyFeatureWithException(callingPackage,
4407 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState");
4408
fionaxu0152e512016-11-14 13:36:14 -08004409 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004410 final long identity = Binder.clearCallingIdentity();
4411 try {
4412 if (phone != null) {
4413 return phone.getDataActivationState();
4414 } else {
4415 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4416 }
4417 } finally {
4418 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004419 }
4420 }
4421
4422 /**
Wink Saville36469e72014-06-11 15:17:00 -07004423 * Returns the unread count of voicemails for a subId
4424 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004425 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004426 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4427 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004428 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004429 mApp, subId, callingPackage, callingFeatureId,
4430 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004431 return 0;
4432 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004433 final long identity = Binder.clearCallingIdentity();
4434 try {
4435 final Phone phone = getPhone(subId);
4436 if (phone != null) {
4437 return phone.getVoiceMessageCount();
4438 } else {
4439 return 0;
4440 }
4441 } finally {
4442 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004443 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004444 }
4445
4446 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004447 * returns true, if the device is in a state where both voice and data
4448 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004449 */
4450 @Override
4451 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00004452 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4453 PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed");
4454
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004455 final long identity = Binder.clearCallingIdentity();
4456 try {
Ling Mac28f0212023-03-24 16:07:15 -07004457 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004458 } finally {
4459 Binder.restoreCallingIdentity(identity);
4460 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004461 }
4462
4463 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004464 * Send the dialer code if called from the current default dialer or the caller has
4465 * carrier privilege.
4466 * @param inputCode The dialer code to send
4467 */
4468 @Override
4469 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004470 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004471 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004472 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4473 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004474 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004475 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004476 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004477 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004478
joonhunshin4ac60942023-11-15 15:23:39 +00004479 enforceTelephonyFeatureWithException(callingPackage,
4480 PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode");
4481
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004482 final long identity = Binder.clearCallingIdentity();
4483 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004484 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004485 } finally {
4486 Binder.restoreCallingIdentity(identity);
4487 }
fionaxu235cc5e2017-03-06 22:25:57 -08004488 }
4489
Pengquan Menga1bb6272018-09-06 09:59:22 -07004490 @Override
4491 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004492 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004493 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4494 mApp, subId, "getNetworkSelectionMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004495
4496 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4497 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode");
4498
shilufc958392020-01-20 11:36:01 -08004499 final long identity = Binder.clearCallingIdentity();
4500 try {
4501 if (!isActiveSubscription(subId)) {
4502 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4503 }
4504 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4505 } finally {
4506 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004507 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004508 }
4509
Brad Ebinger35c841c2018-10-01 10:40:55 -07004510 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004511 public boolean isInEmergencySmsMode() {
4512 enforceReadPrivilegedPermission("isInEmergencySmsMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004513
4514 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4515 PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode");
4516
Brad Ebingerb2b65522019-03-15 13:48:47 -07004517 final long identity = Binder.clearCallingIdentity();
4518 try {
4519 for (Phone phone : PhoneFactory.getPhones()) {
4520 if (phone.isInEmergencySmsMode()) {
4521 return true;
4522 }
4523 }
4524 } finally {
4525 Binder.restoreCallingIdentity(identity);
4526 }
4527 return false;
4528 }
4529
shilu366312e2019-12-17 09:28:10 -08004530 /**
4531 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4532 * @param subId The subscription to use to check the configuration.
4533 * @param c The callback that will be used to send the result.
4534 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004535 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004536 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4537 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004538 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004539 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004540
4541 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4542 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4543 "IMS not available on device.");
4544 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004545 final long token = Binder.clearCallingIdentity();
4546 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004547 int slotId = getSlotIndexOrException(subId);
4548 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004549
4550 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4551 if (controller != null) {
4552 ImsManager imsManager = controller.getImsManager(subId);
4553 if (imsManager != null) {
4554 imsManager.addRegistrationCallbackForSubscription(c, subId);
4555 } else {
4556 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4557 }
4558 } else {
4559 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4560 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004561 } catch (ImsException e) {
4562 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004563 } finally {
4564 Binder.restoreCallingIdentity(token);
4565 }
4566 }
4567
shilu366312e2019-12-17 09:28:10 -08004568 /**
4569 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4570 * @param subId The subscription to use to check the configuration.
4571 * @param c The callback that will be used to send the result.
4572 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004573 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004574 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004575 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004576 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004577 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4578 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4579 }
Meng Wangafbc5852019-09-19 17:37:13 -07004580 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004581
Meng Wangafbc5852019-09-19 17:37:13 -07004582 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004583 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4584 if (controller != null) {
4585 ImsManager imsManager = controller.getImsManager(subId);
4586 if (imsManager != null) {
4587 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4588 } else {
4589 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4590 + "is inactive, ignoring unregister.");
4591 // If the ImsManager is not valid, just return, since the callback
4592 // will already have been removed internally.
4593 }
4594 }
Meng Wangafbc5852019-09-19 17:37:13 -07004595 } finally {
4596 Binder.restoreCallingIdentity(token);
4597 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004598 }
4599
Brad Ebingera34a6c22019-10-22 17:36:18 -07004600 /**
Hidayat Khan99ea48f2023-12-11 04:37:45 +00004601 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4602 * @param subId The subscription to use to check the configuration.
4603 * @param c The callback that will be used to send the result.
4604 */
4605 @Override
4606 public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c)
4607 throws RemoteException {
4608 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4609 mApp, subId, "registerImsEmergencyRegistrationCallback");
4610
4611 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4612 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4613 "IMS not available on device.");
4614 }
4615 final long token = Binder.clearCallingIdentity();
4616 try {
4617 int slotId = getSlotIndexOrException(subId);
4618 verifyImsMmTelConfiguredOrThrow(slotId);
4619
4620 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4621 if (controller != null) {
4622 ImsManager imsManager = controller.getImsManager(subId);
4623 if (imsManager != null) {
4624 imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId);
4625 } else {
4626 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4627 }
4628 } else {
4629 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4630 }
4631 } catch (ImsException e) {
4632 throw new ServiceSpecificException(e.getCode());
4633 } finally {
4634 Binder.restoreCallingIdentity(token);
4635 }
4636 }
4637
4638 /**
4639 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4640 * @param subId The subscription to use to check the configuration.
4641 * @param c The callback that will be used to send the result.
4642 */
4643 @Override
4644 public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) {
4645 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4646 mApp, subId, "unregisterImsEmergencyRegistrationCallback");
4647 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4648 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4649 }
4650 final long token = Binder.clearCallingIdentity();
4651
4652 try {
4653 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4654 if (controller != null) {
4655 ImsManager imsManager = controller.getImsManager(subId);
4656 if (imsManager != null) {
4657 imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId);
4658 } else {
4659 Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId
4660 + "is inactive, ignoring unregister.");
4661 // If the ImsManager is not valid, just return, since the callback
4662 // will already have been removed internally.
4663 }
4664 }
4665 } finally {
4666 Binder.restoreCallingIdentity(token);
4667 }
4668 }
4669
4670 /**
Brad Ebingera34a6c22019-10-22 17:36:18 -07004671 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4672 */
4673 @Override
4674 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4675 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4676 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4677 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4678 "IMS not available on device.");
4679 }
4680 final long token = Binder.clearCallingIdentity();
4681 try {
4682 Phone phone = getPhone(subId);
4683 if (phone == null) {
4684 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4685 + subId + "'");
4686 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4687 }
4688 phone.getImsRegistrationState(regState -> {
4689 try {
4690 consumer.accept((regState == null)
4691 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4692 } catch (RemoteException e) {
4693 // Ignore if the remote process is no longer available to call back.
4694 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4695 }
4696 });
4697 } finally {
4698 Binder.restoreCallingIdentity(token);
4699 }
4700 }
4701
4702 /**
4703 * Get the transport type for the IMS service registration state.
4704 */
4705 @Override
4706 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004707 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004708 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004709 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4710 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4711 "IMS not available on device.");
4712 }
4713 final long token = Binder.clearCallingIdentity();
4714 try {
4715 Phone phone = getPhone(subId);
4716 if (phone == null) {
4717 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4718 + subId + "'");
4719 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4720 }
4721 phone.getImsRegistrationTech(regTech -> {
4722 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4723 int regTechConverted = (regTech == null)
4724 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4725 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4726 regTechConverted);
4727 try {
4728 consumer.accept(regTechConverted);
4729 } catch (RemoteException e) {
4730 // Ignore if the remote process is no longer available to call back.
4731 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4732 }
4733 });
4734 } finally {
4735 Binder.restoreCallingIdentity(token);
4736 }
4737 }
4738
shilu366312e2019-12-17 09:28:10 -08004739 /**
4740 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4741 * @param subId The subscription to use to check the configuration.
4742 * @param c The callback that will be used to send the result.
4743 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004744 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004745 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4746 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004747 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004748 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004749 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4750 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4751 "IMS not available on device.");
4752 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004753 final long token = Binder.clearCallingIdentity();
4754 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004755 int slotId = getSlotIndexOrException(subId);
4756 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004757
4758 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4759 if (controller != null) {
4760 ImsManager imsManager = controller.getImsManager(subId);
4761 if (imsManager != null) {
4762 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4763 } else {
4764 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4765 }
4766 } else {
4767 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4768 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004769 } catch (ImsException e) {
4770 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004771 } finally {
4772 Binder.restoreCallingIdentity(token);
4773 }
4774 }
4775
shilu366312e2019-12-17 09:28:10 -08004776 /**
4777 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4778 * @param subId The subscription to use to check the configuration.
4779 * @param c The callback that will be used to send the result.
4780 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004781 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004782 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004783 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004784 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004785 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4786 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4787 }
Meng Wangafbc5852019-09-19 17:37:13 -07004788
4789 final long token = Binder.clearCallingIdentity();
4790 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004791 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4792 if (controller != null) {
4793 ImsManager imsManager = controller.getImsManager(subId);
4794 if (imsManager != null) {
4795 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4796 } else {
4797 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4798 + " is inactive, ignoring unregister.");
4799 // If the ImsManager is not valid, just return, since the callback
4800 // will already have been removed internally.
4801 }
4802 }
Meng Wangafbc5852019-09-19 17:37:13 -07004803 } finally {
4804 Binder.restoreCallingIdentity(token);
4805 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004806 }
4807
4808 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004809 public boolean isCapable(int subId, int capability, int regTech) {
4810 enforceReadPrivilegedPermission("isCapable");
joonhunshin4ac60942023-11-15 15:23:39 +00004811
4812 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4813 FEATURE_TELEPHONY_IMS, "isCapable");
4814
Brad Ebinger35c841c2018-10-01 10:40:55 -07004815 final long token = Binder.clearCallingIdentity();
4816 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004817 int slotId = getSlotIndexOrException(subId);
4818 verifyImsMmTelConfiguredOrThrow(slotId);
4819 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4820 } catch (com.android.ims.ImsException e) {
4821 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4822 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004823 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004824 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4825 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004826 } finally {
4827 Binder.restoreCallingIdentity(token);
4828 }
4829 }
4830
4831 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004832 public boolean isAvailable(int subId, int capability, int regTech) {
4833 enforceReadPrivilegedPermission("isAvailable");
joonhunshin4ac60942023-11-15 15:23:39 +00004834
4835 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4836 FEATURE_TELEPHONY_IMS, "isAvailable");
4837
Brad Ebinger35c841c2018-10-01 10:40:55 -07004838 final long token = Binder.clearCallingIdentity();
4839 try {
4840 Phone phone = getPhone(subId);
4841 if (phone == null) return false;
4842 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004843 } catch (com.android.ims.ImsException e) {
4844 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4845 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004846 } finally {
4847 Binder.restoreCallingIdentity(token);
4848 }
4849 }
4850
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004851 /**
4852 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4853 * subscription.
4854 * @param subId The subscription to use to check the configuration.
4855 * @param callback The callback that will be used to send the result.
4856 * @param capability The MmTelFeature capability that will be used to send the result.
4857 * @param transportType The transport type of the MmTelFeature capability.
4858 */
4859 @Override
4860 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4861 int transportType) {
4862 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004863 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4864 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4865 "IMS not available on device.");
4866 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004867 final long token = Binder.clearCallingIdentity();
4868 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004869 int slotId = getSlotIndex(subId);
4870 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4871 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4872 + subId + "'");
4873 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4874 }
4875 verifyImsMmTelConfiguredOrThrow(slotId);
4876 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4877 transportType, aBoolean -> {
4878 try {
4879 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4880 } catch (RemoteException e) {
4881 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4882 + "running. Ignore");
4883 }
4884 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004885 } catch (ImsException e) {
4886 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004887 } finally {
4888 Binder.restoreCallingIdentity(token);
4889 }
4890 }
4891
shilu366312e2019-12-17 09:28:10 -08004892 /**
4893 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4894 * @param subId The subscription to use to check the configuration.
4895 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004896 @Override
4897 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004898 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004899 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004900
joonhunshin4ac60942023-11-15 15:23:39 +00004901 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4902 FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled");
4903
Brad Ebinger35c841c2018-10-01 10:40:55 -07004904 final long token = Binder.clearCallingIdentity();
4905 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004906 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004907 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004908 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004909 } catch (ImsException e) {
4910 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004911 } finally {
4912 Binder.restoreCallingIdentity(token);
4913 }
4914 }
4915
4916 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004917 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004918 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004919 "setAdvancedCallingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004920
4921 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4922 FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled");
4923
Brad Ebinger35c841c2018-10-01 10:40:55 -07004924 final long identity = Binder.clearCallingIdentity();
4925 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004926 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004927 // This setting doesn't require an active ImsService connection, so do not verify. The
4928 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004929 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004930 } catch (ImsException e) {
4931 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004932 } finally {
4933 Binder.restoreCallingIdentity(identity);
4934 }
4935 }
4936
shilu366312e2019-12-17 09:28:10 -08004937 /**
4938 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4939 * @param subId The subscription to use to check the configuration.
4940 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004941 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004942 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004943 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004944 mApp, subId, "isVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004945
4946 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4947 FEATURE_TELEPHONY_IMS, "isVtSettingEnabled");
4948
Brad Ebinger35c841c2018-10-01 10:40:55 -07004949 final long identity = Binder.clearCallingIdentity();
4950 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004951 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004952 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004953 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004954 } catch (ImsException e) {
4955 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004956 } finally {
4957 Binder.restoreCallingIdentity(identity);
4958 }
4959 }
4960
4961 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004962 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004963 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004964 "setVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004965
4966 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4967 FEATURE_TELEPHONY_IMS, "setVtSettingEnabled");
4968
Brad Ebinger35c841c2018-10-01 10:40:55 -07004969 final long identity = Binder.clearCallingIdentity();
4970 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004971 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004972 // This setting doesn't require an active ImsService connection, so do not verify. The
4973 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004974 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004975 } catch (ImsException e) {
4976 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004977 } finally {
4978 Binder.restoreCallingIdentity(identity);
4979 }
4980 }
4981
shilu366312e2019-12-17 09:28:10 -08004982 /**
4983 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4984 * @param subId The subscription to use to check the configuration.
4985 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004986 @Override
4987 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004988 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004989 mApp, subId, "isVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004990
4991 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4992 FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled");
4993
Brad Ebinger35c841c2018-10-01 10:40:55 -07004994 final long identity = Binder.clearCallingIdentity();
4995 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004996 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004997 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004998 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004999 } catch (ImsException e) {
5000 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005001 } finally {
5002 Binder.restoreCallingIdentity(identity);
5003 }
5004 }
5005
5006 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005007 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005008 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005009 "setVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005010
5011 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5012 FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled");
5013
Brad Ebinger35c841c2018-10-01 10:40:55 -07005014 final long identity = Binder.clearCallingIdentity();
5015 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005016 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005017 // This setting doesn't require an active ImsService connection, so do not verify. The
5018 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005019 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005020 } catch (ImsException e) {
5021 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005022 } finally {
5023 Binder.restoreCallingIdentity(identity);
5024 }
5025 }
5026
shilu366312e2019-12-17 09:28:10 -08005027 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005028 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
5029 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5030 * @param subId The subscription to use to check the configuration.
5031 */
5032 @Override
5033 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005034 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005035 mApp, subId, "isCrossSimCallingEnabledByUser");
joonhunshin4ac60942023-11-15 15:23:39 +00005036
5037 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5038 FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser");
5039
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005040 final long identity = Binder.clearCallingIdentity();
5041 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005042 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005043 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005044 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005045 } catch (ImsException e) {
5046 throw new ServiceSpecificException(e.getCode());
5047 } finally {
5048 Binder.restoreCallingIdentity(identity);
5049 }
5050 }
5051
5052 /**
5053 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
5054 * Requires MODIFY_PHONE_STATE permission.
5055 * @param subId The subscription to use to check the configuration.
5056 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
5057 * false otherwise
5058 */
5059 @Override
5060 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
5061 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5062 "setCrossSimCallingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005063
5064 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5065 FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled");
5066
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005067 final long identity = Binder.clearCallingIdentity();
5068 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005069 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005070 // This setting doesn't require an active ImsService connection, so do not verify. The
5071 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005072 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005073 } catch (ImsException e) {
5074 throw new ServiceSpecificException(e.getCode());
5075 } finally {
5076 Binder.restoreCallingIdentity(identity);
5077 }
5078 }
5079
5080 /**
shilu366312e2019-12-17 09:28:10 -08005081 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5082 * @param subId The subscription to use to check the configuration.
5083 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005084 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07005085
Brad Ebinger35c841c2018-10-01 10:40:55 -07005086 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005087 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005088 mApp, subId, "isVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005089
5090 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5091 FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled");
5092
Brad Ebinger35c841c2018-10-01 10:40:55 -07005093 final long identity = Binder.clearCallingIdentity();
5094 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005095 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005096 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005097 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005098 } catch (ImsException e) {
5099 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005100 } finally {
5101 Binder.restoreCallingIdentity(identity);
5102 }
5103 }
5104
5105 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005106 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005107 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005108 "setVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005109
5110 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5111 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled");
5112
Brad Ebinger35c841c2018-10-01 10:40:55 -07005113 final long identity = Binder.clearCallingIdentity();
5114 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005115 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005116 // This setting doesn't require an active ImsService connection, so do not verify. The
5117 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005118 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005119 } catch (ImsException e) {
5120 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005121 } finally {
5122 Binder.restoreCallingIdentity(identity);
5123 }
5124 }
5125
5126 @Override
5127 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
5128 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5129 "setVoWiFiNonPersistent");
joonhunshin4ac60942023-11-15 15:23:39 +00005130
5131 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5132 FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent");
5133
Brad Ebinger35c841c2018-10-01 10:40:55 -07005134 final long identity = Binder.clearCallingIdentity();
5135 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005136 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005137 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005138 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005139 } catch (ImsException e) {
5140 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005141 } finally {
5142 Binder.restoreCallingIdentity(identity);
5143 }
5144 }
5145
shilu366312e2019-12-17 09:28:10 -08005146 /**
5147 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5148 * @param subId The subscription to use to check the configuration.
5149 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005150 @Override
5151 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005152 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005153 mApp, subId, "getVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005154
5155 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5156 FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting");
5157
Brad Ebinger35c841c2018-10-01 10:40:55 -07005158 final long identity = Binder.clearCallingIdentity();
5159 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005160 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005161 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005162 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005163 } catch (ImsException e) {
5164 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005165 } finally {
5166 Binder.restoreCallingIdentity(identity);
5167 }
5168 }
5169
5170 @Override
5171 public void setVoWiFiModeSetting(int subId, int mode) {
5172 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5173 "setVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005174
5175 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5176 FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting");
5177
Brad Ebinger35c841c2018-10-01 10:40:55 -07005178 final long identity = Binder.clearCallingIdentity();
5179 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005180 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005181 // This setting doesn't require an active ImsService connection, so do not verify. The
5182 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005183 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005184 } catch (ImsException e) {
5185 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005186 } finally {
5187 Binder.restoreCallingIdentity(identity);
5188 }
5189 }
5190
5191 @Override
5192 public int getVoWiFiRoamingModeSetting(int subId) {
5193 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005194
5195 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5196 FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting");
5197
Brad Ebinger35c841c2018-10-01 10:40:55 -07005198 final long identity = Binder.clearCallingIdentity();
5199 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005200 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005201 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005202 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005203 } catch (ImsException e) {
5204 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005205 } finally {
5206 Binder.restoreCallingIdentity(identity);
5207 }
5208 }
5209
5210 @Override
5211 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
5212 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5213 "setVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005214
5215 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5216 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting");
5217
Brad Ebinger35c841c2018-10-01 10:40:55 -07005218 final long identity = Binder.clearCallingIdentity();
5219 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005220 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005221 // This setting doesn't require an active ImsService connection, so do not verify. The
5222 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005223 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005224 } catch (ImsException e) {
5225 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005226 } finally {
5227 Binder.restoreCallingIdentity(identity);
5228 }
5229 }
5230
5231 @Override
5232 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
5233 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5234 "setRttCapabilityEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005235
5236 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5237 FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting");
5238
Brad Ebinger35c841c2018-10-01 10:40:55 -07005239 final long identity = Binder.clearCallingIdentity();
5240 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005241 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005242 // This setting doesn't require an active ImsService connection, so do not verify. The
5243 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005244 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005245 } catch (ImsException e) {
5246 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005247 } finally {
5248 Binder.restoreCallingIdentity(identity);
5249 }
5250 }
5251
shilu366312e2019-12-17 09:28:10 -08005252 /**
5253 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5254 * @param subId The subscription to use to check the configuration.
5255 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005256 @Override
5257 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005258 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005259 mApp, subId, "isTtyOverVolteEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005260
5261 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5262 FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled");
5263
Brad Ebinger35c841c2018-10-01 10:40:55 -07005264 final long identity = Binder.clearCallingIdentity();
5265 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005266 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005267 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005268 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005269 } catch (ImsException e) {
5270 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005271 } finally {
5272 Binder.restoreCallingIdentity(identity);
5273 }
5274 }
5275
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005276 @Override
5277 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5278 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005279
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005280 final long identity = Binder.clearCallingIdentity();
5281 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005282 if (!isImsAvailableOnDevice()) {
5283 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5284 "IMS not available on device.");
5285 }
5286 int slotId = getSlotIndexOrException(subId);
5287 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005288
5289 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5290 if (controller != null) {
5291 ImsManager imsManager = controller.getImsManager(subId);
5292 if (imsManager != null) {
5293 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5294 } else {
5295 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5296 }
5297 } else {
5298 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5299 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005300 } catch (ImsException e) {
5301 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005302 } finally {
5303 Binder.restoreCallingIdentity(identity);
5304 }
5305 }
5306
5307 @Override
5308 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5309 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005310
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005311 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005312 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5313 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5314 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005315 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005316 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5317 if (controller != null) {
5318 ImsManager imsManager = controller.getImsManager(subId);
5319 if (imsManager != null) {
5320 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5321 } else {
5322 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5323 + " is inactive, ignoring unregister.");
5324 // If the ImsManager is not valid, just return, since the callback will already
5325 // have been removed internally.
5326 }
5327 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005328 } finally {
5329 Binder.restoreCallingIdentity(identity);
5330 }
5331 }
5332
joonhunshincffb7fc2021-11-28 07:32:01 +00005333 @Override
5334 public void registerFeatureProvisioningChangedCallback(int subId,
5335 IFeatureProvisioningCallback callback) {
5336 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5337 mApp, subId, "registerFeatureProvisioningChangedCallback");
5338
5339 final long identity = Binder.clearCallingIdentity();
5340 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5341 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5342 }
5343
joonhunshin91bc1952022-04-29 08:47:15 +00005344 try {
5345 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5346 if (controller == null) {
5347 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5348 "Device does not support IMS");
5349 }
5350 controller.addFeatureProvisioningChangedCallback(subId, callback);
5351 } finally {
5352 Binder.restoreCallingIdentity(identity);
5353 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005354 }
5355
5356 @Override
5357 public void unregisterFeatureProvisioningChangedCallback(int subId,
5358 IFeatureProvisioningCallback callback) {
5359 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5360 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5361
5362 final long identity = Binder.clearCallingIdentity();
5363 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5364 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5365 }
5366
joonhunshin91bc1952022-04-29 08:47:15 +00005367 try {
5368 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5369 if (controller == null) {
5370 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5371 return;
5372 }
5373 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5374 } finally {
5375 Binder.restoreCallingIdentity(identity);
5376 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005377 }
allenwtsu99c623b2020-01-03 18:24:23 +08005378
5379 private void checkModifyPhoneStatePermission(int subId, String message) {
5380 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5381 message);
5382 }
5383
allenwtsu99c623b2020-01-03 18:24:23 +08005384 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005385 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005386 boolean isProvisioned) {
5387 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5388
joonhunshin4ac60942023-11-15 15:23:39 +00005389 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5390 FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability");
5391
allenwtsu99c623b2020-01-03 18:24:23 +08005392 final long identity = Binder.clearCallingIdentity();
5393 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005394 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5395 if (controller == null) {
5396 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5397 return;
5398 }
5399 controller.setRcsProvisioningStatusForCapability(
5400 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005401 } finally {
5402 Binder.restoreCallingIdentity(identity);
5403 }
allenwtsu99c623b2020-01-03 18:24:23 +08005404 }
5405
5406
5407 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005408 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5409 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5410 mApp, subId, "getRcsProvisioningStatusForCapability");
5411
joonhunshin4ac60942023-11-15 15:23:39 +00005412 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5413 FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability");
5414
allenwtsu99c623b2020-01-03 18:24:23 +08005415 final long identity = Binder.clearCallingIdentity();
5416 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005417 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5418 if (controller == null) {
5419 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5420
5421 // device does not support IMS, this method will return true always.
5422 return true;
5423 }
5424 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005425 } finally {
5426 Binder.restoreCallingIdentity(identity);
5427 }
5428 }
5429
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005430 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005431 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5432 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005433 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005434
joonhunshin4ac60942023-11-15 15:23:39 +00005435 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5436 FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability");
5437
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005438 final long identity = Binder.clearCallingIdentity();
5439 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005440 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5441 if (controller == null) {
5442 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5443 return;
5444 }
5445 controller.setImsProvisioningStatusForCapability(
5446 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005447 } finally {
5448 Binder.restoreCallingIdentity(identity);
5449 }
5450 }
5451
5452 @Override
5453 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005454 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5455 mApp, subId, "getProvisioningStatusForCapability");
5456
joonhunshin4ac60942023-11-15 15:23:39 +00005457 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5458 FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability");
5459
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005460 final long identity = Binder.clearCallingIdentity();
5461 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005462 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5463 if (controller == null) {
5464 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005465
joonhunshin91bc1952022-04-29 08:47:15 +00005466 // device does not support IMS, this method will return true always.
5467 return true;
5468 }
5469 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005470 } finally {
5471 Binder.restoreCallingIdentity(identity);
5472 }
5473 }
5474
5475 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005476 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5477 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5478 mApp, subId, "isProvisioningRequiredForCapability");
5479
joonhunshin4ac60942023-11-15 15:23:39 +00005480 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5481 FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability");
5482
joonhunshincffb7fc2021-11-28 07:32:01 +00005483 final long identity = Binder.clearCallingIdentity();
5484 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005485 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5486 if (controller == null) {
5487 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5488
5489 // device does not support IMS, this method will return false
5490 return false;
5491 }
5492 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005493 } finally {
5494 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005495 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005496 }
5497
5498 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005499 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5500 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5501 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005502
joonhunshin4ac60942023-11-15 15:23:39 +00005503 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5504 FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability");
5505
joonhunshincffb7fc2021-11-28 07:32:01 +00005506 final long identity = Binder.clearCallingIdentity();
5507 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005508 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5509 if (controller == null) {
5510 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5511
5512 // device does not support IMS, this method will return false
5513 return false;
5514 }
5515 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005516 } finally {
5517 Binder.restoreCallingIdentity(identity);
5518 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005519 }
5520
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005521 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005522 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005523 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5524 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5525 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005526 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5527 mApp, subId, "getImsProvisioningInt");
5528
joonhunshin4ac60942023-11-15 15:23:39 +00005529 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5530 FEATURE_TELEPHONY_IMS, "getImsProvisioningInt");
5531
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005532 final long identity = Binder.clearCallingIdentity();
5533 try {
5534 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005535 int slotId = getSlotIndex(subId);
5536 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5537 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5538 + subId + "' for key:" + key);
5539 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5540 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005541
joonhunshin91bc1952022-04-29 08:47:15 +00005542 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5543 if (controller == null) {
5544 loge("getImsProvisioningInt: Device does not support IMS");
5545
5546 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5547 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5548 }
5549 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005550 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5551 return retVal;
5552 }
5553
calvinpanb5a34062021-02-08 19:59:36 +08005554 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005555 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005556 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5557 + subId + "' for key:" + key);
5558 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005559 } finally {
5560 Binder.restoreCallingIdentity(identity);
5561 }
5562 }
5563
5564 @Override
5565 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005566 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5567 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5568 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005569 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5570 mApp, subId, "getImsProvisioningString");
5571
joonhunshin4ac60942023-11-15 15:23:39 +00005572 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5573 FEATURE_TELEPHONY_IMS, "getImsProvisioningString");
5574
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005575 final long identity = Binder.clearCallingIdentity();
5576 try {
5577 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005578 int slotId = getSlotIndex(subId);
5579 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5580 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5581 + subId + "' for key:" + key);
5582 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5583 }
calvinpanb5a34062021-02-08 19:59:36 +08005584 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005585 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005586 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5587 + subId + "' for key:" + key);
5588 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005589 } finally {
5590 Binder.restoreCallingIdentity(identity);
5591 }
5592 }
5593
5594 @Override
5595 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005596 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5597 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5598 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005599 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5600 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005601
joonhunshin4ac60942023-11-15 15:23:39 +00005602 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5603 FEATURE_TELEPHONY_IMS, "setImsProvisioningInt");
5604
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005605 final long identity = Binder.clearCallingIdentity();
5606 try {
5607 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005608 int slotId = getSlotIndex(subId);
5609 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5610 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5611 + subId + "' for key:" + key);
5612 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5613 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005614
joonhunshin91bc1952022-04-29 08:47:15 +00005615 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5616 if (controller == null) {
5617 loge("setImsProvisioningInt: Device does not support IMS");
5618
5619 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5620 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5621 }
5622 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005623 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5624 return retVal;
5625 }
5626
calvinpanb5a34062021-02-08 19:59:36 +08005627 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5628 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005629 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005630 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005631 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005632 } finally {
5633 Binder.restoreCallingIdentity(identity);
5634 }
5635 }
5636
5637 @Override
5638 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005639 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5640 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5641 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005642 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5643 "setImsProvisioningString");
joonhunshin4ac60942023-11-15 15:23:39 +00005644
5645 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5646 FEATURE_TELEPHONY_IMS, "setImsProvisioningString");
5647
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005648 final long identity = Binder.clearCallingIdentity();
5649 try {
5650 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005651 int slotId = getSlotIndex(subId);
5652 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5653 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5654 + subId + "' for key:" + key);
5655 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5656 }
calvinpanb5a34062021-02-08 19:59:36 +08005657 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5658 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005659 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005660 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005661 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005662 } finally {
5663 Binder.restoreCallingIdentity(identity);
5664 }
5665 }
5666
Brad Ebinger919631e2021-06-02 17:46:35 -07005667 /**
5668 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5669 * for the given slot ID or no ImsResolver instance has been created.
5670 * @param slotId The slot ID that the IMS service is created for.
5671 * @throws ImsException If there is no ImsService configured for this slot.
5672 */
5673 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5674 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5675 ImsFeature.FEATURE_MMTEL)) {
5676 throw new ImsException("This subscription does not support MMTEL over IMS",
5677 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5678 }
5679 }
5680
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005681 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005682 int slotId = SubscriptionManager.getSlotIndex(subId);
5683 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005684 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5685 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005686 }
5687 return slotId;
5688 }
5689
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005690 private int getSlotIndex(int subId) {
5691 int slotId = SubscriptionManager.getSlotIndex(subId);
5692 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5693 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5694 }
5695 return slotId;
5696 }
5697
Wink Saville36469e72014-06-11 15:17:00 -07005698 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005699 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005700 */
5701 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005702 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5703 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005704 try {
5705 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5706 } catch (SecurityException se) {
5707 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5708 throw new SecurityException("Package " + callingPackage + " does not belong to "
5709 + Binder.getCallingUid());
5710 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005711 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005712 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005713 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005714 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005715 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005716 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005717 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005718 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5719 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005720
joonhunshin4ac60942023-11-15 15:23:39 +00005721 enforceTelephonyFeatureWithException(callingPackage,
5722 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber");
5723
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005724 final long identity = Binder.clearCallingIdentity();
5725 try {
5726 final Phone phone = getPhone(subId);
5727 if (phone != null) {
5728 return phone.getServiceState().getDataNetworkType();
5729 } else {
5730 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5731 }
5732 } finally {
5733 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005734 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005735 }
5736
5737 /**
5738 * Returns the data network type
5739 */
5740 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005741 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005742 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005743 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005744 }
5745
5746 /**
5747 * Returns the data network type for a subId
5748 */
5749 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005750 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5751 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005752 String functionName = "getDataNetworkTypeForSubscriber";
5753 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5754 mApp, functionName)) {
5755 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5756 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5757 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5758 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005759 }
5760
joonhunshin4ac60942023-11-15 15:23:39 +00005761 enforceTelephonyFeatureWithException(callingPackage,
5762 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber");
5763
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005764 final long identity = Binder.clearCallingIdentity();
5765 try {
5766 final Phone phone = getPhone(subId);
5767 if (phone != null) {
5768 return phone.getServiceState().getDataNetworkType();
5769 } else {
5770 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5771 }
5772 } finally {
5773 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005774 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005775 }
5776
5777 /**
Wink Saville36469e72014-06-11 15:17:00 -07005778 * Returns the Voice network type for a subId
5779 */
5780 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005781 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5782 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005783 String functionName = "getVoiceNetworkTypeForSubscriber";
5784 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5785 mApp, functionName)) {
5786 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5787 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5788 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5789 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005790 }
5791
joonhunshin4ac60942023-11-15 15:23:39 +00005792 enforceTelephonyFeatureWithException(callingPackage,
5793 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber");
5794
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005795 final long identity = Binder.clearCallingIdentity();
5796 try {
5797 final Phone phone = getPhone(subId);
5798 if (phone != null) {
5799 return phone.getServiceState().getVoiceNetworkType();
5800 } else {
5801 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5802 }
5803 } finally {
5804 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005805 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005806 }
5807
5808 /**
5809 * @return true if a ICC card is present
5810 */
5811 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005812 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005813 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005814 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005815 }
5816
5817 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005818 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005819 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005820 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005821 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00005822 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5823 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex");
5824
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005825 final long identity = Binder.clearCallingIdentity();
5826 try {
5827 final Phone phone = PhoneFactory.getPhone(slotIndex);
5828 if (phone != null) {
5829 return phone.getIccCard().hasIccCard();
5830 } else {
5831 return false;
5832 }
5833 } finally {
5834 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005835 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005836 }
5837
5838 /**
5839 * Return if the current radio is LTE on CDMA. This
5840 * is a tri-state return value as for a period of time
5841 * the mode may be unknown.
5842 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005843 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005844 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005845 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005846 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005847 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005848 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5849 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5850 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005851 }
5852
Sanket Padawe356d7632015-06-22 14:03:32 -07005853 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005854 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5855 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005856 try {
5857 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5858 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005859 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5860 }
5861
joonhunshin4ac60942023-11-15 15:23:39 +00005862 enforceTelephonyFeatureWithException(callingPackage,
5863 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber");
5864
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005865 final long identity = Binder.clearCallingIdentity();
5866 try {
5867 final Phone phone = getPhone(subId);
5868 if (phone == null) {
5869 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5870 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005871 return TelephonyProperties.lte_on_cdma_device()
5872 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005873 }
5874 } finally {
5875 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005876 }
Wink Saville36469e72014-06-11 15:17:00 -07005877 }
5878
Wink Saville36469e72014-06-11 15:17:00 -07005879 /**
5880 * {@hide}
5881 * Returns Default subId, 0 in the case of single standby.
5882 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005883 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005884 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005885 }
5886
Shishir Agrawala9f32182016-04-12 12:00:16 -07005887 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005888 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005889 }
5890
Wink Savilleb564aae2014-10-23 10:18:09 -07005891 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005892 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005893 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005894
Pengquan Menge92a50d2018-09-21 15:54:48 -07005895 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005896 return getSubscriptionManagerService().isActiveSubId(subId,
5897 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005898 }
5899
Ihab Awadf2177b72013-11-25 13:33:23 -08005900 /**
5901 * @see android.telephony.TelephonyManager.WifiCallingChoices
5902 */
5903 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005904 final long identity = Binder.clearCallingIdentity();
5905 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005906 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005907 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5908 getWhenToMakeWifiCallsDefaultPreference());
5909 } finally {
5910 Binder.restoreCallingIdentity(identity);
5911 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005912 }
5913
5914 /**
5915 * @see android.telephony.TelephonyManager.WifiCallingChoices
5916 */
5917 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005918 final long identity = Binder.clearCallingIdentity();
5919 try {
5920 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005921 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005922 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5923 } finally {
5924 Binder.restoreCallingIdentity(identity);
5925 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005926 }
5927
Sailesh Nepald1e68152013-12-12 19:08:02 -08005928 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005929 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005930 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005931 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005932
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005933 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5934 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5935 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005936 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005937 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005938 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005939 }
5940 return PhoneFactory.getPhone(phoneId);
5941 }
5942
Shishir Agrawal566b7612013-10-28 14:41:00 -07005943 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005944 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005945 @NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00005946
Rambo Wanga1782702021-11-10 20:15:19 -08005947 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5948 /*message=*/ "iccOpenLogicalChannel");
5949
5950 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5951 // Verify that the callingPackage in the request belongs to the calling UID
5952 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5953
joonhunshin4ac60942023-11-15 15:23:39 +00005954 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5955 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel");
5956
Rambo Wanga1782702021-11-10 20:15:19 -08005957 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005958 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005959
Rambo Wanga1782702021-11-10 20:15:19 -08005960 private Phone getPhoneFromValidIccLogicalChannelRequest(
5961 @NonNull IccLogicalChannelRequest request, String message) {
5962 Phone phone;
5963 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5964 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5965 mApp, request.subId, message);
5966 phone = getPhoneFromSubId(request.subId);
5967 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5968 enforceModifyPermission();
5969 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5970 } else {
5971 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005972 }
Rambo Wanga1782702021-11-10 20:15:19 -08005973 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005974 }
5975
5976 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005977 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005978 final long identity = Binder.clearCallingIdentity();
5979 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005980 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005981 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005982 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5983 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005984 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5985 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005986 loge("The calling package is not allowed to access ISD-R.");
5987 throw new SecurityException(
5988 "The calling package is not allowed to access ISD-R.");
5989 }
Derek Tan740e1672017-06-27 14:56:27 -07005990 }
Derek Tan740e1672017-06-27 14:56:27 -07005991
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005992 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005993 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5994 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005995 return response;
5996 } finally {
5997 Binder.restoreCallingIdentity(identity);
5998 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005999 }
6000
6001 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08006002 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00006003 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6004 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel");
6005
Rambo Wanga1782702021-11-10 20:15:19 -08006006 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
6007 /*message=*/"iccCloseLogicalChannel");
6008
6009 if (DBG) log("iccCloseLogicalChannel: request=" + request);
6010
6011 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006012 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006013
Rambo Wanga1782702021-11-10 20:15:19 -08006014 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
6015 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08006016 // before this feature is enabled, this API should only return false if
6017 // the operation fails instead of throwing runtime exception for
6018 // backward-compatibility.
6019 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
6020 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006021 final long identity = Binder.clearCallingIdentity();
6022 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006023 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08006024 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006025 }
Chen Xue9d737e2022-01-01 23:41:31 -08006026 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08006027 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08006028 Boolean success = false;
6029 if (result instanceof RuntimeException) {
6030 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08006031 if (shouldThrowExceptionOnFailure) {
6032 throw (RuntimeException) result;
6033 } else {
6034 return false;
6035 }
Chen Xue9d737e2022-01-01 23:41:31 -08006036 } else if (result instanceof Boolean) {
6037 success = (Boolean) result;
6038 } else {
6039 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
6040 }
Rambo Wanga1782702021-11-10 20:15:19 -08006041 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006042 return success;
6043 } finally {
6044 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006045 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006046 }
6047
6048 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006049 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07006050 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006051 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6052 mApp, subId, "iccTransmitApduLogicalChannel");
joonhunshin4ac60942023-11-15 15:23:39 +00006053
6054 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6055 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel");
6056
Jordan Liu4c733742019-02-28 12:03:40 -08006057 if (DBG) {
6058 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
6059 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
6060 + p3 + " data=" + data);
6061 }
6062 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
6063 command, p1, p2, p3, data);
6064 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006065
Jordan Liu4c733742019-02-28 12:03:40 -08006066 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006067 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006068 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006069 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006070
6071 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6072 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
6073 "iccTransmitApduLogicalChannelBySlot");
6074
Jordan Liu4c733742019-02-28 12:03:40 -08006075 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006076 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006077 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
6078 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006079 }
6080 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006081 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
6082 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006083 }
6084
6085 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
6086 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006087 final long identity = Binder.clearCallingIdentity();
6088 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07006089 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006090 return "";
6091 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006092
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006093 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006094 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
6095 null /* workSource */);
6096 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006097
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006098 // Append the returned status code to the end of the response payload.
6099 String s = Integer.toHexString(
6100 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6101 if (response.payload != null) {
6102 s = IccUtils.bytesToHexString(response.payload) + s;
6103 }
6104 return s;
6105 } finally {
6106 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006107 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006108 }
Jake Hambye994d462014-02-03 13:10:13 -08006109
Evan Charltonc66da362014-05-16 14:06:40 -07006110 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006111 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
6112 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006113 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6114 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006115 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006116
6117 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6118 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel");
6119
Jordan Liu4c733742019-02-28 12:03:40 -08006120 if (DBG) {
6121 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
6122 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
6123 }
6124 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
6125 cla, command, p1, p2, p3, data);
6126 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006127
Jordan Liu4c733742019-02-28 12:03:40 -08006128 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006129 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006130 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006131 enforceModifyPermission();
6132 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006133
6134 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6135 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot");
6136
Jordan Liu4c733742019-02-28 12:03:40 -08006137 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006138 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006139 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
6140 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006141 }
6142
6143 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006144 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
6145 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006146 }
6147
6148 // open APDU basic channel assuming the caller has sufficient permissions
6149 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
6150 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006151 final long identity = Binder.clearCallingIdentity();
6152 try {
6153 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
6154 && TextUtils.equals(ISDR_AID, data)) {
6155 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006156 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6157 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006158 if (bestComponent == null
6159 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
6160 loge("The calling package is not allowed to select ISD-R.");
6161 throw new SecurityException(
6162 "The calling package is not allowed to select ISD-R.");
6163 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006164 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006165
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006166 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006167 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
6168 null /* workSource */);
6169 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006170
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006171 // Append the returned status code to the end of the response payload.
6172 String s = Integer.toHexString(
6173 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6174 if (response.payload != null) {
6175 s = IccUtils.bytesToHexString(response.payload) + s;
6176 }
6177 return s;
6178 } finally {
6179 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006180 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006181 }
6182
6183 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006184 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006185 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006186 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6187 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006188
joonhunshin4ac60942023-11-15 15:23:39 +00006189 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6190 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO");
6191
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006192 final long identity = Binder.clearCallingIdentity();
6193 try {
6194 if (DBG) {
6195 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
6196 + p1 + " " + p2 + " " + p3 + ":" + filePath);
6197 }
6198
6199 IccIoResult response =
6200 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
6201 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
6202 subId);
6203
6204 if (DBG) {
6205 log("Exchange SIM_IO [R]" + response);
6206 }
6207
6208 byte[] result = null;
6209 int length = 2;
6210 if (response.payload != null) {
6211 length = 2 + response.payload.length;
6212 result = new byte[length];
6213 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
6214 } else {
6215 result = new byte[length];
6216 }
6217
6218 result[length - 1] = (byte) response.sw2;
6219 result[length - 2] = (byte) response.sw1;
6220 return result;
6221 } finally {
6222 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006223 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006224 }
6225
Nathan Haroldb3014052017-01-25 15:57:32 -08006226 /**
6227 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
6228 * on a particular subscription
6229 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006230 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
6231 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07006232 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006233 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07006234 return null;
6235 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006236
joonhunshin4ac60942023-11-15 15:23:39 +00006237 enforceTelephonyFeatureWithException(callingPackage,
6238 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns");
6239
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006240 final long identity = Binder.clearCallingIdentity();
6241 try {
6242 if (appType != TelephonyManager.APPTYPE_USIM
6243 && appType != TelephonyManager.APPTYPE_SIM) {
6244 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
6245 return null;
6246 }
6247 Object response = sendRequest(
6248 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
6249 if (response instanceof String[]) {
6250 return (String[]) response;
6251 }
yincheng zhao2737e882019-09-06 17:06:54 -07006252 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006253 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08006254 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006255 } finally {
6256 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08006257 }
Nathan Haroldb3014052017-01-25 15:57:32 -08006258 }
6259
yincheng zhao2737e882019-09-06 17:06:54 -07006260 /**
6261 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
6262 * subscription.
6263 *
6264 * @param subId the id of the subscription.
6265 * @param appType the uicc app type, must be USIM or SIM.
6266 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
6267 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006268 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07006269 * @return number of fplmns that is successfully written to the SIM.
6270 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006271 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
6272 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07006273 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6274 mApp, subId, "setForbiddenPlmns");
6275
joonhunshin4ac60942023-11-15 15:23:39 +00006276 enforceTelephonyFeatureWithException(callingPackage,
6277 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns");
6278
yincheng zhao2737e882019-09-06 17:06:54 -07006279 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
6280 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
6281 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
6282 }
6283 if (fplmns == null) {
6284 throw new IllegalArgumentException("Fplmn List provided is null");
6285 }
6286 for (String fplmn : fplmns) {
6287 if (!CellIdentity.isValidPlmn(fplmn)) {
6288 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
6289 }
6290 }
6291 final long identity = Binder.clearCallingIdentity();
6292 try {
6293 Object response = sendRequest(
6294 CMD_SET_FORBIDDEN_PLMNS,
6295 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
6296 subId);
6297 return (int) response;
6298 } finally {
6299 Binder.restoreCallingIdentity(identity);
6300 }
6301 }
6302
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006303 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006304 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006305 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6306 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07006307
joonhunshin4ac60942023-11-15 15:23:39 +00006308 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6309 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus");
6310
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006311 final long identity = Binder.clearCallingIdentity();
6312 try {
6313 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
6314 if (response.payload == null) {
6315 return "";
6316 }
Evan Charltonc66da362014-05-16 14:06:40 -07006317
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006318 // Append the returned status code to the end of the response payload.
6319 String s = Integer.toHexString(
6320 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6321 s = IccUtils.bytesToHexString(response.payload) + s;
6322 return s;
6323 } finally {
6324 Binder.restoreCallingIdentity(identity);
6325 }
Evan Charltonc66da362014-05-16 14:06:40 -07006326 }
6327
Jake Hambye994d462014-02-03 13:10:13 -08006328 /**
6329 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6330 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6331 *
6332 * @param itemID the ID of the item to read
6333 * @return the NV item as a String, or null on error.
6334 */
6335 @Override
6336 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006337 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006338 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6339 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006340
6341 final long identity = Binder.clearCallingIdentity();
6342 try {
6343 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07006344 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006345 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
6346 return value;
6347 } finally {
6348 Binder.restoreCallingIdentity(identity);
6349 }
Jake Hambye994d462014-02-03 13:10:13 -08006350 }
6351
6352 /**
6353 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6354 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6355 *
6356 * @param itemID the ID of the item to read
6357 * @param itemValue the value to write, as a String
6358 * @return true on success; false on any failure
6359 */
6360 @Override
6361 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006362 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006363 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6364 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006365
6366 final long identity = Binder.clearCallingIdentity();
6367 try {
6368 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6369 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006370 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006371 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6372 return success;
6373 } finally {
6374 Binder.restoreCallingIdentity(identity);
6375 }
Jake Hambye994d462014-02-03 13:10:13 -08006376 }
6377
6378 /**
6379 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6380 * Used for device configuration by some CDMA operators.
6381 *
6382 * @param preferredRoamingList byte array containing the new PRL
6383 * @return true on success; false on any failure
6384 */
6385 @Override
6386 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006387 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6388 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006389
6390 final long identity = Binder.clearCallingIdentity();
6391 try {
6392 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6393 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6394 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6395 return success;
6396 } finally {
6397 Binder.restoreCallingIdentity(identity);
6398 }
Jake Hambye994d462014-02-03 13:10:13 -08006399 }
6400
6401 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006402 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006403 * Used for device configuration by some CDMA operators.
6404 *
chen xu6dac5ab2018-10-26 17:39:23 -07006405 * @param slotIndex - device slot.
6406 *
Jake Hambye994d462014-02-03 13:10:13 -08006407 * @return true on success; false on any failure
6408 */
6409 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006410 public boolean resetModemConfig(int slotIndex) {
6411 Phone phone = PhoneFactory.getPhone(slotIndex);
6412 if (phone != null) {
6413 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6414 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006415
joonhunshin4ac60942023-11-15 15:23:39 +00006416 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6417 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig");
6418
chen xu6dac5ab2018-10-26 17:39:23 -07006419 final long identity = Binder.clearCallingIdentity();
6420 try {
6421 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6422 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6423 return success;
6424 } finally {
6425 Binder.restoreCallingIdentity(identity);
6426 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006427 }
chen xu6dac5ab2018-10-26 17:39:23 -07006428 return false;
6429 }
6430
6431 /**
6432 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6433 *
6434 * @param slotIndex - device slot.
6435 *
6436 * @return true on success; false on any failure
6437 */
6438 @Override
6439 public boolean rebootModem(int slotIndex) {
6440 Phone phone = PhoneFactory.getPhone(slotIndex);
6441 if (phone != null) {
6442 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6443 mApp, phone.getSubId(), "rebootModem");
6444
joonhunshin4ac60942023-11-15 15:23:39 +00006445 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6446 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem");
6447
chen xu6dac5ab2018-10-26 17:39:23 -07006448 final long identity = Binder.clearCallingIdentity();
6449 try {
6450 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6451 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6452 return success;
6453 } finally {
6454 Binder.restoreCallingIdentity(identity);
6455 }
6456 }
6457 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006458 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006459
Brad Ebinger51f743a2017-01-23 13:50:20 -08006460 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006461 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6462 * {@link #disableIms(int)}.
6463 * @param slotIndex device slot.
6464 */
6465 public void resetIms(int slotIndex) {
6466 enforceModifyPermission();
6467
joonhunshin4ac60942023-11-15 15:23:39 +00006468 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6469 PackageManager.FEATURE_TELEPHONY_IMS, "resetIms");
6470
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006471 final long identity = Binder.clearCallingIdentity();
6472 try {
6473 if (mImsResolver == null) {
6474 // may happen if the does not support IMS.
6475 return;
6476 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006477 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006478 } finally {
6479 Binder.restoreCallingIdentity(identity);
6480 }
6481 }
6482
6483 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006484 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6485 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006486 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006487 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006488 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006489
6490 final long identity = Binder.clearCallingIdentity();
6491 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006492 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006493 // may happen if the device does not support IMS.
6494 return;
6495 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006496 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006497 } finally {
6498 Binder.restoreCallingIdentity(identity);
6499 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006500 }
6501
6502 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006503 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6504 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006505 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006506 public void disableIms(int slotId) {
6507 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006508
6509 final long identity = Binder.clearCallingIdentity();
6510 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006511 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006512 // may happen if the device does not support IMS.
6513 return;
6514 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006515 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006516 } finally {
6517 Binder.restoreCallingIdentity(identity);
6518 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006519 }
6520
6521 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006522 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6523 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006524 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006525 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006526 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006527 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006528
6529 final long identity = Binder.clearCallingIdentity();
6530 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006531 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006532 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6533 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006534 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006535 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006536 } finally {
6537 Binder.restoreCallingIdentity(identity);
6538 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006539 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006540 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006541 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6542 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006543 @Override
6544 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006545 enforceModifyPermission();
6546
6547 final long identity = Binder.clearCallingIdentity();
6548 try {
6549 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006550 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006551 } finally {
6552 Binder.restoreCallingIdentity(identity);
6553 }
6554 }
6555
6556 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006557 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006558 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006559 */
6560 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6561 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006562
6563 final long identity = Binder.clearCallingIdentity();
6564 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006565 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006566 // may happen if the device does not support IMS.
6567 return null;
6568 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006569 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006570 } finally {
6571 Binder.restoreCallingIdentity(identity);
6572 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006573 }
6574
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006575 /**
6576 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006577 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006578 */
6579 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6580 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006581
6582 final long identity = Binder.clearCallingIdentity();
6583 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006584 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006585 // may happen if the device does not support IMS.
6586 return null;
6587 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006588 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006589 } finally {
6590 Binder.restoreCallingIdentity(identity);
6591 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006592 }
6593
Brad Ebinger884c07b2018-02-15 16:17:40 -08006594 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006595 * Sets the ImsService Package Name that Telephony will bind to.
6596 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006597 * @param slotIndex the slot ID that the ImsService should bind for.
6598 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006599 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006600 * @param featureTypes An integer array of feature types associated with a packageName.
6601 * @param packageName The name of the package that the current configuration will be replaced
6602 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006603 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006604 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006605 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6606 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006607 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006608 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006609 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006610
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006611 final long identity = Binder.clearCallingIdentity();
6612 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006613 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006614 // may happen if the device does not support IMS.
6615 return false;
6616 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006617 Map<Integer, String> featureConfig = new HashMap<>();
6618 for (int featureType : featureTypes) {
6619 featureConfig.put(featureType, packageName);
6620 }
6621 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6622 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006623 } finally {
6624 Binder.restoreCallingIdentity(identity);
6625 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006626 }
6627
6628 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006629 * Clears any carrier ImsService overrides for the slot index specified that were previously
6630 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6631 *
6632 * This should only be used for testing.
6633 *
6634 * @param slotIndex the slot ID that the ImsService should bind for.
6635 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6636 */
6637 @Override
6638 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006639 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6640 "clearCarrierImsServiceOverride");
6641 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006642 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006643
6644 final long identity = Binder.clearCallingIdentity();
6645 try {
6646 if (mImsResolver == null) {
6647 // may happen if the device does not support IMS.
6648 return false;
6649 }
6650 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6651 } finally {
6652 Binder.restoreCallingIdentity(identity);
6653 }
6654 }
6655
6656 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006657 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006658 *
6659 * @param slotId The slot that the ImsService is associated with.
6660 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6661 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006662 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006663 * @return the package name of the ImsService configuration.
6664 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006665 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6666 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006667 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006668 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6669 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006670
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006671 final long identity = Binder.clearCallingIdentity();
6672 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006673 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006674 // may happen if the device does not support IMS.
6675 return "";
6676 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006677 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006678 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6679 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006680 } finally {
6681 Binder.restoreCallingIdentity(identity);
6682 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006683 }
6684
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006685 /**
6686 * Get the MmTelFeature state associated with the requested subscription id.
6687 * @param subId The subscription that the MmTelFeature is associated with.
6688 * @param callback A callback with an integer containing the
6689 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6690 */
6691 @Override
6692 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6693 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006694 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6695 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6696 "IMS not available on device.");
6697 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006698 final long token = Binder.clearCallingIdentity();
6699 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006700 int slotId = getSlotIndex(subId);
6701 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6702 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6703 + subId + "'");
6704 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6705 }
6706 verifyImsMmTelConfiguredOrThrow(slotId);
6707 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6708 try {
6709 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6710 } catch (RemoteException e) {
6711 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6712 + "Ignore");
6713 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006714 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006715 } catch (ImsException e) {
6716 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006717 } finally {
6718 Binder.restoreCallingIdentity(token);
6719 }
6720 }
6721
Daniel Brightbb5840b2021-01-12 15:48:18 -08006722 /**
6723 * Sets the ims registration state on all valid {@link Phone}s.
6724 */
6725 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006726 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006727
6728 final long identity = Binder.clearCallingIdentity();
6729 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006730 // NOTE: Before S, this method only set the default phone.
6731 for (final Phone phone : PhoneFactory.getPhones()) {
6732 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6733 phone.setImsRegistrationState(registered);
6734 }
6735 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006736 } finally {
6737 Binder.restoreCallingIdentity(identity);
6738 }
Wink Saville36469e72014-06-11 15:17:00 -07006739 }
6740
6741 /**
Stuart Scott54788802015-03-30 13:18:01 -07006742 * Set the network selection mode to automatic.
6743 *
6744 */
6745 @Override
6746 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006747 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6748 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006749
joonhunshin4ac60942023-11-15 15:23:39 +00006750 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6751 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic");
6752
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006753 final long identity = Binder.clearCallingIdentity();
6754 try {
shilufc958392020-01-20 11:36:01 -08006755 if (!isActiveSubscription(subId)) {
6756 return;
6757 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006758 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006759 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6760 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006761 } finally {
6762 Binder.restoreCallingIdentity(identity);
6763 }
Stuart Scott54788802015-03-30 13:18:01 -07006764 }
6765
Jack Yud10cdd42020-09-28 20:28:01 -07006766 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006767 * Ask the radio to connect to the input network and change selection mode to manual.
6768 *
6769 * @param subId the id of the subscription.
6770 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6771 * the operator to attach to.
6772 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6773 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6774 * normal network selection next time.
6775 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006776 */
6777 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006778 public boolean setNetworkSelectionModeManual(
6779 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006780 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6781 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006782
joonhunshin4ac60942023-11-15 15:23:39 +00006783 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6784 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual");
6785
Jack Yu285100e2022-12-02 22:48:35 -08006786 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006787 if (!isActiveSubscription(subId)) {
6788 return false;
6789 }
6790
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006791 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006792 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006793 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006794 if (DBG) {
6795 log("setNetworkSelectionModeManual: subId: " + subId
6796 + " operator: " + operatorInfo);
6797 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006798 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6799 } finally {
6800 Binder.restoreCallingIdentity(identity);
6801 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006802 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006803 /**
shilu84f6e8b2019-12-19 13:58:01 -08006804 * Get the manual network selection
6805 *
6806 * @param subId the id of the subscription.
6807 *
6808 * @return the previously saved user selected PLMN
6809 */
6810 @Override
6811 public String getManualNetworkSelectionPlmn(int subId) {
6812 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006813 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6814 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006815
joonhunshin4ac60942023-11-15 15:23:39 +00006816 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6817 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn");
6818
shilu84f6e8b2019-12-19 13:58:01 -08006819 final long identity = Binder.clearCallingIdentity();
6820 try {
6821 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006822 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006823 }
6824
6825 final Phone phone = getPhone(subId);
6826 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006827 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006828 }
6829 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6830 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006831 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006832 } finally {
6833 Binder.restoreCallingIdentity(identity);
6834 }
6835 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006836
6837 /**
6838 * Scans for available networks.
6839 */
6840 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006841 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6842 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006843 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6844 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006845 LocationAccessPolicy.LocationPermissionResult locationResult =
6846 LocationAccessPolicy.checkLocationPermission(mApp,
6847 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6848 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006849 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006850 .setCallingPid(Binder.getCallingPid())
6851 .setCallingUid(Binder.getCallingUid())
6852 .setMethod("getCellNetworkScanResults")
6853 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006854 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6855 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006856 .build());
6857 switch (locationResult) {
6858 case DENIED_HARD:
6859 throw new SecurityException("Not allowed to access scan results -- location");
6860 case DENIED_SOFT:
6861 return null;
6862 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006863
Pengquan Menga1bb6272018-09-06 09:59:22 -07006864 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006865 try {
6866 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006867 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006868 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006869 } finally {
6870 Binder.restoreCallingIdentity(identity);
6871 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006872 }
6873
6874 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006875 * Get the call forwarding info, given the call forwarding reason.
6876 */
6877 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006878 public void getCallForwarding(int subId, int callForwardingReason,
6879 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006880 enforceReadPrivilegedPermission("getCallForwarding");
joonhunshin4ac60942023-11-15 15:23:39 +00006881
6882 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6883 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding");
6884
Shuo Qian4a594052020-01-23 11:59:30 -08006885 long identity = Binder.clearCallingIdentity();
6886 try {
6887 if (DBG) {
6888 log("getCallForwarding: subId " + subId
6889 + " callForwardingReason" + callForwardingReason);
6890 }
Hall Liu27d24262020-09-18 19:04:59 -07006891
6892 Phone phone = getPhone(subId);
6893 if (phone == null) {
6894 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006895 callback.onError(
6896 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006897 } catch (RemoteException e) {
6898 // ignore
6899 }
6900 return;
6901 }
6902
6903 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6904 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6905 @Override
6906 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6907 try {
6908 callback.onCallForwardingInfoAvailable(info);
6909 } catch (RemoteException e) {
6910 // ignore
6911 }
6912 }
6913
6914 @Override
6915 public void onError(int error) {
6916 try {
6917 callback.onError(error);
6918 } catch (RemoteException e) {
6919 // ignore
6920 }
6921 }
6922 });
6923 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006924 } finally {
6925 Binder.restoreCallingIdentity(identity);
6926 }
6927 }
6928
6929 /**
6930 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6931 * reason, the number to forward, and the timeout before the forwarding is attempted.
6932 */
6933 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006934 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6935 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006936 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006937
6938 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6939 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding");
6940
Shuo Qian4a594052020-01-23 11:59:30 -08006941 long identity = Binder.clearCallingIdentity();
6942 try {
6943 if (DBG) {
6944 log("setCallForwarding: subId " + subId
6945 + " callForwardingInfo" + callForwardingInfo);
6946 }
Hall Liu27d24262020-09-18 19:04:59 -07006947
6948 Phone phone = getPhone(subId);
6949 if (phone == null) {
6950 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006951 callback.accept(
6952 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006953 } catch (RemoteException e) {
6954 // ignore
6955 }
6956 return;
6957 }
6958
6959 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6960 FunctionalUtils.ignoreRemoteException(callback::accept));
6961
6962 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006963 } finally {
6964 Binder.restoreCallingIdentity(identity);
6965 }
6966 }
6967
6968 /**
Hall Liu27d24262020-09-18 19:04:59 -07006969 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006970 */
6971 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006972 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006973 enforceReadPrivilegedPermission("getCallWaitingStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00006974
6975 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6976 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus");
6977
Shuo Qian4a594052020-01-23 11:59:30 -08006978 long identity = Binder.clearCallingIdentity();
6979 try {
Hall Liu27d24262020-09-18 19:04:59 -07006980 Phone phone = getPhone(subId);
6981 if (phone == null) {
6982 try {
6983 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6984 } catch (RemoteException e) {
6985 // ignore
6986 }
6987 return;
6988 }
SongFerngWang0e767992021-03-31 22:08:45 +08006989 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6990 PersistableBundle c = configManager.getConfigForSubId(subId);
6991 boolean requireUssd = c.getBoolean(
6992 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006993
Shuo Qian4a594052020-01-23 11:59:30 -08006994 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006995 if (requireUssd) {
6996 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6997 getSubscriptionCarrierId(subId));
6998 String newUssdCommand = "";
6999 try {
7000 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007001 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007002 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
7003 } catch (NullPointerException e) {
7004 loge("Failed to generate USSD number" + e);
7005 }
7006 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7007 mMainThreadHandler, callback, carrierXmlParser,
7008 CarrierXmlParser.SsEntry.SSAction.QUERY);
7009 final String ussdCommand = newUssdCommand;
7010 Executors.newSingleThreadExecutor().execute(() -> {
7011 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7012 });
7013 } else {
7014 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
7015 callback::accept);
7016 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
7017 }
Shuo Qian4a594052020-01-23 11:59:30 -08007018 } finally {
7019 Binder.restoreCallingIdentity(identity);
7020 }
7021 }
7022
7023 /**
Hall Liu27d24262020-09-18 19:04:59 -07007024 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007025 */
7026 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007027 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007028 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007029
7030 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7031 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus");
7032
Shuo Qian4a594052020-01-23 11:59:30 -08007033 long identity = Binder.clearCallingIdentity();
7034 try {
Hall Liu27d24262020-09-18 19:04:59 -07007035 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
7036
7037 Phone phone = getPhone(subId);
7038 if (phone == null) {
7039 try {
7040 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7041 } catch (RemoteException e) {
7042 // ignore
7043 }
7044 return;
7045 }
7046
SongFerngWang0e767992021-03-31 22:08:45 +08007047 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7048 PersistableBundle c = configManager.getConfigForSubId(subId);
7049 boolean requireUssd = c.getBoolean(
7050 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007051
SongFerngWang0e767992021-03-31 22:08:45 +08007052 if (DBG) log("getCallWaitingStatus: subId " + subId);
7053 if (requireUssd) {
7054 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7055 getSubscriptionCarrierId(subId));
7056 CarrierXmlParser.SsEntry.SSAction ssAction =
7057 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
7058 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
7059 String newUssdCommand = "";
7060 try {
7061 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007062 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007063 .makeCommand(ssAction, null);
7064 } catch (NullPointerException e) {
7065 loge("Failed to generate USSD number" + e);
7066 }
7067 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7068 mMainThreadHandler, callback, carrierXmlParser, ssAction);
7069 final String ussdCommand = newUssdCommand;
7070 Executors.newSingleThreadExecutor().execute(() -> {
7071 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7072 });
7073 } else {
7074 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
7075 FunctionalUtils.ignoreRemoteException(callback::accept));
7076
7077 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
7078 }
Shuo Qian4a594052020-01-23 11:59:30 -08007079 } finally {
7080 Binder.restoreCallingIdentity(identity);
7081 }
7082 }
7083
7084 /**
yinxub1bed742017-04-17 11:45:04 -07007085 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07007086 *
yinxub1bed742017-04-17 11:45:04 -07007087 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007088 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
7089 * location related information which will be sent if the caller already possess
7090 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07007091 * @param request contains the radio access networks with bands/channels to scan
7092 * @param messenger callback messenger for scan results or errors
7093 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07007094 * @return the id of the requested scan which can be used to stop the scan.
7095 */
7096 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007097 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
7098 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007099 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007100 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7101 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08007102 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007103 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
7104 if (!renounceFineLocationAccess) {
7105 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007106 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7107 .setCallingPackage(callingPackage)
7108 .setCallingFeatureId(callingFeatureId)
7109 .setCallingPid(Binder.getCallingPid())
7110 .setCallingUid(Binder.getCallingUid())
7111 .setMethod("requestNetworkScan")
7112 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7113 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7114 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7115 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007116 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08007117 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07007118 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
7119 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08007120 if (e != null) {
7121 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
7122 throw e;
7123 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07007124 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08007125 return TelephonyScanManager.INVALID_SCAN_ID;
7126 }
7127 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007128 }
joonhunshin4ac60942023-11-15 15:23:39 +00007129
7130 enforceTelephonyFeatureWithException(callingPackage,
7131 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan");
7132
Hall Liu912dfd32019-04-25 14:02:26 -07007133 int callingUid = Binder.getCallingUid();
7134 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07007135 final long identity = Binder.clearCallingIdentity();
7136 try {
7137 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07007138 renounceFineLocationAccess, request, messenger, binder,
7139 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07007140 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07007141 } finally {
7142 Binder.restoreCallingIdentity(identity);
7143 }
yinxu504e1392017-04-12 16:03:22 -07007144 }
7145
Hall Liub2ac8ef2019-02-28 15:56:23 -08007146 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07007147 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00007148 boolean hasCarrierPriv;
7149 final long identity = Binder.clearCallingIdentity();
7150 try {
7151 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
7152 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
7153 } finally {
7154 Binder.restoreCallingIdentity(identity);
7155 }
Hall Liu558027f2019-05-15 19:14:05 -07007156 boolean hasNetworkScanPermission =
7157 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007158 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07007159
7160 if (!hasCarrierPriv && !hasNetworkScanPermission) {
7161 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
7162 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08007163 }
7164
7165 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
7166 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08007167 if (ras.getChannels() != null && ras.getChannels().length > 0) {
7168 return new SecurityException("Specific channels must not be"
7169 + " scanned without location access.");
7170 }
7171 }
7172 }
7173
Hall Liub2ac8ef2019-02-28 15:56:23 -08007174 return null;
7175 }
7176
yinxu504e1392017-04-12 16:03:22 -07007177 /**
7178 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07007179 *
7180 * @param subId id of the subscription
7181 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07007182 */
7183 @Override
7184 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007185 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7186 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007187
Hall Liu912dfd32019-04-25 14:02:26 -07007188 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007189 final long identity = Binder.clearCallingIdentity();
7190 try {
Hall Liu912dfd32019-04-25 14:02:26 -07007191 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007192 } finally {
7193 Binder.restoreCallingIdentity(identity);
7194 }
yinxu504e1392017-04-12 16:03:22 -07007195 }
7196
7197 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08007198 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07007199 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08007200 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07007201 */
7202 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08007203 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08007204 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007205 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08007206 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007207
joonhunshin4ac60942023-11-15 15:23:39 +00007208 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7209 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask");
7210
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007211 final long identity = Binder.clearCallingIdentity();
7212 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007213 if (DBG) log("getAllowedNetworkTypesBitmask");
7214 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
7215 int networkTypesBitmask = (result != null ? result[0] : -1);
7216 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
7217 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007218 } finally {
7219 Binder.restoreCallingIdentity(identity);
7220 }
Jake Hamby7c27be32014-03-03 13:25:59 -08007221 }
7222
7223 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007224 * Get the allowed network types for certain reason.
7225 *
7226 * @param subId the id of the subscription.
7227 * @param reason the reason the allowed network type change is taking place
7228 * @return the allowed network types.
7229 */
7230 @Override
7231 public long getAllowedNetworkTypesForReason(int subId,
7232 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07007233 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007234 mApp, subId, "getAllowedNetworkTypesForReason");
joonhunshin4ac60942023-11-15 15:23:39 +00007235
7236 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7237 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesForReason");
7238
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007239 final long identity = Binder.clearCallingIdentity();
7240 try {
Jack Yu7247ac82023-03-02 23:52:10 -08007241 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007242 } finally {
7243 Binder.restoreCallingIdentity(identity);
7244 }
7245 }
7246
7247 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07007248 * Enable/Disable E-UTRA-NR Dual Connectivity
7249 * @param subId subscription id of the sim card
7250 * @param nrDualConnectivityState expected NR dual connectivity state
7251 * This can be passed following states
7252 * <ol>
7253 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
7254 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
7255 * <li>Disable NR dual connectivity and force secondary cell to be released
7256 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
7257 * </ol>
7258 * @return operation result.
7259 */
7260 @Override
7261 public int setNrDualConnectivityState(int subId,
7262 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
7263 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7264 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007265 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007266 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7267 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
7268 }
7269
Sooraj Sasindran37444802020-08-11 10:40:43 -07007270 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7271 final long identity = Binder.clearCallingIdentity();
7272 try {
7273 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
7274 nrDualConnectivityState, subId,
7275 workSource);
7276 if (DBG) log("enableNRDualConnectivity result: " + result);
7277 return result;
7278 } finally {
7279 Binder.restoreCallingIdentity(identity);
7280 }
7281 }
7282
7283 /**
7284 * Is E-UTRA-NR Dual Connectivity enabled
7285 * @return true if dual connectivity is enabled else false
7286 */
7287 @Override
7288 public boolean isNrDualConnectivityEnabled(int subId) {
7289 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007290 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07007291 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007292 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007293 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7294 return false;
7295 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07007296 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7297 final long identity = Binder.clearCallingIdentity();
7298 try {
7299 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
7300 null, subId, workSource);
7301 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
7302 return isEnabled;
7303 } finally {
7304 Binder.restoreCallingIdentity(identity);
7305 }
7306 }
7307
7308 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007309 * Set the allowed network types of the device and
7310 * provide the reason triggering the allowed network change.
7311 *
7312 * @param subId the id of the subscription.
7313 * @param reason the reason the allowed network type change is taking place
7314 * @param allowedNetworkTypes the allowed network types.
7315 * @return true on success; false on any failure.
7316 */
7317 @Override
7318 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08007319 @TelephonyManager.AllowedNetworkTypesReason int reason,
7320 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007321 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7322 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007323 // If the caller only has carrier privileges, then they should not be able to override
7324 // any network types which were set for security reasons.
7325 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
7326 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007327 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007328 throw new SecurityException(
7329 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007330 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007331 }
joonhunshin4ac60942023-11-15 15:23:39 +00007332
7333 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7334 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason");
7335
SongFerngWang3ef3e072020-12-21 16:41:52 +08007336 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007337 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08007338 return false;
7339 }
7340 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
7341 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007342 return false;
7343 }
7344
Jack Yu5b494332023-01-23 18:18:04 +00007345 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
7346 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007347
Jack Yue37dd262022-12-16 11:53:37 -08007348 Phone phone = getPhone(subId);
7349 if (phone == null) {
7350 return false;
7351 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007352
Jack Yue37dd262022-12-16 11:53:37 -08007353 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007354 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007355 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08007356 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007357
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007358 final long identity = Binder.clearCallingIdentity();
7359 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007360 Boolean success = (Boolean) sendRequest(
7361 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
7362 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
7363
7364 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
7365 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007366 } finally {
7367 Binder.restoreCallingIdentity(identity);
7368 }
7369 }
7370
7371 /**
Miaoa84611c2019-03-15 09:21:10 +08007372 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08007373 *
Miaoa84611c2019-03-15 09:21:10 +08007374 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07007375 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08007376 * @hide
7377 */
7378 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08007379 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007380 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007381
7382 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7383 PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber");
7384
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007385 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08007386 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007387 try {
Miaoa84611c2019-03-15 09:21:10 +08007388 if (phone != null) {
7389 return phone.hasMatchedTetherApnSetting();
7390 } else {
7391 return false;
7392 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007393 } finally {
7394 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007395 }
Junda Liu475951f2014-11-07 16:45:03 -08007396 }
7397
7398 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007399 * Get the user enabled state of Mobile Data.
7400 *
7401 * TODO: remove and use isUserDataEnabled.
7402 * This can't be removed now because some vendor codes
7403 * calls through ITelephony directly while they should
7404 * use TelephonyManager.
7405 *
7406 * @return true on enabled
7407 */
7408 @Override
7409 public boolean getDataEnabled(int subId) {
7410 return isUserDataEnabled(subId);
7411 }
7412
7413 /**
7414 * Get whether mobile data is enabled per user setting.
7415 *
7416 * There are other factors deciding whether mobile data is actually enabled, but they are
7417 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007418 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007419 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7420 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007421 *
7422 * @return {@code true} if data is enabled else {@code false}
7423 */
7424 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007425 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007426 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007427 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007428 try {
7429 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7430 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007431 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007432 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7433 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007434 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007435 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007436 mApp, subId, functionName);
7437
Robert Greenwalt646120a2014-05-23 11:54:03 -07007438 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007439
7440 final long identity = Binder.clearCallingIdentity();
7441 try {
Jack Yu285100e2022-12-02 22:48:35 -08007442 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007443 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7444 Phone phone = PhoneFactory.getPhone(phoneId);
7445 if (phone != null) {
7446 boolean retVal = phone.isUserDataEnabled();
7447 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7448 return retVal;
7449 } else {
7450 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7451 return false;
7452 }
7453 } finally {
7454 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007455 }
7456 }
7457
7458 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007459 * Checks if the device is capable of mobile data by considering whether whether the
7460 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7461 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007462 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007463 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007464 */
7465 @Override
7466 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007467 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007468 try {
7469 try {
7470 mApp.enforceCallingOrSelfPermission(
7471 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007472 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007473 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007474 try {
7475 mApp.enforceCallingOrSelfPermission(
7476 android.Manifest.permission.READ_PHONE_STATE,
7477 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007478 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007479 mApp.enforceCallingOrSelfPermission(
7480 permission.READ_BASIC_PHONE_STATE, functionName);
7481 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007482 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007483 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007484 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007485 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007486
joonhunshin4ac60942023-11-15 15:23:39 +00007487 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7488 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled");
7489
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007490 final long identity = Binder.clearCallingIdentity();
7491 try {
Jack Yu285100e2022-12-02 22:48:35 -08007492 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007493 Phone phone = PhoneFactory.getPhone(phoneId);
7494 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007495 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007496 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007497 return retVal;
7498 } else {
7499 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7500 return false;
7501 }
7502 } finally {
7503 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007504 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007505 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007506
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007507 /**
7508 * Check if data is enabled for a specific reason
7509 * @param subId Subscription index
7510 * @param reason the reason the data enable change is taking place
7511 * @return {@code true} if the overall data is enabled; {@code false} if not.
7512 */
7513 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007514 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007515 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007516 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007517 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007518 try {
7519 mApp.enforceCallingOrSelfPermission(
7520 android.Manifest.permission.ACCESS_NETWORK_STATE,
7521 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007522 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007523 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7524 functionName);
7525 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007526 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007527 try {
7528 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007529 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007530 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007531 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007532 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007533 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007534 }
7535
joonhunshin4ac60942023-11-15 15:23:39 +00007536 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7537 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007538
7539 final long identity = Binder.clearCallingIdentity();
7540 try {
Jack Yu285100e2022-12-02 22:48:35 -08007541 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007542 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007543 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007544 + " reason=" + reason);
7545 }
7546 Phone phone = PhoneFactory.getPhone(phoneId);
7547 if (phone != null) {
7548 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007549 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007550 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007551 return retVal;
7552 } else {
7553 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007554 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007555 + subId + " retVal=false");
7556 }
7557 return false;
7558 }
7559 } finally {
7560 Binder.restoreCallingIdentity(identity);
7561 }
7562 }
7563
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007564 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007565 public int getCarrierPrivilegeStatus(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00007566 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7567 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus");
7568
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007569 // No permission needed; this only lets the caller inspect their own status.
7570 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007571 }
Junda Liu29340342014-07-10 15:23:27 -07007572
7573 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007574 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007575 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
joonhunshin4ac60942023-11-15 15:23:39 +00007576
7577 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7578 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatusForUid");
7579
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007580 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7581 }
7582
7583 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7584 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007585 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007586 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007587 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7588 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007589 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7590 if (cpt == null) {
7591 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007592 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7593 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007594 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007595 }
7596
7597 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007598 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007599 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
joonhunshin4ac60942023-11-15 15:23:39 +00007600
7601 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7602 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage");
7603
chen xuf7e9fe82019-05-09 19:31:02 -07007604 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007605 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007606 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007607 Phone phone = getPhone(subId);
7608 if (phone == null) {
7609 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7610 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7611 }
7612 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7613 if (cpt == null) {
7614 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007615 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7616 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007617 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007618 }
7619
7620 @Override
7621 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007622 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007623
7624 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7625 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7626 "checkCarrierPrivilegesForPackageAnyPhone");
7627
Rambo Wange7209ce2022-02-23 13:41:02 -08007628 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7629 }
7630
7631 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007632 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007633 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007634 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007635 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007636 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7637 Phone phone = PhoneFactory.getPhone(phoneId);
7638 if (phone == null) {
7639 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007640 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007641 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7642 if (cpt == null) {
7643 continue;
7644 }
7645 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007646 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7647 break;
7648 }
7649 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007650 return result;
Junda Liu29340342014-07-10 15:23:27 -07007651 }
Derek Tan89e89d42014-07-08 17:00:10 -07007652
7653 @Override
Junda Liue64de782015-04-16 17:19:16 -07007654 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007655 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007656
7657 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7658 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7659 "getCarrierPackageNamesForIntentAndPhone");
7660
Rambo Wang8a247eb2022-02-08 21:11:18 +00007661 Phone phone = PhoneFactory.getPhone(phoneId);
7662 if (phone == null) {
7663 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007664 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007665 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7666 if (cpt == null) {
7667 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007668 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007669 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007670 }
7671
Amith Yamasani6e118872016-02-19 12:53:51 -08007672 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007673 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007674 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007675 Phone phone = PhoneFactory.getPhone(phoneId);
7676 if (phone == null) {
7677 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007678 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007679 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7680 if (cpt == null) {
7681 return Collections.emptyList();
7682 }
7683 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007684 }
7685
chen xuf7e9fe82019-05-09 19:31:02 -07007686 @Override
7687 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007688 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
joonhunshin4ac60942023-11-15 15:23:39 +00007689
7690 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7691 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7692 "getPackagesWithCarrierPrivilegesForAllPhones");
7693
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007694 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007695 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007696 try {
7697 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7698 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7699 }
7700 } finally {
7701 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007702 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007703 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007704 }
7705
Rambo Wang6812ffb2022-03-15 16:54:17 -07007706 @Override
7707 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7708 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7709
joonhunshin4ac60942023-11-15 15:23:39 +00007710 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7711 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7712 "getCarrierServicePackageNameForLogicalSlot");
7713
Rambo Wang6812ffb2022-03-15 16:54:17 -07007714 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7715 if (phone == null) {
7716 return null;
7717 }
7718 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7719 if (cpt == null) {
7720 return null;
7721 }
7722 return cpt.getCarrierServicePackageName();
7723 }
7724
Wink Savilleb564aae2014-10-23 10:18:09 -07007725 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007726 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007727 UiccPort port = phone == null ? null : phone.getUiccPort();
7728 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007729 return null;
7730 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007731 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007732 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007733 return null;
7734 }
7735 return iccId;
7736 }
7737
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007738 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007739 public void setCallComposerStatus(int subId, int status) {
7740 enforceModifyPermission();
7741
joonhunshin4ac60942023-11-15 15:23:39 +00007742 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7743 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus");
7744
Shuo Qiane4e11672020-12-15 22:15:33 -08007745 final long identity = Binder.clearCallingIdentity();
7746 try {
7747 Phone phone = getPhone(subId);
7748 if (phone != null) {
7749 Phone defaultPhone = phone.getImsPhone();
7750 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7751 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7752 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007753 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7754 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007755 }
7756 }
Shuo Qian284ae752020-12-22 19:10:14 -08007757 } catch (ImsException e) {
7758 throw new ServiceSpecificException(e.getCode());
7759 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007760 Binder.restoreCallingIdentity(identity);
7761 }
7762 }
7763
7764 @Override
7765 public int getCallComposerStatus(int subId) {
7766 enforceReadPrivilegedPermission("getCallComposerStatus");
7767
joonhunshin4ac60942023-11-15 15:23:39 +00007768 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7769 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus");
7770
Shuo Qiane4e11672020-12-15 22:15:33 -08007771 final long identity = Binder.clearCallingIdentity();
7772 try {
7773 Phone phone = getPhone(subId);
7774 if (phone != null) {
7775 Phone defaultPhone = phone.getImsPhone();
7776 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7777 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7778 return imsPhone.getCallComposerStatus();
7779 }
7780 }
7781 } finally {
7782 Binder.restoreCallingIdentity(identity);
7783 }
7784 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7785 }
7786
7787 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007788 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7789 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007790 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007791 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007792
joonhunshin4ac60942023-11-15 15:23:39 +00007793 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7794 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7795 "setLine1NumberForDisplayForSubscriber");
7796
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007797 final long identity = Binder.clearCallingIdentity();
7798 try {
7799 final String iccId = getIccId(subId);
7800 final Phone phone = getPhone(subId);
7801 if (phone == null) {
7802 return false;
7803 }
7804 final String subscriberId = phone.getSubscriberId();
7805
7806 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007807 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007808 + subscriberId + " to " + number);
7809 }
7810
7811 if (TextUtils.isEmpty(iccId)) {
7812 return false;
7813 }
7814
7815 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7816
7817 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7818 if (alphaTag == null) {
7819 editor.remove(alphaTagPrefKey);
7820 } else {
7821 editor.putString(alphaTagPrefKey, alphaTag);
7822 }
7823
7824 // Record both the line number and IMSI for this ICCID, since we need to
7825 // track all merged IMSIs based on line number
7826 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7827 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7828 if (number == null) {
7829 editor.remove(numberPrefKey);
7830 editor.remove(subscriberPrefKey);
7831 } else {
7832 editor.putString(numberPrefKey, number);
7833 editor.putString(subscriberPrefKey, subscriberId);
7834 }
7835
7836 editor.commit();
7837 return true;
7838 } finally {
7839 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007840 }
Derek Tan7226c842014-07-02 17:42:23 -07007841 }
7842
7843 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007844 public String getLine1NumberForDisplay(int subId, String callingPackage,
7845 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007846 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007847 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007848 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007849 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007850 return null;
7851 }
Derek Tan97ebb422014-09-05 16:55:38 -07007852
joonhunshin4ac60942023-11-15 15:23:39 +00007853 enforceTelephonyFeatureWithException(callingPackage,
7854 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay");
7855
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007856 final long identity = Binder.clearCallingIdentity();
7857 try {
7858 String iccId = getIccId(subId);
7859 if (iccId != null) {
7860 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7861 if (DBG_MERGE) {
7862 log("getLine1NumberForDisplay returning "
7863 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7864 }
7865 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007866 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007867 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7868 return null;
7869 } finally {
7870 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007871 }
Derek Tan7226c842014-07-02 17:42:23 -07007872 }
7873
7874 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007875 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7876 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007877 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007878 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007879 return null;
7880 }
Derek Tan97ebb422014-09-05 16:55:38 -07007881
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007882 final long identity = Binder.clearCallingIdentity();
7883 try {
7884 String iccId = getIccId(subId);
7885 if (iccId != null) {
7886 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7887 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7888 }
7889 return null;
7890 } finally {
7891 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007892 }
Derek Tan7226c842014-07-02 17:42:23 -07007893 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007894
7895 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007896 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7897 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007898 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7899 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007900 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007901 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007902 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007903 return null;
7904 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007905
Jordan Liub49b04b2019-05-06 14:45:15 -07007906 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7907 // the process, where TelephonyManager was instantiated.
7908 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007909 final long identity = Binder.clearCallingIdentity();
7910 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007911 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007912 final TelephonyManager tele = TelephonyManager.from(context);
7913 final SubscriptionManager sub = SubscriptionManager.from(context);
7914
7915 // Figure out what subscribers are currently active
7916 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007917
Jordan Liub49b04b2019-05-06 14:45:15 -07007918 // Only consider subs which match the current subId
7919 // This logic can be simplified. See b/131189269 for progress.
7920 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007921 activeSubscriberIds.add(tele.getSubscriberId(subId));
7922 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007923
7924 // First pass, find a number override for an active subscriber
7925 String mergeNumber = null;
7926 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7927 for (String key : prefs.keySet()) {
7928 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7929 final String subscriberId = (String) prefs.get(key);
7930 if (activeSubscriberIds.contains(subscriberId)) {
7931 final String iccId = key.substring(
7932 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7933 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7934 mergeNumber = (String) prefs.get(numberKey);
7935 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007936 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007937 + " for active subscriber " + subscriberId);
7938 }
7939 if (!TextUtils.isEmpty(mergeNumber)) {
7940 break;
7941 }
7942 }
7943 }
7944 }
7945
7946 // Shortcut when no active merged subscribers
7947 if (TextUtils.isEmpty(mergeNumber)) {
7948 return null;
7949 }
7950
7951 // Second pass, find all subscribers under that line override
7952 final ArraySet<String> result = new ArraySet<>();
7953 for (String key : prefs.keySet()) {
7954 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7955 final String number = (String) prefs.get(key);
7956 if (mergeNumber.equals(number)) {
7957 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7958 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7959 final String subscriberId = (String) prefs.get(subscriberKey);
7960 if (!TextUtils.isEmpty(subscriberId)) {
7961 result.add(subscriberId);
7962 }
7963 }
7964 }
7965 }
7966
7967 final String[] resultArray = result.toArray(new String[result.size()]);
7968 Arrays.sort(resultArray);
7969 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007970 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007971 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7972 }
7973 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007974 } finally {
7975 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007976 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007977 }
7978
7979 @Override
zoey chen38003472019-12-13 17:16:31 +08007980 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7981 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007982
joonhunshin4ac60942023-11-15 15:23:39 +00007983 enforceTelephonyFeatureWithException(callingPackage,
7984 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup");
7985
Malcolm Chen6ca97372019-07-01 16:28:21 -07007986 final long identity = Binder.clearCallingIdentity();
7987 try {
7988 final TelephonyManager telephonyManager = mApp.getSystemService(
7989 TelephonyManager.class);
7990 String subscriberId = telephonyManager.getSubscriberId(subId);
7991 if (subscriberId == null) {
7992 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007993 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007994 + subId);
7995 }
7996 return null;
7997 }
7998
Jack Yu3beaf9d2023-04-14 09:17:27 -07007999 final SubscriptionInfo info = getSubscriptionManagerService()
8000 .getSubscriptionInfo(subId);
8001 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07008002 // If it doesn't belong to any group, return just subscriberId of itself.
8003 if (groupUuid == null) {
8004 return new String[]{subscriberId};
8005 }
8006
8007 // Get all subscriberIds from the group.
8008 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07008009 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
8010 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
8011 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07008012 for (SubscriptionInfo subInfo : groupInfos) {
8013 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
8014 if (subscriberId != null) {
8015 mergedSubscriberIds.add(subscriberId);
8016 }
8017 }
8018
8019 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
8020 } finally {
8021 Binder.restoreCallingIdentity(identity);
8022
8023 }
8024 }
8025
8026 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008027 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008028 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08008029 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008030
joonhunshin4ac60942023-11-15 15:23:39 +00008031 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8032 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride");
8033
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008034 final long identity = Binder.clearCallingIdentity();
8035 try {
8036 final Phone phone = getPhone(subId);
8037 return phone == null ? false : phone.setOperatorBrandOverride(brand);
8038 } finally {
8039 Binder.restoreCallingIdentity(identity);
8040 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07008041 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05008042
8043 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008044 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008045 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
8046 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008047 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
8048 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008049
8050 final long identity = Binder.clearCallingIdentity();
8051 try {
8052 final Phone phone = getPhone(subId);
8053 if (phone == null) {
8054 return false;
8055 }
8056 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
8057 cdmaNonRoamingList);
8058 } finally {
8059 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008060 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008061 }
8062
8063 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07008064 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008065 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08008066 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008067 if (phone == null) {
8068 return raf;
8069 }
8070
Shuo Qiandee53402020-05-29 14:08:15 -07008071 try {
8072 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008073 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07008074 mApp, phone.getSubId(), "getRadioAccessFamily");
8075 } catch (SecurityException e) {
8076 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
8077 throw e;
8078 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008079
joonhunshin4ac60942023-11-15 15:23:39 +00008080 enforceTelephonyFeatureWithException(callingPackage,
8081 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily");
8082
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008083 final long identity = Binder.clearCallingIdentity();
8084 try {
chen xub97461a2018-10-26 14:17:57 -07008085 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008086 } finally {
8087 Binder.restoreCallingIdentity(identity);
8088 }
chen xub97461a2018-10-26 14:17:57 -07008089 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07008090 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008091
8092 @Override
Hall Liu82694d52020-12-11 18:22:04 -08008093 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08008094 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08008095 try {
8096 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
8097 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008098 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008099 }
8100 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008101 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008102 }
joonhunshin4ac60942023-11-15 15:23:39 +00008103
8104 enforceTelephonyFeatureWithException(callingPackage,
8105 PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture");
8106
Hall Liu82694d52020-12-11 18:22:04 -08008107 RoleManager rm = mApp.getSystemService(RoleManager.class);
8108 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
8109 if (!dialerRoleHolders.contains(callingPackage)) {
8110 throw new SecurityException("App must be the dialer role holder to"
8111 + " upload a call composer pic");
8112 }
8113
8114 Executors.newSingleThreadExecutor().execute(() -> {
8115 ByteArrayOutputStream output = new ByteArrayOutputStream(
8116 (int) TelephonyManager.getMaximumCallComposerPictureSize());
8117 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
8118 boolean readUntilEnd = false;
8119 int totalBytesRead = 0;
8120 byte[] buffer = new byte[16 * 1024];
8121 while (true) {
8122 int numRead;
8123 try {
8124 numRead = input.read(buffer);
8125 } catch (IOException e) {
8126 try {
8127 fd.checkError();
8128 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
8129 null);
8130 } catch (IOException e1) {
8131 // This means that the other side closed explicitly with an error. If this
8132 // happens, log and ignore.
8133 loge("Remote end of call composer picture pipe closed: " + e1);
8134 }
8135 break;
8136 }
8137 if (numRead == -1) {
8138 readUntilEnd = true;
8139 break;
8140 }
8141 totalBytesRead += numRead;
8142 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
8143 loge("Too many bytes read for call composer picture: " + totalBytesRead);
8144 try {
8145 input.close();
8146 } catch (IOException e) {
8147 // ignore
8148 }
8149 break;
8150 }
8151 output.write(buffer, 0, numRead);
8152 }
8153 // Generally, the remote end will close the file descriptors. The only case where we
8154 // close is above, where the picture size is too big.
8155
8156 try {
8157 fd.checkError();
8158 } catch (IOException e) {
8159 loge("Remote end for call composer closed with an error: " + e);
8160 return;
8161 }
8162
Hall Liuaa4211e2021-01-20 15:43:39 -08008163 if (!readUntilEnd) {
8164 loge("Did not finish reading entire image; aborting");
8165 return;
8166 }
Hall Liu82694d52020-12-11 18:22:04 -08008167
Hall Liuaa4211e2021-01-20 15:43:39 -08008168 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
8169 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
8170 new CallComposerPictureTransfer.Factory() {},
8171 imageData,
8172 (result) -> {
8173 if (result.first != null) {
8174 ParcelUuid parcelUuid = new ParcelUuid(result.first);
8175 Bundle outputResult = new Bundle();
8176 outputResult.putParcelable(
8177 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
8178 callback.send(TelephonyManager.CallComposerException.SUCCESS,
8179 outputResult);
8180 } else {
8181 callback.send(result.second, null);
8182 }
8183 }
8184 );
Hall Liu82694d52020-12-11 18:22:04 -08008185 });
8186 }
8187
8188 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07008189 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008190 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07008191 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008192
joonhunshin4ac60942023-11-15 15:23:39 +00008193 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8194 PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling");
8195
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008196 final long identity = Binder.clearCallingIdentity();
8197 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008198 ImsManager.getInstance(defaultPhone.getContext(),
8199 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008200 } finally {
8201 Binder.restoreCallingIdentity(identity);
8202 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008203 }
8204
8205 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008206 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008207 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008208 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
8209 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00008210 return false;
8211 }
Svet Ganovb320e182015-04-16 12:30:10 -07008212
joonhunshin4ac60942023-11-15 15:23:39 +00008213 enforceTelephonyFeatureWithException(callingPackage,
8214 PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled");
8215
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008216 final long identity = Binder.clearCallingIdentity();
8217 try {
8218 // Check the user preference and the system-level IMS setting. Even if the user has
8219 // enabled video calling, if IMS is disabled we aren't able to support video calling.
8220 // In the long run, we may instead need to check if there exists a connection service
8221 // which can support video calling.
8222 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008223 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008224 return imsManager.isVtEnabledByPlatform()
8225 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
8226 && imsManager.isVtEnabledByUser();
8227 } finally {
8228 Binder.restoreCallingIdentity(identity);
8229 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008230 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06008231
Andrew Leea1239f22015-03-02 17:44:07 -08008232 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008233 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
8234 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008235 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008236 mApp, subId, callingPackage, callingFeatureId,
8237 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008238 return false;
8239 }
8240
joonhunshin4ac60942023-11-15 15:23:39 +00008241 enforceTelephonyFeatureWithException(callingPackage,
8242 PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength");
8243
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008244 final long identity = Binder.clearCallingIdentity();
8245 try {
8246 CarrierConfigManager configManager =
8247 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008248 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008249 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
8250 } finally {
8251 Binder.restoreCallingIdentity(identity);
8252 }
Andrew Leea1239f22015-03-02 17:44:07 -08008253 }
8254
8255 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008256 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008257 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008258 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008259 return false;
8260 }
8261
joonhunshin4ac60942023-11-15 15:23:39 +00008262 enforceTelephonyFeatureWithException(callingPackage,
8263 PackageManager.FEATURE_TELEPHONY, "isWorldPhone");
8264
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008265 final long identity = Binder.clearCallingIdentity();
8266 try {
8267 CarrierConfigManager configManager =
8268 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008269 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008270 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
8271 } finally {
8272 Binder.restoreCallingIdentity(identity);
8273 }
Andrew Leea1239f22015-03-02 17:44:07 -08008274 }
8275
Andrew Lee9431b832015-03-09 18:46:45 -07008276 @Override
8277 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008278 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08008279 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07008280 }
8281
8282 @Override
8283 public boolean isHearingAidCompatibilitySupported() {
joonhunshin4ac60942023-11-15 15:23:39 +00008284 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8285 PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported");
8286
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008287 final long identity = Binder.clearCallingIdentity();
8288 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008289 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008290 } finally {
8291 Binder.restoreCallingIdentity(identity);
8292 }
Andrew Lee9431b832015-03-09 18:46:45 -07008293 }
8294
Hall Liuf6668912018-10-31 17:05:23 -07008295 /**
8296 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
8297 * support for the feature and device firmware support.
8298 *
8299 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
8300 */
8301 @Override
8302 public boolean isRttSupported(int subscriptionId) {
joonhunshin4ac60942023-11-15 15:23:39 +00008303 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8304 PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported");
8305
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008306 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008307 final Phone phone = getPhone(subscriptionId);
8308 if (phone == null) {
8309 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
8310 return false;
8311 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008312 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008313 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008314 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
joonhunshin4ac60942023-11-15 15:23:39 +00008315 boolean isDeviceSupported = (phone.getContext().getResources() != null)
8316 ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt)
8317 : false;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008318 return isCarrierSupported && isDeviceSupported;
8319 } finally {
8320 Binder.restoreCallingIdentity(identity);
8321 }
Hall Liu98187582018-01-22 19:15:32 -08008322 }
8323
Hall Liuf6668912018-10-31 17:05:23 -07008324 /**
Hall Liuf2daa022019-07-23 18:39:00 -07008325 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
8326 * RTT setting, will return true if the device and carrier both support RTT.
8327 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07008328 */
8329 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008330 final long identity = Binder.clearCallingIdentity();
8331 try {
joonhunshin4ac60942023-11-15 15:23:39 +00008332 if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) {
8333 if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
8334 return false;
8335 }
8336 }
8337
Hall Liu5bab75c2019-12-11 23:58:20 +00008338 boolean isRttSupported = isRttSupported(subscriptionId);
8339 boolean isUserRttSettingOn = Settings.Secure.getInt(
8340 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
8341 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
8342 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
8343 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008344 } finally {
8345 Binder.restoreCallingIdentity(identity);
8346 }
Hall Liu3ad5f012018-04-06 16:23:39 -07008347 }
8348
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008349 @Deprecated
8350 @Override
8351 public String getDeviceId(String callingPackage) {
8352 return getDeviceIdWithFeature(callingPackage, null);
8353 }
8354
Sanket Padawe7310cc72015-01-14 09:53:20 -08008355 /**
8356 * Returns the unique device ID of phone, for example, the IMEI for
8357 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
8358 *
8359 * <p>Requires Permission:
8360 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
8361 */
8362 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008363 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07008364 try {
8365 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
8366 } catch (SecurityException se) {
8367 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
8368 throw new SecurityException("Package " + callingPackage + " does not belong to "
8369 + Binder.getCallingUid());
8370 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008371 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008372 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008373 return null;
8374 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008375 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008376 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008377 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008378 return null;
8379 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008380
8381 final long identity = Binder.clearCallingIdentity();
8382 try {
8383 return phone.getDeviceId();
8384 } finally {
8385 Binder.restoreCallingIdentity(identity);
8386 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008387 }
8388
Ping Sunc67b7c22016-03-02 19:16:45 +08008389 /**
8390 * {@hide}
8391 * Returns the IMS Registration Status on a particular subid
8392 *
8393 * @param subId
8394 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008395 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008396 Phone phone = getPhone(subId);
8397 if (phone != null) {
8398 return phone.isImsRegistered();
8399 } else {
8400 return false;
8401 }
8402 }
8403
Santos Cordon7a1885b2015-02-03 11:15:19 -08008404 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008405 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008406 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008407 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008408 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008409 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8410 }
8411 final long identity = Binder.clearCallingIdentity();
8412 try {
8413 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8414 } finally {
8415 Binder.restoreCallingIdentity(identity);
8416 }
8417 }
8418
8419 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008420 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008421 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008422 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008423 mApp,
8424 subscriptionId,
8425 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
8426 + subscriptionId);
joonhunshin4ac60942023-11-15 15:23:39 +00008427
8428 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8429 PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId");
8430
Tyler Gunnf70ed162019-04-03 15:28:53 -07008431 final long identity = Binder.clearCallingIdentity();
8432 try {
8433 Phone phone = getPhone(subscriptionId);
8434 if (phone == null) {
8435 return null;
8436 }
8437 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8438 } finally {
8439 Binder.restoreCallingIdentity(identity);
8440 }
8441 }
8442
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008443 /**
8444 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008445 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008446 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008447 final long identity = Binder.clearCallingIdentity();
8448 try {
8449 Phone phone = getPhone(subId);
8450 if (phone != null) {
8451 return phone.isWifiCallingEnabled();
8452 } else {
8453 return false;
8454 }
8455 } finally {
8456 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008457 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008458 }
8459
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008460 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008461 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008462 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008463 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008464 final long identity = Binder.clearCallingIdentity();
8465 try {
8466 Phone phone = getPhone(subId);
8467 if (phone != null) {
8468 return phone.isVideoEnabled();
8469 } else {
8470 return false;
8471 }
8472 } finally {
8473 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008474 }
8475 }
8476
8477 /**
8478 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8479 * defined in {@link ImsRegistrationImplBase}.
8480 */
8481 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008482 final long identity = Binder.clearCallingIdentity();
8483 try {
8484 Phone phone = getPhone(subId);
8485 if (phone != null) {
8486 return phone.getImsRegistrationTech();
8487 } else {
8488 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8489 }
8490 } finally {
8491 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008492 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008493 }
8494
Stuart Scott8eef64f2015-04-08 15:13:54 -07008495 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008496 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008497 enforceSettingsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008498
8499 enforceTelephonyFeatureWithException(callingPackage,
8500 PackageManager.FEATURE_TELEPHONY, "factoryReset");
8501
Stuart Scott981d8582015-04-21 14:09:50 -07008502 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8503 return;
8504 }
Kai Shif70f46f2021-03-03 13:59:46 -08008505 Phone defaultPhone = getDefaultPhone();
8506 if (defaultPhone != null) {
8507 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8508 mApp, getDefaultPhone().getSubId(), "factoryReset");
8509 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008510 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008511
Svet Ganovcc087f82015-05-12 20:35:54 -07008512 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008513 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8514 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008515 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008516 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008517 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008518 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008519 cleanUpAllowedNetworkTypes(phone, subId);
Rambo Wang71f6aa62024-02-23 20:16:22 +00008520 setDataRoamingEnabled(subId, phone == null ? false
8521 : phone.getDataSettingsManager().isDefaultDataRoamingEnabled());
Jordan Liu857e73a2021-03-05 16:24:04 -08008522 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008523 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008524 // There has been issues when Sms raw table somehow stores orphan
8525 // fragments. They lead to garbled message when new fragments come
8526 // in and combined with those stale ones. In case this happens again,
8527 // user can reset all network settings which will clean up this table.
8528 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008529 // Clean up IMS settings as well here.
8530 int slotId = getSlotIndex(subId);
8531 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
8532 ImsManager.getInstance(mApp, slotId).factoryReset();
8533 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008534
Kai Shif70f46f2021-03-03 13:59:46 -08008535 if (defaultPhone == null) {
8536 return;
8537 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008538 // Erase modem config if erase modem on network setting is enabled.
8539 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8540 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8541 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008542 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008543 }
Kai Shif70f46f2021-03-03 13:59:46 -08008544
8545 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008546 } finally {
8547 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008548 }
8549 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008550
SongFerngWangfd89b102021-05-27 22:44:54 +08008551 @VisibleForTesting
8552 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8553 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8554 return;
8555 }
8556 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8557 RILConstants.PREFERRED_NETWORK_MODE);
8558 SubscriptionManager.setSubscriptionProperty(subId,
8559 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8560 "user=" + defaultNetworkType);
8561 phone.loadAllowedNetworksFromSubscriptionDatabase();
8562 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8563 defaultNetworkType, null);
8564 }
8565
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008566 private void cleanUpSmsRawTable(Context context) {
8567 ContentResolver resolver = context.getContentResolver();
8568 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8569 resolver.delete(uri, null, null);
8570 }
8571
Narayan Kamath1c496c22015-04-16 14:40:19 +01008572 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008573 public String getSimLocaleForSubscriber(int subId) {
8574 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
joonhunshin4ac60942023-11-15 15:23:39 +00008575
8576 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8577 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber");
8578
chen xu5d3637b2019-01-21 23:31:38 -08008579 final Phone phone = getPhone(subId);
8580 if (phone == null) {
8581 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008582 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008583 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008584 final long identity = Binder.clearCallingIdentity();
8585 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008586 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
8587 phone.getContext().getOpPackageName(),
8588 phone.getContext().getAttributionTag());
8589 if (info == null) {
8590 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8591 return null;
chen xu6291c472019-02-04 12:55:53 -08008592 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008593 // Try and fetch the locale from the carrier properties or from the SIM language
8594 // preferences (EF-PL and EF-LI)...
8595 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008596 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008597 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8598 if (localeFromDefaultSim != null) {
8599 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8600 if (DBG) log("Using locale from subId: " + subId + " locale: "
8601 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008602 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008603 } else {
8604 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008605 }
8606 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008607
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008608 // The SIM language preferences only store a language (e.g. fr = French), not an
8609 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8610 // the SIM and carrier preferences does not include a country we add the country
8611 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008612 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008613 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008614 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008615 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008616 }
8617
8618 if (DBG) log("No locale found - returning null");
8619 return null;
8620 } finally {
8621 Binder.restoreCallingIdentity(identity);
8622 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008623 }
8624
tom hsu0b59d292022-09-29 23:49:21 +08008625 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008626 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008627 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008628 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008629 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008630 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8631 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008632 Locale.forLanguageTag(localeTag).getCountry())) {
8633 return localeTag;
8634 }
8635 }
8636 return inputLocale.toLanguageTag();
8637 }
8638
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008639 /**
8640 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8641 */
8642 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008643 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Ling Ma9fa67412023-11-13 14:13:19 -08008644 mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/);
Narayan Kamath1c496c22015-04-16 14:40:19 +01008645 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008646
Gary Jian3aa9a762022-01-24 16:41:19 +08008647 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8648 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008649
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008650 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008651 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8652 * representing the state of the modem.
8653 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008654 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8655 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008656 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008657 */
8658 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008659 public void requestModemActivityInfo(ResultReceiver result) {
8660 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008661
8662 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8663 PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo");
8664
vagdeviaf9a5b92018-08-15 16:01:53 -07008665 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008666
8667 final long identity = Binder.clearCallingIdentity();
8668 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008669 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008670 } finally {
8671 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008672 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008673 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008674
Gary Jian76280a42022-12-07 16:18:33 +08008675 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008676 // less than total activity duration.
8677 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8678 if (info == null) {
8679 return false;
8680 }
8681 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008682 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008683 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8684
Hall Liu49656c02020-10-09 19:00:11 -07008685 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8686
Siddharth Rayb8114062018-06-17 15:02:38 -07008687 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008688 && (info.getSleepTimeMillis() <= activityDurationMs)
8689 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008690 }
8691
Gary Jian3aa9a762022-01-24 16:41:19 +08008692 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8693 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8694 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8695 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8696
8697 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8698 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8699 }
8700
8701 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8702 mLastModemActivityInfo.setReceiveTimeMillis(
8703 rat,
8704 freq,
8705 info.getReceiveTimeMillis(rat, freq)
8706 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8707 }
8708
8709 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8710 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8711 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8712 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8713
8714 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8715 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8716 }
8717 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8718 mLastModemActivityInfo.setReceiveTimeMillis(
8719 rat,
8720 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8721 }
8722
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008723 /**
8724 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8725 * @param info recent ModemActivityInfo
8726 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008727 private void mergeModemActivityInfo(ModemActivityInfo info) {
8728 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008729 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008730 boolean matched;
8731 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8732 matched = false;
8733 int rat = info.getSpecificInfoRat(i);
8734 int freq = info.getSpecificInfoFrequencyRange(i);
8735 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8736 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8737 //if it already exists
8738 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8739 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8740 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8741 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8742 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8743 updateLastModemActivityInfo(info, rat, freq);
8744 matched = true;
8745 }
8746 } else {
8747 updateLastModemActivityInfo(info, rat);
8748 matched = true;
8749 }
8750 }
8751 }
8752
8753 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008754 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008755 new ActivityStatsTechSpecificInfo(
8756 rat,
8757 freq,
8758 info.getTransmitTimeMillis(rat, freq),
8759 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008760 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008761 }
8762 }
8763 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8764 mLastModemActivitySpecificInfo =
8765 new ActivityStatsTechSpecificInfo[merged.size()];
8766 merged.toArray(mLastModemActivitySpecificInfo);
8767
8768 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8769 mLastModemActivityInfo.setSleepTimeMillis(
8770 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008771 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008772 mLastModemActivityInfo.setIdleTimeMillis(
8773 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008774 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008775
8776 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008777 new ModemActivityInfo(
8778 mLastModemActivityInfo.getTimestampMillis(),
8779 mLastModemActivityInfo.getSleepTimeMillis(),
8780 mLastModemActivityInfo.getIdleTimeMillis(),
8781 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008782 }
8783
8784 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8785 ActivityStatsTechSpecificInfo[] info) {
8786 int infoSize = info.length;
8787 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8788 for (int i = 0; i < infoSize; i++) {
8789 ret[i] = new ActivityStatsTechSpecificInfo(
8790 info[i].getRat(), info[i].getFrequencyRange(),
8791 info[i].getTransmitTimeMillis(),
8792 (int) info[i].getReceiveTimeMillis());
8793 }
8794 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008795 }
8796
Jack Yu85bd38a2015-11-09 11:34:32 -08008797 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008798 * Returns the service state information on specified subscription.
8799 */
8800 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008801 public ServiceState getServiceStateForSubscriber(int subId,
8802 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8803 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008804 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008805 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008806 return null;
8807 }
8808
joonhunshin4ac60942023-11-15 15:23:39 +00008809 enforceTelephonyFeatureWithException(callingPackage,
8810 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber");
8811
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008812 boolean hasFinePermission = false;
8813 boolean hasCoarsePermission = false;
8814 if (!renounceFineLocationAccess) {
8815 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8816 LocationAccessPolicy.checkLocationPermission(mApp,
8817 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8818 .setCallingPackage(callingPackage)
8819 .setCallingFeatureId(callingFeatureId)
8820 .setCallingPid(Binder.getCallingPid())
8821 .setCallingUid(Binder.getCallingUid())
8822 .setMethod("getServiceStateForSubscriber")
8823 .setLogAsInfo(true)
8824 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8825 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8826 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8827 .build());
8828 hasFinePermission =
8829 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8830 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008831
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008832 if (!renounceCoarseLocationAccess) {
8833 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8834 LocationAccessPolicy.checkLocationPermission(mApp,
8835 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8836 .setCallingPackage(callingPackage)
8837 .setCallingFeatureId(callingFeatureId)
8838 .setCallingPid(Binder.getCallingPid())
8839 .setCallingUid(Binder.getCallingUid())
8840 .setMethod("getServiceStateForSubscriber")
8841 .setLogAsInfo(true)
8842 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8843 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8844 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8845 .build());
8846 hasCoarsePermission =
8847 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8848 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008849
Jack Yu479f40e2020-10-27 21:29:25 -07008850 final Phone phone = getPhone(subId);
8851 if (phone == null) {
8852 return null;
8853 }
8854
Jordan Liu0f2bc442020-11-18 16:47:37 -08008855 final long identity = Binder.clearCallingIdentity();
8856
Jack Yu479f40e2020-10-27 21:29:25 -07008857 boolean isCallingPackageDataService = phone.getDataServicePackages()
8858 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008859 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008860 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu3beaf9d2023-04-14 09:17:27 -07008861 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8862 .getSubscriptionInfoInternal(subId);
8863 if (subInfo == null || !subInfo.isActive()) {
8864 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8865 + "subId=" + subId);
8866 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008867 }
8868
Hall Liuf19c44f2018-11-27 14:38:17 -08008869 ServiceState ss = phone.getServiceState();
8870
8871 // Scrub out the location info in ServiceState depending on what level of access
8872 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008873 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008874 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8875 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008876 } finally {
8877 Binder.restoreCallingIdentity(identity);
8878 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008879 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008880
8881 /**
8882 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8883 *
8884 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8885 * voicemail ringtone.
8886 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8887 * PhoneAccount.
8888 */
8889 @Override
8890 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008891 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8892 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri");
8893
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008894 final long identity = Binder.clearCallingIdentity();
8895 try {
8896 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8897 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008898 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008899 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008900
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008901 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8902 } finally {
8903 Binder.restoreCallingIdentity(identity);
8904 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008905 }
8906
8907 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008908 * Sets the per-account voicemail ringtone.
8909 *
8910 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8911 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8912 *
8913 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8914 * voicemail ringtone.
8915 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8916 * PhoneAccount.
8917 */
8918 @Override
8919 public void setVoicemailRingtoneUri(String callingPackage,
8920 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008921 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008922 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008923 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8924 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008925 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8926 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8927 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008928 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008929
joonhunshin4ac60942023-11-15 15:23:39 +00008930 enforceTelephonyFeatureWithException(callingPackage,
8931 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri");
8932
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008933 final long identity = Binder.clearCallingIdentity();
8934 try {
8935 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8936 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008937 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008938 }
8939 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8940 } finally {
8941 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008942 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008943 }
8944
8945 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008946 * Returns whether vibration is set for voicemail notification in Phone settings.
8947 *
8948 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8949 * voicemail vibration setting.
8950 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8951 */
8952 @Override
8953 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008954 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8955 PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled");
8956
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008957 final long identity = Binder.clearCallingIdentity();
8958 try {
8959 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8960 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008961 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008962 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008963
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008964 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8965 } finally {
8966 Binder.restoreCallingIdentity(identity);
8967 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008968 }
8969
Youhan Wange64578a2016-05-02 15:32:42 -07008970 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008971 * Sets the per-account voicemail vibration.
8972 *
8973 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8974 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8975 *
8976 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8977 * voicemail vibration setting.
8978 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8979 * specific PhoneAccount.
8980 */
8981 @Override
8982 public void setVoicemailVibrationEnabled(String callingPackage,
8983 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008984 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008985 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008986 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8987 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008988 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8989 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8990 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008991 }
8992
joonhunshin4ac60942023-11-15 15:23:39 +00008993 enforceTelephonyFeatureWithException(callingPackage,
8994 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled");
8995
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008996 final long identity = Binder.clearCallingIdentity();
8997 try {
8998 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8999 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009000 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009001 }
9002 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
9003 } finally {
9004 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009005 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009006 }
9007
9008 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009009 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
9010 *
9011 * @throws SecurityException if the caller does not have the required permission
9012 */
arunvoddud7401012022-12-15 16:08:12 +00009013 @VisibleForTesting
9014 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07009015 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07009016 message);
Youhan Wange64578a2016-05-02 15:32:42 -07009017 }
9018
9019 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009020 * Make sure either called from same process as self (phone) or IPC caller has send SMS
9021 * permission.
9022 *
9023 * @throws SecurityException if the caller does not have the required permission
9024 */
9025 private void enforceSendSmsPermission() {
9026 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
9027 }
9028
9029 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00009030 * Make sure either called from same process as self (phone) or IPC caller has interact across
9031 * users permission.
9032 *
9033 * @throws SecurityException if the caller does not have the required permission
9034 */
9035 private void enforceInteractAcrossUsersPermission(String message) {
9036 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
9037 }
9038
9039 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009040 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009041 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009042 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009043 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009044 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009045 final long identity = Binder.clearCallingIdentity();
9046 try {
9047 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009048 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009049 if (componentName == null) {
9050 throw new SecurityException(
9051 "Caller not current active visual voicemail package[null]");
9052 }
9053 String vvmPackage = componentName.getPackageName();
9054 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00009055 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009056 }
9057 } finally {
9058 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009059 }
9060 }
9061
9062 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009063 * Return the application ID for the app type.
9064 *
9065 * @param subId the subscription ID that this request applies to.
9066 * @param appType the uicc app type.
9067 * @return Application ID for specificied app type, or null if no uicc.
9068 */
9069 @Override
9070 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009071 enforceReadPrivilegedPermission("getAidForAppType");
joonhunshin4ac60942023-11-15 15:23:39 +00009072
9073 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9074 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType");
9075
Youhan Wange64578a2016-05-02 15:32:42 -07009076 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009077
9078 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07009079 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009080 if (phone == null) {
9081 return null;
9082 }
9083 String aid = null;
9084 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009085 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009086 .getApplicationByType(appType).getAid();
9087 } catch (Exception e) {
9088 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
9089 }
9090 return aid;
9091 } finally {
9092 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07009093 }
Youhan Wange64578a2016-05-02 15:32:42 -07009094 }
9095
Youhan Wang4001d252016-05-11 10:29:41 -07009096 /**
9097 * Return the Electronic Serial Number.
9098 *
9099 * @param subId the subscription ID that this request applies to.
9100 * @return ESN or null if error.
9101 */
9102 @Override
9103 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009104 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07009105 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009106
9107 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07009108 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009109 if (phone == null) {
9110 return null;
9111 }
9112 String esn = null;
9113 try {
9114 esn = phone.getEsn();
9115 } catch (Exception e) {
9116 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
9117 }
9118 return esn;
9119 } finally {
9120 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07009121 }
Youhan Wang4001d252016-05-11 10:29:41 -07009122 }
9123
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009124 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009125 * Return the Preferred Roaming List Version.
9126 *
9127 * @param subId the subscription ID that this request applies to.
9128 * @return PRLVersion or null if error.
9129 */
9130 @Override
9131 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009132 enforceReadPrivilegedPermission("getCdmaPrlVersion");
joonhunshin4ac60942023-11-15 15:23:39 +00009133
9134 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9135 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion");
9136
Youhan Wang66ad5d72016-07-18 17:56:58 -07009137 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009138
9139 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009140 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009141 if (phone == null) {
9142 return null;
9143 }
9144 String cdmaPrlVersion = null;
9145 try {
9146 cdmaPrlVersion = phone.getCdmaPrlVersion();
9147 } catch (Exception e) {
9148 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9149 }
9150 return cdmaPrlVersion;
9151 } finally {
9152 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009153 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009154 }
9155
9156 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009157 * Get snapshot of Telephony histograms
9158 * @return List of Telephony histograms
9159 * @hide
9160 */
9161 @Override
9162 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009163 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9164 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009165
9166 final long identity = Binder.clearCallingIdentity();
9167 try {
9168 return RIL.getTelephonyRILTimingHistograms();
9169 } finally {
9170 Binder.restoreCallingIdentity(identity);
9171 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009172 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009173
9174 /**
9175 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009176 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9177 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009178 * Require system privileges. In the future we may add this to carrier APIs.
9179 *
Michele Berionne482f8202018-11-27 18:57:59 -08009180 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009181 */
9182 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009183 @TelephonyManager.SetCarrierRestrictionResult
9184 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009185 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009186
9187 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9188 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers");
9189
vagdeviaf9a5b92018-08-15 16:01:53 -07009190 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009191
Michele Berionne482f8202018-11-27 18:57:59 -08009192 if (carrierRestrictionRules == null) {
9193 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009194 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009195
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009196 final long identity = Binder.clearCallingIdentity();
9197 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009198 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009199 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009200 } finally {
9201 Binder.restoreCallingIdentity(identity);
9202 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009203 }
9204
9205 /**
9206 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009207 * Get the allowed carrier list and the excluded carrier list, including the priority between
9208 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009209 * Require system privileges. In the future we may add this to carrier APIs.
9210 *
Michele Berionne482f8202018-11-27 18:57:59 -08009211 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009212 */
9213 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009214 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009215 enforceReadPrivilegedPermission("getAllowedCarriers");
joonhunshin4ac60942023-11-15 15:23:39 +00009216
9217 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9218 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers");
9219
vagdeviaf9a5b92018-08-15 16:01:53 -07009220 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009221
9222 final long identity = Binder.clearCallingIdentity();
9223 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009224 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9225 if (response instanceof CarrierRestrictionRules) {
9226 return (CarrierRestrictionRules) response;
9227 }
9228 // Response is an Exception of some kind,
9229 // which is signalled to the user as a NULL retval
9230 return null;
9231 } catch (Exception e) {
9232 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9233 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009234 } finally {
9235 Binder.restoreCallingIdentity(identity);
9236 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009237 }
9238
fionaxu59545b42016-05-25 15:53:37 -07009239 /**
arunvoddud7401012022-12-15 16:08:12 +00009240 * Fetches the carrier restriction status of the device and sends the status to the caller
9241 * through the callback.
9242 *
9243 * @param callback The callback that will be used to send the result.
9244 * @throws SecurityException if the caller does not have the required permission/privileges or
9245 * the caller is not allowlisted.
9246 */
9247 @Override
9248 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
9249 enforceReadPermission("getCarrierRestrictionStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00009250
9251 enforceTelephonyFeatureWithException(packageName,
9252 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierRestrictionStatus");
9253
Steve Statia28b7cb32024-03-11 23:58:50 +00009254 Set<Integer> carrierIds = validateCallerAndGetCarrierIds(packageName);
9255 if (carrierIds.contains(CarrierAllowListInfo.INVALID_CARRIER_ID)) {
arunvoddud7401012022-12-15 16:08:12 +00009256 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9257 throw new SecurityException("Not an authorized caller");
9258 }
9259 final long identity = Binder.clearCallingIdentity();
9260 try {
9261 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
Steve Statia28b7cb32024-03-11 23:58:50 +00009262 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierIds);
arunvoddud7401012022-12-15 16:08:12 +00009263 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9264 } finally {
9265 Binder.restoreCallingIdentity(identity);
9266 }
9267 }
9268
arunvoddu567f2b42023-04-25 17:22:00 +00009269 @Override
9270 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
9271 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
9272 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9273 return allowListInfo.getShaIdList(pkgName, carrierId);
9274 }
9275
arunvoddud7401012022-12-15 16:08:12 +00009276 @VisibleForTesting
Steve Statia28b7cb32024-03-11 23:58:50 +00009277 public Set<Integer> validateCallerAndGetCarrierIds(String packageName) {
arunvoddud7401012022-12-15 16:08:12 +00009278 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
Steve Statia28b7cb32024-03-11 23:58:50 +00009279 return allowListInfo.validateCallerAndGetCarrierIds(packageName);
arunvoddud7401012022-12-15 16:08:12 +00009280 }
9281
9282 /**
fionaxu59545b42016-05-25 15:53:37 -07009283 * Action set from carrier signalling broadcast receivers to enable/disable radio
9284 * @param subId the subscription ID that this action applies to.
9285 * @param enabled control enable or disable radio.
9286 * {@hide}
9287 */
9288 @Override
9289 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9290 enforceModifyPermission();
9291 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009292
9293 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009294 if (phone == null) {
9295 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9296 return;
9297 }
9298 try {
9299 phone.carrierActionSetRadioEnabled(enabled);
9300 } catch (Exception e) {
9301 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009302 } finally {
9303 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009304 }
9305 }
9306
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009307 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009308 * Enable or disable Voice over NR (VoNR)
9309 * @param subId the subscription ID that this action applies to.
9310 * @param enabled enable or disable VoNR.
9311 * @return operation result.
9312 */
9313 @Override
9314 public int setVoNrEnabled(int subId, boolean enabled) {
9315 enforceModifyPermission();
9316 final Phone phone = getPhone(subId);
9317
9318 final long identity = Binder.clearCallingIdentity();
9319 if (phone == null) {
9320 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9321 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9322 }
9323
9324 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9325 try {
9326 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9327 workSource);
9328 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009329
9330 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9331 if (DBG) {
9332 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9333 }
9334 SubscriptionManager.setSubscriptionProperty(
9335 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9336 (enabled ? "1" : "0"));
9337 }
9338
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009339 return result;
9340 } finally {
9341 Binder.restoreCallingIdentity(identity);
9342 }
9343 }
9344
9345 /**
9346 * Is voice over NR enabled
9347 * @return true if VoNR is enabled else false
9348 */
9349 @Override
9350 public boolean isVoNrEnabled(int subId) {
9351 enforceReadPrivilegedPermission("isVoNrEnabled");
9352 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9353 final long identity = Binder.clearCallingIdentity();
9354 try {
9355 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9356 null, subId, workSource);
9357 if (DBG) log("isVoNrEnabled: " + isEnabled);
9358 return isEnabled;
9359 } finally {
9360 Binder.restoreCallingIdentity(identity);
9361 }
9362 }
9363
9364 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009365 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9366 * network status based on which carrier apps could apply actions accordingly,
9367 * enable/disable default url handler for example.
9368 *
9369 * @param subId the subscription ID that this action applies to.
9370 * @param report control start/stop reporting the default network status.
9371 * {@hide}
9372 */
9373 @Override
9374 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9375 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009376
9377 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9378 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
9379 "carrierActionReportDefaultNetworkStatus");
9380
fionaxu8da9cb12017-05-23 15:02:46 -07009381 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009382
9383 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009384 if (phone == null) {
9385 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9386 return;
9387 }
9388 try {
9389 phone.carrierActionReportDefaultNetworkStatus(report);
9390 } catch (Exception e) {
9391 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009392 } finally {
9393 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009394 }
9395 }
9396
9397 /**
fionaxud9622282017-07-17 17:51:30 -07009398 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9399 * @param subId the subscription ID that this action applies to.
9400 * {@hide}
9401 */
9402 @Override
9403 public void carrierActionResetAll(int subId) {
9404 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009405
9406 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9407 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll");
9408
fionaxud9622282017-07-17 17:51:30 -07009409 final Phone phone = getPhone(subId);
9410 if (phone == null) {
9411 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9412 return;
9413 }
9414 try {
9415 phone.carrierActionResetAll();
9416 } catch (Exception e) {
9417 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9418 }
9419 }
9420
9421 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009422 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9423 * bug report is being generated.
9424 */
9425 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009426 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009427 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9428 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009429 writer.println("Permission Denial: can't dump Phone from pid="
9430 + Binder.getCallingPid()
9431 + ", uid=" + Binder.getCallingUid()
9432 + "without permission "
9433 + android.Manifest.permission.DUMP);
9434 return;
9435 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009436 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009437 }
Jack Yueb89b242016-06-22 13:27:47 -07009438
Brad Ebingerdac2f002018-04-03 15:17:52 -07009439 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009440 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9441 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9442 @NonNull String[] args) {
9443 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9444 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009445 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009446 }
9447
Jack Yueb89b242016-06-22 13:27:47 -07009448 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009449 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009450 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009451 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009452 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009453 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009454 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009455 */
9456 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009457 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009458 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009459 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9460 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9461 try {
9462 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009463 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009464 } catch (SecurityException se) {
9465 enforceModifyPermission();
9466 }
9467 } else {
9468 enforceModifyPermission();
9469 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009470
joonhunshin4ac60942023-11-15 15:23:39 +00009471 enforceTelephonyFeatureWithException(callingPackage,
9472 PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason");
9473
Nate Myren116695d2024-02-09 09:36:01 -08009474 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009475 final long identity = Binder.clearCallingIdentity();
9476 try {
Nate Myren116695d2024-02-09 09:36:01 -08009477 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
9478 && null != callingPackage && opEnableMobileDataByUser()) {
Nate Myren453c3472024-03-13 11:28:11 -07009479 mAppOps.noteOpNoThrow(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER,
Nate Myren116695d2024-02-09 09:36:01 -08009480 callingUid, callingPackage, null, null);
9481 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009482 Phone phone = getPhone(subId);
9483 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009484 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9485 phone.carrierActionSetMeteredApnsEnabled(enabled);
9486 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07009487 phone.getDataSettingsManager().setDataEnabled(
9488 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009489 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009490 }
9491 } finally {
9492 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009493 }
9494 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009495
9496 /**
9497 * Get Client request stats
9498 * @return List of Client Request Stats
9499 * @hide
9500 */
9501 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009502 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9503 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009504 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009505 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009506 return null;
9507 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009508 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009509
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009510 final long identity = Binder.clearCallingIdentity();
9511 try {
9512 if (phone != null) {
9513 return phone.getClientRequestStats();
9514 }
9515
9516 return null;
9517 } finally {
9518 Binder.restoreCallingIdentity(identity);
9519 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009520 }
9521
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009522 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009523 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009524 if (uid == Process.ROOT_UID && packageName == null) {
9525 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9526 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9527 // exception. ROOT_UID seems not to have a valid package name returned by
9528 // PackageManager, so just fake it here to avoid issues when running telephony shell
9529 // commands that plumb through the RIL as root, like so:
9530 // $ adb root
9531 // $ adb shell cmd phone ...
9532 packageName = "root";
9533 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009534 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009535 }
Jack Yueb4124c2017-02-16 15:32:43 -08009536
9537 /**
Grace Chen70990072017-03-24 17:21:30 -07009538 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009539 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009540 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009541 * @param state State of SIM (power down, power up, pass through)
9542 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9543 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9544 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009545 *
9546 **/
9547 @Override
Grace Chen70990072017-03-24 17:21:30 -07009548 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009549 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009550
9551 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9552 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot");
9553
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009554 Phone phone = PhoneFactory.getPhone(slotIndex);
9555
vagdeviaf9a5b92018-08-15 16:01:53 -07009556 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9557
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009558 final long identity = Binder.clearCallingIdentity();
9559 try {
9560 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009561 phone.setSimPowerState(state, null, workSource);
9562 }
9563 } finally {
9564 Binder.restoreCallingIdentity(identity);
9565 }
9566 }
9567
9568 /**
9569 * Set SIM card power state.
9570 *
9571 * @param slotIndex SIM slot id.
9572 * @param state State of SIM (power down, power up, pass through)
9573 * @param callback callback to trigger after success or failure
9574 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9575 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9576 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9577 *
9578 **/
9579 @Override
9580 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9581 IIntegerConsumer callback) {
9582 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009583
9584 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9585 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
9586 "setSimPowerStateForSlotWithCallback");
9587
Jordan Liu109698e2020-11-24 14:50:34 -08009588 Phone phone = PhoneFactory.getPhone(slotIndex);
9589
9590 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9591
9592 final long identity = Binder.clearCallingIdentity();
9593 try {
9594 if (phone != null) {
9595 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9596 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009597 }
9598 } finally {
9599 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009600 }
9601 }
Shuo Qiandd210312017-04-12 22:11:33 +00009602
Tyler Gunn65d45c22017-06-05 11:22:26 -07009603 private boolean isUssdApiAllowed(int subId) {
9604 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009605 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009606 if (configManager == null) {
9607 return false;
9608 }
9609 PersistableBundle pb = configManager.getConfigForSubId(subId);
9610 if (pb == null) {
9611 return false;
9612 }
9613 return pb.getBoolean(
9614 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9615 }
9616
Shuo Qiandd210312017-04-12 22:11:33 +00009617 /**
Ling Mac28f0212023-03-24 16:07:15 -07009618 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00009619 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07009620 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00009621 */
goneil9c5f4872017-12-05 14:07:56 -08009622 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009623 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009624 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
joonhunshin4ac60942023-11-15 15:23:39 +00009625
9626 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9627 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode");
9628
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009629 final long identity = Binder.clearCallingIdentity();
9630 try {
Ling Mac28f0212023-03-24 16:07:15 -07009631 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009632 } finally {
9633 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009634 }
9635 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009636
9637 /**
9638 * Get the current signal strength information for the given subscription.
9639 * Because this information is not updated when the device is in a low power state
9640 * it should not be relied-upon to be current.
9641 * @param subId Subscription index
9642 * @return the most recent cached signal strength info from the modem
9643 */
9644 @Override
9645 public SignalStrength getSignalStrength(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00009646 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9647 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength");
9648
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009649 final long identity = Binder.clearCallingIdentity();
9650 try {
9651 Phone p = getPhone(subId);
9652 if (p == null) {
9653 return null;
9654 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009655
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009656 return p.getSignalStrength();
9657 } finally {
9658 Binder.restoreCallingIdentity(identity);
9659 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009660 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009661
Pengquan Meng77b7f132018-08-22 14:49:57 -07009662 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009663 * Get the current modem radio state for the given slot.
9664 * @param slotIndex slot index.
9665 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009666 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009667 * @return the current radio power state from the modem
9668 */
9669 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009670 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009671 Phone phone = PhoneFactory.getPhone(slotIndex);
9672 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009673 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9674 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009675 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9676 }
9677
joonhunshin4ac60942023-11-15 15:23:39 +00009678 enforceTelephonyFeatureWithException(callingPackage,
9679 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState");
9680
Chen Xuf792fd62018-10-17 17:54:36 +00009681 final long identity = Binder.clearCallingIdentity();
9682 try {
9683 return phone.getRadioPowerState();
9684 } finally {
9685 Binder.restoreCallingIdentity(identity);
9686 }
9687 }
9688 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9689 }
9690
9691 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009692 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9693 *
9694 * <p>Requires one of the following permissions:
9695 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009696 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009697 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9698 * privileges.
9699 *
9700 * @param subId subscription id
9701 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9702 * {@code false}.
9703 */
9704 @Override
9705 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009706 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009707 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009708 try {
9709 mApp.enforceCallingOrSelfPermission(
9710 android.Manifest.permission.ACCESS_NETWORK_STATE,
9711 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009712 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009713 mApp.enforceCallingOrSelfPermission(
9714 permission.READ_BASIC_PHONE_STATE, functionName);
9715 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009716 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009717 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009718 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009719 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009720
joonhunshin4ac60942023-11-15 15:23:39 +00009721 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9722 PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled");
9723
Pengquan Menga1bb6272018-09-06 09:59:22 -07009724 boolean isEnabled = false;
9725 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009726 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009727 Phone phone = getPhone(subId);
9728 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009729 } finally {
9730 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009731 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009732 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009733 }
9734
9735
9736 /**
9737 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9738 *
9739 * <p> Requires permission:
9740 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9741 * privileges.
9742 *
9743 * @param subId subscription id
9744 * @param isEnabled {@code true} means enable, {@code false} means disable.
9745 */
9746 @Override
9747 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009748 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9749 mApp, subId, "setDataRoamingEnabled");
9750
joonhunshin4ac60942023-11-15 15:23:39 +00009751 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9752 PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled");
9753
Pengquan Menga1bb6272018-09-06 09:59:22 -07009754 final long identity = Binder.clearCallingIdentity();
9755 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009756 Phone phone = getPhone(subId);
9757 if (phone != null) {
9758 phone.setDataRoamingEnabled(isEnabled);
9759 }
9760 } finally {
9761 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009762 }
9763 }
9764
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009765 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009766 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009767 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009768 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009769 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009770
joonhunshin4ac60942023-11-15 15:23:39 +00009771 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9772 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed");
9773
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009774 boolean isAllowed = true;
9775 final long identity = Binder.clearCallingIdentity();
9776 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009777 Phone phone = getPhone(subId);
9778 if (phone != null) {
9779 isAllowed = phone.isCspPlmnEnabled();
9780 }
9781 } finally {
9782 Binder.restoreCallingIdentity(identity);
9783 }
9784 return isAllowed;
9785 }
9786
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009787 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9788 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009789 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009790 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009791 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009792 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9793 if (phone == null) {
9794 return false;
9795 }
9796 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9797 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9798 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009799 }
9800
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009801 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009802 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009803 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009804 mApp.getSystemService(AppOpsManager.class)
9805 .checkPackage(Binder.getCallingUid(), callingPackage);
9806
Jordan Liu1e142fc2019-04-22 15:10:43 -07009807 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009808 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009809 try {
9810 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009811 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009812 } catch (SecurityException e) {
9813 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9814 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009815 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009816 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009817 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009818 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009819 }
joonhunshin4ac60942023-11-15 15:23:39 +00009820
9821 enforceTelephonyFeatureWithException(callingPackage,
9822 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo");
9823
sandeepjsb6c87872021-09-27 15:34:44 +00009824 // checking compatibility, if calling app's target SDK is T and beyond.
9825 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9826 Binder.getCallingUid())) {
9827 isIccIdAccessRestricted = true;
9828 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009829 final long identity = Binder.clearCallingIdentity();
9830 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009831 UiccController uiccController = UiccController.getInstance();
9832 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009833 if (hasReadPermission) {
9834 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009835 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009836
9837 // Remove private info if the caller doesn't have access
9838 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9839 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009840 //setting the value after compatibility check
9841 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009842 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9843 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009844 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009845 if (card == null) {
9846 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009847 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009848 continue;
9849 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009850 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9851 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009852 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009853 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009854 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009855 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9856 for (UiccPortInfo portInfo : portInfos) {
9857 UiccPort port = uiccController.getUiccPortForSlot(
9858 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9859 if (port == null) {
9860 // assume no access if port is null
9861 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9862 continue;
9863 }
9864 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9865 uiccPortInfos.add(portInfo);
9866 } else {
9867 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9868 }
9869 }
9870 filteredInfos.add(new UiccCardInfo(
9871 cardInfo.isEuicc(),
9872 cardInfo.getCardId(),
9873 null,
9874 cardInfo.getPhysicalSlotIndex(),
9875 cardInfo.isRemovable(),
9876 cardInfo.isMultipleEnabledProfilesSupported(),
9877 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009878 }
9879 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009880 } finally {
9881 Binder.restoreCallingIdentity(identity);
9882 }
9883 }
9884
sandeepjsb6c87872021-09-27 15:34:44 +00009885 /**
9886 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9887 * generally private and require carrier privileges to view.
9888 *
9889 * @hide
9890 */
9891 @NonNull
9892 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9893 List<UiccPortInfo> portinfo = new ArrayList<>();
9894 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9895 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9896 }
9897 return new UiccCardInfo(
9898 cardInfo.isEuicc(),
9899 cardInfo.getCardId(),
9900 null,
9901 cardInfo.getPhysicalSlotIndex(),
9902 cardInfo.isRemovable(),
9903 cardInfo.isMultipleEnabledProfilesSupported(),
9904 portinfo
9905 );
9906 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009907
sandeepjsb6c87872021-09-27 15:34:44 +00009908 /**
9909 * @hide
9910 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9911 * These values are generally private and require carrier privileges to view.
9912 */
9913 @NonNull
9914 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9915 return new UiccPortInfo(
9916 UiccPortInfo.ICCID_REDACTED,
9917 portInfo.getPortIndex(),
9918 portInfo.getLogicalSlotIndex(),
9919 portInfo.isActive()
9920 );
9921 }
9922 @Override
9923 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009924 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009925 mApp.getSystemService(AppOpsManager.class)
9926 .checkPackage(Binder.getCallingUid(), callingPackage);
9927
sandeepjsb6c87872021-09-27 15:34:44 +00009928 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009929
Aman Guptaf3c90b32022-03-17 04:54:16 +00009930 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9931 // we are reading iccId which is PII data.
9932 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009933
joonhunshin4ac60942023-11-15 15:23:39 +00009934 enforceTelephonyFeatureWithException(callingPackage,
9935 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo");
9936
sandeepjsb6c87872021-09-27 15:34:44 +00009937 // checking compatibility, if calling app's target SDK is T and beyond.
9938 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9939 Binder.getCallingUid())) {
9940 isLogicalSlotAccessRestricted = true;
9941 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009942 final long identity = Binder.clearCallingIdentity();
9943 try {
9944 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009945 if (slots == null || slots.length == 0) {
9946 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009947 return null;
9948 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009949 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9950 for (int i = 0; i < slots.length; i++) {
9951 UiccSlot slot = slots[i];
9952 if (slot == null) {
9953 continue;
9954 }
9955
Jordan Liu7be7e652019-05-06 18:55:02 +00009956 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009957 UiccCard card = slot.getUiccCard();
9958 if (card != null) {
9959 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009960 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009961 cardId = slot.getEid();
9962 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009963 // If cardId is null, use iccId of default port as cardId.
9964 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009965 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009966 }
9967
Jordan Liu857451f2019-05-09 16:35:35 -07009968 if (cardId != null) {
9969 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9970 // if cardId is an EID, it's all digits so this is fine
9971 cardId = IccUtils.stripTrailingFs(cardId);
9972 }
9973
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009974 int cardState = 0;
9975 switch (slot.getCardState()) {
9976 case CARDSTATE_ABSENT:
9977 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9978 break;
9979 case CARDSTATE_PRESENT:
9980 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9981 break;
9982 case CARDSTATE_ERROR:
9983 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9984 break;
9985 case CARDSTATE_RESTRICTED:
9986 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9987 break;
9988 default:
9989 break;
9990
9991 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009992 List<UiccPortInfo> portInfos = new ArrayList<>();
9993 int[] portIndexes = slot.getPortList();
9994 for (int portIdx : portIndexes) {
9995 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009996 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009997 portInfos.add(new UiccPortInfo(iccId, portIdx,
9998 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009999 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010000 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010001 slot.isEuicc(),
10002 cardId,
10003 cardState,
Jordan Liua2619582019-02-14 12:56:40 -080010004 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010005 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +000010006 //setting the value after compatibility check
10007 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010008 }
10009 return infos;
10010 } finally {
10011 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -070010012 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010013 }
10014
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010015 /* Returns null if doesn't have read permission or carrier privilege access. */
10016 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
10017 boolean hasReadPermission) {
10018 String iccId = slot.getIccId(portIndex);
10019 if (hasReadPermission) { // if has read permission
10020 return iccId;
10021 } else {
10022 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
10023 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
10024 // if no read permission, checking carrier privilege access
10025 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
10026 return iccId;
10027 }
10028 }
10029 }
10030 // No read permission or carrier privilege access.
10031 return UiccPortInfo.ICCID_REDACTED;
10032 }
10033
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010034 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010035 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010036 public boolean switchSlots(int[] physicalSlots) {
10037 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010038
joonhunshin4ac60942023-11-15 15:23:39 +000010039 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10040 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots");
10041
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010042 final long identity = Binder.clearCallingIdentity();
10043 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010044 List<UiccSlotMapping> slotMappings = new ArrayList<>();
10045 for (int i = 0; i < physicalSlots.length; i++) {
10046 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
10047 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
10048 physicalSlots[i], i));
10049 }
10050 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010051 } finally {
10052 Binder.restoreCallingIdentity(identity);
10053 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010054 }
Jack Yu4c988042018-02-27 15:30:01 -080010055
10056 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010057 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
10058 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
10059 enforceModifyPermission();
10060
joonhunshin4ac60942023-11-15 15:23:39 +000010061 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10062 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping");
10063
sandeepjsb6c87872021-09-27 15:34:44 +000010064 final long identity = Binder.clearCallingIdentity();
10065 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010066 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +000010067 } finally {
10068 Binder.restoreCallingIdentity(identity);
10069 }
10070 }
10071
10072 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -080010073 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
joonhunshin4ac60942023-11-15 15:23:39 +000010074 enforceTelephonyFeatureWithException(callingPackage,
10075 PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc");
10076
Jordan Liu7de49fa2018-12-06 14:48:49 -080010077 final long identity = Binder.clearCallingIdentity();
10078 try {
10079 return UiccController.getInstance().getCardIdForDefaultEuicc();
10080 } finally {
10081 Binder.restoreCallingIdentity(identity);
10082 }
10083 }
10084
Pengquan Meng85728fb2018-03-12 16:31:21 -070010085 /**
goneil47ffb6e2018-04-06 15:40:58 -070010086 * A test API to reload the UICC profile.
10087 *
10088 * <p>Requires that the calling app has permission
10089 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
10090 * @hide
10091 */
10092 @Override
10093 public void refreshUiccProfile(int subId) {
10094 enforceModifyPermission();
10095
10096 final long identity = Binder.clearCallingIdentity();
10097 try {
10098 Phone phone = getPhone(subId);
10099 if (phone == null) {
10100 return;
10101 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010102 UiccPort uiccPort = phone.getUiccPort();
10103 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -070010104 return;
10105 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010106 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -070010107 if (uiccProfile == null) {
10108 return;
10109 }
10110 uiccProfile.refresh();
10111 } finally {
10112 Binder.restoreCallingIdentity(identity);
10113 }
10114 }
10115
10116 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010117 * Returns false if the mobile data is disabled by default, otherwise return true.
10118 */
10119 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010120 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010121 }
10122
10123 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010124 * Returns the default network type for the given {@code subId}, if the default network type is
10125 * not set, return {@link Phone#PREFERRED_NT_MODE}.
10126 */
10127 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010128 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -080010129 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +090010130 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
10131 return list.get(phoneId);
10132 }
10133 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -070010134 }
fionaxua13278b2018-03-21 00:08:13 -070010135
10136 @Override
10137 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -070010138 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -070010139 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010140
10141 final long identity = Binder.clearCallingIdentity();
10142 try {
10143 final Phone phone = getPhone(subId);
10144 if (phone == null) {
10145 loge("setCarrierTestOverride fails with invalid subId: " + subId);
10146 return;
10147 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -080010148 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10149 if (cpt != null) {
10150 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
10151 }
10152 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -070010153 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
10154 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -070010155 if (carrierPrivilegeRules == null) {
10156 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
10157 } else {
10158 mCarrierPrivilegeTestOverrideSubIds.add(subId);
10159 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010160 } finally {
10161 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010162 }
fionaxua13278b2018-03-21 00:08:13 -070010163 }
10164
10165 @Override
Benedict Wong66477622023-02-03 23:30:57 +000010166 public void setCarrierServicePackageOverride(
10167 int subId, String carrierServicePackage, String callingPackage) {
10168 TelephonyPermissions.enforceShellOnly(
10169 Binder.getCallingUid(), "setCarrierServicePackageOverride");
10170
Benedict Wong66477622023-02-03 23:30:57 +000010171 final long identity = Binder.clearCallingIdentity();
10172 try {
10173 final Phone phone = getPhone(subId);
10174 if (phone == null || phone.getSubId() != subId) {
10175 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
10176 throw new IllegalArgumentException("No phone for subid");
10177 }
10178 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10179 if (cpt == null) {
10180 loge("setCarrierServicePackageOverride failed with no CPT for phone");
10181 throw new IllegalStateException("No CPT for phone");
10182 }
10183 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
10184 } finally {
10185 Binder.restoreCallingIdentity(identity);
10186 }
10187 }
10188
10189 @Override
fionaxua13278b2018-03-21 00:08:13 -070010190 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -070010191 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010192
10193 final long identity = Binder.clearCallingIdentity();
10194 try {
10195 final Phone phone = getPhone(subId);
10196 if (phone == null) {
10197 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
10198 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
10199 }
10200 return phone.getCarrierIdListVersion();
10201 } finally {
10202 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010203 }
fionaxua13278b2018-03-21 00:08:13 -070010204 }
Malcolm Chen2c63d402018-08-14 16:00:53 -070010205
10206 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010207 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
10208 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010209 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010210 mApp, subId, callingPackage, callingFeatureId,
10211 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010212 return -1;
10213 }
10214
10215 final long identity = Binder.clearCallingIdentity();
10216 try {
10217 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10218 } finally {
10219 Binder.restoreCallingIdentity(identity);
10220 }
10221 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010222
10223 @Override
10224 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +080010225 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010226 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010227 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010228
joonhunshin4ac60942023-11-15 15:23:39 +000010229 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10230 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode");
10231
Pengquan Menga1bb6272018-09-06 09:59:22 -070010232 final long identity = Binder.clearCallingIdentity();
10233 try {
10234 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10235 } finally {
10236 Binder.restoreCallingIdentity(identity);
10237 }
10238 }
10239
10240 @Override
10241 public boolean setCdmaRoamingMode(int subId, int mode) {
10242 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10243 mApp, subId, "setCdmaRoamingMode");
10244
joonhunshin4ac60942023-11-15 15:23:39 +000010245 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10246 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode");
10247
Pengquan Menga1bb6272018-09-06 09:59:22 -070010248 final long identity = Binder.clearCallingIdentity();
10249 try {
10250 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10251 } finally {
10252 Binder.restoreCallingIdentity(identity);
10253 }
10254 }
10255
10256 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010257 public int getCdmaSubscriptionMode(int subId) {
10258 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010259 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010260 mApp, subId, "getCdmaSubscriptionMode");
10261
joonhunshin4ac60942023-11-15 15:23:39 +000010262 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10263 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode");
10264
Sarah Chinbaab1432020-10-28 13:46:24 -070010265 final long identity = Binder.clearCallingIdentity();
10266 try {
10267 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10268 } finally {
10269 Binder.restoreCallingIdentity(identity);
10270 }
10271 }
10272
10273 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010274 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10275 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10276 mApp, subId, "setCdmaSubscriptionMode");
10277
joonhunshin4ac60942023-11-15 15:23:39 +000010278 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10279 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode");
10280
Pengquan Menga1bb6272018-09-06 09:59:22 -070010281 final long identity = Binder.clearCallingIdentity();
10282 try {
10283 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10284 } finally {
10285 Binder.restoreCallingIdentity(identity);
10286 }
10287 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010288
sqianc5eccab2018-10-19 18:46:41 -070010289 @Override
sqian8c685422019-02-22 15:55:18 -080010290 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010291 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010292 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010293 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10294 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010295 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10296 }
joonhunshin4ac60942023-11-15 15:23:39 +000010297
10298 enforceTelephonyFeatureWithException(callingPackage,
10299 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList");
10300
sqian11b7a0e2018-12-05 18:48:28 -080010301 final long identity = Binder.clearCallingIdentity();
10302 try {
sqian854d44b2018-12-12 16:48:18 -080010303 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10304 for (Phone phone: PhoneFactory.getPhones()) {
10305 if (phone.getEmergencyNumberTracker() != null
10306 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10307 emergencyNumberListInternal.put(
10308 phone.getSubId(),
10309 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10310 }
sqian11b7a0e2018-12-05 18:48:28 -080010311 }
sqian854d44b2018-12-12 16:48:18 -080010312 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010313 } finally {
10314 Binder.restoreCallingIdentity(identity);
10315 }
sqianc5eccab2018-10-19 18:46:41 -070010316 }
10317
10318 @Override
sqian8c685422019-02-22 15:55:18 -080010319 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010320 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010321 if (!exactMatch) {
10322 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010323 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010324 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010325 }
joonhunshin4ac60942023-11-15 15:23:39 +000010326
10327 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10328 PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber");
10329
sqian11b7a0e2018-12-05 18:48:28 -080010330 final long identity = Binder.clearCallingIdentity();
10331 try {
sqian854d44b2018-12-12 16:48:18 -080010332 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010333 //Note: we ignore passed in param exactMatch. We can remove it once
10334 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010335 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010336 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010337 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010338 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010339 }
sqian11b7a0e2018-12-05 18:48:28 -080010340 }
10341 return false;
10342 } finally {
10343 Binder.restoreCallingIdentity(identity);
10344 }
10345 }
10346
sqianf4ca7ed2019-01-15 18:32:07 -080010347 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010348 * Start emergency callback mode for GsmCdmaPhone for testing.
10349 */
10350 @Override
10351 public void startEmergencyCallbackMode() {
10352 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10353 "startEmergencyCallbackMode");
10354 enforceModifyPermission();
10355 final long identity = Binder.clearCallingIdentity();
10356 try {
10357 for (Phone phone : PhoneFactory.getPhones()) {
10358 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10359 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10360 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10361 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10362 gsmCdmaPhone.obtainMessage(
10363 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10364 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10365 }
10366 }
10367 } finally {
10368 Binder.restoreCallingIdentity(identity);
10369 }
10370 }
10371
10372 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010373 * Update emergency number list for test mode.
10374 */
10375 @Override
10376 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10377 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10378 "updateEmergencyNumberListTestMode");
10379
10380 final long identity = Binder.clearCallingIdentity();
10381 try {
10382 for (Phone phone: PhoneFactory.getPhones()) {
10383 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10384 if (tracker != null) {
10385 tracker.executeEmergencyNumberTestModeCommand(action, num);
10386 }
10387 }
10388 } finally {
10389 Binder.restoreCallingIdentity(identity);
10390 }
10391 }
10392
10393 /**
10394 * Get the full emergency number list for test mode.
10395 */
10396 @Override
10397 public List<String> getEmergencyNumberListTestMode() {
10398 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10399 "getEmergencyNumberListTestMode");
10400
10401 final long identity = Binder.clearCallingIdentity();
10402 try {
10403 Set<String> emergencyNumbers = new HashSet<>();
10404 for (Phone phone: PhoneFactory.getPhones()) {
10405 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10406 if (tracker != null) {
10407 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10408 emergencyNumbers.add(num.getNumber());
10409 }
10410 }
10411 }
10412 return new ArrayList<>(emergencyNumbers);
10413 } finally {
10414 Binder.restoreCallingIdentity(identity);
10415 }
10416 }
10417
chen xud6b45bd2018-10-30 22:27:10 -070010418 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010419 public int getEmergencyNumberDbVersion(int subId) {
10420 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10421
joonhunshin4ac60942023-11-15 15:23:39 +000010422 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10423 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion");
10424
Shuo Qian3b6ee772019-11-13 17:43:31 -080010425 final long identity = Binder.clearCallingIdentity();
10426 try {
10427 final Phone phone = getPhone(subId);
10428 if (phone == null) {
10429 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10430 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10431 }
10432 return phone.getEmergencyNumberDbVersion();
10433 } finally {
10434 Binder.restoreCallingIdentity(identity);
10435 }
10436 }
10437
10438 @Override
10439 public void notifyOtaEmergencyNumberDbInstalled() {
10440 enforceModifyPermission();
10441
joonhunshin4ac60942023-11-15 15:23:39 +000010442 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10443 PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled");
10444
Shuo Qian3b6ee772019-11-13 17:43:31 -080010445 final long identity = Binder.clearCallingIdentity();
10446 try {
10447 for (Phone phone: PhoneFactory.getPhones()) {
10448 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10449 if (tracker != null) {
10450 tracker.updateOtaEmergencyNumberDatabase();
10451 }
10452 }
10453 } finally {
10454 Binder.restoreCallingIdentity(identity);
10455 }
10456 }
10457
10458 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010459 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010460 enforceActiveEmergencySessionPermission();
10461
joonhunshin4ac60942023-11-15 15:23:39 +000010462 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10463 PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath");
10464
Shuo Qian3b6ee772019-11-13 17:43:31 -080010465 final long identity = Binder.clearCallingIdentity();
10466 try {
10467 for (Phone phone: PhoneFactory.getPhones()) {
10468 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10469 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010470 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10471 }
10472 }
10473 } finally {
10474 Binder.restoreCallingIdentity(identity);
10475 }
10476 }
10477
10478 @Override
10479 public void resetOtaEmergencyNumberDbFilePath() {
10480 enforceActiveEmergencySessionPermission();
10481
joonhunshin4ac60942023-11-15 15:23:39 +000010482 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10483 PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath");
10484
Shuo Qianc373f112020-03-05 17:55:34 -080010485 final long identity = Binder.clearCallingIdentity();
10486 try {
10487 for (Phone phone: PhoneFactory.getPhones()) {
10488 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10489 if (tracker != null) {
10490 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010491 }
10492 }
10493 } finally {
10494 Binder.restoreCallingIdentity(identity);
10495 }
10496 }
10497
10498 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010499 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10500 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10501 Phone phone = getPhone(subId);
10502 if (phone == null) {
10503 return null;
10504 }
10505 final long identity = Binder.clearCallingIdentity();
10506 try {
10507 UiccProfile profile = UiccController.getInstance()
10508 .getUiccProfileForPhone(phone.getPhoneId());
10509 if (profile != null) {
10510 return profile.getCertsFromCarrierPrivilegeAccessRules();
10511 }
10512 } finally {
10513 Binder.restoreCallingIdentity(identity);
10514 }
10515 return null;
10516 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010517
10518 /**
10519 * Enable or disable a modem stack.
10520 */
10521 @Override
10522 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10523 enforceModifyPermission();
10524
joonhunshin4ac60942023-11-15 15:23:39 +000010525 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10526 PackageManager.FEATURE_TELEPHONY, "enableModemForSlot");
10527
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010528 final long identity = Binder.clearCallingIdentity();
10529 try {
10530 Phone phone = PhoneFactory.getPhone(slotIndex);
10531 if (phone == null) {
10532 return false;
10533 } else {
10534 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10535 }
10536 } finally {
10537 Binder.restoreCallingIdentity(identity);
10538 }
10539 }
Michelecea4cf22018-12-21 15:00:11 -080010540
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010541 /**
10542 * Whether a modem stack is enabled or not.
10543 */
10544 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010545 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10546 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010547 Phone phone = PhoneFactory.getPhone(slotIndex);
10548 if (phone == null) return false;
10549
10550 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010551 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10552 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010553 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10554 }
10555
joonhunshin4ac60942023-11-15 15:23:39 +000010556 enforceTelephonyFeatureWithException(callingPackage,
10557 PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot");
10558
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010559 final long identity = Binder.clearCallingIdentity();
10560 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010561 try {
10562 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10563 } catch (NoSuchElementException ex) {
10564 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10565 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010566 } finally {
10567 Binder.restoreCallingIdentity(identity);
10568 }
10569 }
10570
Michelecea4cf22018-12-21 15:00:11 -080010571 @Override
Michele0ea7d782019-03-19 14:58:42 -070010572 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010573 enforceModifyPermission();
10574
joonhunshin4ac60942023-11-15 15:23:39 +000010575 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10576 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction");
10577
Michelecea4cf22018-12-21 15:00:11 -080010578 final long identity = Binder.clearCallingIdentity();
10579 try {
10580 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010581 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010582 .commit();
10583 } finally {
10584 Binder.restoreCallingIdentity(identity);
10585 }
10586 }
10587
10588 @Override
Michele0ea7d782019-03-19 14:58:42 -070010589 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010590 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010591 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010592 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10593 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010594 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010595 }
Michelecea4cf22018-12-21 15:00:11 -080010596
joonhunshin4ac60942023-11-15 15:23:39 +000010597 enforceTelephonyFeatureWithException(callingPackage,
10598 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported");
10599
Michelecea4cf22018-12-21 15:00:11 -080010600 final long identity = Binder.clearCallingIdentity();
10601 try {
Michele0ea7d782019-03-19 14:58:42 -070010602 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010603 } finally {
10604 Binder.restoreCallingIdentity(identity);
10605 }
10606 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010607
Michele0ea7d782019-03-19 14:58:42 -070010608 @TelephonyManager.IsMultiSimSupportedResult
10609 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010610 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10611 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10612 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010613 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10614 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010615 }
10616 // Check if the hardware supports multisim functionality. If usage of multisim is not
10617 // supported by the modem, indicate that it is restricted.
10618 PhoneCapability staticCapability =
10619 mPhoneConfigurationManager.getStaticPhoneCapability();
10620 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010621 loge("isMultiSimSupportedInternal: no static configuration available");
10622 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010623 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010624 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010625 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10626 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010627 }
10628 // Check if support of multiple SIMs is restricted by carrier
10629 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010630 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010631 }
10632
Michele0ea7d782019-03-19 14:58:42 -070010633 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010634 }
10635
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010636 /**
10637 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010638 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10639 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10640 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010641 * @param numOfSims number of active sims we want to switch to
10642 */
10643 @Override
10644 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010645 if (numOfSims == 1) {
10646 enforceModifyPermission();
10647 } else {
10648 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10649 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10650 }
joonhunshin4ac60942023-11-15 15:23:39 +000010651
10652 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10653 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig");
10654
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010655 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010656
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010657 try {
Michele30b57b22019-03-01 12:01:14 -080010658 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010659 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010660 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10661 return;
10662 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010663 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10664 } finally {
10665 Binder.restoreCallingIdentity(identity);
10666 }
10667 }
10668
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010669 @Override
10670 public boolean isApplicationOnUicc(int subId, int appType) {
10671 enforceReadPrivilegedPermission("isApplicationOnUicc");
joonhunshin4ac60942023-11-15 15:23:39 +000010672
10673 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10674 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc");
10675
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010676 Phone phone = getPhone(subId);
10677 if (phone == null) {
10678 return false;
10679 }
10680 final long identity = Binder.clearCallingIdentity();
10681 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010682 UiccPort uiccPort = phone.getUiccPort();
10683 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010684 return false;
10685 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010686 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010687 if (uiccProfile == null) {
10688 return false;
10689 }
10690 if (TelephonyManager.APPTYPE_SIM <= appType
10691 && appType <= TelephonyManager.APPTYPE_ISIM) {
10692 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10693 }
10694 return false;
10695 } finally {
10696 Binder.restoreCallingIdentity(identity);
10697 }
10698 }
10699
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010700 /**
chen xub4baa772019-04-03 10:23:41 -070010701 * Get whether making changes to modem configurations will trigger reboot.
10702 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010703 */
10704 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010705 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10706 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010707 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010708 mApp, subId, callingPackage, callingFeatureId,
10709 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010710 return false;
10711 }
joonhunshin4ac60942023-11-15 15:23:39 +000010712
10713 enforceTelephonyFeatureWithException(callingPackage,
10714 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
10715 "doesSwitchMultiSimConfigTriggerReboot");
10716
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010717 final long identity = Binder.clearCallingIdentity();
10718 try {
10719 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10720 } finally {
10721 Binder.restoreCallingIdentity(identity);
10722 }
10723 }
10724
Nathan Harold29f5f052019-02-15 13:41:57 -080010725 private void updateModemStateMetrics() {
10726 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10727 // TODO: check the state for each modem if the api is ready.
10728 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10729 }
10730
Pengquan Meng3889a572019-01-23 11:16:29 -080010731 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010732 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010733 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010734 // Verify that the callingPackage belongs to the calling UID
10735 mApp.getSystemService(AppOpsManager.class)
10736 .checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000010737
10738 enforceTelephonyFeatureWithException(callingPackage,
10739 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping");
10740
Pengquan Meng3889a572019-01-23 11:16:29 -080010741 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010742 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010743 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010744 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10745 if (slotInfos != null) {
10746 for (int i = 0; i < slotInfos.length; i++) {
10747 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10748 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10749 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10750 portInfo.getLogicalSlotIndex()));
10751 }
10752 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010753 }
10754 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010755 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010756 } finally {
10757 Binder.restoreCallingIdentity(identity);
10758 }
10759 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010760
10761 /**
10762 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010763 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010764 */
jimsunf9ec1622022-09-13 21:18:43 +080010765 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010766 @Override
10767 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010768 return getHalVersion(HAL_SERVICE_RADIO);
10769 }
10770
10771 /**
10772 * Get the HAL Version of a specific service
10773 */
10774 @Override
10775 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010776 Phone phone = getDefaultPhone();
10777 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010778 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010779 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10780 return hv.major * 100 + hv.minor;
10781 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010782
10783 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010784 * Get the current calling package name.
sangyun097dcf72024-01-04 10:35:49 +090010785 *
10786 * @return the current calling package name, or null if there is no known package.
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010787 */
10788 @Override
sangyun097dcf72024-01-04 10:35:49 +090010789 public @Nullable String getCurrentPackageName() {
10790 PackageManager pm = mApp.getPackageManager();
10791 String[] packageNames = pm == null ? null : pm.getPackagesForUid(Binder.getCallingUid());
10792 return packageNames == null ? null : packageNames[0];
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010793 }
10794
10795 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010796 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10797 * corresponding network requests on a subId.
10798 *
10799 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010800 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010801 * 2) APN is un-metered for this subscription, or
10802 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010803 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010804 *
10805 * @return whether data is allowed for a apn type.
10806 *
10807 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010808 */
10809 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010810 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010811 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10812 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010813
joonhunshin4ac60942023-11-15 15:23:39 +000010814 enforceTelephonyFeatureWithException(callingPackage,
10815 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn");
10816
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010817 // Now that all security checks passes, perform the operation as ourselves.
10818 final long identity = Binder.clearCallingIdentity();
10819 try {
10820 Phone phone = getPhone(subId);
10821 if (phone == null) return false;
10822
Jack Yu27422a52022-03-21 10:38:05 -070010823 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010824 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010825 isMetered = phone.getDataNetworkController().getDataConfigManager()
10826 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10827 phone.getServiceState().getDataRoaming());
10828 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010829 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010830 } finally {
10831 Binder.restoreCallingIdentity(identity);
10832 }
10833 }
10834
10835 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010836 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010837 enforceReadPrivilegedPermission("isApnMetered");
10838
joonhunshin4ac60942023-11-15 15:23:39 +000010839 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10840 PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered");
10841
Malcolm Chene5ad5792019-04-18 13:51:02 -070010842 // Now that all security checks passes, perform the operation as ourselves.
10843 final long identity = Binder.clearCallingIdentity();
10844 try {
10845 Phone phone = getPhone(subId);
10846 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010847 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10848 DataUtils.apnTypeToNetworkCapability(apnType),
10849 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010850 } finally {
10851 Binder.restoreCallingIdentity(identity);
10852 }
10853 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010854
10855 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010856 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10857 int subscriptionId, IBooleanConsumer resultCallback) {
10858 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +000010859
10860 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10861 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels");
10862
Hall Liu73f5d362020-01-20 13:42:00 -080010863 long token = Binder.clearCallingIdentity();
10864 try {
10865 Phone phone = getPhone(subscriptionId);
10866 if (phone == null) {
10867 try {
10868 if (resultCallback != null) {
10869 resultCallback.accept(false);
10870 }
10871 } catch (RemoteException e) {
10872 // ignore
10873 }
10874 return;
10875 }
10876 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10877 Pair.create(specifiers, (x) -> {
10878 try {
10879 if (resultCallback != null) {
10880 resultCallback.accept(x);
10881 }
10882 } catch (RemoteException e) {
10883 // ignore
10884 }
10885 });
10886 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10887 } finally {
10888 Binder.restoreCallingIdentity(token);
10889 }
10890 }
10891
10892 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010893 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10894 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010895 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010896 mApp, subId, "getSystemSelectionChannels");
joonhunshin4ac60942023-11-15 15:23:39 +000010897
10898 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10899 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels");
10900
Sarah Chin679c08a2020-11-18 13:39:35 -080010901 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10902 final long identity = Binder.clearCallingIdentity();
10903 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010904 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10905 if (result instanceof IllegalStateException) {
10906 throw (IllegalStateException) result;
10907 }
10908 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010909 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10910 return specifiers;
10911 } finally {
10912 Binder.restoreCallingIdentity(identity);
10913 }
10914 }
10915
10916 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010917 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010918 enforceReadPrivilegedPermission("isMvnoMatched");
joonhunshin4ac60942023-11-15 15:23:39 +000010919
10920 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10921 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched");
10922
Jack Yu8b766fc2022-03-21 09:42:33 -070010923 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010924 }
10925
10926 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010927 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10928 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010929 if (callingPackage == null) {
10930 callingPackage = getCurrentPackageName();
10931 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010932 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10933 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010934 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10935 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010936 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10937 }
10938 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10939 Intent intent = new Intent();
10940 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10941 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10942 // Bring up choose default SMS subscription dialog right now
10943 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10944 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10945 mApp.startActivity(intent);
10946 }
chen xud5ca2d52019-05-28 15:20:57 -070010947
10948 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010949 public void showSwitchToManagedProfileDialog() {
10950 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000010951 try {
10952 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
10953 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
10954 // for work telephony.
10955 Intent intent = new Intent(Intent.ACTION_SENDTO);
10956 intent.setData(Uri.parse("smsto:"));
10957 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10958 mApp.startActivity(intent);
10959 } catch (ActivityNotFoundException e) {
10960 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
10961 Intent intent = new Intent();
10962 intent.setClass(mApp, ErrorDialogActivity.class);
10963 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10964 mApp.startActivity(intent);
10965 }
Ayush Sharma787854b2022-12-12 14:55:02 +000010966 }
10967
10968 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010969 public String getMmsUAProfUrl(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000010970 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10971 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl");
10972
chen xud5ca2d52019-05-28 15:20:57 -070010973 //TODO investigate if this API should require proper permission check in R b/133791609
10974 final long identity = Binder.clearCallingIdentity();
10975 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010976 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10977 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10978 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10979 return carrierUAProfUrl;
10980 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010981 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10982 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010983 } finally {
10984 Binder.restoreCallingIdentity(identity);
10985 }
10986 }
10987
10988 @Override
10989 public String getMmsUserAgent(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000010990 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10991 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent");
10992
chen xud5ca2d52019-05-28 15:20:57 -070010993 //TODO investigate if this API should require proper permission check in R b/133791609
10994 final long identity = Binder.clearCallingIdentity();
10995 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010996 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10997 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10998 if (!TextUtils.isEmpty(carrierUserAgent)) {
10999 return carrierUserAgent;
11000 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011001 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11002 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070011003 } finally {
11004 Binder.restoreCallingIdentity(identity);
11005 }
11006 }
Jack Yub07d4972019-05-28 16:12:25 -070011007
11008 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070011009 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
11010 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070011011
joonhunshin4ac60942023-11-15 15:23:39 +000011012 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11013 PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled");
11014
Jack Yub07d4972019-05-28 16:12:25 -070011015 final long identity = Binder.clearCallingIdentity();
11016 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011017 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070011018 if (phone == null) return false;
11019
Ling Maf188d502022-09-16 15:22:36 -070011020 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070011021 } finally {
11022 Binder.restoreCallingIdentity(identity);
11023 }
11024 }
11025
11026 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080011027 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070011028 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080011029 enforceModifyPermission();
11030
joonhunshin4ac60942023-11-15 15:23:39 +000011031 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11032 PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled");
11033
changbettyd5c246e2019-12-24 15:40:37 +080011034 final long identity = Binder.clearCallingIdentity();
11035 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011036 Phone phone = getPhone(subscriptionId);
11037 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080011038
Ling Maf188d502022-09-16 15:22:36 -070011039 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080011040 } finally {
11041 Binder.restoreCallingIdentity(identity);
11042 }
11043 }
11044
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011045 /**
Hall Liu746e03c2020-09-25 11:13:49 -070011046 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011047 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
11048 * otherwise.
11049 */
11050 @Override
11051 public void setCepEnabled(boolean isCepEnabled) {
11052 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
11053
11054 final long identity = Binder.clearCallingIdentity();
11055 try {
11056 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
11057 for (Phone phone : PhoneFactory.getPhones()) {
11058 Phone defaultPhone = phone.getImsPhone();
11059 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
11060 ImsPhone imsPhone = (ImsPhone) defaultPhone;
11061 ImsPhoneCallTracker imsPhoneCallTracker =
11062 (ImsPhoneCallTracker) imsPhone.getCallTracker();
11063 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
11064 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
11065 + imsPhone.getMsisdn());
11066 }
11067 }
11068 } finally {
11069 Binder.restoreCallingIdentity(identity);
11070 }
11071 }
allenwtsu46dcc572020-01-08 18:24:03 +080011072
11073 /**
11074 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
11075 *
11076 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
11077 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
11078 * before being read.
11079 */
11080 @Override
11081 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
11082 isCompressed) {
11083 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11084 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011085 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11086 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11087 }
joonhunshin4ac60942023-11-15 15:23:39 +000011088
11089 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11090 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11091 Binder.getCallingUserHandle())) {
11092 if (!isImsAvailableOnDevice()) {
11093 // ProvisioningManager can not handle ServiceSpecificException.
11094 // Throw the IllegalStateException and annotate ProvisioningManager.
11095 throw new IllegalStateException("IMS not available on device.");
11096 }
11097 } else {
11098 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11099 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11100 "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011101 }
11102
11103 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080011104 try {
Hui Wang761a6682020-10-31 05:12:53 +000011105 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
11106 } finally {
11107 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080011108 }
11109 }
zoey chene02881a2019-12-30 16:11:23 +080011110
11111 @Override
11112 public boolean isIccLockEnabled(int subId) {
11113 enforceReadPrivilegedPermission("isIccLockEnabled");
11114
joonhunshin4ac60942023-11-15 15:23:39 +000011115 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11116 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled");
11117
zoey chene02881a2019-12-30 16:11:23 +080011118 // Now that all security checks passes, perform the operation as ourselves.
11119 final long identity = Binder.clearCallingIdentity();
11120 try {
11121 Phone phone = getPhone(subId);
11122 if (phone != null && phone.getIccCard() != null) {
11123 return phone.getIccCard().getIccLockEnabled();
11124 } else {
11125 return false;
11126 }
11127 } finally {
11128 Binder.restoreCallingIdentity(identity);
11129 }
11130 }
11131
11132 /**
11133 * Set the ICC pin lock enabled or disabled.
11134 *
11135 * @return an integer representing the status of IccLock enabled or disabled in the following
11136 * three cases:
11137 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
11138 * successfully.
11139 * - Positive number and zero for remaining password attempts.
11140 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11141 *
11142 */
11143 @Override
11144 public int setIccLockEnabled(int subId, boolean enabled, String password) {
11145 enforceModifyPermission();
11146
joonhunshin4ac60942023-11-15 15:23:39 +000011147 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11148 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled");
11149
zoey chene02881a2019-12-30 16:11:23 +080011150 Phone phone = getPhone(subId);
11151 if (phone == null) {
11152 return 0;
11153 }
11154 // Now that all security checks passes, perform the operation as ourselves.
11155 final long identity = Binder.clearCallingIdentity();
11156 try {
11157 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
11158 new Pair<Boolean, String>(enabled, password), phone, null);
11159 return attemptsRemaining;
11160
11161 } catch (Exception e) {
11162 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
11163 } finally {
11164 Binder.restoreCallingIdentity(identity);
11165 }
11166 return 0;
11167 }
11168
11169 /**
11170 * Change the ICC password used in ICC pin lock.
11171 *
11172 * @return an integer representing the status of IccLock changed in the following three cases:
11173 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
11174 * - Positive number and zero for remaining password attempts.
11175 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11176 *
11177 */
11178 @Override
11179 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
11180 enforceModifyPermission();
11181
joonhunshin4ac60942023-11-15 15:23:39 +000011182 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11183 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword");
11184
zoey chene02881a2019-12-30 16:11:23 +080011185 Phone phone = getPhone(subId);
11186 if (phone == null) {
11187 return 0;
11188 }
11189 // Now that all security checks passes, perform the operation as ourselves.
11190 final long identity = Binder.clearCallingIdentity();
11191 try {
11192 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
11193 new Pair<String, String>(oldPassword, newPassword), phone, null);
11194 return attemptsRemaining;
11195
11196 } catch (Exception e) {
11197 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
11198 } finally {
11199 Binder.restoreCallingIdentity(identity);
11200 }
11201 return 0;
11202 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080011203
11204 /**
11205 * Request for receiving user activity notification
11206 */
11207 @Override
11208 public void requestUserActivityNotification() {
11209 if (!mNotifyUserActivity.get()
11210 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
11211 mNotifyUserActivity.set(true);
11212 }
11213 }
11214
11215 /**
11216 * Called when userActivity is signalled in the power manager.
11217 * This is safe to call from any thread, with any window manager locks held or not.
11218 */
11219 @Override
11220 public void userActivity() {
11221 // ***************************************
11222 // * Inherited from PhoneWindowManager *
11223 // ***************************************
11224 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
11225 // WITH ITS LOCKS HELD.
11226 //
11227 // This code must be VERY careful about the locks
11228 // it acquires.
11229 // In fact, the current code acquires way too many,
11230 // and probably has lurking deadlocks.
11231
11232 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
11233 throw new SecurityException("Only the OS may call notifyUserActivity()");
11234 }
11235
11236 if (mNotifyUserActivity.getAndSet(false)) {
11237 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
11238 USER_ACTIVITY_NOTIFICATION_DELAY);
11239 }
11240 }
Malcolm Chen4639c562020-04-13 11:59:40 -070011241
11242 @Override
11243 public boolean canConnectTo5GInDsdsMode() {
11244 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
11245 }
Jack Yud10cdd42020-09-28 20:28:01 -070011246
11247 @Override
11248 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
11249 String callingFeatureId) {
11250 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
11251 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
11252 throw new SecurityException("Requires READ_PHONE_STATE permission.");
11253 }
11254
joonhunshin4ac60942023-11-15 15:23:39 +000011255 enforceTelephonyFeatureWithException(callingPackage,
11256 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns");
11257
Jack Yud10cdd42020-09-28 20:28:01 -070011258 Phone phone = getPhone(subId);
11259 if (phone == null) {
11260 throw new RuntimeException("phone is not available");
11261 }
11262 // Now that all security checks passes, perform the operation as ourselves.
11263 final long identity = Binder.clearCallingIdentity();
11264 try {
11265 return phone.getEquivalentHomePlmns();
11266 } finally {
11267 Binder.restoreCallingIdentity(identity);
11268 }
11269 }
Daniel Bright59e67312020-11-13 11:49:37 -080011270
11271 @Override
11272 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011273 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
joonhunshin4ac60942023-11-15 15:23:39 +000011274 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11275 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
11276 "isRadioInterfaceCapabilitySupported");
11277
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011278 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080011279 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080011280 if (radioInterfaceCapabilities == null) {
11281 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080011282 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011283 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080011284 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011285
Hui Wang641e81c2020-10-12 12:14:23 -070011286 @Override
11287 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
11288 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000011289 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
11290 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11291 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
11292 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11293 Manifest.permission.MODIFY_PHONE_STATE);
joonhunshin4ac60942023-11-15 15:23:39 +000011294
11295 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11296 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest");
11297
Hui Wang641e81c2020-10-12 12:14:23 -070011298 if (DBG) {
11299 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
11300 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
11301 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
11302 }
11303
11304 if (!SubscriptionManager.isValidSubscriptionId(subId)
11305 || appType < TelephonyManager.APPTYPE_UNKNOWN
11306 || appType > TelephonyManager.APPTYPE_ISIM
11307 || nafUrl == null || securityProtocol == null || callback == null) {
11308 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
11309 if (callback != null) {
11310 try {
11311 callback.onAuthenticationFailure(
11312 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
11313 } catch (RemoteException exception) {
11314 log("Fail to notify onAuthenticationFailure due to " + exception);
11315 }
11316 return;
11317 }
11318 }
11319
11320 final long token = Binder.clearCallingIdentity();
11321 try {
11322 getGbaManager(subId).bootstrapAuthenticationRequest(
11323 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011324 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070011325 } finally {
11326 Binder.restoreCallingIdentity(token);
11327 }
11328 }
11329
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011330 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011331 * Attempts to set the radio power state for all phones for thermal reason.
11332 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011333 * requested radio power state will actually be set. See {@link
11334 * PhoneInternalInterface#setRadioPowerForReason} for more details.
11335 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011336 * @param enable {@code true} if trying to turn radio on.
11337 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
11338 * false}.
11339 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011340 private boolean setRadioPowerForThermal(boolean enable) {
11341 boolean isPhoneAvailable = false;
11342 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
11343 Phone phone = PhoneFactory.getPhone(i);
11344 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011345 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011346 isPhoneAvailable = true;
11347 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011348 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011349
11350 // return true if successfully informed the phone object about the thermal radio power
11351 // request.
11352 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011353 }
11354
11355 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011356 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011357 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11358 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11359 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11360 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11361 throw new IllegalArgumentException("modem does not support data throttling");
11362 }
11363
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011364 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11365 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011366 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011367 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11368 }
11369
Sarah Chinecc78c42022-03-31 21:16:48 -070011370 setDataEnabledForReason(
11371 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011372
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011373 if (isDataThrottlingSupported) {
11374 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011375 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011376 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11377 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11378 } else if (thermalMitigationResult
11379 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011380 log("Modem likely does not support data throttling on secondary carrier. Data " +
11381 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11382 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011383 }
11384 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011385 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011386
11387 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011388 }
11389
Jack Nudelman644b91a2021-03-12 14:09:48 -080011390 private static List<String> getThermalMitigationAllowlist(Context context) {
11391 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11392 for (String pckg : context.getResources()
11393 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11394 sThermalMitigationAllowlistedPackages.add(pckg);
11395 }
11396 }
11397
11398 return sThermalMitigationAllowlistedPackages;
11399 }
11400
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011401 private boolean isAnyPhoneInEmergencyState() {
11402 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11403 if (tm.isInEmergencyCall()) {
11404 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11405 return true;
11406 }
11407 for (Phone phone : PhoneFactory.getPhones()) {
11408 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11409 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011410 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11411 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011412 return true;
11413 }
11414 }
11415
11416 return false;
11417 }
11418
Jack Nudelman644b91a2021-03-12 14:09:48 -080011419 /**
11420 * Used by shell commands to add an authorized package name for thermal mitigation.
11421 * @param packageName name of package to be allowlisted
11422 * @param context
11423 */
11424 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11425 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11426 sThermalMitigationAllowlistedPackages.add(packageName);
11427 }
11428
11429 /**
11430 * Used by shell commands to remove an authorized package name for thermal mitigation.
11431 * @param packageName name of package to remove from allowlist
11432 * @param context
11433 */
11434 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11435 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11436 sThermalMitigationAllowlistedPackages.remove(packageName);
11437 }
11438
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011439 /**
11440 * Thermal mitigation request to control functionalities at modem.
11441 *
11442 * @param subId the id of the subscription.
11443 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011444 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011445 *
11446 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11447 */
11448 @Override
11449 @ThermalMitigationResult
11450 public int sendThermalMitigationRequest(
11451 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011452 ThermalMitigationRequest thermalMitigationRequest,
11453 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011454 enforceModifyPermission();
11455
Jack Nudelman644b91a2021-03-12 14:09:48 -080011456 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000011457
11458 enforceTelephonyFeatureWithException(callingPackage,
11459 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest");
11460
Jack Nudelman644b91a2021-03-12 14:09:48 -080011461 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11462 .contains(callingPackage)) {
11463 throw new SecurityException("Calling package must be configured in the device config. "
11464 + "calling package: " + callingPackage);
11465 }
11466
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011467 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11468 final long identity = Binder.clearCallingIdentity();
11469
11470 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11471 try {
11472 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11473 switch (thermalMitigationAction) {
11474 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11475 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011476 handleDataThrottlingRequest(subId,
11477 thermalMitigationRequest.getDataThrottlingRequest(),
11478 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011479 break;
11480 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11481 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11482 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11483 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11484 }
11485
11486 // Ensure that radio is on. If not able to power on due to phone being
11487 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011488 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011489 thermalMitigationResult =
11490 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11491 break;
11492 }
11493
11494 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011495 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011496 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11497 break;
11498 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11499 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11500 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11501 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11502 }
11503
11504 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11505 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011506 Phone phone = getPhone(subId);
11507 if (phone == null) {
11508 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011509 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011510 break;
11511 }
11512
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011513 TelephonyConnectionService service =
11514 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011515 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011516 Log.e(LOG_TAG, "An emergency call is pending");
11517 thermalMitigationResult =
11518 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11519 break;
11520 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011521 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011522 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011523 break;
11524 }
11525 } else {
11526 thermalMitigationResult =
11527 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11528 break;
11529 }
11530
11531 // Turn radio off. If not able to power off due to phone being unavailable,
11532 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011533 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011534 thermalMitigationResult =
11535 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11536 break;
11537 }
11538 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011539 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011540 break;
11541 default:
11542 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11543 + "not exist. Requested action: " + thermalMitigationAction);
11544 }
11545 } catch (IllegalArgumentException e) {
11546 throw e;
11547 } catch (Exception e) {
11548 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11549 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11550 } finally {
11551 Binder.restoreCallingIdentity(identity);
11552 }
11553
11554 if (DBG) {
11555 log("thermalMitigationRequest returning with thermalMitigationResult: "
11556 + thermalMitigationResult);
11557 }
11558
11559 return thermalMitigationResult;
11560 }
Hui Wang641e81c2020-10-12 12:14:23 -070011561
11562 /**
11563 * Set the GbaService Package Name that Telephony will bind to.
11564 *
11565 * @param subId The sim that the GbaService is associated with.
11566 * @param packageName The name of the package to be replaced with.
11567 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11568 */
11569 @Override
11570 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11571 enforceModifyPermission();
11572
11573 final long identity = Binder.clearCallingIdentity();
11574 try {
11575 return getGbaManager(subId).overrideServicePackage(packageName);
11576 } finally {
11577 Binder.restoreCallingIdentity(identity);
11578 }
11579 }
11580
11581 /**
11582 * Return the package name of the currently bound GbaService.
11583 *
11584 * @param subId The sim that the GbaService is associated with.
11585 * @return the package name of the GbaService configuration, null if GBA is not supported.
11586 */
11587 @Override
11588 public String getBoundGbaService(int subId) {
11589 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11590
11591 final long identity = Binder.clearCallingIdentity();
11592 try {
11593 return getGbaManager(subId).getServicePackage();
11594 } finally {
11595 Binder.restoreCallingIdentity(identity);
11596 }
11597 }
11598
11599 /**
11600 * Set the release time for telephony to unbind GbaService.
11601 *
11602 * @param subId The sim that the GbaService is associated with.
11603 * @param interval The release time to unbind GbaService by millisecond.
11604 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11605 */
11606 @Override
11607 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11608 enforceModifyPermission();
11609
11610 final long identity = Binder.clearCallingIdentity();
11611 try {
11612 return getGbaManager(subId).overrideReleaseTime(interval);
11613 } finally {
11614 Binder.restoreCallingIdentity(identity);
11615 }
11616 }
11617
11618 /**
11619 * Return the release time for telephony to unbind GbaService.
11620 *
11621 * @param subId The sim that the GbaService is associated with.
11622 * @return The release time to unbind GbaService by millisecond.
11623 */
11624 @Override
11625 public int getGbaReleaseTime(int subId) {
11626 enforceReadPrivilegedPermission("getGbaReleaseTime");
11627
11628 final long identity = Binder.clearCallingIdentity();
11629 try {
11630 return getGbaManager(subId).getReleaseTime();
11631 } finally {
11632 Binder.restoreCallingIdentity(identity);
11633 }
11634 }
11635
11636 private GbaManager getGbaManager(int subId) {
11637 GbaManager instance = GbaManager.getInstance(subId);
11638 if (instance == null) {
11639 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11640 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11641 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11642 }
11643 return instance;
11644 }
Hui Wang761a6682020-10-31 05:12:53 +000011645
11646 /**
11647 * indicate whether the device and the carrier can support
11648 * RCS VoLTE single registration.
11649 */
11650 @Override
11651 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011652 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11653 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11654 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11655 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011656
11657 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11658 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11659 }
11660
11661 final long identity = Binder.clearCallingIdentity();
11662 try {
11663 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11664 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011665 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11666 if (isCapable != null) {
11667 return isCapable;
11668 }
Hui Wang761a6682020-10-31 05:12:53 +000011669 }
Hui Wang67af90e2021-06-04 16:57:15 -070011670 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11671 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011672 } finally {
11673 Binder.restoreCallingIdentity(identity);
11674 }
11675 }
11676
11677 /**
11678 * Register RCS provisioning callback.
11679 */
11680 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011681 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011682 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011683 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011684 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011685 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11686 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011687
11688 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11689 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11690 }
joonhunshin4ac60942023-11-15 15:23:39 +000011691 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11692 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11693 Binder.getCallingUserHandle())) {
11694 if (!isImsAvailableOnDevice()) {
11695 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11696 "IMS not available on device.");
11697 }
11698 } else {
11699 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11700 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011701 }
11702
11703 final long identity = Binder.clearCallingIdentity();
11704 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011705 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011706 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011707 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11708 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011709 }
Hui Wang761a6682020-10-31 05:12:53 +000011710 } finally {
11711 Binder.restoreCallingIdentity(identity);
11712 }
11713 }
11714
11715 /**
11716 * Unregister RCS provisioning callback.
11717 */
11718 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011719 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011720 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011721 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011722 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011723 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11724 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011725
11726 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11727 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11728 }
joonhunshin4ac60942023-11-15 15:23:39 +000011729
11730 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11731 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11732 Binder.getCallingUserHandle())) {
11733 if (!isImsAvailableOnDevice()) {
11734 // operation failed silently
11735 Rlog.w(LOG_TAG, "IMS not available on device.");
11736 return;
11737 }
11738 } else {
11739 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11740 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11741 "unregisterRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011742 }
11743
11744 final long identity = Binder.clearCallingIdentity();
11745 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011746 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011747 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011748 } finally {
11749 Binder.restoreCallingIdentity(identity);
11750 }
11751 }
11752
11753 /**
11754 * trigger RCS reconfiguration.
11755 */
11756 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011757 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11758 "triggerRcsReconfiguration",
11759 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011760
11761 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11762 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11763 }
joonhunshin4ac60942023-11-15 15:23:39 +000011764 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11765 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11766 Binder.getCallingUserHandle())) {
11767 if (!isImsAvailableOnDevice()) {
11768 // ProvisioningManager can not handle ServiceSpecificException.
11769 // Throw the IllegalStateException and annotate ProvisioningManager.
11770 throw new IllegalStateException("IMS not available on device.");
11771 }
11772 } else {
11773 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11774 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011775 }
11776
11777 final long identity = Binder.clearCallingIdentity();
11778 try {
11779 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11780 } finally {
11781 Binder.restoreCallingIdentity(identity);
11782 }
11783 }
11784
11785 /**
11786 * Provide the client configuration parameters of the RCS application.
11787 */
11788 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011789 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11790 "setRcsClientConfiguration",
11791 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011792
11793 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11794 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11795 }
joonhunshin4ac60942023-11-15 15:23:39 +000011796 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11797 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11798 Binder.getCallingUserHandle())) {
11799 if (!isImsAvailableOnDevice()) {
11800 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11801 "IMS not available on device.");
11802 }
11803 } else {
11804 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11805 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011806 }
11807
11808 final long identity = Binder.clearCallingIdentity();
11809
11810 try {
11811 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11812 if (configBinder == null) {
11813 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011814 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11815 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011816 } else {
11817 configBinder.setRcsClientConfiguration(rcc);
11818 }
joonhunshin3e154242021-09-17 06:33:39 +000011819
11820 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11821 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011822 } catch (RemoteException e) {
11823 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011824 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11825 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011826 } finally {
11827 Binder.restoreCallingIdentity(identity);
11828 }
11829 }
11830
11831 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011832 * Enables or disables the test mode for RCS VoLTE single registration.
11833 */
11834 @Override
11835 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11836 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11837 "setRcsSingleRegistrationTestModeEnabled");
11838
11839 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11840 }
11841
11842 /**
11843 * Gets the test mode for RCS VoLTE single registration.
11844 */
11845 @Override
11846 public boolean getRcsSingleRegistrationTestModeEnabled() {
11847 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11848 "getRcsSingleRegistrationTestModeEnabled");
11849
11850 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11851 }
11852
11853 /**
Hui Wang761a6682020-10-31 05:12:53 +000011854 * Overrides the config of RCS VoLTE single registration enabled for the device.
11855 */
11856 @Override
11857 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11858 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11859 "setDeviceSingleRegistrationEnabledOverride");
11860 enforceModifyPermission();
11861
11862 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11863 : Boolean.parseBoolean(enabledStr);
11864 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011865 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011866 }
11867
11868 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011869 * Sends a device to device communication message. Only usable via shell.
11870 * @param message message to send.
11871 * @param value message value.
11872 */
11873 @Override
11874 public void sendDeviceToDeviceMessage(int message, int value) {
11875 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011876 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011877 enforceModifyPermission();
11878
11879 final long identity = Binder.clearCallingIdentity();
11880 try {
11881 TelephonyConnectionService service =
11882 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11883 if (service == null) {
11884 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11885 return;
11886 }
11887 service.sendTestDeviceToDeviceMessage(message, value);
11888 } finally {
11889 Binder.restoreCallingIdentity(identity);
11890 }
11891 }
11892
Tyler Gunnbabbda02021-02-10 11:05:02 -080011893 /**
11894 * Sets the specified device to device transport active.
11895 * @param transport The transport to set active.
11896 */
11897 @Override
11898 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11899 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11900 "setActiveDeviceToDeviceTransport");
11901 enforceModifyPermission();
11902
11903 final long identity = Binder.clearCallingIdentity();
11904 try {
11905 TelephonyConnectionService service =
11906 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11907 if (service == null) {
11908 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11909 return;
11910 }
11911 service.setActiveDeviceToDeviceTransport(transport);
11912 } finally {
11913 Binder.restoreCallingIdentity(identity);
11914 }
11915 }
Tyler Gunn92479152021-01-20 16:30:10 -080011916
Tyler Gunnd4339262021-05-03 14:46:49 -070011917 @Override
11918 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11919 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11920 "setDeviceToDeviceForceEnabled");
11921
11922 final long identity = Binder.clearCallingIdentity();
11923 try {
11924 Arrays.stream(PhoneFactory.getPhones()).forEach(
11925 p -> {
11926 Phone thePhone = p.getImsPhone();
11927 if (thePhone != null && thePhone instanceof ImsPhone) {
11928 ImsPhone imsPhone = (ImsPhone) thePhone;
11929 CallTracker tracker = imsPhone.getCallTracker();
11930 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11931 ImsPhoneCallTracker imsPhoneCallTracker =
11932 (ImsPhoneCallTracker) tracker;
11933 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11934 }
11935 }
11936 }
11937 );
11938 } finally {
11939 Binder.restoreCallingIdentity(identity);
11940 }
11941 }
11942
Tyler Gunn92479152021-01-20 16:30:10 -080011943 /**
Hui Wang761a6682020-10-31 05:12:53 +000011944 * Gets the config of RCS VoLTE single registration enabled for the device.
11945 */
11946 @Override
11947 public boolean getDeviceSingleRegistrationEnabled() {
11948 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11949 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11950 }
11951
11952 /**
11953 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11954 */
11955 @Override
11956 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11957 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11958 "setCarrierSingleRegistrationEnabledOverride");
11959 enforceModifyPermission();
11960
11961 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11962 : Boolean.parseBoolean(enabledStr);
11963 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11964 subId, enabled);
11965 }
11966
11967 /**
11968 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11969 */
11970 @Override
11971 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11972 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11973 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11974 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011975
11976 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011977 * Overrides the ims feature validation result
11978 */
11979 @Override
11980 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11981 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11982 "setImsFeatureValidationOverride");
11983
11984 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11985 : Boolean.parseBoolean(enabledStr);
11986 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11987 subId, enabled);
11988 }
11989
11990 /**
11991 * Gets the ims feature validation override value
11992 */
11993 @Override
11994 public boolean getImsFeatureValidationOverride(int subId) {
11995 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11996 "getImsFeatureValidationOverride");
11997 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11998 }
11999
12000 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080012001 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
12002 * their mobile plan.
12003 */
12004 @Override
12005 public String getMobileProvisioningUrl() {
12006 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
12007 final long identity = Binder.clearCallingIdentity();
12008 try {
12009 return getDefaultPhone().getMobileProvisioningUrl();
12010 } finally {
12011 Binder.restoreCallingIdentity(identity);
12012 }
12013 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012014
James.cf Linbcdf8b32021-01-14 16:44:13 +080012015 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080012016 * Get the EAB contact from the EAB database.
12017 */
12018 @Override
12019 public String getContactFromEab(String contact) {
12020 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
12021 enforceModifyPermission();
12022 final long identity = Binder.clearCallingIdentity();
12023 try {
12024 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
12025 } finally {
12026 Binder.restoreCallingIdentity(identity);
12027 }
12028 }
12029
12030 /**
Calvin Pana1434322021-07-01 19:27:01 +080012031 * Get the EAB capability from the EAB database.
12032 */
12033 @Override
12034 public String getCapabilityFromEab(String contact) {
12035 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
12036 enforceModifyPermission();
12037 final long identity = Binder.clearCallingIdentity();
12038 try {
12039 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
12040 } finally {
12041 Binder.restoreCallingIdentity(identity);
12042 }
12043 }
12044
12045 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080012046 * Remove the EAB contacts from the EAB database.
12047 */
12048 @Override
12049 public int removeContactFromEab(int subId, String contacts) {
12050 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
12051 enforceModifyPermission();
12052 final long identity = Binder.clearCallingIdentity();
12053 try {
12054 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
12055 } finally {
12056 Binder.restoreCallingIdentity(identity);
12057 }
12058 }
12059
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012060 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080012061 public boolean getDeviceUceEnabled() {
12062 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
12063 final long identity = Binder.clearCallingIdentity();
12064 try {
12065 return mApp.getDeviceUceEnabled();
12066 } finally {
12067 Binder.restoreCallingIdentity(identity);
12068 }
12069 }
12070
12071 @Override
12072 public void setDeviceUceEnabled(boolean isEnabled) {
12073 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
12074 final long identity = Binder.clearCallingIdentity();
12075 try {
12076 mApp.setDeviceUceEnabled(isEnabled);
12077 } finally {
12078 Binder.restoreCallingIdentity(identity);
12079 }
12080 }
12081
Brad Ebinger14d467f2021-02-12 06:18:28 +000012082 /**
12083 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
12084 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12085 */
12086 // Used for SHELL command only right now.
12087 @Override
12088 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
12089 List<String> featureTags) {
12090 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12091 "addUceRegistrationOverrideShell");
12092 final long identity = Binder.clearCallingIdentity();
12093 try {
12094 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
12095 new ArraySet<>(featureTags));
12096 } catch (ImsException e) {
12097 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12098 } finally {
12099 Binder.restoreCallingIdentity(identity);
12100 }
12101 }
12102
12103 /**
12104 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
12105 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12106 */
12107 // Used for SHELL command only right now.
12108 @Override
12109 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
12110 List<String> featureTags) {
12111 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12112 "removeUceRegistrationOverrideShell");
12113 final long identity = Binder.clearCallingIdentity();
12114 try {
12115 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
12116 new ArraySet<>(featureTags));
12117 } catch (ImsException e) {
12118 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12119 } finally {
12120 Binder.restoreCallingIdentity(identity);
12121 }
12122 }
12123
12124 /**
12125 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
12126 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12127 */
12128 // Used for SHELL command only right now.
12129 @Override
12130 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
12131 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12132 "clearUceRegistrationOverrideShell");
12133 final long identity = Binder.clearCallingIdentity();
12134 try {
12135 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
12136 } catch (ImsException e) {
12137 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12138 } finally {
12139 Binder.restoreCallingIdentity(identity);
12140 }
12141 }
12142
12143 /**
12144 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12145 */
12146 // Used for SHELL command only right now.
12147 @Override
12148 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
12149 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12150 "getLatestRcsContactUceCapabilityShell");
12151 final long identity = Binder.clearCallingIdentity();
12152 try {
12153 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
12154 } catch (ImsException e) {
12155 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12156 } finally {
12157 Binder.restoreCallingIdentity(identity);
12158 }
12159 }
12160
12161 /**
12162 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
12163 * device does not have an active PUBLISH.
12164 */
12165 // Used for SHELL command only right now.
12166 @Override
12167 public String getLastUcePidfXmlShell(int subId) {
12168 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
12169 final long identity = Binder.clearCallingIdentity();
12170 try {
12171 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
12172 } catch (ImsException e) {
12173 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12174 } finally {
12175 Binder.restoreCallingIdentity(identity);
12176 }
12177 }
12178
James.cf Line8713a42021-04-29 16:04:26 +080012179 /**
12180 * Remove UCE requests cannot be sent to the network status.
12181 */
12182 // Used for SHELL command only right now.
12183 @Override
12184 public boolean removeUceRequestDisallowedStatus(int subId) {
12185 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
12186 final long identity = Binder.clearCallingIdentity();
12187 try {
12188 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
12189 } catch (ImsException e) {
12190 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12191 } finally {
12192 Binder.restoreCallingIdentity(identity);
12193 }
12194 }
12195
James.cf Lin18bb9002021-05-25 01:37:38 +080012196 /**
12197 * Remove UCE requests cannot be sent to the network status.
12198 */
12199 // Used for SHELL command only.
12200 @Override
12201 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
12202 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
12203 final long identity = Binder.clearCallingIdentity();
12204 try {
12205 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
12206 } catch (ImsException e) {
12207 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12208 } finally {
12209 Binder.restoreCallingIdentity(identity);
12210 }
12211 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000012212
James.cf Lin4b784aa2021-01-31 03:25:15 +080012213 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012214 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12215 String callingPackage) {
12216 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12217 mApp, subId, "setSignalStrengthUpdateRequest");
12218
joonhunshin4ac60942023-11-15 15:23:39 +000012219 enforceTelephonyFeatureWithException(callingPackage,
12220 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest");
12221
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012222 final int callingUid = Binder.getCallingUid();
12223 // Verify that tha callingPackage belongs to the calling UID
12224 mApp.getSystemService(AppOpsManager.class)
12225 .checkPackage(callingUid, callingPackage);
12226
Rambo Wang3607f502021-02-01 21:51:40 -080012227 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012228
12229 final long identity = Binder.clearCallingIdentity();
12230 try {
12231 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
12232 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12233
12234 if (result instanceof IllegalStateException) {
12235 throw (IllegalStateException) result;
12236 }
12237 } finally {
12238 Binder.restoreCallingIdentity(identity);
12239 }
12240 }
12241
12242 @Override
12243 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12244 String callingPackage) {
12245 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12246 mApp, subId, "clearSignalStrengthUpdateRequest");
12247
joonhunshin4ac60942023-11-15 15:23:39 +000012248 enforceTelephonyFeatureWithException(callingPackage,
12249 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest");
12250
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012251 final int callingUid = Binder.getCallingUid();
12252 // Verify that tha callingPackage belongs to the calling UID
12253 mApp.getSystemService(AppOpsManager.class)
12254 .checkPackage(callingUid, callingPackage);
12255
12256 final long identity = Binder.clearCallingIdentity();
12257 try {
12258 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
12259 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12260
12261 if (result instanceof IllegalStateException) {
12262 throw (IllegalStateException) result;
12263 }
12264 } finally {
12265 Binder.restoreCallingIdentity(identity);
12266 }
12267 }
12268
Rambo Wang3607f502021-02-01 21:51:40 -080012269 private static void validateSignalStrengthUpdateRequest(Context context,
12270 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012271 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
12272 // phone/system process do not have further restriction on request
12273 return;
12274 }
12275
12276 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080012277 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012278 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080012279 context.enforceCallingOrSelfPermission(
12280 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
12281 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012282 }
12283
12284 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000012285 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012286 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012287 || info.isEnabled()) {
12288 throw new IllegalArgumentException(
12289 "Only system can set hide fields in SignalThresholdInfo");
12290 }
12291
12292 // Thresholds length for each RAN need in range. This has been validated in
12293 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
12294 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
12295 final int[] thresholds = info.getThresholds();
12296 Objects.requireNonNull(thresholds);
12297 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
12298 || thresholds.length
12299 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
12300 throw new IllegalArgumentException(
12301 "thresholds length is out of range: " + thresholds.length);
12302 }
12303 }
12304 }
SongFerngWang8236caa2021-01-17 21:51:44 +080012305
12306 /**
12307 * Gets the current phone capability.
12308 *
12309 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
12310 * @return the PhoneCapability which describes the data connection capability of modem.
12311 * It's used to evaluate possible phone config change, for example from single
12312 * SIM device to multi-SIM device.
12313 */
12314 @Override
12315 public PhoneCapability getPhoneCapability() {
12316 enforceReadPrivilegedPermission("getPhoneCapability");
joonhunshin4ac60942023-11-15 15:23:39 +000012317
12318 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12319 PackageManager.FEATURE_TELEPHONY, "getPhoneCapability");
12320
SongFerngWang8236caa2021-01-17 21:51:44 +080012321 final long identity = Binder.clearCallingIdentity();
12322 try {
12323 return mPhoneConfigurationManager.getCurrentPhoneCapability();
12324 } finally {
12325 Binder.restoreCallingIdentity(identity);
12326 }
12327 }
Michele Berionne5e411512020-11-13 02:36:59 +000012328
12329 /**
12330 * Prepare TelephonyManager for an unattended reboot. The reboot is
12331 * required to be done shortly after the API is invoked.
12332 */
12333 @Override
12334 @TelephonyManager.PrepareUnattendedRebootResult
12335 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012336 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000012337 enforceRebootPermission();
12338
joonhunshin4ac60942023-11-15 15:23:39 +000012339 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12340 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot");
12341
Michele Berionne5e411512020-11-13 02:36:59 +000012342 final long identity = Binder.clearCallingIdentity();
12343 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012344 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000012345 } finally {
12346 Binder.restoreCallingIdentity(identity);
12347 }
12348 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012349
12350 /**
12351 * Request to get the current slicing configuration including URSP rules and
12352 * NSSAIs (configured, allowed and rejected).
12353 *
12354 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
12355 */
12356 @Override
12357 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000012358 TelephonyPermissions
12359 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
12360 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012361
joonhunshin4ac60942023-11-15 15:23:39 +000012362 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12363 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
12364 "getSlicingConfig");
12365
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012366 final long identity = Binder.clearCallingIdentity();
12367 try {
12368 Phone phone = getDefaultPhone();
12369 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
12370 } finally {
12371 Binder.restoreCallingIdentity(identity);
12372 }
12373 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012374
12375 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070012376 * Check whether the given premium capability is available for purchase from the carrier.
12377 *
12378 * @param capability The premium capability to check.
12379 * @param subId The subId to check the premium capability for.
12380 *
12381 * @return Whether the given premium capability is available to purchase.
12382 */
12383 @Override
12384 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
12385 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12386 mApp, "isPremiumCapabilityAvailableForPurchase")) {
12387 log("Premium capability "
12388 + TelephonyManager.convertPremiumCapabilityToString(capability)
12389 + " is not available for purchase due to missing permissions.");
12390 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
12391 + "permission READ_BASIC_PHONE_STATE.");
12392 }
12393
joonhunshin4ac60942023-11-15 15:23:39 +000012394 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12395 PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase");
12396
Sarah Chin2ec39f62022-08-31 17:03:26 -070012397 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080012398 if (phone == null) {
12399 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12400 return false;
12401 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012402 final long identity = Binder.clearCallingIdentity();
12403 try {
Sarah Chincc5446f2023-10-23 17:57:19 -070012404 return SlicePurchaseController.getInstance(phone, mFeatureFlags)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012405 .isPremiumCapabilityAvailableForPurchase(capability);
12406 } finally {
12407 Binder.restoreCallingIdentity(identity);
12408 }
12409 }
12410
12411 /**
12412 * Purchase the given premium capability from the carrier.
12413 *
12414 * @param capability The premium capability to purchase.
12415 * @param callback The result of the purchase request.
12416 * @param subId The subId to purchase the premium capability for.
12417 */
12418 @Override
12419 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12420 log("purchasePremiumCapability: capability="
12421 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12422 + getCurrentPackageName());
12423
12424 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12425 mApp, "purchasePremiumCapability")) {
12426 log("purchasePremiumCapability "
12427 + TelephonyManager.convertPremiumCapabilityToString(capability)
12428 + " failed due to missing permissions.");
12429 throw new SecurityException("purchasePremiumCapability requires permission "
12430 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012431 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12432 mApp, "purchasePremiumCapability")) {
12433 log("purchasePremiumCapability "
12434 + TelephonyManager.convertPremiumCapabilityToString(capability)
12435 + " failed due to missing permissions.");
12436 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012437 }
12438
joonhunshin4ac60942023-11-15 15:23:39 +000012439 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12440 PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability");
12441
Sarah Chin2ec39f62022-08-31 17:03:26 -070012442 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012443 if (phone == null) {
12444 try {
12445 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12446 callback.accept(result);
12447 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12448 } catch (RemoteException e) {
12449 String logStr = "Purchase premium capability "
12450 + TelephonyManager.convertPremiumCapabilityToString(capability)
12451 + " failed due to RemoteException handling null phone: " + e;
12452 if (DBG) log(logStr);
12453 AnomalyReporter.reportAnomaly(
12454 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12455 }
12456 return;
12457 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012458
12459 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012460 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012461 callingProcess = mApp.getPackageManager().getApplicationInfo(
12462 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070012463 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012464 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012465 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012466
12467 boolean isVisible = false;
12468 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12469 if (am != null) {
12470 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12471 if (processes != null) {
12472 for (ActivityManager.RunningAppProcessInfo process : processes) {
12473 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070012474 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080012475 if (process.processName.equals(callingProcess) && process.importance
12476 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12477 isVisible = true;
12478 break;
12479 }
12480 }
12481 }
12482 }
12483
12484 if (!isVisible) {
12485 try {
12486 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12487 callback.accept(result);
12488 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12489 } catch (RemoteException e) {
12490 String logStr = "Purchase premium capability "
12491 + TelephonyManager.convertPremiumCapabilityToString(capability)
12492 + " failed due to RemoteException handling background application: " + e;
12493 if (DBG) log(logStr);
12494 AnomalyReporter.reportAnomaly(
12495 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12496 }
12497 return;
12498 }
12499
Sarah Chin71b3a852022-09-28 15:54:19 -070012500 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012501 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012502 }
12503
12504 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012505 * Register an IMS connection state callback
12506 */
12507 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012508 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12509 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012510 if (feature == ImsFeature.FEATURE_MMTEL) {
12511 // ImsMmTelManager
12512 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12513 TelephonyPermissions
12514 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12515 mApp, subId, "registerImsStateCallback");
12516 } else if (feature == ImsFeature.FEATURE_RCS) {
12517 // ImsRcsManager or SipDelegateManager
12518 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12519 Binder.getCallingUid(), "registerImsStateCallback",
12520 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12521 Manifest.permission.READ_PRECISE_PHONE_STATE,
12522 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12523 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12524 }
12525
12526 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12527 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12528 "IMS not available on device.");
12529 }
12530
12531 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12532 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12533 }
12534
12535 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12536 if (controller == null) {
12537 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12538 "IMS not available on device.");
12539 }
12540
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012541 if (callingPackage == null) {
12542 callingPackage = getCurrentPackageName();
12543 }
12544
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012545 final long token = Binder.clearCallingIdentity();
12546 try {
12547 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012548 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012549 } catch (ImsException e) {
12550 throw new ServiceSpecificException(e.getCode());
12551 } finally {
12552 Binder.restoreCallingIdentity(token);
12553 }
12554 }
12555
12556 /**
12557 * Unregister an IMS connection state callback
12558 */
12559 @Override
12560 public void unregisterImsStateCallback(IImsStateCallback cb) {
12561 final long token = Binder.clearCallingIdentity();
12562 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12563 if (controller == null) {
12564 return;
12565 }
12566 try {
12567 controller.unregisterImsStateCallback(cb);
12568 } finally {
12569 Binder.restoreCallingIdentity(token);
12570 }
12571 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012572
12573 /**
12574 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12575 *
12576 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012577 * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012578 * SecurityException.
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012579 *
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012580 * If there is current registered network this value will be same as the registered cell
12581 * identity. If the device goes out of service the previous cell identity is cached and
12582 * will be returned. If the cache age of the Cell identity is more than 24 hours
12583 * it will be cleared and null will be returned.
12584 *
12585 */
12586 @Override
12587 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12588 String callingFeatureId) {
12589 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12590 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12591 LocationAccessPolicy.checkLocationPermission(mApp,
12592 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12593 .setCallingPackage(callingPackage)
12594 .setCallingFeatureId(callingFeatureId)
12595 .setCallingPid(Binder.getCallingPid())
12596 .setCallingUid(Binder.getCallingUid())
12597 .setMethod("getLastKnownCellIdentity")
12598 .setLogAsInfo(true)
12599 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12600 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12601 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12602 .build());
12603
12604 boolean hasFinePermission =
12605 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12606 if (!hasFinePermission
12607 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12608 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012609 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012610 }
12611
12612 final long identity = Binder.clearCallingIdentity();
12613 try {
Ling Mac28f0212023-03-24 16:07:15 -070012614 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012615 if (sst == null) return null;
12616 return sst.getLastKnownCellIdentity();
12617 } finally {
12618 Binder.restoreCallingIdentity(identity);
12619 }
12620 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012621
jimsun3b9ccac2021-10-26 15:01:23 +080012622 /**
12623 * Sets the modem service class Name that Telephony will bind to.
12624 *
12625 * @param serviceName The class name of the modem service.
12626 * @return true if the operation is succeed, otherwise false.
12627 */
12628 public boolean setModemService(String serviceName) {
12629 Log.d(LOG_TAG, "setModemService - " + serviceName);
12630 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12631 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012632 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12633 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012634 return mPhoneConfigurationManager.setModemService(serviceName);
12635 }
12636
12637 /**
12638 * Return the class name of the currently bounded modem service.
12639 *
12640 * @return the class name of the modem service.
12641 */
12642 public String getModemService() {
12643 String result;
12644 Log.d(LOG_TAG, "getModemService");
12645 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12646 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012647 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012648 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12649 "getModemService");
12650 result = mPhoneConfigurationManager.getModemService();
12651 Log.d(LOG_TAG, "result = " + result);
12652 return result;
12653 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012654
Hakjun Choi3ee81112023-12-19 15:40:58 +000012655 /**
12656 * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources,
12657 * including carrier config, entitlement server, and config update.
12658 *
12659 * @param subId subId The subscription ID of the carrier.
12660 *
12661 * @return List of plmns for carrier satellite service. If no plmn is available, empty list will
12662 * be returned.
12663 *
12664 * @throws SecurityException if the caller doesn't have the required permission.
12665 */
Hakjun Choi74c16be2024-01-19 08:18:09 +000012666 @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) {
12667 enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier");
Hakjun Choi3ee81112023-12-19 15:40:58 +000012668 final long identity = Binder.clearCallingIdentity();
12669 try {
Hakjun Choi74c16be2024-01-19 08:18:09 +000012670 return mSatelliteController.getSatellitePlmnsForCarrier(subId);
Hakjun Choi3ee81112023-12-19 15:40:58 +000012671 } finally {
12672 Binder.restoreCallingIdentity(identity);
12673 }
12674 }
12675
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012676 @Override
12677 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12678 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12679 mApp.enforceCallingOrSelfPermission(
12680 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12681 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12682
12683 final long identity = Binder.clearCallingIdentity();
12684 try {
12685 Phone phone = getPhone(subId);
12686 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012687 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12688 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012689 phone.setVoiceServiceStateOverride(hasService);
12690 } finally {
12691 Binder.restoreCallingIdentity(identity);
12692 }
12693 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012694
12695 /**
12696 * set removable eSIM as default eUICC.
12697 *
12698 * @hide
12699 */
12700 @Override
12701 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12702 enforceModifyPermission();
12703 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12704
12705 final long identity = Binder.clearCallingIdentity();
12706 try {
12707 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12708 } finally {
12709 Binder.restoreCallingIdentity(identity);
12710 }
12711 }
12712
12713 /**
12714 * Returns whether the removable eSIM is default eUICC or not.
12715 *
12716 * @hide
12717 */
12718 @Override
12719 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12720 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12721 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12722
12723 final long identity = Binder.clearCallingIdentity();
12724 try {
12725 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12726 } finally {
12727 Binder.restoreCallingIdentity(identity);
12728 }
12729 }
12730
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012731 /**
12732 * Get the component name of the default app to direct respond-via-message intent for the
12733 * user associated with this subscription, update the cache if there is no respond-via-message
12734 * application currently configured for this user.
12735 * @return component name of the app and class to direct Respond Via Message intent to, or
12736 * {@code null} if the functionality is not supported.
12737 * @hide
12738 */
12739 @Override
12740 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12741 boolean updateIfNeeded) {
12742 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012743
joonhunshin4ac60942023-11-15 15:23:39 +000012744 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12745 PackageManager.FEATURE_TELEPHONY_MESSAGING,
12746 "getDefaultRespondViaMessageApplication");
12747
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012748 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12749
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012750 UserHandle userHandle = null;
12751 final long identity = Binder.clearCallingIdentity();
12752 try {
12753 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12754 } finally {
12755 Binder.restoreCallingIdentity(identity);
12756 }
12757 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12758 updateIfNeeded, userHandle);
12759 }
Jack Yuf5badd92022-12-08 00:50:53 -080012760
12761 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012762 * Set whether the device is able to connect with null ciphering or integrity
12763 * algorithms. This is a global setting and will apply to all active subscriptions
12764 * and all new subscriptions after this.
12765 *
12766 * @param enabled when true, null cipher and integrity algorithms are allowed.
12767 * @hide
12768 */
12769 @Override
12770 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12771 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12772 enforceModifyPermission();
12773 checkForNullCipherAndIntegritySupport();
12774
12775 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12776 // for listening to these preference changes and applying them immediately.
12777 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12778 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12779 editor.apply();
12780
12781 for (Phone phone: PhoneFactory.getPhones()) {
12782 phone.handleNullCipherEnabledChange();
12783 }
12784 }
12785
12786
12787 /**
12788 * Get whether the device is able to connect with null ciphering or integrity
12789 * algorithms. Note that this retrieves the phone-global preference and not
12790 * the state of the radio.
12791 *
12792 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12793 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12794 * version for this feature.
12795 * @hide
12796 */
12797 @Override
12798 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12799 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12800 enforceReadPermission();
12801 checkForNullCipherAndIntegritySupport();
12802 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12803 }
12804
12805 private void checkForNullCipherAndIntegritySupport() {
12806 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12807 throw new UnsupportedOperationException(
12808 "Null cipher and integrity operations require HAL 2.1 or above");
12809 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012810 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12811 throw new UnsupportedOperationException(
12812 "Null cipher and integrity operations unsupported by modem");
12813 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012814 }
12815
Gil Cukierman06403e12023-11-29 16:33:03 +000012816 private void checkForIdentifierDisclosureNotificationSupport() {
12817 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) {
12818 throw new UnsupportedOperationException(
12819 "Cellular identifier disclosure transparency operations require HAL 2.2 or "
12820 + "above");
12821 }
12822 if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) {
12823 throw new UnsupportedOperationException(
12824 "Cellular identifier disclosure transparency operations unsupported by modem");
12825 }
12826 }
12827
Michael Groover826b71d2023-12-21 22:08:06 -060012828 private void checkForNullCipherNotificationSupport() {
12829 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) {
12830 throw new UnsupportedOperationException(
12831 "Null cipher notification operations require HAL 2.2 or above");
12832 }
12833 if (!getDefaultPhone().isNullCipherNotificationSupported()) {
12834 throw new UnsupportedOperationException(
12835 "Null cipher notification operations unsupported by modem");
12836 }
12837 }
12838
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012839 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012840 * Get the SIM state for the slot index.
12841 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12842 *
12843 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12844 */
12845 @Override
12846 @SimState
12847 public int getSimStateForSlotIndex(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +000012848 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12849 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex");
12850
Jack Yuf5badd92022-12-08 00:50:53 -080012851 IccCardConstants.State simState;
12852 if (slotIndex < 0) {
12853 simState = IccCardConstants.State.UNKNOWN;
12854 } else {
12855 Phone phone = null;
12856 try {
12857 phone = PhoneFactory.getPhone(slotIndex);
12858 } catch (IllegalStateException e) {
12859 // ignore
12860 }
12861 if (phone == null) {
12862 simState = IccCardConstants.State.UNKNOWN;
12863 } else {
12864 IccCard icc = phone.getIccCard();
12865 if (icc == null) {
12866 simState = IccCardConstants.State.UNKNOWN;
12867 } else {
12868 simState = icc.getState();
12869 }
12870 }
12871 }
12872 return simState.ordinal();
12873 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012874
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012875 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
12876 boolean enableLogcat,
12877 long logcatStartTimestampMillis, boolean enableTelecomDump,
12878 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012879 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012880 TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder =
12881 new TelephonyManager.EmergencyCallDiagnosticData.Builder();
12882 ecdDataBuilder
12883 .setTelecomDumpsysCollectionEnabled(enableTelecomDump)
12884 .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012885 if (enableLogcat) {
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012886 ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012887 }
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012888 TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build();
12889 Log.d(LOG_TAG, "persisting with Params " + ecdData.toString());
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012890 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
12891 Executors.newCachedThreadPool(), db,
12892 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012893 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012894 }
12895
12896 /**
12897 * Request telephony to persist state for debugging emergency call failures.
12898 *
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012899 * @param dropboxTag Tag to use when persisting data to dropbox service.
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012900 * @param enableLogcat whether to collect logcat output
12901 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
12902 * @param enableTelecomDump whether to collect telecom dumpsys
12903 * @param enableTelephonyDump whether to collect telephony dumpsys
12904 */
12905 @Override
12906 @RequiresPermission(android.Manifest.permission.DUMP)
12907 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
12908 long logcatStartTimestampMillis, boolean enableTelecomDump,
12909 boolean enableTelephonyDump) {
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -080012910 // Verify that the caller has READ_DROPBOX_DATA permission.
12911 if (mTelecomFeatureFlags.telecomResolveHiddenDependencies()
12912 && Flags.enableReadDropboxPermission()) {
12913 mApp.enforceCallingPermission(permission.READ_DROPBOX_DATA,
12914 "persistEmergencyCallDiagnosticData");
12915 } else {
12916 // Otherwise, enforce legacy permission.
12917 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
12918 "persistEmergencyCallDiagnosticData");
12919 }
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012920 final long identity = Binder.clearCallingIdentity();
12921 try {
12922 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
12923 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
12924
12925 } finally {
12926 Binder.restoreCallingIdentity(identity);
12927 }
12928 }
12929
Hui Wang9b5793a2022-12-05 14:38:06 -060012930 /**
12931 * Get current cell broadcast ranges.
12932 */
12933 @Override
12934 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12935 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12936 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12937 "getCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012938
12939 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12940 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges");
12941
Hui Wang9b5793a2022-12-05 14:38:06 -060012942 final long identity = Binder.clearCallingIdentity();
12943 try {
12944 return getPhone(subId).getCellBroadcastIdRanges();
12945 } finally {
12946 Binder.restoreCallingIdentity(identity);
12947 }
12948 }
12949
12950 /**
12951 * Set reception of cell broadcast messages with the list of the given ranges
12952 *
12953 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12954 */
12955 @Override
12956 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12957 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12958 @Nullable IIntegerConsumer callback) {
12959 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12960 "setCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012961
12962 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12963 PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges");
12964
Hui Wang9b5793a2022-12-05 14:38:06 -060012965 final long identity = Binder.clearCallingIdentity();
12966 try {
12967 Phone phone = getPhoneFromSubId(subId);
12968 if (DBG) {
12969 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12970 }
12971 phone.setCellBroadcastIdRanges(ranges, result -> {
12972 if (callback != null) {
12973 try {
12974 callback.accept(result);
12975 } catch (RemoteException e) {
12976 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12977 }
12978 }
12979 });
12980 } finally {
12981 Binder.restoreCallingIdentity(identity);
12982 }
12983 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012984
12985 /**
12986 * Returns whether the device supports the domain selection service.
12987 *
12988 * @return {@code true} if the device supports the domain selection service.
12989 */
12990 @Override
12991 public boolean isDomainSelectionSupported() {
12992 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12993 "isDomainSelectionSupported");
12994
12995 final long identity = Binder.clearCallingIdentity();
12996 try {
12997 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12998 } finally {
12999 Binder.restoreCallingIdentity(identity);
13000 }
13001 }
arunvoddud5c6ce02022-12-11 06:03:12 +000013002
13003 /**
Hunsuk Choi9c69a802024-04-11 20:39:23 +000013004 * Returns whether the AOSP domain selection service is supported.
13005 *
13006 * @return {@code true} if the AOSP domain selection service is supported,
13007 * {@code false} otherwise.
13008 */
13009 @Override
13010 public boolean isAospDomainSelectionService() {
13011 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
13012 "isAospDomainSelectionService");
13013
13014 final long identity = Binder.clearCallingIdentity();
13015 try {
13016 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13017 String dssComponentName = mApp.getResources().getString(
13018 R.string.config_domain_selection_service_component_name);
13019 ComponentName componentName = ComponentName.createRelative(mApp.getPackageName(),
13020 TelephonyDomainSelectionService.class.getName());
13021 Log.i(LOG_TAG, "isAospDomainSelectionService dss=" + dssComponentName
13022 + ", aosp=" + componentName.flattenToString());
13023 return TextUtils.equals(componentName.flattenToString(), dssComponentName);
13024 }
13025 } finally {
13026 Binder.restoreCallingIdentity(identity);
13027 }
13028 return false;
13029 }
13030
13031 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013032 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
13033 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
13034 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080013035 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013036 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chinabf081b2023-03-09 23:00:57 -080013037 * @param enableSatellite {@code true} to enable the satellite modem and
13038 * {@code false} to disable.
13039 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
Thomas Nguyena8062672024-02-05 14:18:19 -080013040 * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise.
Sarah Chinabf081b2023-03-09 23:00:57 -080013041 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080013042 *
13043 * @throws SecurityException if the caller doesn't have the required permission.
13044 */
13045 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013046 public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode,
Thomas Nguyena8062672024-02-05 14:18:19 -080013047 boolean isEmergency, @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013048 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013049 if (enableSatellite) {
13050 ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) {
13051 @Override
13052 protected void onReceiveResult(int resultCode, Bundle resultData) {
13053 Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode
13054 + ", resultData=" + resultData);
13055 boolean isAllowed = false;
13056 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(
13057 callback::accept);
13058 if (resultCode == SATELLITE_RESULT_SUCCESS) {
13059 if (resultData != null
13060 && resultData.containsKey(KEY_SATELLITE_COMMUNICATION_ALLOWED)) {
13061 isAllowed = resultData.getBoolean(KEY_SATELLITE_COMMUNICATION_ALLOWED);
13062 } else {
13063 loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist.");
13064 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013065 } else {
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013066 result.accept(resultCode);
13067 return;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013068 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013069 if (isAllowed) {
13070 mSatelliteController.requestSatelliteEnabled(
Hyosun Kimab304792024-03-29 09:18:03 +000013071 subId, enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013072 } else {
13073 result.accept(SATELLITE_RESULT_ACCESS_BARRED);
13074 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013075 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013076 };
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013077 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013078 subId, resultReceiver);
13079 } else {
13080 // No need to check if satellite is allowed at current location when disabling satellite
13081 mSatelliteController.requestSatelliteEnabled(
Hyosun Kimab304792024-03-29 09:18:03 +000013082 subId, enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013083 }
Sarah Chin503828c2023-02-01 23:54:20 -080013084 }
13085
13086 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013087 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080013088 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013089 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013090 * @param result The result receiver that returns whether the satellite modem is enabled
13091 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013092 *
13093 * @throws SecurityException if the caller doesn't have the required permission.
13094 */
13095 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013096 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
13097 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013098 mSatelliteController.requestIsSatelliteEnabled(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013099 }
13100
13101 /**
Sarah Chin43457982023-02-15 17:50:38 -080013102 * Request to get whether the satellite service demo mode is enabled.
13103 *
13104 * @param subId The subId of the subscription to check whether the satellite demo mode
13105 * is enabled for.
13106 * @param result The result receiver that returns whether the satellite demo mode is enabled
13107 * if the request is successful or an error code if the request failed.
13108 *
13109 * @throws SecurityException if the caller doesn't have the required permission.
13110 */
13111 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013112 public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
13113 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
13114 mSatelliteController.requestIsDemoModeEnabled(subId, result);
Sarah Chin43457982023-02-15 17:50:38 -080013115 }
13116
13117 /**
Thomas Nguyena8062672024-02-05 14:18:19 -080013118 * Request to get whether the satellite service is enabled with emergency mode.
13119 *
13120 * @param subId The subId of the subscription to check whether the satellite demo mode
13121 * is enabled for.
13122 * @param result The result receiver that returns whether the satellite emergency mode is
13123 * enabled if the request is successful or an error code if the request failed.
13124 *
13125 * @throws SecurityException if the caller doesn't have the required permission.
13126 */
13127 @Override
13128 public void requestIsEmergencyModeEnabled(int subId, @NonNull ResultReceiver result) {
13129 enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled");
13130 result.send(SATELLITE_RESULT_REQUEST_NOT_SUPPORTED, null);
13131 }
13132
13133 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013134 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080013135 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013136 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013137 * @param result The result receiver that returns whether the satellite service is supported on
13138 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013139 */
13140 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013141 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013142 mSatelliteController.requestIsSatelliteSupported(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013143 }
13144
13145 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013146 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080013147 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013148 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013149 * @param result The result receiver that returns the {@link SatelliteCapabilities}
13150 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013151 *
13152 * @throws SecurityException if the caller doesn't have required permission.
13153 */
13154 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013155 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
13156 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013157 mSatelliteController.requestSatelliteCapabilities(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013158 }
13159
13160 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013161 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013162 * This can be called by the pointing UI when the user starts pointing to the satellite.
13163 * Modem should continue to report the pointing input as the device or satellite moves.
13164 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013165 * @param subId The subId of the subscription to start satellite transmission updates for.
13166 * @param resultCallback The callback to get the result of the request.
13167 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080013168 *
13169 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013170 */
13171 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013172 public void startSatelliteTransmissionUpdates(int subId,
13173 @NonNull IIntegerConsumer resultCallback,
13174 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13175 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
13176 mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080013177 }
13178
13179 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013180 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013181 * This can be called by the pointing UI when the user stops pointing to the satellite.
13182 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013183 * @param subId The subId of the subscription to stop satellite transmission updates for.
13184 * @param resultCallback The callback to get the result of the request.
13185 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
13186 * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080013187 *
13188 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013189 */
13190 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013191 public void stopSatelliteTransmissionUpdates(int subId,
13192 @NonNull IIntegerConsumer resultCallback,
13193 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13194 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
13195 mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013196 }
13197
13198 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013199 * Register the subscription with a satellite provider.
13200 * This is needed to register the subscription if the provider allows dynamic registration.
13201 *
13202 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013203 * @param token The token to be used as a unique identifier for provisioning with satellite
13204 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013205 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080013206 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013207 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013208 * @return The signal transport used by the caller to cancel the provision request,
13209 * or {@code null} if the request failed.
13210 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013211 * @throws SecurityException if the caller doesn't have the required permission.
13212 */
13213 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013214 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013215 @NonNull String token, @NonNull byte[] provisionData,
13216 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013217 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013218 return mSatelliteController.provisionSatelliteService(subId, token, provisionData,
13219 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013220 }
13221
13222 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013223 * Unregister the device/subscription with the satellite provider.
13224 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013225 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013226 * should report as deprovisioned.
13227 *
13228 * @param subId The subId of the subscription to be deprovisioned.
13229 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080013230 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013231 *
13232 * @throws SecurityException if the caller doesn't have the required permission.
13233 */
13234 @Override
13235 public void deprovisionSatelliteService(int subId,
13236 @NonNull String token, @NonNull IIntegerConsumer callback) {
13237 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013238 mSatelliteController.deprovisionSatelliteService(subId, token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013239 }
13240
13241 /**
Sarah Chin43457982023-02-15 17:50:38 -080013242 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013243 *
Sarah Chin43457982023-02-15 17:50:38 -080013244 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013245 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013246 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013247 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013248 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013249 * @throws SecurityException if the caller doesn't have the required permission.
13250 */
13251 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013252 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
13253 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013254 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013255 return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013256 }
13257
13258 /**
Sarah Chin43457982023-02-15 17:50:38 -080013259 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013260 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013261 *
Sarah Chin43457982023-02-15 17:50:38 -080013262 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013263 * @param callback The callback that was passed to
13264 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013265 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013266 * @throws SecurityException if the caller doesn't have the required permission.
13267 */
13268 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013269 public void unregisterForSatelliteProvisionStateChanged(
13270 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013271 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013272 mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013273 }
13274
13275 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013276 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013277 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013278 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013279 * @param result The result receiver that returns whether the device is provisioned with a
13280 * satellite provider if the request is successful or an error code if the
13281 * request failed.
13282 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013283 * @throws SecurityException if the caller doesn't have the required permission.
13284 */
13285 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013286 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
13287 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013288 mSatelliteController.requestIsSatelliteProvisioned(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013289 }
13290
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013291 /**
Sarah Chin43457982023-02-15 17:50:38 -080013292 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013293 *
Sarah Chin43457982023-02-15 17:50:38 -080013294 * @param subId The subId of the subscription to register for satellite modem state changed.
13295 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080013296 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013297 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013298 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013299 * @throws SecurityException if the caller doesn't have the required permission.
13300 */
13301 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013302 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013303 @NonNull ISatelliteModemStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080013304 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013305 return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013306 }
13307
13308 /**
Sarah Chin43457982023-02-15 17:50:38 -080013309 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013310 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013311 *
Sarah Chin43457982023-02-15 17:50:38 -080013312 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080013313 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013314 * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013315 *
13316 * @throws SecurityException if the caller doesn't have the required permission.
13317 */
13318 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013319 public void unregisterForModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013320 @NonNull ISatelliteModemStateCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013321 enforceSatelliteCommunicationPermission("unregisterForModemStateChanged");
13322 mSatelliteController.unregisterForModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013323 }
13324
13325 /**
13326 * Register to receive incoming datagrams over satellite.
13327 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013328 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Sarah Chindf715ec2023-02-13 13:46:24 -080013329 * @param callback The callback to handle incoming datagrams over satellite.
13330 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013331 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013332 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013333 * @throws SecurityException if the caller doesn't have the required permission.
13334 */
13335 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013336 @SatelliteManager.SatelliteResult public int registerForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013337 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013338 enforceSatelliteCommunicationPermission("registerForIncomingDatagram");
13339 return mSatelliteController.registerForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013340 }
13341
13342 /**
13343 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013344 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013345 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013346 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
13347 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013348 * {@link #registerForIncomingDatagram(int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013349 *
13350 * @throws SecurityException if the caller doesn't have the required permission.
13351 */
13352 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013353 public void unregisterForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013354 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013355 enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram");
13356 mSatelliteController.unregisterForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013357 }
13358
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013359 /**
13360 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013361 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013362 * This method requests modem to check if there are any pending datagrams to be received over
13363 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000013364 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080013365 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013366 * @param subId The subId of the subscription used for receiving datagrams.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013367 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013368 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013369 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013370 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013371 public void pollPendingDatagrams(int subId, IIntegerConsumer callback) {
13372 enforceSatelliteCommunicationPermission("pollPendingDatagrams");
13373 mSatelliteController.pollPendingDatagrams(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013374 }
13375
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013376 /**
13377 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013378 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013379 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
13380 * input to this method. Datagram received here will be passed down to modem without any
13381 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080013382 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013383 * @param subId The subId of the subscription to send satellite datagrams for.
13384 * @param datagramType datagram type indicating whether the datagram is of type
13385 * SOS_SMS or LOCATION_SHARING.
13386 * @param datagram encoded gateway datagram which is encrypted by the caller.
13387 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000013388 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
13389 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013390 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013391 *
13392 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013393 */
13394 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013395 public void sendDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000013396 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
13397 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013398 enforceSatelliteCommunicationPermission("sendDatagram");
13399 mSatelliteController.sendDatagram(subId, datagramType, datagram, needFullScreenPointingUI,
13400 callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013401 }
13402
Sarah Chindf715ec2023-02-13 13:46:24 -080013403 /**
13404 * Request to get whether satellite communication is allowed for the current location.
13405 *
13406 * @param subId The subId of the subscription to check whether satellite communication is
13407 * allowed for the current location for.
13408 * @param result The result receiver that returns whether satellite communication is allowed
13409 * for the current location if the request is successful or an error code
13410 * if the request failed.
13411 *
13412 * @throws SecurityException if the caller doesn't have the required permission.
13413 */
13414 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013415 public void requestIsCommunicationAllowedForCurrentLocation(int subId,
Sarah Chindf715ec2023-02-13 13:46:24 -080013416 @NonNull ResultReceiver result) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013417 enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation");
13418 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(subId,
13419 result);
Sarah Chindf715ec2023-02-13 13:46:24 -080013420 }
13421
13422 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013423 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080013424 *
Sarah Chin5f57c582023-02-14 04:16:10 -080013425 * @param subId The subId to get the time after which the satellite will be visible for.
13426 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080013427 * be visible if the request is successful or an error code if the request failed.
13428 *
13429 * @throws SecurityException if the caller doesn't have the required permission.
13430 */
13431 @Override
13432 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
13433 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013434 mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013435 }
13436
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013437 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013438 * Inform that Device is aligned to satellite for demo mode.
13439 *
13440 * @param subId The subId to get the time after which the satellite will be visible for.
13441 * @param isAligned {@code true} Device is aligned with the satellite for demo mode
13442 * {@code false} Device fails to align with the satellite for demo mode.
13443 *
13444 * @throws SecurityException if the caller doesn't have required permission.
13445 */
13446 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
13447
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013448 public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) {
Hakjun Choiae365972023-04-25 11:00:31 +000013449 enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite");
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013450 mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned);
Hakjun Choiae365972023-04-25 11:00:31 +000013451 }
13452
13453 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000013454 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
13455 * by modem.
13456 *
13457 * @param subId The subId of the subscription to request for.
13458 * @param reason Reason for disallowing satellite communication for carrier.
Hakjun Choif92ac752024-03-18 19:34:29 +000013459 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013460 * operation.
13461 *
13462 * @throws SecurityException if the caller doesn't have required permission.
13463 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013464 public void addAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013465 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13466 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013467 enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013468 final long identity = Binder.clearCallingIdentity();
13469 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013470 mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013471 } finally {
13472 Binder.restoreCallingIdentity(identity);
13473 }
13474 }
13475
13476 /**
13477 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
13478 * by modem.
13479 *
13480 * @param subId The subId of the subscription to request for.
13481 * @param reason Reason for disallowing satellite communication.
Hakjun Choif92ac752024-03-18 19:34:29 +000013482 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013483 * operation.
13484 *
13485 * @throws SecurityException if the caller doesn't have required permission.
13486 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013487 public void removeAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013488 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13489 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013490 enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013491 final long identity = Binder.clearCallingIdentity();
13492 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013493 mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013494 } finally {
13495 Binder.restoreCallingIdentity(identity);
13496 }
13497 }
13498
13499 /**
13500 * Get reasons for disallowing satellite communication, as requested by
Hakjun Choif92ac752024-03-18 19:34:29 +000013501 * {@link #addAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
Hakjun Choicb39db92023-07-14 15:51:12 +000013502 *
13503 * @param subId The subId of the subscription to request for.
13504 *
13505 * @return Integer array of reasons for disallowing satellite communication.
13506 *
13507 * @throws SecurityException if the caller doesn't have the required permission.
13508 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013509 public @NonNull int[] getAttachRestrictionReasonsForCarrier(
Hakjun Choicb39db92023-07-14 15:51:12 +000013510 int subId) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013511 enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013512 final long identity = Binder.clearCallingIdentity();
13513 try {
13514 Set<Integer> reasonSet =
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013515 mSatelliteController.getAttachRestrictionReasonsForCarrier(subId);
Hakjun Choicb39db92023-07-14 15:51:12 +000013516 return reasonSet.stream().mapToInt(i->i).toArray();
13517 } finally {
13518 Binder.restoreCallingIdentity(identity);
13519 }
13520 }
13521
13522 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000013523 * Request to get the signal strength of the satellite connection.
13524 *
13525 * @param subId The subId of the subscription to request for.
13526 * @param result Result receiver to get the error code of the request and the current signal
13527 * strength of the satellite connection.
13528 *
13529 * @throws SecurityException if the caller doesn't have required permission.
13530 */
13531 @Override
13532 public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) {
13533 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
13534 final long identity = Binder.clearCallingIdentity();
13535 try {
13536 mSatelliteController.requestNtnSignalStrength(subId, result);
13537 } finally {
13538 Binder.restoreCallingIdentity(identity);
13539 }
13540 }
13541
13542 /**
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013543 * Registers for NTN signal strength changed from satellite modem. If the registration operation
13544 * is not successful, a {@link ServiceSpecificException} that contains
13545 * {@link SatelliteManager.SatelliteResult} will be thrown.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013546 *
13547 * @param subId The subId of the subscription to request for.
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013548 * @param callback The callback to handle the NTN signal strength changed event. If the
13549 * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged(
13550 * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of
13551 * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial
13552 * network has changed.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013553 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013554 * @throws SecurityException If the caller doesn't have the required permission.
13555 * @throws ServiceSpecificException If the callback registration operation fails.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013556 */
13557 @Override
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013558 public void registerForNtnSignalStrengthChanged(int subId,
13559 @NonNull INtnSignalStrengthCallback callback) throws RemoteException {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013560 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
13561 final long identity = Binder.clearCallingIdentity();
13562 try {
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013563 mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013564 } finally {
13565 Binder.restoreCallingIdentity(identity);
13566 }
13567 }
13568
13569 /**
13570 * Unregisters for NTN signal strength changed from satellite modem.
13571 * If callback was not registered before, the request will be ignored.
13572 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013573 * @param subId The subId of the subscription to unregister for listening NTN signal strength
13574 * changed event.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013575 * @param callback The callback that was passed to
13576 * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)}
13577 *
13578 * @throws SecurityException if the caller doesn't have the required permission.
13579 */
13580 @Override
13581 public void unregisterForNtnSignalStrengthChanged(
13582 int subId, @NonNull INtnSignalStrengthCallback callback) {
13583 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
13584 final long identity = Binder.clearCallingIdentity();
13585 try {
13586 mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback);
13587 } finally {
13588 Binder.restoreCallingIdentity(identity);
13589 }
13590 }
13591
13592 /**
Hakjun Choi8d96a562023-10-26 15:01:40 +000013593 * Registers for satellite capabilities change event from the satellite service.
13594 *
13595 * @param subId The subId of the subscription to request for.
13596 * @param callback The callback to handle the satellite capabilities changed event.
13597 *
13598 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13599 *
13600 * @throws SecurityException if the caller doesn't have required permission.
13601 */
13602 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013603 @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged(
Hakjun Choi8d96a562023-10-26 15:01:40 +000013604 int subId, @NonNull ISatelliteCapabilitiesCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013605 enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013606 final long identity = Binder.clearCallingIdentity();
13607 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013608 return mSatelliteController.registerForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013609 } finally {
13610 Binder.restoreCallingIdentity(identity);
13611 }
13612 }
13613
13614 /**
13615 * Unregisters for satellite capabilities change event from the satellite service.
13616 * If callback was not registered before, the request will be ignored.
13617 *
13618 * @param subId The subId of the subscription to unregister for satellite capabilities change.
13619 * @param callback The callback that was passed to.
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013620 * {@link #registerForCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}.
Hakjun Choi8d96a562023-10-26 15:01:40 +000013621 *
13622 * @throws SecurityException if the caller doesn't have required permission.
13623 */
13624 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013625 public void unregisterForCapabilitiesChanged(int subId,
13626 @NonNull ISatelliteCapabilitiesCallback callback) {
13627 enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013628 final long identity = Binder.clearCallingIdentity();
13629 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013630 mSatelliteController.unregisterForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013631 } finally {
13632 Binder.restoreCallingIdentity(identity);
13633 }
13634 }
13635
13636 /**
Hakjun Choif92ac752024-03-18 19:34:29 +000013637 * Registers for the satellite supported state changed.
13638 *
13639 * @param subId The subId of the subscription to register for supported state changed.
13640 * @param callback The callback to handle the satellite supported state changed event.
13641 *
13642 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13643 *
13644 * @throws SecurityException if the caller doesn't have the required permission.
13645 */
13646 @Override
13647 @SatelliteManager.SatelliteResult public int registerForSatelliteSupportedStateChanged(
13648 int subId, @NonNull ISatelliteSupportedStateCallback callback) {
13649 enforceSatelliteCommunicationPermission("registerForSatelliteSupportedStateChanged");
13650 return mSatelliteController.registerForSatelliteSupportedStateChanged(subId, callback);
13651 }
13652
13653 /**
13654 * Unregisters for the satellite supported state changed.
13655 * If callback was not registered before, the request will be ignored.
13656 *
13657 * @param subId The subId of the subscription to unregister for supported state changed.
13658 * @param callback The callback that was passed to
13659 * {@link #registerForSatelliteSupportedStateChanged(int, ISatelliteSupportedStateCallback)}.
13660 *
13661 * @throws SecurityException if the caller doesn't have the required permission.
13662 */
13663 @Override
13664 public void unregisterForSatelliteSupportedStateChanged(
13665 int subId, @NonNull ISatelliteSupportedStateCallback callback) {
13666 enforceSatelliteCommunicationPermission("unregisterForSatelliteSupportedStateChanged");
13667 mSatelliteController.unregisterForSatelliteSupportedStateChanged(subId, callback);
13668 }
13669
13670 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013671 * This API can be used by only CTS to update satellite vendor service package name.
13672 *
13673 * @param servicePackageName The package name of the satellite vendor service.
13674 * @return {@code true} if the satellite vendor service is set successfully,
13675 * {@code false} otherwise.
13676 */
13677 public boolean setSatelliteServicePackageName(String servicePackageName) {
13678 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName);
13679 TelephonyPermissions.enforceShellOnly(
13680 Binder.getCallingUid(), "setSatelliteServicePackageName");
13681 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13682 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13683 "setSatelliteServicePackageName");
13684 return mSatelliteController.setSatelliteServicePackageName(servicePackageName);
13685 }
13686
13687 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070013688 * This API can be used by only CTS to update satellite gateway service package name.
13689 *
13690 * @param servicePackageName The package name of the satellite gateway service.
13691 * @return {@code true} if the satellite gateway service is set successfully,
13692 * {@code false} otherwise.
13693 */
13694 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
13695 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
13696 TelephonyPermissions.enforceShellOnly(
13697 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
13698 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13699 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13700 "setSatelliteGatewayServicePackageName");
13701 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
13702 }
13703
13704 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070013705 * This API can be used by only CTS to update satellite pointing UI app package and class names.
13706 *
13707 * @param packageName The package name of the satellite pointing UI app.
13708 * @param className The class name of the satellite pointing UI app.
13709 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
13710 * {@code false} otherwise.
13711 */
13712 public boolean setSatellitePointingUiClassName(
13713 @Nullable String packageName, @Nullable String className) {
13714 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
13715 + ", className=" + className);
13716 TelephonyPermissions.enforceShellOnly(
13717 Binder.getCallingUid(), "setSatellitePointingUiClassName");
13718 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13719 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13720 "setSatelliteGatewayServicePackageName");
13721 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
13722 }
13723
13724 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070013725 * This API can be used by only CTS to update the timeout duration in milliseconds that
13726 * satellite should stay at listening mode to wait for the next incoming page before disabling
13727 * listening mode.
13728 *
13729 * @param timeoutMillis The timeout duration in millisecond.
13730 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13731 */
13732 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
13733 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
13734 TelephonyPermissions.enforceShellOnly(
13735 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
13736 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13737 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13738 "setSatelliteListeningTimeoutDuration");
13739 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
13740 }
13741
13742 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013743 * This API can be used by only CTS to override the timeout durations used by the
13744 * DatagramController module.
Hakjun Choiae365972023-04-25 11:00:31 +000013745 *
13746 * @param timeoutMillis The timeout duration in millisecond.
13747 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13748 */
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013749 public boolean setDatagramControllerTimeoutDuration(
13750 boolean reset, int timeoutType, long timeoutMillis) {
13751 Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset="
13752 + reset + ", timeoutMillis=" + timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013753 TelephonyPermissions.enforceShellOnly(
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013754 Binder.getCallingUid(), "setDatagramControllerTimeoutDuration");
Hakjun Choiae365972023-04-25 11:00:31 +000013755 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13756 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013757 "setDatagramControllerTimeoutDuration");
13758 return mSatelliteController.setDatagramControllerTimeoutDuration(
13759 reset, timeoutType, timeoutMillis);
13760 }
13761
13762 /**
13763 * This API can be used by only CTS to override the timeout durations used by the
13764 * SatelliteController module.
13765 *
13766 * @param timeoutMillis The timeout duration in millisecond.
13767 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13768 */
13769 public boolean setSatelliteControllerTimeoutDuration(
13770 boolean reset, int timeoutType, long timeoutMillis) {
13771 Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset="
13772 + reset + ", timeoutMillis=" + timeoutMillis);
13773 TelephonyPermissions.enforceShellOnly(
13774 Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration");
13775 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13776 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13777 "setSatelliteControllerTimeoutDuration");
13778 return mSatelliteController.setSatelliteControllerTimeoutDuration(
13779 reset, timeoutType, timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013780 }
13781
13782 /**
Thomas Nguyen11a051f2023-10-25 10:14:55 -070013783 * This API can be used in only testing to override connectivity status in monitoring emergency
13784 * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.
13785 *
13786 * @param handoverType The type of handover from emergency call to satellite messaging. Use one
13787 * of the following values to enable the override:
13788 * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS
13789 * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911
13790 * To disable the override, use -1 for handoverType.
13791 * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer
13792 * delaySeconds after the emergency call starts.
13793 * @return {@code true} if the handover type is set successfully, {@code false} otherwise.
13794 */
13795 public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) {
13796 Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType);
13797 TelephonyPermissions.enforceShellOnly(
13798 Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType");
13799 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13800 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13801 "setEmergencyCallToSatelliteHandoverType");
13802 return mSatelliteController.setEmergencyCallToSatelliteHandoverType(
13803 handoverType, delaySeconds);
13804 }
13805
13806 /**
Thomas Nguyen3d602742024-01-19 11:29:35 -080013807 * This API can be used in only testing to override oem-enabled satellite provision status.
13808 *
13809 * @param reset {@code true} mean the overriding status should not be used, {@code false}
13810 * otherwise.
13811 * @param isProvisioned The overriding provision status.
13812 * @return {@code true} if the provision status is set successfully, {@code false} otherwise.
13813 */
13814 public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) {
13815 Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset
13816 + ", isProvisioned=" + isProvisioned);
13817 TelephonyPermissions.enforceShellOnly(
13818 Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus");
13819 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13820 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13821 "setOemEnabledSatelliteProvisionStatus");
13822 return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned);
13823 }
13824
13825 /**
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013826 * This API should be used by only CTS tests to forcefully set telephony country codes.
13827 *
13828 * @return {@code true} if the country code is set successfully, {@code false} otherwise.
13829 */
13830 public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes,
13831 Map cachedNetworkCountryCodes, String locationCountryCode,
13832 long locationCountryCodeTimestampNanos) {
13833 Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes="
13834 + String.join(", ", currentNetworkCountryCodes)
13835 + ", locationCountryCode=" + locationCountryCode
13836 + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos
13837 + ", reset=" + reset + ", cachedNetworkCountryCodes="
13838 + String.join(", ", cachedNetworkCountryCodes.keySet()));
13839 TelephonyPermissions.enforceShellOnly(
13840 Binder.getCallingUid(), "setCachedLocationCountryCode");
13841 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13842 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13843 "setCachedLocationCountryCode");
13844 return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext()).setCountryCodes(
13845 reset, currentNetworkCountryCodes, cachedNetworkCountryCodes, locationCountryCode,
13846 locationCountryCodeTimestampNanos);
13847 }
13848
13849 /**
13850 * This API should be used by only CTS tests to override the overlay configs of satellite
13851 * access controller.
13852 *
13853 * @param reset {@code true} mean the overridden configs should not be used, {@code false}
13854 * otherwise.
13855 * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise.
13856 */
13857 public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed,
13858 String s2CellFile, long locationFreshDurationNanos,
13859 List<String> satelliteCountryCodes) {
13860 Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset
13861 + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile
13862 + ", locationFreshDurationNanos=" + locationFreshDurationNanos
13863 + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null)
13864 ? String.join(", ", satelliteCountryCodes) : null));
13865 TelephonyPermissions.enforceShellOnly(
13866 Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs");
13867 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13868 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13869 "setSatelliteAccessControlOverlayConfigs");
13870 return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset, isAllowed,
13871 s2CellFile, locationFreshDurationNanos, satelliteCountryCodes);
13872 }
13873
13874 /**
Hakjun Choibc6ce992023-11-07 16:04:33 +000013875 * This API can be used by only CTS to override the cached value for the device overlay config
13876 * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether
13877 * outgoing satellite datagrams should be sent to modem in demo mode.
13878 *
13879 * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to
13880 * satellite modem or not.
13881 *
13882 * @return {@code true} if the operation is successful, {@code false} otherwise.
13883 */
13884 public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) {
13885 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
13886 Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is "
13887 + "disabled");
13888 return false;
13889 }
13890 Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode");
13891 TelephonyPermissions.enforceShellOnly(
13892 Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode");
13893 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13894 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13895 "setShouldSendDatagramToModemInDemoMode");
13896 return mSatelliteController.setShouldSendDatagramToModemInDemoMode(
13897 shouldSendToModemInDemoMode);
13898 }
13899
13900 /**
Hunsuk Choi13078be2023-09-13 10:55:21 +000013901 * Sets the service defined in ComponentName to be bound.
13902 *
13903 * This should only be used for testing.
13904 * @return {@code true} if the DomainSelectionService to bind to was set,
13905 * {@code false} otherwise.
13906 */
13907 @Override
13908 public boolean setDomainSelectionServiceOverride(ComponentName componentName) {
13909 Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName);
13910
13911 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
13912 "setDomainSelectionServiceOverride");
13913 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13914 getDefaultSubscription(), "setDomainSelectionServiceOverride");
13915
13916 final long identity = Binder.clearCallingIdentity();
13917 try {
13918 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13919 return DomainSelectionResolver.getInstance()
13920 .setDomainSelectionServiceOverride(componentName);
13921 }
13922 } finally {
13923 Binder.restoreCallingIdentity(identity);
13924 }
13925 return false;
13926 }
13927
13928 /**
13929 * Clears the DomainSelectionService override.
13930 *
13931 * This should only be used for testing.
13932 * @return {@code true} if the DomainSelectionService override was cleared,
13933 * {@code false} otherwise.
13934 */
13935 @Override
13936 public boolean clearDomainSelectionServiceOverride() {
13937 Log.i(LOG_TAG, "clearDomainSelectionServiceOverride");
13938
13939 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
13940 "clearDomainSelectionServiceOverride");
13941 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13942 getDefaultSubscription(), "clearDomainSelectionServiceOverride");
13943
13944 final long identity = Binder.clearCallingIdentity();
13945 try {
13946 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13947 return DomainSelectionResolver.getInstance()
13948 .clearDomainSelectionServiceOverride();
13949 }
13950 } finally {
13951 Binder.restoreCallingIdentity(identity);
13952 }
13953 return false;
13954 }
13955
13956 /**
Gil Cukierman06403e12023-11-29 16:33:03 +000013957 * Enable or disable notifications sent for cellular identifier disclosure events.
13958 *
13959 * Disclosure events are defined as instances where a device has sent a cellular identifier
13960 * on the Non-access stratum (NAS) before a security context is established. As a result the
13961 * identifier is sent in the clear, which has privacy implications for the user.
13962 *
13963 * @param enable if notifications about disclosure events should be enabled
13964 * @throws SecurityException if the caller does not have the required privileges
13965 * @throws UnsupportedOperationException if the modem does not support this feature.
13966 */
13967 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000013968 public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) {
Gil Cukierman06403e12023-11-29 16:33:03 +000013969 enforceModifyPermission();
13970 checkForIdentifierDisclosureNotificationSupport();
13971
13972 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
13973 editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable);
13974 editor.apply();
13975
13976 // Each phone instance is responsible for updating its respective modem immediately
13977 // after we've made a preference change.
13978 for (Phone phone : PhoneFactory.getPhones()) {
13979 phone.handleIdentifierDisclosureNotificationPreferenceChange();
13980 }
13981 }
13982
13983 /**
13984 * Get whether or not cellular identifier disclosure notifications are enabled.
13985 *
13986 * @throws SecurityException if the caller does not have the required privileges
13987 * @throws UnsupportedOperationException if the modem does not support this feature.
13988 */
13989 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000013990 public boolean isCellularIdentifierDisclosureNotificationsEnabled() {
Gil Cukierman06403e12023-11-29 16:33:03 +000013991 enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled");
13992 checkForIdentifierDisclosureNotificationSupport();
13993 return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled();
13994 }
13995
13996 /**
Michael Groover826b71d2023-12-21 22:08:06 -060013997 * Enables or disables notifications sent when cellular null cipher or integrity algorithms
13998 * are in use by the cellular modem.
13999 *
14000 * @throws IllegalStateException if the Telephony process is not currently available
14001 * @throws SecurityException if the caller does not have the required privileges
14002 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14003 * and integrity algorithms in use
14004 * @hide
14005 */
14006 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Michael Grooverae447b22024-01-24 22:35:46 -060014007 public void setNullCipherNotificationsEnabled(boolean enable) {
Michael Groover826b71d2023-12-21 22:08:06 -060014008 enforceModifyPermission();
14009 checkForNullCipherNotificationSupport();
14010
14011 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
14012 editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable);
14013 editor.apply();
14014
14015 // Each phone instance is responsible for updating its respective modem immediately
14016 // after a preference change.
14017 for (Phone phone : PhoneFactory.getPhones()) {
14018 phone.handleNullCipherNotificationPreferenceChanged();
14019 }
14020 }
14021
14022 /**
14023 * Get whether notifications are enabled for null cipher or integrity algorithms in use by the
14024 * cellular modem.
14025 *
14026 * @throws IllegalStateException if the Telephony process is not currently available
14027 * @throws SecurityException if the caller does not have the required privileges
14028 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14029 * and integrity algorithms in use
14030 * @hide
14031 */
14032 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
14033 public boolean isNullCipherNotificationsEnabled() {
14034 enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled");
14035 checkForNullCipherNotificationSupport();
14036 return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled();
14037 }
14038
14039 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000014040 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
14041 *
14042 * <p>This method behaves in one of the following ways:
14043 * <ul>
14044 * <li>return true : if the calling package has the appop permission {@link
14045 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
14046 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
14047 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
14048 * Owner device identifier access check, or the calling package has carrier privileges</>
14049 * <li>throw SecurityException: if the caller does not meet any of the requirements.
14050 * </ul>
14051 */
14052 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
14053 String callingPackage, @Nullable String callingFeatureId, String message) {
14054 for (Phone phone : PhoneFactory.getPhones()) {
14055 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
14056 phone.getSubId(), callingPackage, callingFeatureId, message)) {
14057 return true;
14058 }
14059 }
14060 return false;
14061 }
arunvoddud7401012022-12-15 16:08:12 +000014062
14063 /**
Jack Yufa8ed012023-02-11 15:42:28 -080014064 * @return The subscription manager service instance.
14065 */
14066 public SubscriptionManagerService getSubscriptionManagerService() {
14067 return SubscriptionManagerService.getInstance();
14068 }
14069
14070 /**
arunvoddud7401012022-12-15 16:08:12 +000014071 * Class binds the consumer[callback] and carrierId.
14072 */
14073 private static class CallerCallbackInfo {
14074 private final Consumer<Integer> mConsumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014075 private final Set<Integer> mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014076
Steve Statia28b7cb32024-03-11 23:58:50 +000014077 public CallerCallbackInfo(Consumer<Integer> consumer, Set<Integer> carrierIds) {
arunvoddud7401012022-12-15 16:08:12 +000014078 mConsumer = consumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014079 mCarrierIds = carrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014080 }
14081
14082 public Consumer<Integer> getConsumer() {
14083 return mConsumer;
14084 }
14085
Steve Statia28b7cb32024-03-11 23:58:50 +000014086 public Set<Integer> getCarrierIds() {
14087 return mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014088 }
14089 }
joonhunshin4ac60942023-11-15 15:23:39 +000014090
14091 /*
14092 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14093 * But the context that is passed in is unused if the phone app is already alive.
14094 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14095 */
14096 @VisibleForTesting
14097 public void setPackageManager(PackageManager packageManager) {
14098 mPackageManager = packageManager;
14099 }
14100
14101 /*
Nate Myren453c3472024-03-13 11:28:11 -070014102 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14103 * But the context that is passed in is unused if the phone app is already alive.
14104 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14105 */
14106 @VisibleForTesting
14107 public void setAppOpsManager(AppOpsManager appOps) {
14108 mAppOps = appOps;
14109 }
14110
14111 /*
joonhunshin4ac60942023-11-15 15:23:39 +000014112 * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags.
14113 * But the FeatureFlags that is passed in is unused if the phone app is already alive.
14114 * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test.
14115 */
14116 @VisibleForTesting
14117 public void setFeatureFlags(FeatureFlags featureFlags) {
14118 mFeatureFlags = featureFlags;
14119 }
14120
14121 /**
14122 * Make sure the device has required telephony feature
14123 *
14124 * @throws UnsupportedOperationException if the device does not have required telephony feature
14125 */
14126 private void enforceTelephonyFeatureWithException(@Nullable String callingPackage,
14127 @NonNull String telephonyFeature, @NonNull String methodName) {
14128 if (callingPackage == null || mPackageManager == null) {
14129 return;
14130 }
14131
14132 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
14133 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage,
joonhunshinf624b2a2024-04-18 04:42:12 +000014134 Binder.getCallingUserHandle())
14135 || mVendorApiLevel < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
14136 // Skip to check associated telephony feature,
14137 // if compatibility change is not enabled for the current process or
14138 // the SDK version of vendor partition is less than Android V.
joonhunshin4ac60942023-11-15 15:23:39 +000014139 return;
14140 }
14141
14142 if (!mPackageManager.hasSystemFeature(telephonyFeature)) {
14143 throw new UnsupportedOperationException(
14144 methodName + " is unsupported without " + telephonyFeature);
14145 }
14146 }
youngtaecha5d483d52024-04-29 17:05:45 +000014147
14148 /**
14149 * Registers for the satellite communication allowed state changed.
14150 *
14151 * @param subId The subId of the subscription to register for the satellite communication
14152 * allowed state changed.
14153 * @param callback The callback to handle the satellite communication allowed
14154 * state changed event.
14155 *
14156 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
14157 *
14158 * @throws SecurityException if the caller doesn't have the required permission.
14159 */
14160 @Override
14161 @SatelliteManager.SatelliteResult public int registerForCommunicationAllowedStateChanged(
14162 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14163 enforceSatelliteCommunicationPermission("registerForCommunicationAllowedStateChanged");
14164 return mSatelliteAccessController.registerForCommunicationAllowedStateChanged(
14165 subId, callback);
14166 }
14167
14168 /**
14169 * Unregisters for the satellite communication allowed state changed.
14170 * If callback was not registered before, the request will be ignored.
14171 *
14172 * @param subId The subId of the subscription to unregister for the satellite communication
14173 * allowed state changed.
14174 * @param callback The callback that was passed to
14175 * {@link #registerForCommunicationAllowedStateChanged(int,
14176 * ISatelliteCommunicationAllowedStateCallback)}. *
14177 * @throws SecurityException if the caller doesn't have the required permission.
14178 */
14179 @Override
14180 public void unregisterForCommunicationAllowedStateChanged(
14181 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14182 enforceSatelliteCommunicationPermission("unregisterForCommunicationAllowedStateChanged");
14183 mSatelliteAccessController.unregisterForCommunicationAllowedStateChanged(subId, callback);
14184 }
Jack Yufa8ed012023-02-11 15:42:28 -080014185}