blob: d7d34b182c673505673cb43b4fc62061ee05dcbf [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
joonhunshin4ac60942023-11-15 15:23:39 +000019import static android.content.pm.PackageManager.FEATURE_TELEPHONY_IMS;
20import static android.content.pm.PackageManager.FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION;
Hall Liud892bec2018-11-30 14:51:45 -080021import static android.content.pm.PackageManager.PERMISSION_GRANTED;
Nate Myrenae97d192023-06-09 15:22:31 -070022import static android.permission.flags.Flags.opEnableMobileDataByUser;
joonhunshin4ac60942023-11-15 15:23:39 +000023import static android.telephony.TelephonyManager.ENABLE_FEATURE_MAPPING;
Gil Cukierman1c0eb932022-12-06 22:28:24 +000024import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK;
jimsunf9ec1622022-09-13 21:18:43 +080025import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080026import static android.telephony.satellite.SatelliteManager.KEY_SATELLITE_COMMUNICATION_ALLOWED;
27import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_ACCESS_BARRED;
Thomas Nguyena8062672024-02-05 14:18:19 -080028import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_REQUEST_NOT_SUPPORTED;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080029import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_SUCCESS;
Hall Liud892bec2018-11-30 14:51:45 -080030
Shuo Qianccbaf742021-02-22 18:32:21 -080031import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
32import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070033import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070034import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000035import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070036
Brad Ebinger34c09a52021-02-17 23:23:21 +000037import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080038import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080039import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070040import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000041import android.annotation.RequiresPermission;
Sarah Chin532d6bb2022-12-28 22:50:43 -080042import android.app.ActivityManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070043import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080044import android.app.PendingIntent;
Tyler Gunn64144d92022-03-17 14:16:41 -070045import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000046import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080047import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000048import android.compat.annotation.ChangeId;
49import android.compat.annotation.EnabledSince;
Anthony Alridge70ba5572023-05-02 12:14:14 +000050import android.content.ActivityNotFoundException;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070051import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070052import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.content.Context;
54import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070055import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070056import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070057import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070058import android.net.Uri;
59import android.os.AsyncResult;
60import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080061import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070062import android.os.Bundle;
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080063import android.os.DropBoxManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070065import android.os.IBinder;
Thomas Nguyen8ee49682023-02-01 11:46:09 -080066import android.os.ICancellationSignal;
tom hsu0b59d292022-09-29 23:49:21 +080067import android.os.LocaleList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070068import android.os.Looper;
69import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070070import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080071import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070072import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070073import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080074import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080075import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070076import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070077import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080078import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070079import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070080import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070081import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070082import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070083import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080084import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070085import android.provider.Telephony;
arunvoddud7401012022-12-15 16:08:12 +000086import android.service.carrier.CarrierIdentifier;
Inseob Kim14bb3d02018-12-13 17:11:34 +090087import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080088import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080089import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070090import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080091import android.telephony.AccessNetworkConstants;
92import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070093import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070094import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080095import android.telephony.Annotation.ThermalMitigationResult;
Sarah Chin2ec39f62022-08-31 17:03:26 -070096import android.telephony.AnomalyReporter;
Shuo Qian4a594052020-01-23 11:59:30 -080097import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070098import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080099import android.telephony.CarrierRestrictionRules;
Hui Wang9b5793a2022-12-05 14:38:06 -0600100import android.telephony.CellBroadcastIdRange;
yincheng zhao2737e882019-09-06 17:06:54 -0700101import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -0800102import android.telephony.CellIdentityCdma;
103import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700104import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -0700105import android.telephony.CellInfoGsm;
106import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700107import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800108import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -0700109import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700110import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700111import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -0800112import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700113import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -0800114import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -0700115import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -0800116import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800117import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700118import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800119import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700120import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800121import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800122import android.telephony.SignalStrengthUpdateRequest;
123import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800124import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800125import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800126import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700127import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700128import android.telephony.TelephonyManager;
Jack Yuf5badd92022-12-08 00:50:53 -0800129import android.telephony.TelephonyManager.SimState;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800130import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800131import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800132import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000133import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000134import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000135import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700136import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700137import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800138import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800139import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700140import android.telephony.gba.GbaAuthRequest;
141import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700142import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800143import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000144import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000145import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700146import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000147import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700148import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800149import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700150import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800151import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700152import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000153import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700154import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800155import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800156import android.telephony.ims.stub.ImsRegistrationImplBase;
Hakjun Choifa3e6172023-09-22 03:56:34 +0000157import android.telephony.satellite.INtnSignalStrengthCallback;
Hakjun Choi8d96a562023-10-26 15:01:40 +0000158import android.telephony.satellite.ISatelliteCapabilitiesCallback;
youngtaecha5d483d52024-04-29 17:05:45 +0000159import android.telephony.satellite.ISatelliteCommunicationAllowedStateCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800160import android.telephony.satellite.ISatelliteDatagramCallback;
Hakjun Choid4a52a22023-12-13 09:48:24 +0000161import android.telephony.satellite.ISatelliteModemStateCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800162import android.telephony.satellite.ISatelliteProvisionStateCallback;
Hakjun Choif92ac752024-03-18 19:34:29 +0000163import android.telephony.satellite.ISatelliteSupportedStateCallback;
Sarah Chinabf081b2023-03-09 23:00:57 -0800164import android.telephony.satellite.ISatelliteTransmissionUpdateCallback;
Hakjun Choi4c3668a2023-12-05 11:55:36 +0000165import android.telephony.satellite.NtnSignalStrength;
166import android.telephony.satellite.NtnSignalStrengthCallback;
Sarah Chin503828c2023-02-01 23:54:20 -0800167import android.telephony.satellite.SatelliteCapabilities;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000168import android.telephony.satellite.SatelliteDatagram;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800169import android.telephony.satellite.SatelliteDatagramCallback;
Sarah Chineccfbd12023-01-20 19:00:35 -0800170import android.telephony.satellite.SatelliteManager;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800171import android.telephony.satellite.SatelliteProvisionStateCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700172import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800173import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700174import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700175import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800176import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800177
Andrew Lee312e8172014-10-23 17:01:36 -0700178import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800179import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800180import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800181import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800182import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700183import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700184import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700185import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800186import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800187import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700188import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700189import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800190import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700191import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800192import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800193import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800194import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700195import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000196import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700197import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800198import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700199import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800200import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800201import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800202import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700203import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700204import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700205import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700206import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700207import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800208import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700209import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700210import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700211import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700212import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800213import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800214import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700215import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000216import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700217import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700218import com.android.internal.telephony.SmsPermissions;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800219import com.android.internal.telephony.TelephonyCountryDetector;
Peter Wang59571be2020-01-27 12:35:15 +0800220import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800221import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700222import com.android.internal.telephony.data.DataUtils;
Hunsuk Choi42cc62a2022-10-16 06:03:40 +0000223import com.android.internal.telephony.domainselection.DomainSelectionResolver;
sqianf4ca7ed2019-01-15 18:32:07 -0800224import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700225import com.android.internal.telephony.euicc.EuiccConnector;
Sarah Chincc5446f2023-10-23 17:57:19 -0700226import com.android.internal.telephony.flags.FeatureFlags;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800227import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700228import com.android.internal.telephony.imsphone.ImsPhone;
229import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000230import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800231import com.android.internal.telephony.metrics.TelephonyMetrics;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000232import com.android.internal.telephony.satellite.SatelliteController;
Jack Yu285100e2022-12-02 22:48:35 -0800233import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
234import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700235import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700236import com.android.internal.telephony.uicc.IccIoResult;
237import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800238import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700239import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800240import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700241import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000242import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800243import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000244import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800245import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000246import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700247import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700248import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800249import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800250import com.android.phone.callcomposer.CallComposerPictureManager;
251import com.android.phone.callcomposer.CallComposerPictureTransfer;
252import com.android.phone.callcomposer.ImageData;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800253import com.android.phone.satellite.accesscontrol.SatelliteAccessController;
Hyosun Kim240214a2023-11-02 13:30:15 +0000254import com.android.phone.satellite.entitlement.SatelliteEntitlementController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700255import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700256import com.android.phone.slice.SlicePurchaseController;
arunvoddud7401012022-12-15 16:08:12 +0000257import com.android.phone.utils.CarrierAllowListInfo;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700258import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800259import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700260import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700261import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800262import com.android.services.telephony.TelecomAccountRegistry;
263import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800264import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800265
Hall Liu82694d52020-12-11 18:22:04 -0800266import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700267import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800268import java.io.IOException;
269import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700270import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700271import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800272import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000273import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800274import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800275import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800276import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800277import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100278import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800279import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700280import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800281import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800282import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700283import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800284import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800285import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800286import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700287
288/**
289 * Implementation of the ITelephony interface.
290 */
Santos Cordon117fee72014-05-16 17:56:12 -0700291public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700292 private static final String LOG_TAG = "PhoneInterfaceManager";
293 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
294 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800295 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700296
297 // Message codes used with mMainThreadHandler
298 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700299 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
300 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700301 private static final int CMD_OPEN_CHANNEL = 9;
302 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
303 private static final int CMD_CLOSE_CHANNEL = 11;
304 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800305 private static final int CMD_NV_READ_ITEM = 13;
306 private static final int EVENT_NV_READ_ITEM_DONE = 14;
307 private static final int CMD_NV_WRITE_ITEM = 15;
308 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
309 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
310 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700311 private static final int CMD_RESET_MODEM_CONFIG = 19;
312 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800313 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
314 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800315 private static final int CMD_SEND_ENVELOPE = 25;
316 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700317 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
318 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
319 private static final int CMD_EXCHANGE_SIM_IO = 31;
320 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800321 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
322 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700323 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
324 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700325 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
326 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700327 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
328 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
329 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
330 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700331 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
332 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
333 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
334 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700335 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800336 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
337 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000338 private static final int CMD_SWITCH_SLOTS = 50;
339 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700340 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
341 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
342 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
343 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
344 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
345 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
346 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
347 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700348 private static final int CMD_GET_ALL_CELL_INFO = 60;
349 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
350 private static final int CMD_GET_CELL_LOCATION = 62;
351 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700352 private static final int CMD_MODEM_REBOOT = 64;
353 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700354 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
355 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800356 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
357 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700358 private static final int CMD_GET_MODEM_STATUS = 70;
359 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700360 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
361 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700362 private static final int CMD_ERASE_MODEM_CONFIG = 74;
363 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800364 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
365 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
366 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
367 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800368 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
369 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800370 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800371 private static final int CMD_GET_CALL_FORWARDING = 83;
372 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
373 private static final int CMD_SET_CALL_FORWARDING = 85;
374 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
375 private static final int CMD_GET_CALL_WAITING = 87;
376 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
377 private static final int CMD_SET_CALL_WAITING = 89;
378 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700379 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
380 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
381 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
382 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700383 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
384 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800385 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
386 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800387 private static final int CMD_SET_DATA_THROTTLING = 99;
388 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800389 private static final int CMD_SET_SIM_POWER = 101;
390 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800391 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
392 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
393 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
394 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800395 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
396 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000397 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800398 private static final int CMD_GET_SLICING_CONFIG = 110;
399 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800400 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700401 private static final int CMD_ENABLE_VONR = 113;
402 private static final int EVENT_ENABLE_VONR_DONE = 114;
403 private static final int CMD_IS_VONR_ENABLED = 115;
404 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700405 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
406 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000407
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800408 // Parameters of select command.
409 private static final int SELECT_COMMAND = 0xA4;
410 private static final int SELECT_P1 = 0x04;
411 private static final int SELECT_P2 = 0;
412 private static final int SELECT_P3 = 0x10;
413
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000414 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
415 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
Gil Cukierman06403e12023-11-29 16:33:03 +0000416 // Cellular identifier disclosure transparency was added in IRadioNetwork 2.2
417 private static final int MIN_IDENTIFIER_DISCLOSURE_VERSION = 202;
Michael Groover826b71d2023-12-21 22:08:06 -0600418 // Null cipher notification support was added in IRadioNetwork 2.2
419 private static final int MIN_NULL_CIPHER_NOTIFICATION_VERSION = 202;
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000420
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700421 /** The singleton instance. */
422 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800423 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700424
Sarah Chin4beb2b72023-02-14 14:47:54 -0800425 private final PhoneGlobals mApp;
joonhunshin4ac60942023-11-15 15:23:39 +0000426 private FeatureFlags mFeatureFlags;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800427 private final CallManager mCM;
428 private final ImsResolver mImsResolver;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000429
430 private final SatelliteController mSatelliteController;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800431 private final SatelliteAccessController mSatelliteAccessController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800432 private final UserManager mUserManager;
433 private final AppOpsManager mAppOps;
434 private final MainThreadHandler mMainThreadHandler;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800435 private final SharedPreferences mTelephonySharedPreferences;
436 private final PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800437 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
joonhunshin4ac60942023-11-15 15:23:39 +0000438 private PackageManager mPackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700439
Peter Wangdafb9ac2020-01-15 14:13:38 -0800440 /** User Activity */
Sarah Chin4beb2b72023-02-14 14:47:54 -0800441 private final AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800442 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800443 private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800444
Derek Tan97ebb422014-09-05 16:55:38 -0700445 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
446 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800447 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800448 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700449
Michelecea4cf22018-12-21 15:00:11 -0800450 // String to store multi SIM allowed
451 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
452
Derek Tan740e1672017-06-27 14:56:27 -0700453 // The AID of ISD-R.
454 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
455
yinxub1bed742017-04-17 11:45:04 -0700456 private NetworkScanRequestTracker mNetworkScanRequestTracker;
457
David Kelly5e06a7f2018-03-12 14:10:59 +0000458 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
459 private static final int MANUFACTURER_CODE_LENGTH = 8;
460
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800461 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800462 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800463
Sarah Chin2ec39f62022-08-31 17:03:26 -0700464 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
465 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
466
Derek Tan89e89d42014-07-08 17:00:10 -0700467 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700468 * Experiment flag to enable erase modem config on reset network, default value is false
469 */
470 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
471 "reset_network_erase_modem_config_enabled";
472
Rambo Wang0f050d82021-02-12 11:43:36 -0800473 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800474
Gary Jian76280a42022-12-07 16:18:33 +0800475 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
476
sandeepjsb6c87872021-09-27 15:34:44 +0000477 /**
478 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
479 * one ICCID active at the same time.
480 * Apps should use below API signatures if targeting SDK is T and beyond.
481 *
482 * @hide
483 */
484 @ChangeId
485 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
486 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800487
Naina Nallurid63128d2019-09-17 14:10:30 -0700488 /**
Chen Xu540470b2021-12-14 17:15:47 -0800489 * Apps targeting on Android T and beyond will get exception whenever icc close channel
490 * operation fails.
491 */
492 @ChangeId
493 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
494 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
495
496 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700497 * A request object to use for transmitting data to an ICC.
498 */
499 private static final class IccAPDUArgument {
500 public int channel, cla, command, p1, p2, p3;
501 public String data;
502
503 public IccAPDUArgument(int channel, int cla, int command,
504 int p1, int p2, int p3, String data) {
505 this.channel = channel;
506 this.cla = cla;
507 this.command = command;
508 this.p1 = p1;
509 this.p2 = p2;
510 this.p3 = p3;
511 this.data = data;
512 }
513 }
514
515 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700516 * A request object to use for transmitting data to an ICC.
517 */
518 private static final class ManualNetworkSelectionArgument {
519 public OperatorInfo operatorInfo;
520 public boolean persistSelection;
521
522 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
523 this.operatorInfo = operatorInfo;
524 this.persistSelection = persistSelection;
525 }
526 }
527
Sarah Chin71b3a852022-09-28 15:54:19 -0700528 private static final class PurchasePremiumCapabilityArgument {
529 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700530 public @NonNull IIntegerConsumer callback;
531
532 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800533 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700534 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700535 this.callback = callback;
536 }
537 }
538
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700539 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700540 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
541 * request after sending. The main thread will notify the request when it is complete.
542 */
543 private static final class MainThreadRequest {
544 /** The argument to use for the request */
545 public Object argument;
546 /** The result of the request that is run on the main thread */
547 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800548 // The subscriber id that this request applies to. Defaults to
549 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
550 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700551
Nathan Harold92bed182018-10-12 18:16:49 -0700552 // In cases where subId is unavailable, the caller needs to specify the phone.
553 public Phone phone;
554
vagdeviaf9a5b92018-08-15 16:01:53 -0700555 public WorkSource workSource;
556
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700557 public MainThreadRequest(Object argument) {
558 this.argument = argument;
559 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800560
Nathan Harold92bed182018-10-12 18:16:49 -0700561 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
562 this.argument = argument;
563 if (phone != null) {
564 this.phone = phone;
565 }
566 this.workSource = workSource;
567 }
568
vagdeviaf9a5b92018-08-15 16:01:53 -0700569 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800570 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800571 if (subId != null) {
572 this.subId = subId;
573 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700574 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800575 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700576 }
577
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800578 private static final class IncomingThirdPartyCallArgs {
579 public final ComponentName component;
580 public final String callId;
581 public final String callerDisplayName;
582
583 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
584 String callerDisplayName) {
585 this.component = component;
586 this.callId = callId;
587 this.callerDisplayName = callerDisplayName;
588 }
589 }
590
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700591 /**
592 * A handler that processes messages on the main thread in the phone process. Since many
593 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
594 * inbound binder threads to the main thread in the phone process. The Binder thread
595 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
596 * on, which will be notified when the operation completes and will contain the result of the
597 * request.
598 *
599 * <p>If a MainThreadRequest object is provided in the msg.obj field,
600 * note that request.result must be set to something non-null for the calling thread to
601 * unblock.
602 */
603 private final class MainThreadHandler extends Handler {
604 @Override
605 public void handleMessage(Message msg) {
606 MainThreadRequest request;
607 Message onCompleted;
608 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000609 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700610 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800611 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700612
613 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700614 case CMD_HANDLE_USSD_REQUEST: {
615 request = (MainThreadRequest) msg.obj;
616 final Phone phone = getPhoneFromRequest(request);
617 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800618 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700619 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700620
Pengquan Menga1bb6272018-09-06 09:59:22 -0700621 if (!isUssdApiAllowed(request.subId)) {
622 // Carrier does not support use of this API, return failure.
623 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
624 UssdResponse response = new UssdResponse(ussdRequest, null);
625 Bundle returnData = new Bundle();
626 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
627 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700628
Pengquan Menga1bb6272018-09-06 09:59:22 -0700629 request.result = true;
630 notifyRequester(request);
631 return;
632 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700633
Pengquan Menga1bb6272018-09-06 09:59:22 -0700634 try {
635 request.result = phone != null
636 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
637 } catch (CallStateException cse) {
638 request.result = false;
639 }
640 // Wake up the requesting thread
641 notifyRequester(request);
642 break;
pkanwar32d516d2016-10-14 19:37:38 -0700643 }
644
Yorke Lee716f67e2015-06-17 15:39:16 -0700645 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700646 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700647 final Phone phone = getPhoneFromRequest(request);
648 request.result = phone != null ?
649 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
650 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700651 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700652 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700653 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700654 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700655
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700656 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700657 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700658 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000659 uiccPort = getUiccPortFromRequest(request);
660 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700661 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800662 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700663 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700664 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700665 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800666 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000667 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800668 iccArgument.channel, iccArgument.cla, iccArgument.command,
669 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
670 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700671 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700672 break;
673
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700674 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700675 ar = (AsyncResult) msg.obj;
676 request = (MainThreadRequest) ar.userObj;
677 if (ar.exception == null && ar.result != null) {
678 request.result = ar.result;
679 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800680 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700681 if (ar.result == null) {
682 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800683 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700684 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800685 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700686 } else {
687 loge("iccTransmitApduLogicalChannel: Unknown exception");
688 }
689 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700690 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700691 break;
692
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700693 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
694 request = (MainThreadRequest) msg.obj;
695 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000696 uiccPort = getUiccPortFromRequest(request);
697 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700698 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800699 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700700 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700701 } else {
702 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800703 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000704 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800705 iccArgument.cla, iccArgument.command, iccArgument.p1,
706 iccArgument.p2,
707 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700708 }
709 break;
710
711 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
712 ar = (AsyncResult) msg.obj;
713 request = (MainThreadRequest) ar.userObj;
714 if (ar.exception == null && ar.result != null) {
715 request.result = ar.result;
716 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800717 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700718 if (ar.result == null) {
719 loge("iccTransmitApduBasicChannel: Empty response");
720 } else if (ar.exception instanceof CommandException) {
721 loge("iccTransmitApduBasicChannel: CommandException: " +
722 ar.exception);
723 } else {
724 loge("iccTransmitApduBasicChannel: Unknown exception");
725 }
726 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700727 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700728 break;
729
730 case CMD_EXCHANGE_SIM_IO:
731 request = (MainThreadRequest) msg.obj;
732 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000733 uiccPort = getUiccPortFromRequest(request);
734 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700735 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800736 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700737 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700738 } else {
739 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
740 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000741 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700742 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
743 iccArgument.data, onCompleted);
744 }
745 break;
746
747 case EVENT_EXCHANGE_SIM_IO_DONE:
748 ar = (AsyncResult) msg.obj;
749 request = (MainThreadRequest) ar.userObj;
750 if (ar.exception == null && ar.result != null) {
751 request.result = ar.result;
752 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800753 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700754 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700755 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700756 break;
757
Derek Tan4d5e5c12014-02-04 11:54:58 -0800758 case CMD_SEND_ENVELOPE:
759 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000760 uiccPort = getUiccPortFromRequest(request);
761 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700762 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800763 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700764 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700765 } else {
766 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800767 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700768 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800769 break;
770
771 case EVENT_SEND_ENVELOPE_DONE:
772 ar = (AsyncResult) msg.obj;
773 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700774 if (ar.exception == null && ar.result != null) {
775 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800776 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800777 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700778 if (ar.result == null) {
779 loge("sendEnvelopeWithStatus: Empty response");
780 } else if (ar.exception instanceof CommandException) {
781 loge("sendEnvelopeWithStatus: CommandException: " +
782 ar.exception);
783 } else {
784 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
785 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800786 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700787 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800788 break;
789
Shishir Agrawal566b7612013-10-28 14:41:00 -0700790 case CMD_OPEN_CHANNEL:
791 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000792 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800793 IccLogicalChannelRequest openChannelRequest =
794 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000795 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700796 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800797 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800798 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700799 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700800 } else {
801 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800802 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
803 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700804 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700805 break;
806
807 case EVENT_OPEN_CHANNEL_DONE:
808 ar = (AsyncResult) msg.obj;
809 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700810 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700811 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700812 int[] result = (int[]) ar.result;
813 int channelId = result[0];
814 byte[] selectResponse = null;
815 if (result.length > 1) {
816 selectResponse = new byte[result.length - 1];
817 for (int i = 1; i < result.length; ++i) {
818 selectResponse[i - 1] = (byte) result[i];
819 }
820 }
821 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800822 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800823
824 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700825 if (uiccPort == null) {
826 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
827 } else {
828 IccLogicalChannelRequest channelRequest =
829 (IccLogicalChannelRequest) request.argument;
830 channelRequest.channel = channelId;
831 uiccPort.onLogicalChannelOpened(channelRequest);
832 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700833 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700834 if (ar.result == null) {
835 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700836 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700837 if (ar.exception != null) {
838 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
839 }
840
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700841 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700842 if (ar.exception instanceof CommandException) {
843 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800844 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700845 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700846 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700847 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700848 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700849 }
850 }
851 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800852 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700853 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700854 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700855 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700856 break;
857
858 case CMD_CLOSE_CHANNEL:
859 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000860 uiccPort = getUiccPortFromRequest(request);
861 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700862 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800863 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800864 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800865 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700866 } else {
867 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000868 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700869 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700870 break;
871
872 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800873 ar = (AsyncResult) msg.obj;
874 request = (MainThreadRequest) ar.userObj;
875 if (ar.exception == null) {
876 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800877 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700878 if (uiccPort == null) {
879 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
880 } else {
881 final int channelId = (Integer) request.argument;
882 uiccPort.onLogicalChannelClosed(channelId);
883 }
Chen Xu540470b2021-12-14 17:15:47 -0800884 } else {
885 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800886 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800887 if (ar.exception instanceof CommandException) {
888 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
889 CommandException.Error error =
890 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800891 if (error == CommandException.Error.INVALID_ARGUMENTS) {
892 // should only throw exceptions from the binder threads.
893 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800894 "iccCloseLogicalChannel: invalid argument ");
895 }
896 } else {
897 loge("iccCloseLogicalChannel: Unknown exception");
898 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800899 request.result = (exception != null) ? exception :
900 new IllegalStateException(
901 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800902 }
903 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800904 break;
905
906 case CMD_NV_READ_ITEM:
907 request = (MainThreadRequest) msg.obj;
908 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800909 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
910 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800911 break;
912
913 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700914 ar = (AsyncResult) msg.obj;
915 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800916 if (ar.exception == null && ar.result != null) {
917 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700918 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800919 request.result = "";
920 if (ar.result == null) {
921 loge("nvReadItem: Empty response");
922 } else if (ar.exception instanceof CommandException) {
923 loge("nvReadItem: CommandException: " +
924 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700925 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800926 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700927 }
928 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700929 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700930 break;
931
Jake Hambye994d462014-02-03 13:10:13 -0800932 case CMD_NV_WRITE_ITEM:
933 request = (MainThreadRequest) msg.obj;
934 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
935 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800936 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700937 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800938 break;
939
940 case EVENT_NV_WRITE_ITEM_DONE:
941 handleNullReturnEvent(msg, "nvWriteItem");
942 break;
943
944 case CMD_NV_WRITE_CDMA_PRL:
945 request = (MainThreadRequest) msg.obj;
946 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800947 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800948 break;
949
950 case EVENT_NV_WRITE_CDMA_PRL_DONE:
951 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
952 break;
953
chen xu6dac5ab2018-10-26 17:39:23 -0700954 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800955 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700956 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800957 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800958 break;
959
chen xu6dac5ab2018-10-26 17:39:23 -0700960 case EVENT_RESET_MODEM_CONFIG_DONE:
961 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800962 break;
963
Sooraj Sasindran37444802020-08-11 10:40:43 -0700964 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
965 request = (MainThreadRequest) msg.obj;
966 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
967 request);
968 Phone phone = getPhoneFromRequest(request);
969 if (phone != null) {
970 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
971 } else {
972 loge("isNRDualConnectivityEnabled: No phone object");
973 request.result = false;
974 notifyRequester(request);
975 }
976 break;
977 }
978
979 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
980 ar = (AsyncResult) msg.obj;
981 request = (MainThreadRequest) ar.userObj;
982 if (ar.exception == null && ar.result != null) {
983 request.result = ar.result;
984 } else {
985 // request.result must be set to something non-null
986 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700987 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700988 request.result = ar.result;
989 } else {
990 request.result = false;
991 }
992 if (ar.result == null) {
993 loge("isNRDualConnectivityEnabled: Empty response");
994 } else if (ar.exception instanceof CommandException) {
995 loge("isNRDualConnectivityEnabled: CommandException: "
996 + ar.exception);
997 } else {
998 loge("isNRDualConnectivityEnabled: Unknown exception");
999 }
1000 }
1001 notifyRequester(request);
1002 break;
1003
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001004 case CMD_IS_VONR_ENABLED: {
1005 request = (MainThreadRequest) msg.obj;
1006 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
1007 request);
1008 Phone phone = getPhoneFromRequest(request);
1009 if (phone != null) {
1010 phone.isVoNrEnabled(onCompleted, request.workSource);
1011 } else {
1012 loge("isVoNrEnabled: No phone object");
1013 request.result = false;
1014 notifyRequester(request);
1015 }
1016 break;
1017 }
1018
1019 case EVENT_IS_VONR_ENABLED_DONE:
1020 ar = (AsyncResult) msg.obj;
1021 request = (MainThreadRequest) ar.userObj;
1022 if (ar.exception == null && ar.result != null) {
1023 request.result = ar.result;
1024 } else {
1025 // request.result must be set to something non-null
1026 // for the calling thread to unblock
1027 if (ar.result != null) {
1028 request.result = ar.result;
1029 } else {
1030 request.result = false;
1031 }
1032 if (ar.result == null) {
1033 loge("isVoNrEnabled: Empty response");
1034 } else if (ar.exception instanceof CommandException) {
1035 loge("isVoNrEnabled: CommandException: "
1036 + ar.exception);
1037 } else {
1038 loge("isVoNrEnabled: Unknown exception");
1039 }
1040 }
1041 notifyRequester(request);
1042 break;
1043
Sooraj Sasindran37444802020-08-11 10:40:43 -07001044 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1045 request = (MainThreadRequest) msg.obj;
1046 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1047 Phone phone = getPhoneFromRequest(request);
1048 if (phone != null) {
1049 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1050 request.workSource);
1051 } else {
1052 loge("enableNrDualConnectivity: No phone object");
1053 request.result =
1054 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1055 notifyRequester(request);
1056 }
1057 break;
1058 }
1059
1060 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1061 ar = (AsyncResult) msg.obj;
1062 request = (MainThreadRequest) ar.userObj;
1063 if (ar.exception == null) {
1064 request.result =
1065 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1066 } else {
1067 request.result =
1068 TelephonyManager
1069 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1070 if (ar.exception instanceof CommandException) {
1071 CommandException.Error error =
1072 ((CommandException) (ar.exception)).getCommandError();
1073 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1074 request.result =
1075 TelephonyManager
1076 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001077 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1078 request.result =
1079 TelephonyManager
1080 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001081 }
1082 loge("enableNrDualConnectivity" + ": CommandException: "
1083 + ar.exception);
1084 } else {
1085 loge("enableNrDualConnectivity" + ": Unknown exception");
1086 }
1087 }
1088 notifyRequester(request);
1089 break;
1090 }
1091
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001092 case CMD_ENABLE_VONR: {
1093 request = (MainThreadRequest) msg.obj;
1094 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1095 Phone phone = getPhoneFromRequest(request);
1096 if (phone != null) {
1097 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1098 request.workSource);
1099 } else {
1100 loge("setVoNrEnabled: No phone object");
1101 request.result =
1102 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1103 notifyRequester(request);
1104 }
1105 break;
1106 }
1107
1108 case EVENT_ENABLE_VONR_DONE: {
1109 ar = (AsyncResult) msg.obj;
1110 request = (MainThreadRequest) ar.userObj;
1111 if (ar.exception == null) {
1112 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1113 } else {
1114 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1115 if (ar.exception instanceof CommandException) {
1116 CommandException.Error error =
1117 ((CommandException) (ar.exception)).getCommandError();
1118 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1119 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1120 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1121 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1122 } else {
1123 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1124 }
1125 loge("setVoNrEnabled" + ": CommandException: "
1126 + ar.exception);
1127 } else {
1128 loge("setVoNrEnabled" + ": Unknown exception");
1129 }
1130 }
1131 notifyRequester(request);
1132 break;
1133 }
1134
SongFerngWang3ef3e072020-12-21 16:41:52 +08001135 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001136 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001137 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1138 request);
1139 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001140 break;
1141
SongFerngWang3ef3e072020-12-21 16:41:52 +08001142 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001143 ar = (AsyncResult) msg.obj;
1144 request = (MainThreadRequest) ar.userObj;
1145 if (ar.exception == null && ar.result != null) {
1146 request.result = ar.result; // Integer
1147 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301148 // request.result must be set to something non-null
1149 // for the calling thread to unblock
1150 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001151 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001152 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001153 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001154 loge("getAllowedNetworkTypesBitmask: CommandException: "
1155 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001156 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001157 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001158 }
1159 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001160 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001161 break;
1162
SongFerngWang3ef3e072020-12-21 16:41:52 +08001163 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001164 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001165 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1166 request);
1167 Pair<Integer, Long> reasonWithNetworkTypes =
1168 (Pair<Integer, Long>) request.argument;
1169 getPhoneFromRequest(request).setAllowedNetworkTypes(
1170 reasonWithNetworkTypes.first,
1171 reasonWithNetworkTypes.second,
1172 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001173 break;
1174
SongFerngWang3ef3e072020-12-21 16:41:52 +08001175 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1176 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001177 break;
1178
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001179 case CMD_SET_VOICEMAIL_NUMBER:
1180 request = (MainThreadRequest) msg.obj;
1181 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1182 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001183 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1184 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001185 break;
1186
1187 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1188 handleNullReturnEvent(msg, "setVoicemailNumber");
1189 break;
1190
Stuart Scott54788802015-03-30 13:18:01 -07001191 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1192 request = (MainThreadRequest) msg.obj;
1193 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1194 request);
1195 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1196 break;
1197
1198 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1199 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1200 break;
1201
Shishir Agrawal302c8692015-06-19 13:49:39 -07001202 case CMD_PERFORM_NETWORK_SCAN:
1203 request = (MainThreadRequest) msg.obj;
1204 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1205 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1206 break;
1207
Hall Liu27d24262020-09-18 19:04:59 -07001208 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001209 request = (MainThreadRequest) msg.obj;
1210 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001211 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1212 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1213 request.argument;
1214 int callForwardingReason = args.first;
1215 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001216 break;
Hall Liu27d24262020-09-18 19:04:59 -07001217 }
1218 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001219 ar = (AsyncResult) msg.obj;
1220 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001221 TelephonyManager.CallForwardingInfoCallback callback =
1222 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1223 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001224 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001225 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001226 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1227 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1228 // Service Class is a bit mask per 3gpp 27.007. Search for
1229 // any service for voice call.
1230 if ((callForwardInfo.serviceClass
1231 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001232 callForwardingInfo = new CallForwardingInfo(
1233 callForwardInfo.status
1234 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001235 callForwardInfo.reason,
1236 callForwardInfo.number,
1237 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001238 break;
1239 }
1240 }
1241 // Didn't find a call forward info for voice call.
1242 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001243 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1244 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001245 }
Hall Liu27d24262020-09-18 19:04:59 -07001246 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001247 } else {
1248 if (ar.result == null) {
1249 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1250 }
1251 if (ar.exception != null) {
1252 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1253 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001254 int errorCode = TelephonyManager
1255 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001256 if (ar.exception instanceof CommandException) {
1257 CommandException.Error error =
1258 ((CommandException) (ar.exception)).getCommandError();
1259 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001260 errorCode = TelephonyManager
1261 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001262 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001263 errorCode = TelephonyManager
1264 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001265 }
1266 }
Hall Liu27d24262020-09-18 19:04:59 -07001267 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001268 }
Shuo Qian4a594052020-01-23 11:59:30 -08001269 break;
Hall Liu27d24262020-09-18 19:04:59 -07001270 }
Shuo Qian4a594052020-01-23 11:59:30 -08001271
Hall Liu27d24262020-09-18 19:04:59 -07001272 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001273 request = (MainThreadRequest) msg.obj;
1274 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001275 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001276 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001277 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1278 request.argument).first;
1279 request.phone.setCallForwardingOption(
1280 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001281 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001282 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001283 callForwardingInfoToSet.getReason(),
1284 callForwardingInfoToSet.getNumber(),
1285 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1286 break;
Hall Liu27d24262020-09-18 19:04:59 -07001287 }
Shuo Qian4a594052020-01-23 11:59:30 -08001288
Hall Liu27d24262020-09-18 19:04:59 -07001289 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001290 ar = (AsyncResult) msg.obj;
1291 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001292 Consumer<Integer> callback =
1293 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1294 request.argument).second;
1295 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001296 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001297 int errorCode = TelephonyManager.CallForwardingInfoCallback
1298 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001299 if (ar.exception instanceof CommandException) {
1300 CommandException.Error error =
1301 ((CommandException) (ar.exception)).getCommandError();
1302 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001303 errorCode = TelephonyManager.CallForwardingInfoCallback
1304 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001305 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001306 errorCode = TelephonyManager.CallForwardingInfoCallback
1307 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001308 }
1309 }
1310 callback.accept(errorCode);
1311 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001312 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001313 }
Shuo Qian4a594052020-01-23 11:59:30 -08001314 break;
Hall Liu27d24262020-09-18 19:04:59 -07001315 }
Shuo Qian4a594052020-01-23 11:59:30 -08001316
Hall Liu27d24262020-09-18 19:04:59 -07001317 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001318 request = (MainThreadRequest) msg.obj;
1319 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1320 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1321 break;
Hall Liu27d24262020-09-18 19:04:59 -07001322 }
Shuo Qian4a594052020-01-23 11:59:30 -08001323
Hall Liu27d24262020-09-18 19:04:59 -07001324 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001325 ar = (AsyncResult) msg.obj;
1326 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001327 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001328 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001329 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001330 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001331 // Service Class is a bit mask per 3gpp 27.007.
1332 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001333 if (callForwardResults.length > 1
1334 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001335 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001336 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001337 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1338 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001339 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001340 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001341 }
1342 } else {
1343 if (ar.result == null) {
1344 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1345 }
1346 if (ar.exception != null) {
1347 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1348 }
1349 if (ar.exception instanceof CommandException) {
1350 CommandException.Error error =
1351 ((CommandException) (ar.exception)).getCommandError();
1352 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001353 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001354 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001355 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1356 callWaitingStatus =
1357 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001358 }
1359 }
1360 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001361 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001362 break;
Hall Liu27d24262020-09-18 19:04:59 -07001363 }
Shuo Qian4a594052020-01-23 11:59:30 -08001364
Hall Liu27d24262020-09-18 19:04:59 -07001365 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001366 request = (MainThreadRequest) msg.obj;
1367 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001368 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1369 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001370 break;
Hall Liu27d24262020-09-18 19:04:59 -07001371 }
Shuo Qian4a594052020-01-23 11:59:30 -08001372
Hall Liu27d24262020-09-18 19:04:59 -07001373 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001374 ar = (AsyncResult) msg.obj;
1375 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001376 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1377 Consumer<Integer> callback =
1378 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1379 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001380 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001381 if (ar.exception instanceof CommandException) {
1382 CommandException.Error error =
1383 ((CommandException) (ar.exception)).getCommandError();
1384 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1385 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001386 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1387 callback.accept(
1388 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001389 } else {
1390 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1391 }
1392 } else {
1393 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1394 }
1395 } else {
1396 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1397 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001398 }
Shuo Qian4a594052020-01-23 11:59:30 -08001399 break;
Hall Liu27d24262020-09-18 19:04:59 -07001400 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001401 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1402 ar = (AsyncResult) msg.obj;
1403 request = (MainThreadRequest) ar.userObj;
1404 CellNetworkScanResult cellScanResult;
1405 if (ar.exception == null && ar.result != null) {
1406 cellScanResult = new CellNetworkScanResult(
1407 CellNetworkScanResult.STATUS_SUCCESS,
1408 (List<OperatorInfo>) ar.result);
1409 } else {
1410 if (ar.result == null) {
1411 loge("getCellNetworkScanResults: Empty response");
1412 }
1413 if (ar.exception != null) {
1414 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1415 }
1416 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1417 if (ar.exception instanceof CommandException) {
1418 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001419 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001420 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1421 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1422 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1423 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1424 }
1425 }
1426 cellScanResult = new CellNetworkScanResult(errorCode, null);
1427 }
1428 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001429 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001430 break;
1431
1432 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1433 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001434 ManualNetworkSelectionArgument selArg =
1435 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001436 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1437 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001438 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1439 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001440 break;
1441
1442 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001443 ar = (AsyncResult) msg.obj;
1444 request = (MainThreadRequest) ar.userObj;
1445 if (ar.exception == null) {
1446 request.result = true;
1447 } else {
1448 request.result = false;
1449 loge("setNetworkSelectionModeManual " + ar.exception);
1450 }
1451 notifyRequester(request);
1452 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001453 break;
1454
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001455 case CMD_GET_MODEM_ACTIVITY_INFO:
1456 request = (MainThreadRequest) msg.obj;
1457 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001458 if (defaultPhone != null) {
1459 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001460 } else {
1461 ResultReceiver result = (ResultReceiver) request.argument;
1462 Bundle bundle = new Bundle();
1463 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001464 new ModemActivityInfo(0, 0, 0,
1465 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001466 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001467 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001468 break;
1469
Hall Liud0f208c2020-10-14 16:54:44 -07001470 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001471 ar = (AsyncResult) msg.obj;
1472 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001473 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001474 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001475 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001476 if (mLastModemActivityInfo == null) {
1477 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1478 mLastModemActivitySpecificInfo[0] =
1479 new ActivityStatsTechSpecificInfo(
1480 0,
1481 0,
1482 new int[ModemActivityInfo.getNumTxPowerLevels()],
1483 0);
1484 mLastModemActivityInfo =
1485 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1486 }
1487
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001488 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001489 // Update the last modem activity info and the result of the request.
1490 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1491 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001492 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001493 } else {
1494 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001495 }
Kai Shi917fdc62022-11-28 14:01:02 -08001496 // This is needed to decouple ret from mLastModemActivityInfo
1497 // We don't want to return mLastModemActivityInfo which is updated
1498 // inside mergeModemActivityInfo()
1499 ret = new ModemActivityInfo(
1500 mLastModemActivityInfo.getTimestampMillis(),
1501 mLastModemActivityInfo.getSleepTimeMillis(),
1502 mLastModemActivityInfo.getIdleTimeMillis(),
1503 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001504
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001505 } else {
1506 if (ar.result == null) {
1507 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001508 error = TelephonyManager.ModemActivityInfoException
1509 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001510 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001511 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001512 error = TelephonyManager.ModemActivityInfoException
1513 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001514 } else {
1515 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001516 error = TelephonyManager.ModemActivityInfoException
1517 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001518 }
1519 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001520 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001521 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001522 bundle.putParcelable(
1523 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001524 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001525 } else {
1526 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1527 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001528 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001529 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001530 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001531 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001532
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001533 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001534 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001535 CarrierRestrictionRules argument =
1536 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001537 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001538 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001539 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001540 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001541
1542 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1543 ar = (AsyncResult) msg.obj;
1544 request = (MainThreadRequest) ar.userObj;
1545 if (ar.exception == null && ar.result != null) {
1546 request.result = ar.result;
1547 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001548 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1549 if (ar.exception instanceof CommandException) {
1550 loge("setAllowedCarriers: CommandException: " + ar.exception);
1551 CommandException.Error error =
1552 ((CommandException) (ar.exception)).getCommandError();
1553 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1554 request.result =
1555 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1556 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001557 } else {
1558 loge("setAllowedCarriers: Unknown exception");
1559 }
1560 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001561 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001562 break;
1563
1564 case CMD_GET_ALLOWED_CARRIERS:
1565 request = (MainThreadRequest) msg.obj;
1566 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001567 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001568 break;
1569
1570 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1571 ar = (AsyncResult) msg.obj;
1572 request = (MainThreadRequest) ar.userObj;
1573 if (ar.exception == null && ar.result != null) {
1574 request.result = ar.result;
1575 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001576 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001577 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001578 if (ar.result == null) {
1579 loge("getAllowedCarriers: Empty response");
1580 } else if (ar.exception instanceof CommandException) {
1581 loge("getAllowedCarriers: CommandException: " +
1582 ar.exception);
1583 } else {
1584 loge("getAllowedCarriers: Unknown exception");
1585 }
1586 }
arunvoddud7401012022-12-15 16:08:12 +00001587 if (request.argument != null) {
1588 // This is for the implementation of carrierRestrictionStatus.
1589 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1590 Consumer<Integer> callback = callbackInfo.getConsumer();
1591 int callerCarrierId = callbackInfo.getCarrierId();
1592 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1593 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1594 CarrierRestrictionRules carrierRestrictionRules =
1595 (CarrierRestrictionRules) ar.result;
1596 int carrierId = -1;
1597 try {
1598 CarrierIdentifier carrierIdentifier =
1599 carrierRestrictionRules.getAllowedCarriers().get(0);
1600 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1601 carrierIdentifier);
1602 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1603 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1604 }
1605 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
1606 if (carrierId != -1 && callerCarrierId == carrierId && lockStatus
1607 == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001608 lockStatus = TelephonyManager
1609 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001610 }
1611 } else {
1612 Rlog.e(LOG_TAG,
1613 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1614 }
1615 callback.accept(lockStatus);
1616 } else {
1617 // This is for the implementation of getAllowedCarriers.
1618 notifyRequester(request);
1619 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001620 break;
1621
Nathan Haroldb3014052017-01-25 15:57:32 -08001622 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1623 ar = (AsyncResult) msg.obj;
1624 request = (MainThreadRequest) ar.userObj;
1625 if (ar.exception == null && ar.result != null) {
1626 request.result = ar.result;
1627 } else {
1628 request.result = new IllegalArgumentException(
1629 "Failed to retrieve Forbidden Plmns");
1630 if (ar.result == null) {
1631 loge("getForbiddenPlmns: Empty response");
1632 } else {
1633 loge("getForbiddenPlmns: Unknown exception");
1634 }
1635 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001636 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001637 break;
1638
1639 case CMD_GET_FORBIDDEN_PLMNS:
1640 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001641 uiccPort = getUiccPortFromRequest(request);
1642 if (uiccPort == null) {
1643 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001644 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001645 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001646 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001647 break;
1648 }
1649 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001650 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001651 if (uiccApp == null) {
1652 loge("getForbiddenPlmns() no app with specified type -- "
1653 + appType);
1654 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001655 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001656 break;
1657 } else {
1658 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1659 + " specified type -- " + appType);
1660 }
1661 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1662 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001663 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001664 break;
1665
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001666 case CMD_SWITCH_SLOTS:
1667 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001668 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001669 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001670 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001671 break;
1672
1673 case EVENT_SWITCH_SLOTS_DONE:
1674 ar = (AsyncResult) msg.obj;
1675 request = (MainThreadRequest) ar.userObj;
1676 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001677 notifyRequester(request);
1678 break;
1679 case CMD_GET_NETWORK_SELECTION_MODE:
1680 request = (MainThreadRequest) msg.obj;
1681 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1682 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1683 break;
1684
1685 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1686 ar = (AsyncResult) msg.obj;
1687 request = (MainThreadRequest) ar.userObj;
1688 if (ar.exception != null) {
1689 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1690 } else {
1691 int mode = ((int[]) ar.result)[0];
1692 if (mode == 0) {
1693 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1694 } else {
1695 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1696 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001697 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001698 notifyRequester(request);
1699 break;
1700 case CMD_GET_CDMA_ROAMING_MODE:
1701 request = (MainThreadRequest) msg.obj;
1702 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1703 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1704 break;
1705 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1706 ar = (AsyncResult) msg.obj;
1707 request = (MainThreadRequest) ar.userObj;
1708 if (ar.exception != null) {
1709 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1710 } else {
1711 request.result = ((int[]) ar.result)[0];
1712 }
1713 notifyRequester(request);
1714 break;
1715 case CMD_SET_CDMA_ROAMING_MODE:
1716 request = (MainThreadRequest) msg.obj;
1717 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1718 int mode = (int) request.argument;
1719 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1720 break;
1721 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1722 ar = (AsyncResult) msg.obj;
1723 request = (MainThreadRequest) ar.userObj;
1724 request.result = ar.exception == null;
1725 notifyRequester(request);
1726 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001727 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1728 request = (MainThreadRequest) msg.obj;
1729 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1730 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1731 break;
1732 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1733 ar = (AsyncResult) msg.obj;
1734 request = (MainThreadRequest) ar.userObj;
1735 if (ar.exception != null) {
1736 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1737 } else {
1738 request.result = ((int[]) ar.result)[0];
1739 }
1740 notifyRequester(request);
1741 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001742 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1743 request = (MainThreadRequest) msg.obj;
1744 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1745 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001746 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1747 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001748 break;
1749 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1750 ar = (AsyncResult) msg.obj;
1751 request = (MainThreadRequest) ar.userObj;
1752 request.result = ar.exception == null;
1753 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001754 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001755 case CMD_GET_ALL_CELL_INFO:
1756 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001757 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001758 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001759 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001760 case EVENT_GET_ALL_CELL_INFO_DONE:
1761 ar = (AsyncResult) msg.obj;
1762 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001763 // If a timeout occurs, the response will be null
1764 request.result = (ar.exception == null && ar.result != null)
1765 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001766 synchronized (request) {
1767 request.notifyAll();
1768 }
1769 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001770 case CMD_REQUEST_CELL_INFO_UPDATE:
1771 request = (MainThreadRequest) msg.obj;
1772 request.phone.requestCellInfoUpdate(request.workSource,
1773 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1774 break;
1775 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1776 ar = (AsyncResult) msg.obj;
1777 request = (MainThreadRequest) ar.userObj;
1778 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1779 try {
1780 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001781 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001782 cb.onError(
1783 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1784 ar.exception.getClass().getName(),
1785 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001786 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001787 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001788 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001789 } else {
1790 // use the result as returned
1791 cb.onCellInfo((List<CellInfo>) ar.result);
1792 }
1793 } catch (RemoteException re) {
1794 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1795 }
1796 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001797 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001798 request = (MainThreadRequest) msg.obj;
1799 WorkSource ws = (WorkSource) request.argument;
1800 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001801 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001802 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001803 }
1804 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001805 ar = (AsyncResult) msg.obj;
1806 request = (MainThreadRequest) ar.userObj;
1807 if (ar.exception == null) {
1808 request.result = ar.result;
1809 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001810 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001811 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001812 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001813 }
1814
1815 synchronized (request) {
1816 request.notifyAll();
1817 }
1818 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001819 }
chen xu6dac5ab2018-10-26 17:39:23 -07001820 case CMD_MODEM_REBOOT:
1821 request = (MainThreadRequest) msg.obj;
1822 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001823 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001824 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001825 case EVENT_CMD_MODEM_REBOOT_DONE:
1826 handleNullReturnEvent(msg, "rebootModem");
1827 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001828 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001829 request = (MainThreadRequest) msg.obj;
1830 boolean enable = (boolean) request.argument;
1831 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001832 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001833 PhoneConfigurationManager.getInstance()
1834 .enablePhone(request.phone, enable, onCompleted);
1835 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001836 }
Michele Berionne5e411512020-11-13 02:36:59 +00001837 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001838 ar = (AsyncResult) msg.obj;
1839 request = (MainThreadRequest) ar.userObj;
1840 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001841 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001842 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001843 if ((boolean) request.result) {
1844 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1845 updateModemStateMetrics();
1846 } else {
1847 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1848 + ar.exception);
1849 }
1850 notifyRequester(request);
1851 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001852 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001853 case CMD_GET_MODEM_STATUS:
1854 request = (MainThreadRequest) msg.obj;
1855 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1856 PhoneConfigurationManager.getInstance()
1857 .getPhoneStatusFromModem(request.phone, onCompleted);
1858 break;
1859 case EVENT_GET_MODEM_STATUS_DONE:
1860 ar = (AsyncResult) msg.obj;
1861 request = (MainThreadRequest) ar.userObj;
1862 int id = request.phone.getPhoneId();
1863 if (ar.exception == null && ar.result != null) {
1864 request.result = ar.result;
1865 //update the cache as modem status has changed
1866 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1867 (boolean) request.result);
1868 } else {
1869 // Return true if modem status cannot be retrieved. For most cases,
1870 // modem status is on. And for older version modems, GET_MODEM_STATUS
1871 // and disable modem are not supported. Modem is always on.
1872 // TODO: this should be fixed in R to support a third
1873 // status UNKNOWN b/131631629
1874 request.result = true;
1875 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1876 + ar.exception);
1877 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001878 notifyRequester(request);
1879 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001880 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1881 request = (MainThreadRequest) msg.obj;
1882 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1883 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1884 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1885 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1886 break;
1887 }
1888 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1889 ar = (AsyncResult) msg.obj;
1890 request = (MainThreadRequest) ar.userObj;
1891 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1892 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1893 args.second.accept(ar.exception == null);
1894 notifyRequester(request);
1895 break;
1896 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001897 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1898 request = (MainThreadRequest) msg.obj;
1899 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1900 Phone phone = getPhoneFromRequest(request);
1901 if (phone != null) {
1902 phone.getSystemSelectionChannels(onCompleted);
1903 } else {
1904 loge("getSystemSelectionChannels: No phone object");
1905 request.result = new ArrayList<RadioAccessSpecifier>();
1906 notifyRequester(request);
1907 }
1908 break;
1909 }
1910 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1911 ar = (AsyncResult) msg.obj;
1912 request = (MainThreadRequest) ar.userObj;
1913 if (ar.exception == null && ar.result != null) {
1914 request.result = ar.result;
1915 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001916 request.result = new IllegalStateException(
1917 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001918 if (ar.result == null) {
1919 loge("getSystemSelectionChannels: Empty response");
1920 } else {
1921 loge("getSystemSelectionChannels: Unknown exception");
1922 }
1923 }
1924 notifyRequester(request);
1925 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001926 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1927 ar = (AsyncResult) msg.obj;
1928 request = (MainThreadRequest) ar.userObj;
1929 if (ar.exception == null && ar.result != null) {
1930 request.result = ar.result;
1931 } else {
1932 request.result = -1;
1933 loge("Failed to set Forbidden Plmns");
1934 if (ar.result == null) {
1935 loge("setForbidenPlmns: Empty response");
1936 } else if (ar.exception != null) {
1937 loge("setForbiddenPlmns: Exception: " + ar.exception);
1938 request.result = -1;
1939 } else {
1940 loge("setForbiddenPlmns: Unknown exception");
1941 }
1942 }
1943 notifyRequester(request);
1944 break;
1945 case CMD_SET_FORBIDDEN_PLMNS:
1946 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001947 uiccPort = getUiccPortFromRequest(request);
1948 if (uiccPort == null) {
1949 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001950 request.result = -1;
1951 notifyRequester(request);
1952 break;
1953 }
1954 Pair<Integer, List<String>> setFplmnsArgs =
1955 (Pair<Integer, List<String>>) request.argument;
1956 appType = setFplmnsArgs.first;
1957 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001958 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001959 if (uiccApp == null) {
1960 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1961 request.result = -1;
1962 loge("Failed to get UICC App");
1963 notifyRequester(request);
1964 } else {
1965 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1966 ((SIMRecords) uiccApp.getIccRecords())
1967 .setForbiddenPlmns(onCompleted, fplmns);
1968 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001969 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001970 case CMD_ERASE_MODEM_CONFIG:
1971 request = (MainThreadRequest) msg.obj;
1972 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1973 defaultPhone.eraseModemConfig(onCompleted);
1974 break;
1975 case EVENT_ERASE_MODEM_CONFIG_DONE:
1976 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001977 break;
zoey chene02881a2019-12-30 16:11:23 +08001978
Kai Shif70f46f2021-03-03 13:59:46 -08001979 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1980 request = (MainThreadRequest) msg.obj;
1981 request.result = defaultPhone.eraseDataInSharedPreferences();
1982 notifyRequester(request);
1983 break;
1984
zoey chene02881a2019-12-30 16:11:23 +08001985 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1986 request = (MainThreadRequest) msg.obj;
1987 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1988 Pair<String, String> changed = (Pair<String, String>) request.argument;
1989 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1990 changed.first, changed.second, onCompleted);
1991 break;
1992 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1993 ar = (AsyncResult) msg.obj;
1994 request = (MainThreadRequest) ar.userObj;
1995 if (ar.exception == null) {
1996 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001997 // If the operation is successful, update the PIN storage
1998 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1999 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00002000 UiccController.getInstance().getPinStorage()
2001 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08002002 } else {
2003 request.result = msg.arg1;
2004 }
2005 notifyRequester(request);
2006 break;
2007
Michele Berionne5e411512020-11-13 02:36:59 +00002008 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08002009 request = (MainThreadRequest) msg.obj;
2010 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
2011 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2012 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2013 enabled.first, enabled.second, onCompleted);
2014 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002015 }
zoey chene02881a2019-12-30 16:11:23 +08002016 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2017 ar = (AsyncResult) msg.obj;
2018 request = (MainThreadRequest) ar.userObj;
2019 if (ar.exception == null) {
2020 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002021 // If the operation is successful, update the PIN storage
2022 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2023 int phoneId = getPhoneFromRequest(request).getPhoneId();
2024 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002025 UiccController.getInstance().getPinStorage()
2026 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002027 } else {
2028 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2029 }
zoey chene02881a2019-12-30 16:11:23 +08002030 } else {
2031 request.result = msg.arg1;
2032 }
Michele Berionne5e411512020-11-13 02:36:59 +00002033
2034
zoey chene02881a2019-12-30 16:11:23 +08002035 notifyRequester(request);
2036 break;
2037
Peter Wangdafb9ac2020-01-15 14:13:38 -08002038 case MSG_NOTIFY_USER_ACTIVITY:
2039 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002040 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002041 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2042 getDefaultPhone().getContext().sendBroadcastAsUser(
2043 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2044 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002045
2046 case CMD_SET_DATA_THROTTLING: {
2047 request = (MainThreadRequest) msg.obj;
2048 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2049 DataThrottlingRequest dataThrottlingRequest =
2050 (DataThrottlingRequest) request.argument;
2051 Phone phone = getPhoneFromRequest(request);
2052 if (phone != null) {
2053 phone.setDataThrottling(onCompleted,
2054 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2055 dataThrottlingRequest.getCompletionDurationMillis());
2056 } else {
2057 loge("setDataThrottling: No phone object");
2058 request.result =
2059 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2060 notifyRequester(request);
2061 }
2062
2063 break;
2064 }
2065 case EVENT_SET_DATA_THROTTLING_DONE:
2066 ar = (AsyncResult) msg.obj;
2067 request = (MainThreadRequest) ar.userObj;
2068
2069 if (ar.exception == null) {
2070 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2071 } else if (ar.exception instanceof CommandException) {
2072 loge("setDataThrottling: CommandException: " + ar.exception);
2073 CommandException.Error error =
2074 ((CommandException) (ar.exception)).getCommandError();
2075
2076 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2077 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002078 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002079 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2080 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002081 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2082 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002083 } else {
2084 request.result =
2085 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2086 }
2087 } else {
2088 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2089 }
2090 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2091 notifyRequester(request);
2092 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002093
2094 case CMD_SET_SIM_POWER: {
2095 request = (MainThreadRequest) msg.obj;
2096 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2097 request = (MainThreadRequest) msg.obj;
2098 int stateToSet =
2099 ((Pair<Integer, IIntegerConsumer>)
2100 request.argument).first;
2101 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2102 break;
2103 }
2104 case EVENT_SET_SIM_POWER_DONE: {
2105 ar = (AsyncResult) msg.obj;
2106 request = (MainThreadRequest) ar.userObj;
2107 IIntegerConsumer callback =
2108 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2109 if (ar.exception != null) {
2110 loge("setSimPower exception: " + ar.exception);
2111 int errorCode = TelephonyManager.CallForwardingInfoCallback
2112 .RESULT_ERROR_UNKNOWN;
2113 if (ar.exception instanceof CommandException) {
2114 CommandException.Error error =
2115 ((CommandException) (ar.exception)).getCommandError();
2116 if (error == CommandException.Error.SIM_ERR) {
2117 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2118 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2119 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2120 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2121 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2122 } else {
2123 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2124 }
2125 }
2126 try {
2127 callback.accept(errorCode);
2128 } catch (RemoteException e) {
2129 // Ignore if the remote process is no longer available to call back.
2130 Log.w(LOG_TAG, "setSimPower: callback not available.");
2131 }
2132 } else {
2133 try {
2134 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
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 }
2140 break;
2141 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002142 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2143 request = (MainThreadRequest) msg.obj;
2144
2145 final Phone phone = getPhoneFromRequest(request);
2146 if (phone == null || phone.getServiceStateTracker() == null) {
2147 request.result = new IllegalStateException("Phone or SST is null");
2148 notifyRequester(request);
2149 break;
2150 }
2151
2152 Pair<Integer, SignalStrengthUpdateRequest> pair =
2153 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2154 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2155 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002156 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002157 request.subId, pair.first /*callingUid*/,
2158 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002159 break;
2160 }
2161 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2162 ar = (AsyncResult) msg.obj;
2163 request = (MainThreadRequest) ar.userObj;
2164 // request.result will be the exception of ar if present, true otherwise.
2165 // Be cautious not to leave result null which will wait() forever
2166 request.result = ar.exception != null ? ar.exception : true;
2167 notifyRequester(request);
2168 break;
2169 }
2170 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2171 request = (MainThreadRequest) msg.obj;
2172
2173 Phone phone = getPhoneFromRequest(request);
2174 if (phone == null || phone.getServiceStateTracker() == null) {
2175 request.result = new IllegalStateException("Phone or SST is null");
2176 notifyRequester(request);
2177 break;
2178 }
2179
2180 Pair<Integer, SignalStrengthUpdateRequest> pair =
2181 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2182 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2183 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002184 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002185 request.subId, pair.first /*callingUid*/,
2186 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002187 break;
2188 }
2189 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2190 ar = (AsyncResult) msg.obj;
2191 request = (MainThreadRequest) ar.userObj;
2192 request.result = ar.exception != null ? ar.exception : true;
2193 notifyRequester(request);
2194 break;
2195 }
Jordan Liu109698e2020-11-24 14:50:34 -08002196
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002197 case CMD_GET_SLICING_CONFIG: {
2198 request = (MainThreadRequest) msg.obj;
2199 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2200 request.phone.getSlicingConfig(onCompleted);
2201 break;
2202 }
2203 case EVENT_GET_SLICING_CONFIG_DONE: {
2204 ar = (AsyncResult) msg.obj;
2205 request = (MainThreadRequest) ar.userObj;
2206 ResultReceiver result = (ResultReceiver) request.argument;
2207
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002208 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002209 Bundle bundle = new Bundle();
2210 int resultCode = 0;
2211 if (ar.exception != null) {
2212 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2213 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002214 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002215 } else if (ar.result == null) {
2216 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002217 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002218 } else {
2219 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002220 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2221 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002222 }
2223
2224 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002225 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002226 }
2227 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2228 result.send(resultCode, bundle);
2229 notifyRequester(request);
2230 break;
2231 }
2232
Sarah Chin71b3a852022-09-28 15:54:19 -07002233 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002234 request = (MainThreadRequest) msg.obj;
2235 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002236 PurchasePremiumCapabilityArgument arg =
2237 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chincc5446f2023-10-23 17:57:19 -07002238 SlicePurchaseController.getInstance(request.phone, mFeatureFlags)
2239 .purchasePremiumCapability(arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002240 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002241 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002242
Sarah Chin71b3a852022-09-28 15:54:19 -07002243 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002244 ar = (AsyncResult) msg.obj;
2245 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002246 PurchasePremiumCapabilityArgument arg =
2247 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002248 try {
2249 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002250 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002251 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002252 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chinff8b1802023-04-11 14:22:14 -07002253 + ", result="
Sarah Chin2ec39f62022-08-31 17:03:26 -07002254 + TelephonyManager.convertPurchaseResultToString(result));
2255 } catch (RemoteException e) {
2256 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002257 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002258 + " failed: " + e;
2259 if (DBG) log(logStr);
2260 AnomalyReporter.reportAnomaly(
2261 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2262 }
2263 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002264 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002265
Michele Berionne5e411512020-11-13 02:36:59 +00002266 case CMD_PREPARE_UNATTENDED_REBOOT:
2267 request = (MainThreadRequest) msg.obj;
2268 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002269 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002270 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002271 notifyRequester(request);
2272 break;
2273
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002274 default:
2275 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2276 break;
2277 }
2278 }
Jake Hambye994d462014-02-03 13:10:13 -08002279
Pengquan Menga1bb6272018-09-06 09:59:22 -07002280 private void notifyRequester(MainThreadRequest request) {
2281 synchronized (request) {
2282 request.notifyAll();
2283 }
2284 }
2285
Jake Hambye994d462014-02-03 13:10:13 -08002286 private void handleNullReturnEvent(Message msg, String command) {
2287 AsyncResult ar = (AsyncResult) msg.obj;
2288 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2289 if (ar.exception == null) {
2290 request.result = true;
2291 } else {
2292 request.result = false;
2293 if (ar.exception instanceof CommandException) {
2294 loge(command + ": CommandException: " + ar.exception);
2295 } else {
2296 loge(command + ": Unknown exception");
2297 }
2298 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002299 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002300 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002301 }
2302
2303 /**
2304 * Posts the specified command to be executed on the main thread,
2305 * waits for the request to complete, and returns the result.
2306 * @see #sendRequestAsync
2307 */
2308 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002309 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2310 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002311 }
2312
2313 /**
2314 * Posts the specified command to be executed on the main thread,
2315 * waits for the request to complete, and returns the result.
2316 * @see #sendRequestAsync
2317 */
2318 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2319 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002320 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002321 }
2322
2323 /**
2324 * Posts the specified command to be executed on the main thread,
2325 * waits for the request to complete, and returns the result.
2326 * @see #sendRequestAsync
2327 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002328 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002329 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2330 }
2331
2332 /**
2333 * Posts the specified command to be executed on the main thread,
2334 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2335 * if not timeout or null otherwise.
2336 * @see #sendRequestAsync
2337 */
2338 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2339 long timeoutInMs) {
2340 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002341 }
2342
2343 /**
2344 * Posts the specified command to be executed on the main thread,
2345 * waits for the request to complete, and returns the result.
2346 * @see #sendRequestAsync
2347 */
Nathan Harold92bed182018-10-12 18:16:49 -07002348 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002349 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002350 }
2351
2352 /**
2353 * Posts the specified command to be executed on the main thread,
2354 * waits for the request to complete, and returns the result.
2355 * @see #sendRequestAsync
2356 */
2357 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002358 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2359 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002360 }
2361
2362 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002363 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2364 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2365 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002366 * @see #sendRequestAsync
2367 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002368 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2369 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002370 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2371 throw new RuntimeException("This method will deadlock if called from the main thread.");
2372 }
2373
Nathan Harold92bed182018-10-12 18:16:49 -07002374 MainThreadRequest request = null;
2375 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2376 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2377 } else if (phone != null) {
2378 request = new MainThreadRequest(argument, phone, workSource);
2379 } else {
2380 request = new MainThreadRequest(argument, subId, workSource);
2381 }
2382
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002383 Message msg = mMainThreadHandler.obtainMessage(command, request);
2384 msg.sendToTarget();
2385
Rambo Wang0f050d82021-02-12 11:43:36 -08002386
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002387 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002388 if (timeoutInMs >= 0) {
2389 // Wait for at least timeoutInMs before returning null request result
2390 long now = SystemClock.elapsedRealtime();
2391 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002392 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002393 try {
2394 request.wait(deadline - now);
2395 } catch (InterruptedException e) {
2396 // Do nothing, go back and check if request is completed or timeout
2397 } finally {
2398 now = SystemClock.elapsedRealtime();
2399 }
2400 }
2401 } else {
2402 // Wait for the request to complete
2403 while (request.result == null) {
2404 try {
2405 request.wait();
2406 } catch (InterruptedException e) {
2407 // Do nothing, go back and wait until the request is complete
2408 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002409 }
2410 }
2411 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002412 if (request.result == null) {
2413 Log.wtf(LOG_TAG,
2414 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2415 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002416 return request.result;
2417 }
2418
2419 /**
2420 * Asynchronous ("fire and forget") version of sendRequest():
2421 * Posts the specified command to be executed on the main thread, and
2422 * returns immediately.
2423 * @see #sendRequest
2424 */
2425 private void sendRequestAsync(int command) {
2426 mMainThreadHandler.sendEmptyMessage(command);
2427 }
2428
2429 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002430 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002431 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002432 */
2433 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002434 sendRequestAsync(command, argument, null, null);
2435 }
2436
2437 /**
2438 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2439 * @see {@link #sendRequest(int,Object)}
2440 */
2441 private void sendRequestAsync(
2442 int command, Object argument, Phone phone, WorkSource workSource) {
2443 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002444 Message msg = mMainThreadHandler.obtainMessage(command, request);
2445 msg.sendToTarget();
2446 }
2447
2448 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002449 * Initialize the singleton PhoneInterfaceManager instance.
2450 * This is only done once, at startup, from PhoneApp.onCreate().
2451 */
Sarah Chincc5446f2023-10-23 17:57:19 -07002452 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002453 synchronized (PhoneInterfaceManager.class) {
2454 if (sInstance == null) {
Sarah Chincc5446f2023-10-23 17:57:19 -07002455 sInstance = new PhoneInterfaceManager(app, featureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002456 } else {
2457 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2458 }
2459 return sInstance;
2460 }
2461 }
2462
2463 /** Private constructor; @see init() */
Sarah Chincc5446f2023-10-23 17:57:19 -07002464 private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002465 mApp = app;
Sarah Chincc5446f2023-10-23 17:57:19 -07002466 mFeatureFlags = featureFlags;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002467 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002468 mImsResolver = ImsResolver.getInstance();
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +00002469 mSatelliteController = SatelliteController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002470 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002471 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2472 mMainThreadHandler = new MainThreadHandler();
Sarah Chin4beb2b72023-02-14 14:47:54 -08002473 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002474 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002475 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002476 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002477 mNotifyUserActivity = new AtomicBoolean(false);
joonhunshin4ac60942023-11-15 15:23:39 +00002478 mPackageManager = app.getPackageManager();
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -08002479 mSatelliteAccessController = SatelliteAccessController.getOrCreateInstance(
2480 getDefaultPhone().getContext(), featureFlags);
Tyler Gunn64144d92022-03-17 14:16:41 -07002481 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002482 publish();
arunvoddud7401012022-12-15 16:08:12 +00002483 CarrierAllowListInfo.loadInstance(mApp);
Hyosun Kim240214a2023-11-02 13:30:15 +00002484
2485 // Create the SatelliteEntitlementController singleton, for using the get the
2486 // entitlementStatus for satellite service.
2487 SatelliteEntitlementController.make(mApp, mFeatureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002488 }
2489
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002490 @VisibleForTesting
2491 public SharedPreferences getSharedPreferences() {
2492 return mTelephonySharedPreferences;
2493 }
2494
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002495 /**
2496 * Get the default phone for this device.
2497 */
2498 @VisibleForTesting
2499 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002500 Phone thePhone = getPhone(getDefaultSubscription());
2501 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2502 }
2503
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002504 private void publish() {
2505 if (DBG) log("publish: " + this);
2506
Peter Wangc035ce42020-01-08 21:00:22 -08002507 TelephonyFrameworkInitializer
2508 .getTelephonyServiceManager()
2509 .getTelephonyServiceRegisterer()
2510 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002511 }
2512
Stuart Scott584921c2015-01-15 17:10:34 -08002513 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002514 if (request.phone != null) {
2515 return request.phone;
2516 } else {
2517 return getPhoneFromSubId(request.subId);
2518 }
2519 }
2520
2521 private Phone getPhoneFromSubId(int subId) {
2522 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2523 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002524 }
2525
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002526 /**
2527 * Get phone object associated with a subscription.
2528 * Return default phone if phone object associated with subscription is null
2529 * @param subId - subscriptionId
2530 * @return phone object associated with a subscription or default phone if null.
2531 */
Ling Mac28f0212023-03-24 16:07:15 -07002532 private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) {
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002533 Phone phone = getPhoneFromSubId(subId);
2534 if (phone == null) {
Ling Mac28f0212023-03-24 16:07:15 -07002535 loge("Called with invalid subId: " + subId + ". Retrying with default phone.");
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002536 phone = getDefaultPhone();
2537 }
2538 return phone;
2539 }
2540
Rambo Wange53e07d2022-05-10 13:01:13 -07002541 @Nullable
2542 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002543 Phone phone = getPhoneFromRequest(request);
2544 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002545 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002546 }
2547
Ling Mac28f0212023-03-24 16:07:15 -07002548 /**
2549 * @param subId The sub Id that associates the phone. If the device has no active SIM, passing
2550 * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <=
2551 * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}.
2552 * @return The Phone associated the sub Id
2553 */
2554 private @Nullable Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002555 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002556 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002557
Kai Shif70f46f2021-03-03 13:59:46 -08002558 private void sendEraseModemConfig(@NonNull Phone phone) {
2559 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2560 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2561 }
2562
2563 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2564 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2565 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002566 }
2567
Peter Wang44b186e2020-01-13 23:33:09 -08002568 private boolean isImsAvailableOnDevice() {
2569 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2570 if (pm == null) {
2571 // For some reason package manger is not available.. This will fail internally anyway,
2572 // so do not throw error and allow.
2573 return true;
2574 }
2575 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2576 }
2577
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002578 public void dial(String number) {
joonhunshin4ac60942023-11-15 15:23:39 +00002579 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2580 PackageManager.FEATURE_TELEPHONY_CALLING, "dial");
2581
Wink Savilleadd7cc52014-09-08 14:23:09 -07002582 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002583 }
2584
Wink Savilleb564aae2014-10-23 10:18:09 -07002585 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002586 if (DBG) log("dial: " + number);
2587 // No permission check needed here: This is just a wrapper around the
2588 // ACTION_DIAL intent, which is available to any app since it puts up
2589 // the UI before it does anything.
2590
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002591 final long identity = Binder.clearCallingIdentity();
2592 try {
2593 String url = createTelUrl(number);
2594 if (url == null) {
2595 return;
2596 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002597
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002598 // PENDING: should we just silently fail if phone is offhook or ringing?
2599 PhoneConstants.State state = mCM.getState(subId);
2600 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2601 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2602 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2603 mApp.startActivity(intent);
2604 }
2605 } finally {
2606 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002607 }
2608 }
2609
2610 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002611 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002612 }
2613
Wink Savilleb564aae2014-10-23 10:18:09 -07002614 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002615 if (DBG) log("call: " + number);
2616
2617 // This is just a wrapper around the ACTION_CALL intent, but we still
2618 // need to do a permission check since we're calling startActivity()
2619 // from the context of the phone app.
2620 enforceCallPermission();
2621
Jordan Liu1617b712019-07-10 15:06:26 -07002622 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002623 != AppOpsManager.MODE_ALLOWED) {
2624 return;
2625 }
2626
joonhunshin4ac60942023-11-15 15:23:39 +00002627 enforceTelephonyFeatureWithException(callingPackage,
2628 PackageManager.FEATURE_TELEPHONY_CALLING, "call");
2629
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002630 final long identity = Binder.clearCallingIdentity();
2631 try {
2632 String url = createTelUrl(number);
2633 if (url == null) {
2634 return;
2635 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002636
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002637 boolean isValid = false;
2638 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2639 if (slist != null) {
2640 for (SubscriptionInfo subInfoRecord : slist) {
2641 if (subInfoRecord.getSubscriptionId() == subId) {
2642 isValid = true;
2643 break;
2644 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002645 }
Wink Saville08874612014-08-31 19:19:58 -07002646 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002647 if (!isValid) {
2648 return;
2649 }
Wink Saville08874612014-08-31 19:19:58 -07002650
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002651 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2652 intent.putExtra(SUBSCRIPTION_KEY, subId);
2653 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2654 mApp.startActivity(intent);
2655 } finally {
2656 Binder.restoreCallingIdentity(identity);
2657 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002658 }
2659
Wink Savilleb564aae2014-10-23 10:18:09 -07002660 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002661 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002662 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2663 }
2664
Wink Savilleb564aae2014-10-23 10:18:09 -07002665 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002666 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002667 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2668 }
2669
Wink Savilleb564aae2014-10-23 10:18:09 -07002670 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002671 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002672
joonhunshin4ac60942023-11-15 15:23:39 +00002673 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2674 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
2675 "supplyPinReportResultForSubscriber");
2676
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002677 final long identity = Binder.clearCallingIdentity();
2678 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002679 Phone phone = getPhone(subId);
2680 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002681 checkSimPin.start();
2682 return checkSimPin.unlockSim(null, pin);
2683 } finally {
2684 Binder.restoreCallingIdentity(identity);
2685 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002686 }
2687
Wink Savilleb564aae2014-10-23 10:18:09 -07002688 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002689 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002690
joonhunshin4ac60942023-11-15 15:23:39 +00002691 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2692 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "supplyPukForSubscriber");
2693
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002694 final long identity = Binder.clearCallingIdentity();
2695 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002696 Phone phone = getPhone(subId);
2697 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002698 checkSimPuk.start();
2699 return checkSimPuk.unlockSim(puk, pin);
2700 } finally {
2701 Binder.restoreCallingIdentity(identity);
2702 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002703 }
2704
2705 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002706 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002707 * a synchronous one.
2708 */
2709 private static class UnlockSim extends Thread {
2710
2711 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002712 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002713
2714 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002715 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2716 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002717
2718 // For replies from SimCard interface
2719 private Handler mHandler;
2720
2721 // For async handler to identify request type
2722 private static final int SUPPLY_PIN_COMPLETE = 100;
2723
Michele Berionne5e411512020-11-13 02:36:59 +00002724 UnlockSim(int phoneId, IccCard simCard) {
2725 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002726 mSimCard = simCard;
2727 }
2728
2729 @Override
2730 public void run() {
2731 Looper.prepare();
2732 synchronized (UnlockSim.this) {
2733 mHandler = new Handler() {
2734 @Override
2735 public void handleMessage(Message msg) {
2736 AsyncResult ar = (AsyncResult) msg.obj;
2737 switch (msg.what) {
2738 case SUPPLY_PIN_COMPLETE:
2739 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2740 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002741 mRetryCount = msg.arg1;
2742 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002743 CommandException.Error error = null;
2744 if (ar.exception instanceof CommandException) {
2745 error = ((CommandException) (ar.exception))
2746 .getCommandError();
2747 }
2748 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07002749 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002750 } else if (error == CommandException.Error.ABORTED) {
2751 /* When UiccCardApp dispose, handle message and return
2752 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08002753 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002754 } else {
2755 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2756 }
2757 } else {
2758 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2759 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002760 mDone = true;
2761 UnlockSim.this.notifyAll();
2762 }
2763 break;
2764 }
2765 }
2766 };
2767 UnlockSim.this.notifyAll();
2768 }
2769 Looper.loop();
2770 }
2771
2772 /*
2773 * Use PIN or PUK to unlock SIM card
2774 *
2775 * If PUK is null, unlock SIM card with PIN
2776 *
2777 * If PUK is not null, unlock SIM card with PUK and set PIN code
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302778 *
2779 * Besides, since it is reused in class level, the thread's looper will be stopped to avoid
2780 * its thread leak.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002781 */
Wink Saville9de0f752013-10-22 19:04:03 -07002782 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002783
2784 while (mHandler == null) {
2785 try {
2786 wait();
2787 } catch (InterruptedException e) {
2788 Thread.currentThread().interrupt();
2789 }
2790 }
2791 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2792
2793 if (puk == null) {
2794 mSimCard.supplyPin(pin, callback);
2795 } else {
2796 mSimCard.supplyPuk(puk, pin, callback);
2797 }
2798
2799 while (!mDone) {
2800 try {
2801 Log.d(LOG_TAG, "wait for done");
2802 wait();
2803 } catch (InterruptedException e) {
2804 // Restore the interrupted status
2805 Thread.currentThread().interrupt();
2806 }
2807 }
2808 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002809 int[] resultArray = new int[2];
2810 resultArray[0] = mResult;
2811 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002812
2813 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002814 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002815 }
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302816 // This instance is no longer reused, so quit its thread's looper.
2817 mHandler.getLooper().quitSafely();
Michele Berionne5e411512020-11-13 02:36:59 +00002818
Wink Saville9de0f752013-10-22 19:04:03 -07002819 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002820 }
2821 }
2822
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002823 /**
2824 * This method has been removed due to privacy and stability concerns.
2825 */
2826 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002827 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002828 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2829 return;
Wink Saville36469e72014-06-11 15:17:00 -07002830 }
2831
Nathan Harold1f889d82020-06-04 17:05:26 -07002832 @Override
2833 public void updateServiceLocationWithPackageName(String callingPackage) {
2834 mApp.getSystemService(AppOpsManager.class)
2835 .checkPackage(Binder.getCallingUid(), callingPackage);
2836
Nathan Haroldf096d982020-11-18 17:18:06 -08002837 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002838 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2839 // Callers targeting S have no business invoking this method.
2840 return;
2841 }
2842
2843 LocationAccessPolicy.LocationPermissionResult locationResult =
2844 LocationAccessPolicy.checkLocationPermission(mApp,
2845 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2846 .setCallingPackage(callingPackage)
2847 .setCallingFeatureId(null)
2848 .setCallingPid(Binder.getCallingPid())
2849 .setCallingUid(Binder.getCallingUid())
2850 .setMethod("updateServiceLocation")
2851 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2852 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2853 .build());
2854 // Apps that lack location permission have no business calling this method;
2855 // however, because no permission was declared in the public API, denials must
2856 // all be "soft".
2857 switch (locationResult) {
2858 case DENIED_HARD: /* fall through */
2859 case DENIED_SOFT:
2860 return;
2861 }
2862
2863 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002864 final long identity = Binder.clearCallingIdentity();
2865 try {
Ling Mac28f0212023-03-24 16:07:15 -07002866 getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002867 } finally {
2868 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002869 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002870 }
2871
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002872 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002873 @Override
2874 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002875 return isRadioOnWithFeature(callingPackage, null);
2876 }
2877
2878
2879 @Override
2880 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2881 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2882 callingFeatureId);
2883 }
2884
2885 @Deprecated
2886 @Override
2887 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2888 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002889 }
2890
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002891 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002892 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2893 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002894 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002895 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002896 return false;
2897 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002898
joonhunshin4ac60942023-11-15 15:23:39 +00002899 enforceTelephonyFeatureWithException(callingPackage,
2900 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isRadioOnWithFeature");
2901
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002902 final long identity = Binder.clearCallingIdentity();
2903 try {
2904 return isRadioOnForSubscriber(subId);
2905 } finally {
2906 Binder.restoreCallingIdentity(identity);
2907 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002908 }
2909
2910 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002911 final long identity = Binder.clearCallingIdentity();
2912 try {
2913 final Phone phone = getPhone(subId);
2914 if (phone != null) {
2915 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2916 } else {
2917 return false;
2918 }
2919 } finally {
2920 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002921 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002922 }
2923
2924 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002925 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002926 }
Wink Saville36469e72014-06-11 15:17:00 -07002927
Wink Savilleb564aae2014-10-23 10:18:09 -07002928 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002929 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002930
joonhunshin4ac60942023-11-15 15:23:39 +00002931 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2932 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "toggleRadioOnOffForSubscriber");
2933
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002934 final long identity = Binder.clearCallingIdentity();
2935 try {
2936 final Phone phone = getPhone(subId);
2937 if (phone != null) {
2938 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2939 }
2940 } finally {
2941 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002942 }
Wink Saville36469e72014-06-11 15:17:00 -07002943 }
2944
2945 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002946 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002947 }
2948
Wink Savilleb564aae2014-10-23 10:18:09 -07002949 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002950 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002951
2952 final long identity = Binder.clearCallingIdentity();
2953 try {
2954 final Phone phone = getPhone(subId);
2955 if (phone == null) {
2956 return false;
2957 }
2958 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2959 toggleRadioOnOffForSubscriber(subId);
2960 }
2961 return true;
2962 } finally {
2963 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002964 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002965 }
Wink Saville36469e72014-06-11 15:17:00 -07002966
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002967 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002968 enforceReadPrivilegedPermission("needMobileRadioShutdown");
joonhunshin4ac60942023-11-15 15:23:39 +00002969
2970 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2971 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needMobileRadioShutdown");
2972
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002973 /*
2974 * If any of the Radios are available, it will need to be
2975 * shutdown. So return true if any Radio is available.
2976 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002977 final long identity = Binder.clearCallingIdentity();
2978 try {
2979 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2980 Phone phone = PhoneFactory.getPhone(i);
2981 if (phone != null && phone.isRadioAvailable()) return true;
2982 }
2983 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2984 return false;
2985 } finally {
2986 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002987 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002988 }
2989
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002990 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002991 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002992 enforceModifyPermission();
2993
joonhunshin4ac60942023-11-15 15:23:39 +00002994 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2995 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "shutdownMobileRadios");
2996
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002997 final long identity = Binder.clearCallingIdentity();
2998 try {
2999 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3000 logv("Shutting down Phone " + i);
3001 shutdownRadioUsingPhoneId(i);
3002 }
3003 } finally {
3004 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003005 }
3006 }
3007
3008 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003009 Phone phone = PhoneFactory.getPhone(phoneId);
3010 if (phone != null && phone.isRadioAvailable()) {
3011 phone.shutdownRadio();
3012 }
3013 }
3014
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003015 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07003016 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003017
Ling Ma83dc5ea2023-01-12 15:06:04 -08003018 if (!turnOn) {
3019 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
3020 }
3021
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003022 final long identity = Binder.clearCallingIdentity();
3023 try {
3024 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
3025 if (defaultPhone != null) {
3026 defaultPhone.setRadioPower(turnOn);
3027 return true;
3028 } else {
3029 loge("There's no default phone.");
3030 return false;
3031 }
3032 } finally {
3033 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07003034 }
Wink Saville36469e72014-06-11 15:17:00 -07003035 }
3036
Wink Savilleb564aae2014-10-23 10:18:09 -07003037 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003038 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003039
Ling Ma83dc5ea2023-01-12 15:06:04 -08003040 if (!turnOn) {
3041 log("setRadioPowerForSubscriber off: subId=" + subId
3042 + ",callingPackage=" + getCurrentPackageName());
3043 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003044 final long identity = Binder.clearCallingIdentity();
3045 try {
3046 final Phone phone = getPhone(subId);
3047 if (phone != null) {
3048 phone.setRadioPower(turnOn);
3049 return true;
3050 } else {
3051 return false;
3052 }
3053 } finally {
3054 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003055 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003056 }
3057
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003058 /**
3059 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3060 * no reason to power it off. When any of the voters want to power it off, it will be turned
3061 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3062 * powering it off, and these radio off votes will be cleared.
3063 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3064 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3065 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3066 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3067 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3068 * check its vote.
3069 *
3070 * @param subId The subscription ID.
3071 * @param reason The reason for powering off radio.
3072 * @return true on success and false on failure.
3073 */
3074 public boolean requestRadioPowerOffForReason(int subId,
3075 @TelephonyManager.RadioPowerReason int reason) {
3076 enforceModifyPermission();
3077
joonhunshin4ac60942023-11-15 15:23:39 +00003078 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3079 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestRadioPowerOffForReason");
3080
Ling Ma83dc5ea2023-01-12 15:06:04 -08003081 log("requestRadioPowerOffForReason: subId=" + subId
3082 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003083 final long identity = Binder.clearCallingIdentity();
3084 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003085 boolean result = false;
3086 for (Phone phone : PhoneFactory.getPhones()) {
3087 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003088 phone.setRadioPowerForReason(false, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003089 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003090 if (!result) {
3091 loge("requestRadioPowerOffForReason: no phone exists");
3092 }
3093 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003094 } finally {
3095 Binder.restoreCallingIdentity(identity);
3096 }
3097 }
3098
3099 /**
3100 * Remove the vote on powering off the radio for a reason, as requested by
3101 * {@link requestRadioPowerOffForReason}.
3102 *
3103 * @param subId The subscription ID.
3104 * @param reason The reason for powering off radio.
3105 * @return true on success and false on failure.
3106 */
3107 public boolean clearRadioPowerOffForReason(int subId,
3108 @TelephonyManager.RadioPowerReason int reason) {
3109 enforceModifyPermission();
3110
joonhunshin4ac60942023-11-15 15:23:39 +00003111 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3112 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearRadioPowerOffForReason");
3113
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003114 final long identity = Binder.clearCallingIdentity();
3115 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003116 boolean result = false;
3117 for (Phone phone : PhoneFactory.getPhones()) {
3118 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003119 phone.setRadioPowerForReason(true, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003120 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003121 if (!result) {
3122 loge("clearRadioPowerOffForReason: no phone exists");
3123 }
3124 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003125 } finally {
3126 Binder.restoreCallingIdentity(identity);
3127 }
3128 }
3129
3130 /**
3131 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3132 *
3133 * @param subId The subscription ID.
3134 * @param callingPackage The package making the call.
3135 * @param callingFeatureId The feature in the package.
3136 * @return List of reasons for powering off radio.
3137 */
3138 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3139 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3140
joonhunshin4ac60942023-11-15 15:23:39 +00003141 enforceTelephonyFeatureWithException(callingPackage,
3142 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerOffReasons");
3143
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003144 final long identity = Binder.clearCallingIdentity();
3145 List result = new ArrayList();
3146 try {
3147 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3148 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3149 return result;
3150 }
3151
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003152 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003153 if (phone != null) {
3154 result.addAll(phone.getRadioPowerOffReasons());
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003155 } else {
3156 loge("getRadioPowerOffReasons: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003157 }
3158 } finally {
3159 Binder.restoreCallingIdentity(identity);
3160 }
3161 return result;
3162 }
3163
Wink Saville36469e72014-06-11 15:17:00 -07003164 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003165 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003166 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003167 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003168
joonhunshin4ac60942023-11-15 15:23:39 +00003169 enforceTelephonyFeatureWithException(callingPackage,
3170 PackageManager.FEATURE_TELEPHONY_DATA, "enableDataConnectivity");
3171
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003172 final long identity = Binder.clearCallingIdentity();
3173 try {
Jack Yu285100e2022-12-02 22:48:35 -08003174 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003175 final Phone phone = getPhone(subId);
3176 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003177 phone.getDataSettingsManager().setDataEnabled(
3178 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003179 return true;
3180 } else {
3181 return false;
3182 }
3183 } finally {
3184 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003185 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003186 }
3187
Wink Saville36469e72014-06-11 15:17:00 -07003188 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003189 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003190 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003191 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003192
joonhunshin4ac60942023-11-15 15:23:39 +00003193 enforceTelephonyFeatureWithException(callingPackage,
3194 PackageManager.FEATURE_TELEPHONY_DATA, "disableDataConnectivity");
3195
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003196 final long identity = Binder.clearCallingIdentity();
3197 try {
Jack Yu285100e2022-12-02 22:48:35 -08003198 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003199 final Phone phone = getPhone(subId);
3200 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003201 phone.getDataSettingsManager().setDataEnabled(
3202 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003203 return true;
3204 } else {
3205 return false;
3206 }
3207 } finally {
3208 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003209 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003210 }
3211
Sanket Padawe356d7632015-06-22 14:03:32 -07003212 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003213 public boolean isDataConnectivityPossible(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003214 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3215 PackageManager.FEATURE_TELEPHONY_DATA, "isDataConnectivityPossible");
3216
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003217 final long identity = Binder.clearCallingIdentity();
3218 try {
3219 final Phone phone = getPhone(subId);
3220 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003221 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003222 } else {
3223 return false;
3224 }
3225 } finally {
3226 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003227 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003228 }
3229
3230 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003231 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003232 }
3233
pkanwarae03a6b2016-11-06 20:37:09 -08003234 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003235 enforceCallPermission();
3236
joonhunshin4ac60942023-11-15 15:23:39 +00003237 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3238 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "handleUssdRequest");
3239
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003240 final long identity = Binder.clearCallingIdentity();
3241 try {
3242 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3243 return;
3244 }
3245 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3246 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3247 } finally {
3248 Binder.restoreCallingIdentity(identity);
3249 }
pkanwar32d516d2016-10-14 19:37:38 -07003250 };
3251
Wink Savilleb564aae2014-10-23 10:18:09 -07003252 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003253 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003254
joonhunshin4ac60942023-11-15 15:23:39 +00003255 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3256 PackageManager.FEATURE_TELEPHONY_CALLING, "handlePinMmiForSubscriber");
3257
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003258 final long identity = Binder.clearCallingIdentity();
3259 try {
3260 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3261 return false;
3262 }
3263 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3264 } finally {
3265 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003266 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003267 }
3268
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003269 /**
3270 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3271 * tag on getCallState Binder call.
3272 */
3273 @Deprecated
3274 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003275 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003276 if (CompatChanges.isChangeEnabled(
3277 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3278 Binder.getCallingUid())) {
3279 // Do not allow this API to be called on API version 31+, it should only be
3280 // called on old apps using this Binder call directly.
3281 throw new SecurityException("This method can only be used for applications "
3282 + "targeting API version 30 or less.");
3283 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003284 final long identity = Binder.clearCallingIdentity();
3285 try {
Ling Mac28f0212023-03-24 16:07:15 -07003286 Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription());
3287 return PhoneConstantConversions.convertCallState(phone.getState());
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003288 } finally {
3289 Binder.restoreCallingIdentity(identity);
3290 }
3291 }
3292
3293 @Override
3294 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3295 if (CompatChanges.isChangeEnabled(
3296 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3297 Binder.getCallingUid())) {
3298 // Check READ_PHONE_STATE for API version 31+
3299 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3300 featureId, "getCallStateForSubscription")) {
3301 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3302 + "targeting API level 31+.");
3303 }
3304 }
joonhunshin4ac60942023-11-15 15:23:39 +00003305
3306 enforceTelephonyFeatureWithException(callingPackage,
3307 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallStateForSubscription");
3308
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003309 final long identity = Binder.clearCallingIdentity();
3310 try {
3311 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003312 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3313 PhoneConstantConversions.convertCallState(phone.getState());
3314 } finally {
3315 Binder.restoreCallingIdentity(identity);
3316 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003317 }
3318
Sanket Padawe356d7632015-06-22 14:03:32 -07003319 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003320 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003321 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003322 }
3323
3324 @Override
3325 public int getDataStateForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003326 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3327 PackageManager.FEATURE_TELEPHONY_DATA, "getDataStateForSubId");
3328
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003329 final long identity = Binder.clearCallingIdentity();
3330 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003331 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003332 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003333 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003334 } else {
3335 return PhoneConstantConversions.convertDataState(
3336 PhoneConstants.DataState.DISCONNECTED);
3337 }
3338 } finally {
3339 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003340 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003341 }
3342
Sanket Padawe356d7632015-06-22 14:03:32 -07003343 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003344 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003345 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003346 }
3347
3348 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003349 public @DataActivityType int getDataActivityForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003350 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3351 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivityForSubId");
3352
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003353 final long identity = Binder.clearCallingIdentity();
3354 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003355 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003356 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003357 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003358 } else {
3359 return TelephonyManager.DATA_ACTIVITY_NONE;
3360 }
3361 } finally {
3362 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003363 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003364 }
3365
3366 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003367 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003368 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003369 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003370
3371 LocationAccessPolicy.LocationPermissionResult locationResult =
3372 LocationAccessPolicy.checkLocationPermission(mApp,
3373 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3374 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003375 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003376 .setCallingPid(Binder.getCallingPid())
3377 .setCallingUid(Binder.getCallingUid())
3378 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003379 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003380 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3381 .build());
3382 switch (locationResult) {
3383 case DENIED_HARD:
3384 throw new SecurityException("Not allowed to access cell location");
3385 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003386 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3387 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003388 }
3389
joonhunshin4ac60942023-11-15 15:23:39 +00003390 enforceTelephonyFeatureWithException(callingPackage,
3391 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getCellLocation");
3392
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003393 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003394 final long identity = Binder.clearCallingIdentity();
3395 try {
3396 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003397 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003398 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003399 } finally {
3400 Binder.restoreCallingIdentity(identity);
3401 }
Svetoslav64fad262015-04-14 14:35:21 -07003402 }
3403
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003404 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003405 public String getNetworkCountryIsoForPhone(int phoneId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003406 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3407 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkCountryIsoForPhone");
3408
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003409 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3410 // registered cell info, so return a NULL country instead.
3411 final long identity = Binder.clearCallingIdentity();
3412 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003413 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3414 // Get default phone in this case.
3415 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3416 }
Jack Yu285100e2022-12-02 22:48:35 -08003417 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003418 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003419 if (phone == null) return "";
3420 ServiceStateTracker sst = phone.getServiceStateTracker();
3421 if (sst == null) return "";
3422 LocaleTracker lt = sst.getLocaleTracker();
3423 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003424 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003425 } finally {
3426 Binder.restoreCallingIdentity(identity);
3427 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003428 }
3429
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003430 /**
3431 * This method was removed due to potential issues caused by performing partial
3432 * updates of service state, and lack of a credible use case.
3433 *
3434 * This has the ability to break the telephony implementation by disabling notification of
3435 * changes in device connectivity. DO NOT USE THIS!
3436 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003437 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003438 public void enableLocationUpdates() {
3439 mApp.enforceCallingOrSelfPermission(
3440 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003441 }
3442
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003443 /**
3444 * This method was removed due to potential issues caused by performing partial
3445 * updates of service state, and lack of a credible use case.
3446 *
3447 * This has the ability to break the telephony implementation by disabling notification of
3448 * changes in device connectivity. DO NOT USE THIS!
3449 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003450 @Override
3451 public void disableLocationUpdates() {
3452 mApp.enforceCallingOrSelfPermission(
3453 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003454 }
3455
3456 @Override
3457 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003458 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3459 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003460 try {
3461 mApp.getSystemService(AppOpsManager.class)
3462 .checkPackage(Binder.getCallingUid(), callingPackage);
3463 } catch (SecurityException e) {
3464 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3465 throw e;
3466 }
3467
Nathan Haroldf096d982020-11-18 17:18:06 -08003468 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003469 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3470 throw new SecurityException(
3471 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3472 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003473
Jordan Liu1617b712019-07-10 15:06:26 -07003474 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003475 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3476 return null;
3477 }
Svetoslav64fad262015-04-14 14:35:21 -07003478
joonhunshin4ac60942023-11-15 15:23:39 +00003479 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3480 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNeighboringCellInfo");
3481
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003482 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003483
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003484 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003485 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003486
Nathan Haroldf180aac2018-06-01 18:43:55 -07003487 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3488 for (CellInfo ci : info) {
3489 if (ci instanceof CellInfoGsm) {
3490 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3491 } else if (ci instanceof CellInfoWcdma) {
3492 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3493 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003494 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003495 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003496 }
3497
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003498 private List<CellInfo> getCachedCellInfo() {
3499 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3500 for (Phone phone : PhoneFactory.getPhones()) {
3501 List<CellInfo> info = phone.getAllCellInfo();
3502 if (info != null) cellInfos.addAll(info);
3503 }
3504 return cellInfos;
3505 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003506
3507 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003508 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003509 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003510 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003511
3512 LocationAccessPolicy.LocationPermissionResult locationResult =
3513 LocationAccessPolicy.checkLocationPermission(mApp,
3514 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3515 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003516 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003517 .setCallingPid(Binder.getCallingPid())
3518 .setCallingUid(Binder.getCallingUid())
3519 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003520 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003521 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3522 .build());
3523 switch (locationResult) {
3524 case DENIED_HARD:
3525 throw new SecurityException("Not allowed to access cell info");
3526 case DENIED_SOFT:
3527 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003528 }
3529
Nathan Haroldf096d982020-11-18 17:18:06 -08003530 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003531 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3532 return getCachedCellInfo();
3533 }
3534
joonhunshin4ac60942023-11-15 15:23:39 +00003535 enforceTelephonyFeatureWithException(callingPackage,
3536 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllCellInfo");
3537
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003538 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003539 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003540 final long identity = Binder.clearCallingIdentity();
3541 try {
3542 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3543 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003544 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003545 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003546 if (info != null) cellInfos.addAll(info);
3547 }
3548 return cellInfos;
3549 } finally {
3550 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003551 }
3552 }
3553
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003554 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003555 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3556 String callingFeatureId) {
3557 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3558 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003559 }
3560
3561 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003562 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3563 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003564 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003565 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003566 }
3567
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003568 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3569 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003570 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003571 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003572
3573 LocationAccessPolicy.LocationPermissionResult locationResult =
3574 LocationAccessPolicy.checkLocationPermission(mApp,
3575 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3576 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003577 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003578 .setCallingPid(Binder.getCallingPid())
3579 .setCallingUid(Binder.getCallingUid())
3580 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003581 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3582 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003583 .build());
3584 switch (locationResult) {
3585 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003586 if (TelephonyPermissions
3587 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003588 // Safetynet logging for b/154934934
3589 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3590 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003591 throw new SecurityException("Not allowed to access cell info");
3592 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003593 if (TelephonyPermissions
3594 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003595 // Safetynet logging for b/154934934
3596 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3597 }
Nathan Harold5320c422019-05-09 10:26:08 -07003598 try {
3599 cb.onCellInfo(new ArrayList<CellInfo>());
3600 } catch (RemoteException re) {
3601 // Drop without consequences
3602 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003603 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003604 }
3605
joonhunshin4ac60942023-11-15 15:23:39 +00003606 enforceTelephonyFeatureWithException(callingPackage,
3607 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestCellInfoUpdateInternal");
Nathan Harolda939a962019-05-09 10:13:47 -07003608
3609 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003610 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3611
3612 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3613 }
3614
3615 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003616 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003617 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003618 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003619
3620 final long identity = Binder.clearCallingIdentity();
3621 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003622 Phone phone = getPhone(subId);
3623 if (phone == null) {
3624 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3625 } else {
3626 phone.setCellInfoListRate(rateInMillis, workSource);
3627 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003628 } finally {
3629 Binder.restoreCallingIdentity(identity);
3630 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003631 }
3632
Shishir Agrawala9f32182016-04-12 12:00:16 -07003633 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003634 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003635 Phone phone = PhoneFactory.getPhone(slotIndex);
3636 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003637 return null;
3638 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003639 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003640 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003641 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003642 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003643 return null;
3644 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003645
joonhunshin4ac60942023-11-15 15:23:39 +00003646 enforceTelephonyFeatureWithException(callingPackage,
3647 PackageManager.FEATURE_TELEPHONY_GSM, "getImeiForSlot");
3648
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003649 final long identity = Binder.clearCallingIdentity();
3650 try {
3651 return phone.getImei();
3652 } finally {
3653 Binder.restoreCallingIdentity(identity);
3654 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003655 }
3656
3657 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003658 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3659 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3660 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3661 callingFeatureId, "getPrimaryImei")) {
3662 throw new SecurityException("Caller does not have permission");
3663 }
joonhunshin4ac60942023-11-15 15:23:39 +00003664
3665 enforceTelephonyFeatureWithException(callingPackage,
3666 PackageManager.FEATURE_TELEPHONY_GSM, "getPrimaryImei");
3667
arunvoddud5c6ce02022-12-11 06:03:12 +00003668 final long identity = Binder.clearCallingIdentity();
3669 try {
3670 for (Phone phone : PhoneFactory.getPhones()) {
3671 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3672 return phone.getImei();
3673 }
3674 }
3675 throw new UnsupportedOperationException("Operation not supported");
3676 } finally {
3677 Binder.restoreCallingIdentity(identity);
3678 }
3679 }
3680
3681 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003682 public String getTypeAllocationCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003683 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3684 PackageManager.FEATURE_TELEPHONY_GSM, "getTypeAllocationCodeForSlot");
3685
David Kelly5e06a7f2018-03-12 14:10:59 +00003686 Phone phone = PhoneFactory.getPhone(slotIndex);
3687 String tac = null;
3688 if (phone != null) {
3689 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003690 try {
3691 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3692 } catch (IndexOutOfBoundsException e) {
3693 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3694 return null;
3695 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003696 }
3697 return tac;
3698 }
3699
3700 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003701 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003702 try {
3703 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3704 } catch (SecurityException se) {
3705 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3706 throw new SecurityException("Package " + callingPackage + " does not belong to "
3707 + Binder.getCallingUid());
3708 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003709 Phone phone = PhoneFactory.getPhone(slotIndex);
3710 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003711 return null;
3712 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003713
Jeff Davidson913390f2018-02-23 17:11:49 -08003714 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003715 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003716 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003717 return null;
3718 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003719
joonhunshin4ac60942023-11-15 15:23:39 +00003720 enforceTelephonyFeatureWithException(callingPackage,
3721 PackageManager.FEATURE_TELEPHONY_CDMA, "getMeidForSlot");
3722
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003723 final long identity = Binder.clearCallingIdentity();
3724 try {
3725 return phone.getMeid();
3726 } finally {
3727 Binder.restoreCallingIdentity(identity);
3728 }
Jack Yu2af8d712017-03-15 17:14:14 -07003729 }
3730
3731 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003732 public String getManufacturerCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003733 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3734 PackageManager.FEATURE_TELEPHONY_CDMA, "getManufacturerCodeForSlot");
3735
David Kelly5e06a7f2018-03-12 14:10:59 +00003736 Phone phone = PhoneFactory.getPhone(slotIndex);
3737 String manufacturerCode = null;
3738 if (phone != null) {
3739 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003740 try {
3741 manufacturerCode =
3742 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3743 } catch (IndexOutOfBoundsException e) {
3744 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3745 return null;
3746 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003747 }
3748 return manufacturerCode;
3749 }
3750
3751 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003752 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3753 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003754 Phone phone = PhoneFactory.getPhone(slotIndex);
3755 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003756 return null;
3757 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003758 int subId = phone.getSubId();
3759 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003760 mApp, subId, callingPackage, callingFeatureId,
3761 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003762 return null;
3763 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003764
joonhunshin4ac60942023-11-15 15:23:39 +00003765 enforceTelephonyFeatureWithException(callingPackage,
3766 PackageManager.FEATURE_TELEPHONY, "getDeviceSoftwareVersionForSlot");
3767
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003768 final long identity = Binder.clearCallingIdentity();
3769 try {
3770 return phone.getDeviceSvn();
3771 } finally {
3772 Binder.restoreCallingIdentity(identity);
3773 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003774 }
3775
fionaxu43304da2017-11-27 22:51:16 -08003776 @Override
3777 public int getSubscriptionCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003778 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3779 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierId");
3780
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003781 final long identity = Binder.clearCallingIdentity();
3782 try {
3783 final Phone phone = getPhone(subId);
3784 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3785 } finally {
3786 Binder.restoreCallingIdentity(identity);
3787 }
fionaxu43304da2017-11-27 22:51:16 -08003788 }
3789
3790 @Override
3791 public String getSubscriptionCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003792 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3793 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierName");
3794
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003795 final long identity = Binder.clearCallingIdentity();
3796 try {
3797 final Phone phone = getPhone(subId);
3798 return phone == null ? null : phone.getCarrierName();
3799 } finally {
3800 Binder.restoreCallingIdentity(identity);
3801 }
fionaxu43304da2017-11-27 22:51:16 -08003802 }
3803
calvinpanffe225e2018-11-01 19:43:06 +08003804 @Override
chen xu0026ca62019-03-06 15:28:50 -08003805 public int getSubscriptionSpecificCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003806 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3807 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionSpecificCarrierId");
3808
chen xu25637222018-11-04 17:17:00 -08003809 final long identity = Binder.clearCallingIdentity();
3810 try {
3811 final Phone phone = getPhone(subId);
3812 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003813 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003814 } finally {
3815 Binder.restoreCallingIdentity(identity);
3816 }
3817 }
3818
3819 @Override
chen xu0026ca62019-03-06 15:28:50 -08003820 public String getSubscriptionSpecificCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003821 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3822 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
3823 "getSubscriptionSpecificCarrierName");
3824
chen xu25637222018-11-04 17:17:00 -08003825 final long identity = Binder.clearCallingIdentity();
3826 try {
3827 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003828 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003829 } finally {
3830 Binder.restoreCallingIdentity(identity);
3831 }
3832 }
3833
chen xu651eec72018-11-11 19:03:44 -08003834 @Override
chen xu864e11c2018-12-06 22:10:03 -08003835 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3836 if (!isSubscriptionMccMnc) {
3837 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3838 }
chen xu651eec72018-11-11 19:03:44 -08003839 final Phone phone = PhoneFactory.getPhone(slotIndex);
3840 if (phone == null) {
3841 return TelephonyManager.UNKNOWN_CARRIER_ID;
3842 }
joonhunshin4ac60942023-11-15 15:23:39 +00003843
3844 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3845 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromMccMnc");
3846
chen xu651eec72018-11-11 19:03:44 -08003847 final long identity = Binder.clearCallingIdentity();
3848 try {
3849 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3850 } finally {
3851 Binder.restoreCallingIdentity(identity);
3852 }
3853 }
3854
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003855 //
3856 // Internal helper methods.
3857 //
3858
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003859 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003860 * Make sure the caller is the calling package itself
3861 *
3862 * @throws SecurityException if the caller is not the calling package
3863 */
3864 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3865 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003866 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3867 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003868 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003869 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003870 } catch (PackageManager.NameNotFoundException e) {
3871 // packageUid is -1
3872 }
3873 if (packageUid != callingUid) {
3874 throw new SecurityException(message + ": Package " + callingPackage
3875 + " does not belong to " + callingUid);
3876 }
3877 }
3878
3879 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003880 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3881 *
3882 * @throws SecurityException if the caller does not have the required permission
3883 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003884 @VisibleForTesting
3885 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003886 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3887 }
3888
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003889 /**
arunvoddud7401012022-12-15 16:08:12 +00003890 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003891 *
3892 * @throws SecurityException if the caller does not have the required permission
3893 */
3894 @VisibleForTesting
3895 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003896 enforceReadPermission(null);
3897 }
3898
3899 /**
3900 * Make sure the caller has the READ_PHONE_STATE permissions.
3901 *
3902 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3903 */
3904 @VisibleForTesting
3905 public void enforceReadPermission(String msg) {
3906 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003907 }
3908
Shuo Qian3b6ee772019-11-13 17:43:31 -08003909 private void enforceActiveEmergencySessionPermission() {
3910 mApp.enforceCallingOrSelfPermission(
3911 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3912 }
3913
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003914 /**
3915 * Make sure the caller has the CALL_PHONE permission.
3916 *
3917 * @throws SecurityException if the caller does not have the required permission
3918 */
3919 private void enforceCallPermission() {
3920 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3921 }
3922
paulhu5a773602019-08-23 19:17:33 +08003923 private void enforceSettingsPermission() {
3924 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003925 }
3926
Michele Berionne5e411512020-11-13 02:36:59 +00003927 private void enforceRebootPermission() {
3928 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3929 }
3930
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003931 /**
3932 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3933 * @param message - log message to print.
3934 * @throws SecurityException if the caller does not have the required permission
3935 */
3936 private void enforceSatelliteCommunicationPermission(String message) {
3937 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3938 }
3939
Aishwarya Mallampatif265cea2024-06-04 19:55:41 +00003940 /**
3941 * Make sure the caller has PACKAGE_USAGE_STATS permission.
3942 * @param message - log message to print.
3943 * @throws SecurityException if the caller does not have the required permission
3944 */
3945 private void enforcePackageUsageStatsPermission(String message) {
3946 mApp.enforceCallingOrSelfPermission(permission.PACKAGE_USAGE_STATS, message);
3947 }
3948
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003949 private String createTelUrl(String number) {
3950 if (TextUtils.isEmpty(number)) {
3951 return null;
3952 }
3953
Jake Hambye994d462014-02-03 13:10:13 -08003954 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003955 }
3956
Ihab Awadf9e92732013-12-05 18:02:52 -08003957 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003958 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003959 }
3960
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003961 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003962 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003963 }
3964
Ihab Awadf9e92732013-12-05 18:02:52 -08003965 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003966 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003967 }
3968
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003969 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003970 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003971 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003972 }
3973
Sanket Padawe356d7632015-06-22 14:03:32 -07003974 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003975 public int getActivePhoneTypeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003976 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3977 PackageManager.FEATURE_TELEPHONY, "getActivePhoneTypeForSlot");
3978
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003979 final long identity = Binder.clearCallingIdentity();
3980 try {
3981 final Phone phone = PhoneFactory.getPhone(slotIndex);
3982 if (phone == null) {
3983 return PhoneConstants.PHONE_TYPE_NONE;
3984 } else {
3985 return phone.getPhoneType();
3986 }
3987 } finally {
3988 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003989 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003990 }
3991
3992 /**
3993 * Returns the CDMA ERI icon index to display
3994 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003995 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003996 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3997 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3998 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003999 }
4000
Sanket Padawe356d7632015-06-22 14:03:32 -07004001 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004002 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
4003 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004004 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004005 mApp, subId, callingPackage, callingFeatureId,
4006 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004007 return -1;
4008 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004009
joonhunshin4ac60942023-11-15 15:23:39 +00004010 enforceTelephonyFeatureWithException(callingPackage,
4011 PackageManager.FEATURE_TELEPHONY_CDMA,
4012 "getCdmaEriIconIndexForSubscriber");
4013
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004014 final long identity = Binder.clearCallingIdentity();
4015 try {
4016 final Phone phone = getPhone(subId);
4017 if (phone != null) {
4018 return phone.getCdmaEriIconIndex();
4019 } else {
4020 return -1;
4021 }
4022 } finally {
4023 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004024 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004025 }
4026
4027 /**
4028 * Returns the CDMA ERI icon mode,
4029 * 0 - ON
4030 * 1 - FLASHING
4031 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004032 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004033 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
4034 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
4035 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004036 }
4037
Sanket Padawe356d7632015-06-22 14:03:32 -07004038 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004039 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
4040 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004041 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004042 mApp, subId, callingPackage, callingFeatureId,
4043 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004044 return -1;
4045 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004046
4047 final long identity = Binder.clearCallingIdentity();
4048 try {
4049 final Phone phone = getPhone(subId);
4050 if (phone != null) {
4051 return phone.getCdmaEriIconMode();
4052 } else {
4053 return -1;
4054 }
4055 } finally {
4056 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004057 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004058 }
4059
4060 /**
4061 * Returns the CDMA ERI text,
4062 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004063 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004064 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
4065 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
4066 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004067 }
4068
Sanket Padawe356d7632015-06-22 14:03:32 -07004069 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004070 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
4071 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004072 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004073 mApp, subId, callingPackage, callingFeatureId,
4074 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004075 return null;
4076 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004077
4078 final long identity = Binder.clearCallingIdentity();
4079 try {
4080 final Phone phone = getPhone(subId);
4081 if (phone != null) {
4082 return phone.getCdmaEriText();
4083 } else {
4084 return null;
4085 }
4086 } finally {
4087 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004088 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004089 }
4090
4091 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07004092 * Returns the CDMA MDN.
4093 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004094 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004095 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004096 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4097 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004098
joonhunshin4ac60942023-11-15 15:23:39 +00004099 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4100 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMdn");
4101
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004102 final long identity = Binder.clearCallingIdentity();
4103 try {
4104 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004105 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004106 return phone.getLine1Number();
4107 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004108 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004109 return null;
4110 }
4111 } finally {
4112 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004113 }
4114 }
4115
4116 /**
4117 * Returns the CDMA MIN.
4118 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004119 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004120 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004121 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4122 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004123
joonhunshin4ac60942023-11-15 15:23:39 +00004124 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4125 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMin");
4126
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004127 final long identity = Binder.clearCallingIdentity();
4128 try {
4129 final Phone phone = getPhone(subId);
4130 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
4131 return phone.getCdmaMin();
4132 } else {
4133 return null;
4134 }
4135 } finally {
4136 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004137 }
4138 }
4139
Hall Liud892bec2018-11-30 14:51:45 -08004140 @Override
4141 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
4142 INumberVerificationCallback callback, String callingPackage) {
4143 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
4144 != PERMISSION_GRANTED) {
4145 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
4146 }
4147 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4148
4149 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
4150 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08004151 throw new SecurityException("Calling package must be configured in the device config: "
4152 + "calling package: " + callingPackage
4153 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004154 }
4155
joonhunshin4ac60942023-11-15 15:23:39 +00004156 enforceTelephonyFeatureWithException(callingPackage,
4157 PackageManager.FEATURE_TELEPHONY_CALLING, "requestNumberVerification");
4158
Hall Liud892bec2018-11-30 14:51:45 -08004159 if (range == null) {
4160 throw new NullPointerException("Range must be non-null");
4161 }
4162
4163 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004164 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004165
4166 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4167 }
4168
Junda Liuca05d5d2014-08-14 22:36:34 -07004169 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004170 * Returns true if CDMA provisioning needs to run.
4171 */
4172 public boolean needsOtaServiceProvisioning() {
joonhunshin4ac60942023-11-15 15:23:39 +00004173 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4174 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needsOtaServiceProvisioning");
4175
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004176 final long identity = Binder.clearCallingIdentity();
4177 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004178 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004179 } finally {
4180 Binder.restoreCallingIdentity(identity);
4181 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004182 }
4183
4184 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004185 * Sets the voice mail number of a given subId.
4186 */
4187 @Override
4188 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004189 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4190 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004191
joonhunshin4ac60942023-11-15 15:23:39 +00004192 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4193 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceMailNumber");
4194
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004195 final long identity = Binder.clearCallingIdentity();
4196 try {
4197 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4198 new Pair<String, String>(alphaTag, number), new Integer(subId));
4199 return success;
4200 } finally {
4201 Binder.restoreCallingIdentity(identity);
4202 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004203 }
4204
Ta-wei Yen87c49842016-05-13 21:19:52 -07004205 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004206 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4207 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004208 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4209 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004210 if (!TextUtils.equals(callingPackage, systemDialer)) {
4211 throw new SecurityException("caller must be system dialer");
4212 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004213
joonhunshin4ac60942023-11-15 15:23:39 +00004214 enforceTelephonyFeatureWithException(callingPackage,
4215 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailSettings");
4216
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004217 final long identity = Binder.clearCallingIdentity();
4218 try {
4219 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4220 if (phoneAccountHandle == null) {
4221 return null;
4222 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004223 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004224 } finally {
4225 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004226 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004227 }
4228
4229 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004230 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4231 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004232 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004233 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004234 mApp, subId, callingPackage, callingFeatureId,
4235 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004236 return null;
4237 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004238
joonhunshin4ac60942023-11-15 15:23:39 +00004239 enforceTelephonyFeatureWithException(callingPackage,
4240 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailPackageName");
4241
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004242 final long identity = Binder.clearCallingIdentity();
4243 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004244 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004245 } finally {
4246 Binder.restoreCallingIdentity(identity);
4247 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004248 }
4249
4250 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004251 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4252 VisualVoicemailSmsFilterSettings settings) {
4253 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004254
joonhunshin4ac60942023-11-15 15:23:39 +00004255 enforceTelephonyFeatureWithException(callingPackage,
4256 PackageManager.FEATURE_TELEPHONY_CALLING, "enableVisualVoicemailSmsFilter");
4257
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004258 final long identity = Binder.clearCallingIdentity();
4259 try {
4260 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004261 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004262 } finally {
4263 Binder.restoreCallingIdentity(identity);
4264 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004265 }
4266
4267 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004268 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4269 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004270
joonhunshin4ac60942023-11-15 15:23:39 +00004271 enforceTelephonyFeatureWithException(callingPackage,
4272 PackageManager.FEATURE_TELEPHONY_CALLING, "disableVisualVoicemailSmsFilter");
4273
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004274 final long identity = Binder.clearCallingIdentity();
4275 try {
4276 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004277 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004278 } finally {
4279 Binder.restoreCallingIdentity(identity);
4280 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004281 }
4282
4283 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004284 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4285 String callingPackage, int subId) {
4286 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004287
4288 final long identity = Binder.clearCallingIdentity();
4289 try {
4290 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004291 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004292 } finally {
4293 Binder.restoreCallingIdentity(identity);
4294 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004295 }
4296
4297 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004298 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004299 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004300
4301 final long identity = Binder.clearCallingIdentity();
4302 try {
4303 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004304 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004305 } finally {
4306 Binder.restoreCallingIdentity(identity);
4307 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004308 }
4309
4310 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004311 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4312 String callingAttributionTag, int subId, String number, int port, String text,
4313 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004314 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004315 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004316 enforceSendSmsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00004317
4318 enforceTelephonyFeatureWithException(callingPackage,
4319 PackageManager.FEATURE_TELEPHONY_CALLING, "sendVisualVoicemailSmsForSubscriber");
4320
Amit Mahajandccb3f12019-05-13 13:48:32 -07004321 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004322 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4323 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004324 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004325
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004326 /**
fionaxu0152e512016-11-14 13:36:14 -08004327 * Sets the voice activation state of a given subId.
4328 */
4329 @Override
4330 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004331 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4332 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004333
joonhunshin4ac60942023-11-15 15:23:39 +00004334 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4335 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState");
4336
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004337 final long identity = Binder.clearCallingIdentity();
4338 try {
4339 final Phone phone = getPhone(subId);
4340 if (phone != null) {
4341 phone.setVoiceActivationState(activationState);
4342 } else {
4343 loge("setVoiceActivationState fails with invalid subId: " + subId);
4344 }
4345 } finally {
4346 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004347 }
4348 }
4349
4350 /**
4351 * Sets the data activation state of a given subId.
4352 */
4353 @Override
4354 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004355 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4356 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004357
joonhunshin4ac60942023-11-15 15:23:39 +00004358 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4359 PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState");
4360
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004361 final long identity = Binder.clearCallingIdentity();
4362 try {
4363 final Phone phone = getPhone(subId);
4364 if (phone != null) {
4365 phone.setDataActivationState(activationState);
4366 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004367 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004368 }
4369 } finally {
4370 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004371 }
4372 }
4373
4374 /**
4375 * Returns the voice activation state of a given subId.
4376 */
4377 @Override
4378 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004379 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004380
joonhunshin4ac60942023-11-15 15:23:39 +00004381 enforceTelephonyFeatureWithException(callingPackage,
4382 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState");
4383
fionaxu0152e512016-11-14 13:36:14 -08004384 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004385 final long identity = Binder.clearCallingIdentity();
4386 try {
4387 if (phone != null) {
4388 return phone.getVoiceActivationState();
4389 } else {
4390 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4391 }
4392 } finally {
4393 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004394 }
4395 }
4396
4397 /**
4398 * Returns the data activation state of a given subId.
4399 */
4400 @Override
4401 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004402 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004403
joonhunshin4ac60942023-11-15 15:23:39 +00004404 enforceTelephonyFeatureWithException(callingPackage,
4405 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState");
4406
fionaxu0152e512016-11-14 13:36:14 -08004407 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004408 final long identity = Binder.clearCallingIdentity();
4409 try {
4410 if (phone != null) {
4411 return phone.getDataActivationState();
4412 } else {
4413 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4414 }
4415 } finally {
4416 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004417 }
4418 }
4419
4420 /**
Wink Saville36469e72014-06-11 15:17:00 -07004421 * Returns the unread count of voicemails for a subId
4422 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004423 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004424 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4425 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004426 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004427 mApp, subId, callingPackage, callingFeatureId,
4428 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004429 return 0;
4430 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004431 final long identity = Binder.clearCallingIdentity();
4432 try {
4433 final Phone phone = getPhone(subId);
4434 if (phone != null) {
4435 return phone.getVoiceMessageCount();
4436 } else {
4437 return 0;
4438 }
4439 } finally {
4440 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004441 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004442 }
4443
4444 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004445 * returns true, if the device is in a state where both voice and data
4446 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004447 */
4448 @Override
4449 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00004450 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4451 PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed");
4452
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004453 final long identity = Binder.clearCallingIdentity();
4454 try {
Ling Mac28f0212023-03-24 16:07:15 -07004455 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004456 } finally {
4457 Binder.restoreCallingIdentity(identity);
4458 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004459 }
4460
4461 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004462 * Send the dialer code if called from the current default dialer or the caller has
4463 * carrier privilege.
4464 * @param inputCode The dialer code to send
4465 */
4466 @Override
4467 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004468 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004469 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004470 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4471 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004472 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004473 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004474 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004475 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004476
joonhunshin4ac60942023-11-15 15:23:39 +00004477 enforceTelephonyFeatureWithException(callingPackage,
4478 PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode");
4479
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004480 final long identity = Binder.clearCallingIdentity();
4481 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004482 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004483 } finally {
4484 Binder.restoreCallingIdentity(identity);
4485 }
fionaxu235cc5e2017-03-06 22:25:57 -08004486 }
4487
Pengquan Menga1bb6272018-09-06 09:59:22 -07004488 @Override
4489 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004490 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004491 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4492 mApp, subId, "getNetworkSelectionMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004493
4494 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4495 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode");
4496
shilufc958392020-01-20 11:36:01 -08004497 final long identity = Binder.clearCallingIdentity();
4498 try {
4499 if (!isActiveSubscription(subId)) {
4500 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4501 }
4502 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4503 } finally {
4504 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004505 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004506 }
4507
Brad Ebinger35c841c2018-10-01 10:40:55 -07004508 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004509 public boolean isInEmergencySmsMode() {
4510 enforceReadPrivilegedPermission("isInEmergencySmsMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004511
4512 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4513 PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode");
4514
Brad Ebingerb2b65522019-03-15 13:48:47 -07004515 final long identity = Binder.clearCallingIdentity();
4516 try {
4517 for (Phone phone : PhoneFactory.getPhones()) {
4518 if (phone.isInEmergencySmsMode()) {
4519 return true;
4520 }
4521 }
4522 } finally {
4523 Binder.restoreCallingIdentity(identity);
4524 }
4525 return false;
4526 }
4527
shilu366312e2019-12-17 09:28:10 -08004528 /**
4529 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4530 * @param subId The subscription to use to check the configuration.
4531 * @param c The callback that will be used to send the result.
4532 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004533 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004534 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4535 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004536 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004537 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004538
4539 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4540 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4541 "IMS not available on device.");
4542 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004543 final long token = Binder.clearCallingIdentity();
4544 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004545 int slotId = getSlotIndexOrException(subId);
4546 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004547
4548 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4549 if (controller != null) {
4550 ImsManager imsManager = controller.getImsManager(subId);
4551 if (imsManager != null) {
4552 imsManager.addRegistrationCallbackForSubscription(c, subId);
4553 } else {
4554 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4555 }
4556 } else {
4557 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4558 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004559 } catch (ImsException e) {
4560 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004561 } finally {
4562 Binder.restoreCallingIdentity(token);
4563 }
4564 }
4565
shilu366312e2019-12-17 09:28:10 -08004566 /**
4567 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4568 * @param subId The subscription to use to check the configuration.
4569 * @param c The callback that will be used to send the result.
4570 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004571 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004572 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004573 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004574 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004575 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4576 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4577 }
Meng Wangafbc5852019-09-19 17:37:13 -07004578 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004579
Meng Wangafbc5852019-09-19 17:37:13 -07004580 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004581 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4582 if (controller != null) {
4583 ImsManager imsManager = controller.getImsManager(subId);
4584 if (imsManager != null) {
4585 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4586 } else {
4587 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4588 + "is inactive, ignoring unregister.");
4589 // If the ImsManager is not valid, just return, since the callback
4590 // will already have been removed internally.
4591 }
4592 }
Meng Wangafbc5852019-09-19 17:37:13 -07004593 } finally {
4594 Binder.restoreCallingIdentity(token);
4595 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004596 }
4597
Brad Ebingera34a6c22019-10-22 17:36:18 -07004598 /**
Hidayat Khan99ea48f2023-12-11 04:37:45 +00004599 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4600 * @param subId The subscription to use to check the configuration.
4601 * @param c The callback that will be used to send the result.
4602 */
4603 @Override
4604 public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c)
4605 throws RemoteException {
4606 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4607 mApp, subId, "registerImsEmergencyRegistrationCallback");
4608
4609 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4610 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4611 "IMS not available on device.");
4612 }
4613 final long token = Binder.clearCallingIdentity();
4614 try {
4615 int slotId = getSlotIndexOrException(subId);
4616 verifyImsMmTelConfiguredOrThrow(slotId);
4617
4618 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4619 if (controller != null) {
4620 ImsManager imsManager = controller.getImsManager(subId);
4621 if (imsManager != null) {
4622 imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId);
4623 } else {
4624 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4625 }
4626 } else {
4627 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4628 }
4629 } catch (ImsException e) {
4630 throw new ServiceSpecificException(e.getCode());
4631 } finally {
4632 Binder.restoreCallingIdentity(token);
4633 }
4634 }
4635
4636 /**
4637 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4638 * @param subId The subscription to use to check the configuration.
4639 * @param c The callback that will be used to send the result.
4640 */
4641 @Override
4642 public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) {
4643 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4644 mApp, subId, "unregisterImsEmergencyRegistrationCallback");
4645 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4646 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4647 }
4648 final long token = Binder.clearCallingIdentity();
4649
4650 try {
4651 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4652 if (controller != null) {
4653 ImsManager imsManager = controller.getImsManager(subId);
4654 if (imsManager != null) {
4655 imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId);
4656 } else {
4657 Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId
4658 + "is inactive, ignoring unregister.");
4659 // If the ImsManager is not valid, just return, since the callback
4660 // will already have been removed internally.
4661 }
4662 }
4663 } finally {
4664 Binder.restoreCallingIdentity(token);
4665 }
4666 }
4667
4668 /**
Brad Ebingera34a6c22019-10-22 17:36:18 -07004669 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4670 */
4671 @Override
4672 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4673 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4674 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4675 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4676 "IMS not available on device.");
4677 }
4678 final long token = Binder.clearCallingIdentity();
4679 try {
4680 Phone phone = getPhone(subId);
4681 if (phone == null) {
4682 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4683 + subId + "'");
4684 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4685 }
4686 phone.getImsRegistrationState(regState -> {
4687 try {
4688 consumer.accept((regState == null)
4689 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4690 } catch (RemoteException e) {
4691 // Ignore if the remote process is no longer available to call back.
4692 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4693 }
4694 });
4695 } finally {
4696 Binder.restoreCallingIdentity(token);
4697 }
4698 }
4699
4700 /**
4701 * Get the transport type for the IMS service registration state.
4702 */
4703 @Override
4704 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004705 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004706 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004707 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4708 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4709 "IMS not available on device.");
4710 }
4711 final long token = Binder.clearCallingIdentity();
4712 try {
4713 Phone phone = getPhone(subId);
4714 if (phone == null) {
4715 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4716 + subId + "'");
4717 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4718 }
4719 phone.getImsRegistrationTech(regTech -> {
4720 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4721 int regTechConverted = (regTech == null)
4722 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4723 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4724 regTechConverted);
4725 try {
4726 consumer.accept(regTechConverted);
4727 } catch (RemoteException e) {
4728 // Ignore if the remote process is no longer available to call back.
4729 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4730 }
4731 });
4732 } finally {
4733 Binder.restoreCallingIdentity(token);
4734 }
4735 }
4736
shilu366312e2019-12-17 09:28:10 -08004737 /**
4738 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4739 * @param subId The subscription to use to check the configuration.
4740 * @param c The callback that will be used to send the result.
4741 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004742 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004743 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4744 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004745 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004746 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004747 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4748 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4749 "IMS not available on device.");
4750 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004751 final long token = Binder.clearCallingIdentity();
4752 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004753 int slotId = getSlotIndexOrException(subId);
4754 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004755
4756 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4757 if (controller != null) {
4758 ImsManager imsManager = controller.getImsManager(subId);
4759 if (imsManager != null) {
4760 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4761 } else {
4762 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4763 }
4764 } else {
4765 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4766 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004767 } catch (ImsException e) {
4768 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004769 } finally {
4770 Binder.restoreCallingIdentity(token);
4771 }
4772 }
4773
shilu366312e2019-12-17 09:28:10 -08004774 /**
4775 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4776 * @param subId The subscription to use to check the configuration.
4777 * @param c The callback that will be used to send the result.
4778 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004779 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004780 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004781 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004782 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004783 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4784 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4785 }
Meng Wangafbc5852019-09-19 17:37:13 -07004786
4787 final long token = Binder.clearCallingIdentity();
4788 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004789 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4790 if (controller != null) {
4791 ImsManager imsManager = controller.getImsManager(subId);
4792 if (imsManager != null) {
4793 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4794 } else {
4795 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4796 + " is inactive, ignoring unregister.");
4797 // If the ImsManager is not valid, just return, since the callback
4798 // will already have been removed internally.
4799 }
4800 }
Meng Wangafbc5852019-09-19 17:37:13 -07004801 } finally {
4802 Binder.restoreCallingIdentity(token);
4803 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004804 }
4805
4806 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004807 public boolean isCapable(int subId, int capability, int regTech) {
4808 enforceReadPrivilegedPermission("isCapable");
joonhunshin4ac60942023-11-15 15:23:39 +00004809
4810 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4811 FEATURE_TELEPHONY_IMS, "isCapable");
4812
Brad Ebinger35c841c2018-10-01 10:40:55 -07004813 final long token = Binder.clearCallingIdentity();
4814 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004815 int slotId = getSlotIndexOrException(subId);
4816 verifyImsMmTelConfiguredOrThrow(slotId);
4817 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4818 } catch (com.android.ims.ImsException e) {
4819 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4820 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004821 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004822 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4823 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004824 } finally {
4825 Binder.restoreCallingIdentity(token);
4826 }
4827 }
4828
4829 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004830 public boolean isAvailable(int subId, int capability, int regTech) {
4831 enforceReadPrivilegedPermission("isAvailable");
joonhunshin4ac60942023-11-15 15:23:39 +00004832
4833 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4834 FEATURE_TELEPHONY_IMS, "isAvailable");
4835
Brad Ebinger35c841c2018-10-01 10:40:55 -07004836 final long token = Binder.clearCallingIdentity();
4837 try {
4838 Phone phone = getPhone(subId);
4839 if (phone == null) return false;
4840 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004841 } catch (com.android.ims.ImsException e) {
4842 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4843 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004844 } finally {
4845 Binder.restoreCallingIdentity(token);
4846 }
4847 }
4848
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004849 /**
4850 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4851 * subscription.
4852 * @param subId The subscription to use to check the configuration.
4853 * @param callback The callback that will be used to send the result.
4854 * @param capability The MmTelFeature capability that will be used to send the result.
4855 * @param transportType The transport type of the MmTelFeature capability.
4856 */
4857 @Override
4858 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4859 int transportType) {
4860 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004861 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4862 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4863 "IMS not available on device.");
4864 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004865 final long token = Binder.clearCallingIdentity();
4866 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004867 int slotId = getSlotIndex(subId);
4868 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4869 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4870 + subId + "'");
4871 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4872 }
4873 verifyImsMmTelConfiguredOrThrow(slotId);
4874 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4875 transportType, aBoolean -> {
4876 try {
4877 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4878 } catch (RemoteException e) {
4879 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4880 + "running. Ignore");
4881 }
4882 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004883 } catch (ImsException e) {
4884 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004885 } finally {
4886 Binder.restoreCallingIdentity(token);
4887 }
4888 }
4889
shilu366312e2019-12-17 09:28:10 -08004890 /**
4891 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4892 * @param subId The subscription to use to check the configuration.
4893 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004894 @Override
4895 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004896 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004897 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004898
joonhunshin4ac60942023-11-15 15:23:39 +00004899 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4900 FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled");
4901
Brad Ebinger35c841c2018-10-01 10:40:55 -07004902 final long token = Binder.clearCallingIdentity();
4903 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004904 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004905 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004906 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004907 } catch (ImsException e) {
4908 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004909 } finally {
4910 Binder.restoreCallingIdentity(token);
4911 }
4912 }
4913
4914 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004915 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004916 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004917 "setAdvancedCallingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004918
4919 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4920 FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled");
4921
Brad Ebinger35c841c2018-10-01 10:40:55 -07004922 final long identity = Binder.clearCallingIdentity();
4923 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004924 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004925 // This setting doesn't require an active ImsService connection, so do not verify. The
4926 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004927 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004928 } catch (ImsException e) {
4929 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004930 } finally {
4931 Binder.restoreCallingIdentity(identity);
4932 }
4933 }
4934
shilu366312e2019-12-17 09:28:10 -08004935 /**
4936 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4937 * @param subId The subscription to use to check the configuration.
4938 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004939 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004940 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004941 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004942 mApp, subId, "isVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004943
4944 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4945 FEATURE_TELEPHONY_IMS, "isVtSettingEnabled");
4946
Brad Ebinger35c841c2018-10-01 10:40:55 -07004947 final long identity = Binder.clearCallingIdentity();
4948 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004949 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004950 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004951 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004952 } catch (ImsException e) {
4953 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004954 } finally {
4955 Binder.restoreCallingIdentity(identity);
4956 }
4957 }
4958
4959 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004960 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004961 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004962 "setVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004963
4964 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4965 FEATURE_TELEPHONY_IMS, "setVtSettingEnabled");
4966
Brad Ebinger35c841c2018-10-01 10:40:55 -07004967 final long identity = Binder.clearCallingIdentity();
4968 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004969 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004970 // This setting doesn't require an active ImsService connection, so do not verify. The
4971 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004972 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004973 } catch (ImsException e) {
4974 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004975 } finally {
4976 Binder.restoreCallingIdentity(identity);
4977 }
4978 }
4979
shilu366312e2019-12-17 09:28:10 -08004980 /**
4981 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4982 * @param subId The subscription to use to check the configuration.
4983 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004984 @Override
4985 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004986 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004987 mApp, subId, "isVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004988
4989 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4990 FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled");
4991
Brad Ebinger35c841c2018-10-01 10:40:55 -07004992 final long identity = Binder.clearCallingIdentity();
4993 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004994 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004995 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004996 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004997 } catch (ImsException e) {
4998 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004999 } finally {
5000 Binder.restoreCallingIdentity(identity);
5001 }
5002 }
5003
5004 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005005 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005006 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005007 "setVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005008
5009 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5010 FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled");
5011
Brad Ebinger35c841c2018-10-01 10:40:55 -07005012 final long identity = Binder.clearCallingIdentity();
5013 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005014 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005015 // This setting doesn't require an active ImsService connection, so do not verify. The
5016 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005017 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005018 } catch (ImsException e) {
5019 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005020 } finally {
5021 Binder.restoreCallingIdentity(identity);
5022 }
5023 }
5024
shilu366312e2019-12-17 09:28:10 -08005025 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005026 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
5027 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5028 * @param subId The subscription to use to check the configuration.
5029 */
5030 @Override
5031 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005032 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005033 mApp, subId, "isCrossSimCallingEnabledByUser");
joonhunshin4ac60942023-11-15 15:23:39 +00005034
5035 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5036 FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser");
5037
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005038 final long identity = Binder.clearCallingIdentity();
5039 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005040 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005041 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005042 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005043 } catch (ImsException e) {
5044 throw new ServiceSpecificException(e.getCode());
5045 } finally {
5046 Binder.restoreCallingIdentity(identity);
5047 }
5048 }
5049
5050 /**
5051 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
5052 * Requires MODIFY_PHONE_STATE permission.
5053 * @param subId The subscription to use to check the configuration.
5054 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
5055 * false otherwise
5056 */
5057 @Override
5058 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
5059 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5060 "setCrossSimCallingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005061
5062 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5063 FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled");
5064
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005065 final long identity = Binder.clearCallingIdentity();
5066 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005067 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005068 // This setting doesn't require an active ImsService connection, so do not verify. The
5069 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005070 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005071 } catch (ImsException e) {
5072 throw new ServiceSpecificException(e.getCode());
5073 } finally {
5074 Binder.restoreCallingIdentity(identity);
5075 }
5076 }
5077
5078 /**
shilu366312e2019-12-17 09:28:10 -08005079 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5080 * @param subId The subscription to use to check the configuration.
5081 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005082 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07005083
Brad Ebinger35c841c2018-10-01 10:40:55 -07005084 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005085 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005086 mApp, subId, "isVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005087
5088 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5089 FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled");
5090
Brad Ebinger35c841c2018-10-01 10:40:55 -07005091 final long identity = Binder.clearCallingIdentity();
5092 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005093 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005094 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005095 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005096 } catch (ImsException e) {
5097 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005098 } finally {
5099 Binder.restoreCallingIdentity(identity);
5100 }
5101 }
5102
5103 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005104 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005105 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005106 "setVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005107
5108 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5109 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled");
5110
Brad Ebinger35c841c2018-10-01 10:40:55 -07005111 final long identity = Binder.clearCallingIdentity();
5112 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005113 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005114 // This setting doesn't require an active ImsService connection, so do not verify. The
5115 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005116 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005117 } catch (ImsException e) {
5118 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005119 } finally {
5120 Binder.restoreCallingIdentity(identity);
5121 }
5122 }
5123
5124 @Override
5125 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
5126 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5127 "setVoWiFiNonPersistent");
joonhunshin4ac60942023-11-15 15:23:39 +00005128
5129 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5130 FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent");
5131
Brad Ebinger35c841c2018-10-01 10:40:55 -07005132 final long identity = Binder.clearCallingIdentity();
5133 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005134 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005135 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005136 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005137 } catch (ImsException e) {
5138 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005139 } finally {
5140 Binder.restoreCallingIdentity(identity);
5141 }
5142 }
5143
shilu366312e2019-12-17 09:28:10 -08005144 /**
5145 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5146 * @param subId The subscription to use to check the configuration.
5147 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005148 @Override
5149 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005150 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005151 mApp, subId, "getVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005152
5153 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5154 FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting");
5155
Brad Ebinger35c841c2018-10-01 10:40:55 -07005156 final long identity = Binder.clearCallingIdentity();
5157 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005158 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005159 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005160 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005161 } catch (ImsException e) {
5162 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005163 } finally {
5164 Binder.restoreCallingIdentity(identity);
5165 }
5166 }
5167
5168 @Override
5169 public void setVoWiFiModeSetting(int subId, int mode) {
5170 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5171 "setVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005172
5173 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5174 FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting");
5175
Brad Ebinger35c841c2018-10-01 10:40:55 -07005176 final long identity = Binder.clearCallingIdentity();
5177 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005178 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005179 // This setting doesn't require an active ImsService connection, so do not verify. The
5180 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005181 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005182 } catch (ImsException e) {
5183 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005184 } finally {
5185 Binder.restoreCallingIdentity(identity);
5186 }
5187 }
5188
5189 @Override
5190 public int getVoWiFiRoamingModeSetting(int subId) {
5191 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005192
5193 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5194 FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting");
5195
Brad Ebinger35c841c2018-10-01 10:40:55 -07005196 final long identity = Binder.clearCallingIdentity();
5197 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005198 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005199 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005200 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005201 } catch (ImsException e) {
5202 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005203 } finally {
5204 Binder.restoreCallingIdentity(identity);
5205 }
5206 }
5207
5208 @Override
5209 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
5210 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5211 "setVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005212
5213 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5214 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting");
5215
Brad Ebinger35c841c2018-10-01 10:40:55 -07005216 final long identity = Binder.clearCallingIdentity();
5217 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005218 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005219 // This setting doesn't require an active ImsService connection, so do not verify. The
5220 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005221 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005222 } catch (ImsException e) {
5223 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005224 } finally {
5225 Binder.restoreCallingIdentity(identity);
5226 }
5227 }
5228
5229 @Override
5230 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
5231 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5232 "setRttCapabilityEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005233
5234 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5235 FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting");
5236
Brad Ebinger35c841c2018-10-01 10:40:55 -07005237 final long identity = Binder.clearCallingIdentity();
5238 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005239 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005240 // This setting doesn't require an active ImsService connection, so do not verify. The
5241 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005242 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005243 } catch (ImsException e) {
5244 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005245 } finally {
5246 Binder.restoreCallingIdentity(identity);
5247 }
5248 }
5249
shilu366312e2019-12-17 09:28:10 -08005250 /**
5251 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5252 * @param subId The subscription to use to check the configuration.
5253 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005254 @Override
5255 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005256 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005257 mApp, subId, "isTtyOverVolteEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005258
5259 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5260 FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled");
5261
Brad Ebinger35c841c2018-10-01 10:40:55 -07005262 final long identity = Binder.clearCallingIdentity();
5263 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005264 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005265 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005266 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005267 } catch (ImsException e) {
5268 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005269 } finally {
5270 Binder.restoreCallingIdentity(identity);
5271 }
5272 }
5273
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005274 @Override
5275 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5276 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005277
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005278 final long identity = Binder.clearCallingIdentity();
5279 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005280 if (!isImsAvailableOnDevice()) {
5281 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5282 "IMS not available on device.");
5283 }
5284 int slotId = getSlotIndexOrException(subId);
5285 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005286
5287 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5288 if (controller != null) {
5289 ImsManager imsManager = controller.getImsManager(subId);
5290 if (imsManager != null) {
5291 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5292 } else {
5293 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5294 }
5295 } else {
5296 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5297 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005298 } catch (ImsException e) {
5299 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005300 } finally {
5301 Binder.restoreCallingIdentity(identity);
5302 }
5303 }
5304
5305 @Override
5306 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5307 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005308
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005309 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005310 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5311 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5312 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005313 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005314 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5315 if (controller != null) {
5316 ImsManager imsManager = controller.getImsManager(subId);
5317 if (imsManager != null) {
5318 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5319 } else {
5320 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5321 + " is inactive, ignoring unregister.");
5322 // If the ImsManager is not valid, just return, since the callback will already
5323 // have been removed internally.
5324 }
5325 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005326 } finally {
5327 Binder.restoreCallingIdentity(identity);
5328 }
5329 }
5330
joonhunshincffb7fc2021-11-28 07:32:01 +00005331 @Override
5332 public void registerFeatureProvisioningChangedCallback(int subId,
5333 IFeatureProvisioningCallback callback) {
5334 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5335 mApp, subId, "registerFeatureProvisioningChangedCallback");
5336
5337 final long identity = Binder.clearCallingIdentity();
5338 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5339 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5340 }
5341
joonhunshin91bc1952022-04-29 08:47:15 +00005342 try {
5343 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5344 if (controller == null) {
5345 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5346 "Device does not support IMS");
5347 }
5348 controller.addFeatureProvisioningChangedCallback(subId, callback);
5349 } finally {
5350 Binder.restoreCallingIdentity(identity);
5351 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005352 }
5353
5354 @Override
5355 public void unregisterFeatureProvisioningChangedCallback(int subId,
5356 IFeatureProvisioningCallback callback) {
5357 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5358 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5359
5360 final long identity = Binder.clearCallingIdentity();
5361 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5362 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5363 }
5364
joonhunshin91bc1952022-04-29 08:47:15 +00005365 try {
5366 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5367 if (controller == null) {
5368 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5369 return;
5370 }
5371 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5372 } finally {
5373 Binder.restoreCallingIdentity(identity);
5374 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005375 }
allenwtsu99c623b2020-01-03 18:24:23 +08005376
5377 private void checkModifyPhoneStatePermission(int subId, String message) {
5378 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5379 message);
5380 }
5381
allenwtsu99c623b2020-01-03 18:24:23 +08005382 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005383 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005384 boolean isProvisioned) {
5385 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5386
joonhunshin4ac60942023-11-15 15:23:39 +00005387 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5388 FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability");
5389
allenwtsu99c623b2020-01-03 18:24:23 +08005390 final long identity = Binder.clearCallingIdentity();
5391 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005392 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5393 if (controller == null) {
5394 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5395 return;
5396 }
5397 controller.setRcsProvisioningStatusForCapability(
5398 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005399 } finally {
5400 Binder.restoreCallingIdentity(identity);
5401 }
allenwtsu99c623b2020-01-03 18:24:23 +08005402 }
5403
5404
5405 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005406 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5407 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5408 mApp, subId, "getRcsProvisioningStatusForCapability");
5409
joonhunshin4ac60942023-11-15 15:23:39 +00005410 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5411 FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability");
5412
allenwtsu99c623b2020-01-03 18:24:23 +08005413 final long identity = Binder.clearCallingIdentity();
5414 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005415 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5416 if (controller == null) {
5417 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5418
5419 // device does not support IMS, this method will return true always.
5420 return true;
5421 }
5422 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005423 } finally {
5424 Binder.restoreCallingIdentity(identity);
5425 }
5426 }
5427
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005428 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005429 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5430 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005431 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005432
joonhunshin4ac60942023-11-15 15:23:39 +00005433 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5434 FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability");
5435
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005436 final long identity = Binder.clearCallingIdentity();
5437 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005438 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5439 if (controller == null) {
5440 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5441 return;
5442 }
5443 controller.setImsProvisioningStatusForCapability(
5444 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005445 } finally {
5446 Binder.restoreCallingIdentity(identity);
5447 }
5448 }
5449
5450 @Override
5451 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005452 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5453 mApp, subId, "getProvisioningStatusForCapability");
5454
joonhunshin4ac60942023-11-15 15:23:39 +00005455 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5456 FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability");
5457
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005458 final long identity = Binder.clearCallingIdentity();
5459 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005460 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5461 if (controller == null) {
5462 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005463
joonhunshin91bc1952022-04-29 08:47:15 +00005464 // device does not support IMS, this method will return true always.
5465 return true;
5466 }
5467 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005468 } finally {
5469 Binder.restoreCallingIdentity(identity);
5470 }
5471 }
5472
5473 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005474 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5475 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5476 mApp, subId, "isProvisioningRequiredForCapability");
5477
joonhunshin4ac60942023-11-15 15:23:39 +00005478 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5479 FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability");
5480
joonhunshincffb7fc2021-11-28 07:32:01 +00005481 final long identity = Binder.clearCallingIdentity();
5482 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005483 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5484 if (controller == null) {
5485 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5486
5487 // device does not support IMS, this method will return false
5488 return false;
5489 }
5490 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005491 } finally {
5492 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005493 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005494 }
5495
5496 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005497 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5498 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5499 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005500
joonhunshin4ac60942023-11-15 15:23:39 +00005501 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5502 FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability");
5503
joonhunshincffb7fc2021-11-28 07:32:01 +00005504 final long identity = Binder.clearCallingIdentity();
5505 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005506 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5507 if (controller == null) {
5508 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5509
5510 // device does not support IMS, this method will return false
5511 return false;
5512 }
5513 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005514 } finally {
5515 Binder.restoreCallingIdentity(identity);
5516 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005517 }
5518
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005519 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005520 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005521 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5522 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5523 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005524 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5525 mApp, subId, "getImsProvisioningInt");
5526
joonhunshin4ac60942023-11-15 15:23:39 +00005527 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5528 FEATURE_TELEPHONY_IMS, "getImsProvisioningInt");
5529
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005530 final long identity = Binder.clearCallingIdentity();
5531 try {
5532 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005533 int slotId = getSlotIndex(subId);
5534 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5535 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5536 + subId + "' for key:" + key);
5537 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5538 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005539
joonhunshin91bc1952022-04-29 08:47:15 +00005540 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5541 if (controller == null) {
5542 loge("getImsProvisioningInt: Device does not support IMS");
5543
5544 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5545 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5546 }
5547 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005548 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5549 return retVal;
5550 }
5551
calvinpanb5a34062021-02-08 19:59:36 +08005552 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005553 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005554 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5555 + subId + "' for key:" + key);
5556 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005557 } finally {
5558 Binder.restoreCallingIdentity(identity);
5559 }
5560 }
5561
5562 @Override
5563 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005564 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5565 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5566 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005567 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5568 mApp, subId, "getImsProvisioningString");
5569
joonhunshin4ac60942023-11-15 15:23:39 +00005570 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5571 FEATURE_TELEPHONY_IMS, "getImsProvisioningString");
5572
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005573 final long identity = Binder.clearCallingIdentity();
5574 try {
5575 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005576 int slotId = getSlotIndex(subId);
5577 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5578 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5579 + subId + "' for key:" + key);
5580 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5581 }
calvinpanb5a34062021-02-08 19:59:36 +08005582 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005583 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005584 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5585 + subId + "' for key:" + key);
5586 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005587 } finally {
5588 Binder.restoreCallingIdentity(identity);
5589 }
5590 }
5591
5592 @Override
5593 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005594 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5595 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5596 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005597 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5598 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005599
joonhunshin4ac60942023-11-15 15:23:39 +00005600 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5601 FEATURE_TELEPHONY_IMS, "setImsProvisioningInt");
5602
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005603 final long identity = Binder.clearCallingIdentity();
5604 try {
5605 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005606 int slotId = getSlotIndex(subId);
5607 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5608 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5609 + subId + "' for key:" + key);
5610 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5611 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005612
joonhunshin91bc1952022-04-29 08:47:15 +00005613 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5614 if (controller == null) {
5615 loge("setImsProvisioningInt: Device does not support IMS");
5616
5617 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5618 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5619 }
5620 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005621 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5622 return retVal;
5623 }
5624
calvinpanb5a34062021-02-08 19:59:36 +08005625 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5626 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005627 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005628 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005629 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005630 } finally {
5631 Binder.restoreCallingIdentity(identity);
5632 }
5633 }
5634
5635 @Override
5636 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005637 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5638 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5639 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005640 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5641 "setImsProvisioningString");
joonhunshin4ac60942023-11-15 15:23:39 +00005642
5643 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5644 FEATURE_TELEPHONY_IMS, "setImsProvisioningString");
5645
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005646 final long identity = Binder.clearCallingIdentity();
5647 try {
5648 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005649 int slotId = getSlotIndex(subId);
5650 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5651 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5652 + subId + "' for key:" + key);
5653 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5654 }
calvinpanb5a34062021-02-08 19:59:36 +08005655 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5656 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005657 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005658 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005659 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005660 } finally {
5661 Binder.restoreCallingIdentity(identity);
5662 }
5663 }
5664
Brad Ebinger919631e2021-06-02 17:46:35 -07005665 /**
5666 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5667 * for the given slot ID or no ImsResolver instance has been created.
5668 * @param slotId The slot ID that the IMS service is created for.
5669 * @throws ImsException If there is no ImsService configured for this slot.
5670 */
5671 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5672 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5673 ImsFeature.FEATURE_MMTEL)) {
5674 throw new ImsException("This subscription does not support MMTEL over IMS",
5675 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5676 }
5677 }
5678
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005679 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005680 int slotId = SubscriptionManager.getSlotIndex(subId);
5681 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005682 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5683 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005684 }
5685 return slotId;
5686 }
5687
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005688 private int getSlotIndex(int subId) {
5689 int slotId = SubscriptionManager.getSlotIndex(subId);
5690 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5691 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5692 }
5693 return slotId;
5694 }
5695
Wink Saville36469e72014-06-11 15:17:00 -07005696 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005697 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005698 */
5699 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005700 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5701 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005702 try {
5703 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5704 } catch (SecurityException se) {
5705 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5706 throw new SecurityException("Package " + callingPackage + " does not belong to "
5707 + Binder.getCallingUid());
5708 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005709 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005710 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005711 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005712 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005713 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005714 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005715 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005716 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5717 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005718
joonhunshin4ac60942023-11-15 15:23:39 +00005719 enforceTelephonyFeatureWithException(callingPackage,
5720 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber");
5721
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005722 final long identity = Binder.clearCallingIdentity();
5723 try {
5724 final Phone phone = getPhone(subId);
5725 if (phone != null) {
5726 return phone.getServiceState().getDataNetworkType();
5727 } else {
5728 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5729 }
5730 } finally {
5731 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005732 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005733 }
5734
5735 /**
5736 * Returns the data network type
5737 */
5738 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005739 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005740 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005741 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005742 }
5743
5744 /**
5745 * Returns the data network type for a subId
5746 */
5747 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005748 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5749 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005750 String functionName = "getDataNetworkTypeForSubscriber";
5751 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5752 mApp, functionName)) {
5753 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5754 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5755 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5756 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005757 }
5758
joonhunshin4ac60942023-11-15 15:23:39 +00005759 enforceTelephonyFeatureWithException(callingPackage,
5760 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber");
5761
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005762 final long identity = Binder.clearCallingIdentity();
5763 try {
5764 final Phone phone = getPhone(subId);
5765 if (phone != null) {
5766 return phone.getServiceState().getDataNetworkType();
5767 } else {
5768 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5769 }
5770 } finally {
5771 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005772 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005773 }
5774
5775 /**
Wink Saville36469e72014-06-11 15:17:00 -07005776 * Returns the Voice network type for a subId
5777 */
5778 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005779 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5780 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005781 String functionName = "getVoiceNetworkTypeForSubscriber";
5782 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5783 mApp, functionName)) {
5784 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5785 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5786 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5787 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005788 }
5789
joonhunshin4ac60942023-11-15 15:23:39 +00005790 enforceTelephonyFeatureWithException(callingPackage,
5791 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber");
5792
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005793 final long identity = Binder.clearCallingIdentity();
5794 try {
5795 final Phone phone = getPhone(subId);
5796 if (phone != null) {
5797 return phone.getServiceState().getVoiceNetworkType();
5798 } else {
5799 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5800 }
5801 } finally {
5802 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005803 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005804 }
5805
5806 /**
5807 * @return true if a ICC card is present
5808 */
5809 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005810 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005811 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005812 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005813 }
5814
5815 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005816 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005817 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005818 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005819 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00005820 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5821 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex");
5822
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005823 final long identity = Binder.clearCallingIdentity();
5824 try {
5825 final Phone phone = PhoneFactory.getPhone(slotIndex);
5826 if (phone != null) {
5827 return phone.getIccCard().hasIccCard();
5828 } else {
5829 return false;
5830 }
5831 } finally {
5832 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005833 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005834 }
5835
5836 /**
5837 * Return if the current radio is LTE on CDMA. This
5838 * is a tri-state return value as for a period of time
5839 * the mode may be unknown.
5840 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005841 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005842 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005843 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005844 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005845 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005846 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5847 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5848 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005849 }
5850
Sanket Padawe356d7632015-06-22 14:03:32 -07005851 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005852 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5853 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005854 try {
5855 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5856 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005857 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5858 }
5859
joonhunshin4ac60942023-11-15 15:23:39 +00005860 enforceTelephonyFeatureWithException(callingPackage,
5861 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber");
5862
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005863 final long identity = Binder.clearCallingIdentity();
5864 try {
5865 final Phone phone = getPhone(subId);
5866 if (phone == null) {
5867 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5868 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005869 return TelephonyProperties.lte_on_cdma_device()
5870 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005871 }
5872 } finally {
5873 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005874 }
Wink Saville36469e72014-06-11 15:17:00 -07005875 }
5876
Wink Saville36469e72014-06-11 15:17:00 -07005877 /**
5878 * {@hide}
5879 * Returns Default subId, 0 in the case of single standby.
5880 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005881 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005882 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005883 }
5884
Shishir Agrawala9f32182016-04-12 12:00:16 -07005885 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005886 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005887 }
5888
Wink Savilleb564aae2014-10-23 10:18:09 -07005889 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005890 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005891 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005892
Pengquan Menge92a50d2018-09-21 15:54:48 -07005893 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005894 return getSubscriptionManagerService().isActiveSubId(subId,
5895 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005896 }
5897
Ihab Awadf2177b72013-11-25 13:33:23 -08005898 /**
5899 * @see android.telephony.TelephonyManager.WifiCallingChoices
5900 */
5901 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005902 final long identity = Binder.clearCallingIdentity();
5903 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005904 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005905 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5906 getWhenToMakeWifiCallsDefaultPreference());
5907 } finally {
5908 Binder.restoreCallingIdentity(identity);
5909 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005910 }
5911
5912 /**
5913 * @see android.telephony.TelephonyManager.WifiCallingChoices
5914 */
5915 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005916 final long identity = Binder.clearCallingIdentity();
5917 try {
5918 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005919 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005920 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5921 } finally {
5922 Binder.restoreCallingIdentity(identity);
5923 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005924 }
5925
Sailesh Nepald1e68152013-12-12 19:08:02 -08005926 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005927 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005928 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005929 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005930
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005931 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5932 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5933 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005934 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005935 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005936 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005937 }
5938 return PhoneFactory.getPhone(phoneId);
5939 }
5940
Shishir Agrawal566b7612013-10-28 14:41:00 -07005941 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005942 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005943 @NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00005944
Rambo Wanga1782702021-11-10 20:15:19 -08005945 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5946 /*message=*/ "iccOpenLogicalChannel");
5947
5948 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5949 // Verify that the callingPackage in the request belongs to the calling UID
5950 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5951
joonhunshin4ac60942023-11-15 15:23:39 +00005952 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5953 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel");
5954
Rambo Wanga1782702021-11-10 20:15:19 -08005955 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005956 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005957
Rambo Wanga1782702021-11-10 20:15:19 -08005958 private Phone getPhoneFromValidIccLogicalChannelRequest(
5959 @NonNull IccLogicalChannelRequest request, String message) {
5960 Phone phone;
5961 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5962 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5963 mApp, request.subId, message);
5964 phone = getPhoneFromSubId(request.subId);
5965 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5966 enforceModifyPermission();
5967 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5968 } else {
5969 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005970 }
Rambo Wanga1782702021-11-10 20:15:19 -08005971 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005972 }
5973
5974 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005975 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005976 final long identity = Binder.clearCallingIdentity();
5977 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005978 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005979 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005980 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5981 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005982 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5983 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005984 loge("The calling package is not allowed to access ISD-R.");
5985 throw new SecurityException(
5986 "The calling package is not allowed to access ISD-R.");
5987 }
Derek Tan740e1672017-06-27 14:56:27 -07005988 }
Derek Tan740e1672017-06-27 14:56:27 -07005989
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005990 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005991 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5992 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005993 return response;
5994 } finally {
5995 Binder.restoreCallingIdentity(identity);
5996 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005997 }
5998
5999 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08006000 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00006001 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6002 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel");
6003
Rambo Wanga1782702021-11-10 20:15:19 -08006004 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
6005 /*message=*/"iccCloseLogicalChannel");
6006
6007 if (DBG) log("iccCloseLogicalChannel: request=" + request);
6008
6009 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006010 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006011
Rambo Wanga1782702021-11-10 20:15:19 -08006012 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
6013 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08006014 // before this feature is enabled, this API should only return false if
6015 // the operation fails instead of throwing runtime exception for
6016 // backward-compatibility.
6017 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
6018 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006019 final long identity = Binder.clearCallingIdentity();
6020 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006021 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08006022 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006023 }
Chen Xue9d737e2022-01-01 23:41:31 -08006024 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08006025 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08006026 Boolean success = false;
6027 if (result instanceof RuntimeException) {
6028 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08006029 if (shouldThrowExceptionOnFailure) {
6030 throw (RuntimeException) result;
6031 } else {
6032 return false;
6033 }
Chen Xue9d737e2022-01-01 23:41:31 -08006034 } else if (result instanceof Boolean) {
6035 success = (Boolean) result;
6036 } else {
6037 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
6038 }
Rambo Wanga1782702021-11-10 20:15:19 -08006039 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006040 return success;
6041 } finally {
6042 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006043 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006044 }
6045
6046 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006047 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07006048 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006049 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6050 mApp, subId, "iccTransmitApduLogicalChannel");
joonhunshin4ac60942023-11-15 15:23:39 +00006051
6052 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6053 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel");
6054
Jordan Liu4c733742019-02-28 12:03:40 -08006055 if (DBG) {
6056 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
6057 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
6058 + p3 + " data=" + data);
6059 }
6060 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
6061 command, p1, p2, p3, data);
6062 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006063
Jordan Liu4c733742019-02-28 12:03:40 -08006064 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006065 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006066 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006067 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006068
6069 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6070 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
6071 "iccTransmitApduLogicalChannelBySlot");
6072
Jordan Liu4c733742019-02-28 12:03:40 -08006073 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006074 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006075 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
6076 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006077 }
6078 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006079 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
6080 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006081 }
6082
6083 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
6084 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006085 final long identity = Binder.clearCallingIdentity();
6086 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07006087 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006088 return "";
6089 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006090
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006091 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006092 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
6093 null /* workSource */);
6094 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006095
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006096 // Append the returned status code to the end of the response payload.
6097 String s = Integer.toHexString(
6098 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6099 if (response.payload != null) {
6100 s = IccUtils.bytesToHexString(response.payload) + s;
6101 }
6102 return s;
6103 } finally {
6104 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006105 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006106 }
Jake Hambye994d462014-02-03 13:10:13 -08006107
Evan Charltonc66da362014-05-16 14:06:40 -07006108 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006109 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
6110 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006111 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6112 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006113 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006114
6115 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6116 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel");
6117
Jordan Liu4c733742019-02-28 12:03:40 -08006118 if (DBG) {
6119 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
6120 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
6121 }
6122 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
6123 cla, command, p1, p2, p3, data);
6124 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006125
Jordan Liu4c733742019-02-28 12:03:40 -08006126 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006127 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006128 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006129 enforceModifyPermission();
6130 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006131
6132 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6133 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot");
6134
Jordan Liu4c733742019-02-28 12:03:40 -08006135 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006136 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006137 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
6138 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006139 }
6140
6141 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006142 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
6143 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006144 }
6145
6146 // open APDU basic channel assuming the caller has sufficient permissions
6147 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
6148 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006149 final long identity = Binder.clearCallingIdentity();
6150 try {
6151 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
6152 && TextUtils.equals(ISDR_AID, data)) {
6153 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006154 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6155 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006156 if (bestComponent == null
6157 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
6158 loge("The calling package is not allowed to select ISD-R.");
6159 throw new SecurityException(
6160 "The calling package is not allowed to select ISD-R.");
6161 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006162 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006163
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006164 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006165 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
6166 null /* workSource */);
6167 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006168
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006169 // Append the returned status code to the end of the response payload.
6170 String s = Integer.toHexString(
6171 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6172 if (response.payload != null) {
6173 s = IccUtils.bytesToHexString(response.payload) + s;
6174 }
6175 return s;
6176 } finally {
6177 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006178 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006179 }
6180
6181 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006182 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006183 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006184 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6185 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006186
joonhunshin4ac60942023-11-15 15:23:39 +00006187 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6188 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO");
6189
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006190 final long identity = Binder.clearCallingIdentity();
6191 try {
6192 if (DBG) {
6193 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
6194 + p1 + " " + p2 + " " + p3 + ":" + filePath);
6195 }
6196
6197 IccIoResult response =
6198 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
6199 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
6200 subId);
6201
6202 if (DBG) {
6203 log("Exchange SIM_IO [R]" + response);
6204 }
6205
6206 byte[] result = null;
6207 int length = 2;
6208 if (response.payload != null) {
6209 length = 2 + response.payload.length;
6210 result = new byte[length];
6211 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
6212 } else {
6213 result = new byte[length];
6214 }
6215
6216 result[length - 1] = (byte) response.sw2;
6217 result[length - 2] = (byte) response.sw1;
6218 return result;
6219 } finally {
6220 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006221 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006222 }
6223
Nathan Haroldb3014052017-01-25 15:57:32 -08006224 /**
6225 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
6226 * on a particular subscription
6227 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006228 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
6229 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07006230 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006231 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07006232 return null;
6233 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006234
joonhunshin4ac60942023-11-15 15:23:39 +00006235 enforceTelephonyFeatureWithException(callingPackage,
6236 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns");
6237
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006238 final long identity = Binder.clearCallingIdentity();
6239 try {
6240 if (appType != TelephonyManager.APPTYPE_USIM
6241 && appType != TelephonyManager.APPTYPE_SIM) {
6242 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
6243 return null;
6244 }
6245 Object response = sendRequest(
6246 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
6247 if (response instanceof String[]) {
6248 return (String[]) response;
6249 }
yincheng zhao2737e882019-09-06 17:06:54 -07006250 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006251 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08006252 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006253 } finally {
6254 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08006255 }
Nathan Haroldb3014052017-01-25 15:57:32 -08006256 }
6257
yincheng zhao2737e882019-09-06 17:06:54 -07006258 /**
6259 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
6260 * subscription.
6261 *
6262 * @param subId the id of the subscription.
6263 * @param appType the uicc app type, must be USIM or SIM.
6264 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
6265 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006266 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07006267 * @return number of fplmns that is successfully written to the SIM.
6268 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006269 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
6270 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07006271 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6272 mApp, subId, "setForbiddenPlmns");
6273
joonhunshin4ac60942023-11-15 15:23:39 +00006274 enforceTelephonyFeatureWithException(callingPackage,
6275 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns");
6276
yincheng zhao2737e882019-09-06 17:06:54 -07006277 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
6278 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
6279 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
6280 }
6281 if (fplmns == null) {
6282 throw new IllegalArgumentException("Fplmn List provided is null");
6283 }
6284 for (String fplmn : fplmns) {
6285 if (!CellIdentity.isValidPlmn(fplmn)) {
6286 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
6287 }
6288 }
6289 final long identity = Binder.clearCallingIdentity();
6290 try {
6291 Object response = sendRequest(
6292 CMD_SET_FORBIDDEN_PLMNS,
6293 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
6294 subId);
6295 return (int) response;
6296 } finally {
6297 Binder.restoreCallingIdentity(identity);
6298 }
6299 }
6300
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006301 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006302 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006303 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6304 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07006305
joonhunshin4ac60942023-11-15 15:23:39 +00006306 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6307 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus");
6308
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006309 final long identity = Binder.clearCallingIdentity();
6310 try {
6311 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
6312 if (response.payload == null) {
6313 return "";
6314 }
Evan Charltonc66da362014-05-16 14:06:40 -07006315
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006316 // Append the returned status code to the end of the response payload.
6317 String s = Integer.toHexString(
6318 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6319 s = IccUtils.bytesToHexString(response.payload) + s;
6320 return s;
6321 } finally {
6322 Binder.restoreCallingIdentity(identity);
6323 }
Evan Charltonc66da362014-05-16 14:06:40 -07006324 }
6325
Jake Hambye994d462014-02-03 13:10:13 -08006326 /**
6327 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6328 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6329 *
6330 * @param itemID the ID of the item to read
6331 * @return the NV item as a String, or null on error.
6332 */
6333 @Override
6334 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006335 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006336 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6337 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006338
6339 final long identity = Binder.clearCallingIdentity();
6340 try {
6341 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07006342 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006343 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
6344 return value;
6345 } finally {
6346 Binder.restoreCallingIdentity(identity);
6347 }
Jake Hambye994d462014-02-03 13:10:13 -08006348 }
6349
6350 /**
6351 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6352 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6353 *
6354 * @param itemID the ID of the item to read
6355 * @param itemValue the value to write, as a String
6356 * @return true on success; false on any failure
6357 */
6358 @Override
6359 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006360 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006361 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6362 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006363
6364 final long identity = Binder.clearCallingIdentity();
6365 try {
6366 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6367 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006368 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006369 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6370 return success;
6371 } finally {
6372 Binder.restoreCallingIdentity(identity);
6373 }
Jake Hambye994d462014-02-03 13:10:13 -08006374 }
6375
6376 /**
6377 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6378 * Used for device configuration by some CDMA operators.
6379 *
6380 * @param preferredRoamingList byte array containing the new PRL
6381 * @return true on success; false on any failure
6382 */
6383 @Override
6384 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006385 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6386 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006387
6388 final long identity = Binder.clearCallingIdentity();
6389 try {
6390 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6391 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6392 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6393 return success;
6394 } finally {
6395 Binder.restoreCallingIdentity(identity);
6396 }
Jake Hambye994d462014-02-03 13:10:13 -08006397 }
6398
6399 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006400 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006401 * Used for device configuration by some CDMA operators.
6402 *
chen xu6dac5ab2018-10-26 17:39:23 -07006403 * @param slotIndex - device slot.
6404 *
Jake Hambye994d462014-02-03 13:10:13 -08006405 * @return true on success; false on any failure
6406 */
6407 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006408 public boolean resetModemConfig(int slotIndex) {
6409 Phone phone = PhoneFactory.getPhone(slotIndex);
6410 if (phone != null) {
6411 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6412 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006413
joonhunshin4ac60942023-11-15 15:23:39 +00006414 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6415 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig");
6416
chen xu6dac5ab2018-10-26 17:39:23 -07006417 final long identity = Binder.clearCallingIdentity();
6418 try {
6419 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6420 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6421 return success;
6422 } finally {
6423 Binder.restoreCallingIdentity(identity);
6424 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006425 }
chen xu6dac5ab2018-10-26 17:39:23 -07006426 return false;
6427 }
6428
6429 /**
6430 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6431 *
6432 * @param slotIndex - device slot.
6433 *
6434 * @return true on success; false on any failure
6435 */
6436 @Override
6437 public boolean rebootModem(int slotIndex) {
6438 Phone phone = PhoneFactory.getPhone(slotIndex);
6439 if (phone != null) {
6440 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6441 mApp, phone.getSubId(), "rebootModem");
6442
joonhunshin4ac60942023-11-15 15:23:39 +00006443 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6444 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem");
6445
chen xu6dac5ab2018-10-26 17:39:23 -07006446 final long identity = Binder.clearCallingIdentity();
6447 try {
6448 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6449 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6450 return success;
6451 } finally {
6452 Binder.restoreCallingIdentity(identity);
6453 }
6454 }
6455 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006456 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006457
Brad Ebinger51f743a2017-01-23 13:50:20 -08006458 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006459 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6460 * {@link #disableIms(int)}.
6461 * @param slotIndex device slot.
6462 */
6463 public void resetIms(int slotIndex) {
6464 enforceModifyPermission();
6465
joonhunshin4ac60942023-11-15 15:23:39 +00006466 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6467 PackageManager.FEATURE_TELEPHONY_IMS, "resetIms");
6468
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006469 final long identity = Binder.clearCallingIdentity();
6470 try {
6471 if (mImsResolver == null) {
6472 // may happen if the does not support IMS.
6473 return;
6474 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006475 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006476 } finally {
6477 Binder.restoreCallingIdentity(identity);
6478 }
6479 }
6480
6481 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006482 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6483 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006484 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006485 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006486 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006487
6488 final long identity = Binder.clearCallingIdentity();
6489 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006490 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006491 // may happen if the device does not support IMS.
6492 return;
6493 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006494 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006495 } finally {
6496 Binder.restoreCallingIdentity(identity);
6497 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006498 }
6499
6500 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006501 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6502 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006503 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006504 public void disableIms(int slotId) {
6505 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006506
6507 final long identity = Binder.clearCallingIdentity();
6508 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006509 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006510 // may happen if the device does not support IMS.
6511 return;
6512 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006513 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006514 } finally {
6515 Binder.restoreCallingIdentity(identity);
6516 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006517 }
6518
6519 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006520 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6521 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006522 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006523 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006524 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006525 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006526
6527 final long identity = Binder.clearCallingIdentity();
6528 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006529 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006530 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6531 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006532 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006533 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006534 } finally {
6535 Binder.restoreCallingIdentity(identity);
6536 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006537 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006538 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006539 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6540 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006541 @Override
6542 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006543 enforceModifyPermission();
6544
6545 final long identity = Binder.clearCallingIdentity();
6546 try {
6547 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006548 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006549 } finally {
6550 Binder.restoreCallingIdentity(identity);
6551 }
6552 }
6553
6554 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006555 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006556 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006557 */
6558 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6559 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006560
6561 final long identity = Binder.clearCallingIdentity();
6562 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006563 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006564 // may happen if the device does not support IMS.
6565 return null;
6566 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006567 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006568 } finally {
6569 Binder.restoreCallingIdentity(identity);
6570 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006571 }
6572
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006573 /**
6574 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006575 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006576 */
6577 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6578 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006579
6580 final long identity = Binder.clearCallingIdentity();
6581 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006582 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006583 // may happen if the device does not support IMS.
6584 return null;
6585 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006586 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006587 } finally {
6588 Binder.restoreCallingIdentity(identity);
6589 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006590 }
6591
Brad Ebinger884c07b2018-02-15 16:17:40 -08006592 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006593 * Sets the ImsService Package Name that Telephony will bind to.
6594 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006595 * @param slotIndex the slot ID that the ImsService should bind for.
6596 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006597 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006598 * @param featureTypes An integer array of feature types associated with a packageName.
6599 * @param packageName The name of the package that the current configuration will be replaced
6600 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006601 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006602 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006603 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6604 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006605 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006606 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006607 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006608
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006609 final long identity = Binder.clearCallingIdentity();
6610 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006611 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006612 // may happen if the device does not support IMS.
6613 return false;
6614 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006615 Map<Integer, String> featureConfig = new HashMap<>();
6616 for (int featureType : featureTypes) {
6617 featureConfig.put(featureType, packageName);
6618 }
6619 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6620 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006621 } finally {
6622 Binder.restoreCallingIdentity(identity);
6623 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006624 }
6625
6626 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006627 * Clears any carrier ImsService overrides for the slot index specified that were previously
6628 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6629 *
6630 * This should only be used for testing.
6631 *
6632 * @param slotIndex the slot ID that the ImsService should bind for.
6633 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6634 */
6635 @Override
6636 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006637 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6638 "clearCarrierImsServiceOverride");
6639 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006640 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006641
6642 final long identity = Binder.clearCallingIdentity();
6643 try {
6644 if (mImsResolver == null) {
6645 // may happen if the device does not support IMS.
6646 return false;
6647 }
6648 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6649 } finally {
6650 Binder.restoreCallingIdentity(identity);
6651 }
6652 }
6653
6654 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006655 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006656 *
6657 * @param slotId The slot that the ImsService is associated with.
6658 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6659 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006660 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006661 * @return the package name of the ImsService configuration.
6662 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006663 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6664 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006665 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006666 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6667 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006668
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006669 final long identity = Binder.clearCallingIdentity();
6670 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006671 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006672 // may happen if the device does not support IMS.
6673 return "";
6674 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006675 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006676 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6677 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006678 } finally {
6679 Binder.restoreCallingIdentity(identity);
6680 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006681 }
6682
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006683 /**
6684 * Get the MmTelFeature state associated with the requested subscription id.
6685 * @param subId The subscription that the MmTelFeature is associated with.
6686 * @param callback A callback with an integer containing the
6687 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6688 */
6689 @Override
6690 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6691 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006692 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6693 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6694 "IMS not available on device.");
6695 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006696 final long token = Binder.clearCallingIdentity();
6697 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006698 int slotId = getSlotIndex(subId);
6699 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6700 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6701 + subId + "'");
6702 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6703 }
6704 verifyImsMmTelConfiguredOrThrow(slotId);
6705 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6706 try {
6707 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6708 } catch (RemoteException e) {
6709 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6710 + "Ignore");
6711 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006712 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006713 } catch (ImsException e) {
6714 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006715 } finally {
6716 Binder.restoreCallingIdentity(token);
6717 }
6718 }
6719
Daniel Brightbb5840b2021-01-12 15:48:18 -08006720 /**
6721 * Sets the ims registration state on all valid {@link Phone}s.
6722 */
6723 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006724 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006725
6726 final long identity = Binder.clearCallingIdentity();
6727 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006728 // NOTE: Before S, this method only set the default phone.
6729 for (final Phone phone : PhoneFactory.getPhones()) {
6730 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6731 phone.setImsRegistrationState(registered);
6732 }
6733 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006734 } finally {
6735 Binder.restoreCallingIdentity(identity);
6736 }
Wink Saville36469e72014-06-11 15:17:00 -07006737 }
6738
6739 /**
Stuart Scott54788802015-03-30 13:18:01 -07006740 * Set the network selection mode to automatic.
6741 *
6742 */
6743 @Override
6744 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006745 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6746 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006747
joonhunshin4ac60942023-11-15 15:23:39 +00006748 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6749 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic");
6750
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006751 final long identity = Binder.clearCallingIdentity();
6752 try {
shilufc958392020-01-20 11:36:01 -08006753 if (!isActiveSubscription(subId)) {
6754 return;
6755 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006756 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006757 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6758 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006759 } finally {
6760 Binder.restoreCallingIdentity(identity);
6761 }
Stuart Scott54788802015-03-30 13:18:01 -07006762 }
6763
Jack Yud10cdd42020-09-28 20:28:01 -07006764 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006765 * Ask the radio to connect to the input network and change selection mode to manual.
6766 *
6767 * @param subId the id of the subscription.
6768 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6769 * the operator to attach to.
6770 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6771 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6772 * normal network selection next time.
6773 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006774 */
6775 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006776 public boolean setNetworkSelectionModeManual(
6777 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006778 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6779 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006780
joonhunshin4ac60942023-11-15 15:23:39 +00006781 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6782 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual");
6783
Jack Yu285100e2022-12-02 22:48:35 -08006784 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006785 if (!isActiveSubscription(subId)) {
6786 return false;
6787 }
6788
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006789 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006790 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006791 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006792 if (DBG) {
6793 log("setNetworkSelectionModeManual: subId: " + subId
6794 + " operator: " + operatorInfo);
6795 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006796 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6797 } finally {
6798 Binder.restoreCallingIdentity(identity);
6799 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006800 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006801 /**
shilu84f6e8b2019-12-19 13:58:01 -08006802 * Get the manual network selection
6803 *
6804 * @param subId the id of the subscription.
6805 *
6806 * @return the previously saved user selected PLMN
6807 */
6808 @Override
6809 public String getManualNetworkSelectionPlmn(int subId) {
6810 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006811 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6812 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006813
joonhunshin4ac60942023-11-15 15:23:39 +00006814 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6815 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn");
6816
shilu84f6e8b2019-12-19 13:58:01 -08006817 final long identity = Binder.clearCallingIdentity();
6818 try {
6819 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006820 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006821 }
6822
6823 final Phone phone = getPhone(subId);
6824 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006825 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006826 }
6827 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6828 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006829 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006830 } finally {
6831 Binder.restoreCallingIdentity(identity);
6832 }
6833 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006834
6835 /**
6836 * Scans for available networks.
6837 */
6838 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006839 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6840 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006841 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6842 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006843 LocationAccessPolicy.LocationPermissionResult locationResult =
6844 LocationAccessPolicy.checkLocationPermission(mApp,
6845 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6846 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006847 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006848 .setCallingPid(Binder.getCallingPid())
6849 .setCallingUid(Binder.getCallingUid())
6850 .setMethod("getCellNetworkScanResults")
6851 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006852 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6853 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006854 .build());
6855 switch (locationResult) {
6856 case DENIED_HARD:
6857 throw new SecurityException("Not allowed to access scan results -- location");
6858 case DENIED_SOFT:
6859 return null;
6860 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006861
Pengquan Menga1bb6272018-09-06 09:59:22 -07006862 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006863 try {
6864 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006865 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006866 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006867 } finally {
6868 Binder.restoreCallingIdentity(identity);
6869 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006870 }
6871
6872 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006873 * Get the call forwarding info, given the call forwarding reason.
6874 */
6875 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006876 public void getCallForwarding(int subId, int callForwardingReason,
6877 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006878 enforceReadPrivilegedPermission("getCallForwarding");
joonhunshin4ac60942023-11-15 15:23:39 +00006879
6880 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6881 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding");
6882
Shuo Qian4a594052020-01-23 11:59:30 -08006883 long identity = Binder.clearCallingIdentity();
6884 try {
6885 if (DBG) {
6886 log("getCallForwarding: subId " + subId
6887 + " callForwardingReason" + callForwardingReason);
6888 }
Hall Liu27d24262020-09-18 19:04:59 -07006889
6890 Phone phone = getPhone(subId);
6891 if (phone == null) {
6892 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006893 callback.onError(
6894 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006895 } catch (RemoteException e) {
6896 // ignore
6897 }
6898 return;
6899 }
6900
6901 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6902 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6903 @Override
6904 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6905 try {
6906 callback.onCallForwardingInfoAvailable(info);
6907 } catch (RemoteException e) {
6908 // ignore
6909 }
6910 }
6911
6912 @Override
6913 public void onError(int error) {
6914 try {
6915 callback.onError(error);
6916 } catch (RemoteException e) {
6917 // ignore
6918 }
6919 }
6920 });
6921 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006922 } finally {
6923 Binder.restoreCallingIdentity(identity);
6924 }
6925 }
6926
6927 /**
6928 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6929 * reason, the number to forward, and the timeout before the forwarding is attempted.
6930 */
6931 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006932 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6933 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006934 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006935
6936 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6937 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding");
6938
Shuo Qian4a594052020-01-23 11:59:30 -08006939 long identity = Binder.clearCallingIdentity();
6940 try {
6941 if (DBG) {
6942 log("setCallForwarding: subId " + subId
6943 + " callForwardingInfo" + callForwardingInfo);
6944 }
Hall Liu27d24262020-09-18 19:04:59 -07006945
6946 Phone phone = getPhone(subId);
6947 if (phone == null) {
6948 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006949 callback.accept(
6950 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006951 } catch (RemoteException e) {
6952 // ignore
6953 }
6954 return;
6955 }
6956
6957 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6958 FunctionalUtils.ignoreRemoteException(callback::accept));
6959
6960 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006961 } finally {
6962 Binder.restoreCallingIdentity(identity);
6963 }
6964 }
6965
6966 /**
Hall Liu27d24262020-09-18 19:04:59 -07006967 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006968 */
6969 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006970 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006971 enforceReadPrivilegedPermission("getCallWaitingStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00006972
6973 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6974 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus");
6975
Shuo Qian4a594052020-01-23 11:59:30 -08006976 long identity = Binder.clearCallingIdentity();
6977 try {
Hall Liu27d24262020-09-18 19:04:59 -07006978 Phone phone = getPhone(subId);
6979 if (phone == null) {
6980 try {
6981 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6982 } catch (RemoteException e) {
6983 // ignore
6984 }
6985 return;
6986 }
SongFerngWang0e767992021-03-31 22:08:45 +08006987 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6988 PersistableBundle c = configManager.getConfigForSubId(subId);
6989 boolean requireUssd = c.getBoolean(
6990 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006991
Shuo Qian4a594052020-01-23 11:59:30 -08006992 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006993 if (requireUssd) {
6994 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6995 getSubscriptionCarrierId(subId));
6996 String newUssdCommand = "";
6997 try {
6998 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006999 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007000 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
7001 } catch (NullPointerException e) {
7002 loge("Failed to generate USSD number" + e);
7003 }
7004 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7005 mMainThreadHandler, callback, carrierXmlParser,
7006 CarrierXmlParser.SsEntry.SSAction.QUERY);
7007 final String ussdCommand = newUssdCommand;
7008 Executors.newSingleThreadExecutor().execute(() -> {
7009 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7010 });
7011 } else {
7012 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
7013 callback::accept);
7014 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
7015 }
Shuo Qian4a594052020-01-23 11:59:30 -08007016 } finally {
7017 Binder.restoreCallingIdentity(identity);
7018 }
7019 }
7020
7021 /**
Hall Liu27d24262020-09-18 19:04:59 -07007022 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007023 */
7024 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007025 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007026 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007027
7028 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7029 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus");
7030
Shuo Qian4a594052020-01-23 11:59:30 -08007031 long identity = Binder.clearCallingIdentity();
7032 try {
Hall Liu27d24262020-09-18 19:04:59 -07007033 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
7034
7035 Phone phone = getPhone(subId);
7036 if (phone == null) {
7037 try {
7038 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7039 } catch (RemoteException e) {
7040 // ignore
7041 }
7042 return;
7043 }
7044
SongFerngWang0e767992021-03-31 22:08:45 +08007045 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7046 PersistableBundle c = configManager.getConfigForSubId(subId);
7047 boolean requireUssd = c.getBoolean(
7048 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007049
SongFerngWang0e767992021-03-31 22:08:45 +08007050 if (DBG) log("getCallWaitingStatus: subId " + subId);
7051 if (requireUssd) {
7052 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7053 getSubscriptionCarrierId(subId));
7054 CarrierXmlParser.SsEntry.SSAction ssAction =
7055 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
7056 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
7057 String newUssdCommand = "";
7058 try {
7059 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007060 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007061 .makeCommand(ssAction, null);
7062 } catch (NullPointerException e) {
7063 loge("Failed to generate USSD number" + e);
7064 }
7065 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7066 mMainThreadHandler, callback, carrierXmlParser, ssAction);
7067 final String ussdCommand = newUssdCommand;
7068 Executors.newSingleThreadExecutor().execute(() -> {
7069 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7070 });
7071 } else {
7072 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
7073 FunctionalUtils.ignoreRemoteException(callback::accept));
7074
7075 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
7076 }
Shuo Qian4a594052020-01-23 11:59:30 -08007077 } finally {
7078 Binder.restoreCallingIdentity(identity);
7079 }
7080 }
7081
7082 /**
yinxub1bed742017-04-17 11:45:04 -07007083 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07007084 *
yinxub1bed742017-04-17 11:45:04 -07007085 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007086 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
7087 * location related information which will be sent if the caller already possess
7088 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07007089 * @param request contains the radio access networks with bands/channels to scan
7090 * @param messenger callback messenger for scan results or errors
7091 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07007092 * @return the id of the requested scan which can be used to stop the scan.
7093 */
7094 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007095 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
7096 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007097 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007098 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7099 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08007100 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007101 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
7102 if (!renounceFineLocationAccess) {
7103 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007104 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7105 .setCallingPackage(callingPackage)
7106 .setCallingFeatureId(callingFeatureId)
7107 .setCallingPid(Binder.getCallingPid())
7108 .setCallingUid(Binder.getCallingUid())
7109 .setMethod("requestNetworkScan")
7110 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7111 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7112 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7113 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007114 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08007115 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07007116 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
7117 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08007118 if (e != null) {
7119 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
7120 throw e;
7121 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07007122 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08007123 return TelephonyScanManager.INVALID_SCAN_ID;
7124 }
7125 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007126 }
joonhunshin4ac60942023-11-15 15:23:39 +00007127
7128 enforceTelephonyFeatureWithException(callingPackage,
7129 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan");
7130
Hall Liu912dfd32019-04-25 14:02:26 -07007131 int callingUid = Binder.getCallingUid();
7132 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07007133 final long identity = Binder.clearCallingIdentity();
7134 try {
7135 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07007136 renounceFineLocationAccess, request, messenger, binder,
7137 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07007138 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07007139 } finally {
7140 Binder.restoreCallingIdentity(identity);
7141 }
yinxu504e1392017-04-12 16:03:22 -07007142 }
7143
Hall Liub2ac8ef2019-02-28 15:56:23 -08007144 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07007145 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00007146 boolean hasCarrierPriv;
7147 final long identity = Binder.clearCallingIdentity();
7148 try {
7149 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
7150 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
7151 } finally {
7152 Binder.restoreCallingIdentity(identity);
7153 }
Hall Liu558027f2019-05-15 19:14:05 -07007154 boolean hasNetworkScanPermission =
7155 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007156 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07007157
7158 if (!hasCarrierPriv && !hasNetworkScanPermission) {
7159 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
7160 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08007161 }
7162
7163 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
7164 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08007165 if (ras.getChannels() != null && ras.getChannels().length > 0) {
7166 return new SecurityException("Specific channels must not be"
7167 + " scanned without location access.");
7168 }
7169 }
7170 }
7171
Hall Liub2ac8ef2019-02-28 15:56:23 -08007172 return null;
7173 }
7174
yinxu504e1392017-04-12 16:03:22 -07007175 /**
7176 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07007177 *
7178 * @param subId id of the subscription
7179 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07007180 */
7181 @Override
7182 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007183 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7184 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007185
Hall Liu912dfd32019-04-25 14:02:26 -07007186 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007187 final long identity = Binder.clearCallingIdentity();
7188 try {
Hall Liu912dfd32019-04-25 14:02:26 -07007189 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007190 } finally {
7191 Binder.restoreCallingIdentity(identity);
7192 }
yinxu504e1392017-04-12 16:03:22 -07007193 }
7194
7195 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08007196 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07007197 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08007198 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07007199 */
7200 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08007201 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08007202 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007203 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08007204 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007205
joonhunshin4ac60942023-11-15 15:23:39 +00007206 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7207 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask");
7208
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007209 final long identity = Binder.clearCallingIdentity();
7210 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007211 if (DBG) log("getAllowedNetworkTypesBitmask");
7212 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
7213 int networkTypesBitmask = (result != null ? result[0] : -1);
7214 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
7215 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007216 } finally {
7217 Binder.restoreCallingIdentity(identity);
7218 }
Jake Hamby7c27be32014-03-03 13:25:59 -08007219 }
7220
7221 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007222 * Get the allowed network types for certain reason.
7223 *
7224 * @param subId the id of the subscription.
7225 * @param reason the reason the allowed network type change is taking place
7226 * @return the allowed network types.
7227 */
7228 @Override
7229 public long getAllowedNetworkTypesForReason(int subId,
7230 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07007231 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007232 mApp, subId, "getAllowedNetworkTypesForReason");
joonhunshin4ac60942023-11-15 15:23:39 +00007233
7234 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7235 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesForReason");
7236
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007237 final long identity = Binder.clearCallingIdentity();
7238 try {
Jack Yu7247ac82023-03-02 23:52:10 -08007239 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007240 } finally {
7241 Binder.restoreCallingIdentity(identity);
7242 }
7243 }
7244
7245 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07007246 * Enable/Disable E-UTRA-NR Dual Connectivity
7247 * @param subId subscription id of the sim card
7248 * @param nrDualConnectivityState expected NR dual connectivity state
7249 * This can be passed following states
7250 * <ol>
7251 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
7252 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
7253 * <li>Disable NR dual connectivity and force secondary cell to be released
7254 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
7255 * </ol>
7256 * @return operation result.
7257 */
7258 @Override
7259 public int setNrDualConnectivityState(int subId,
7260 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
7261 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7262 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007263 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007264 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7265 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
7266 }
7267
Sooraj Sasindran37444802020-08-11 10:40:43 -07007268 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7269 final long identity = Binder.clearCallingIdentity();
7270 try {
7271 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
7272 nrDualConnectivityState, subId,
7273 workSource);
7274 if (DBG) log("enableNRDualConnectivity result: " + result);
7275 return result;
7276 } finally {
7277 Binder.restoreCallingIdentity(identity);
7278 }
7279 }
7280
7281 /**
7282 * Is E-UTRA-NR Dual Connectivity enabled
7283 * @return true if dual connectivity is enabled else false
7284 */
7285 @Override
7286 public boolean isNrDualConnectivityEnabled(int subId) {
7287 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007288 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07007289 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007290 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007291 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7292 return false;
7293 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07007294 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7295 final long identity = Binder.clearCallingIdentity();
7296 try {
7297 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
7298 null, subId, workSource);
7299 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
7300 return isEnabled;
7301 } finally {
7302 Binder.restoreCallingIdentity(identity);
7303 }
7304 }
7305
7306 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007307 * Set the allowed network types of the device and
7308 * provide the reason triggering the allowed network change.
7309 *
7310 * @param subId the id of the subscription.
7311 * @param reason the reason the allowed network type change is taking place
7312 * @param allowedNetworkTypes the allowed network types.
7313 * @return true on success; false on any failure.
7314 */
7315 @Override
7316 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08007317 @TelephonyManager.AllowedNetworkTypesReason int reason,
7318 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007319 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7320 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007321 // If the caller only has carrier privileges, then they should not be able to override
7322 // any network types which were set for security reasons.
7323 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
7324 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007325 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007326 throw new SecurityException(
7327 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007328 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007329 }
joonhunshin4ac60942023-11-15 15:23:39 +00007330
7331 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7332 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason");
7333
SongFerngWang3ef3e072020-12-21 16:41:52 +08007334 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007335 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08007336 return false;
7337 }
7338 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
7339 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007340 return false;
7341 }
7342
Jack Yu5b494332023-01-23 18:18:04 +00007343 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
7344 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007345
Jack Yue37dd262022-12-16 11:53:37 -08007346 Phone phone = getPhone(subId);
7347 if (phone == null) {
7348 return false;
7349 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007350
Jack Yue37dd262022-12-16 11:53:37 -08007351 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007352 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007353 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08007354 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007355
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007356 final long identity = Binder.clearCallingIdentity();
7357 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007358 Boolean success = (Boolean) sendRequest(
7359 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
7360 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
7361
7362 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
7363 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007364 } finally {
7365 Binder.restoreCallingIdentity(identity);
7366 }
7367 }
7368
7369 /**
Miaoa84611c2019-03-15 09:21:10 +08007370 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08007371 *
Miaoa84611c2019-03-15 09:21:10 +08007372 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07007373 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08007374 * @hide
7375 */
7376 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08007377 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007378 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007379
7380 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7381 PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber");
7382
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007383 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08007384 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007385 try {
Miaoa84611c2019-03-15 09:21:10 +08007386 if (phone != null) {
7387 return phone.hasMatchedTetherApnSetting();
7388 } else {
7389 return false;
7390 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007391 } finally {
7392 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007393 }
Junda Liu475951f2014-11-07 16:45:03 -08007394 }
7395
7396 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007397 * Get the user enabled state of Mobile Data.
7398 *
7399 * TODO: remove and use isUserDataEnabled.
7400 * This can't be removed now because some vendor codes
7401 * calls through ITelephony directly while they should
7402 * use TelephonyManager.
7403 *
7404 * @return true on enabled
7405 */
7406 @Override
7407 public boolean getDataEnabled(int subId) {
7408 return isUserDataEnabled(subId);
7409 }
7410
7411 /**
7412 * Get whether mobile data is enabled per user setting.
7413 *
7414 * There are other factors deciding whether mobile data is actually enabled, but they are
7415 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007416 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007417 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7418 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007419 *
7420 * @return {@code true} if data is enabled else {@code false}
7421 */
7422 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007423 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007424 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007425 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007426 try {
7427 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7428 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007429 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007430 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7431 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007432 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007433 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007434 mApp, subId, functionName);
7435
Robert Greenwalt646120a2014-05-23 11:54:03 -07007436 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007437
7438 final long identity = Binder.clearCallingIdentity();
7439 try {
Jack Yu285100e2022-12-02 22:48:35 -08007440 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007441 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7442 Phone phone = PhoneFactory.getPhone(phoneId);
7443 if (phone != null) {
7444 boolean retVal = phone.isUserDataEnabled();
7445 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7446 return retVal;
7447 } else {
7448 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7449 return false;
7450 }
7451 } finally {
7452 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007453 }
7454 }
7455
7456 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007457 * Checks if the device is capable of mobile data by considering whether whether the
7458 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7459 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007460 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007461 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007462 */
7463 @Override
7464 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007465 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007466 try {
7467 try {
7468 mApp.enforceCallingOrSelfPermission(
7469 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007470 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007471 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007472 try {
7473 mApp.enforceCallingOrSelfPermission(
7474 android.Manifest.permission.READ_PHONE_STATE,
7475 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007476 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007477 mApp.enforceCallingOrSelfPermission(
7478 permission.READ_BASIC_PHONE_STATE, functionName);
7479 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007480 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007481 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007482 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007483 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007484
joonhunshin4ac60942023-11-15 15:23:39 +00007485 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7486 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled");
7487
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007488 final long identity = Binder.clearCallingIdentity();
7489 try {
Jack Yu285100e2022-12-02 22:48:35 -08007490 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007491 Phone phone = PhoneFactory.getPhone(phoneId);
7492 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007493 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007494 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007495 return retVal;
7496 } else {
7497 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7498 return false;
7499 }
7500 } finally {
7501 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007502 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007503 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007504
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007505 /**
7506 * Check if data is enabled for a specific reason
7507 * @param subId Subscription index
7508 * @param reason the reason the data enable change is taking place
7509 * @return {@code true} if the overall data is enabled; {@code false} if not.
7510 */
7511 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007512 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007513 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007514 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007515 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007516 try {
7517 mApp.enforceCallingOrSelfPermission(
7518 android.Manifest.permission.ACCESS_NETWORK_STATE,
7519 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007520 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007521 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7522 functionName);
7523 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007524 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007525 try {
7526 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007527 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007528 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007529 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007530 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007531 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007532 }
7533
joonhunshin4ac60942023-11-15 15:23:39 +00007534 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7535 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007536
7537 final long identity = Binder.clearCallingIdentity();
7538 try {
Jack Yu285100e2022-12-02 22:48:35 -08007539 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007540 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007541 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007542 + " reason=" + reason);
7543 }
7544 Phone phone = PhoneFactory.getPhone(phoneId);
7545 if (phone != null) {
7546 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007547 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007548 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007549 return retVal;
7550 } else {
7551 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007552 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007553 + subId + " retVal=false");
7554 }
7555 return false;
7556 }
7557 } finally {
7558 Binder.restoreCallingIdentity(identity);
7559 }
7560 }
7561
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007562 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007563 public int getCarrierPrivilegeStatus(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00007564 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7565 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus");
7566
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007567 // No permission needed; this only lets the caller inspect their own status.
7568 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007569 }
Junda Liu29340342014-07-10 15:23:27 -07007570
7571 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007572 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007573 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
joonhunshin4ac60942023-11-15 15:23:39 +00007574
7575 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7576 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatusForUid");
7577
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007578 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7579 }
7580
7581 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7582 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007583 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007584 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007585 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7586 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007587 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7588 if (cpt == null) {
7589 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007590 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7591 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007592 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007593 }
7594
7595 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007596 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007597 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
joonhunshin4ac60942023-11-15 15:23:39 +00007598
7599 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7600 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage");
7601
chen xuf7e9fe82019-05-09 19:31:02 -07007602 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007603 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007604 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007605 Phone phone = getPhone(subId);
7606 if (phone == null) {
7607 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7608 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7609 }
7610 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7611 if (cpt == null) {
7612 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007613 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7614 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007615 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007616 }
7617
7618 @Override
7619 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007620 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007621
7622 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7623 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7624 "checkCarrierPrivilegesForPackageAnyPhone");
7625
Rambo Wange7209ce2022-02-23 13:41:02 -08007626 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7627 }
7628
7629 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007630 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007631 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007632 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007633 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007634 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7635 Phone phone = PhoneFactory.getPhone(phoneId);
7636 if (phone == null) {
7637 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007638 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007639 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7640 if (cpt == null) {
7641 continue;
7642 }
7643 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007644 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7645 break;
7646 }
7647 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007648 return result;
Junda Liu29340342014-07-10 15:23:27 -07007649 }
Derek Tan89e89d42014-07-08 17:00:10 -07007650
7651 @Override
Junda Liue64de782015-04-16 17:19:16 -07007652 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007653 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007654
7655 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7656 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7657 "getCarrierPackageNamesForIntentAndPhone");
7658
Rambo Wang8a247eb2022-02-08 21:11:18 +00007659 Phone phone = PhoneFactory.getPhone(phoneId);
7660 if (phone == null) {
7661 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007662 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007663 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7664 if (cpt == null) {
7665 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007666 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007667 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007668 }
7669
Amith Yamasani6e118872016-02-19 12:53:51 -08007670 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007671 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007672 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007673 Phone phone = PhoneFactory.getPhone(phoneId);
7674 if (phone == null) {
7675 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007676 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007677 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7678 if (cpt == null) {
7679 return Collections.emptyList();
7680 }
7681 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007682 }
7683
chen xuf7e9fe82019-05-09 19:31:02 -07007684 @Override
7685 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007686 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
joonhunshin4ac60942023-11-15 15:23:39 +00007687
7688 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7689 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7690 "getPackagesWithCarrierPrivilegesForAllPhones");
7691
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007692 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007693 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007694 try {
7695 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7696 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7697 }
7698 } finally {
7699 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007700 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007701 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007702 }
7703
Rambo Wang6812ffb2022-03-15 16:54:17 -07007704 @Override
7705 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7706 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7707
joonhunshin4ac60942023-11-15 15:23:39 +00007708 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7709 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7710 "getCarrierServicePackageNameForLogicalSlot");
7711
Rambo Wang6812ffb2022-03-15 16:54:17 -07007712 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7713 if (phone == null) {
7714 return null;
7715 }
7716 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7717 if (cpt == null) {
7718 return null;
7719 }
7720 return cpt.getCarrierServicePackageName();
7721 }
7722
Wink Savilleb564aae2014-10-23 10:18:09 -07007723 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007724 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007725 UiccPort port = phone == null ? null : phone.getUiccPort();
7726 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007727 return null;
7728 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007729 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007730 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007731 return null;
7732 }
7733 return iccId;
7734 }
7735
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007736 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007737 public void setCallComposerStatus(int subId, int status) {
7738 enforceModifyPermission();
7739
joonhunshin4ac60942023-11-15 15:23:39 +00007740 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7741 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus");
7742
Shuo Qiane4e11672020-12-15 22:15:33 -08007743 final long identity = Binder.clearCallingIdentity();
7744 try {
7745 Phone phone = getPhone(subId);
7746 if (phone != null) {
7747 Phone defaultPhone = phone.getImsPhone();
7748 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7749 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7750 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007751 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7752 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007753 }
7754 }
Shuo Qian284ae752020-12-22 19:10:14 -08007755 } catch (ImsException e) {
7756 throw new ServiceSpecificException(e.getCode());
7757 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007758 Binder.restoreCallingIdentity(identity);
7759 }
7760 }
7761
7762 @Override
7763 public int getCallComposerStatus(int subId) {
7764 enforceReadPrivilegedPermission("getCallComposerStatus");
7765
joonhunshin4ac60942023-11-15 15:23:39 +00007766 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7767 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus");
7768
Shuo Qiane4e11672020-12-15 22:15:33 -08007769 final long identity = Binder.clearCallingIdentity();
7770 try {
7771 Phone phone = getPhone(subId);
7772 if (phone != null) {
7773 Phone defaultPhone = phone.getImsPhone();
7774 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7775 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7776 return imsPhone.getCallComposerStatus();
7777 }
7778 }
7779 } finally {
7780 Binder.restoreCallingIdentity(identity);
7781 }
7782 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7783 }
7784
7785 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007786 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7787 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007788 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007789 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007790
joonhunshin4ac60942023-11-15 15:23:39 +00007791 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7792 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7793 "setLine1NumberForDisplayForSubscriber");
7794
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007795 final long identity = Binder.clearCallingIdentity();
7796 try {
7797 final String iccId = getIccId(subId);
7798 final Phone phone = getPhone(subId);
7799 if (phone == null) {
7800 return false;
7801 }
7802 final String subscriberId = phone.getSubscriberId();
7803
7804 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007805 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007806 + subscriberId + " to " + number);
7807 }
7808
7809 if (TextUtils.isEmpty(iccId)) {
7810 return false;
7811 }
7812
7813 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7814
7815 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7816 if (alphaTag == null) {
7817 editor.remove(alphaTagPrefKey);
7818 } else {
7819 editor.putString(alphaTagPrefKey, alphaTag);
7820 }
7821
7822 // Record both the line number and IMSI for this ICCID, since we need to
7823 // track all merged IMSIs based on line number
7824 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7825 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7826 if (number == null) {
7827 editor.remove(numberPrefKey);
7828 editor.remove(subscriberPrefKey);
7829 } else {
7830 editor.putString(numberPrefKey, number);
7831 editor.putString(subscriberPrefKey, subscriberId);
7832 }
7833
7834 editor.commit();
7835 return true;
7836 } finally {
7837 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007838 }
Derek Tan7226c842014-07-02 17:42:23 -07007839 }
7840
7841 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007842 public String getLine1NumberForDisplay(int subId, String callingPackage,
7843 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007844 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007845 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007846 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007847 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007848 return null;
7849 }
Derek Tan97ebb422014-09-05 16:55:38 -07007850
joonhunshin4ac60942023-11-15 15:23:39 +00007851 enforceTelephonyFeatureWithException(callingPackage,
7852 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay");
7853
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007854 final long identity = Binder.clearCallingIdentity();
7855 try {
7856 String iccId = getIccId(subId);
7857 if (iccId != null) {
7858 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7859 if (DBG_MERGE) {
7860 log("getLine1NumberForDisplay returning "
7861 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7862 }
7863 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007864 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007865 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7866 return null;
7867 } finally {
7868 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007869 }
Derek Tan7226c842014-07-02 17:42:23 -07007870 }
7871
7872 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007873 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7874 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007875 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007876 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007877 return null;
7878 }
Derek Tan97ebb422014-09-05 16:55:38 -07007879
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007880 final long identity = Binder.clearCallingIdentity();
7881 try {
7882 String iccId = getIccId(subId);
7883 if (iccId != null) {
7884 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7885 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7886 }
7887 return null;
7888 } finally {
7889 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007890 }
Derek Tan7226c842014-07-02 17:42:23 -07007891 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007892
7893 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007894 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7895 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007896 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7897 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007898 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007899 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007900 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007901 return null;
7902 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007903
Jordan Liub49b04b2019-05-06 14:45:15 -07007904 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7905 // the process, where TelephonyManager was instantiated.
7906 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007907 final long identity = Binder.clearCallingIdentity();
7908 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007909 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007910 final TelephonyManager tele = TelephonyManager.from(context);
7911 final SubscriptionManager sub = SubscriptionManager.from(context);
7912
7913 // Figure out what subscribers are currently active
7914 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007915
Jordan Liub49b04b2019-05-06 14:45:15 -07007916 // Only consider subs which match the current subId
7917 // This logic can be simplified. See b/131189269 for progress.
7918 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007919 activeSubscriberIds.add(tele.getSubscriberId(subId));
7920 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007921
7922 // First pass, find a number override for an active subscriber
7923 String mergeNumber = null;
7924 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7925 for (String key : prefs.keySet()) {
7926 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7927 final String subscriberId = (String) prefs.get(key);
7928 if (activeSubscriberIds.contains(subscriberId)) {
7929 final String iccId = key.substring(
7930 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7931 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7932 mergeNumber = (String) prefs.get(numberKey);
7933 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007934 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007935 + " for active subscriber " + subscriberId);
7936 }
7937 if (!TextUtils.isEmpty(mergeNumber)) {
7938 break;
7939 }
7940 }
7941 }
7942 }
7943
7944 // Shortcut when no active merged subscribers
7945 if (TextUtils.isEmpty(mergeNumber)) {
7946 return null;
7947 }
7948
7949 // Second pass, find all subscribers under that line override
7950 final ArraySet<String> result = new ArraySet<>();
7951 for (String key : prefs.keySet()) {
7952 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7953 final String number = (String) prefs.get(key);
7954 if (mergeNumber.equals(number)) {
7955 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7956 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7957 final String subscriberId = (String) prefs.get(subscriberKey);
7958 if (!TextUtils.isEmpty(subscriberId)) {
7959 result.add(subscriberId);
7960 }
7961 }
7962 }
7963 }
7964
7965 final String[] resultArray = result.toArray(new String[result.size()]);
7966 Arrays.sort(resultArray);
7967 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007968 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007969 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7970 }
7971 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007972 } finally {
7973 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007974 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007975 }
7976
7977 @Override
zoey chen38003472019-12-13 17:16:31 +08007978 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7979 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007980
joonhunshin4ac60942023-11-15 15:23:39 +00007981 enforceTelephonyFeatureWithException(callingPackage,
7982 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup");
7983
Malcolm Chen6ca97372019-07-01 16:28:21 -07007984 final long identity = Binder.clearCallingIdentity();
7985 try {
7986 final TelephonyManager telephonyManager = mApp.getSystemService(
7987 TelephonyManager.class);
7988 String subscriberId = telephonyManager.getSubscriberId(subId);
7989 if (subscriberId == null) {
7990 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007991 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007992 + subId);
7993 }
7994 return null;
7995 }
7996
Jack Yu3beaf9d2023-04-14 09:17:27 -07007997 final SubscriptionInfo info = getSubscriptionManagerService()
7998 .getSubscriptionInfo(subId);
7999 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07008000 // If it doesn't belong to any group, return just subscriberId of itself.
8001 if (groupUuid == null) {
8002 return new String[]{subscriberId};
8003 }
8004
8005 // Get all subscriberIds from the group.
8006 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07008007 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
8008 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
8009 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07008010 for (SubscriptionInfo subInfo : groupInfos) {
8011 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
8012 if (subscriberId != null) {
8013 mergedSubscriberIds.add(subscriberId);
8014 }
8015 }
8016
8017 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
8018 } finally {
8019 Binder.restoreCallingIdentity(identity);
8020
8021 }
8022 }
8023
8024 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008025 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008026 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08008027 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008028
joonhunshin4ac60942023-11-15 15:23:39 +00008029 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8030 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride");
8031
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008032 final long identity = Binder.clearCallingIdentity();
8033 try {
8034 final Phone phone = getPhone(subId);
8035 return phone == null ? false : phone.setOperatorBrandOverride(brand);
8036 } finally {
8037 Binder.restoreCallingIdentity(identity);
8038 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07008039 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05008040
8041 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008042 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008043 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
8044 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008045 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
8046 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008047
8048 final long identity = Binder.clearCallingIdentity();
8049 try {
8050 final Phone phone = getPhone(subId);
8051 if (phone == null) {
8052 return false;
8053 }
8054 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
8055 cdmaNonRoamingList);
8056 } finally {
8057 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008058 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008059 }
8060
8061 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07008062 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008063 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08008064 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008065 if (phone == null) {
8066 return raf;
8067 }
8068
Shuo Qiandee53402020-05-29 14:08:15 -07008069 try {
8070 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008071 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07008072 mApp, phone.getSubId(), "getRadioAccessFamily");
8073 } catch (SecurityException e) {
8074 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
8075 throw e;
8076 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008077
joonhunshin4ac60942023-11-15 15:23:39 +00008078 enforceTelephonyFeatureWithException(callingPackage,
8079 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily");
8080
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008081 final long identity = Binder.clearCallingIdentity();
8082 try {
chen xub97461a2018-10-26 14:17:57 -07008083 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008084 } finally {
8085 Binder.restoreCallingIdentity(identity);
8086 }
chen xub97461a2018-10-26 14:17:57 -07008087 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07008088 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008089
8090 @Override
Hall Liu82694d52020-12-11 18:22:04 -08008091 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08008092 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08008093 try {
8094 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
8095 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008096 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008097 }
8098 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008099 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008100 }
joonhunshin4ac60942023-11-15 15:23:39 +00008101
8102 enforceTelephonyFeatureWithException(callingPackage,
8103 PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture");
8104
Hall Liu82694d52020-12-11 18:22:04 -08008105 RoleManager rm = mApp.getSystemService(RoleManager.class);
8106 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
8107 if (!dialerRoleHolders.contains(callingPackage)) {
8108 throw new SecurityException("App must be the dialer role holder to"
8109 + " upload a call composer pic");
8110 }
8111
8112 Executors.newSingleThreadExecutor().execute(() -> {
8113 ByteArrayOutputStream output = new ByteArrayOutputStream(
8114 (int) TelephonyManager.getMaximumCallComposerPictureSize());
8115 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
8116 boolean readUntilEnd = false;
8117 int totalBytesRead = 0;
8118 byte[] buffer = new byte[16 * 1024];
8119 while (true) {
8120 int numRead;
8121 try {
8122 numRead = input.read(buffer);
8123 } catch (IOException e) {
8124 try {
8125 fd.checkError();
8126 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
8127 null);
8128 } catch (IOException e1) {
8129 // This means that the other side closed explicitly with an error. If this
8130 // happens, log and ignore.
8131 loge("Remote end of call composer picture pipe closed: " + e1);
8132 }
8133 break;
8134 }
8135 if (numRead == -1) {
8136 readUntilEnd = true;
8137 break;
8138 }
8139 totalBytesRead += numRead;
8140 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
8141 loge("Too many bytes read for call composer picture: " + totalBytesRead);
8142 try {
8143 input.close();
8144 } catch (IOException e) {
8145 // ignore
8146 }
8147 break;
8148 }
8149 output.write(buffer, 0, numRead);
8150 }
8151 // Generally, the remote end will close the file descriptors. The only case where we
8152 // close is above, where the picture size is too big.
8153
8154 try {
8155 fd.checkError();
8156 } catch (IOException e) {
8157 loge("Remote end for call composer closed with an error: " + e);
8158 return;
8159 }
8160
Hall Liuaa4211e2021-01-20 15:43:39 -08008161 if (!readUntilEnd) {
8162 loge("Did not finish reading entire image; aborting");
8163 return;
8164 }
Hall Liu82694d52020-12-11 18:22:04 -08008165
Hall Liuaa4211e2021-01-20 15:43:39 -08008166 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
8167 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
8168 new CallComposerPictureTransfer.Factory() {},
8169 imageData,
8170 (result) -> {
8171 if (result.first != null) {
8172 ParcelUuid parcelUuid = new ParcelUuid(result.first);
8173 Bundle outputResult = new Bundle();
8174 outputResult.putParcelable(
8175 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
8176 callback.send(TelephonyManager.CallComposerException.SUCCESS,
8177 outputResult);
8178 } else {
8179 callback.send(result.second, null);
8180 }
8181 }
8182 );
Hall Liu82694d52020-12-11 18:22:04 -08008183 });
8184 }
8185
8186 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07008187 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008188 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07008189 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008190
joonhunshin4ac60942023-11-15 15:23:39 +00008191 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8192 PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling");
8193
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008194 final long identity = Binder.clearCallingIdentity();
8195 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008196 ImsManager.getInstance(defaultPhone.getContext(),
8197 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008198 } finally {
8199 Binder.restoreCallingIdentity(identity);
8200 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008201 }
8202
8203 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008204 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008205 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008206 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
8207 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00008208 return false;
8209 }
Svet Ganovb320e182015-04-16 12:30:10 -07008210
joonhunshin4ac60942023-11-15 15:23:39 +00008211 enforceTelephonyFeatureWithException(callingPackage,
8212 PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled");
8213
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008214 final long identity = Binder.clearCallingIdentity();
8215 try {
8216 // Check the user preference and the system-level IMS setting. Even if the user has
8217 // enabled video calling, if IMS is disabled we aren't able to support video calling.
8218 // In the long run, we may instead need to check if there exists a connection service
8219 // which can support video calling.
8220 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008221 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008222 return imsManager.isVtEnabledByPlatform()
8223 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
8224 && imsManager.isVtEnabledByUser();
8225 } finally {
8226 Binder.restoreCallingIdentity(identity);
8227 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008228 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06008229
Andrew Leea1239f22015-03-02 17:44:07 -08008230 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008231 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
8232 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008233 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008234 mApp, subId, callingPackage, callingFeatureId,
8235 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008236 return false;
8237 }
8238
joonhunshin4ac60942023-11-15 15:23:39 +00008239 enforceTelephonyFeatureWithException(callingPackage,
8240 PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength");
8241
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008242 final long identity = Binder.clearCallingIdentity();
8243 try {
8244 CarrierConfigManager configManager =
8245 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008246 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008247 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
8248 } finally {
8249 Binder.restoreCallingIdentity(identity);
8250 }
Andrew Leea1239f22015-03-02 17:44:07 -08008251 }
8252
8253 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008254 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008255 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008256 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008257 return false;
8258 }
8259
joonhunshin4ac60942023-11-15 15:23:39 +00008260 enforceTelephonyFeatureWithException(callingPackage,
8261 PackageManager.FEATURE_TELEPHONY, "isWorldPhone");
8262
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008263 final long identity = Binder.clearCallingIdentity();
8264 try {
8265 CarrierConfigManager configManager =
8266 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008267 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008268 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
8269 } finally {
8270 Binder.restoreCallingIdentity(identity);
8271 }
Andrew Leea1239f22015-03-02 17:44:07 -08008272 }
8273
Andrew Lee9431b832015-03-09 18:46:45 -07008274 @Override
8275 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008276 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08008277 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07008278 }
8279
8280 @Override
8281 public boolean isHearingAidCompatibilitySupported() {
joonhunshin4ac60942023-11-15 15:23:39 +00008282 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8283 PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported");
8284
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008285 final long identity = Binder.clearCallingIdentity();
8286 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008287 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008288 } finally {
8289 Binder.restoreCallingIdentity(identity);
8290 }
Andrew Lee9431b832015-03-09 18:46:45 -07008291 }
8292
Hall Liuf6668912018-10-31 17:05:23 -07008293 /**
8294 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
8295 * support for the feature and device firmware support.
8296 *
8297 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
8298 */
8299 @Override
8300 public boolean isRttSupported(int subscriptionId) {
joonhunshin4ac60942023-11-15 15:23:39 +00008301 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8302 PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported");
8303
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008304 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008305 final Phone phone = getPhone(subscriptionId);
8306 if (phone == null) {
8307 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
8308 return false;
8309 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008310 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008311 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008312 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
joonhunshin4ac60942023-11-15 15:23:39 +00008313 boolean isDeviceSupported = (phone.getContext().getResources() != null)
8314 ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt)
8315 : false;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008316 return isCarrierSupported && isDeviceSupported;
8317 } finally {
8318 Binder.restoreCallingIdentity(identity);
8319 }
Hall Liu98187582018-01-22 19:15:32 -08008320 }
8321
Hall Liuf6668912018-10-31 17:05:23 -07008322 /**
Hall Liuf2daa022019-07-23 18:39:00 -07008323 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
8324 * RTT setting, will return true if the device and carrier both support RTT.
8325 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07008326 */
8327 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008328 final long identity = Binder.clearCallingIdentity();
8329 try {
joonhunshin4ac60942023-11-15 15:23:39 +00008330 if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) {
8331 if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
8332 return false;
8333 }
8334 }
8335
Hall Liu5bab75c2019-12-11 23:58:20 +00008336 boolean isRttSupported = isRttSupported(subscriptionId);
8337 boolean isUserRttSettingOn = Settings.Secure.getInt(
8338 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
8339 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
8340 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
8341 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008342 } finally {
8343 Binder.restoreCallingIdentity(identity);
8344 }
Hall Liu3ad5f012018-04-06 16:23:39 -07008345 }
8346
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008347 @Deprecated
8348 @Override
8349 public String getDeviceId(String callingPackage) {
8350 return getDeviceIdWithFeature(callingPackage, null);
8351 }
8352
Sanket Padawe7310cc72015-01-14 09:53:20 -08008353 /**
8354 * Returns the unique device ID of phone, for example, the IMEI for
8355 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
8356 *
8357 * <p>Requires Permission:
8358 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
8359 */
8360 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008361 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07008362 try {
8363 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
8364 } catch (SecurityException se) {
8365 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
8366 throw new SecurityException("Package " + callingPackage + " does not belong to "
8367 + Binder.getCallingUid());
8368 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008369 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008370 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008371 return null;
8372 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008373 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008374 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008375 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008376 return null;
8377 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008378
8379 final long identity = Binder.clearCallingIdentity();
8380 try {
8381 return phone.getDeviceId();
8382 } finally {
8383 Binder.restoreCallingIdentity(identity);
8384 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008385 }
8386
Ping Sunc67b7c22016-03-02 19:16:45 +08008387 /**
8388 * {@hide}
8389 * Returns the IMS Registration Status on a particular subid
8390 *
8391 * @param subId
8392 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008393 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008394 Phone phone = getPhone(subId);
8395 if (phone != null) {
8396 return phone.isImsRegistered();
8397 } else {
8398 return false;
8399 }
8400 }
8401
Santos Cordon7a1885b2015-02-03 11:15:19 -08008402 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008403 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008404 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008405 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008406 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008407 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8408 }
8409 final long identity = Binder.clearCallingIdentity();
8410 try {
8411 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8412 } finally {
8413 Binder.restoreCallingIdentity(identity);
8414 }
8415 }
8416
8417 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008418 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008419 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008420 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008421 mApp,
8422 subscriptionId,
8423 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
8424 + subscriptionId);
joonhunshin4ac60942023-11-15 15:23:39 +00008425
8426 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8427 PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId");
8428
Tyler Gunnf70ed162019-04-03 15:28:53 -07008429 final long identity = Binder.clearCallingIdentity();
8430 try {
8431 Phone phone = getPhone(subscriptionId);
8432 if (phone == null) {
8433 return null;
8434 }
8435 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8436 } finally {
8437 Binder.restoreCallingIdentity(identity);
8438 }
8439 }
8440
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008441 /**
8442 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008443 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008444 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008445 final long identity = Binder.clearCallingIdentity();
8446 try {
8447 Phone phone = getPhone(subId);
8448 if (phone != null) {
8449 return phone.isWifiCallingEnabled();
8450 } else {
8451 return false;
8452 }
8453 } finally {
8454 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008455 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008456 }
8457
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008458 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008459 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008460 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008461 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008462 final long identity = Binder.clearCallingIdentity();
8463 try {
8464 Phone phone = getPhone(subId);
8465 if (phone != null) {
8466 return phone.isVideoEnabled();
8467 } else {
8468 return false;
8469 }
8470 } finally {
8471 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008472 }
8473 }
8474
8475 /**
8476 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8477 * defined in {@link ImsRegistrationImplBase}.
8478 */
8479 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008480 final long identity = Binder.clearCallingIdentity();
8481 try {
8482 Phone phone = getPhone(subId);
8483 if (phone != null) {
8484 return phone.getImsRegistrationTech();
8485 } else {
8486 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8487 }
8488 } finally {
8489 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008490 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008491 }
8492
Stuart Scott8eef64f2015-04-08 15:13:54 -07008493 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008494 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008495 enforceSettingsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008496
8497 enforceTelephonyFeatureWithException(callingPackage,
8498 PackageManager.FEATURE_TELEPHONY, "factoryReset");
8499
Stuart Scott981d8582015-04-21 14:09:50 -07008500 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8501 return;
8502 }
Kai Shif70f46f2021-03-03 13:59:46 -08008503 Phone defaultPhone = getDefaultPhone();
8504 if (defaultPhone != null) {
8505 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8506 mApp, getDefaultPhone().getSubId(), "factoryReset");
8507 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008508 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008509
Svet Ganovcc087f82015-05-12 20:35:54 -07008510 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008511 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8512 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008513 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008514 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008515 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008516 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008517 cleanUpAllowedNetworkTypes(phone, subId);
Rambo Wang71f6aa62024-02-23 20:16:22 +00008518 setDataRoamingEnabled(subId, phone == null ? false
8519 : phone.getDataSettingsManager().isDefaultDataRoamingEnabled());
Jordan Liu857e73a2021-03-05 16:24:04 -08008520 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008521 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008522 // There has been issues when Sms raw table somehow stores orphan
8523 // fragments. They lead to garbled message when new fragments come
8524 // in and combined with those stale ones. In case this happens again,
8525 // user can reset all network settings which will clean up this table.
8526 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008527 // Clean up IMS settings as well here.
8528 int slotId = getSlotIndex(subId);
8529 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
8530 ImsManager.getInstance(mApp, slotId).factoryReset();
8531 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008532
Kai Shif70f46f2021-03-03 13:59:46 -08008533 if (defaultPhone == null) {
8534 return;
8535 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008536 // Erase modem config if erase modem on network setting is enabled.
8537 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8538 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8539 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008540 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008541 }
Kai Shif70f46f2021-03-03 13:59:46 -08008542
8543 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008544 } finally {
8545 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008546 }
8547 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008548
SongFerngWangfd89b102021-05-27 22:44:54 +08008549 @VisibleForTesting
8550 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8551 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8552 return;
8553 }
8554 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8555 RILConstants.PREFERRED_NETWORK_MODE);
8556 SubscriptionManager.setSubscriptionProperty(subId,
8557 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8558 "user=" + defaultNetworkType);
8559 phone.loadAllowedNetworksFromSubscriptionDatabase();
8560 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8561 defaultNetworkType, null);
8562 }
8563
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008564 private void cleanUpSmsRawTable(Context context) {
8565 ContentResolver resolver = context.getContentResolver();
8566 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8567 resolver.delete(uri, null, null);
8568 }
8569
Narayan Kamath1c496c22015-04-16 14:40:19 +01008570 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008571 public String getSimLocaleForSubscriber(int subId) {
8572 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
joonhunshin4ac60942023-11-15 15:23:39 +00008573
8574 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8575 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber");
8576
chen xu5d3637b2019-01-21 23:31:38 -08008577 final Phone phone = getPhone(subId);
8578 if (phone == null) {
8579 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008580 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008581 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008582 final long identity = Binder.clearCallingIdentity();
8583 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008584 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
8585 phone.getContext().getOpPackageName(),
8586 phone.getContext().getAttributionTag());
8587 if (info == null) {
8588 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8589 return null;
chen xu6291c472019-02-04 12:55:53 -08008590 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008591 // Try and fetch the locale from the carrier properties or from the SIM language
8592 // preferences (EF-PL and EF-LI)...
8593 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008594 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008595 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8596 if (localeFromDefaultSim != null) {
8597 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8598 if (DBG) log("Using locale from subId: " + subId + " locale: "
8599 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008600 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008601 } else {
8602 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008603 }
8604 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008605
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008606 // The SIM language preferences only store a language (e.g. fr = French), not an
8607 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8608 // the SIM and carrier preferences does not include a country we add the country
8609 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008610 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008611 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008612 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008613 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008614 }
8615
8616 if (DBG) log("No locale found - returning null");
8617 return null;
8618 } finally {
8619 Binder.restoreCallingIdentity(identity);
8620 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008621 }
8622
tom hsu0b59d292022-09-29 23:49:21 +08008623 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008624 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008625 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008626 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008627 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008628 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8629 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008630 Locale.forLanguageTag(localeTag).getCountry())) {
8631 return localeTag;
8632 }
8633 }
8634 return inputLocale.toLanguageTag();
8635 }
8636
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008637 /**
8638 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8639 */
8640 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008641 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Ling Ma9fa67412023-11-13 14:13:19 -08008642 mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/);
Narayan Kamath1c496c22015-04-16 14:40:19 +01008643 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008644
Gary Jian3aa9a762022-01-24 16:41:19 +08008645 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8646 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008647
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008648 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008649 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8650 * representing the state of the modem.
8651 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008652 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8653 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008654 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008655 */
8656 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008657 public void requestModemActivityInfo(ResultReceiver result) {
8658 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008659
8660 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8661 PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo");
8662
vagdeviaf9a5b92018-08-15 16:01:53 -07008663 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008664
8665 final long identity = Binder.clearCallingIdentity();
8666 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008667 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008668 } finally {
8669 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008670 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008671 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008672
Gary Jian76280a42022-12-07 16:18:33 +08008673 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008674 // less than total activity duration.
8675 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8676 if (info == null) {
8677 return false;
8678 }
8679 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008680 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008681 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8682
Hall Liu49656c02020-10-09 19:00:11 -07008683 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8684
Siddharth Rayb8114062018-06-17 15:02:38 -07008685 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008686 && (info.getSleepTimeMillis() <= activityDurationMs)
8687 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008688 }
8689
Gary Jian3aa9a762022-01-24 16:41:19 +08008690 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8691 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8692 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8693 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8694
8695 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8696 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8697 }
8698
8699 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8700 mLastModemActivityInfo.setReceiveTimeMillis(
8701 rat,
8702 freq,
8703 info.getReceiveTimeMillis(rat, freq)
8704 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8705 }
8706
8707 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8708 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8709 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8710 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8711
8712 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8713 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8714 }
8715 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8716 mLastModemActivityInfo.setReceiveTimeMillis(
8717 rat,
8718 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8719 }
8720
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008721 /**
8722 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8723 * @param info recent ModemActivityInfo
8724 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008725 private void mergeModemActivityInfo(ModemActivityInfo info) {
8726 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008727 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008728 boolean matched;
8729 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8730 matched = false;
8731 int rat = info.getSpecificInfoRat(i);
8732 int freq = info.getSpecificInfoFrequencyRange(i);
8733 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8734 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8735 //if it already exists
8736 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8737 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8738 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8739 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8740 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8741 updateLastModemActivityInfo(info, rat, freq);
8742 matched = true;
8743 }
8744 } else {
8745 updateLastModemActivityInfo(info, rat);
8746 matched = true;
8747 }
8748 }
8749 }
8750
8751 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008752 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008753 new ActivityStatsTechSpecificInfo(
8754 rat,
8755 freq,
8756 info.getTransmitTimeMillis(rat, freq),
8757 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008758 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008759 }
8760 }
8761 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8762 mLastModemActivitySpecificInfo =
8763 new ActivityStatsTechSpecificInfo[merged.size()];
8764 merged.toArray(mLastModemActivitySpecificInfo);
8765
8766 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8767 mLastModemActivityInfo.setSleepTimeMillis(
8768 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008769 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008770 mLastModemActivityInfo.setIdleTimeMillis(
8771 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008772 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008773
8774 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008775 new ModemActivityInfo(
8776 mLastModemActivityInfo.getTimestampMillis(),
8777 mLastModemActivityInfo.getSleepTimeMillis(),
8778 mLastModemActivityInfo.getIdleTimeMillis(),
8779 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008780 }
8781
8782 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8783 ActivityStatsTechSpecificInfo[] info) {
8784 int infoSize = info.length;
8785 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8786 for (int i = 0; i < infoSize; i++) {
8787 ret[i] = new ActivityStatsTechSpecificInfo(
8788 info[i].getRat(), info[i].getFrequencyRange(),
8789 info[i].getTransmitTimeMillis(),
8790 (int) info[i].getReceiveTimeMillis());
8791 }
8792 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008793 }
8794
Jack Yu85bd38a2015-11-09 11:34:32 -08008795 /**
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008796 * Returns the service state information on specified SIM slot.
Jack Yu85bd38a2015-11-09 11:34:32 -08008797 */
8798 @Override
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008799 public ServiceState getServiceStateForSlot(int slotIndex, boolean renounceFineLocationAccess,
8800 boolean renounceCoarseLocationAccess, String callingPackage, String callingFeatureId) {
8801 Phone phone = PhoneFactory.getPhone(slotIndex);
8802 if (phone == null) {
8803 loge("getServiceStateForSlot retuning null for invalid slotIndex=" + slotIndex);
8804 return null;
8805 }
8806
8807 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08008808 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008809 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008810 return null;
8811 }
8812
joonhunshin4ac60942023-11-15 15:23:39 +00008813 enforceTelephonyFeatureWithException(callingPackage,
8814 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber");
8815
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008816 boolean hasFinePermission = false;
8817 boolean hasCoarsePermission = false;
8818 if (!renounceFineLocationAccess) {
8819 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8820 LocationAccessPolicy.checkLocationPermission(mApp,
8821 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8822 .setCallingPackage(callingPackage)
8823 .setCallingFeatureId(callingFeatureId)
8824 .setCallingPid(Binder.getCallingPid())
8825 .setCallingUid(Binder.getCallingUid())
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008826 .setMethod("getServiceStateForSlot")
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008827 .setLogAsInfo(true)
8828 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8829 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8830 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8831 .build());
8832 hasFinePermission =
8833 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8834 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008835
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008836 if (!renounceCoarseLocationAccess) {
8837 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8838 LocationAccessPolicy.checkLocationPermission(mApp,
8839 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8840 .setCallingPackage(callingPackage)
8841 .setCallingFeatureId(callingFeatureId)
8842 .setCallingPid(Binder.getCallingPid())
8843 .setCallingUid(Binder.getCallingUid())
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008844 .setMethod("getServiceStateForSlot")
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008845 .setLogAsInfo(true)
8846 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8847 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8848 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8849 .build());
8850 hasCoarsePermission =
8851 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8852 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008853
Jordan Liu0f2bc442020-11-18 16:47:37 -08008854 final long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008855 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008856 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8857 .getSubscriptionInfoInternal(subId);
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008858 if (subInfo != null && !subInfo.isActive()) {
8859 log("getServiceStateForSlot returning null for inactive subId=" + subId);
Jack Yu3beaf9d2023-04-14 09:17:27 -07008860 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008861 }
8862
Hall Liuf19c44f2018-11-27 14:38:17 -08008863 ServiceState ss = phone.getServiceState();
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008864 boolean isCallingPackageDataService = phone.getDataServicePackages()
8865 .contains(callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08008866
8867 // Scrub out the location info in ServiceState depending on what level of access
8868 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008869 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008870 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8871 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008872 } finally {
8873 Binder.restoreCallingIdentity(identity);
8874 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008875 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008876
8877 /**
8878 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8879 *
8880 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8881 * voicemail ringtone.
8882 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8883 * PhoneAccount.
8884 */
8885 @Override
8886 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008887 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8888 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri");
8889
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008890 final long identity = Binder.clearCallingIdentity();
8891 try {
8892 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8893 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008894 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008895 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008896
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008897 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8898 } finally {
8899 Binder.restoreCallingIdentity(identity);
8900 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008901 }
8902
8903 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008904 * Sets the per-account voicemail ringtone.
8905 *
8906 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8907 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8908 *
8909 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8910 * voicemail ringtone.
8911 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8912 * PhoneAccount.
8913 */
8914 @Override
8915 public void setVoicemailRingtoneUri(String callingPackage,
8916 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008917 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008918 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008919 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8920 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008921 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8922 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8923 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008924 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008925
joonhunshin4ac60942023-11-15 15:23:39 +00008926 enforceTelephonyFeatureWithException(callingPackage,
8927 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri");
8928
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008929 final long identity = Binder.clearCallingIdentity();
8930 try {
8931 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8932 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008933 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008934 }
8935 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8936 } finally {
8937 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008938 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008939 }
8940
8941 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008942 * Returns whether vibration is set for voicemail notification in Phone settings.
8943 *
8944 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8945 * voicemail vibration setting.
8946 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8947 */
8948 @Override
8949 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008950 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8951 PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled");
8952
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008953 final long identity = Binder.clearCallingIdentity();
8954 try {
8955 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8956 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008957 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008958 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008959
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008960 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8961 } finally {
8962 Binder.restoreCallingIdentity(identity);
8963 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008964 }
8965
Youhan Wange64578a2016-05-02 15:32:42 -07008966 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008967 * Sets the per-account voicemail vibration.
8968 *
8969 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8970 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8971 *
8972 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8973 * voicemail vibration setting.
8974 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8975 * specific PhoneAccount.
8976 */
8977 @Override
8978 public void setVoicemailVibrationEnabled(String callingPackage,
8979 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008980 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008981 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008982 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8983 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008984 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8985 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8986 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008987 }
8988
joonhunshin4ac60942023-11-15 15:23:39 +00008989 enforceTelephonyFeatureWithException(callingPackage,
8990 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled");
8991
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008992 final long identity = Binder.clearCallingIdentity();
8993 try {
8994 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8995 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008996 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008997 }
8998 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8999 } finally {
9000 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009001 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009002 }
9003
9004 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009005 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
9006 *
9007 * @throws SecurityException if the caller does not have the required permission
9008 */
arunvoddud7401012022-12-15 16:08:12 +00009009 @VisibleForTesting
9010 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07009011 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07009012 message);
Youhan Wange64578a2016-05-02 15:32:42 -07009013 }
9014
9015 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009016 * Make sure either called from same process as self (phone) or IPC caller has send SMS
9017 * permission.
9018 *
9019 * @throws SecurityException if the caller does not have the required permission
9020 */
9021 private void enforceSendSmsPermission() {
9022 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
9023 }
9024
9025 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00009026 * Make sure either called from same process as self (phone) or IPC caller has interact across
9027 * users permission.
9028 *
9029 * @throws SecurityException if the caller does not have the required permission
9030 */
9031 private void enforceInteractAcrossUsersPermission(String message) {
9032 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
9033 }
9034
9035 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009036 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009037 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009038 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009039 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009040 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009041 final long identity = Binder.clearCallingIdentity();
9042 try {
9043 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009044 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009045 if (componentName == null) {
9046 throw new SecurityException(
9047 "Caller not current active visual voicemail package[null]");
9048 }
9049 String vvmPackage = componentName.getPackageName();
9050 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00009051 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009052 }
9053 } finally {
9054 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009055 }
9056 }
9057
9058 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009059 * Return the application ID for the app type.
9060 *
9061 * @param subId the subscription ID that this request applies to.
9062 * @param appType the uicc app type.
9063 * @return Application ID for specificied app type, or null if no uicc.
9064 */
9065 @Override
9066 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009067 enforceReadPrivilegedPermission("getAidForAppType");
joonhunshin4ac60942023-11-15 15:23:39 +00009068
9069 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9070 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType");
9071
Youhan Wange64578a2016-05-02 15:32:42 -07009072 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009073
9074 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07009075 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009076 if (phone == null) {
9077 return null;
9078 }
9079 String aid = null;
9080 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009081 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009082 .getApplicationByType(appType).getAid();
9083 } catch (Exception e) {
9084 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
9085 }
9086 return aid;
9087 } finally {
9088 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07009089 }
Youhan Wange64578a2016-05-02 15:32:42 -07009090 }
9091
Youhan Wang4001d252016-05-11 10:29:41 -07009092 /**
9093 * Return the Electronic Serial Number.
9094 *
9095 * @param subId the subscription ID that this request applies to.
9096 * @return ESN or null if error.
9097 */
9098 @Override
9099 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009100 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07009101 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009102
9103 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07009104 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009105 if (phone == null) {
9106 return null;
9107 }
9108 String esn = null;
9109 try {
9110 esn = phone.getEsn();
9111 } catch (Exception e) {
9112 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
9113 }
9114 return esn;
9115 } finally {
9116 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07009117 }
Youhan Wang4001d252016-05-11 10:29:41 -07009118 }
9119
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009120 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009121 * Return the Preferred Roaming List Version.
9122 *
9123 * @param subId the subscription ID that this request applies to.
9124 * @return PRLVersion or null if error.
9125 */
9126 @Override
9127 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009128 enforceReadPrivilegedPermission("getCdmaPrlVersion");
joonhunshin4ac60942023-11-15 15:23:39 +00009129
9130 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9131 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion");
9132
Youhan Wang66ad5d72016-07-18 17:56:58 -07009133 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009134
9135 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009136 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009137 if (phone == null) {
9138 return null;
9139 }
9140 String cdmaPrlVersion = null;
9141 try {
9142 cdmaPrlVersion = phone.getCdmaPrlVersion();
9143 } catch (Exception e) {
9144 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9145 }
9146 return cdmaPrlVersion;
9147 } finally {
9148 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009149 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009150 }
9151
9152 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009153 * Get snapshot of Telephony histograms
9154 * @return List of Telephony histograms
9155 * @hide
9156 */
9157 @Override
9158 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009159 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9160 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009161
9162 final long identity = Binder.clearCallingIdentity();
9163 try {
9164 return RIL.getTelephonyRILTimingHistograms();
9165 } finally {
9166 Binder.restoreCallingIdentity(identity);
9167 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009168 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009169
9170 /**
9171 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009172 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9173 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009174 * Require system privileges. In the future we may add this to carrier APIs.
9175 *
Michele Berionne482f8202018-11-27 18:57:59 -08009176 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009177 */
9178 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009179 @TelephonyManager.SetCarrierRestrictionResult
9180 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009181 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009182
9183 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9184 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers");
9185
vagdeviaf9a5b92018-08-15 16:01:53 -07009186 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009187
Michele Berionne482f8202018-11-27 18:57:59 -08009188 if (carrierRestrictionRules == null) {
9189 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009190 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009191
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009192 final long identity = Binder.clearCallingIdentity();
9193 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009194 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009195 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009196 } finally {
9197 Binder.restoreCallingIdentity(identity);
9198 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009199 }
9200
9201 /**
9202 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009203 * Get the allowed carrier list and the excluded carrier list, including the priority between
9204 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009205 * Require system privileges. In the future we may add this to carrier APIs.
9206 *
Michele Berionne482f8202018-11-27 18:57:59 -08009207 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009208 */
9209 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009210 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009211 enforceReadPrivilegedPermission("getAllowedCarriers");
joonhunshin4ac60942023-11-15 15:23:39 +00009212
9213 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9214 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers");
9215
vagdeviaf9a5b92018-08-15 16:01:53 -07009216 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009217
9218 final long identity = Binder.clearCallingIdentity();
9219 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009220 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9221 if (response instanceof CarrierRestrictionRules) {
9222 return (CarrierRestrictionRules) response;
9223 }
9224 // Response is an Exception of some kind,
9225 // which is signalled to the user as a NULL retval
9226 return null;
9227 } catch (Exception e) {
9228 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9229 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009230 } finally {
9231 Binder.restoreCallingIdentity(identity);
9232 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009233 }
9234
fionaxu59545b42016-05-25 15:53:37 -07009235 /**
arunvoddud7401012022-12-15 16:08:12 +00009236 * Fetches the carrier restriction status of the device and sends the status to the caller
9237 * through the callback.
9238 *
9239 * @param callback The callback that will be used to send the result.
9240 * @throws SecurityException if the caller does not have the required permission/privileges or
9241 * the caller is not allowlisted.
9242 */
9243 @Override
9244 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
9245 enforceReadPermission("getCarrierRestrictionStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00009246
9247 enforceTelephonyFeatureWithException(packageName,
9248 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierRestrictionStatus");
9249
arunvoddud7401012022-12-15 16:08:12 +00009250 int carrierId = validateCallerAndGetCarrierId(packageName);
9251 if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) {
9252 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9253 throw new SecurityException("Not an authorized caller");
9254 }
9255 final long identity = Binder.clearCallingIdentity();
9256 try {
9257 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
9258 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId);
9259 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9260 } finally {
9261 Binder.restoreCallingIdentity(identity);
9262 }
9263 }
9264
arunvoddu567f2b42023-04-25 17:22:00 +00009265 @Override
9266 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
9267 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
9268 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9269 return allowListInfo.getShaIdList(pkgName, carrierId);
9270 }
9271
arunvoddud7401012022-12-15 16:08:12 +00009272 @VisibleForTesting
9273 public int validateCallerAndGetCarrierId(String packageName) {
9274 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9275 return allowListInfo.validateCallerAndGetCarrierId(packageName);
9276 }
9277
9278 /**
fionaxu59545b42016-05-25 15:53:37 -07009279 * Action set from carrier signalling broadcast receivers to enable/disable radio
9280 * @param subId the subscription ID that this action applies to.
9281 * @param enabled control enable or disable radio.
9282 * {@hide}
9283 */
9284 @Override
9285 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9286 enforceModifyPermission();
9287 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009288
9289 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009290 if (phone == null) {
9291 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9292 return;
9293 }
9294 try {
9295 phone.carrierActionSetRadioEnabled(enabled);
9296 } catch (Exception e) {
9297 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009298 } finally {
9299 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009300 }
9301 }
9302
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009303 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009304 * Enable or disable Voice over NR (VoNR)
9305 * @param subId the subscription ID that this action applies to.
9306 * @param enabled enable or disable VoNR.
9307 * @return operation result.
9308 */
9309 @Override
9310 public int setVoNrEnabled(int subId, boolean enabled) {
9311 enforceModifyPermission();
9312 final Phone phone = getPhone(subId);
9313
9314 final long identity = Binder.clearCallingIdentity();
9315 if (phone == null) {
9316 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9317 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9318 }
9319
9320 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9321 try {
9322 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9323 workSource);
9324 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009325
9326 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9327 if (DBG) {
9328 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9329 }
9330 SubscriptionManager.setSubscriptionProperty(
9331 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9332 (enabled ? "1" : "0"));
9333 }
9334
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009335 return result;
9336 } finally {
9337 Binder.restoreCallingIdentity(identity);
9338 }
9339 }
9340
9341 /**
9342 * Is voice over NR enabled
9343 * @return true if VoNR is enabled else false
9344 */
9345 @Override
9346 public boolean isVoNrEnabled(int subId) {
9347 enforceReadPrivilegedPermission("isVoNrEnabled");
9348 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9349 final long identity = Binder.clearCallingIdentity();
9350 try {
9351 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9352 null, subId, workSource);
9353 if (DBG) log("isVoNrEnabled: " + isEnabled);
9354 return isEnabled;
9355 } finally {
9356 Binder.restoreCallingIdentity(identity);
9357 }
9358 }
9359
9360 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009361 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9362 * network status based on which carrier apps could apply actions accordingly,
9363 * enable/disable default url handler for example.
9364 *
9365 * @param subId the subscription ID that this action applies to.
9366 * @param report control start/stop reporting the default network status.
9367 * {@hide}
9368 */
9369 @Override
9370 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9371 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009372
9373 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9374 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
9375 "carrierActionReportDefaultNetworkStatus");
9376
fionaxu8da9cb12017-05-23 15:02:46 -07009377 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009378
9379 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009380 if (phone == null) {
9381 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9382 return;
9383 }
9384 try {
9385 phone.carrierActionReportDefaultNetworkStatus(report);
9386 } catch (Exception e) {
9387 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009388 } finally {
9389 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009390 }
9391 }
9392
9393 /**
fionaxud9622282017-07-17 17:51:30 -07009394 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9395 * @param subId the subscription ID that this action applies to.
9396 * {@hide}
9397 */
9398 @Override
9399 public void carrierActionResetAll(int subId) {
9400 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009401
9402 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9403 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll");
9404
fionaxud9622282017-07-17 17:51:30 -07009405 final Phone phone = getPhone(subId);
9406 if (phone == null) {
9407 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9408 return;
9409 }
9410 try {
9411 phone.carrierActionResetAll();
9412 } catch (Exception e) {
9413 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9414 }
9415 }
9416
9417 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009418 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9419 * bug report is being generated.
9420 */
9421 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009422 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009423 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9424 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009425 writer.println("Permission Denial: can't dump Phone from pid="
9426 + Binder.getCallingPid()
9427 + ", uid=" + Binder.getCallingUid()
9428 + "without permission "
9429 + android.Manifest.permission.DUMP);
9430 return;
9431 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009432 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009433 }
Jack Yueb89b242016-06-22 13:27:47 -07009434
Brad Ebingerdac2f002018-04-03 15:17:52 -07009435 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009436 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9437 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9438 @NonNull String[] args) {
9439 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9440 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009441 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009442 }
9443
Jack Yueb89b242016-06-22 13:27:47 -07009444 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009445 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009446 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009447 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009448 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009449 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009450 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009451 */
9452 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009453 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009454 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009455 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9456 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9457 try {
9458 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009459 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009460 } catch (SecurityException se) {
9461 enforceModifyPermission();
9462 }
9463 } else {
9464 enforceModifyPermission();
9465 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009466
joonhunshin4ac60942023-11-15 15:23:39 +00009467 enforceTelephonyFeatureWithException(callingPackage,
9468 PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason");
9469
Nate Myren116695d2024-02-09 09:36:01 -08009470 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009471 final long identity = Binder.clearCallingIdentity();
9472 try {
Nate Myren116695d2024-02-09 09:36:01 -08009473 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
9474 && null != callingPackage && opEnableMobileDataByUser()) {
9475 mAppOps.noteOp(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER,
9476 callingUid, callingPackage, null, null);
9477 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009478 Phone phone = getPhone(subId);
9479 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009480 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9481 phone.carrierActionSetMeteredApnsEnabled(enabled);
9482 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07009483 phone.getDataSettingsManager().setDataEnabled(
9484 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009485 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009486 }
9487 } finally {
9488 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009489 }
9490 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009491
9492 /**
9493 * Get Client request stats
9494 * @return List of Client Request Stats
9495 * @hide
9496 */
9497 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009498 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9499 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009500 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009501 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009502 return null;
9503 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009504 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009505
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009506 final long identity = Binder.clearCallingIdentity();
9507 try {
9508 if (phone != null) {
9509 return phone.getClientRequestStats();
9510 }
9511
9512 return null;
9513 } finally {
9514 Binder.restoreCallingIdentity(identity);
9515 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009516 }
9517
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009518 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009519 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009520 if (uid == Process.ROOT_UID && packageName == null) {
9521 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9522 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9523 // exception. ROOT_UID seems not to have a valid package name returned by
9524 // PackageManager, so just fake it here to avoid issues when running telephony shell
9525 // commands that plumb through the RIL as root, like so:
9526 // $ adb root
9527 // $ adb shell cmd phone ...
9528 packageName = "root";
9529 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009530 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009531 }
Jack Yueb4124c2017-02-16 15:32:43 -08009532
9533 /**
Grace Chen70990072017-03-24 17:21:30 -07009534 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009535 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009536 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009537 * @param state State of SIM (power down, power up, pass through)
9538 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9539 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9540 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009541 *
9542 **/
9543 @Override
Grace Chen70990072017-03-24 17:21:30 -07009544 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009545 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009546
9547 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9548 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot");
9549
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009550 Phone phone = PhoneFactory.getPhone(slotIndex);
9551
vagdeviaf9a5b92018-08-15 16:01:53 -07009552 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9553
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009554 final long identity = Binder.clearCallingIdentity();
9555 try {
9556 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009557 phone.setSimPowerState(state, null, workSource);
9558 }
9559 } finally {
9560 Binder.restoreCallingIdentity(identity);
9561 }
9562 }
9563
9564 /**
9565 * Set SIM card power state.
9566 *
9567 * @param slotIndex SIM slot id.
9568 * @param state State of SIM (power down, power up, pass through)
9569 * @param callback callback to trigger after success or failure
9570 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9571 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9572 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9573 *
9574 **/
9575 @Override
9576 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9577 IIntegerConsumer callback) {
9578 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009579
9580 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9581 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
9582 "setSimPowerStateForSlotWithCallback");
9583
Jordan Liu109698e2020-11-24 14:50:34 -08009584 Phone phone = PhoneFactory.getPhone(slotIndex);
9585
9586 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9587
9588 final long identity = Binder.clearCallingIdentity();
9589 try {
9590 if (phone != null) {
9591 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9592 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009593 }
9594 } finally {
9595 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009596 }
9597 }
Shuo Qiandd210312017-04-12 22:11:33 +00009598
Tyler Gunn65d45c22017-06-05 11:22:26 -07009599 private boolean isUssdApiAllowed(int subId) {
9600 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009601 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009602 if (configManager == null) {
9603 return false;
9604 }
9605 PersistableBundle pb = configManager.getConfigForSubId(subId);
9606 if (pb == null) {
9607 return false;
9608 }
9609 return pb.getBoolean(
9610 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9611 }
9612
Shuo Qiandd210312017-04-12 22:11:33 +00009613 /**
Ling Mac28f0212023-03-24 16:07:15 -07009614 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00009615 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07009616 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00009617 */
goneil9c5f4872017-12-05 14:07:56 -08009618 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009619 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009620 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
joonhunshin4ac60942023-11-15 15:23:39 +00009621
9622 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9623 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode");
9624
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009625 final long identity = Binder.clearCallingIdentity();
9626 try {
Ling Mac28f0212023-03-24 16:07:15 -07009627 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009628 } finally {
9629 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009630 }
9631 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009632
9633 /**
9634 * Get the current signal strength information for the given subscription.
9635 * Because this information is not updated when the device is in a low power state
9636 * it should not be relied-upon to be current.
9637 * @param subId Subscription index
9638 * @return the most recent cached signal strength info from the modem
9639 */
9640 @Override
9641 public SignalStrength getSignalStrength(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00009642 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9643 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength");
9644
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009645 final long identity = Binder.clearCallingIdentity();
9646 try {
9647 Phone p = getPhone(subId);
9648 if (p == null) {
9649 return null;
9650 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009651
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009652 return p.getSignalStrength();
9653 } finally {
9654 Binder.restoreCallingIdentity(identity);
9655 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009656 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009657
Pengquan Meng77b7f132018-08-22 14:49:57 -07009658 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009659 * Get the current modem radio state for the given slot.
9660 * @param slotIndex slot index.
9661 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009662 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009663 * @return the current radio power state from the modem
9664 */
9665 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009666 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009667 Phone phone = PhoneFactory.getPhone(slotIndex);
9668 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009669 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9670 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009671 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9672 }
9673
joonhunshin4ac60942023-11-15 15:23:39 +00009674 enforceTelephonyFeatureWithException(callingPackage,
9675 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState");
9676
Chen Xuf792fd62018-10-17 17:54:36 +00009677 final long identity = Binder.clearCallingIdentity();
9678 try {
9679 return phone.getRadioPowerState();
9680 } finally {
9681 Binder.restoreCallingIdentity(identity);
9682 }
9683 }
9684 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9685 }
9686
9687 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009688 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9689 *
9690 * <p>Requires one of the following permissions:
9691 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009692 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009693 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9694 * privileges.
9695 *
9696 * @param subId subscription id
9697 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9698 * {@code false}.
9699 */
9700 @Override
9701 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009702 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009703 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009704 try {
9705 mApp.enforceCallingOrSelfPermission(
9706 android.Manifest.permission.ACCESS_NETWORK_STATE,
9707 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009708 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009709 mApp.enforceCallingOrSelfPermission(
9710 permission.READ_BASIC_PHONE_STATE, functionName);
9711 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009712 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009713 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009714 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009715 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009716
joonhunshin4ac60942023-11-15 15:23:39 +00009717 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9718 PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled");
9719
Pengquan Menga1bb6272018-09-06 09:59:22 -07009720 boolean isEnabled = false;
9721 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009722 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009723 Phone phone = getPhone(subId);
9724 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009725 } finally {
9726 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009727 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009728 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009729 }
9730
9731
9732 /**
9733 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9734 *
9735 * <p> Requires permission:
9736 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9737 * privileges.
9738 *
9739 * @param subId subscription id
9740 * @param isEnabled {@code true} means enable, {@code false} means disable.
9741 */
9742 @Override
9743 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009744 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9745 mApp, subId, "setDataRoamingEnabled");
9746
joonhunshin4ac60942023-11-15 15:23:39 +00009747 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9748 PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled");
9749
Pengquan Menga1bb6272018-09-06 09:59:22 -07009750 final long identity = Binder.clearCallingIdentity();
9751 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009752 Phone phone = getPhone(subId);
9753 if (phone != null) {
9754 phone.setDataRoamingEnabled(isEnabled);
9755 }
9756 } finally {
9757 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009758 }
9759 }
9760
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009761 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009762 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009763 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009764 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009765 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009766
joonhunshin4ac60942023-11-15 15:23:39 +00009767 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9768 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed");
9769
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009770 boolean isAllowed = true;
9771 final long identity = Binder.clearCallingIdentity();
9772 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009773 Phone phone = getPhone(subId);
9774 if (phone != null) {
9775 isAllowed = phone.isCspPlmnEnabled();
9776 }
9777 } finally {
9778 Binder.restoreCallingIdentity(identity);
9779 }
9780 return isAllowed;
9781 }
9782
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009783 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9784 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009785 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009786 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009787 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009788 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9789 if (phone == null) {
9790 return false;
9791 }
9792 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9793 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9794 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009795 }
9796
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009797 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009798 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009799 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009800 mApp.getSystemService(AppOpsManager.class)
9801 .checkPackage(Binder.getCallingUid(), callingPackage);
9802
Jordan Liu1e142fc2019-04-22 15:10:43 -07009803 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009804 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009805 try {
9806 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009807 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009808 } catch (SecurityException e) {
9809 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9810 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009811 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009812 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009813 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009814 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009815 }
joonhunshin4ac60942023-11-15 15:23:39 +00009816
9817 enforceTelephonyFeatureWithException(callingPackage,
9818 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo");
9819
sandeepjsb6c87872021-09-27 15:34:44 +00009820 // checking compatibility, if calling app's target SDK is T and beyond.
9821 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9822 Binder.getCallingUid())) {
9823 isIccIdAccessRestricted = true;
9824 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009825 final long identity = Binder.clearCallingIdentity();
9826 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009827 UiccController uiccController = UiccController.getInstance();
9828 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009829 if (hasReadPermission) {
9830 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009831 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009832
9833 // Remove private info if the caller doesn't have access
9834 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9835 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009836 //setting the value after compatibility check
9837 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009838 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9839 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009840 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009841 if (card == null) {
9842 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009843 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009844 continue;
9845 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009846 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9847 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009848 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009849 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009850 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009851 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9852 for (UiccPortInfo portInfo : portInfos) {
9853 UiccPort port = uiccController.getUiccPortForSlot(
9854 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9855 if (port == null) {
9856 // assume no access if port is null
9857 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9858 continue;
9859 }
9860 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9861 uiccPortInfos.add(portInfo);
9862 } else {
9863 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9864 }
9865 }
9866 filteredInfos.add(new UiccCardInfo(
9867 cardInfo.isEuicc(),
9868 cardInfo.getCardId(),
9869 null,
9870 cardInfo.getPhysicalSlotIndex(),
9871 cardInfo.isRemovable(),
9872 cardInfo.isMultipleEnabledProfilesSupported(),
9873 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009874 }
9875 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009876 } finally {
9877 Binder.restoreCallingIdentity(identity);
9878 }
9879 }
9880
sandeepjsb6c87872021-09-27 15:34:44 +00009881 /**
9882 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9883 * generally private and require carrier privileges to view.
9884 *
9885 * @hide
9886 */
9887 @NonNull
9888 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9889 List<UiccPortInfo> portinfo = new ArrayList<>();
9890 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9891 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9892 }
9893 return new UiccCardInfo(
9894 cardInfo.isEuicc(),
9895 cardInfo.getCardId(),
9896 null,
9897 cardInfo.getPhysicalSlotIndex(),
9898 cardInfo.isRemovable(),
9899 cardInfo.isMultipleEnabledProfilesSupported(),
9900 portinfo
9901 );
9902 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009903
sandeepjsb6c87872021-09-27 15:34:44 +00009904 /**
9905 * @hide
9906 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9907 * These values are generally private and require carrier privileges to view.
9908 */
9909 @NonNull
9910 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9911 return new UiccPortInfo(
9912 UiccPortInfo.ICCID_REDACTED,
9913 portInfo.getPortIndex(),
9914 portInfo.getLogicalSlotIndex(),
9915 portInfo.isActive()
9916 );
9917 }
9918 @Override
9919 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009920 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009921 mApp.getSystemService(AppOpsManager.class)
9922 .checkPackage(Binder.getCallingUid(), callingPackage);
9923
sandeepjsb6c87872021-09-27 15:34:44 +00009924 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009925
Aman Guptaf3c90b32022-03-17 04:54:16 +00009926 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9927 // we are reading iccId which is PII data.
9928 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009929
joonhunshin4ac60942023-11-15 15:23:39 +00009930 enforceTelephonyFeatureWithException(callingPackage,
9931 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo");
9932
sandeepjsb6c87872021-09-27 15:34:44 +00009933 // checking compatibility, if calling app's target SDK is T and beyond.
9934 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9935 Binder.getCallingUid())) {
9936 isLogicalSlotAccessRestricted = true;
9937 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009938 final long identity = Binder.clearCallingIdentity();
9939 try {
9940 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009941 if (slots == null || slots.length == 0) {
9942 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009943 return null;
9944 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009945 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9946 for (int i = 0; i < slots.length; i++) {
9947 UiccSlot slot = slots[i];
9948 if (slot == null) {
9949 continue;
9950 }
9951
Jordan Liu7be7e652019-05-06 18:55:02 +00009952 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009953 UiccCard card = slot.getUiccCard();
9954 if (card != null) {
9955 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009956 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009957 cardId = slot.getEid();
9958 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009959 // If cardId is null, use iccId of default port as cardId.
9960 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009961 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009962 }
9963
Jordan Liu857451f2019-05-09 16:35:35 -07009964 if (cardId != null) {
9965 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9966 // if cardId is an EID, it's all digits so this is fine
9967 cardId = IccUtils.stripTrailingFs(cardId);
9968 }
9969
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009970 int cardState = 0;
9971 switch (slot.getCardState()) {
9972 case CARDSTATE_ABSENT:
9973 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9974 break;
9975 case CARDSTATE_PRESENT:
9976 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9977 break;
9978 case CARDSTATE_ERROR:
9979 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9980 break;
9981 case CARDSTATE_RESTRICTED:
9982 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9983 break;
9984 default:
9985 break;
9986
9987 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009988 List<UiccPortInfo> portInfos = new ArrayList<>();
9989 int[] portIndexes = slot.getPortList();
9990 for (int portIdx : portIndexes) {
9991 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009992 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009993 portInfos.add(new UiccPortInfo(iccId, portIdx,
9994 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009995 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009996 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009997 slot.isEuicc(),
9998 cardId,
9999 cardState,
Jordan Liua2619582019-02-14 12:56:40 -080010000 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010001 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +000010002 //setting the value after compatibility check
10003 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010004 }
10005 return infos;
10006 } finally {
10007 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -070010008 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010009 }
10010
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010011 /* Returns null if doesn't have read permission or carrier privilege access. */
10012 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
10013 boolean hasReadPermission) {
10014 String iccId = slot.getIccId(portIndex);
10015 if (hasReadPermission) { // if has read permission
10016 return iccId;
10017 } else {
10018 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
10019 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
10020 // if no read permission, checking carrier privilege access
10021 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
10022 return iccId;
10023 }
10024 }
10025 }
10026 // No read permission or carrier privilege access.
10027 return UiccPortInfo.ICCID_REDACTED;
10028 }
10029
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010030 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010031 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010032 public boolean switchSlots(int[] physicalSlots) {
10033 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010034
joonhunshin4ac60942023-11-15 15:23:39 +000010035 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10036 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots");
10037
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010038 final long identity = Binder.clearCallingIdentity();
10039 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010040 List<UiccSlotMapping> slotMappings = new ArrayList<>();
10041 for (int i = 0; i < physicalSlots.length; i++) {
10042 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
10043 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
10044 physicalSlots[i], i));
10045 }
10046 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010047 } finally {
10048 Binder.restoreCallingIdentity(identity);
10049 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010050 }
Jack Yu4c988042018-02-27 15:30:01 -080010051
10052 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010053 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
10054 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
10055 enforceModifyPermission();
10056
joonhunshin4ac60942023-11-15 15:23:39 +000010057 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10058 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping");
10059
sandeepjsb6c87872021-09-27 15:34:44 +000010060 final long identity = Binder.clearCallingIdentity();
10061 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010062 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +000010063 } finally {
10064 Binder.restoreCallingIdentity(identity);
10065 }
10066 }
10067
10068 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -080010069 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
joonhunshin4ac60942023-11-15 15:23:39 +000010070 enforceTelephonyFeatureWithException(callingPackage,
10071 PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc");
10072
Jordan Liu7de49fa2018-12-06 14:48:49 -080010073 final long identity = Binder.clearCallingIdentity();
10074 try {
10075 return UiccController.getInstance().getCardIdForDefaultEuicc();
10076 } finally {
10077 Binder.restoreCallingIdentity(identity);
10078 }
10079 }
10080
Pengquan Meng85728fb2018-03-12 16:31:21 -070010081 /**
goneil47ffb6e2018-04-06 15:40:58 -070010082 * A test API to reload the UICC profile.
10083 *
10084 * <p>Requires that the calling app has permission
10085 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
10086 * @hide
10087 */
10088 @Override
10089 public void refreshUiccProfile(int subId) {
10090 enforceModifyPermission();
10091
10092 final long identity = Binder.clearCallingIdentity();
10093 try {
10094 Phone phone = getPhone(subId);
10095 if (phone == null) {
10096 return;
10097 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010098 UiccPort uiccPort = phone.getUiccPort();
10099 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -070010100 return;
10101 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010102 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -070010103 if (uiccProfile == null) {
10104 return;
10105 }
10106 uiccProfile.refresh();
10107 } finally {
10108 Binder.restoreCallingIdentity(identity);
10109 }
10110 }
10111
10112 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010113 * Returns false if the mobile data is disabled by default, otherwise return true.
10114 */
10115 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010116 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010117 }
10118
10119 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010120 * Returns the default network type for the given {@code subId}, if the default network type is
10121 * not set, return {@link Phone#PREFERRED_NT_MODE}.
10122 */
10123 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010124 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -080010125 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +090010126 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
10127 return list.get(phoneId);
10128 }
10129 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -070010130 }
fionaxua13278b2018-03-21 00:08:13 -070010131
10132 @Override
10133 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -070010134 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -070010135 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010136
10137 final long identity = Binder.clearCallingIdentity();
10138 try {
10139 final Phone phone = getPhone(subId);
10140 if (phone == null) {
10141 loge("setCarrierTestOverride fails with invalid subId: " + subId);
10142 return;
10143 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -080010144 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10145 if (cpt != null) {
10146 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
10147 }
10148 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -070010149 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
10150 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -070010151 if (carrierPrivilegeRules == null) {
10152 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
10153 } else {
10154 mCarrierPrivilegeTestOverrideSubIds.add(subId);
10155 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010156 } finally {
10157 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010158 }
fionaxua13278b2018-03-21 00:08:13 -070010159 }
10160
10161 @Override
Benedict Wong66477622023-02-03 23:30:57 +000010162 public void setCarrierServicePackageOverride(
10163 int subId, String carrierServicePackage, String callingPackage) {
10164 TelephonyPermissions.enforceShellOnly(
10165 Binder.getCallingUid(), "setCarrierServicePackageOverride");
10166
Benedict Wong66477622023-02-03 23:30:57 +000010167 final long identity = Binder.clearCallingIdentity();
10168 try {
10169 final Phone phone = getPhone(subId);
10170 if (phone == null || phone.getSubId() != subId) {
10171 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
10172 throw new IllegalArgumentException("No phone for subid");
10173 }
10174 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10175 if (cpt == null) {
10176 loge("setCarrierServicePackageOverride failed with no CPT for phone");
10177 throw new IllegalStateException("No CPT for phone");
10178 }
10179 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
10180 } finally {
10181 Binder.restoreCallingIdentity(identity);
10182 }
10183 }
10184
10185 @Override
fionaxua13278b2018-03-21 00:08:13 -070010186 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -070010187 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010188
10189 final long identity = Binder.clearCallingIdentity();
10190 try {
10191 final Phone phone = getPhone(subId);
10192 if (phone == null) {
10193 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
10194 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
10195 }
10196 return phone.getCarrierIdListVersion();
10197 } finally {
10198 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010199 }
fionaxua13278b2018-03-21 00:08:13 -070010200 }
Malcolm Chen2c63d402018-08-14 16:00:53 -070010201
10202 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010203 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
10204 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010205 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010206 mApp, subId, callingPackage, callingFeatureId,
10207 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010208 return -1;
10209 }
10210
10211 final long identity = Binder.clearCallingIdentity();
10212 try {
10213 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10214 } finally {
10215 Binder.restoreCallingIdentity(identity);
10216 }
10217 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010218
10219 @Override
10220 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +080010221 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010222 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010223 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010224
joonhunshin4ac60942023-11-15 15:23:39 +000010225 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10226 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode");
10227
Pengquan Menga1bb6272018-09-06 09:59:22 -070010228 final long identity = Binder.clearCallingIdentity();
10229 try {
10230 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10231 } finally {
10232 Binder.restoreCallingIdentity(identity);
10233 }
10234 }
10235
10236 @Override
10237 public boolean setCdmaRoamingMode(int subId, int mode) {
10238 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10239 mApp, subId, "setCdmaRoamingMode");
10240
joonhunshin4ac60942023-11-15 15:23:39 +000010241 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10242 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode");
10243
Pengquan Menga1bb6272018-09-06 09:59:22 -070010244 final long identity = Binder.clearCallingIdentity();
10245 try {
10246 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10247 } finally {
10248 Binder.restoreCallingIdentity(identity);
10249 }
10250 }
10251
10252 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010253 public int getCdmaSubscriptionMode(int subId) {
10254 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010255 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010256 mApp, subId, "getCdmaSubscriptionMode");
10257
joonhunshin4ac60942023-11-15 15:23:39 +000010258 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10259 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode");
10260
Sarah Chinbaab1432020-10-28 13:46:24 -070010261 final long identity = Binder.clearCallingIdentity();
10262 try {
10263 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10264 } finally {
10265 Binder.restoreCallingIdentity(identity);
10266 }
10267 }
10268
10269 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010270 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10271 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10272 mApp, subId, "setCdmaSubscriptionMode");
10273
joonhunshin4ac60942023-11-15 15:23:39 +000010274 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10275 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode");
10276
Pengquan Menga1bb6272018-09-06 09:59:22 -070010277 final long identity = Binder.clearCallingIdentity();
10278 try {
10279 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10280 } finally {
10281 Binder.restoreCallingIdentity(identity);
10282 }
10283 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010284
sqianc5eccab2018-10-19 18:46:41 -070010285 @Override
sqian8c685422019-02-22 15:55:18 -080010286 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010287 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010288 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010289 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10290 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010291 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10292 }
joonhunshin4ac60942023-11-15 15:23:39 +000010293
10294 enforceTelephonyFeatureWithException(callingPackage,
10295 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList");
10296
sqian11b7a0e2018-12-05 18:48:28 -080010297 final long identity = Binder.clearCallingIdentity();
10298 try {
sqian854d44b2018-12-12 16:48:18 -080010299 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10300 for (Phone phone: PhoneFactory.getPhones()) {
10301 if (phone.getEmergencyNumberTracker() != null
10302 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10303 emergencyNumberListInternal.put(
10304 phone.getSubId(),
10305 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10306 }
sqian11b7a0e2018-12-05 18:48:28 -080010307 }
sqian854d44b2018-12-12 16:48:18 -080010308 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010309 } finally {
10310 Binder.restoreCallingIdentity(identity);
10311 }
sqianc5eccab2018-10-19 18:46:41 -070010312 }
10313
10314 @Override
sqian8c685422019-02-22 15:55:18 -080010315 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010316 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010317 if (!exactMatch) {
10318 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010319 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010320 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010321 }
joonhunshin4ac60942023-11-15 15:23:39 +000010322
10323 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10324 PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber");
10325
sqian11b7a0e2018-12-05 18:48:28 -080010326 final long identity = Binder.clearCallingIdentity();
10327 try {
sqian854d44b2018-12-12 16:48:18 -080010328 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010329 //Note: we ignore passed in param exactMatch. We can remove it once
10330 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010331 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010332 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010333 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010334 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010335 }
sqian11b7a0e2018-12-05 18:48:28 -080010336 }
10337 return false;
10338 } finally {
10339 Binder.restoreCallingIdentity(identity);
10340 }
10341 }
10342
sqianf4ca7ed2019-01-15 18:32:07 -080010343 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010344 * Start emergency callback mode for GsmCdmaPhone for testing.
10345 */
10346 @Override
10347 public void startEmergencyCallbackMode() {
10348 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10349 "startEmergencyCallbackMode");
10350 enforceModifyPermission();
10351 final long identity = Binder.clearCallingIdentity();
10352 try {
10353 for (Phone phone : PhoneFactory.getPhones()) {
10354 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10355 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10356 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10357 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10358 gsmCdmaPhone.obtainMessage(
10359 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10360 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10361 }
10362 }
10363 } finally {
10364 Binder.restoreCallingIdentity(identity);
10365 }
10366 }
10367
10368 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010369 * Update emergency number list for test mode.
10370 */
10371 @Override
10372 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10373 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10374 "updateEmergencyNumberListTestMode");
10375
10376 final long identity = Binder.clearCallingIdentity();
10377 try {
10378 for (Phone phone: PhoneFactory.getPhones()) {
10379 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10380 if (tracker != null) {
10381 tracker.executeEmergencyNumberTestModeCommand(action, num);
10382 }
10383 }
10384 } finally {
10385 Binder.restoreCallingIdentity(identity);
10386 }
10387 }
10388
10389 /**
10390 * Get the full emergency number list for test mode.
10391 */
10392 @Override
10393 public List<String> getEmergencyNumberListTestMode() {
10394 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10395 "getEmergencyNumberListTestMode");
10396
10397 final long identity = Binder.clearCallingIdentity();
10398 try {
10399 Set<String> emergencyNumbers = new HashSet<>();
10400 for (Phone phone: PhoneFactory.getPhones()) {
10401 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10402 if (tracker != null) {
10403 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10404 emergencyNumbers.add(num.getNumber());
10405 }
10406 }
10407 }
10408 return new ArrayList<>(emergencyNumbers);
10409 } finally {
10410 Binder.restoreCallingIdentity(identity);
10411 }
10412 }
10413
chen xud6b45bd2018-10-30 22:27:10 -070010414 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010415 public int getEmergencyNumberDbVersion(int subId) {
10416 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10417
joonhunshin4ac60942023-11-15 15:23:39 +000010418 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10419 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion");
10420
Shuo Qian3b6ee772019-11-13 17:43:31 -080010421 final long identity = Binder.clearCallingIdentity();
10422 try {
10423 final Phone phone = getPhone(subId);
10424 if (phone == null) {
10425 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10426 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10427 }
10428 return phone.getEmergencyNumberDbVersion();
10429 } finally {
10430 Binder.restoreCallingIdentity(identity);
10431 }
10432 }
10433
10434 @Override
10435 public void notifyOtaEmergencyNumberDbInstalled() {
10436 enforceModifyPermission();
10437
joonhunshin4ac60942023-11-15 15:23:39 +000010438 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10439 PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled");
10440
Shuo Qian3b6ee772019-11-13 17:43:31 -080010441 final long identity = Binder.clearCallingIdentity();
10442 try {
10443 for (Phone phone: PhoneFactory.getPhones()) {
10444 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10445 if (tracker != null) {
10446 tracker.updateOtaEmergencyNumberDatabase();
10447 }
10448 }
10449 } finally {
10450 Binder.restoreCallingIdentity(identity);
10451 }
10452 }
10453
10454 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010455 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010456 enforceActiveEmergencySessionPermission();
10457
joonhunshin4ac60942023-11-15 15:23:39 +000010458 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10459 PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath");
10460
Shuo Qian3b6ee772019-11-13 17:43:31 -080010461 final long identity = Binder.clearCallingIdentity();
10462 try {
10463 for (Phone phone: PhoneFactory.getPhones()) {
10464 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10465 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010466 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10467 }
10468 }
10469 } finally {
10470 Binder.restoreCallingIdentity(identity);
10471 }
10472 }
10473
10474 @Override
10475 public void resetOtaEmergencyNumberDbFilePath() {
10476 enforceActiveEmergencySessionPermission();
10477
joonhunshin4ac60942023-11-15 15:23:39 +000010478 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10479 PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath");
10480
Shuo Qianc373f112020-03-05 17:55:34 -080010481 final long identity = Binder.clearCallingIdentity();
10482 try {
10483 for (Phone phone: PhoneFactory.getPhones()) {
10484 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10485 if (tracker != null) {
10486 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010487 }
10488 }
10489 } finally {
10490 Binder.restoreCallingIdentity(identity);
10491 }
10492 }
10493
10494 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010495 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10496 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10497 Phone phone = getPhone(subId);
10498 if (phone == null) {
10499 return null;
10500 }
10501 final long identity = Binder.clearCallingIdentity();
10502 try {
10503 UiccProfile profile = UiccController.getInstance()
10504 .getUiccProfileForPhone(phone.getPhoneId());
10505 if (profile != null) {
10506 return profile.getCertsFromCarrierPrivilegeAccessRules();
10507 }
10508 } finally {
10509 Binder.restoreCallingIdentity(identity);
10510 }
10511 return null;
10512 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010513
10514 /**
10515 * Enable or disable a modem stack.
10516 */
10517 @Override
10518 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10519 enforceModifyPermission();
10520
joonhunshin4ac60942023-11-15 15:23:39 +000010521 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10522 PackageManager.FEATURE_TELEPHONY, "enableModemForSlot");
10523
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010524 final long identity = Binder.clearCallingIdentity();
10525 try {
10526 Phone phone = PhoneFactory.getPhone(slotIndex);
10527 if (phone == null) {
10528 return false;
10529 } else {
10530 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10531 }
10532 } finally {
10533 Binder.restoreCallingIdentity(identity);
10534 }
10535 }
Michelecea4cf22018-12-21 15:00:11 -080010536
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010537 /**
10538 * Whether a modem stack is enabled or not.
10539 */
10540 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010541 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10542 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010543 Phone phone = PhoneFactory.getPhone(slotIndex);
10544 if (phone == null) return false;
10545
10546 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010547 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10548 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010549 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10550 }
10551
joonhunshin4ac60942023-11-15 15:23:39 +000010552 enforceTelephonyFeatureWithException(callingPackage,
10553 PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot");
10554
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010555 final long identity = Binder.clearCallingIdentity();
10556 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010557 try {
10558 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10559 } catch (NoSuchElementException ex) {
10560 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10561 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010562 } finally {
10563 Binder.restoreCallingIdentity(identity);
10564 }
10565 }
10566
Michelecea4cf22018-12-21 15:00:11 -080010567 @Override
Michele0ea7d782019-03-19 14:58:42 -070010568 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010569 enforceModifyPermission();
10570
joonhunshin4ac60942023-11-15 15:23:39 +000010571 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10572 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction");
10573
Michelecea4cf22018-12-21 15:00:11 -080010574 final long identity = Binder.clearCallingIdentity();
10575 try {
10576 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010577 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010578 .commit();
10579 } finally {
10580 Binder.restoreCallingIdentity(identity);
10581 }
10582 }
10583
10584 @Override
Michele0ea7d782019-03-19 14:58:42 -070010585 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010586 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010587 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010588 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10589 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010590 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010591 }
Michelecea4cf22018-12-21 15:00:11 -080010592
joonhunshin4ac60942023-11-15 15:23:39 +000010593 enforceTelephonyFeatureWithException(callingPackage,
10594 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported");
10595
Michelecea4cf22018-12-21 15:00:11 -080010596 final long identity = Binder.clearCallingIdentity();
10597 try {
Michele0ea7d782019-03-19 14:58:42 -070010598 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010599 } finally {
10600 Binder.restoreCallingIdentity(identity);
10601 }
10602 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010603
Michele0ea7d782019-03-19 14:58:42 -070010604 @TelephonyManager.IsMultiSimSupportedResult
10605 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010606 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10607 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10608 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010609 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10610 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010611 }
10612 // Check if the hardware supports multisim functionality. If usage of multisim is not
10613 // supported by the modem, indicate that it is restricted.
10614 PhoneCapability staticCapability =
10615 mPhoneConfigurationManager.getStaticPhoneCapability();
10616 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010617 loge("isMultiSimSupportedInternal: no static configuration available");
10618 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010619 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010620 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010621 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10622 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010623 }
10624 // Check if support of multiple SIMs is restricted by carrier
10625 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010626 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010627 }
10628
Michele0ea7d782019-03-19 14:58:42 -070010629 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010630 }
10631
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010632 /**
10633 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010634 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10635 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10636 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010637 * @param numOfSims number of active sims we want to switch to
10638 */
10639 @Override
10640 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010641 if (numOfSims == 1) {
10642 enforceModifyPermission();
10643 } else {
10644 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10645 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10646 }
joonhunshin4ac60942023-11-15 15:23:39 +000010647
10648 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10649 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig");
10650
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010651 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010652
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010653 try {
Michele30b57b22019-03-01 12:01:14 -080010654 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010655 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010656 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10657 return;
10658 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010659 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10660 } finally {
10661 Binder.restoreCallingIdentity(identity);
10662 }
10663 }
10664
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010665 @Override
10666 public boolean isApplicationOnUicc(int subId, int appType) {
10667 enforceReadPrivilegedPermission("isApplicationOnUicc");
joonhunshin4ac60942023-11-15 15:23:39 +000010668
10669 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10670 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc");
10671
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010672 Phone phone = getPhone(subId);
10673 if (phone == null) {
10674 return false;
10675 }
10676 final long identity = Binder.clearCallingIdentity();
10677 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010678 UiccPort uiccPort = phone.getUiccPort();
10679 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010680 return false;
10681 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010682 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010683 if (uiccProfile == null) {
10684 return false;
10685 }
10686 if (TelephonyManager.APPTYPE_SIM <= appType
10687 && appType <= TelephonyManager.APPTYPE_ISIM) {
10688 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10689 }
10690 return false;
10691 } finally {
10692 Binder.restoreCallingIdentity(identity);
10693 }
10694 }
10695
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010696 /**
chen xub4baa772019-04-03 10:23:41 -070010697 * Get whether making changes to modem configurations will trigger reboot.
10698 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010699 */
10700 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010701 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10702 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010703 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010704 mApp, subId, callingPackage, callingFeatureId,
10705 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010706 return false;
10707 }
joonhunshin4ac60942023-11-15 15:23:39 +000010708
10709 enforceTelephonyFeatureWithException(callingPackage,
10710 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
10711 "doesSwitchMultiSimConfigTriggerReboot");
10712
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010713 final long identity = Binder.clearCallingIdentity();
10714 try {
10715 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10716 } finally {
10717 Binder.restoreCallingIdentity(identity);
10718 }
10719 }
10720
Nathan Harold29f5f052019-02-15 13:41:57 -080010721 private void updateModemStateMetrics() {
10722 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10723 // TODO: check the state for each modem if the api is ready.
10724 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10725 }
10726
Pengquan Meng3889a572019-01-23 11:16:29 -080010727 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010728 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010729 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010730 // Verify that the callingPackage belongs to the calling UID
10731 mApp.getSystemService(AppOpsManager.class)
10732 .checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000010733
10734 enforceTelephonyFeatureWithException(callingPackage,
10735 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping");
10736
Pengquan Meng3889a572019-01-23 11:16:29 -080010737 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010738 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010739 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010740 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10741 if (slotInfos != null) {
10742 for (int i = 0; i < slotInfos.length; i++) {
10743 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10744 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10745 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10746 portInfo.getLogicalSlotIndex()));
10747 }
10748 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010749 }
10750 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010751 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010752 } finally {
10753 Binder.restoreCallingIdentity(identity);
10754 }
10755 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010756
10757 /**
10758 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010759 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010760 */
jimsunf9ec1622022-09-13 21:18:43 +080010761 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010762 @Override
10763 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010764 return getHalVersion(HAL_SERVICE_RADIO);
10765 }
10766
10767 /**
10768 * Get the HAL Version of a specific service
10769 */
10770 @Override
10771 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010772 Phone phone = getDefaultPhone();
10773 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010774 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010775 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10776 return hv.major * 100 + hv.minor;
10777 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010778
10779 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010780 * Get the current calling package name.
sangyun097dcf72024-01-04 10:35:49 +090010781 *
10782 * @return the current calling package name, or null if there is no known package.
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010783 */
10784 @Override
sangyun097dcf72024-01-04 10:35:49 +090010785 public @Nullable String getCurrentPackageName() {
10786 PackageManager pm = mApp.getPackageManager();
10787 String[] packageNames = pm == null ? null : pm.getPackagesForUid(Binder.getCallingUid());
10788 return packageNames == null ? null : packageNames[0];
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010789 }
10790
10791 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010792 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10793 * corresponding network requests on a subId.
10794 *
10795 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010796 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010797 * 2) APN is un-metered for this subscription, or
10798 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010799 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010800 *
10801 * @return whether data is allowed for a apn type.
10802 *
10803 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010804 */
10805 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010806 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010807 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10808 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010809
joonhunshin4ac60942023-11-15 15:23:39 +000010810 enforceTelephonyFeatureWithException(callingPackage,
10811 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn");
10812
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010813 // Now that all security checks passes, perform the operation as ourselves.
10814 final long identity = Binder.clearCallingIdentity();
10815 try {
10816 Phone phone = getPhone(subId);
10817 if (phone == null) return false;
10818
Jack Yu27422a52022-03-21 10:38:05 -070010819 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010820 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010821 isMetered = phone.getDataNetworkController().getDataConfigManager()
10822 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10823 phone.getServiceState().getDataRoaming());
10824 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010825 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010826 } finally {
10827 Binder.restoreCallingIdentity(identity);
10828 }
10829 }
10830
10831 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010832 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010833 enforceReadPrivilegedPermission("isApnMetered");
10834
joonhunshin4ac60942023-11-15 15:23:39 +000010835 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10836 PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered");
10837
Malcolm Chene5ad5792019-04-18 13:51:02 -070010838 // Now that all security checks passes, perform the operation as ourselves.
10839 final long identity = Binder.clearCallingIdentity();
10840 try {
10841 Phone phone = getPhone(subId);
10842 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010843 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10844 DataUtils.apnTypeToNetworkCapability(apnType),
10845 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010846 } finally {
10847 Binder.restoreCallingIdentity(identity);
10848 }
10849 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010850
10851 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010852 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10853 int subscriptionId, IBooleanConsumer resultCallback) {
10854 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +000010855
10856 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10857 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels");
10858
Hall Liu73f5d362020-01-20 13:42:00 -080010859 long token = Binder.clearCallingIdentity();
10860 try {
10861 Phone phone = getPhone(subscriptionId);
10862 if (phone == null) {
10863 try {
10864 if (resultCallback != null) {
10865 resultCallback.accept(false);
10866 }
10867 } catch (RemoteException e) {
10868 // ignore
10869 }
10870 return;
10871 }
10872 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10873 Pair.create(specifiers, (x) -> {
10874 try {
10875 if (resultCallback != null) {
10876 resultCallback.accept(x);
10877 }
10878 } catch (RemoteException e) {
10879 // ignore
10880 }
10881 });
10882 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10883 } finally {
10884 Binder.restoreCallingIdentity(token);
10885 }
10886 }
10887
10888 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010889 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10890 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010891 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010892 mApp, subId, "getSystemSelectionChannels");
joonhunshin4ac60942023-11-15 15:23:39 +000010893
10894 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10895 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels");
10896
Sarah Chin679c08a2020-11-18 13:39:35 -080010897 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10898 final long identity = Binder.clearCallingIdentity();
10899 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010900 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10901 if (result instanceof IllegalStateException) {
10902 throw (IllegalStateException) result;
10903 }
10904 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010905 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10906 return specifiers;
10907 } finally {
10908 Binder.restoreCallingIdentity(identity);
10909 }
10910 }
10911
10912 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010913 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010914 enforceReadPrivilegedPermission("isMvnoMatched");
joonhunshin4ac60942023-11-15 15:23:39 +000010915
10916 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10917 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched");
10918
Jack Yu8b766fc2022-03-21 09:42:33 -070010919 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010920 }
10921
10922 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010923 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10924 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010925 if (callingPackage == null) {
10926 callingPackage = getCurrentPackageName();
10927 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010928 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10929 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010930 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10931 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010932 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10933 }
10934 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10935 Intent intent = new Intent();
10936 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10937 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10938 // Bring up choose default SMS subscription dialog right now
10939 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10940 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10941 mApp.startActivity(intent);
10942 }
chen xud5ca2d52019-05-28 15:20:57 -070010943
10944 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010945 public void showSwitchToManagedProfileDialog() {
10946 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000010947 try {
10948 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
10949 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
10950 // for work telephony.
10951 Intent intent = new Intent(Intent.ACTION_SENDTO);
10952 intent.setData(Uri.parse("smsto:"));
10953 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10954 mApp.startActivity(intent);
10955 } catch (ActivityNotFoundException e) {
10956 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
10957 Intent intent = new Intent();
10958 intent.setClass(mApp, ErrorDialogActivity.class);
10959 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10960 mApp.startActivity(intent);
10961 }
Ayush Sharma787854b2022-12-12 14:55:02 +000010962 }
10963
10964 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010965 public String getMmsUAProfUrl(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000010966 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10967 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl");
10968
chen xud5ca2d52019-05-28 15:20:57 -070010969 //TODO investigate if this API should require proper permission check in R b/133791609
10970 final long identity = Binder.clearCallingIdentity();
10971 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010972 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10973 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10974 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10975 return carrierUAProfUrl;
10976 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010977 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10978 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010979 } finally {
10980 Binder.restoreCallingIdentity(identity);
10981 }
10982 }
10983
10984 @Override
10985 public String getMmsUserAgent(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000010986 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10987 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent");
10988
chen xud5ca2d52019-05-28 15:20:57 -070010989 //TODO investigate if this API should require proper permission check in R b/133791609
10990 final long identity = Binder.clearCallingIdentity();
10991 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010992 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10993 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10994 if (!TextUtils.isEmpty(carrierUserAgent)) {
10995 return carrierUserAgent;
10996 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010997 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10998 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010999 } finally {
11000 Binder.restoreCallingIdentity(identity);
11001 }
11002 }
Jack Yub07d4972019-05-28 16:12:25 -070011003
11004 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070011005 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
11006 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070011007
joonhunshin4ac60942023-11-15 15:23:39 +000011008 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11009 PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled");
11010
Jack Yub07d4972019-05-28 16:12:25 -070011011 final long identity = Binder.clearCallingIdentity();
11012 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011013 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070011014 if (phone == null) return false;
11015
Ling Maf188d502022-09-16 15:22:36 -070011016 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070011017 } finally {
11018 Binder.restoreCallingIdentity(identity);
11019 }
11020 }
11021
11022 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080011023 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070011024 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080011025 enforceModifyPermission();
11026
joonhunshin4ac60942023-11-15 15:23:39 +000011027 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11028 PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled");
11029
changbettyd5c246e2019-12-24 15:40:37 +080011030 final long identity = Binder.clearCallingIdentity();
11031 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011032 Phone phone = getPhone(subscriptionId);
11033 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080011034
Ling Maf188d502022-09-16 15:22:36 -070011035 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080011036 } finally {
11037 Binder.restoreCallingIdentity(identity);
11038 }
11039 }
11040
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011041 /**
Hall Liu746e03c2020-09-25 11:13:49 -070011042 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011043 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
11044 * otherwise.
11045 */
11046 @Override
11047 public void setCepEnabled(boolean isCepEnabled) {
11048 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
11049
11050 final long identity = Binder.clearCallingIdentity();
11051 try {
11052 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
11053 for (Phone phone : PhoneFactory.getPhones()) {
11054 Phone defaultPhone = phone.getImsPhone();
11055 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
11056 ImsPhone imsPhone = (ImsPhone) defaultPhone;
11057 ImsPhoneCallTracker imsPhoneCallTracker =
11058 (ImsPhoneCallTracker) imsPhone.getCallTracker();
11059 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
11060 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
11061 + imsPhone.getMsisdn());
11062 }
11063 }
11064 } finally {
11065 Binder.restoreCallingIdentity(identity);
11066 }
11067 }
allenwtsu46dcc572020-01-08 18:24:03 +080011068
11069 /**
11070 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
11071 *
11072 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
11073 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
11074 * before being read.
11075 */
11076 @Override
11077 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
11078 isCompressed) {
11079 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11080 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011081 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11082 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11083 }
joonhunshin4ac60942023-11-15 15:23:39 +000011084
11085 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11086 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11087 Binder.getCallingUserHandle())) {
11088 if (!isImsAvailableOnDevice()) {
11089 // ProvisioningManager can not handle ServiceSpecificException.
11090 // Throw the IllegalStateException and annotate ProvisioningManager.
11091 throw new IllegalStateException("IMS not available on device.");
11092 }
11093 } else {
11094 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11095 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11096 "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011097 }
11098
11099 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080011100 try {
Hui Wang761a6682020-10-31 05:12:53 +000011101 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
11102 } finally {
11103 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080011104 }
11105 }
zoey chene02881a2019-12-30 16:11:23 +080011106
11107 @Override
11108 public boolean isIccLockEnabled(int subId) {
11109 enforceReadPrivilegedPermission("isIccLockEnabled");
11110
joonhunshin4ac60942023-11-15 15:23:39 +000011111 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11112 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled");
11113
zoey chene02881a2019-12-30 16:11:23 +080011114 // Now that all security checks passes, perform the operation as ourselves.
11115 final long identity = Binder.clearCallingIdentity();
11116 try {
11117 Phone phone = getPhone(subId);
11118 if (phone != null && phone.getIccCard() != null) {
11119 return phone.getIccCard().getIccLockEnabled();
11120 } else {
11121 return false;
11122 }
11123 } finally {
11124 Binder.restoreCallingIdentity(identity);
11125 }
11126 }
11127
11128 /**
11129 * Set the ICC pin lock enabled or disabled.
11130 *
11131 * @return an integer representing the status of IccLock enabled or disabled in the following
11132 * three cases:
11133 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
11134 * successfully.
11135 * - Positive number and zero for remaining password attempts.
11136 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11137 *
11138 */
11139 @Override
11140 public int setIccLockEnabled(int subId, boolean enabled, String password) {
11141 enforceModifyPermission();
11142
joonhunshin4ac60942023-11-15 15:23:39 +000011143 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11144 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled");
11145
zoey chene02881a2019-12-30 16:11:23 +080011146 Phone phone = getPhone(subId);
11147 if (phone == null) {
11148 return 0;
11149 }
11150 // Now that all security checks passes, perform the operation as ourselves.
11151 final long identity = Binder.clearCallingIdentity();
11152 try {
11153 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
11154 new Pair<Boolean, String>(enabled, password), phone, null);
11155 return attemptsRemaining;
11156
11157 } catch (Exception e) {
11158 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
11159 } finally {
11160 Binder.restoreCallingIdentity(identity);
11161 }
11162 return 0;
11163 }
11164
11165 /**
11166 * Change the ICC password used in ICC pin lock.
11167 *
11168 * @return an integer representing the status of IccLock changed in the following three cases:
11169 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
11170 * - Positive number and zero for remaining password attempts.
11171 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11172 *
11173 */
11174 @Override
11175 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
11176 enforceModifyPermission();
11177
joonhunshin4ac60942023-11-15 15:23:39 +000011178 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11179 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword");
11180
zoey chene02881a2019-12-30 16:11:23 +080011181 Phone phone = getPhone(subId);
11182 if (phone == null) {
11183 return 0;
11184 }
11185 // Now that all security checks passes, perform the operation as ourselves.
11186 final long identity = Binder.clearCallingIdentity();
11187 try {
11188 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
11189 new Pair<String, String>(oldPassword, newPassword), phone, null);
11190 return attemptsRemaining;
11191
11192 } catch (Exception e) {
11193 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
11194 } finally {
11195 Binder.restoreCallingIdentity(identity);
11196 }
11197 return 0;
11198 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080011199
11200 /**
11201 * Request for receiving user activity notification
11202 */
11203 @Override
11204 public void requestUserActivityNotification() {
11205 if (!mNotifyUserActivity.get()
11206 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
11207 mNotifyUserActivity.set(true);
11208 }
11209 }
11210
11211 /**
11212 * Called when userActivity is signalled in the power manager.
11213 * This is safe to call from any thread, with any window manager locks held or not.
11214 */
11215 @Override
11216 public void userActivity() {
11217 // ***************************************
11218 // * Inherited from PhoneWindowManager *
11219 // ***************************************
11220 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
11221 // WITH ITS LOCKS HELD.
11222 //
11223 // This code must be VERY careful about the locks
11224 // it acquires.
11225 // In fact, the current code acquires way too many,
11226 // and probably has lurking deadlocks.
11227
11228 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
11229 throw new SecurityException("Only the OS may call notifyUserActivity()");
11230 }
11231
11232 if (mNotifyUserActivity.getAndSet(false)) {
11233 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
11234 USER_ACTIVITY_NOTIFICATION_DELAY);
11235 }
11236 }
Malcolm Chen4639c562020-04-13 11:59:40 -070011237
11238 @Override
11239 public boolean canConnectTo5GInDsdsMode() {
11240 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
11241 }
Jack Yud10cdd42020-09-28 20:28:01 -070011242
11243 @Override
11244 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
11245 String callingFeatureId) {
11246 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
11247 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
11248 throw new SecurityException("Requires READ_PHONE_STATE permission.");
11249 }
11250
joonhunshin4ac60942023-11-15 15:23:39 +000011251 enforceTelephonyFeatureWithException(callingPackage,
11252 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns");
11253
Jack Yud10cdd42020-09-28 20:28:01 -070011254 Phone phone = getPhone(subId);
11255 if (phone == null) {
11256 throw new RuntimeException("phone is not available");
11257 }
11258 // Now that all security checks passes, perform the operation as ourselves.
11259 final long identity = Binder.clearCallingIdentity();
11260 try {
11261 return phone.getEquivalentHomePlmns();
11262 } finally {
11263 Binder.restoreCallingIdentity(identity);
11264 }
11265 }
Daniel Bright59e67312020-11-13 11:49:37 -080011266
11267 @Override
11268 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011269 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
joonhunshin4ac60942023-11-15 15:23:39 +000011270 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11271 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
11272 "isRadioInterfaceCapabilitySupported");
11273
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011274 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080011275 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080011276 if (radioInterfaceCapabilities == null) {
11277 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080011278 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011279 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080011280 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011281
Hui Wang641e81c2020-10-12 12:14:23 -070011282 @Override
11283 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
11284 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000011285 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
11286 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11287 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
11288 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11289 Manifest.permission.MODIFY_PHONE_STATE);
joonhunshin4ac60942023-11-15 15:23:39 +000011290
11291 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11292 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest");
11293
Hui Wang641e81c2020-10-12 12:14:23 -070011294 if (DBG) {
11295 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
11296 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
11297 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
11298 }
11299
11300 if (!SubscriptionManager.isValidSubscriptionId(subId)
11301 || appType < TelephonyManager.APPTYPE_UNKNOWN
11302 || appType > TelephonyManager.APPTYPE_ISIM
11303 || nafUrl == null || securityProtocol == null || callback == null) {
11304 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
11305 if (callback != null) {
11306 try {
11307 callback.onAuthenticationFailure(
11308 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
11309 } catch (RemoteException exception) {
11310 log("Fail to notify onAuthenticationFailure due to " + exception);
11311 }
11312 return;
11313 }
11314 }
11315
11316 final long token = Binder.clearCallingIdentity();
11317 try {
11318 getGbaManager(subId).bootstrapAuthenticationRequest(
11319 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011320 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070011321 } finally {
11322 Binder.restoreCallingIdentity(token);
11323 }
11324 }
11325
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011326 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011327 * Attempts to set the radio power state for all phones for thermal reason.
11328 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011329 * requested radio power state will actually be set. See {@link
11330 * PhoneInternalInterface#setRadioPowerForReason} for more details.
11331 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011332 * @param enable {@code true} if trying to turn radio on.
11333 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
11334 * false}.
11335 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011336 private boolean setRadioPowerForThermal(boolean enable) {
11337 boolean isPhoneAvailable = false;
11338 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
11339 Phone phone = PhoneFactory.getPhone(i);
11340 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011341 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011342 isPhoneAvailable = true;
11343 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011344 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011345
11346 // return true if successfully informed the phone object about the thermal radio power
11347 // request.
11348 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011349 }
11350
11351 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011352 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011353 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11354 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11355 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11356 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11357 throw new IllegalArgumentException("modem does not support data throttling");
11358 }
11359
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011360 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11361 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011362 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011363 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11364 }
11365
Sarah Chinecc78c42022-03-31 21:16:48 -070011366 setDataEnabledForReason(
11367 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011368
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011369 if (isDataThrottlingSupported) {
11370 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011371 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011372 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11373 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11374 } else if (thermalMitigationResult
11375 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011376 log("Modem likely does not support data throttling on secondary carrier. Data " +
11377 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11378 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011379 }
11380 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011381 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011382
11383 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011384 }
11385
Jack Nudelman644b91a2021-03-12 14:09:48 -080011386 private static List<String> getThermalMitigationAllowlist(Context context) {
11387 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11388 for (String pckg : context.getResources()
11389 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11390 sThermalMitigationAllowlistedPackages.add(pckg);
11391 }
11392 }
11393
11394 return sThermalMitigationAllowlistedPackages;
11395 }
11396
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011397 private boolean isAnyPhoneInEmergencyState() {
11398 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11399 if (tm.isInEmergencyCall()) {
11400 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11401 return true;
11402 }
11403 for (Phone phone : PhoneFactory.getPhones()) {
11404 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11405 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011406 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11407 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011408 return true;
11409 }
11410 }
11411
11412 return false;
11413 }
11414
Jack Nudelman644b91a2021-03-12 14:09:48 -080011415 /**
11416 * Used by shell commands to add an authorized package name for thermal mitigation.
11417 * @param packageName name of package to be allowlisted
11418 * @param context
11419 */
11420 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11421 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11422 sThermalMitigationAllowlistedPackages.add(packageName);
11423 }
11424
11425 /**
11426 * Used by shell commands to remove an authorized package name for thermal mitigation.
11427 * @param packageName name of package to remove from allowlist
11428 * @param context
11429 */
11430 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11431 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11432 sThermalMitigationAllowlistedPackages.remove(packageName);
11433 }
11434
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011435 /**
11436 * Thermal mitigation request to control functionalities at modem.
11437 *
11438 * @param subId the id of the subscription.
11439 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011440 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011441 *
11442 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11443 */
11444 @Override
11445 @ThermalMitigationResult
11446 public int sendThermalMitigationRequest(
11447 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011448 ThermalMitigationRequest thermalMitigationRequest,
11449 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011450 enforceModifyPermission();
11451
Jack Nudelman644b91a2021-03-12 14:09:48 -080011452 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000011453
11454 enforceTelephonyFeatureWithException(callingPackage,
11455 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest");
11456
Jack Nudelman644b91a2021-03-12 14:09:48 -080011457 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11458 .contains(callingPackage)) {
11459 throw new SecurityException("Calling package must be configured in the device config. "
11460 + "calling package: " + callingPackage);
11461 }
11462
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011463 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11464 final long identity = Binder.clearCallingIdentity();
11465
11466 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11467 try {
11468 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11469 switch (thermalMitigationAction) {
11470 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11471 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011472 handleDataThrottlingRequest(subId,
11473 thermalMitigationRequest.getDataThrottlingRequest(),
11474 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011475 break;
11476 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11477 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11478 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11479 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11480 }
11481
11482 // Ensure that radio is on. If not able to power on due to phone being
11483 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011484 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011485 thermalMitigationResult =
11486 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11487 break;
11488 }
11489
11490 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011491 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011492 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11493 break;
11494 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11495 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11496 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11497 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11498 }
11499
11500 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11501 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011502 Phone phone = getPhone(subId);
11503 if (phone == null) {
11504 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011505 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011506 break;
11507 }
11508
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011509 TelephonyConnectionService service =
11510 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011511 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011512 Log.e(LOG_TAG, "An emergency call is pending");
11513 thermalMitigationResult =
11514 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11515 break;
11516 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011517 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011518 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011519 break;
11520 }
11521 } else {
11522 thermalMitigationResult =
11523 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11524 break;
11525 }
11526
11527 // Turn radio off. If not able to power off due to phone being unavailable,
11528 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011529 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011530 thermalMitigationResult =
11531 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11532 break;
11533 }
11534 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011535 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011536 break;
11537 default:
11538 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11539 + "not exist. Requested action: " + thermalMitigationAction);
11540 }
11541 } catch (IllegalArgumentException e) {
11542 throw e;
11543 } catch (Exception e) {
11544 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11545 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11546 } finally {
11547 Binder.restoreCallingIdentity(identity);
11548 }
11549
11550 if (DBG) {
11551 log("thermalMitigationRequest returning with thermalMitigationResult: "
11552 + thermalMitigationResult);
11553 }
11554
11555 return thermalMitigationResult;
11556 }
Hui Wang641e81c2020-10-12 12:14:23 -070011557
11558 /**
11559 * Set the GbaService Package Name that Telephony will bind to.
11560 *
11561 * @param subId The sim that the GbaService is associated with.
11562 * @param packageName The name of the package to be replaced with.
11563 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11564 */
11565 @Override
11566 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11567 enforceModifyPermission();
11568
11569 final long identity = Binder.clearCallingIdentity();
11570 try {
11571 return getGbaManager(subId).overrideServicePackage(packageName);
11572 } finally {
11573 Binder.restoreCallingIdentity(identity);
11574 }
11575 }
11576
11577 /**
11578 * Return the package name of the currently bound GbaService.
11579 *
11580 * @param subId The sim that the GbaService is associated with.
11581 * @return the package name of the GbaService configuration, null if GBA is not supported.
11582 */
11583 @Override
11584 public String getBoundGbaService(int subId) {
11585 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11586
11587 final long identity = Binder.clearCallingIdentity();
11588 try {
11589 return getGbaManager(subId).getServicePackage();
11590 } finally {
11591 Binder.restoreCallingIdentity(identity);
11592 }
11593 }
11594
11595 /**
11596 * Set the release time for telephony to unbind GbaService.
11597 *
11598 * @param subId The sim that the GbaService is associated with.
11599 * @param interval The release time to unbind GbaService by millisecond.
11600 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11601 */
11602 @Override
11603 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11604 enforceModifyPermission();
11605
11606 final long identity = Binder.clearCallingIdentity();
11607 try {
11608 return getGbaManager(subId).overrideReleaseTime(interval);
11609 } finally {
11610 Binder.restoreCallingIdentity(identity);
11611 }
11612 }
11613
11614 /**
11615 * Return the release time for telephony to unbind GbaService.
11616 *
11617 * @param subId The sim that the GbaService is associated with.
11618 * @return The release time to unbind GbaService by millisecond.
11619 */
11620 @Override
11621 public int getGbaReleaseTime(int subId) {
11622 enforceReadPrivilegedPermission("getGbaReleaseTime");
11623
11624 final long identity = Binder.clearCallingIdentity();
11625 try {
11626 return getGbaManager(subId).getReleaseTime();
11627 } finally {
11628 Binder.restoreCallingIdentity(identity);
11629 }
11630 }
11631
11632 private GbaManager getGbaManager(int subId) {
11633 GbaManager instance = GbaManager.getInstance(subId);
11634 if (instance == null) {
11635 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11636 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11637 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11638 }
11639 return instance;
11640 }
Hui Wang761a6682020-10-31 05:12:53 +000011641
11642 /**
11643 * indicate whether the device and the carrier can support
11644 * RCS VoLTE single registration.
11645 */
11646 @Override
11647 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011648 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11649 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11650 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11651 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011652
11653 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11654 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11655 }
11656
11657 final long identity = Binder.clearCallingIdentity();
11658 try {
11659 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11660 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011661 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11662 if (isCapable != null) {
11663 return isCapable;
11664 }
Hui Wang761a6682020-10-31 05:12:53 +000011665 }
Hui Wang67af90e2021-06-04 16:57:15 -070011666 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11667 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011668 } finally {
11669 Binder.restoreCallingIdentity(identity);
11670 }
11671 }
11672
11673 /**
11674 * Register RCS provisioning callback.
11675 */
11676 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011677 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011678 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011679 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011680 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011681 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11682 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011683
11684 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11685 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11686 }
joonhunshin4ac60942023-11-15 15:23:39 +000011687 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11688 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11689 Binder.getCallingUserHandle())) {
11690 if (!isImsAvailableOnDevice()) {
11691 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11692 "IMS not available on device.");
11693 }
11694 } else {
11695 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11696 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011697 }
11698
11699 final long identity = Binder.clearCallingIdentity();
11700 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011701 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011702 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011703 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11704 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011705 }
Hui Wang761a6682020-10-31 05:12:53 +000011706 } finally {
11707 Binder.restoreCallingIdentity(identity);
11708 }
11709 }
11710
11711 /**
11712 * Unregister RCS provisioning callback.
11713 */
11714 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011715 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011716 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011717 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011718 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011719 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11720 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011721
11722 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11723 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11724 }
joonhunshin4ac60942023-11-15 15:23:39 +000011725
11726 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11727 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11728 Binder.getCallingUserHandle())) {
11729 if (!isImsAvailableOnDevice()) {
11730 // operation failed silently
11731 Rlog.w(LOG_TAG, "IMS not available on device.");
11732 return;
11733 }
11734 } else {
11735 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11736 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11737 "unregisterRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011738 }
11739
11740 final long identity = Binder.clearCallingIdentity();
11741 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011742 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011743 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011744 } finally {
11745 Binder.restoreCallingIdentity(identity);
11746 }
11747 }
11748
11749 /**
11750 * trigger RCS reconfiguration.
11751 */
11752 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011753 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11754 "triggerRcsReconfiguration",
11755 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011756
11757 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11758 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11759 }
joonhunshin4ac60942023-11-15 15:23:39 +000011760 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11761 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11762 Binder.getCallingUserHandle())) {
11763 if (!isImsAvailableOnDevice()) {
11764 // ProvisioningManager can not handle ServiceSpecificException.
11765 // Throw the IllegalStateException and annotate ProvisioningManager.
11766 throw new IllegalStateException("IMS not available on device.");
11767 }
11768 } else {
11769 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11770 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011771 }
11772
11773 final long identity = Binder.clearCallingIdentity();
11774 try {
11775 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11776 } finally {
11777 Binder.restoreCallingIdentity(identity);
11778 }
11779 }
11780
11781 /**
11782 * Provide the client configuration parameters of the RCS application.
11783 */
11784 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011785 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11786 "setRcsClientConfiguration",
11787 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011788
11789 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11790 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11791 }
joonhunshin4ac60942023-11-15 15:23:39 +000011792 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11793 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11794 Binder.getCallingUserHandle())) {
11795 if (!isImsAvailableOnDevice()) {
11796 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11797 "IMS not available on device.");
11798 }
11799 } else {
11800 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11801 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011802 }
11803
11804 final long identity = Binder.clearCallingIdentity();
11805
11806 try {
11807 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11808 if (configBinder == null) {
11809 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011810 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11811 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011812 } else {
11813 configBinder.setRcsClientConfiguration(rcc);
11814 }
joonhunshin3e154242021-09-17 06:33:39 +000011815
11816 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11817 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011818 } catch (RemoteException e) {
11819 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011820 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11821 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011822 } finally {
11823 Binder.restoreCallingIdentity(identity);
11824 }
11825 }
11826
11827 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011828 * Enables or disables the test mode for RCS VoLTE single registration.
11829 */
11830 @Override
11831 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11832 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11833 "setRcsSingleRegistrationTestModeEnabled");
11834
11835 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11836 }
11837
11838 /**
11839 * Gets the test mode for RCS VoLTE single registration.
11840 */
11841 @Override
11842 public boolean getRcsSingleRegistrationTestModeEnabled() {
11843 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11844 "getRcsSingleRegistrationTestModeEnabled");
11845
11846 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11847 }
11848
11849 /**
Hui Wang761a6682020-10-31 05:12:53 +000011850 * Overrides the config of RCS VoLTE single registration enabled for the device.
11851 */
11852 @Override
11853 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11854 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11855 "setDeviceSingleRegistrationEnabledOverride");
11856 enforceModifyPermission();
11857
11858 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11859 : Boolean.parseBoolean(enabledStr);
11860 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011861 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011862 }
11863
11864 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011865 * Sends a device to device communication message. Only usable via shell.
11866 * @param message message to send.
11867 * @param value message value.
11868 */
11869 @Override
11870 public void sendDeviceToDeviceMessage(int message, int value) {
11871 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011872 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011873 enforceModifyPermission();
11874
11875 final long identity = Binder.clearCallingIdentity();
11876 try {
11877 TelephonyConnectionService service =
11878 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11879 if (service == null) {
11880 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11881 return;
11882 }
11883 service.sendTestDeviceToDeviceMessage(message, value);
11884 } finally {
11885 Binder.restoreCallingIdentity(identity);
11886 }
11887 }
11888
Tyler Gunnbabbda02021-02-10 11:05:02 -080011889 /**
11890 * Sets the specified device to device transport active.
11891 * @param transport The transport to set active.
11892 */
11893 @Override
11894 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11895 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11896 "setActiveDeviceToDeviceTransport");
11897 enforceModifyPermission();
11898
11899 final long identity = Binder.clearCallingIdentity();
11900 try {
11901 TelephonyConnectionService service =
11902 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11903 if (service == null) {
11904 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11905 return;
11906 }
11907 service.setActiveDeviceToDeviceTransport(transport);
11908 } finally {
11909 Binder.restoreCallingIdentity(identity);
11910 }
11911 }
Tyler Gunn92479152021-01-20 16:30:10 -080011912
Tyler Gunnd4339262021-05-03 14:46:49 -070011913 @Override
11914 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11915 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11916 "setDeviceToDeviceForceEnabled");
11917
11918 final long identity = Binder.clearCallingIdentity();
11919 try {
11920 Arrays.stream(PhoneFactory.getPhones()).forEach(
11921 p -> {
11922 Phone thePhone = p.getImsPhone();
11923 if (thePhone != null && thePhone instanceof ImsPhone) {
11924 ImsPhone imsPhone = (ImsPhone) thePhone;
11925 CallTracker tracker = imsPhone.getCallTracker();
11926 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11927 ImsPhoneCallTracker imsPhoneCallTracker =
11928 (ImsPhoneCallTracker) tracker;
11929 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11930 }
11931 }
11932 }
11933 );
11934 } finally {
11935 Binder.restoreCallingIdentity(identity);
11936 }
11937 }
11938
Tyler Gunn92479152021-01-20 16:30:10 -080011939 /**
Hui Wang761a6682020-10-31 05:12:53 +000011940 * Gets the config of RCS VoLTE single registration enabled for the device.
11941 */
11942 @Override
11943 public boolean getDeviceSingleRegistrationEnabled() {
11944 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11945 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11946 }
11947
11948 /**
11949 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11950 */
11951 @Override
11952 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11953 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11954 "setCarrierSingleRegistrationEnabledOverride");
11955 enforceModifyPermission();
11956
11957 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11958 : Boolean.parseBoolean(enabledStr);
11959 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11960 subId, enabled);
11961 }
11962
11963 /**
11964 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11965 */
11966 @Override
11967 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11968 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11969 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11970 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011971
11972 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011973 * Overrides the ims feature validation result
11974 */
11975 @Override
11976 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11977 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11978 "setImsFeatureValidationOverride");
11979
11980 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11981 : Boolean.parseBoolean(enabledStr);
11982 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11983 subId, enabled);
11984 }
11985
11986 /**
11987 * Gets the ims feature validation override value
11988 */
11989 @Override
11990 public boolean getImsFeatureValidationOverride(int subId) {
11991 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11992 "getImsFeatureValidationOverride");
11993 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11994 }
11995
11996 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011997 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11998 * their mobile plan.
11999 */
12000 @Override
12001 public String getMobileProvisioningUrl() {
12002 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
12003 final long identity = Binder.clearCallingIdentity();
12004 try {
12005 return getDefaultPhone().getMobileProvisioningUrl();
12006 } finally {
12007 Binder.restoreCallingIdentity(identity);
12008 }
12009 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012010
James.cf Linbcdf8b32021-01-14 16:44:13 +080012011 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080012012 * Get the EAB contact from the EAB database.
12013 */
12014 @Override
12015 public String getContactFromEab(String contact) {
12016 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
12017 enforceModifyPermission();
12018 final long identity = Binder.clearCallingIdentity();
12019 try {
12020 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
12021 } finally {
12022 Binder.restoreCallingIdentity(identity);
12023 }
12024 }
12025
12026 /**
Calvin Pana1434322021-07-01 19:27:01 +080012027 * Get the EAB capability from the EAB database.
12028 */
12029 @Override
12030 public String getCapabilityFromEab(String contact) {
12031 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
12032 enforceModifyPermission();
12033 final long identity = Binder.clearCallingIdentity();
12034 try {
12035 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
12036 } finally {
12037 Binder.restoreCallingIdentity(identity);
12038 }
12039 }
12040
12041 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080012042 * Remove the EAB contacts from the EAB database.
12043 */
12044 @Override
12045 public int removeContactFromEab(int subId, String contacts) {
12046 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
12047 enforceModifyPermission();
12048 final long identity = Binder.clearCallingIdentity();
12049 try {
12050 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
12051 } finally {
12052 Binder.restoreCallingIdentity(identity);
12053 }
12054 }
12055
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012056 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080012057 public boolean getDeviceUceEnabled() {
12058 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
12059 final long identity = Binder.clearCallingIdentity();
12060 try {
12061 return mApp.getDeviceUceEnabled();
12062 } finally {
12063 Binder.restoreCallingIdentity(identity);
12064 }
12065 }
12066
12067 @Override
12068 public void setDeviceUceEnabled(boolean isEnabled) {
12069 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
12070 final long identity = Binder.clearCallingIdentity();
12071 try {
12072 mApp.setDeviceUceEnabled(isEnabled);
12073 } finally {
12074 Binder.restoreCallingIdentity(identity);
12075 }
12076 }
12077
Brad Ebinger14d467f2021-02-12 06:18:28 +000012078 /**
12079 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
12080 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12081 */
12082 // Used for SHELL command only right now.
12083 @Override
12084 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
12085 List<String> featureTags) {
12086 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12087 "addUceRegistrationOverrideShell");
12088 final long identity = Binder.clearCallingIdentity();
12089 try {
12090 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
12091 new ArraySet<>(featureTags));
12092 } catch (ImsException e) {
12093 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12094 } finally {
12095 Binder.restoreCallingIdentity(identity);
12096 }
12097 }
12098
12099 /**
12100 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
12101 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12102 */
12103 // Used for SHELL command only right now.
12104 @Override
12105 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
12106 List<String> featureTags) {
12107 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12108 "removeUceRegistrationOverrideShell");
12109 final long identity = Binder.clearCallingIdentity();
12110 try {
12111 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
12112 new ArraySet<>(featureTags));
12113 } catch (ImsException e) {
12114 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12115 } finally {
12116 Binder.restoreCallingIdentity(identity);
12117 }
12118 }
12119
12120 /**
12121 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
12122 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12123 */
12124 // Used for SHELL command only right now.
12125 @Override
12126 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
12127 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12128 "clearUceRegistrationOverrideShell");
12129 final long identity = Binder.clearCallingIdentity();
12130 try {
12131 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
12132 } catch (ImsException e) {
12133 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12134 } finally {
12135 Binder.restoreCallingIdentity(identity);
12136 }
12137 }
12138
12139 /**
12140 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12141 */
12142 // Used for SHELL command only right now.
12143 @Override
12144 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
12145 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12146 "getLatestRcsContactUceCapabilityShell");
12147 final long identity = Binder.clearCallingIdentity();
12148 try {
12149 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
12150 } catch (ImsException e) {
12151 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12152 } finally {
12153 Binder.restoreCallingIdentity(identity);
12154 }
12155 }
12156
12157 /**
12158 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
12159 * device does not have an active PUBLISH.
12160 */
12161 // Used for SHELL command only right now.
12162 @Override
12163 public String getLastUcePidfXmlShell(int subId) {
12164 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
12165 final long identity = Binder.clearCallingIdentity();
12166 try {
12167 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
12168 } catch (ImsException e) {
12169 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12170 } finally {
12171 Binder.restoreCallingIdentity(identity);
12172 }
12173 }
12174
James.cf Line8713a42021-04-29 16:04:26 +080012175 /**
12176 * Remove UCE requests cannot be sent to the network status.
12177 */
12178 // Used for SHELL command only right now.
12179 @Override
12180 public boolean removeUceRequestDisallowedStatus(int subId) {
12181 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
12182 final long identity = Binder.clearCallingIdentity();
12183 try {
12184 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
12185 } catch (ImsException e) {
12186 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12187 } finally {
12188 Binder.restoreCallingIdentity(identity);
12189 }
12190 }
12191
James.cf Lin18bb9002021-05-25 01:37:38 +080012192 /**
12193 * Remove UCE requests cannot be sent to the network status.
12194 */
12195 // Used for SHELL command only.
12196 @Override
12197 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
12198 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
12199 final long identity = Binder.clearCallingIdentity();
12200 try {
12201 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
12202 } catch (ImsException e) {
12203 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12204 } finally {
12205 Binder.restoreCallingIdentity(identity);
12206 }
12207 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000012208
James.cf Lin4b784aa2021-01-31 03:25:15 +080012209 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012210 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12211 String callingPackage) {
12212 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12213 mApp, subId, "setSignalStrengthUpdateRequest");
12214
joonhunshin4ac60942023-11-15 15:23:39 +000012215 enforceTelephonyFeatureWithException(callingPackage,
12216 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest");
12217
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012218 final int callingUid = Binder.getCallingUid();
12219 // Verify that tha callingPackage belongs to the calling UID
12220 mApp.getSystemService(AppOpsManager.class)
12221 .checkPackage(callingUid, callingPackage);
12222
Rambo Wang3607f502021-02-01 21:51:40 -080012223 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012224
12225 final long identity = Binder.clearCallingIdentity();
12226 try {
12227 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
12228 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12229
12230 if (result instanceof IllegalStateException) {
12231 throw (IllegalStateException) result;
12232 }
12233 } finally {
12234 Binder.restoreCallingIdentity(identity);
12235 }
12236 }
12237
12238 @Override
12239 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12240 String callingPackage) {
12241 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12242 mApp, subId, "clearSignalStrengthUpdateRequest");
12243
joonhunshin4ac60942023-11-15 15:23:39 +000012244 enforceTelephonyFeatureWithException(callingPackage,
12245 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest");
12246
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012247 final int callingUid = Binder.getCallingUid();
12248 // Verify that tha callingPackage belongs to the calling UID
12249 mApp.getSystemService(AppOpsManager.class)
12250 .checkPackage(callingUid, callingPackage);
12251
12252 final long identity = Binder.clearCallingIdentity();
12253 try {
12254 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
12255 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12256
12257 if (result instanceof IllegalStateException) {
12258 throw (IllegalStateException) result;
12259 }
12260 } finally {
12261 Binder.restoreCallingIdentity(identity);
12262 }
12263 }
12264
Rambo Wang3607f502021-02-01 21:51:40 -080012265 private static void validateSignalStrengthUpdateRequest(Context context,
12266 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012267 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
12268 // phone/system process do not have further restriction on request
12269 return;
12270 }
12271
12272 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080012273 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012274 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080012275 context.enforceCallingOrSelfPermission(
12276 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
12277 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012278 }
12279
12280 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000012281 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012282 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012283 || info.isEnabled()) {
12284 throw new IllegalArgumentException(
12285 "Only system can set hide fields in SignalThresholdInfo");
12286 }
12287
12288 // Thresholds length for each RAN need in range. This has been validated in
12289 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
12290 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
12291 final int[] thresholds = info.getThresholds();
12292 Objects.requireNonNull(thresholds);
12293 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
12294 || thresholds.length
12295 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
12296 throw new IllegalArgumentException(
12297 "thresholds length is out of range: " + thresholds.length);
12298 }
12299 }
12300 }
SongFerngWang8236caa2021-01-17 21:51:44 +080012301
12302 /**
12303 * Gets the current phone capability.
12304 *
12305 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
12306 * @return the PhoneCapability which describes the data connection capability of modem.
12307 * It's used to evaluate possible phone config change, for example from single
12308 * SIM device to multi-SIM device.
12309 */
12310 @Override
12311 public PhoneCapability getPhoneCapability() {
12312 enforceReadPrivilegedPermission("getPhoneCapability");
joonhunshin4ac60942023-11-15 15:23:39 +000012313
12314 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12315 PackageManager.FEATURE_TELEPHONY, "getPhoneCapability");
12316
SongFerngWang8236caa2021-01-17 21:51:44 +080012317 final long identity = Binder.clearCallingIdentity();
12318 try {
12319 return mPhoneConfigurationManager.getCurrentPhoneCapability();
12320 } finally {
12321 Binder.restoreCallingIdentity(identity);
12322 }
12323 }
Michele Berionne5e411512020-11-13 02:36:59 +000012324
12325 /**
12326 * Prepare TelephonyManager for an unattended reboot. The reboot is
12327 * required to be done shortly after the API is invoked.
12328 */
12329 @Override
12330 @TelephonyManager.PrepareUnattendedRebootResult
12331 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012332 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000012333 enforceRebootPermission();
12334
joonhunshin4ac60942023-11-15 15:23:39 +000012335 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12336 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot");
12337
Michele Berionne5e411512020-11-13 02:36:59 +000012338 final long identity = Binder.clearCallingIdentity();
12339 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012340 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000012341 } finally {
12342 Binder.restoreCallingIdentity(identity);
12343 }
12344 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012345
12346 /**
12347 * Request to get the current slicing configuration including URSP rules and
12348 * NSSAIs (configured, allowed and rejected).
12349 *
12350 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
12351 */
12352 @Override
12353 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000012354 TelephonyPermissions
12355 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
12356 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012357
joonhunshin4ac60942023-11-15 15:23:39 +000012358 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12359 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
12360 "getSlicingConfig");
12361
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012362 final long identity = Binder.clearCallingIdentity();
12363 try {
12364 Phone phone = getDefaultPhone();
12365 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
12366 } finally {
12367 Binder.restoreCallingIdentity(identity);
12368 }
12369 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012370
12371 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070012372 * Check whether the given premium capability is available for purchase from the carrier.
12373 *
12374 * @param capability The premium capability to check.
12375 * @param subId The subId to check the premium capability for.
12376 *
12377 * @return Whether the given premium capability is available to purchase.
12378 */
12379 @Override
12380 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
12381 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12382 mApp, "isPremiumCapabilityAvailableForPurchase")) {
12383 log("Premium capability "
12384 + TelephonyManager.convertPremiumCapabilityToString(capability)
12385 + " is not available for purchase due to missing permissions.");
12386 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
12387 + "permission READ_BASIC_PHONE_STATE.");
12388 }
12389
joonhunshin4ac60942023-11-15 15:23:39 +000012390 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12391 PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase");
12392
Sarah Chin2ec39f62022-08-31 17:03:26 -070012393 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080012394 if (phone == null) {
12395 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12396 return false;
12397 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012398 final long identity = Binder.clearCallingIdentity();
12399 try {
Sarah Chincc5446f2023-10-23 17:57:19 -070012400 return SlicePurchaseController.getInstance(phone, mFeatureFlags)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012401 .isPremiumCapabilityAvailableForPurchase(capability);
12402 } finally {
12403 Binder.restoreCallingIdentity(identity);
12404 }
12405 }
12406
12407 /**
12408 * Purchase the given premium capability from the carrier.
12409 *
12410 * @param capability The premium capability to purchase.
12411 * @param callback The result of the purchase request.
12412 * @param subId The subId to purchase the premium capability for.
12413 */
12414 @Override
12415 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12416 log("purchasePremiumCapability: capability="
12417 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12418 + getCurrentPackageName());
12419
12420 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12421 mApp, "purchasePremiumCapability")) {
12422 log("purchasePremiumCapability "
12423 + TelephonyManager.convertPremiumCapabilityToString(capability)
12424 + " failed due to missing permissions.");
12425 throw new SecurityException("purchasePremiumCapability requires permission "
12426 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012427 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12428 mApp, "purchasePremiumCapability")) {
12429 log("purchasePremiumCapability "
12430 + TelephonyManager.convertPremiumCapabilityToString(capability)
12431 + " failed due to missing permissions.");
12432 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012433 }
12434
joonhunshin4ac60942023-11-15 15:23:39 +000012435 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12436 PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability");
12437
Sarah Chin2ec39f62022-08-31 17:03:26 -070012438 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012439 if (phone == null) {
12440 try {
12441 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12442 callback.accept(result);
12443 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12444 } catch (RemoteException e) {
12445 String logStr = "Purchase premium capability "
12446 + TelephonyManager.convertPremiumCapabilityToString(capability)
12447 + " failed due to RemoteException handling null phone: " + e;
12448 if (DBG) log(logStr);
12449 AnomalyReporter.reportAnomaly(
12450 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12451 }
12452 return;
12453 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012454
12455 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012456 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012457 callingProcess = mApp.getPackageManager().getApplicationInfo(
12458 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070012459 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012460 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012461 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012462
12463 boolean isVisible = false;
12464 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12465 if (am != null) {
12466 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12467 if (processes != null) {
12468 for (ActivityManager.RunningAppProcessInfo process : processes) {
12469 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070012470 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080012471 if (process.processName.equals(callingProcess) && process.importance
12472 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12473 isVisible = true;
12474 break;
12475 }
12476 }
12477 }
12478 }
12479
12480 if (!isVisible) {
12481 try {
12482 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12483 callback.accept(result);
12484 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12485 } catch (RemoteException e) {
12486 String logStr = "Purchase premium capability "
12487 + TelephonyManager.convertPremiumCapabilityToString(capability)
12488 + " failed due to RemoteException handling background application: " + e;
12489 if (DBG) log(logStr);
12490 AnomalyReporter.reportAnomaly(
12491 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12492 }
12493 return;
12494 }
12495
Sarah Chin71b3a852022-09-28 15:54:19 -070012496 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012497 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012498 }
12499
12500 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012501 * Register an IMS connection state callback
12502 */
12503 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012504 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12505 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012506 if (feature == ImsFeature.FEATURE_MMTEL) {
12507 // ImsMmTelManager
12508 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12509 TelephonyPermissions
12510 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12511 mApp, subId, "registerImsStateCallback");
12512 } else if (feature == ImsFeature.FEATURE_RCS) {
12513 // ImsRcsManager or SipDelegateManager
12514 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12515 Binder.getCallingUid(), "registerImsStateCallback",
12516 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12517 Manifest.permission.READ_PRECISE_PHONE_STATE,
12518 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12519 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12520 }
12521
12522 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12523 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12524 "IMS not available on device.");
12525 }
12526
12527 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12528 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12529 }
12530
12531 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12532 if (controller == null) {
12533 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12534 "IMS not available on device.");
12535 }
12536
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012537 if (callingPackage == null) {
12538 callingPackage = getCurrentPackageName();
12539 }
12540
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012541 final long token = Binder.clearCallingIdentity();
12542 try {
12543 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012544 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012545 } catch (ImsException e) {
12546 throw new ServiceSpecificException(e.getCode());
12547 } finally {
12548 Binder.restoreCallingIdentity(token);
12549 }
12550 }
12551
12552 /**
12553 * Unregister an IMS connection state callback
12554 */
12555 @Override
12556 public void unregisterImsStateCallback(IImsStateCallback cb) {
12557 final long token = Binder.clearCallingIdentity();
12558 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12559 if (controller == null) {
12560 return;
12561 }
12562 try {
12563 controller.unregisterImsStateCallback(cb);
12564 } finally {
12565 Binder.restoreCallingIdentity(token);
12566 }
12567 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012568
12569 /**
12570 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12571 *
12572 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012573 * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012574 * SecurityException.
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012575 *
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012576 * If there is current registered network this value will be same as the registered cell
12577 * identity. If the device goes out of service the previous cell identity is cached and
12578 * will be returned. If the cache age of the Cell identity is more than 24 hours
12579 * it will be cleared and null will be returned.
12580 *
12581 */
12582 @Override
12583 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12584 String callingFeatureId) {
12585 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12586 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12587 LocationAccessPolicy.checkLocationPermission(mApp,
12588 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12589 .setCallingPackage(callingPackage)
12590 .setCallingFeatureId(callingFeatureId)
12591 .setCallingPid(Binder.getCallingPid())
12592 .setCallingUid(Binder.getCallingUid())
12593 .setMethod("getLastKnownCellIdentity")
12594 .setLogAsInfo(true)
12595 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12596 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12597 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12598 .build());
12599
12600 boolean hasFinePermission =
12601 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12602 if (!hasFinePermission
12603 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12604 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012605 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012606 }
12607
12608 final long identity = Binder.clearCallingIdentity();
12609 try {
Ling Mac28f0212023-03-24 16:07:15 -070012610 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012611 if (sst == null) return null;
12612 return sst.getLastKnownCellIdentity();
12613 } finally {
12614 Binder.restoreCallingIdentity(identity);
12615 }
12616 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012617
jimsun3b9ccac2021-10-26 15:01:23 +080012618 /**
12619 * Sets the modem service class Name that Telephony will bind to.
12620 *
12621 * @param serviceName The class name of the modem service.
12622 * @return true if the operation is succeed, otherwise false.
12623 */
12624 public boolean setModemService(String serviceName) {
12625 Log.d(LOG_TAG, "setModemService - " + serviceName);
12626 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12627 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012628 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12629 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012630 return mPhoneConfigurationManager.setModemService(serviceName);
12631 }
12632
12633 /**
12634 * Return the class name of the currently bounded modem service.
12635 *
12636 * @return the class name of the modem service.
12637 */
12638 public String getModemService() {
12639 String result;
12640 Log.d(LOG_TAG, "getModemService");
12641 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12642 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012643 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012644 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12645 "getModemService");
12646 result = mPhoneConfigurationManager.getModemService();
12647 Log.d(LOG_TAG, "result = " + result);
12648 return result;
12649 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012650
Hakjun Choi3ee81112023-12-19 15:40:58 +000012651 /**
12652 * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources,
12653 * including carrier config, entitlement server, and config update.
12654 *
12655 * @param subId subId The subscription ID of the carrier.
12656 *
12657 * @return List of plmns for carrier satellite service. If no plmn is available, empty list will
12658 * be returned.
12659 *
12660 * @throws SecurityException if the caller doesn't have the required permission.
12661 */
Hakjun Choi74c16be2024-01-19 08:18:09 +000012662 @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) {
12663 enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier");
Hakjun Choi3ee81112023-12-19 15:40:58 +000012664 final long identity = Binder.clearCallingIdentity();
12665 try {
Hakjun Choi74c16be2024-01-19 08:18:09 +000012666 return mSatelliteController.getSatellitePlmnsForCarrier(subId);
Hakjun Choi3ee81112023-12-19 15:40:58 +000012667 } finally {
12668 Binder.restoreCallingIdentity(identity);
12669 }
12670 }
12671
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012672 @Override
12673 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12674 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12675 mApp.enforceCallingOrSelfPermission(
12676 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12677 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12678
12679 final long identity = Binder.clearCallingIdentity();
12680 try {
12681 Phone phone = getPhone(subId);
12682 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012683 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12684 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012685 phone.setVoiceServiceStateOverride(hasService);
12686 } finally {
12687 Binder.restoreCallingIdentity(identity);
12688 }
12689 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012690
12691 /**
12692 * set removable eSIM as default eUICC.
12693 *
12694 * @hide
12695 */
12696 @Override
12697 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12698 enforceModifyPermission();
12699 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12700
12701 final long identity = Binder.clearCallingIdentity();
12702 try {
12703 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12704 } finally {
12705 Binder.restoreCallingIdentity(identity);
12706 }
12707 }
12708
12709 /**
12710 * Returns whether the removable eSIM is default eUICC or not.
12711 *
12712 * @hide
12713 */
12714 @Override
12715 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12716 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12717 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12718
12719 final long identity = Binder.clearCallingIdentity();
12720 try {
12721 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12722 } finally {
12723 Binder.restoreCallingIdentity(identity);
12724 }
12725 }
12726
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012727 /**
12728 * Get the component name of the default app to direct respond-via-message intent for the
12729 * user associated with this subscription, update the cache if there is no respond-via-message
12730 * application currently configured for this user.
12731 * @return component name of the app and class to direct Respond Via Message intent to, or
12732 * {@code null} if the functionality is not supported.
12733 * @hide
12734 */
12735 @Override
12736 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12737 boolean updateIfNeeded) {
12738 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012739
joonhunshin4ac60942023-11-15 15:23:39 +000012740 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12741 PackageManager.FEATURE_TELEPHONY_MESSAGING,
12742 "getDefaultRespondViaMessageApplication");
12743
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012744 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12745
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012746 UserHandle userHandle = null;
12747 final long identity = Binder.clearCallingIdentity();
12748 try {
12749 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12750 } finally {
12751 Binder.restoreCallingIdentity(identity);
12752 }
12753 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12754 updateIfNeeded, userHandle);
12755 }
Jack Yuf5badd92022-12-08 00:50:53 -080012756
12757 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012758 * Set whether the device is able to connect with null ciphering or integrity
12759 * algorithms. This is a global setting and will apply to all active subscriptions
12760 * and all new subscriptions after this.
12761 *
12762 * @param enabled when true, null cipher and integrity algorithms are allowed.
12763 * @hide
12764 */
12765 @Override
12766 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12767 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12768 enforceModifyPermission();
12769 checkForNullCipherAndIntegritySupport();
12770
12771 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12772 // for listening to these preference changes and applying them immediately.
12773 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12774 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12775 editor.apply();
12776
12777 for (Phone phone: PhoneFactory.getPhones()) {
12778 phone.handleNullCipherEnabledChange();
12779 }
12780 }
12781
12782
12783 /**
12784 * Get whether the device is able to connect with null ciphering or integrity
12785 * algorithms. Note that this retrieves the phone-global preference and not
12786 * the state of the radio.
12787 *
12788 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12789 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12790 * version for this feature.
12791 * @hide
12792 */
12793 @Override
12794 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12795 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12796 enforceReadPermission();
12797 checkForNullCipherAndIntegritySupport();
12798 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12799 }
12800
12801 private void checkForNullCipherAndIntegritySupport() {
12802 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12803 throw new UnsupportedOperationException(
12804 "Null cipher and integrity operations require HAL 2.1 or above");
12805 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012806 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12807 throw new UnsupportedOperationException(
12808 "Null cipher and integrity operations unsupported by modem");
12809 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012810 }
12811
Gil Cukierman06403e12023-11-29 16:33:03 +000012812 private void checkForIdentifierDisclosureNotificationSupport() {
12813 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) {
12814 throw new UnsupportedOperationException(
12815 "Cellular identifier disclosure transparency operations require HAL 2.2 or "
12816 + "above");
12817 }
12818 if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) {
12819 throw new UnsupportedOperationException(
12820 "Cellular identifier disclosure transparency operations unsupported by modem");
12821 }
12822 }
12823
Michael Groover826b71d2023-12-21 22:08:06 -060012824 private void checkForNullCipherNotificationSupport() {
12825 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) {
12826 throw new UnsupportedOperationException(
12827 "Null cipher notification operations require HAL 2.2 or above");
12828 }
12829 if (!getDefaultPhone().isNullCipherNotificationSupported()) {
12830 throw new UnsupportedOperationException(
12831 "Null cipher notification operations unsupported by modem");
12832 }
12833 }
12834
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012835 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012836 * Get the SIM state for the slot index.
12837 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12838 *
12839 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12840 */
12841 @Override
12842 @SimState
12843 public int getSimStateForSlotIndex(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +000012844 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12845 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex");
12846
Jack Yuf5badd92022-12-08 00:50:53 -080012847 IccCardConstants.State simState;
12848 if (slotIndex < 0) {
12849 simState = IccCardConstants.State.UNKNOWN;
12850 } else {
12851 Phone phone = null;
12852 try {
12853 phone = PhoneFactory.getPhone(slotIndex);
12854 } catch (IllegalStateException e) {
12855 // ignore
12856 }
12857 if (phone == null) {
12858 simState = IccCardConstants.State.UNKNOWN;
12859 } else {
12860 IccCard icc = phone.getIccCard();
12861 if (icc == null) {
12862 simState = IccCardConstants.State.UNKNOWN;
12863 } else {
12864 simState = icc.getState();
12865 }
12866 }
12867 }
12868 return simState.ordinal();
12869 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012870
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012871 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
12872 boolean enableLogcat,
12873 long logcatStartTimestampMillis, boolean enableTelecomDump,
12874 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012875 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012876 TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder =
12877 new TelephonyManager.EmergencyCallDiagnosticData.Builder();
12878 ecdDataBuilder
12879 .setTelecomDumpsysCollectionEnabled(enableTelecomDump)
12880 .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012881 if (enableLogcat) {
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012882 ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012883 }
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012884 TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build();
12885 Log.d(LOG_TAG, "persisting with Params " + ecdData.toString());
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012886 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
12887 Executors.newCachedThreadPool(), db,
12888 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012889 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012890 }
12891
12892 /**
12893 * Request telephony to persist state for debugging emergency call failures.
12894 *
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012895 * @param dropboxTag Tag to use when persisting data to dropbox service.
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012896 * @param enableLogcat whether to collect logcat output
12897 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
12898 * @param enableTelecomDump whether to collect telecom dumpsys
12899 * @param enableTelephonyDump whether to collect telephony dumpsys
12900 */
12901 @Override
12902 @RequiresPermission(android.Manifest.permission.DUMP)
12903 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
12904 long logcatStartTimestampMillis, boolean enableTelecomDump,
12905 boolean enableTelephonyDump) {
12906 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
12907 "persistEmergencyCallDiagnosticData");
12908 final long identity = Binder.clearCallingIdentity();
12909 try {
12910 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
12911 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
12912
12913 } finally {
12914 Binder.restoreCallingIdentity(identity);
12915 }
12916 }
12917
Hui Wang9b5793a2022-12-05 14:38:06 -060012918 /**
12919 * Get current cell broadcast ranges.
12920 */
12921 @Override
12922 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12923 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12924 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12925 "getCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012926
12927 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12928 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges");
12929
Hui Wang9b5793a2022-12-05 14:38:06 -060012930 final long identity = Binder.clearCallingIdentity();
12931 try {
12932 return getPhone(subId).getCellBroadcastIdRanges();
12933 } finally {
12934 Binder.restoreCallingIdentity(identity);
12935 }
12936 }
12937
12938 /**
12939 * Set reception of cell broadcast messages with the list of the given ranges
12940 *
12941 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12942 */
12943 @Override
12944 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12945 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12946 @Nullable IIntegerConsumer callback) {
12947 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12948 "setCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012949
12950 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12951 PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges");
12952
Hui Wang9b5793a2022-12-05 14:38:06 -060012953 final long identity = Binder.clearCallingIdentity();
12954 try {
12955 Phone phone = getPhoneFromSubId(subId);
12956 if (DBG) {
12957 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12958 }
12959 phone.setCellBroadcastIdRanges(ranges, result -> {
12960 if (callback != null) {
12961 try {
12962 callback.accept(result);
12963 } catch (RemoteException e) {
12964 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12965 }
12966 }
12967 });
12968 } finally {
12969 Binder.restoreCallingIdentity(identity);
12970 }
12971 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012972
12973 /**
12974 * Returns whether the device supports the domain selection service.
12975 *
12976 * @return {@code true} if the device supports the domain selection service.
12977 */
12978 @Override
12979 public boolean isDomainSelectionSupported() {
12980 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12981 "isDomainSelectionSupported");
12982
12983 final long identity = Binder.clearCallingIdentity();
12984 try {
12985 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12986 } finally {
12987 Binder.restoreCallingIdentity(identity);
12988 }
12989 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012990
12991 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012992 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
12993 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
12994 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080012995 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012996 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chinabf081b2023-03-09 23:00:57 -080012997 * @param enableSatellite {@code true} to enable the satellite modem and
12998 * {@code false} to disable.
12999 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
Thomas Nguyena8062672024-02-05 14:18:19 -080013000 * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise.
Sarah Chinabf081b2023-03-09 23:00:57 -080013001 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080013002 *
13003 * @throws SecurityException if the caller doesn't have the required permission.
13004 */
13005 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013006 public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode,
Thomas Nguyena8062672024-02-05 14:18:19 -080013007 boolean isEmergency, @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013008 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013009 if (enableSatellite) {
13010 ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) {
13011 @Override
13012 protected void onReceiveResult(int resultCode, Bundle resultData) {
13013 Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode
13014 + ", resultData=" + resultData);
13015 boolean isAllowed = false;
13016 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(
13017 callback::accept);
13018 if (resultCode == SATELLITE_RESULT_SUCCESS) {
13019 if (resultData != null
13020 && resultData.containsKey(KEY_SATELLITE_COMMUNICATION_ALLOWED)) {
13021 isAllowed = resultData.getBoolean(KEY_SATELLITE_COMMUNICATION_ALLOWED);
13022 } else {
13023 loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist.");
13024 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013025 } else {
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013026 result.accept(resultCode);
13027 return;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013028 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013029 if (isAllowed) {
13030 mSatelliteController.requestSatelliteEnabled(
Hyosun Kimab304792024-03-29 09:18:03 +000013031 subId, enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013032 } else {
13033 result.accept(SATELLITE_RESULT_ACCESS_BARRED);
13034 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013035 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013036 };
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013037 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013038 subId, resultReceiver);
13039 } else {
13040 // No need to check if satellite is allowed at current location when disabling satellite
13041 mSatelliteController.requestSatelliteEnabled(
Hyosun Kimab304792024-03-29 09:18:03 +000013042 subId, enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013043 }
Sarah Chin503828c2023-02-01 23:54:20 -080013044 }
13045
13046 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013047 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080013048 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013049 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013050 * @param result The result receiver that returns whether the satellite modem is enabled
13051 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013052 *
13053 * @throws SecurityException if the caller doesn't have the required permission.
13054 */
13055 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013056 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
13057 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013058 mSatelliteController.requestIsSatelliteEnabled(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013059 }
13060
13061 /**
Sarah Chin43457982023-02-15 17:50:38 -080013062 * Request to get whether the satellite service demo mode is enabled.
13063 *
13064 * @param subId The subId of the subscription to check whether the satellite demo mode
13065 * is enabled for.
13066 * @param result The result receiver that returns whether the satellite demo mode is enabled
13067 * if the request is successful or an error code if the request failed.
13068 *
13069 * @throws SecurityException if the caller doesn't have the required permission.
13070 */
13071 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013072 public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
13073 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
13074 mSatelliteController.requestIsDemoModeEnabled(subId, result);
Sarah Chin43457982023-02-15 17:50:38 -080013075 }
13076
13077 /**
Thomas Nguyena8062672024-02-05 14:18:19 -080013078 * Request to get whether the satellite service is enabled with emergency mode.
13079 *
13080 * @param subId The subId of the subscription to check whether the satellite demo mode
13081 * is enabled for.
13082 * @param result The result receiver that returns whether the satellite emergency mode is
13083 * enabled if the request is successful or an error code if the request failed.
13084 *
13085 * @throws SecurityException if the caller doesn't have the required permission.
13086 */
13087 @Override
13088 public void requestIsEmergencyModeEnabled(int subId, @NonNull ResultReceiver result) {
13089 enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled");
13090 result.send(SATELLITE_RESULT_REQUEST_NOT_SUPPORTED, null);
13091 }
13092
13093 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013094 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080013095 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013096 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013097 * @param result The result receiver that returns whether the satellite service is supported on
13098 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013099 */
13100 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013101 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013102 mSatelliteController.requestIsSatelliteSupported(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013103 }
13104
13105 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013106 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080013107 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013108 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013109 * @param result The result receiver that returns the {@link SatelliteCapabilities}
13110 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013111 *
13112 * @throws SecurityException if the caller doesn't have required permission.
13113 */
13114 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013115 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
13116 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013117 mSatelliteController.requestSatelliteCapabilities(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013118 }
13119
13120 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013121 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013122 * This can be called by the pointing UI when the user starts pointing to the satellite.
13123 * Modem should continue to report the pointing input as the device or satellite moves.
13124 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013125 * @param subId The subId of the subscription to start satellite transmission updates for.
13126 * @param resultCallback The callback to get the result of the request.
13127 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080013128 *
13129 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013130 */
13131 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013132 public void startSatelliteTransmissionUpdates(int subId,
13133 @NonNull IIntegerConsumer resultCallback,
13134 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13135 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
13136 mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080013137 }
13138
13139 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013140 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013141 * This can be called by the pointing UI when the user stops pointing to the satellite.
13142 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013143 * @param subId The subId of the subscription to stop satellite transmission updates for.
13144 * @param resultCallback The callback to get the result of the request.
13145 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
13146 * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080013147 *
13148 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013149 */
13150 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013151 public void stopSatelliteTransmissionUpdates(int subId,
13152 @NonNull IIntegerConsumer resultCallback,
13153 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13154 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
13155 mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013156 }
13157
13158 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013159 * Register the subscription with a satellite provider.
13160 * This is needed to register the subscription if the provider allows dynamic registration.
13161 *
13162 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013163 * @param token The token to be used as a unique identifier for provisioning with satellite
13164 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013165 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080013166 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013167 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013168 * @return The signal transport used by the caller to cancel the provision request,
13169 * or {@code null} if the request failed.
13170 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013171 * @throws SecurityException if the caller doesn't have the required permission.
13172 */
13173 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013174 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013175 @NonNull String token, @NonNull byte[] provisionData,
13176 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013177 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013178 return mSatelliteController.provisionSatelliteService(subId, token, provisionData,
13179 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013180 }
13181
13182 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013183 * Unregister the device/subscription with the satellite provider.
13184 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013185 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013186 * should report as deprovisioned.
13187 *
13188 * @param subId The subId of the subscription to be deprovisioned.
13189 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080013190 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013191 *
13192 * @throws SecurityException if the caller doesn't have the required permission.
13193 */
13194 @Override
13195 public void deprovisionSatelliteService(int subId,
13196 @NonNull String token, @NonNull IIntegerConsumer callback) {
13197 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013198 mSatelliteController.deprovisionSatelliteService(subId, token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013199 }
13200
13201 /**
Sarah Chin43457982023-02-15 17:50:38 -080013202 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013203 *
Sarah Chin43457982023-02-15 17:50:38 -080013204 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013205 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013206 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013207 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013208 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013209 * @throws SecurityException if the caller doesn't have the required permission.
13210 */
13211 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013212 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
13213 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013214 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013215 return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013216 }
13217
13218 /**
Sarah Chin43457982023-02-15 17:50:38 -080013219 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013220 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013221 *
Sarah Chin43457982023-02-15 17:50:38 -080013222 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013223 * @param callback The callback that was passed to
13224 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013225 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013226 * @throws SecurityException if the caller doesn't have the required permission.
13227 */
13228 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013229 public void unregisterForSatelliteProvisionStateChanged(
13230 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013231 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013232 mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013233 }
13234
13235 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013236 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013237 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013238 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013239 * @param result The result receiver that returns whether the device is provisioned with a
13240 * satellite provider if the request is successful or an error code if the
13241 * request failed.
13242 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013243 * @throws SecurityException if the caller doesn't have the required permission.
13244 */
13245 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013246 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
13247 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013248 mSatelliteController.requestIsSatelliteProvisioned(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013249 }
13250
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013251 /**
Sarah Chin43457982023-02-15 17:50:38 -080013252 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013253 *
Sarah Chin43457982023-02-15 17:50:38 -080013254 * @param subId The subId of the subscription to register for satellite modem state changed.
13255 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080013256 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013257 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013258 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013259 * @throws SecurityException if the caller doesn't have the required permission.
13260 */
13261 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013262 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013263 @NonNull ISatelliteModemStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080013264 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013265 return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013266 }
13267
13268 /**
Sarah Chin43457982023-02-15 17:50:38 -080013269 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013270 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013271 *
Sarah Chin43457982023-02-15 17:50:38 -080013272 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080013273 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013274 * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013275 *
13276 * @throws SecurityException if the caller doesn't have the required permission.
13277 */
13278 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013279 public void unregisterForModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013280 @NonNull ISatelliteModemStateCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013281 enforceSatelliteCommunicationPermission("unregisterForModemStateChanged");
13282 mSatelliteController.unregisterForModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013283 }
13284
13285 /**
13286 * Register to receive incoming datagrams over satellite.
13287 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013288 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Sarah Chindf715ec2023-02-13 13:46:24 -080013289 * @param callback The callback to handle incoming datagrams over satellite.
13290 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013291 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013292 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013293 * @throws SecurityException if the caller doesn't have the required permission.
13294 */
13295 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013296 @SatelliteManager.SatelliteResult public int registerForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013297 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013298 enforceSatelliteCommunicationPermission("registerForIncomingDatagram");
13299 return mSatelliteController.registerForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013300 }
13301
13302 /**
13303 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013304 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013305 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013306 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
13307 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013308 * {@link #registerForIncomingDatagram(int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013309 *
13310 * @throws SecurityException if the caller doesn't have the required permission.
13311 */
13312 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013313 public void unregisterForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013314 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013315 enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram");
13316 mSatelliteController.unregisterForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013317 }
13318
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013319 /**
13320 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013321 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013322 * This method requests modem to check if there are any pending datagrams to be received over
13323 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000013324 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080013325 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013326 * @param subId The subId of the subscription used for receiving datagrams.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013327 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013328 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013329 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013330 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013331 public void pollPendingDatagrams(int subId, IIntegerConsumer callback) {
13332 enforceSatelliteCommunicationPermission("pollPendingDatagrams");
13333 mSatelliteController.pollPendingDatagrams(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013334 }
13335
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013336 /**
13337 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013338 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013339 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
13340 * input to this method. Datagram received here will be passed down to modem without any
13341 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080013342 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013343 * @param subId The subId of the subscription to send satellite datagrams for.
13344 * @param datagramType datagram type indicating whether the datagram is of type
13345 * SOS_SMS or LOCATION_SHARING.
13346 * @param datagram encoded gateway datagram which is encrypted by the caller.
13347 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000013348 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
13349 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013350 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013351 *
13352 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013353 */
13354 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013355 public void sendDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000013356 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
13357 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013358 enforceSatelliteCommunicationPermission("sendDatagram");
13359 mSatelliteController.sendDatagram(subId, datagramType, datagram, needFullScreenPointingUI,
13360 callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013361 }
13362
Sarah Chindf715ec2023-02-13 13:46:24 -080013363 /**
13364 * Request to get whether satellite communication is allowed for the current location.
13365 *
13366 * @param subId The subId of the subscription to check whether satellite communication is
13367 * allowed for the current location for.
13368 * @param result The result receiver that returns whether satellite communication is allowed
13369 * for the current location if the request is successful or an error code
13370 * if the request failed.
13371 *
13372 * @throws SecurityException if the caller doesn't have the required permission.
13373 */
13374 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013375 public void requestIsCommunicationAllowedForCurrentLocation(int subId,
Sarah Chindf715ec2023-02-13 13:46:24 -080013376 @NonNull ResultReceiver result) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013377 enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation");
13378 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(subId,
13379 result);
Sarah Chindf715ec2023-02-13 13:46:24 -080013380 }
13381
13382 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013383 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080013384 *
Sarah Chin5f57c582023-02-14 04:16:10 -080013385 * @param subId The subId to get the time after which the satellite will be visible for.
13386 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080013387 * be visible if the request is successful or an error code if the request failed.
13388 *
13389 * @throws SecurityException if the caller doesn't have the required permission.
13390 */
13391 @Override
13392 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
13393 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013394 mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013395 }
13396
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013397 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013398 * Inform that Device is aligned to satellite for demo mode.
13399 *
13400 * @param subId The subId to get the time after which the satellite will be visible for.
13401 * @param isAligned {@code true} Device is aligned with the satellite for demo mode
13402 * {@code false} Device fails to align with the satellite for demo mode.
13403 *
13404 * @throws SecurityException if the caller doesn't have required permission.
13405 */
13406 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
13407
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013408 public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) {
Hakjun Choiae365972023-04-25 11:00:31 +000013409 enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite");
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013410 mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned);
Hakjun Choiae365972023-04-25 11:00:31 +000013411 }
13412
13413 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000013414 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
13415 * by modem.
13416 *
13417 * @param subId The subId of the subscription to request for.
13418 * @param reason Reason for disallowing satellite communication for carrier.
Hakjun Choif92ac752024-03-18 19:34:29 +000013419 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013420 * operation.
13421 *
13422 * @throws SecurityException if the caller doesn't have required permission.
13423 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013424 public void addAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013425 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13426 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013427 enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013428 final long identity = Binder.clearCallingIdentity();
13429 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013430 mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013431 } finally {
13432 Binder.restoreCallingIdentity(identity);
13433 }
13434 }
13435
13436 /**
13437 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
13438 * by modem.
13439 *
13440 * @param subId The subId of the subscription to request for.
13441 * @param reason Reason for disallowing satellite communication.
Hakjun Choif92ac752024-03-18 19:34:29 +000013442 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013443 * operation.
13444 *
13445 * @throws SecurityException if the caller doesn't have required permission.
13446 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013447 public void removeAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013448 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13449 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013450 enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013451 final long identity = Binder.clearCallingIdentity();
13452 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013453 mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013454 } finally {
13455 Binder.restoreCallingIdentity(identity);
13456 }
13457 }
13458
13459 /**
13460 * Get reasons for disallowing satellite communication, as requested by
Hakjun Choif92ac752024-03-18 19:34:29 +000013461 * {@link #addAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
Hakjun Choicb39db92023-07-14 15:51:12 +000013462 *
13463 * @param subId The subId of the subscription to request for.
13464 *
13465 * @return Integer array of reasons for disallowing satellite communication.
13466 *
13467 * @throws SecurityException if the caller doesn't have the required permission.
13468 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013469 public @NonNull int[] getAttachRestrictionReasonsForCarrier(
Hakjun Choicb39db92023-07-14 15:51:12 +000013470 int subId) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013471 enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013472 final long identity = Binder.clearCallingIdentity();
13473 try {
13474 Set<Integer> reasonSet =
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013475 mSatelliteController.getAttachRestrictionReasonsForCarrier(subId);
Hakjun Choicb39db92023-07-14 15:51:12 +000013476 return reasonSet.stream().mapToInt(i->i).toArray();
13477 } finally {
13478 Binder.restoreCallingIdentity(identity);
13479 }
13480 }
13481
13482 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000013483 * Request to get the signal strength of the satellite connection.
13484 *
13485 * @param subId The subId of the subscription to request for.
13486 * @param result Result receiver to get the error code of the request and the current signal
13487 * strength of the satellite connection.
13488 *
13489 * @throws SecurityException if the caller doesn't have required permission.
13490 */
13491 @Override
13492 public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) {
13493 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
13494 final long identity = Binder.clearCallingIdentity();
13495 try {
13496 mSatelliteController.requestNtnSignalStrength(subId, result);
13497 } finally {
13498 Binder.restoreCallingIdentity(identity);
13499 }
13500 }
13501
13502 /**
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013503 * Registers for NTN signal strength changed from satellite modem. If the registration operation
13504 * is not successful, a {@link ServiceSpecificException} that contains
13505 * {@link SatelliteManager.SatelliteResult} will be thrown.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013506 *
13507 * @param subId The subId of the subscription to request for.
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013508 * @param callback The callback to handle the NTN signal strength changed event. If the
13509 * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged(
13510 * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of
13511 * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial
13512 * network has changed.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013513 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013514 * @throws SecurityException If the caller doesn't have the required permission.
13515 * @throws ServiceSpecificException If the callback registration operation fails.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013516 */
13517 @Override
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013518 public void registerForNtnSignalStrengthChanged(int subId,
13519 @NonNull INtnSignalStrengthCallback callback) throws RemoteException {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013520 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
13521 final long identity = Binder.clearCallingIdentity();
13522 try {
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013523 mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013524 } finally {
13525 Binder.restoreCallingIdentity(identity);
13526 }
13527 }
13528
13529 /**
13530 * Unregisters for NTN signal strength changed from satellite modem.
13531 * If callback was not registered before, the request will be ignored.
13532 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013533 * @param subId The subId of the subscription to unregister for listening NTN signal strength
13534 * changed event.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013535 * @param callback The callback that was passed to
13536 * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)}
13537 *
13538 * @throws SecurityException if the caller doesn't have the required permission.
13539 */
13540 @Override
13541 public void unregisterForNtnSignalStrengthChanged(
13542 int subId, @NonNull INtnSignalStrengthCallback callback) {
13543 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
13544 final long identity = Binder.clearCallingIdentity();
13545 try {
13546 mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback);
13547 } finally {
13548 Binder.restoreCallingIdentity(identity);
13549 }
13550 }
13551
13552 /**
Hakjun Choi8d96a562023-10-26 15:01:40 +000013553 * Registers for satellite capabilities change event from the satellite service.
13554 *
13555 * @param subId The subId of the subscription to request for.
13556 * @param callback The callback to handle the satellite capabilities changed event.
13557 *
13558 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13559 *
13560 * @throws SecurityException if the caller doesn't have required permission.
13561 */
13562 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013563 @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged(
Hakjun Choi8d96a562023-10-26 15:01:40 +000013564 int subId, @NonNull ISatelliteCapabilitiesCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013565 enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013566 final long identity = Binder.clearCallingIdentity();
13567 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013568 return mSatelliteController.registerForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013569 } finally {
13570 Binder.restoreCallingIdentity(identity);
13571 }
13572 }
13573
13574 /**
13575 * Unregisters for satellite capabilities change event from the satellite service.
13576 * If callback was not registered before, the request will be ignored.
13577 *
13578 * @param subId The subId of the subscription to unregister for satellite capabilities change.
13579 * @param callback The callback that was passed to.
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013580 * {@link #registerForCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}.
Hakjun Choi8d96a562023-10-26 15:01:40 +000013581 *
13582 * @throws SecurityException if the caller doesn't have required permission.
13583 */
13584 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013585 public void unregisterForCapabilitiesChanged(int subId,
13586 @NonNull ISatelliteCapabilitiesCallback callback) {
13587 enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013588 final long identity = Binder.clearCallingIdentity();
13589 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013590 mSatelliteController.unregisterForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013591 } finally {
13592 Binder.restoreCallingIdentity(identity);
13593 }
13594 }
13595
13596 /**
Hakjun Choif92ac752024-03-18 19:34:29 +000013597 * Registers for the satellite supported state changed.
13598 *
13599 * @param subId The subId of the subscription to register for supported state changed.
13600 * @param callback The callback to handle the satellite supported state changed event.
13601 *
13602 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13603 *
13604 * @throws SecurityException if the caller doesn't have the required permission.
13605 */
13606 @Override
13607 @SatelliteManager.SatelliteResult public int registerForSatelliteSupportedStateChanged(
13608 int subId, @NonNull ISatelliteSupportedStateCallback callback) {
13609 enforceSatelliteCommunicationPermission("registerForSatelliteSupportedStateChanged");
13610 return mSatelliteController.registerForSatelliteSupportedStateChanged(subId, callback);
13611 }
13612
13613 /**
13614 * Unregisters for the satellite supported state changed.
13615 * If callback was not registered before, the request will be ignored.
13616 *
13617 * @param subId The subId of the subscription to unregister for supported state changed.
13618 * @param callback The callback that was passed to
13619 * {@link #registerForSatelliteSupportedStateChanged(int, ISatelliteSupportedStateCallback)}.
13620 *
13621 * @throws SecurityException if the caller doesn't have the required permission.
13622 */
13623 @Override
13624 public void unregisterForSatelliteSupportedStateChanged(
13625 int subId, @NonNull ISatelliteSupportedStateCallback callback) {
13626 enforceSatelliteCommunicationPermission("unregisterForSatelliteSupportedStateChanged");
13627 mSatelliteController.unregisterForSatelliteSupportedStateChanged(subId, callback);
13628 }
13629
13630 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013631 * This API can be used by only CTS to update satellite vendor service package name.
13632 *
13633 * @param servicePackageName The package name of the satellite vendor service.
13634 * @return {@code true} if the satellite vendor service is set successfully,
13635 * {@code false} otherwise.
13636 */
13637 public boolean setSatelliteServicePackageName(String servicePackageName) {
13638 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName);
13639 TelephonyPermissions.enforceShellOnly(
13640 Binder.getCallingUid(), "setSatelliteServicePackageName");
13641 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13642 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13643 "setSatelliteServicePackageName");
13644 return mSatelliteController.setSatelliteServicePackageName(servicePackageName);
13645 }
13646
13647 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070013648 * This API can be used by only CTS to update satellite gateway service package name.
13649 *
13650 * @param servicePackageName The package name of the satellite gateway service.
13651 * @return {@code true} if the satellite gateway service is set successfully,
13652 * {@code false} otherwise.
13653 */
13654 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
13655 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
13656 TelephonyPermissions.enforceShellOnly(
13657 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
13658 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13659 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13660 "setSatelliteGatewayServicePackageName");
13661 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
13662 }
13663
13664 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070013665 * This API can be used by only CTS to update satellite pointing UI app package and class names.
13666 *
13667 * @param packageName The package name of the satellite pointing UI app.
13668 * @param className The class name of the satellite pointing UI app.
13669 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
13670 * {@code false} otherwise.
13671 */
13672 public boolean setSatellitePointingUiClassName(
13673 @Nullable String packageName, @Nullable String className) {
13674 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
13675 + ", className=" + className);
13676 TelephonyPermissions.enforceShellOnly(
13677 Binder.getCallingUid(), "setSatellitePointingUiClassName");
13678 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13679 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13680 "setSatelliteGatewayServicePackageName");
13681 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
13682 }
13683
13684 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070013685 * This API can be used by only CTS to update the timeout duration in milliseconds that
13686 * satellite should stay at listening mode to wait for the next incoming page before disabling
13687 * listening mode.
13688 *
13689 * @param timeoutMillis The timeout duration in millisecond.
13690 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13691 */
13692 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
13693 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
13694 TelephonyPermissions.enforceShellOnly(
13695 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
13696 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13697 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13698 "setSatelliteListeningTimeoutDuration");
13699 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
13700 }
13701
13702 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013703 * This API can be used by only CTS to override the timeout durations used by the
13704 * DatagramController module.
Hakjun Choiae365972023-04-25 11:00:31 +000013705 *
13706 * @param timeoutMillis The timeout duration in millisecond.
13707 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13708 */
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013709 public boolean setDatagramControllerTimeoutDuration(
13710 boolean reset, int timeoutType, long timeoutMillis) {
13711 Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset="
13712 + reset + ", timeoutMillis=" + timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013713 TelephonyPermissions.enforceShellOnly(
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013714 Binder.getCallingUid(), "setDatagramControllerTimeoutDuration");
Hakjun Choiae365972023-04-25 11:00:31 +000013715 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13716 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013717 "setDatagramControllerTimeoutDuration");
13718 return mSatelliteController.setDatagramControllerTimeoutDuration(
13719 reset, timeoutType, timeoutMillis);
13720 }
13721
13722 /**
Aishwarya Mallampati65d60ab2024-05-17 22:47:04 +000013723 * This API can be used by only CTS to override the boolean configs used by the
13724 * DatagramController module.
13725 *
13726 * @param enable Whether to enable or disable boolean config.
13727 * @return {@code true} if the boolean config is set successfully, {@code false} otherwise.
13728 */
13729 public boolean setDatagramControllerBooleanConfig(
13730 boolean reset, int booleanType, boolean enable) {
13731 Log.d(LOG_TAG, "setDatagramControllerBooleanConfig: booleanType=" + booleanType
13732 + ", reset=" + reset + ", enable=" + enable);
13733 TelephonyPermissions.enforceShellOnly(
13734 Binder.getCallingUid(), "setDatagramControllerBooleanConfig");
13735 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13736 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13737 "ssetDatagramControllerBooleanConfig");
13738 return mSatelliteController.setDatagramControllerBooleanConfig(reset, booleanType, enable);
13739 }
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 * SatelliteController module.
13745 *
13746 * @param timeoutMillis The timeout duration in millisecond.
13747 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13748 */
13749 public boolean setSatelliteControllerTimeoutDuration(
13750 boolean reset, int timeoutType, long timeoutMillis) {
13751 Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset="
13752 + reset + ", timeoutMillis=" + timeoutMillis);
13753 TelephonyPermissions.enforceShellOnly(
13754 Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration");
13755 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13756 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13757 "setSatelliteControllerTimeoutDuration");
13758 return mSatelliteController.setSatelliteControllerTimeoutDuration(
13759 reset, timeoutType, timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013760 }
13761
13762 /**
Thomas Nguyen11a051f2023-10-25 10:14:55 -070013763 * This API can be used in only testing to override connectivity status in monitoring emergency
13764 * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.
13765 *
13766 * @param handoverType The type of handover from emergency call to satellite messaging. Use one
13767 * of the following values to enable the override:
13768 * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS
13769 * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911
13770 * To disable the override, use -1 for handoverType.
13771 * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer
13772 * delaySeconds after the emergency call starts.
13773 * @return {@code true} if the handover type is set successfully, {@code false} otherwise.
13774 */
13775 public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) {
13776 Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType);
13777 TelephonyPermissions.enforceShellOnly(
13778 Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType");
13779 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13780 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13781 "setEmergencyCallToSatelliteHandoverType");
13782 return mSatelliteController.setEmergencyCallToSatelliteHandoverType(
13783 handoverType, delaySeconds);
13784 }
13785
13786 /**
Thomas Nguyen3d602742024-01-19 11:29:35 -080013787 * This API can be used in only testing to override oem-enabled satellite provision status.
13788 *
13789 * @param reset {@code true} mean the overriding status should not be used, {@code false}
13790 * otherwise.
13791 * @param isProvisioned The overriding provision status.
13792 * @return {@code true} if the provision status is set successfully, {@code false} otherwise.
13793 */
13794 public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) {
13795 Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset
13796 + ", isProvisioned=" + isProvisioned);
13797 TelephonyPermissions.enforceShellOnly(
13798 Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus");
13799 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13800 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13801 "setOemEnabledSatelliteProvisionStatus");
13802 return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned);
13803 }
13804
13805 /**
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013806 * This API should be used by only CTS tests to forcefully set telephony country codes.
13807 *
13808 * @return {@code true} if the country code is set successfully, {@code false} otherwise.
13809 */
13810 public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes,
13811 Map cachedNetworkCountryCodes, String locationCountryCode,
13812 long locationCountryCodeTimestampNanos) {
13813 Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes="
13814 + String.join(", ", currentNetworkCountryCodes)
13815 + ", locationCountryCode=" + locationCountryCode
13816 + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos
13817 + ", reset=" + reset + ", cachedNetworkCountryCodes="
13818 + String.join(", ", cachedNetworkCountryCodes.keySet()));
13819 TelephonyPermissions.enforceShellOnly(
13820 Binder.getCallingUid(), "setCachedLocationCountryCode");
13821 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13822 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13823 "setCachedLocationCountryCode");
13824 return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext()).setCountryCodes(
13825 reset, currentNetworkCountryCodes, cachedNetworkCountryCodes, locationCountryCode,
13826 locationCountryCodeTimestampNanos);
13827 }
13828
13829 /**
13830 * This API should be used by only CTS tests to override the overlay configs of satellite
13831 * access controller.
13832 *
13833 * @param reset {@code true} mean the overridden configs should not be used, {@code false}
13834 * otherwise.
13835 * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise.
13836 */
13837 public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed,
13838 String s2CellFile, long locationFreshDurationNanos,
13839 List<String> satelliteCountryCodes) {
13840 Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset
13841 + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile
13842 + ", locationFreshDurationNanos=" + locationFreshDurationNanos
13843 + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null)
13844 ? String.join(", ", satelliteCountryCodes) : null));
13845 TelephonyPermissions.enforceShellOnly(
13846 Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs");
13847 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13848 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13849 "setSatelliteAccessControlOverlayConfigs");
13850 return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset, isAllowed,
13851 s2CellFile, locationFreshDurationNanos, satelliteCountryCodes);
13852 }
13853
13854 /**
Hakjun Choibc6ce992023-11-07 16:04:33 +000013855 * This API can be used by only CTS to override the cached value for the device overlay config
13856 * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether
13857 * outgoing satellite datagrams should be sent to modem in demo mode.
13858 *
13859 * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to
13860 * satellite modem or not.
13861 *
13862 * @return {@code true} if the operation is successful, {@code false} otherwise.
13863 */
13864 public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) {
13865 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
13866 Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is "
13867 + "disabled");
13868 return false;
13869 }
13870 Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode");
13871 TelephonyPermissions.enforceShellOnly(
13872 Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode");
13873 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13874 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13875 "setShouldSendDatagramToModemInDemoMode");
13876 return mSatelliteController.setShouldSendDatagramToModemInDemoMode(
13877 shouldSendToModemInDemoMode);
13878 }
13879
13880 /**
Hunsuk Choi13078be2023-09-13 10:55:21 +000013881 * Sets the service defined in ComponentName to be bound.
13882 *
13883 * This should only be used for testing.
13884 * @return {@code true} if the DomainSelectionService to bind to was set,
13885 * {@code false} otherwise.
13886 */
13887 @Override
13888 public boolean setDomainSelectionServiceOverride(ComponentName componentName) {
13889 Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName);
13890
13891 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
13892 "setDomainSelectionServiceOverride");
13893 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13894 getDefaultSubscription(), "setDomainSelectionServiceOverride");
13895
13896 final long identity = Binder.clearCallingIdentity();
13897 try {
13898 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13899 return DomainSelectionResolver.getInstance()
13900 .setDomainSelectionServiceOverride(componentName);
13901 }
13902 } finally {
13903 Binder.restoreCallingIdentity(identity);
13904 }
13905 return false;
13906 }
13907
13908 /**
13909 * Clears the DomainSelectionService override.
13910 *
13911 * This should only be used for testing.
13912 * @return {@code true} if the DomainSelectionService override was cleared,
13913 * {@code false} otherwise.
13914 */
13915 @Override
13916 public boolean clearDomainSelectionServiceOverride() {
13917 Log.i(LOG_TAG, "clearDomainSelectionServiceOverride");
13918
13919 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
13920 "clearDomainSelectionServiceOverride");
13921 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13922 getDefaultSubscription(), "clearDomainSelectionServiceOverride");
13923
13924 final long identity = Binder.clearCallingIdentity();
13925 try {
13926 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13927 return DomainSelectionResolver.getInstance()
13928 .clearDomainSelectionServiceOverride();
13929 }
13930 } finally {
13931 Binder.restoreCallingIdentity(identity);
13932 }
13933 return false;
13934 }
13935
13936 /**
Gil Cukierman06403e12023-11-29 16:33:03 +000013937 * Enable or disable notifications sent for cellular identifier disclosure events.
13938 *
13939 * Disclosure events are defined as instances where a device has sent a cellular identifier
13940 * on the Non-access stratum (NAS) before a security context is established. As a result the
13941 * identifier is sent in the clear, which has privacy implications for the user.
13942 *
13943 * @param enable if notifications about disclosure events should be enabled
13944 * @throws SecurityException if the caller does not have the required privileges
13945 * @throws UnsupportedOperationException if the modem does not support this feature.
13946 */
13947 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000013948 public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) {
Gil Cukierman06403e12023-11-29 16:33:03 +000013949 enforceModifyPermission();
13950 checkForIdentifierDisclosureNotificationSupport();
13951
13952 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
13953 editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable);
13954 editor.apply();
13955
13956 // Each phone instance is responsible for updating its respective modem immediately
13957 // after we've made a preference change.
13958 for (Phone phone : PhoneFactory.getPhones()) {
13959 phone.handleIdentifierDisclosureNotificationPreferenceChange();
13960 }
13961 }
13962
13963 /**
13964 * Get whether or not cellular identifier disclosure notifications are enabled.
13965 *
13966 * @throws SecurityException if the caller does not have the required privileges
13967 * @throws UnsupportedOperationException if the modem does not support this feature.
13968 */
13969 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000013970 public boolean isCellularIdentifierDisclosureNotificationsEnabled() {
Gil Cukierman06403e12023-11-29 16:33:03 +000013971 enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled");
13972 checkForIdentifierDisclosureNotificationSupport();
13973 return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled();
13974 }
13975
13976 /**
Michael Groover826b71d2023-12-21 22:08:06 -060013977 * Enables or disables notifications sent when cellular null cipher or integrity algorithms
13978 * are in use by the cellular modem.
13979 *
13980 * @throws IllegalStateException if the Telephony process is not currently available
13981 * @throws SecurityException if the caller does not have the required privileges
13982 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
13983 * and integrity algorithms in use
13984 * @hide
13985 */
13986 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Michael Grooverae447b22024-01-24 22:35:46 -060013987 public void setNullCipherNotificationsEnabled(boolean enable) {
Michael Groover826b71d2023-12-21 22:08:06 -060013988 enforceModifyPermission();
13989 checkForNullCipherNotificationSupport();
13990
13991 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
13992 editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable);
13993 editor.apply();
13994
13995 // Each phone instance is responsible for updating its respective modem immediately
13996 // after a preference change.
13997 for (Phone phone : PhoneFactory.getPhones()) {
13998 phone.handleNullCipherNotificationPreferenceChanged();
13999 }
14000 }
14001
14002 /**
14003 * Get whether notifications are enabled for null cipher or integrity algorithms in use by the
14004 * cellular modem.
14005 *
14006 * @throws IllegalStateException if the Telephony process is not currently available
14007 * @throws SecurityException if the caller does not have the required privileges
14008 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14009 * and integrity algorithms in use
14010 * @hide
14011 */
14012 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
14013 public boolean isNullCipherNotificationsEnabled() {
14014 enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled");
14015 checkForNullCipherNotificationSupport();
14016 return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled();
14017 }
14018
14019 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000014020 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
14021 *
14022 * <p>This method behaves in one of the following ways:
14023 * <ul>
14024 * <li>return true : if the calling package has the appop permission {@link
14025 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
14026 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
14027 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
14028 * Owner device identifier access check, or the calling package has carrier privileges</>
14029 * <li>throw SecurityException: if the caller does not meet any of the requirements.
14030 * </ul>
14031 */
14032 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
14033 String callingPackage, @Nullable String callingFeatureId, String message) {
14034 for (Phone phone : PhoneFactory.getPhones()) {
14035 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
14036 phone.getSubId(), callingPackage, callingFeatureId, message)) {
14037 return true;
14038 }
14039 }
14040 return false;
14041 }
arunvoddud7401012022-12-15 16:08:12 +000014042
14043 /**
Jack Yufa8ed012023-02-11 15:42:28 -080014044 * @return The subscription manager service instance.
14045 */
14046 public SubscriptionManagerService getSubscriptionManagerService() {
14047 return SubscriptionManagerService.getInstance();
14048 }
14049
14050 /**
arunvoddud7401012022-12-15 16:08:12 +000014051 * Class binds the consumer[callback] and carrierId.
14052 */
14053 private static class CallerCallbackInfo {
14054 private final Consumer<Integer> mConsumer;
14055 private final int mCarrierId;
14056
14057 public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) {
14058 mConsumer = consumer;
14059 mCarrierId = carrierId;
14060 }
14061
14062 public Consumer<Integer> getConsumer() {
14063 return mConsumer;
14064 }
14065
14066 public int getCarrierId() {
14067 return mCarrierId;
14068 }
14069 }
joonhunshin4ac60942023-11-15 15:23:39 +000014070
14071 /*
14072 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14073 * But the context that is passed in is unused if the phone app is already alive.
14074 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14075 */
14076 @VisibleForTesting
14077 public void setPackageManager(PackageManager packageManager) {
14078 mPackageManager = packageManager;
14079 }
14080
14081 /*
14082 * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags.
14083 * But the FeatureFlags that is passed in is unused if the phone app is already alive.
14084 * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test.
14085 */
14086 @VisibleForTesting
14087 public void setFeatureFlags(FeatureFlags featureFlags) {
14088 mFeatureFlags = featureFlags;
14089 }
14090
14091 /**
14092 * Make sure the device has required telephony feature
14093 *
14094 * @throws UnsupportedOperationException if the device does not have required telephony feature
14095 */
14096 private void enforceTelephonyFeatureWithException(@Nullable String callingPackage,
14097 @NonNull String telephonyFeature, @NonNull String methodName) {
14098 if (callingPackage == null || mPackageManager == null) {
14099 return;
14100 }
14101
14102 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
14103 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage,
14104 Binder.getCallingUserHandle())) {
14105 return;
14106 }
14107
14108 if (!mPackageManager.hasSystemFeature(telephonyFeature)) {
14109 throw new UnsupportedOperationException(
14110 methodName + " is unsupported without " + telephonyFeature);
14111 }
14112 }
youngtaecha5d483d52024-04-29 17:05:45 +000014113
14114 /**
14115 * Registers for the satellite communication allowed state changed.
14116 *
14117 * @param subId The subId of the subscription to register for the satellite communication
14118 * allowed state changed.
14119 * @param callback The callback to handle the satellite communication allowed
14120 * state changed event.
14121 *
14122 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
14123 *
14124 * @throws SecurityException if the caller doesn't have the required permission.
14125 */
14126 @Override
14127 @SatelliteManager.SatelliteResult public int registerForCommunicationAllowedStateChanged(
14128 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14129 enforceSatelliteCommunicationPermission("registerForCommunicationAllowedStateChanged");
14130 return mSatelliteAccessController.registerForCommunicationAllowedStateChanged(
14131 subId, callback);
14132 }
14133
14134 /**
14135 * Unregisters for the satellite communication allowed state changed.
14136 * If callback was not registered before, the request will be ignored.
14137 *
14138 * @param subId The subId of the subscription to unregister for the satellite communication
14139 * allowed state changed.
14140 * @param callback The callback that was passed to
14141 * {@link #registerForCommunicationAllowedStateChanged(int,
14142 * ISatelliteCommunicationAllowedStateCallback)}. *
14143 * @throws SecurityException if the caller doesn't have the required permission.
14144 */
14145 @Override
14146 public void unregisterForCommunicationAllowedStateChanged(
14147 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14148 enforceSatelliteCommunicationPermission("unregisterForCommunicationAllowedStateChanged");
14149 mSatelliteAccessController.unregisterForCommunicationAllowedStateChanged(subId, callback);
14150 }
Aishwarya Mallampatif265cea2024-06-04 19:55:41 +000014151
14152 /**
14153 * Request to get the {@link SatelliteSessionStats} of the satellite service.
14154 *
14155 * @param subId The subId of the subscription to the satellite session stats for.
14156 * @param result The result receiver that returns the {@link SatelliteSessionStats}
14157 * if the request is successful or an error code if the request failed.
14158 *
14159 * @throws SecurityException if the caller doesn't have required permission.
14160 */
14161 @Override
14162 public void requestSatelliteSessionStats(int subId, @NonNull ResultReceiver result) {
14163 enforceModifyPermission();
14164 enforcePackageUsageStatsPermission("requestSatelliteSessionStats");
14165 mSatelliteController.requestSatelliteSessionStats(subId, result);
14166 }
Jack Yufa8ed012023-02-11 15:42:28 -080014167}