blob: 2d149d53440fd51621cb734496e3dd61ed519620 [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;
28import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_SUCCESS;
Hall Liud892bec2018-11-30 14:51:45 -080029
Shuo Qianccbaf742021-02-22 18:32:21 -080030import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
31import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070032import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070033import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000034import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070035
Brad Ebinger34c09a52021-02-17 23:23:21 +000036import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080037import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080038import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070039import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000040import android.annotation.RequiresPermission;
Sarah Chin532d6bb2022-12-28 22:50:43 -080041import android.app.ActivityManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080043import android.app.PendingIntent;
Tyler Gunn64144d92022-03-17 14:16:41 -070044import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000045import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080046import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000047import android.compat.annotation.ChangeId;
48import android.compat.annotation.EnabledSince;
Anthony Alridge70ba5572023-05-02 12:14:14 +000049import android.content.ActivityNotFoundException;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070050import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070051import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070052import android.content.Context;
53import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070054import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070055import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070056import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070057import android.net.Uri;
58import android.os.AsyncResult;
59import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080060import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070061import android.os.Bundle;
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080062import android.os.DropBoxManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070063import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070064import android.os.IBinder;
Thomas Nguyen8ee49682023-02-01 11:46:09 -080065import android.os.ICancellationSignal;
tom hsu0b59d292022-09-29 23:49:21 +080066import android.os.LocaleList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070067import android.os.Looper;
68import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070069import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080070import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070071import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070072import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080073import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080074import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070075import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070076import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080077import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070078import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070079import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070080import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070081import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070082import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080083import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070084import android.provider.Telephony;
arunvoddud7401012022-12-15 16:08:12 +000085import android.service.carrier.CarrierIdentifier;
Inseob Kim14bb3d02018-12-13 17:11:34 +090086import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080087import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080088import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070089import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080090import android.telephony.AccessNetworkConstants;
91import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070092import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070093import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080094import android.telephony.Annotation.ThermalMitigationResult;
Sarah Chin2ec39f62022-08-31 17:03:26 -070095import android.telephony.AnomalyReporter;
Shuo Qian4a594052020-01-23 11:59:30 -080096import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070097import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080098import android.telephony.CarrierRestrictionRules;
Hui Wang9b5793a2022-12-05 14:38:06 -060099import android.telephony.CellBroadcastIdRange;
yincheng zhao2737e882019-09-06 17:06:54 -0700100import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -0800101import android.telephony.CellIdentityCdma;
102import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700103import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -0700104import android.telephony.CellInfoGsm;
105import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700106import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800107import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -0700108import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700109import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700110import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -0800111import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700112import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -0800113import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -0700114import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -0800115import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800116import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700117import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800118import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700119import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800120import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800121import android.telephony.SignalStrengthUpdateRequest;
122import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800123import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800124import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800125import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700126import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700127import android.telephony.TelephonyManager;
Jack Yuf5badd92022-12-08 00:50:53 -0800128import android.telephony.TelephonyManager.SimState;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800129import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800130import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800131import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000132import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000133import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000134import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700135import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700136import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800137import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800138import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700139import android.telephony.gba.GbaAuthRequest;
140import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700141import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800142import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000143import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000144import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700145import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000146import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700147import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800148import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700149import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800150import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700151import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000152import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700153import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800154import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800155import android.telephony.ims.stub.ImsRegistrationImplBase;
Hakjun Choifa3e6172023-09-22 03:56:34 +0000156import android.telephony.satellite.INtnSignalStrengthCallback;
Hakjun Choi8d96a562023-10-26 15:01:40 +0000157import android.telephony.satellite.ISatelliteCapabilitiesCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800158import android.telephony.satellite.ISatelliteDatagramCallback;
Hakjun Choid4a52a22023-12-13 09:48:24 +0000159import android.telephony.satellite.ISatelliteModemStateCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800160import android.telephony.satellite.ISatelliteProvisionStateCallback;
Sarah Chinabf081b2023-03-09 23:00:57 -0800161import android.telephony.satellite.ISatelliteTransmissionUpdateCallback;
Hakjun Choi4c3668a2023-12-05 11:55:36 +0000162import android.telephony.satellite.NtnSignalStrength;
163import android.telephony.satellite.NtnSignalStrengthCallback;
Sarah Chin503828c2023-02-01 23:54:20 -0800164import android.telephony.satellite.SatelliteCapabilities;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000165import android.telephony.satellite.SatelliteDatagram;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800166import android.telephony.satellite.SatelliteDatagramCallback;
Sarah Chineccfbd12023-01-20 19:00:35 -0800167import android.telephony.satellite.SatelliteManager;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800168import android.telephony.satellite.SatelliteProvisionStateCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700169import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800170import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700171import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700172import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800173import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800174
Andrew Lee312e8172014-10-23 17:01:36 -0700175import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800176import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800177import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800178import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800179import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700180import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700181import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700182import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800183import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800184import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700185import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700186import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800187import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700188import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800189import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800190import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800191import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700192import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000193import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700194import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800195import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700196import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800197import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800198import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800199import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700200import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700201import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700202import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700203import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700204import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800205import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700206import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700207import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700208import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700209import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800210import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800211import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700212import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000213import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700214import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700215import com.android.internal.telephony.SmsPermissions;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800216import com.android.internal.telephony.TelephonyCountryDetector;
Peter Wang59571be2020-01-27 12:35:15 +0800217import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800218import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700219import com.android.internal.telephony.data.DataUtils;
Hunsuk Choi42cc62a2022-10-16 06:03:40 +0000220import com.android.internal.telephony.domainselection.DomainSelectionResolver;
sqianf4ca7ed2019-01-15 18:32:07 -0800221import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700222import com.android.internal.telephony.euicc.EuiccConnector;
Sarah Chincc5446f2023-10-23 17:57:19 -0700223import com.android.internal.telephony.flags.FeatureFlags;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800224import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700225import com.android.internal.telephony.imsphone.ImsPhone;
226import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000227import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800228import com.android.internal.telephony.metrics.TelephonyMetrics;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000229import com.android.internal.telephony.satellite.SatelliteController;
Jack Yu285100e2022-12-02 22:48:35 -0800230import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
231import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700232import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700233import com.android.internal.telephony.uicc.IccIoResult;
234import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800235import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700236import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800237import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700238import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000239import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800240import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000241import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800242import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000243import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700244import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700245import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800246import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800247import com.android.phone.callcomposer.CallComposerPictureManager;
248import com.android.phone.callcomposer.CallComposerPictureTransfer;
249import com.android.phone.callcomposer.ImageData;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800250import com.android.phone.satellite.accesscontrol.SatelliteAccessController;
Hyosun Kim240214a2023-11-02 13:30:15 +0000251import com.android.phone.satellite.entitlement.SatelliteEntitlementController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700252import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700253import com.android.phone.slice.SlicePurchaseController;
arunvoddud7401012022-12-15 16:08:12 +0000254import com.android.phone.utils.CarrierAllowListInfo;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700255import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800256import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700257import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700258import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800259import com.android.services.telephony.TelecomAccountRegistry;
260import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800261import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800262
Hall Liu82694d52020-12-11 18:22:04 -0800263import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700264import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800265import java.io.IOException;
266import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700267import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700268import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800269import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000270import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800271import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800272import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800273import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800274import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100275import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800276import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700277import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800278import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800279import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700280import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800281import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800282import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800283import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700284
285/**
286 * Implementation of the ITelephony interface.
287 */
Santos Cordon117fee72014-05-16 17:56:12 -0700288public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700289 private static final String LOG_TAG = "PhoneInterfaceManager";
290 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
291 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800292 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700293
294 // Message codes used with mMainThreadHandler
295 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700296 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
297 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700298 private static final int CMD_OPEN_CHANNEL = 9;
299 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
300 private static final int CMD_CLOSE_CHANNEL = 11;
301 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800302 private static final int CMD_NV_READ_ITEM = 13;
303 private static final int EVENT_NV_READ_ITEM_DONE = 14;
304 private static final int CMD_NV_WRITE_ITEM = 15;
305 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
306 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
307 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700308 private static final int CMD_RESET_MODEM_CONFIG = 19;
309 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800310 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
311 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800312 private static final int CMD_SEND_ENVELOPE = 25;
313 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700314 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
315 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
316 private static final int CMD_EXCHANGE_SIM_IO = 31;
317 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800318 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
319 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700320 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
321 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700322 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
323 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700324 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
325 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
326 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
327 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700328 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
329 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
330 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
331 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700332 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800333 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
334 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000335 private static final int CMD_SWITCH_SLOTS = 50;
336 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700337 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
338 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
339 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
340 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
341 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
342 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
343 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
344 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700345 private static final int CMD_GET_ALL_CELL_INFO = 60;
346 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
347 private static final int CMD_GET_CELL_LOCATION = 62;
348 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700349 private static final int CMD_MODEM_REBOOT = 64;
350 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700351 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
352 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800353 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
354 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700355 private static final int CMD_GET_MODEM_STATUS = 70;
356 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700357 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
358 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700359 private static final int CMD_ERASE_MODEM_CONFIG = 74;
360 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800361 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
362 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
363 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
364 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800365 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
366 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800367 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800368 private static final int CMD_GET_CALL_FORWARDING = 83;
369 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
370 private static final int CMD_SET_CALL_FORWARDING = 85;
371 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
372 private static final int CMD_GET_CALL_WAITING = 87;
373 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
374 private static final int CMD_SET_CALL_WAITING = 89;
375 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700376 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
377 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
378 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
379 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700380 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
381 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800382 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
383 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800384 private static final int CMD_SET_DATA_THROTTLING = 99;
385 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800386 private static final int CMD_SET_SIM_POWER = 101;
387 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800388 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
389 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
390 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
391 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800392 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
393 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000394 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800395 private static final int CMD_GET_SLICING_CONFIG = 110;
396 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800397 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700398 private static final int CMD_ENABLE_VONR = 113;
399 private static final int EVENT_ENABLE_VONR_DONE = 114;
400 private static final int CMD_IS_VONR_ENABLED = 115;
401 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700402 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
403 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000404
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800405 // Parameters of select command.
406 private static final int SELECT_COMMAND = 0xA4;
407 private static final int SELECT_P1 = 0x04;
408 private static final int SELECT_P2 = 0;
409 private static final int SELECT_P3 = 0x10;
410
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000411 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
412 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
Gil Cukierman06403e12023-11-29 16:33:03 +0000413 // Cellular identifier disclosure transparency was added in IRadioNetwork 2.2
414 private static final int MIN_IDENTIFIER_DISCLOSURE_VERSION = 202;
Michael Groover826b71d2023-12-21 22:08:06 -0600415 // Null cipher notification support was added in IRadioNetwork 2.2
416 private static final int MIN_NULL_CIPHER_NOTIFICATION_VERSION = 202;
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000417
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700418 /** The singleton instance. */
419 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800420 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700421
Sarah Chin4beb2b72023-02-14 14:47:54 -0800422 private final PhoneGlobals mApp;
joonhunshin4ac60942023-11-15 15:23:39 +0000423 private FeatureFlags mFeatureFlags;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800424 private final CallManager mCM;
425 private final ImsResolver mImsResolver;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000426
427 private final SatelliteController mSatelliteController;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800428 private final SatelliteAccessController mSatelliteAccessController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800429 private final UserManager mUserManager;
430 private final AppOpsManager mAppOps;
431 private final MainThreadHandler mMainThreadHandler;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800432 private final SharedPreferences mTelephonySharedPreferences;
433 private final PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800434 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
joonhunshin4ac60942023-11-15 15:23:39 +0000435 private PackageManager mPackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700436
Peter Wangdafb9ac2020-01-15 14:13:38 -0800437 /** User Activity */
Sarah Chin4beb2b72023-02-14 14:47:54 -0800438 private final AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800439 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800440 private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800441
Derek Tan97ebb422014-09-05 16:55:38 -0700442 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
443 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800444 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800445 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700446
Michelecea4cf22018-12-21 15:00:11 -0800447 // String to store multi SIM allowed
448 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
449
Derek Tan740e1672017-06-27 14:56:27 -0700450 // The AID of ISD-R.
451 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
452
yinxub1bed742017-04-17 11:45:04 -0700453 private NetworkScanRequestTracker mNetworkScanRequestTracker;
454
David Kelly5e06a7f2018-03-12 14:10:59 +0000455 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
456 private static final int MANUFACTURER_CODE_LENGTH = 8;
457
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800458 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800459 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800460
Sarah Chin2ec39f62022-08-31 17:03:26 -0700461 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
462 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
463
Derek Tan89e89d42014-07-08 17:00:10 -0700464 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700465 * Experiment flag to enable erase modem config on reset network, default value is false
466 */
467 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
468 "reset_network_erase_modem_config_enabled";
469
Rambo Wang0f050d82021-02-12 11:43:36 -0800470 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800471
Gary Jian76280a42022-12-07 16:18:33 +0800472 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
473
sandeepjsb6c87872021-09-27 15:34:44 +0000474 /**
475 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
476 * one ICCID active at the same time.
477 * Apps should use below API signatures if targeting SDK is T and beyond.
478 *
479 * @hide
480 */
481 @ChangeId
482 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
483 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800484
Naina Nallurid63128d2019-09-17 14:10:30 -0700485 /**
Chen Xu540470b2021-12-14 17:15:47 -0800486 * Apps targeting on Android T and beyond will get exception whenever icc close channel
487 * operation fails.
488 */
489 @ChangeId
490 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
491 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
492
493 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700494 * A request object to use for transmitting data to an ICC.
495 */
496 private static final class IccAPDUArgument {
497 public int channel, cla, command, p1, p2, p3;
498 public String data;
499
500 public IccAPDUArgument(int channel, int cla, int command,
501 int p1, int p2, int p3, String data) {
502 this.channel = channel;
503 this.cla = cla;
504 this.command = command;
505 this.p1 = p1;
506 this.p2 = p2;
507 this.p3 = p3;
508 this.data = data;
509 }
510 }
511
512 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700513 * A request object to use for transmitting data to an ICC.
514 */
515 private static final class ManualNetworkSelectionArgument {
516 public OperatorInfo operatorInfo;
517 public boolean persistSelection;
518
519 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
520 this.operatorInfo = operatorInfo;
521 this.persistSelection = persistSelection;
522 }
523 }
524
Sarah Chin71b3a852022-09-28 15:54:19 -0700525 private static final class PurchasePremiumCapabilityArgument {
526 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700527 public @NonNull IIntegerConsumer callback;
528
529 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800530 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700531 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700532 this.callback = callback;
533 }
534 }
535
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700536 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700537 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
538 * request after sending. The main thread will notify the request when it is complete.
539 */
540 private static final class MainThreadRequest {
541 /** The argument to use for the request */
542 public Object argument;
543 /** The result of the request that is run on the main thread */
544 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800545 // The subscriber id that this request applies to. Defaults to
546 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
547 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700548
Nathan Harold92bed182018-10-12 18:16:49 -0700549 // In cases where subId is unavailable, the caller needs to specify the phone.
550 public Phone phone;
551
vagdeviaf9a5b92018-08-15 16:01:53 -0700552 public WorkSource workSource;
553
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700554 public MainThreadRequest(Object argument) {
555 this.argument = argument;
556 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800557
Nathan Harold92bed182018-10-12 18:16:49 -0700558 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
559 this.argument = argument;
560 if (phone != null) {
561 this.phone = phone;
562 }
563 this.workSource = workSource;
564 }
565
vagdeviaf9a5b92018-08-15 16:01:53 -0700566 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800567 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800568 if (subId != null) {
569 this.subId = subId;
570 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700571 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800572 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700573 }
574
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800575 private static final class IncomingThirdPartyCallArgs {
576 public final ComponentName component;
577 public final String callId;
578 public final String callerDisplayName;
579
580 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
581 String callerDisplayName) {
582 this.component = component;
583 this.callId = callId;
584 this.callerDisplayName = callerDisplayName;
585 }
586 }
587
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700588 /**
589 * A handler that processes messages on the main thread in the phone process. Since many
590 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
591 * inbound binder threads to the main thread in the phone process. The Binder thread
592 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
593 * on, which will be notified when the operation completes and will contain the result of the
594 * request.
595 *
596 * <p>If a MainThreadRequest object is provided in the msg.obj field,
597 * note that request.result must be set to something non-null for the calling thread to
598 * unblock.
599 */
600 private final class MainThreadHandler extends Handler {
601 @Override
602 public void handleMessage(Message msg) {
603 MainThreadRequest request;
604 Message onCompleted;
605 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000606 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700607 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800608 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700609
610 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700611 case CMD_HANDLE_USSD_REQUEST: {
612 request = (MainThreadRequest) msg.obj;
613 final Phone phone = getPhoneFromRequest(request);
614 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800615 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700616 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700617
Pengquan Menga1bb6272018-09-06 09:59:22 -0700618 if (!isUssdApiAllowed(request.subId)) {
619 // Carrier does not support use of this API, return failure.
620 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
621 UssdResponse response = new UssdResponse(ussdRequest, null);
622 Bundle returnData = new Bundle();
623 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
624 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700625
Pengquan Menga1bb6272018-09-06 09:59:22 -0700626 request.result = true;
627 notifyRequester(request);
628 return;
629 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700630
Pengquan Menga1bb6272018-09-06 09:59:22 -0700631 try {
632 request.result = phone != null
633 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
634 } catch (CallStateException cse) {
635 request.result = false;
636 }
637 // Wake up the requesting thread
638 notifyRequester(request);
639 break;
pkanwar32d516d2016-10-14 19:37:38 -0700640 }
641
Yorke Lee716f67e2015-06-17 15:39:16 -0700642 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700643 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700644 final Phone phone = getPhoneFromRequest(request);
645 request.result = phone != null ?
646 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
647 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700648 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700649 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700650 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700651 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700652
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700653 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700654 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700655 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000656 uiccPort = getUiccPortFromRequest(request);
657 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700658 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800659 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700660 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700661 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700662 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800663 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000664 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800665 iccArgument.channel, iccArgument.cla, iccArgument.command,
666 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
667 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700668 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700669 break;
670
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700671 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700672 ar = (AsyncResult) msg.obj;
673 request = (MainThreadRequest) ar.userObj;
674 if (ar.exception == null && ar.result != null) {
675 request.result = ar.result;
676 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800677 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700678 if (ar.result == null) {
679 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800680 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700681 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800682 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700683 } else {
684 loge("iccTransmitApduLogicalChannel: Unknown exception");
685 }
686 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700687 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700688 break;
689
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700690 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
691 request = (MainThreadRequest) msg.obj;
692 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000693 uiccPort = getUiccPortFromRequest(request);
694 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700695 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800696 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700697 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700698 } else {
699 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800700 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000701 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800702 iccArgument.cla, iccArgument.command, iccArgument.p1,
703 iccArgument.p2,
704 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700705 }
706 break;
707
708 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
709 ar = (AsyncResult) msg.obj;
710 request = (MainThreadRequest) ar.userObj;
711 if (ar.exception == null && ar.result != null) {
712 request.result = ar.result;
713 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800714 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700715 if (ar.result == null) {
716 loge("iccTransmitApduBasicChannel: Empty response");
717 } else if (ar.exception instanceof CommandException) {
718 loge("iccTransmitApduBasicChannel: CommandException: " +
719 ar.exception);
720 } else {
721 loge("iccTransmitApduBasicChannel: Unknown exception");
722 }
723 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700724 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700725 break;
726
727 case CMD_EXCHANGE_SIM_IO:
728 request = (MainThreadRequest) msg.obj;
729 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000730 uiccPort = getUiccPortFromRequest(request);
731 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700732 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800733 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700734 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700735 } else {
736 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
737 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000738 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700739 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
740 iccArgument.data, onCompleted);
741 }
742 break;
743
744 case EVENT_EXCHANGE_SIM_IO_DONE:
745 ar = (AsyncResult) msg.obj;
746 request = (MainThreadRequest) ar.userObj;
747 if (ar.exception == null && ar.result != null) {
748 request.result = ar.result;
749 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800750 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700751 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700752 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700753 break;
754
Derek Tan4d5e5c12014-02-04 11:54:58 -0800755 case CMD_SEND_ENVELOPE:
756 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000757 uiccPort = getUiccPortFromRequest(request);
758 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700759 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800760 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700761 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700762 } else {
763 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800764 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700765 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800766 break;
767
768 case EVENT_SEND_ENVELOPE_DONE:
769 ar = (AsyncResult) msg.obj;
770 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700771 if (ar.exception == null && ar.result != null) {
772 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800773 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800774 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700775 if (ar.result == null) {
776 loge("sendEnvelopeWithStatus: Empty response");
777 } else if (ar.exception instanceof CommandException) {
778 loge("sendEnvelopeWithStatus: CommandException: " +
779 ar.exception);
780 } else {
781 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
782 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800783 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700784 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800785 break;
786
Shishir Agrawal566b7612013-10-28 14:41:00 -0700787 case CMD_OPEN_CHANNEL:
788 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000789 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800790 IccLogicalChannelRequest openChannelRequest =
791 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000792 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700793 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800794 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800795 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700796 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700797 } else {
798 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800799 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
800 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700801 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700802 break;
803
804 case EVENT_OPEN_CHANNEL_DONE:
805 ar = (AsyncResult) msg.obj;
806 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700807 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700808 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700809 int[] result = (int[]) ar.result;
810 int channelId = result[0];
811 byte[] selectResponse = null;
812 if (result.length > 1) {
813 selectResponse = new byte[result.length - 1];
814 for (int i = 1; i < result.length; ++i) {
815 selectResponse[i - 1] = (byte) result[i];
816 }
817 }
818 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800819 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800820
821 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700822 if (uiccPort == null) {
823 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
824 } else {
825 IccLogicalChannelRequest channelRequest =
826 (IccLogicalChannelRequest) request.argument;
827 channelRequest.channel = channelId;
828 uiccPort.onLogicalChannelOpened(channelRequest);
829 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700830 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700831 if (ar.result == null) {
832 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700833 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700834 if (ar.exception != null) {
835 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
836 }
837
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700838 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700839 if (ar.exception instanceof CommandException) {
840 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800841 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700842 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700843 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700844 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700845 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700846 }
847 }
848 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800849 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700850 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700851 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700852 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700853 break;
854
855 case CMD_CLOSE_CHANNEL:
856 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000857 uiccPort = getUiccPortFromRequest(request);
858 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700859 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800860 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800861 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800862 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700863 } else {
864 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000865 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700866 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700867 break;
868
869 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800870 ar = (AsyncResult) msg.obj;
871 request = (MainThreadRequest) ar.userObj;
872 if (ar.exception == null) {
873 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800874 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700875 if (uiccPort == null) {
876 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
877 } else {
878 final int channelId = (Integer) request.argument;
879 uiccPort.onLogicalChannelClosed(channelId);
880 }
Chen Xu540470b2021-12-14 17:15:47 -0800881 } else {
882 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800883 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800884 if (ar.exception instanceof CommandException) {
885 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
886 CommandException.Error error =
887 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800888 if (error == CommandException.Error.INVALID_ARGUMENTS) {
889 // should only throw exceptions from the binder threads.
890 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800891 "iccCloseLogicalChannel: invalid argument ");
892 }
893 } else {
894 loge("iccCloseLogicalChannel: Unknown exception");
895 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800896 request.result = (exception != null) ? exception :
897 new IllegalStateException(
898 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800899 }
900 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800901 break;
902
903 case CMD_NV_READ_ITEM:
904 request = (MainThreadRequest) msg.obj;
905 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800906 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
907 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800908 break;
909
910 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700911 ar = (AsyncResult) msg.obj;
912 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800913 if (ar.exception == null && ar.result != null) {
914 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700915 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800916 request.result = "";
917 if (ar.result == null) {
918 loge("nvReadItem: Empty response");
919 } else if (ar.exception instanceof CommandException) {
920 loge("nvReadItem: CommandException: " +
921 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700922 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800923 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700924 }
925 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700926 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700927 break;
928
Jake Hambye994d462014-02-03 13:10:13 -0800929 case CMD_NV_WRITE_ITEM:
930 request = (MainThreadRequest) msg.obj;
931 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
932 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800933 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700934 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800935 break;
936
937 case EVENT_NV_WRITE_ITEM_DONE:
938 handleNullReturnEvent(msg, "nvWriteItem");
939 break;
940
941 case CMD_NV_WRITE_CDMA_PRL:
942 request = (MainThreadRequest) msg.obj;
943 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800944 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800945 break;
946
947 case EVENT_NV_WRITE_CDMA_PRL_DONE:
948 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
949 break;
950
chen xu6dac5ab2018-10-26 17:39:23 -0700951 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800952 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700953 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800954 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800955 break;
956
chen xu6dac5ab2018-10-26 17:39:23 -0700957 case EVENT_RESET_MODEM_CONFIG_DONE:
958 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800959 break;
960
Sooraj Sasindran37444802020-08-11 10:40:43 -0700961 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
962 request = (MainThreadRequest) msg.obj;
963 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
964 request);
965 Phone phone = getPhoneFromRequest(request);
966 if (phone != null) {
967 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
968 } else {
969 loge("isNRDualConnectivityEnabled: No phone object");
970 request.result = false;
971 notifyRequester(request);
972 }
973 break;
974 }
975
976 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
977 ar = (AsyncResult) msg.obj;
978 request = (MainThreadRequest) ar.userObj;
979 if (ar.exception == null && ar.result != null) {
980 request.result = ar.result;
981 } else {
982 // request.result must be set to something non-null
983 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700984 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700985 request.result = ar.result;
986 } else {
987 request.result = false;
988 }
989 if (ar.result == null) {
990 loge("isNRDualConnectivityEnabled: Empty response");
991 } else if (ar.exception instanceof CommandException) {
992 loge("isNRDualConnectivityEnabled: CommandException: "
993 + ar.exception);
994 } else {
995 loge("isNRDualConnectivityEnabled: Unknown exception");
996 }
997 }
998 notifyRequester(request);
999 break;
1000
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001001 case CMD_IS_VONR_ENABLED: {
1002 request = (MainThreadRequest) msg.obj;
1003 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
1004 request);
1005 Phone phone = getPhoneFromRequest(request);
1006 if (phone != null) {
1007 phone.isVoNrEnabled(onCompleted, request.workSource);
1008 } else {
1009 loge("isVoNrEnabled: No phone object");
1010 request.result = false;
1011 notifyRequester(request);
1012 }
1013 break;
1014 }
1015
1016 case EVENT_IS_VONR_ENABLED_DONE:
1017 ar = (AsyncResult) msg.obj;
1018 request = (MainThreadRequest) ar.userObj;
1019 if (ar.exception == null && ar.result != null) {
1020 request.result = ar.result;
1021 } else {
1022 // request.result must be set to something non-null
1023 // for the calling thread to unblock
1024 if (ar.result != null) {
1025 request.result = ar.result;
1026 } else {
1027 request.result = false;
1028 }
1029 if (ar.result == null) {
1030 loge("isVoNrEnabled: Empty response");
1031 } else if (ar.exception instanceof CommandException) {
1032 loge("isVoNrEnabled: CommandException: "
1033 + ar.exception);
1034 } else {
1035 loge("isVoNrEnabled: Unknown exception");
1036 }
1037 }
1038 notifyRequester(request);
1039 break;
1040
Sooraj Sasindran37444802020-08-11 10:40:43 -07001041 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1042 request = (MainThreadRequest) msg.obj;
1043 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1044 Phone phone = getPhoneFromRequest(request);
1045 if (phone != null) {
1046 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1047 request.workSource);
1048 } else {
1049 loge("enableNrDualConnectivity: No phone object");
1050 request.result =
1051 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1052 notifyRequester(request);
1053 }
1054 break;
1055 }
1056
1057 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1058 ar = (AsyncResult) msg.obj;
1059 request = (MainThreadRequest) ar.userObj;
1060 if (ar.exception == null) {
1061 request.result =
1062 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1063 } else {
1064 request.result =
1065 TelephonyManager
1066 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1067 if (ar.exception instanceof CommandException) {
1068 CommandException.Error error =
1069 ((CommandException) (ar.exception)).getCommandError();
1070 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1071 request.result =
1072 TelephonyManager
1073 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001074 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1075 request.result =
1076 TelephonyManager
1077 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001078 }
1079 loge("enableNrDualConnectivity" + ": CommandException: "
1080 + ar.exception);
1081 } else {
1082 loge("enableNrDualConnectivity" + ": Unknown exception");
1083 }
1084 }
1085 notifyRequester(request);
1086 break;
1087 }
1088
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001089 case CMD_ENABLE_VONR: {
1090 request = (MainThreadRequest) msg.obj;
1091 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1092 Phone phone = getPhoneFromRequest(request);
1093 if (phone != null) {
1094 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1095 request.workSource);
1096 } else {
1097 loge("setVoNrEnabled: No phone object");
1098 request.result =
1099 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1100 notifyRequester(request);
1101 }
1102 break;
1103 }
1104
1105 case EVENT_ENABLE_VONR_DONE: {
1106 ar = (AsyncResult) msg.obj;
1107 request = (MainThreadRequest) ar.userObj;
1108 if (ar.exception == null) {
1109 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1110 } else {
1111 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1112 if (ar.exception instanceof CommandException) {
1113 CommandException.Error error =
1114 ((CommandException) (ar.exception)).getCommandError();
1115 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1116 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1117 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1118 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1119 } else {
1120 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1121 }
1122 loge("setVoNrEnabled" + ": CommandException: "
1123 + ar.exception);
1124 } else {
1125 loge("setVoNrEnabled" + ": Unknown exception");
1126 }
1127 }
1128 notifyRequester(request);
1129 break;
1130 }
1131
SongFerngWang3ef3e072020-12-21 16:41:52 +08001132 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001133 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001134 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1135 request);
1136 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001137 break;
1138
SongFerngWang3ef3e072020-12-21 16:41:52 +08001139 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001140 ar = (AsyncResult) msg.obj;
1141 request = (MainThreadRequest) ar.userObj;
1142 if (ar.exception == null && ar.result != null) {
1143 request.result = ar.result; // Integer
1144 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301145 // request.result must be set to something non-null
1146 // for the calling thread to unblock
1147 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001148 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001149 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001150 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001151 loge("getAllowedNetworkTypesBitmask: CommandException: "
1152 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001153 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001154 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001155 }
1156 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001157 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001158 break;
1159
SongFerngWang3ef3e072020-12-21 16:41:52 +08001160 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001161 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001162 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1163 request);
1164 Pair<Integer, Long> reasonWithNetworkTypes =
1165 (Pair<Integer, Long>) request.argument;
1166 getPhoneFromRequest(request).setAllowedNetworkTypes(
1167 reasonWithNetworkTypes.first,
1168 reasonWithNetworkTypes.second,
1169 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001170 break;
1171
SongFerngWang3ef3e072020-12-21 16:41:52 +08001172 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1173 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001174 break;
1175
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001176 case CMD_SET_VOICEMAIL_NUMBER:
1177 request = (MainThreadRequest) msg.obj;
1178 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1179 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001180 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1181 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001182 break;
1183
1184 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1185 handleNullReturnEvent(msg, "setVoicemailNumber");
1186 break;
1187
Stuart Scott54788802015-03-30 13:18:01 -07001188 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1189 request = (MainThreadRequest) msg.obj;
1190 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1191 request);
1192 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1193 break;
1194
1195 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1196 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1197 break;
1198
Shishir Agrawal302c8692015-06-19 13:49:39 -07001199 case CMD_PERFORM_NETWORK_SCAN:
1200 request = (MainThreadRequest) msg.obj;
1201 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1202 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1203 break;
1204
Hall Liu27d24262020-09-18 19:04:59 -07001205 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001206 request = (MainThreadRequest) msg.obj;
1207 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001208 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1209 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1210 request.argument;
1211 int callForwardingReason = args.first;
1212 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001213 break;
Hall Liu27d24262020-09-18 19:04:59 -07001214 }
1215 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001216 ar = (AsyncResult) msg.obj;
1217 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001218 TelephonyManager.CallForwardingInfoCallback callback =
1219 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1220 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001221 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001222 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001223 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1224 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1225 // Service Class is a bit mask per 3gpp 27.007. Search for
1226 // any service for voice call.
1227 if ((callForwardInfo.serviceClass
1228 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001229 callForwardingInfo = new CallForwardingInfo(
1230 callForwardInfo.status
1231 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001232 callForwardInfo.reason,
1233 callForwardInfo.number,
1234 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001235 break;
1236 }
1237 }
1238 // Didn't find a call forward info for voice call.
1239 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001240 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1241 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001242 }
Hall Liu27d24262020-09-18 19:04:59 -07001243 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001244 } else {
1245 if (ar.result == null) {
1246 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1247 }
1248 if (ar.exception != null) {
1249 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1250 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001251 int errorCode = TelephonyManager
1252 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001253 if (ar.exception instanceof CommandException) {
1254 CommandException.Error error =
1255 ((CommandException) (ar.exception)).getCommandError();
1256 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001257 errorCode = TelephonyManager
1258 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001259 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001260 errorCode = TelephonyManager
1261 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001262 }
1263 }
Hall Liu27d24262020-09-18 19:04:59 -07001264 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001265 }
Shuo Qian4a594052020-01-23 11:59:30 -08001266 break;
Hall Liu27d24262020-09-18 19:04:59 -07001267 }
Shuo Qian4a594052020-01-23 11:59:30 -08001268
Hall Liu27d24262020-09-18 19:04:59 -07001269 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001270 request = (MainThreadRequest) msg.obj;
1271 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001272 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001273 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001274 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1275 request.argument).first;
1276 request.phone.setCallForwardingOption(
1277 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001278 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001279 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001280 callForwardingInfoToSet.getReason(),
1281 callForwardingInfoToSet.getNumber(),
1282 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1283 break;
Hall Liu27d24262020-09-18 19:04:59 -07001284 }
Shuo Qian4a594052020-01-23 11:59:30 -08001285
Hall Liu27d24262020-09-18 19:04:59 -07001286 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001287 ar = (AsyncResult) msg.obj;
1288 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001289 Consumer<Integer> callback =
1290 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1291 request.argument).second;
1292 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001293 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001294 int errorCode = TelephonyManager.CallForwardingInfoCallback
1295 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001296 if (ar.exception instanceof CommandException) {
1297 CommandException.Error error =
1298 ((CommandException) (ar.exception)).getCommandError();
1299 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001300 errorCode = TelephonyManager.CallForwardingInfoCallback
1301 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001302 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001303 errorCode = TelephonyManager.CallForwardingInfoCallback
1304 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001305 }
1306 }
1307 callback.accept(errorCode);
1308 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001309 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001310 }
Shuo Qian4a594052020-01-23 11:59:30 -08001311 break;
Hall Liu27d24262020-09-18 19:04:59 -07001312 }
Shuo Qian4a594052020-01-23 11:59:30 -08001313
Hall Liu27d24262020-09-18 19:04:59 -07001314 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001315 request = (MainThreadRequest) msg.obj;
1316 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1317 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1318 break;
Hall Liu27d24262020-09-18 19:04:59 -07001319 }
Shuo Qian4a594052020-01-23 11:59:30 -08001320
Hall Liu27d24262020-09-18 19:04:59 -07001321 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001322 ar = (AsyncResult) msg.obj;
1323 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001324 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001325 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001326 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001327 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001328 // Service Class is a bit mask per 3gpp 27.007.
1329 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001330 if (callForwardResults.length > 1
1331 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001332 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001333 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001334 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1335 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001336 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001337 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001338 }
1339 } else {
1340 if (ar.result == null) {
1341 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1342 }
1343 if (ar.exception != null) {
1344 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1345 }
1346 if (ar.exception instanceof CommandException) {
1347 CommandException.Error error =
1348 ((CommandException) (ar.exception)).getCommandError();
1349 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001350 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001351 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001352 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1353 callWaitingStatus =
1354 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001355 }
1356 }
1357 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001358 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001359 break;
Hall Liu27d24262020-09-18 19:04:59 -07001360 }
Shuo Qian4a594052020-01-23 11:59:30 -08001361
Hall Liu27d24262020-09-18 19:04:59 -07001362 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001363 request = (MainThreadRequest) msg.obj;
1364 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001365 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1366 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001367 break;
Hall Liu27d24262020-09-18 19:04:59 -07001368 }
Shuo Qian4a594052020-01-23 11:59:30 -08001369
Hall Liu27d24262020-09-18 19:04:59 -07001370 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001371 ar = (AsyncResult) msg.obj;
1372 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001373 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1374 Consumer<Integer> callback =
1375 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1376 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001377 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001378 if (ar.exception instanceof CommandException) {
1379 CommandException.Error error =
1380 ((CommandException) (ar.exception)).getCommandError();
1381 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1382 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001383 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1384 callback.accept(
1385 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001386 } else {
1387 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1388 }
1389 } else {
1390 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1391 }
1392 } else {
1393 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1394 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001395 }
Shuo Qian4a594052020-01-23 11:59:30 -08001396 break;
Hall Liu27d24262020-09-18 19:04:59 -07001397 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001398 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1399 ar = (AsyncResult) msg.obj;
1400 request = (MainThreadRequest) ar.userObj;
1401 CellNetworkScanResult cellScanResult;
1402 if (ar.exception == null && ar.result != null) {
1403 cellScanResult = new CellNetworkScanResult(
1404 CellNetworkScanResult.STATUS_SUCCESS,
1405 (List<OperatorInfo>) ar.result);
1406 } else {
1407 if (ar.result == null) {
1408 loge("getCellNetworkScanResults: Empty response");
1409 }
1410 if (ar.exception != null) {
1411 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1412 }
1413 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1414 if (ar.exception instanceof CommandException) {
1415 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001416 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001417 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1418 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1419 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1420 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1421 }
1422 }
1423 cellScanResult = new CellNetworkScanResult(errorCode, null);
1424 }
1425 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001426 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001427 break;
1428
1429 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1430 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001431 ManualNetworkSelectionArgument selArg =
1432 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001433 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1434 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001435 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1436 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001437 break;
1438
1439 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001440 ar = (AsyncResult) msg.obj;
1441 request = (MainThreadRequest) ar.userObj;
1442 if (ar.exception == null) {
1443 request.result = true;
1444 } else {
1445 request.result = false;
1446 loge("setNetworkSelectionModeManual " + ar.exception);
1447 }
1448 notifyRequester(request);
1449 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001450 break;
1451
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001452 case CMD_GET_MODEM_ACTIVITY_INFO:
1453 request = (MainThreadRequest) msg.obj;
1454 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001455 if (defaultPhone != null) {
1456 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001457 } else {
1458 ResultReceiver result = (ResultReceiver) request.argument;
1459 Bundle bundle = new Bundle();
1460 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001461 new ModemActivityInfo(0, 0, 0,
1462 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001463 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001464 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001465 break;
1466
Hall Liud0f208c2020-10-14 16:54:44 -07001467 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001468 ar = (AsyncResult) msg.obj;
1469 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001470 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001471 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001472 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001473 if (mLastModemActivityInfo == null) {
1474 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1475 mLastModemActivitySpecificInfo[0] =
1476 new ActivityStatsTechSpecificInfo(
1477 0,
1478 0,
1479 new int[ModemActivityInfo.getNumTxPowerLevels()],
1480 0);
1481 mLastModemActivityInfo =
1482 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1483 }
1484
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001485 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001486 // Update the last modem activity info and the result of the request.
1487 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1488 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001489 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001490 } else {
1491 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001492 }
Kai Shi917fdc62022-11-28 14:01:02 -08001493 // This is needed to decouple ret from mLastModemActivityInfo
1494 // We don't want to return mLastModemActivityInfo which is updated
1495 // inside mergeModemActivityInfo()
1496 ret = new ModemActivityInfo(
1497 mLastModemActivityInfo.getTimestampMillis(),
1498 mLastModemActivityInfo.getSleepTimeMillis(),
1499 mLastModemActivityInfo.getIdleTimeMillis(),
1500 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001501
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001502 } else {
1503 if (ar.result == null) {
1504 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001505 error = TelephonyManager.ModemActivityInfoException
1506 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001507 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001508 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001509 error = TelephonyManager.ModemActivityInfoException
1510 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001511 } else {
1512 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001513 error = TelephonyManager.ModemActivityInfoException
1514 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001515 }
1516 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001517 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001518 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001519 bundle.putParcelable(
1520 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001521 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001522 } else {
1523 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1524 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001525 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001526 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001527 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001528 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001529
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001530 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001531 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001532 CarrierRestrictionRules argument =
1533 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001534 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001535 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001536 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001537 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001538
1539 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1540 ar = (AsyncResult) msg.obj;
1541 request = (MainThreadRequest) ar.userObj;
1542 if (ar.exception == null && ar.result != null) {
1543 request.result = ar.result;
1544 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001545 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1546 if (ar.exception instanceof CommandException) {
1547 loge("setAllowedCarriers: CommandException: " + ar.exception);
1548 CommandException.Error error =
1549 ((CommandException) (ar.exception)).getCommandError();
1550 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1551 request.result =
1552 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1553 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001554 } else {
1555 loge("setAllowedCarriers: Unknown exception");
1556 }
1557 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001558 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001559 break;
1560
1561 case CMD_GET_ALLOWED_CARRIERS:
1562 request = (MainThreadRequest) msg.obj;
1563 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001564 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001565 break;
1566
1567 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1568 ar = (AsyncResult) msg.obj;
1569 request = (MainThreadRequest) ar.userObj;
1570 if (ar.exception == null && ar.result != null) {
1571 request.result = ar.result;
1572 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001573 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001574 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001575 if (ar.result == null) {
1576 loge("getAllowedCarriers: Empty response");
1577 } else if (ar.exception instanceof CommandException) {
1578 loge("getAllowedCarriers: CommandException: " +
1579 ar.exception);
1580 } else {
1581 loge("getAllowedCarriers: Unknown exception");
1582 }
1583 }
arunvoddud7401012022-12-15 16:08:12 +00001584 if (request.argument != null) {
1585 // This is for the implementation of carrierRestrictionStatus.
1586 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1587 Consumer<Integer> callback = callbackInfo.getConsumer();
1588 int callerCarrierId = callbackInfo.getCarrierId();
1589 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1590 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1591 CarrierRestrictionRules carrierRestrictionRules =
1592 (CarrierRestrictionRules) ar.result;
1593 int carrierId = -1;
1594 try {
1595 CarrierIdentifier carrierIdentifier =
1596 carrierRestrictionRules.getAllowedCarriers().get(0);
1597 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1598 carrierIdentifier);
1599 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1600 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1601 }
1602 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
1603 if (carrierId != -1 && callerCarrierId == carrierId && lockStatus
1604 == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001605 lockStatus = TelephonyManager
1606 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001607 }
1608 } else {
1609 Rlog.e(LOG_TAG,
1610 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1611 }
1612 callback.accept(lockStatus);
1613 } else {
1614 // This is for the implementation of getAllowedCarriers.
1615 notifyRequester(request);
1616 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001617 break;
1618
Nathan Haroldb3014052017-01-25 15:57:32 -08001619 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1620 ar = (AsyncResult) msg.obj;
1621 request = (MainThreadRequest) ar.userObj;
1622 if (ar.exception == null && ar.result != null) {
1623 request.result = ar.result;
1624 } else {
1625 request.result = new IllegalArgumentException(
1626 "Failed to retrieve Forbidden Plmns");
1627 if (ar.result == null) {
1628 loge("getForbiddenPlmns: Empty response");
1629 } else {
1630 loge("getForbiddenPlmns: Unknown exception");
1631 }
1632 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001633 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001634 break;
1635
1636 case CMD_GET_FORBIDDEN_PLMNS:
1637 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001638 uiccPort = getUiccPortFromRequest(request);
1639 if (uiccPort == null) {
1640 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001641 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001642 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001643 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001644 break;
1645 }
1646 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001647 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001648 if (uiccApp == null) {
1649 loge("getForbiddenPlmns() no app with specified type -- "
1650 + appType);
1651 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001652 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001653 break;
1654 } else {
1655 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1656 + " specified type -- " + appType);
1657 }
1658 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1659 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001660 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001661 break;
1662
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001663 case CMD_SWITCH_SLOTS:
1664 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001665 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001666 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001667 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001668 break;
1669
1670 case EVENT_SWITCH_SLOTS_DONE:
1671 ar = (AsyncResult) msg.obj;
1672 request = (MainThreadRequest) ar.userObj;
1673 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001674 notifyRequester(request);
1675 break;
1676 case CMD_GET_NETWORK_SELECTION_MODE:
1677 request = (MainThreadRequest) msg.obj;
1678 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1679 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1680 break;
1681
1682 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1683 ar = (AsyncResult) msg.obj;
1684 request = (MainThreadRequest) ar.userObj;
1685 if (ar.exception != null) {
1686 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1687 } else {
1688 int mode = ((int[]) ar.result)[0];
1689 if (mode == 0) {
1690 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1691 } else {
1692 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1693 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001694 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001695 notifyRequester(request);
1696 break;
1697 case CMD_GET_CDMA_ROAMING_MODE:
1698 request = (MainThreadRequest) msg.obj;
1699 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1700 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1701 break;
1702 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1703 ar = (AsyncResult) msg.obj;
1704 request = (MainThreadRequest) ar.userObj;
1705 if (ar.exception != null) {
1706 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1707 } else {
1708 request.result = ((int[]) ar.result)[0];
1709 }
1710 notifyRequester(request);
1711 break;
1712 case CMD_SET_CDMA_ROAMING_MODE:
1713 request = (MainThreadRequest) msg.obj;
1714 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1715 int mode = (int) request.argument;
1716 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1717 break;
1718 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1719 ar = (AsyncResult) msg.obj;
1720 request = (MainThreadRequest) ar.userObj;
1721 request.result = ar.exception == null;
1722 notifyRequester(request);
1723 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001724 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1725 request = (MainThreadRequest) msg.obj;
1726 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1727 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1728 break;
1729 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1730 ar = (AsyncResult) msg.obj;
1731 request = (MainThreadRequest) ar.userObj;
1732 if (ar.exception != null) {
1733 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1734 } else {
1735 request.result = ((int[]) ar.result)[0];
1736 }
1737 notifyRequester(request);
1738 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001739 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1740 request = (MainThreadRequest) msg.obj;
1741 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1742 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001743 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1744 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001745 break;
1746 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1747 ar = (AsyncResult) msg.obj;
1748 request = (MainThreadRequest) ar.userObj;
1749 request.result = ar.exception == null;
1750 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001751 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001752 case CMD_GET_ALL_CELL_INFO:
1753 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001754 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001755 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001756 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001757 case EVENT_GET_ALL_CELL_INFO_DONE:
1758 ar = (AsyncResult) msg.obj;
1759 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001760 // If a timeout occurs, the response will be null
1761 request.result = (ar.exception == null && ar.result != null)
1762 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001763 synchronized (request) {
1764 request.notifyAll();
1765 }
1766 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001767 case CMD_REQUEST_CELL_INFO_UPDATE:
1768 request = (MainThreadRequest) msg.obj;
1769 request.phone.requestCellInfoUpdate(request.workSource,
1770 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1771 break;
1772 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1773 ar = (AsyncResult) msg.obj;
1774 request = (MainThreadRequest) ar.userObj;
1775 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1776 try {
1777 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001778 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001779 cb.onError(
1780 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1781 ar.exception.getClass().getName(),
1782 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001783 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001784 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001785 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001786 } else {
1787 // use the result as returned
1788 cb.onCellInfo((List<CellInfo>) ar.result);
1789 }
1790 } catch (RemoteException re) {
1791 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1792 }
1793 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001794 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001795 request = (MainThreadRequest) msg.obj;
1796 WorkSource ws = (WorkSource) request.argument;
1797 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001798 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001799 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001800 }
1801 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001802 ar = (AsyncResult) msg.obj;
1803 request = (MainThreadRequest) ar.userObj;
1804 if (ar.exception == null) {
1805 request.result = ar.result;
1806 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001807 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001808 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001809 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001810 }
1811
1812 synchronized (request) {
1813 request.notifyAll();
1814 }
1815 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001816 }
chen xu6dac5ab2018-10-26 17:39:23 -07001817 case CMD_MODEM_REBOOT:
1818 request = (MainThreadRequest) msg.obj;
1819 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001820 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001821 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001822 case EVENT_CMD_MODEM_REBOOT_DONE:
1823 handleNullReturnEvent(msg, "rebootModem");
1824 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001825 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001826 request = (MainThreadRequest) msg.obj;
1827 boolean enable = (boolean) request.argument;
1828 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001829 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001830 PhoneConfigurationManager.getInstance()
1831 .enablePhone(request.phone, enable, onCompleted);
1832 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001833 }
Michele Berionne5e411512020-11-13 02:36:59 +00001834 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001835 ar = (AsyncResult) msg.obj;
1836 request = (MainThreadRequest) ar.userObj;
1837 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001838 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001839 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001840 if ((boolean) request.result) {
1841 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1842 updateModemStateMetrics();
1843 } else {
1844 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1845 + ar.exception);
1846 }
1847 notifyRequester(request);
1848 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001849 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001850 case CMD_GET_MODEM_STATUS:
1851 request = (MainThreadRequest) msg.obj;
1852 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1853 PhoneConfigurationManager.getInstance()
1854 .getPhoneStatusFromModem(request.phone, onCompleted);
1855 break;
1856 case EVENT_GET_MODEM_STATUS_DONE:
1857 ar = (AsyncResult) msg.obj;
1858 request = (MainThreadRequest) ar.userObj;
1859 int id = request.phone.getPhoneId();
1860 if (ar.exception == null && ar.result != null) {
1861 request.result = ar.result;
1862 //update the cache as modem status has changed
1863 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1864 (boolean) request.result);
1865 } else {
1866 // Return true if modem status cannot be retrieved. For most cases,
1867 // modem status is on. And for older version modems, GET_MODEM_STATUS
1868 // and disable modem are not supported. Modem is always on.
1869 // TODO: this should be fixed in R to support a third
1870 // status UNKNOWN b/131631629
1871 request.result = true;
1872 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1873 + ar.exception);
1874 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001875 notifyRequester(request);
1876 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001877 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1878 request = (MainThreadRequest) msg.obj;
1879 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1880 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1881 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1882 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1883 break;
1884 }
1885 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1886 ar = (AsyncResult) msg.obj;
1887 request = (MainThreadRequest) ar.userObj;
1888 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1889 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1890 args.second.accept(ar.exception == null);
1891 notifyRequester(request);
1892 break;
1893 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001894 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1895 request = (MainThreadRequest) msg.obj;
1896 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1897 Phone phone = getPhoneFromRequest(request);
1898 if (phone != null) {
1899 phone.getSystemSelectionChannels(onCompleted);
1900 } else {
1901 loge("getSystemSelectionChannels: No phone object");
1902 request.result = new ArrayList<RadioAccessSpecifier>();
1903 notifyRequester(request);
1904 }
1905 break;
1906 }
1907 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1908 ar = (AsyncResult) msg.obj;
1909 request = (MainThreadRequest) ar.userObj;
1910 if (ar.exception == null && ar.result != null) {
1911 request.result = ar.result;
1912 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001913 request.result = new IllegalStateException(
1914 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001915 if (ar.result == null) {
1916 loge("getSystemSelectionChannels: Empty response");
1917 } else {
1918 loge("getSystemSelectionChannels: Unknown exception");
1919 }
1920 }
1921 notifyRequester(request);
1922 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001923 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1924 ar = (AsyncResult) msg.obj;
1925 request = (MainThreadRequest) ar.userObj;
1926 if (ar.exception == null && ar.result != null) {
1927 request.result = ar.result;
1928 } else {
1929 request.result = -1;
1930 loge("Failed to set Forbidden Plmns");
1931 if (ar.result == null) {
1932 loge("setForbidenPlmns: Empty response");
1933 } else if (ar.exception != null) {
1934 loge("setForbiddenPlmns: Exception: " + ar.exception);
1935 request.result = -1;
1936 } else {
1937 loge("setForbiddenPlmns: Unknown exception");
1938 }
1939 }
1940 notifyRequester(request);
1941 break;
1942 case CMD_SET_FORBIDDEN_PLMNS:
1943 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001944 uiccPort = getUiccPortFromRequest(request);
1945 if (uiccPort == null) {
1946 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001947 request.result = -1;
1948 notifyRequester(request);
1949 break;
1950 }
1951 Pair<Integer, List<String>> setFplmnsArgs =
1952 (Pair<Integer, List<String>>) request.argument;
1953 appType = setFplmnsArgs.first;
1954 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001955 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001956 if (uiccApp == null) {
1957 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1958 request.result = -1;
1959 loge("Failed to get UICC App");
1960 notifyRequester(request);
1961 } else {
1962 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1963 ((SIMRecords) uiccApp.getIccRecords())
1964 .setForbiddenPlmns(onCompleted, fplmns);
1965 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001966 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001967 case CMD_ERASE_MODEM_CONFIG:
1968 request = (MainThreadRequest) msg.obj;
1969 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1970 defaultPhone.eraseModemConfig(onCompleted);
1971 break;
1972 case EVENT_ERASE_MODEM_CONFIG_DONE:
1973 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001974 break;
zoey chene02881a2019-12-30 16:11:23 +08001975
Kai Shif70f46f2021-03-03 13:59:46 -08001976 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1977 request = (MainThreadRequest) msg.obj;
1978 request.result = defaultPhone.eraseDataInSharedPreferences();
1979 notifyRequester(request);
1980 break;
1981
zoey chene02881a2019-12-30 16:11:23 +08001982 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1983 request = (MainThreadRequest) msg.obj;
1984 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1985 Pair<String, String> changed = (Pair<String, String>) request.argument;
1986 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1987 changed.first, changed.second, onCompleted);
1988 break;
1989 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1990 ar = (AsyncResult) msg.obj;
1991 request = (MainThreadRequest) ar.userObj;
1992 if (ar.exception == null) {
1993 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001994 // If the operation is successful, update the PIN storage
1995 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1996 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001997 UiccController.getInstance().getPinStorage()
1998 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001999 } else {
2000 request.result = msg.arg1;
2001 }
2002 notifyRequester(request);
2003 break;
2004
Michele Berionne5e411512020-11-13 02:36:59 +00002005 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08002006 request = (MainThreadRequest) msg.obj;
2007 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
2008 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2009 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2010 enabled.first, enabled.second, onCompleted);
2011 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002012 }
zoey chene02881a2019-12-30 16:11:23 +08002013 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2014 ar = (AsyncResult) msg.obj;
2015 request = (MainThreadRequest) ar.userObj;
2016 if (ar.exception == null) {
2017 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002018 // If the operation is successful, update the PIN storage
2019 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2020 int phoneId = getPhoneFromRequest(request).getPhoneId();
2021 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002022 UiccController.getInstance().getPinStorage()
2023 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002024 } else {
2025 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2026 }
zoey chene02881a2019-12-30 16:11:23 +08002027 } else {
2028 request.result = msg.arg1;
2029 }
Michele Berionne5e411512020-11-13 02:36:59 +00002030
2031
zoey chene02881a2019-12-30 16:11:23 +08002032 notifyRequester(request);
2033 break;
2034
Peter Wangdafb9ac2020-01-15 14:13:38 -08002035 case MSG_NOTIFY_USER_ACTIVITY:
2036 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002037 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002038 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2039 getDefaultPhone().getContext().sendBroadcastAsUser(
2040 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2041 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002042
2043 case CMD_SET_DATA_THROTTLING: {
2044 request = (MainThreadRequest) msg.obj;
2045 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2046 DataThrottlingRequest dataThrottlingRequest =
2047 (DataThrottlingRequest) request.argument;
2048 Phone phone = getPhoneFromRequest(request);
2049 if (phone != null) {
2050 phone.setDataThrottling(onCompleted,
2051 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2052 dataThrottlingRequest.getCompletionDurationMillis());
2053 } else {
2054 loge("setDataThrottling: No phone object");
2055 request.result =
2056 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2057 notifyRequester(request);
2058 }
2059
2060 break;
2061 }
2062 case EVENT_SET_DATA_THROTTLING_DONE:
2063 ar = (AsyncResult) msg.obj;
2064 request = (MainThreadRequest) ar.userObj;
2065
2066 if (ar.exception == null) {
2067 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2068 } else if (ar.exception instanceof CommandException) {
2069 loge("setDataThrottling: CommandException: " + ar.exception);
2070 CommandException.Error error =
2071 ((CommandException) (ar.exception)).getCommandError();
2072
2073 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2074 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002075 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002076 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2077 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002078 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2079 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002080 } else {
2081 request.result =
2082 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2083 }
2084 } else {
2085 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2086 }
2087 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2088 notifyRequester(request);
2089 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002090
2091 case CMD_SET_SIM_POWER: {
2092 request = (MainThreadRequest) msg.obj;
2093 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2094 request = (MainThreadRequest) msg.obj;
2095 int stateToSet =
2096 ((Pair<Integer, IIntegerConsumer>)
2097 request.argument).first;
2098 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2099 break;
2100 }
2101 case EVENT_SET_SIM_POWER_DONE: {
2102 ar = (AsyncResult) msg.obj;
2103 request = (MainThreadRequest) ar.userObj;
2104 IIntegerConsumer callback =
2105 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2106 if (ar.exception != null) {
2107 loge("setSimPower exception: " + ar.exception);
2108 int errorCode = TelephonyManager.CallForwardingInfoCallback
2109 .RESULT_ERROR_UNKNOWN;
2110 if (ar.exception instanceof CommandException) {
2111 CommandException.Error error =
2112 ((CommandException) (ar.exception)).getCommandError();
2113 if (error == CommandException.Error.SIM_ERR) {
2114 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2115 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2116 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2117 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2118 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2119 } else {
2120 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2121 }
2122 }
2123 try {
2124 callback.accept(errorCode);
2125 } catch (RemoteException e) {
2126 // Ignore if the remote process is no longer available to call back.
2127 Log.w(LOG_TAG, "setSimPower: callback not available.");
2128 }
2129 } else {
2130 try {
2131 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2132 } catch (RemoteException e) {
2133 // Ignore if the remote process is no longer available to call back.
2134 Log.w(LOG_TAG, "setSimPower: callback not available.");
2135 }
2136 }
2137 break;
2138 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002139 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2140 request = (MainThreadRequest) msg.obj;
2141
2142 final Phone phone = getPhoneFromRequest(request);
2143 if (phone == null || phone.getServiceStateTracker() == null) {
2144 request.result = new IllegalStateException("Phone or SST is null");
2145 notifyRequester(request);
2146 break;
2147 }
2148
2149 Pair<Integer, SignalStrengthUpdateRequest> pair =
2150 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2151 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2152 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002153 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002154 request.subId, pair.first /*callingUid*/,
2155 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002156 break;
2157 }
2158 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2159 ar = (AsyncResult) msg.obj;
2160 request = (MainThreadRequest) ar.userObj;
2161 // request.result will be the exception of ar if present, true otherwise.
2162 // Be cautious not to leave result null which will wait() forever
2163 request.result = ar.exception != null ? ar.exception : true;
2164 notifyRequester(request);
2165 break;
2166 }
2167 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2168 request = (MainThreadRequest) msg.obj;
2169
2170 Phone phone = getPhoneFromRequest(request);
2171 if (phone == null || phone.getServiceStateTracker() == null) {
2172 request.result = new IllegalStateException("Phone or SST is null");
2173 notifyRequester(request);
2174 break;
2175 }
2176
2177 Pair<Integer, SignalStrengthUpdateRequest> pair =
2178 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2179 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2180 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002181 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002182 request.subId, pair.first /*callingUid*/,
2183 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002184 break;
2185 }
2186 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2187 ar = (AsyncResult) msg.obj;
2188 request = (MainThreadRequest) ar.userObj;
2189 request.result = ar.exception != null ? ar.exception : true;
2190 notifyRequester(request);
2191 break;
2192 }
Jordan Liu109698e2020-11-24 14:50:34 -08002193
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002194 case CMD_GET_SLICING_CONFIG: {
2195 request = (MainThreadRequest) msg.obj;
2196 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2197 request.phone.getSlicingConfig(onCompleted);
2198 break;
2199 }
2200 case EVENT_GET_SLICING_CONFIG_DONE: {
2201 ar = (AsyncResult) msg.obj;
2202 request = (MainThreadRequest) ar.userObj;
2203 ResultReceiver result = (ResultReceiver) request.argument;
2204
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002205 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002206 Bundle bundle = new Bundle();
2207 int resultCode = 0;
2208 if (ar.exception != null) {
2209 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2210 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002211 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002212 } else if (ar.result == null) {
2213 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002214 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002215 } else {
2216 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002217 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2218 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002219 }
2220
2221 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002222 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002223 }
2224 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2225 result.send(resultCode, bundle);
2226 notifyRequester(request);
2227 break;
2228 }
2229
Sarah Chin71b3a852022-09-28 15:54:19 -07002230 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002231 request = (MainThreadRequest) msg.obj;
2232 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002233 PurchasePremiumCapabilityArgument arg =
2234 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chincc5446f2023-10-23 17:57:19 -07002235 SlicePurchaseController.getInstance(request.phone, mFeatureFlags)
2236 .purchasePremiumCapability(arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002237 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002238 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002239
Sarah Chin71b3a852022-09-28 15:54:19 -07002240 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002241 ar = (AsyncResult) msg.obj;
2242 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002243 PurchasePremiumCapabilityArgument arg =
2244 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002245 try {
2246 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002247 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002248 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002249 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chinff8b1802023-04-11 14:22:14 -07002250 + ", result="
Sarah Chin2ec39f62022-08-31 17:03:26 -07002251 + TelephonyManager.convertPurchaseResultToString(result));
2252 } catch (RemoteException e) {
2253 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002254 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002255 + " failed: " + e;
2256 if (DBG) log(logStr);
2257 AnomalyReporter.reportAnomaly(
2258 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2259 }
2260 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002261 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002262
Michele Berionne5e411512020-11-13 02:36:59 +00002263 case CMD_PREPARE_UNATTENDED_REBOOT:
2264 request = (MainThreadRequest) msg.obj;
2265 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002266 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002267 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002268 notifyRequester(request);
2269 break;
2270
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002271 default:
2272 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2273 break;
2274 }
2275 }
Jake Hambye994d462014-02-03 13:10:13 -08002276
Pengquan Menga1bb6272018-09-06 09:59:22 -07002277 private void notifyRequester(MainThreadRequest request) {
2278 synchronized (request) {
2279 request.notifyAll();
2280 }
2281 }
2282
Jake Hambye994d462014-02-03 13:10:13 -08002283 private void handleNullReturnEvent(Message msg, String command) {
2284 AsyncResult ar = (AsyncResult) msg.obj;
2285 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2286 if (ar.exception == null) {
2287 request.result = true;
2288 } else {
2289 request.result = false;
2290 if (ar.exception instanceof CommandException) {
2291 loge(command + ": CommandException: " + ar.exception);
2292 } else {
2293 loge(command + ": Unknown exception");
2294 }
2295 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002296 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002297 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002298 }
2299
2300 /**
2301 * Posts the specified command to be executed on the main thread,
2302 * waits for the request to complete, and returns the result.
2303 * @see #sendRequestAsync
2304 */
2305 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002306 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2307 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002308 }
2309
2310 /**
2311 * Posts the specified command to be executed on the main thread,
2312 * waits for the request to complete, and returns the result.
2313 * @see #sendRequestAsync
2314 */
2315 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2316 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002317 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002318 }
2319
2320 /**
2321 * Posts the specified command to be executed on the main thread,
2322 * waits for the request to complete, and returns the result.
2323 * @see #sendRequestAsync
2324 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002325 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002326 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2327 }
2328
2329 /**
2330 * Posts the specified command to be executed on the main thread,
2331 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2332 * if not timeout or null otherwise.
2333 * @see #sendRequestAsync
2334 */
2335 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2336 long timeoutInMs) {
2337 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002338 }
2339
2340 /**
2341 * Posts the specified command to be executed on the main thread,
2342 * waits for the request to complete, and returns the result.
2343 * @see #sendRequestAsync
2344 */
Nathan Harold92bed182018-10-12 18:16:49 -07002345 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002346 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002347 }
2348
2349 /**
2350 * Posts the specified command to be executed on the main thread,
2351 * waits for the request to complete, and returns the result.
2352 * @see #sendRequestAsync
2353 */
2354 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002355 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2356 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002357 }
2358
2359 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002360 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2361 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2362 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002363 * @see #sendRequestAsync
2364 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002365 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2366 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002367 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2368 throw new RuntimeException("This method will deadlock if called from the main thread.");
2369 }
2370
Nathan Harold92bed182018-10-12 18:16:49 -07002371 MainThreadRequest request = null;
2372 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2373 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2374 } else if (phone != null) {
2375 request = new MainThreadRequest(argument, phone, workSource);
2376 } else {
2377 request = new MainThreadRequest(argument, subId, workSource);
2378 }
2379
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002380 Message msg = mMainThreadHandler.obtainMessage(command, request);
2381 msg.sendToTarget();
2382
Rambo Wang0f050d82021-02-12 11:43:36 -08002383
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002384 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002385 if (timeoutInMs >= 0) {
2386 // Wait for at least timeoutInMs before returning null request result
2387 long now = SystemClock.elapsedRealtime();
2388 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002389 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002390 try {
2391 request.wait(deadline - now);
2392 } catch (InterruptedException e) {
2393 // Do nothing, go back and check if request is completed or timeout
2394 } finally {
2395 now = SystemClock.elapsedRealtime();
2396 }
2397 }
2398 } else {
2399 // Wait for the request to complete
2400 while (request.result == null) {
2401 try {
2402 request.wait();
2403 } catch (InterruptedException e) {
2404 // Do nothing, go back and wait until the request is complete
2405 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002406 }
2407 }
2408 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002409 if (request.result == null) {
2410 Log.wtf(LOG_TAG,
2411 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2412 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002413 return request.result;
2414 }
2415
2416 /**
2417 * Asynchronous ("fire and forget") version of sendRequest():
2418 * Posts the specified command to be executed on the main thread, and
2419 * returns immediately.
2420 * @see #sendRequest
2421 */
2422 private void sendRequestAsync(int command) {
2423 mMainThreadHandler.sendEmptyMessage(command);
2424 }
2425
2426 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002427 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002428 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002429 */
2430 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002431 sendRequestAsync(command, argument, null, null);
2432 }
2433
2434 /**
2435 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2436 * @see {@link #sendRequest(int,Object)}
2437 */
2438 private void sendRequestAsync(
2439 int command, Object argument, Phone phone, WorkSource workSource) {
2440 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002441 Message msg = mMainThreadHandler.obtainMessage(command, request);
2442 msg.sendToTarget();
2443 }
2444
2445 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002446 * Initialize the singleton PhoneInterfaceManager instance.
2447 * This is only done once, at startup, from PhoneApp.onCreate().
2448 */
Sarah Chincc5446f2023-10-23 17:57:19 -07002449 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002450 synchronized (PhoneInterfaceManager.class) {
2451 if (sInstance == null) {
Sarah Chincc5446f2023-10-23 17:57:19 -07002452 sInstance = new PhoneInterfaceManager(app, featureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002453 } else {
2454 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2455 }
2456 return sInstance;
2457 }
2458 }
2459
2460 /** Private constructor; @see init() */
Sarah Chincc5446f2023-10-23 17:57:19 -07002461 private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002462 mApp = app;
Sarah Chincc5446f2023-10-23 17:57:19 -07002463 mFeatureFlags = featureFlags;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002464 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002465 mImsResolver = ImsResolver.getInstance();
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +00002466 mSatelliteController = SatelliteController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002467 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002468 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2469 mMainThreadHandler = new MainThreadHandler();
Sarah Chin4beb2b72023-02-14 14:47:54 -08002470 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002471 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002472 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002473 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002474 mNotifyUserActivity = new AtomicBoolean(false);
joonhunshin4ac60942023-11-15 15:23:39 +00002475 mPackageManager = app.getPackageManager();
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -08002476 mSatelliteAccessController = SatelliteAccessController.getOrCreateInstance(
2477 getDefaultPhone().getContext(), featureFlags);
Tyler Gunn64144d92022-03-17 14:16:41 -07002478 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002479 publish();
arunvoddud7401012022-12-15 16:08:12 +00002480 CarrierAllowListInfo.loadInstance(mApp);
Hyosun Kim240214a2023-11-02 13:30:15 +00002481
2482 // Create the SatelliteEntitlementController singleton, for using the get the
2483 // entitlementStatus for satellite service.
2484 SatelliteEntitlementController.make(mApp, mFeatureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002485 }
2486
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002487 @VisibleForTesting
2488 public SharedPreferences getSharedPreferences() {
2489 return mTelephonySharedPreferences;
2490 }
2491
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002492 /**
2493 * Get the default phone for this device.
2494 */
2495 @VisibleForTesting
2496 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002497 Phone thePhone = getPhone(getDefaultSubscription());
2498 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2499 }
2500
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002501 private void publish() {
2502 if (DBG) log("publish: " + this);
2503
Peter Wangc035ce42020-01-08 21:00:22 -08002504 TelephonyFrameworkInitializer
2505 .getTelephonyServiceManager()
2506 .getTelephonyServiceRegisterer()
2507 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002508 }
2509
Stuart Scott584921c2015-01-15 17:10:34 -08002510 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002511 if (request.phone != null) {
2512 return request.phone;
2513 } else {
2514 return getPhoneFromSubId(request.subId);
2515 }
2516 }
2517
2518 private Phone getPhoneFromSubId(int subId) {
2519 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2520 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002521 }
2522
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002523 /**
2524 * Get phone object associated with a subscription.
2525 * Return default phone if phone object associated with subscription is null
2526 * @param subId - subscriptionId
2527 * @return phone object associated with a subscription or default phone if null.
2528 */
Ling Mac28f0212023-03-24 16:07:15 -07002529 private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) {
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002530 Phone phone = getPhoneFromSubId(subId);
2531 if (phone == null) {
Ling Mac28f0212023-03-24 16:07:15 -07002532 loge("Called with invalid subId: " + subId + ". Retrying with default phone.");
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002533 phone = getDefaultPhone();
2534 }
2535 return phone;
2536 }
2537
Rambo Wange53e07d2022-05-10 13:01:13 -07002538 @Nullable
2539 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002540 Phone phone = getPhoneFromRequest(request);
2541 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002542 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002543 }
2544
Ling Mac28f0212023-03-24 16:07:15 -07002545 /**
2546 * @param subId The sub Id that associates the phone. If the device has no active SIM, passing
2547 * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <=
2548 * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}.
2549 * @return The Phone associated the sub Id
2550 */
2551 private @Nullable Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002552 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002553 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002554
Kai Shif70f46f2021-03-03 13:59:46 -08002555 private void sendEraseModemConfig(@NonNull Phone phone) {
2556 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2557 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2558 }
2559
2560 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2561 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2562 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002563 }
2564
Peter Wang44b186e2020-01-13 23:33:09 -08002565 private boolean isImsAvailableOnDevice() {
2566 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2567 if (pm == null) {
2568 // For some reason package manger is not available.. This will fail internally anyway,
2569 // so do not throw error and allow.
2570 return true;
2571 }
2572 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2573 }
2574
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002575 public void dial(String number) {
joonhunshin4ac60942023-11-15 15:23:39 +00002576 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2577 PackageManager.FEATURE_TELEPHONY_CALLING, "dial");
2578
Wink Savilleadd7cc52014-09-08 14:23:09 -07002579 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002580 }
2581
Wink Savilleb564aae2014-10-23 10:18:09 -07002582 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002583 if (DBG) log("dial: " + number);
2584 // No permission check needed here: This is just a wrapper around the
2585 // ACTION_DIAL intent, which is available to any app since it puts up
2586 // the UI before it does anything.
2587
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002588 final long identity = Binder.clearCallingIdentity();
2589 try {
2590 String url = createTelUrl(number);
2591 if (url == null) {
2592 return;
2593 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002594
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002595 // PENDING: should we just silently fail if phone is offhook or ringing?
2596 PhoneConstants.State state = mCM.getState(subId);
2597 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2598 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2599 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2600 mApp.startActivity(intent);
2601 }
2602 } finally {
2603 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002604 }
2605 }
2606
2607 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002608 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002609 }
2610
Wink Savilleb564aae2014-10-23 10:18:09 -07002611 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002612 if (DBG) log("call: " + number);
2613
2614 // This is just a wrapper around the ACTION_CALL intent, but we still
2615 // need to do a permission check since we're calling startActivity()
2616 // from the context of the phone app.
2617 enforceCallPermission();
2618
Jordan Liu1617b712019-07-10 15:06:26 -07002619 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002620 != AppOpsManager.MODE_ALLOWED) {
2621 return;
2622 }
2623
joonhunshin4ac60942023-11-15 15:23:39 +00002624 enforceTelephonyFeatureWithException(callingPackage,
2625 PackageManager.FEATURE_TELEPHONY_CALLING, "call");
2626
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002627 final long identity = Binder.clearCallingIdentity();
2628 try {
2629 String url = createTelUrl(number);
2630 if (url == null) {
2631 return;
2632 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002633
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002634 boolean isValid = false;
2635 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2636 if (slist != null) {
2637 for (SubscriptionInfo subInfoRecord : slist) {
2638 if (subInfoRecord.getSubscriptionId() == subId) {
2639 isValid = true;
2640 break;
2641 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002642 }
Wink Saville08874612014-08-31 19:19:58 -07002643 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002644 if (!isValid) {
2645 return;
2646 }
Wink Saville08874612014-08-31 19:19:58 -07002647
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002648 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2649 intent.putExtra(SUBSCRIPTION_KEY, subId);
2650 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2651 mApp.startActivity(intent);
2652 } finally {
2653 Binder.restoreCallingIdentity(identity);
2654 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002655 }
2656
Wink Savilleb564aae2014-10-23 10:18:09 -07002657 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002658 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002659 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2660 }
2661
Wink Savilleb564aae2014-10-23 10:18:09 -07002662 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002663 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002664 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2665 }
2666
Wink Savilleb564aae2014-10-23 10:18:09 -07002667 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002668 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002669
joonhunshin4ac60942023-11-15 15:23:39 +00002670 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2671 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
2672 "supplyPinReportResultForSubscriber");
2673
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002674 final long identity = Binder.clearCallingIdentity();
2675 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002676 Phone phone = getPhone(subId);
2677 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002678 checkSimPin.start();
2679 return checkSimPin.unlockSim(null, pin);
2680 } finally {
2681 Binder.restoreCallingIdentity(identity);
2682 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002683 }
2684
Wink Savilleb564aae2014-10-23 10:18:09 -07002685 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002686 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002687
joonhunshin4ac60942023-11-15 15:23:39 +00002688 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2689 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "supplyPukForSubscriber");
2690
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002691 final long identity = Binder.clearCallingIdentity();
2692 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002693 Phone phone = getPhone(subId);
2694 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002695 checkSimPuk.start();
2696 return checkSimPuk.unlockSim(puk, pin);
2697 } finally {
2698 Binder.restoreCallingIdentity(identity);
2699 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002700 }
2701
2702 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002703 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002704 * a synchronous one.
2705 */
2706 private static class UnlockSim extends Thread {
2707
2708 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002709 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002710
2711 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002712 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2713 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002714
2715 // For replies from SimCard interface
2716 private Handler mHandler;
2717
2718 // For async handler to identify request type
2719 private static final int SUPPLY_PIN_COMPLETE = 100;
2720
Michele Berionne5e411512020-11-13 02:36:59 +00002721 UnlockSim(int phoneId, IccCard simCard) {
2722 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002723 mSimCard = simCard;
2724 }
2725
2726 @Override
2727 public void run() {
2728 Looper.prepare();
2729 synchronized (UnlockSim.this) {
2730 mHandler = new Handler() {
2731 @Override
2732 public void handleMessage(Message msg) {
2733 AsyncResult ar = (AsyncResult) msg.obj;
2734 switch (msg.what) {
2735 case SUPPLY_PIN_COMPLETE:
2736 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2737 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002738 mRetryCount = msg.arg1;
2739 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002740 CommandException.Error error = null;
2741 if (ar.exception instanceof CommandException) {
2742 error = ((CommandException) (ar.exception))
2743 .getCommandError();
2744 }
2745 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07002746 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002747 } else if (error == CommandException.Error.ABORTED) {
2748 /* When UiccCardApp dispose, handle message and return
2749 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08002750 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002751 } else {
2752 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2753 }
2754 } else {
2755 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2756 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002757 mDone = true;
2758 UnlockSim.this.notifyAll();
2759 }
2760 break;
2761 }
2762 }
2763 };
2764 UnlockSim.this.notifyAll();
2765 }
2766 Looper.loop();
2767 }
2768
2769 /*
2770 * Use PIN or PUK to unlock SIM card
2771 *
2772 * If PUK is null, unlock SIM card with PIN
2773 *
2774 * If PUK is not null, unlock SIM card with PUK and set PIN code
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302775 *
2776 * Besides, since it is reused in class level, the thread's looper will be stopped to avoid
2777 * its thread leak.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002778 */
Wink Saville9de0f752013-10-22 19:04:03 -07002779 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002780
2781 while (mHandler == null) {
2782 try {
2783 wait();
2784 } catch (InterruptedException e) {
2785 Thread.currentThread().interrupt();
2786 }
2787 }
2788 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2789
2790 if (puk == null) {
2791 mSimCard.supplyPin(pin, callback);
2792 } else {
2793 mSimCard.supplyPuk(puk, pin, callback);
2794 }
2795
2796 while (!mDone) {
2797 try {
2798 Log.d(LOG_TAG, "wait for done");
2799 wait();
2800 } catch (InterruptedException e) {
2801 // Restore the interrupted status
2802 Thread.currentThread().interrupt();
2803 }
2804 }
2805 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002806 int[] resultArray = new int[2];
2807 resultArray[0] = mResult;
2808 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002809
2810 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002811 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002812 }
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302813 // This instance is no longer reused, so quit its thread's looper.
2814 mHandler.getLooper().quitSafely();
Michele Berionne5e411512020-11-13 02:36:59 +00002815
Wink Saville9de0f752013-10-22 19:04:03 -07002816 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002817 }
2818 }
2819
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002820 /**
2821 * This method has been removed due to privacy and stability concerns.
2822 */
2823 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002824 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002825 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2826 return;
Wink Saville36469e72014-06-11 15:17:00 -07002827 }
2828
Nathan Harold1f889d82020-06-04 17:05:26 -07002829 @Override
2830 public void updateServiceLocationWithPackageName(String callingPackage) {
2831 mApp.getSystemService(AppOpsManager.class)
2832 .checkPackage(Binder.getCallingUid(), callingPackage);
2833
Nathan Haroldf096d982020-11-18 17:18:06 -08002834 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002835 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2836 // Callers targeting S have no business invoking this method.
2837 return;
2838 }
2839
2840 LocationAccessPolicy.LocationPermissionResult locationResult =
2841 LocationAccessPolicy.checkLocationPermission(mApp,
2842 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2843 .setCallingPackage(callingPackage)
2844 .setCallingFeatureId(null)
2845 .setCallingPid(Binder.getCallingPid())
2846 .setCallingUid(Binder.getCallingUid())
2847 .setMethod("updateServiceLocation")
2848 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2849 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2850 .build());
2851 // Apps that lack location permission have no business calling this method;
2852 // however, because no permission was declared in the public API, denials must
2853 // all be "soft".
2854 switch (locationResult) {
2855 case DENIED_HARD: /* fall through */
2856 case DENIED_SOFT:
2857 return;
2858 }
2859
2860 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002861 final long identity = Binder.clearCallingIdentity();
2862 try {
Ling Mac28f0212023-03-24 16:07:15 -07002863 getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002864 } finally {
2865 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002866 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002867 }
2868
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002869 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002870 @Override
2871 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002872 return isRadioOnWithFeature(callingPackage, null);
2873 }
2874
2875
2876 @Override
2877 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2878 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2879 callingFeatureId);
2880 }
2881
2882 @Deprecated
2883 @Override
2884 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2885 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002886 }
2887
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002888 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002889 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2890 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002891 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002892 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002893 return false;
2894 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002895
joonhunshin4ac60942023-11-15 15:23:39 +00002896 enforceTelephonyFeatureWithException(callingPackage,
2897 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isRadioOnWithFeature");
2898
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002899 final long identity = Binder.clearCallingIdentity();
2900 try {
2901 return isRadioOnForSubscriber(subId);
2902 } finally {
2903 Binder.restoreCallingIdentity(identity);
2904 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002905 }
2906
2907 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002908 final long identity = Binder.clearCallingIdentity();
2909 try {
2910 final Phone phone = getPhone(subId);
2911 if (phone != null) {
2912 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2913 } else {
2914 return false;
2915 }
2916 } finally {
2917 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002918 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002919 }
2920
2921 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002922 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002923 }
Wink Saville36469e72014-06-11 15:17:00 -07002924
Wink Savilleb564aae2014-10-23 10:18:09 -07002925 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002926 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002927
joonhunshin4ac60942023-11-15 15:23:39 +00002928 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2929 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "toggleRadioOnOffForSubscriber");
2930
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002931 final long identity = Binder.clearCallingIdentity();
2932 try {
2933 final Phone phone = getPhone(subId);
2934 if (phone != null) {
2935 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2936 }
2937 } finally {
2938 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002939 }
Wink Saville36469e72014-06-11 15:17:00 -07002940 }
2941
2942 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002943 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002944 }
2945
Wink Savilleb564aae2014-10-23 10:18:09 -07002946 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002947 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002948
2949 final long identity = Binder.clearCallingIdentity();
2950 try {
2951 final Phone phone = getPhone(subId);
2952 if (phone == null) {
2953 return false;
2954 }
2955 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2956 toggleRadioOnOffForSubscriber(subId);
2957 }
2958 return true;
2959 } finally {
2960 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002961 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002962 }
Wink Saville36469e72014-06-11 15:17:00 -07002963
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002964 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002965 enforceReadPrivilegedPermission("needMobileRadioShutdown");
joonhunshin4ac60942023-11-15 15:23:39 +00002966
2967 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2968 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needMobileRadioShutdown");
2969
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002970 /*
2971 * If any of the Radios are available, it will need to be
2972 * shutdown. So return true if any Radio is available.
2973 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002974 final long identity = Binder.clearCallingIdentity();
2975 try {
2976 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2977 Phone phone = PhoneFactory.getPhone(i);
2978 if (phone != null && phone.isRadioAvailable()) return true;
2979 }
2980 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2981 return false;
2982 } finally {
2983 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002984 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002985 }
2986
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002987 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002988 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002989 enforceModifyPermission();
2990
joonhunshin4ac60942023-11-15 15:23:39 +00002991 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2992 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "shutdownMobileRadios");
2993
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002994 final long identity = Binder.clearCallingIdentity();
2995 try {
2996 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2997 logv("Shutting down Phone " + i);
2998 shutdownRadioUsingPhoneId(i);
2999 }
3000 } finally {
3001 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003002 }
3003 }
3004
3005 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003006 Phone phone = PhoneFactory.getPhone(phoneId);
3007 if (phone != null && phone.isRadioAvailable()) {
3008 phone.shutdownRadio();
3009 }
3010 }
3011
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003012 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07003013 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003014
Ling Ma83dc5ea2023-01-12 15:06:04 -08003015 if (!turnOn) {
3016 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
3017 }
3018
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003019 final long identity = Binder.clearCallingIdentity();
3020 try {
3021 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
3022 if (defaultPhone != null) {
3023 defaultPhone.setRadioPower(turnOn);
3024 return true;
3025 } else {
3026 loge("There's no default phone.");
3027 return false;
3028 }
3029 } finally {
3030 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07003031 }
Wink Saville36469e72014-06-11 15:17:00 -07003032 }
3033
Wink Savilleb564aae2014-10-23 10:18:09 -07003034 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003035 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003036
Ling Ma83dc5ea2023-01-12 15:06:04 -08003037 if (!turnOn) {
3038 log("setRadioPowerForSubscriber off: subId=" + subId
3039 + ",callingPackage=" + getCurrentPackageName());
3040 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003041 final long identity = Binder.clearCallingIdentity();
3042 try {
3043 final Phone phone = getPhone(subId);
3044 if (phone != null) {
3045 phone.setRadioPower(turnOn);
3046 return true;
3047 } else {
3048 return false;
3049 }
3050 } finally {
3051 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003052 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003053 }
3054
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003055 /**
3056 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3057 * no reason to power it off. When any of the voters want to power it off, it will be turned
3058 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3059 * powering it off, and these radio off votes will be cleared.
3060 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3061 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3062 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3063 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3064 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3065 * check its vote.
3066 *
3067 * @param subId The subscription ID.
3068 * @param reason The reason for powering off radio.
3069 * @return true on success and false on failure.
3070 */
3071 public boolean requestRadioPowerOffForReason(int subId,
3072 @TelephonyManager.RadioPowerReason int reason) {
3073 enforceModifyPermission();
3074
joonhunshin4ac60942023-11-15 15:23:39 +00003075 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3076 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestRadioPowerOffForReason");
3077
Ling Ma83dc5ea2023-01-12 15:06:04 -08003078 log("requestRadioPowerOffForReason: subId=" + subId
3079 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003080 final long identity = Binder.clearCallingIdentity();
3081 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003082 boolean result = false;
3083 for (Phone phone : PhoneFactory.getPhones()) {
3084 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003085 phone.setRadioPowerForReason(false, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003086 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003087 if (!result) {
3088 loge("requestRadioPowerOffForReason: no phone exists");
3089 }
3090 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003091 } finally {
3092 Binder.restoreCallingIdentity(identity);
3093 }
3094 }
3095
3096 /**
3097 * Remove the vote on powering off the radio for a reason, as requested by
3098 * {@link requestRadioPowerOffForReason}.
3099 *
3100 * @param subId The subscription ID.
3101 * @param reason The reason for powering off radio.
3102 * @return true on success and false on failure.
3103 */
3104 public boolean clearRadioPowerOffForReason(int subId,
3105 @TelephonyManager.RadioPowerReason int reason) {
3106 enforceModifyPermission();
3107
joonhunshin4ac60942023-11-15 15:23:39 +00003108 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3109 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearRadioPowerOffForReason");
3110
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003111 final long identity = Binder.clearCallingIdentity();
3112 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003113 boolean result = false;
3114 for (Phone phone : PhoneFactory.getPhones()) {
3115 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003116 phone.setRadioPowerForReason(true, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003117 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003118 if (!result) {
3119 loge("clearRadioPowerOffForReason: no phone exists");
3120 }
3121 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003122 } finally {
3123 Binder.restoreCallingIdentity(identity);
3124 }
3125 }
3126
3127 /**
3128 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3129 *
3130 * @param subId The subscription ID.
3131 * @param callingPackage The package making the call.
3132 * @param callingFeatureId The feature in the package.
3133 * @return List of reasons for powering off radio.
3134 */
3135 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3136 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3137
joonhunshin4ac60942023-11-15 15:23:39 +00003138 enforceTelephonyFeatureWithException(callingPackage,
3139 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerOffReasons");
3140
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003141 final long identity = Binder.clearCallingIdentity();
3142 List result = new ArrayList();
3143 try {
3144 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3145 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3146 return result;
3147 }
3148
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003149 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003150 if (phone != null) {
3151 result.addAll(phone.getRadioPowerOffReasons());
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003152 } else {
3153 loge("getRadioPowerOffReasons: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003154 }
3155 } finally {
3156 Binder.restoreCallingIdentity(identity);
3157 }
3158 return result;
3159 }
3160
Wink Saville36469e72014-06-11 15:17:00 -07003161 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003162 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003163 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003164 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003165
joonhunshin4ac60942023-11-15 15:23:39 +00003166 enforceTelephonyFeatureWithException(callingPackage,
3167 PackageManager.FEATURE_TELEPHONY_DATA, "enableDataConnectivity");
3168
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003169 final long identity = Binder.clearCallingIdentity();
3170 try {
Jack Yu285100e2022-12-02 22:48:35 -08003171 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003172 final Phone phone = getPhone(subId);
3173 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003174 phone.getDataSettingsManager().setDataEnabled(
3175 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003176 return true;
3177 } else {
3178 return false;
3179 }
3180 } finally {
3181 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003182 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003183 }
3184
Wink Saville36469e72014-06-11 15:17:00 -07003185 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003186 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003187 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003188 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003189
joonhunshin4ac60942023-11-15 15:23:39 +00003190 enforceTelephonyFeatureWithException(callingPackage,
3191 PackageManager.FEATURE_TELEPHONY_DATA, "disableDataConnectivity");
3192
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003193 final long identity = Binder.clearCallingIdentity();
3194 try {
Jack Yu285100e2022-12-02 22:48:35 -08003195 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003196 final Phone phone = getPhone(subId);
3197 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003198 phone.getDataSettingsManager().setDataEnabled(
3199 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003200 return true;
3201 } else {
3202 return false;
3203 }
3204 } finally {
3205 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003206 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003207 }
3208
Sanket Padawe356d7632015-06-22 14:03:32 -07003209 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003210 public boolean isDataConnectivityPossible(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003211 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3212 PackageManager.FEATURE_TELEPHONY_DATA, "isDataConnectivityPossible");
3213
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003214 final long identity = Binder.clearCallingIdentity();
3215 try {
3216 final Phone phone = getPhone(subId);
3217 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003218 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003219 } else {
3220 return false;
3221 }
3222 } finally {
3223 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003224 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003225 }
3226
3227 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003228 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003229 }
3230
pkanwarae03a6b2016-11-06 20:37:09 -08003231 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003232 enforceCallPermission();
3233
joonhunshin4ac60942023-11-15 15:23:39 +00003234 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3235 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "handleUssdRequest");
3236
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003237 final long identity = Binder.clearCallingIdentity();
3238 try {
3239 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3240 return;
3241 }
3242 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3243 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3244 } finally {
3245 Binder.restoreCallingIdentity(identity);
3246 }
pkanwar32d516d2016-10-14 19:37:38 -07003247 };
3248
Wink Savilleb564aae2014-10-23 10:18:09 -07003249 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003250 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003251
joonhunshin4ac60942023-11-15 15:23:39 +00003252 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3253 PackageManager.FEATURE_TELEPHONY_CALLING, "handlePinMmiForSubscriber");
3254
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003255 final long identity = Binder.clearCallingIdentity();
3256 try {
3257 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3258 return false;
3259 }
3260 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3261 } finally {
3262 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003263 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003264 }
3265
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003266 /**
3267 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3268 * tag on getCallState Binder call.
3269 */
3270 @Deprecated
3271 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003272 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003273 if (CompatChanges.isChangeEnabled(
3274 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3275 Binder.getCallingUid())) {
3276 // Do not allow this API to be called on API version 31+, it should only be
3277 // called on old apps using this Binder call directly.
3278 throw new SecurityException("This method can only be used for applications "
3279 + "targeting API version 30 or less.");
3280 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003281 final long identity = Binder.clearCallingIdentity();
3282 try {
Ling Mac28f0212023-03-24 16:07:15 -07003283 Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription());
3284 return PhoneConstantConversions.convertCallState(phone.getState());
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003285 } finally {
3286 Binder.restoreCallingIdentity(identity);
3287 }
3288 }
3289
3290 @Override
3291 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3292 if (CompatChanges.isChangeEnabled(
3293 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3294 Binder.getCallingUid())) {
3295 // Check READ_PHONE_STATE for API version 31+
3296 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3297 featureId, "getCallStateForSubscription")) {
3298 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3299 + "targeting API level 31+.");
3300 }
3301 }
joonhunshin4ac60942023-11-15 15:23:39 +00003302
3303 enforceTelephonyFeatureWithException(callingPackage,
3304 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallStateForSubscription");
3305
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003306 final long identity = Binder.clearCallingIdentity();
3307 try {
3308 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003309 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3310 PhoneConstantConversions.convertCallState(phone.getState());
3311 } finally {
3312 Binder.restoreCallingIdentity(identity);
3313 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003314 }
3315
Sanket Padawe356d7632015-06-22 14:03:32 -07003316 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003317 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003318 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003319 }
3320
3321 @Override
3322 public int getDataStateForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003323 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3324 PackageManager.FEATURE_TELEPHONY_DATA, "getDataStateForSubId");
3325
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003326 final long identity = Binder.clearCallingIdentity();
3327 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003328 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003329 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003330 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003331 } else {
3332 return PhoneConstantConversions.convertDataState(
3333 PhoneConstants.DataState.DISCONNECTED);
3334 }
3335 } finally {
3336 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003337 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003338 }
3339
Sanket Padawe356d7632015-06-22 14:03:32 -07003340 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003341 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003342 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003343 }
3344
3345 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003346 public @DataActivityType int getDataActivityForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003347 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3348 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivityForSubId");
3349
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003350 final long identity = Binder.clearCallingIdentity();
3351 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003352 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003353 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003354 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003355 } else {
3356 return TelephonyManager.DATA_ACTIVITY_NONE;
3357 }
3358 } finally {
3359 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003360 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003361 }
3362
3363 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003364 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003365 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003366 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003367
3368 LocationAccessPolicy.LocationPermissionResult locationResult =
3369 LocationAccessPolicy.checkLocationPermission(mApp,
3370 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3371 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003372 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003373 .setCallingPid(Binder.getCallingPid())
3374 .setCallingUid(Binder.getCallingUid())
3375 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003376 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003377 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3378 .build());
3379 switch (locationResult) {
3380 case DENIED_HARD:
3381 throw new SecurityException("Not allowed to access cell location");
3382 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003383 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3384 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003385 }
3386
joonhunshin4ac60942023-11-15 15:23:39 +00003387 enforceTelephonyFeatureWithException(callingPackage,
3388 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getCellLocation");
3389
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003390 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003391 final long identity = Binder.clearCallingIdentity();
3392 try {
3393 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003394 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003395 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003396 } finally {
3397 Binder.restoreCallingIdentity(identity);
3398 }
Svetoslav64fad262015-04-14 14:35:21 -07003399 }
3400
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003401 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003402 public String getNetworkCountryIsoForPhone(int phoneId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003403 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3404 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkCountryIsoForPhone");
3405
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003406 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3407 // registered cell info, so return a NULL country instead.
3408 final long identity = Binder.clearCallingIdentity();
3409 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003410 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3411 // Get default phone in this case.
3412 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3413 }
Jack Yu285100e2022-12-02 22:48:35 -08003414 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003415 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003416 if (phone == null) return "";
3417 ServiceStateTracker sst = phone.getServiceStateTracker();
3418 if (sst == null) return "";
3419 LocaleTracker lt = sst.getLocaleTracker();
3420 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003421 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003422 } finally {
3423 Binder.restoreCallingIdentity(identity);
3424 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003425 }
3426
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003427 /**
3428 * This method was removed due to potential issues caused by performing partial
3429 * updates of service state, and lack of a credible use case.
3430 *
3431 * This has the ability to break the telephony implementation by disabling notification of
3432 * changes in device connectivity. DO NOT USE THIS!
3433 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003434 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003435 public void enableLocationUpdates() {
3436 mApp.enforceCallingOrSelfPermission(
3437 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003438 }
3439
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003440 /**
3441 * This method was removed due to potential issues caused by performing partial
3442 * updates of service state, and lack of a credible use case.
3443 *
3444 * This has the ability to break the telephony implementation by disabling notification of
3445 * changes in device connectivity. DO NOT USE THIS!
3446 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003447 @Override
3448 public void disableLocationUpdates() {
3449 mApp.enforceCallingOrSelfPermission(
3450 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003451 }
3452
3453 @Override
3454 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003455 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3456 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003457 try {
3458 mApp.getSystemService(AppOpsManager.class)
3459 .checkPackage(Binder.getCallingUid(), callingPackage);
3460 } catch (SecurityException e) {
3461 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3462 throw e;
3463 }
3464
Nathan Haroldf096d982020-11-18 17:18:06 -08003465 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003466 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3467 throw new SecurityException(
3468 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3469 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003470
Jordan Liu1617b712019-07-10 15:06:26 -07003471 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003472 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3473 return null;
3474 }
Svetoslav64fad262015-04-14 14:35:21 -07003475
joonhunshin4ac60942023-11-15 15:23:39 +00003476 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3477 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNeighboringCellInfo");
3478
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003479 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003480
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003481 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003482 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003483
Nathan Haroldf180aac2018-06-01 18:43:55 -07003484 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3485 for (CellInfo ci : info) {
3486 if (ci instanceof CellInfoGsm) {
3487 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3488 } else if (ci instanceof CellInfoWcdma) {
3489 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3490 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003491 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003492 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003493 }
3494
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003495 private List<CellInfo> getCachedCellInfo() {
3496 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3497 for (Phone phone : PhoneFactory.getPhones()) {
3498 List<CellInfo> info = phone.getAllCellInfo();
3499 if (info != null) cellInfos.addAll(info);
3500 }
3501 return cellInfos;
3502 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003503
3504 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003505 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003506 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003507 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003508
3509 LocationAccessPolicy.LocationPermissionResult locationResult =
3510 LocationAccessPolicy.checkLocationPermission(mApp,
3511 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3512 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003513 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003514 .setCallingPid(Binder.getCallingPid())
3515 .setCallingUid(Binder.getCallingUid())
3516 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003517 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003518 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3519 .build());
3520 switch (locationResult) {
3521 case DENIED_HARD:
3522 throw new SecurityException("Not allowed to access cell info");
3523 case DENIED_SOFT:
3524 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003525 }
3526
Nathan Haroldf096d982020-11-18 17:18:06 -08003527 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003528 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3529 return getCachedCellInfo();
3530 }
3531
joonhunshin4ac60942023-11-15 15:23:39 +00003532 enforceTelephonyFeatureWithException(callingPackage,
3533 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllCellInfo");
3534
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003535 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003536 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003537 final long identity = Binder.clearCallingIdentity();
3538 try {
3539 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3540 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003541 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003542 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003543 if (info != null) cellInfos.addAll(info);
3544 }
3545 return cellInfos;
3546 } finally {
3547 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003548 }
3549 }
3550
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003551 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003552 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3553 String callingFeatureId) {
3554 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3555 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003556 }
3557
3558 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003559 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3560 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003561 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003562 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003563 }
3564
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003565 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3566 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003567 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003568 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003569
3570 LocationAccessPolicy.LocationPermissionResult locationResult =
3571 LocationAccessPolicy.checkLocationPermission(mApp,
3572 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3573 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003574 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003575 .setCallingPid(Binder.getCallingPid())
3576 .setCallingUid(Binder.getCallingUid())
3577 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003578 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3579 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003580 .build());
3581 switch (locationResult) {
3582 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003583 if (TelephonyPermissions
3584 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003585 // Safetynet logging for b/154934934
3586 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3587 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003588 throw new SecurityException("Not allowed to access cell info");
3589 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003590 if (TelephonyPermissions
3591 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003592 // Safetynet logging for b/154934934
3593 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3594 }
Nathan Harold5320c422019-05-09 10:26:08 -07003595 try {
3596 cb.onCellInfo(new ArrayList<CellInfo>());
3597 } catch (RemoteException re) {
3598 // Drop without consequences
3599 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003600 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003601 }
3602
joonhunshin4ac60942023-11-15 15:23:39 +00003603 enforceTelephonyFeatureWithException(callingPackage,
3604 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestCellInfoUpdateInternal");
Nathan Harolda939a962019-05-09 10:13:47 -07003605
3606 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003607 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3608
3609 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3610 }
3611
3612 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003613 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003614 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003615 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003616
3617 final long identity = Binder.clearCallingIdentity();
3618 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003619 Phone phone = getPhone(subId);
3620 if (phone == null) {
3621 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3622 } else {
3623 phone.setCellInfoListRate(rateInMillis, workSource);
3624 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003625 } finally {
3626 Binder.restoreCallingIdentity(identity);
3627 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003628 }
3629
Shishir Agrawala9f32182016-04-12 12:00:16 -07003630 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003631 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003632 Phone phone = PhoneFactory.getPhone(slotIndex);
3633 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003634 return null;
3635 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003636 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003637 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003638 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003639 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003640 return null;
3641 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003642
joonhunshin4ac60942023-11-15 15:23:39 +00003643 enforceTelephonyFeatureWithException(callingPackage,
3644 PackageManager.FEATURE_TELEPHONY_GSM, "getImeiForSlot");
3645
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003646 final long identity = Binder.clearCallingIdentity();
3647 try {
3648 return phone.getImei();
3649 } finally {
3650 Binder.restoreCallingIdentity(identity);
3651 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003652 }
3653
3654 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003655 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3656 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3657 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3658 callingFeatureId, "getPrimaryImei")) {
3659 throw new SecurityException("Caller does not have permission");
3660 }
joonhunshin4ac60942023-11-15 15:23:39 +00003661
3662 enforceTelephonyFeatureWithException(callingPackage,
3663 PackageManager.FEATURE_TELEPHONY_GSM, "getPrimaryImei");
3664
arunvoddud5c6ce02022-12-11 06:03:12 +00003665 final long identity = Binder.clearCallingIdentity();
3666 try {
3667 for (Phone phone : PhoneFactory.getPhones()) {
3668 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3669 return phone.getImei();
3670 }
3671 }
3672 throw new UnsupportedOperationException("Operation not supported");
3673 } finally {
3674 Binder.restoreCallingIdentity(identity);
3675 }
3676 }
3677
3678 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003679 public String getTypeAllocationCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003680 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3681 PackageManager.FEATURE_TELEPHONY_GSM, "getTypeAllocationCodeForSlot");
3682
David Kelly5e06a7f2018-03-12 14:10:59 +00003683 Phone phone = PhoneFactory.getPhone(slotIndex);
3684 String tac = null;
3685 if (phone != null) {
3686 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003687 try {
3688 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3689 } catch (IndexOutOfBoundsException e) {
3690 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3691 return null;
3692 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003693 }
3694 return tac;
3695 }
3696
3697 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003698 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003699 try {
3700 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3701 } catch (SecurityException se) {
3702 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3703 throw new SecurityException("Package " + callingPackage + " does not belong to "
3704 + Binder.getCallingUid());
3705 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003706 Phone phone = PhoneFactory.getPhone(slotIndex);
3707 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003708 return null;
3709 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003710
Jeff Davidson913390f2018-02-23 17:11:49 -08003711 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003712 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003713 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003714 return null;
3715 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003716
joonhunshin4ac60942023-11-15 15:23:39 +00003717 enforceTelephonyFeatureWithException(callingPackage,
3718 PackageManager.FEATURE_TELEPHONY_CDMA, "getMeidForSlot");
3719
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003720 final long identity = Binder.clearCallingIdentity();
3721 try {
3722 return phone.getMeid();
3723 } finally {
3724 Binder.restoreCallingIdentity(identity);
3725 }
Jack Yu2af8d712017-03-15 17:14:14 -07003726 }
3727
3728 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003729 public String getManufacturerCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003730 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3731 PackageManager.FEATURE_TELEPHONY_CDMA, "getManufacturerCodeForSlot");
3732
David Kelly5e06a7f2018-03-12 14:10:59 +00003733 Phone phone = PhoneFactory.getPhone(slotIndex);
3734 String manufacturerCode = null;
3735 if (phone != null) {
3736 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003737 try {
3738 manufacturerCode =
3739 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3740 } catch (IndexOutOfBoundsException e) {
3741 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3742 return null;
3743 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003744 }
3745 return manufacturerCode;
3746 }
3747
3748 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003749 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3750 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003751 Phone phone = PhoneFactory.getPhone(slotIndex);
3752 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003753 return null;
3754 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003755 int subId = phone.getSubId();
3756 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003757 mApp, subId, callingPackage, callingFeatureId,
3758 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003759 return null;
3760 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003761
joonhunshin4ac60942023-11-15 15:23:39 +00003762 enforceTelephonyFeatureWithException(callingPackage,
3763 PackageManager.FEATURE_TELEPHONY, "getDeviceSoftwareVersionForSlot");
3764
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003765 final long identity = Binder.clearCallingIdentity();
3766 try {
3767 return phone.getDeviceSvn();
3768 } finally {
3769 Binder.restoreCallingIdentity(identity);
3770 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003771 }
3772
fionaxu43304da2017-11-27 22:51:16 -08003773 @Override
3774 public int getSubscriptionCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003775 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3776 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierId");
3777
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003778 final long identity = Binder.clearCallingIdentity();
3779 try {
3780 final Phone phone = getPhone(subId);
3781 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3782 } finally {
3783 Binder.restoreCallingIdentity(identity);
3784 }
fionaxu43304da2017-11-27 22:51:16 -08003785 }
3786
3787 @Override
3788 public String getSubscriptionCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003789 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3790 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierName");
3791
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003792 final long identity = Binder.clearCallingIdentity();
3793 try {
3794 final Phone phone = getPhone(subId);
3795 return phone == null ? null : phone.getCarrierName();
3796 } finally {
3797 Binder.restoreCallingIdentity(identity);
3798 }
fionaxu43304da2017-11-27 22:51:16 -08003799 }
3800
calvinpanffe225e2018-11-01 19:43:06 +08003801 @Override
chen xu0026ca62019-03-06 15:28:50 -08003802 public int getSubscriptionSpecificCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003803 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3804 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionSpecificCarrierId");
3805
chen xu25637222018-11-04 17:17:00 -08003806 final long identity = Binder.clearCallingIdentity();
3807 try {
3808 final Phone phone = getPhone(subId);
3809 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003810 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003811 } finally {
3812 Binder.restoreCallingIdentity(identity);
3813 }
3814 }
3815
3816 @Override
chen xu0026ca62019-03-06 15:28:50 -08003817 public String getSubscriptionSpecificCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003818 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3819 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
3820 "getSubscriptionSpecificCarrierName");
3821
chen xu25637222018-11-04 17:17:00 -08003822 final long identity = Binder.clearCallingIdentity();
3823 try {
3824 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003825 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003826 } finally {
3827 Binder.restoreCallingIdentity(identity);
3828 }
3829 }
3830
chen xu651eec72018-11-11 19:03:44 -08003831 @Override
chen xu864e11c2018-12-06 22:10:03 -08003832 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3833 if (!isSubscriptionMccMnc) {
3834 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3835 }
chen xu651eec72018-11-11 19:03:44 -08003836 final Phone phone = PhoneFactory.getPhone(slotIndex);
3837 if (phone == null) {
3838 return TelephonyManager.UNKNOWN_CARRIER_ID;
3839 }
joonhunshin4ac60942023-11-15 15:23:39 +00003840
3841 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3842 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromMccMnc");
3843
chen xu651eec72018-11-11 19:03:44 -08003844 final long identity = Binder.clearCallingIdentity();
3845 try {
3846 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3847 } finally {
3848 Binder.restoreCallingIdentity(identity);
3849 }
3850 }
3851
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003852 //
3853 // Internal helper methods.
3854 //
3855
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003856 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003857 * Make sure the caller is the calling package itself
3858 *
3859 * @throws SecurityException if the caller is not the calling package
3860 */
3861 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3862 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003863 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3864 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003865 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003866 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003867 } catch (PackageManager.NameNotFoundException e) {
3868 // packageUid is -1
3869 }
3870 if (packageUid != callingUid) {
3871 throw new SecurityException(message + ": Package " + callingPackage
3872 + " does not belong to " + callingUid);
3873 }
3874 }
3875
3876 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003877 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3878 *
3879 * @throws SecurityException if the caller does not have the required permission
3880 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003881 @VisibleForTesting
3882 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003883 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3884 }
3885
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003886 /**
arunvoddud7401012022-12-15 16:08:12 +00003887 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003888 *
3889 * @throws SecurityException if the caller does not have the required permission
3890 */
3891 @VisibleForTesting
3892 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003893 enforceReadPermission(null);
3894 }
3895
3896 /**
3897 * Make sure the caller has the READ_PHONE_STATE permissions.
3898 *
3899 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3900 */
3901 @VisibleForTesting
3902 public void enforceReadPermission(String msg) {
3903 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003904 }
3905
Shuo Qian3b6ee772019-11-13 17:43:31 -08003906 private void enforceActiveEmergencySessionPermission() {
3907 mApp.enforceCallingOrSelfPermission(
3908 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3909 }
3910
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003911 /**
3912 * Make sure the caller has the CALL_PHONE permission.
3913 *
3914 * @throws SecurityException if the caller does not have the required permission
3915 */
3916 private void enforceCallPermission() {
3917 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3918 }
3919
paulhu5a773602019-08-23 19:17:33 +08003920 private void enforceSettingsPermission() {
3921 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003922 }
3923
Michele Berionne5e411512020-11-13 02:36:59 +00003924 private void enforceRebootPermission() {
3925 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3926 }
3927
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003928 /**
3929 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3930 * @param message - log message to print.
3931 * @throws SecurityException if the caller does not have the required permission
3932 */
3933 private void enforceSatelliteCommunicationPermission(String message) {
3934 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3935 }
3936
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003937 private String createTelUrl(String number) {
3938 if (TextUtils.isEmpty(number)) {
3939 return null;
3940 }
3941
Jake Hambye994d462014-02-03 13:10:13 -08003942 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003943 }
3944
Ihab Awadf9e92732013-12-05 18:02:52 -08003945 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003946 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003947 }
3948
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003949 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003950 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003951 }
3952
Ihab Awadf9e92732013-12-05 18:02:52 -08003953 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003954 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003955 }
3956
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003957 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003958 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003959 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003960 }
3961
Sanket Padawe356d7632015-06-22 14:03:32 -07003962 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003963 public int getActivePhoneTypeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003964 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3965 PackageManager.FEATURE_TELEPHONY, "getActivePhoneTypeForSlot");
3966
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003967 final long identity = Binder.clearCallingIdentity();
3968 try {
3969 final Phone phone = PhoneFactory.getPhone(slotIndex);
3970 if (phone == null) {
3971 return PhoneConstants.PHONE_TYPE_NONE;
3972 } else {
3973 return phone.getPhoneType();
3974 }
3975 } finally {
3976 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003977 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003978 }
3979
3980 /**
3981 * Returns the CDMA ERI icon index to display
3982 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003983 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003984 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3985 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3986 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003987 }
3988
Sanket Padawe356d7632015-06-22 14:03:32 -07003989 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003990 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3991 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003992 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003993 mApp, subId, callingPackage, callingFeatureId,
3994 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003995 return -1;
3996 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003997
joonhunshin4ac60942023-11-15 15:23:39 +00003998 enforceTelephonyFeatureWithException(callingPackage,
3999 PackageManager.FEATURE_TELEPHONY_CDMA,
4000 "getCdmaEriIconIndexForSubscriber");
4001
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004002 final long identity = Binder.clearCallingIdentity();
4003 try {
4004 final Phone phone = getPhone(subId);
4005 if (phone != null) {
4006 return phone.getCdmaEriIconIndex();
4007 } else {
4008 return -1;
4009 }
4010 } finally {
4011 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004012 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004013 }
4014
4015 /**
4016 * Returns the CDMA ERI icon mode,
4017 * 0 - ON
4018 * 1 - FLASHING
4019 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004020 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004021 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
4022 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
4023 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004024 }
4025
Sanket Padawe356d7632015-06-22 14:03:32 -07004026 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004027 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
4028 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004029 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004030 mApp, subId, callingPackage, callingFeatureId,
4031 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004032 return -1;
4033 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004034
4035 final long identity = Binder.clearCallingIdentity();
4036 try {
4037 final Phone phone = getPhone(subId);
4038 if (phone != null) {
4039 return phone.getCdmaEriIconMode();
4040 } else {
4041 return -1;
4042 }
4043 } finally {
4044 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004045 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004046 }
4047
4048 /**
4049 * Returns the CDMA ERI text,
4050 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004051 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004052 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
4053 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
4054 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004055 }
4056
Sanket Padawe356d7632015-06-22 14:03:32 -07004057 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004058 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
4059 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004060 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004061 mApp, subId, callingPackage, callingFeatureId,
4062 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004063 return null;
4064 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004065
4066 final long identity = Binder.clearCallingIdentity();
4067 try {
4068 final Phone phone = getPhone(subId);
4069 if (phone != null) {
4070 return phone.getCdmaEriText();
4071 } else {
4072 return null;
4073 }
4074 } finally {
4075 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004076 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004077 }
4078
4079 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07004080 * Returns the CDMA MDN.
4081 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004082 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004083 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004084 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4085 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004086
joonhunshin4ac60942023-11-15 15:23:39 +00004087 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4088 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMdn");
4089
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004090 final long identity = Binder.clearCallingIdentity();
4091 try {
4092 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004093 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004094 return phone.getLine1Number();
4095 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004096 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004097 return null;
4098 }
4099 } finally {
4100 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004101 }
4102 }
4103
4104 /**
4105 * Returns the CDMA MIN.
4106 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004107 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004108 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004109 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4110 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004111
joonhunshin4ac60942023-11-15 15:23:39 +00004112 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4113 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMin");
4114
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004115 final long identity = Binder.clearCallingIdentity();
4116 try {
4117 final Phone phone = getPhone(subId);
4118 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
4119 return phone.getCdmaMin();
4120 } else {
4121 return null;
4122 }
4123 } finally {
4124 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004125 }
4126 }
4127
Hall Liud892bec2018-11-30 14:51:45 -08004128 @Override
4129 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
4130 INumberVerificationCallback callback, String callingPackage) {
4131 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
4132 != PERMISSION_GRANTED) {
4133 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
4134 }
4135 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4136
4137 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
4138 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08004139 throw new SecurityException("Calling package must be configured in the device config: "
4140 + "calling package: " + callingPackage
4141 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004142 }
4143
joonhunshin4ac60942023-11-15 15:23:39 +00004144 enforceTelephonyFeatureWithException(callingPackage,
4145 PackageManager.FEATURE_TELEPHONY_CALLING, "requestNumberVerification");
4146
Hall Liud892bec2018-11-30 14:51:45 -08004147 if (range == null) {
4148 throw new NullPointerException("Range must be non-null");
4149 }
4150
4151 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004152 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004153
4154 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4155 }
4156
Junda Liuca05d5d2014-08-14 22:36:34 -07004157 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004158 * Returns true if CDMA provisioning needs to run.
4159 */
4160 public boolean needsOtaServiceProvisioning() {
joonhunshin4ac60942023-11-15 15:23:39 +00004161 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4162 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needsOtaServiceProvisioning");
4163
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004164 final long identity = Binder.clearCallingIdentity();
4165 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004166 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004167 } finally {
4168 Binder.restoreCallingIdentity(identity);
4169 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004170 }
4171
4172 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004173 * Sets the voice mail number of a given subId.
4174 */
4175 @Override
4176 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004177 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4178 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004179
joonhunshin4ac60942023-11-15 15:23:39 +00004180 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4181 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceMailNumber");
4182
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004183 final long identity = Binder.clearCallingIdentity();
4184 try {
4185 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4186 new Pair<String, String>(alphaTag, number), new Integer(subId));
4187 return success;
4188 } finally {
4189 Binder.restoreCallingIdentity(identity);
4190 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004191 }
4192
Ta-wei Yen87c49842016-05-13 21:19:52 -07004193 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004194 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4195 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004196 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4197 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004198 if (!TextUtils.equals(callingPackage, systemDialer)) {
4199 throw new SecurityException("caller must be system dialer");
4200 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004201
joonhunshin4ac60942023-11-15 15:23:39 +00004202 enforceTelephonyFeatureWithException(callingPackage,
4203 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailSettings");
4204
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004205 final long identity = Binder.clearCallingIdentity();
4206 try {
4207 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4208 if (phoneAccountHandle == null) {
4209 return null;
4210 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004211 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004212 } finally {
4213 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004214 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004215 }
4216
4217 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004218 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4219 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004220 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004221 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004222 mApp, subId, callingPackage, callingFeatureId,
4223 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004224 return null;
4225 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004226
joonhunshin4ac60942023-11-15 15:23:39 +00004227 enforceTelephonyFeatureWithException(callingPackage,
4228 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailPackageName");
4229
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004230 final long identity = Binder.clearCallingIdentity();
4231 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004232 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004233 } finally {
4234 Binder.restoreCallingIdentity(identity);
4235 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004236 }
4237
4238 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004239 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4240 VisualVoicemailSmsFilterSettings settings) {
4241 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004242
joonhunshin4ac60942023-11-15 15:23:39 +00004243 enforceTelephonyFeatureWithException(callingPackage,
4244 PackageManager.FEATURE_TELEPHONY_CALLING, "enableVisualVoicemailSmsFilter");
4245
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004246 final long identity = Binder.clearCallingIdentity();
4247 try {
4248 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004249 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004250 } finally {
4251 Binder.restoreCallingIdentity(identity);
4252 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004253 }
4254
4255 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004256 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4257 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004258
joonhunshin4ac60942023-11-15 15:23:39 +00004259 enforceTelephonyFeatureWithException(callingPackage,
4260 PackageManager.FEATURE_TELEPHONY_CALLING, "disableVisualVoicemailSmsFilter");
4261
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004262 final long identity = Binder.clearCallingIdentity();
4263 try {
4264 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004265 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004266 } finally {
4267 Binder.restoreCallingIdentity(identity);
4268 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004269 }
4270
4271 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004272 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4273 String callingPackage, int subId) {
4274 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004275
4276 final long identity = Binder.clearCallingIdentity();
4277 try {
4278 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004279 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004280 } finally {
4281 Binder.restoreCallingIdentity(identity);
4282 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004283 }
4284
4285 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004286 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004287 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004288
4289 final long identity = Binder.clearCallingIdentity();
4290 try {
4291 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004292 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004293 } finally {
4294 Binder.restoreCallingIdentity(identity);
4295 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004296 }
4297
4298 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004299 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4300 String callingAttributionTag, int subId, String number, int port, String text,
4301 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004302 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004303 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004304 enforceSendSmsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00004305
4306 enforceTelephonyFeatureWithException(callingPackage,
4307 PackageManager.FEATURE_TELEPHONY_CALLING, "sendVisualVoicemailSmsForSubscriber");
4308
Amit Mahajandccb3f12019-05-13 13:48:32 -07004309 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004310 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4311 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004312 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004313
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004314 /**
fionaxu0152e512016-11-14 13:36:14 -08004315 * Sets the voice activation state of a given subId.
4316 */
4317 @Override
4318 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004319 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4320 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004321
joonhunshin4ac60942023-11-15 15:23:39 +00004322 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4323 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState");
4324
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004325 final long identity = Binder.clearCallingIdentity();
4326 try {
4327 final Phone phone = getPhone(subId);
4328 if (phone != null) {
4329 phone.setVoiceActivationState(activationState);
4330 } else {
4331 loge("setVoiceActivationState fails with invalid subId: " + subId);
4332 }
4333 } finally {
4334 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004335 }
4336 }
4337
4338 /**
4339 * Sets the data activation state of a given subId.
4340 */
4341 @Override
4342 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004343 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4344 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004345
joonhunshin4ac60942023-11-15 15:23:39 +00004346 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4347 PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState");
4348
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004349 final long identity = Binder.clearCallingIdentity();
4350 try {
4351 final Phone phone = getPhone(subId);
4352 if (phone != null) {
4353 phone.setDataActivationState(activationState);
4354 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004355 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004356 }
4357 } finally {
4358 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004359 }
4360 }
4361
4362 /**
4363 * Returns the voice activation state of a given subId.
4364 */
4365 @Override
4366 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004367 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004368
joonhunshin4ac60942023-11-15 15:23:39 +00004369 enforceTelephonyFeatureWithException(callingPackage,
4370 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState");
4371
fionaxu0152e512016-11-14 13:36:14 -08004372 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004373 final long identity = Binder.clearCallingIdentity();
4374 try {
4375 if (phone != null) {
4376 return phone.getVoiceActivationState();
4377 } else {
4378 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4379 }
4380 } finally {
4381 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004382 }
4383 }
4384
4385 /**
4386 * Returns the data activation state of a given subId.
4387 */
4388 @Override
4389 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004390 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004391
joonhunshin4ac60942023-11-15 15:23:39 +00004392 enforceTelephonyFeatureWithException(callingPackage,
4393 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState");
4394
fionaxu0152e512016-11-14 13:36:14 -08004395 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004396 final long identity = Binder.clearCallingIdentity();
4397 try {
4398 if (phone != null) {
4399 return phone.getDataActivationState();
4400 } else {
4401 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4402 }
4403 } finally {
4404 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004405 }
4406 }
4407
4408 /**
Wink Saville36469e72014-06-11 15:17:00 -07004409 * Returns the unread count of voicemails for a subId
4410 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004411 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004412 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4413 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004414 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004415 mApp, subId, callingPackage, callingFeatureId,
4416 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004417 return 0;
4418 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004419 final long identity = Binder.clearCallingIdentity();
4420 try {
4421 final Phone phone = getPhone(subId);
4422 if (phone != null) {
4423 return phone.getVoiceMessageCount();
4424 } else {
4425 return 0;
4426 }
4427 } finally {
4428 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004429 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004430 }
4431
4432 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004433 * returns true, if the device is in a state where both voice and data
4434 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004435 */
4436 @Override
4437 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00004438 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4439 PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed");
4440
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004441 final long identity = Binder.clearCallingIdentity();
4442 try {
Ling Mac28f0212023-03-24 16:07:15 -07004443 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004444 } finally {
4445 Binder.restoreCallingIdentity(identity);
4446 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004447 }
4448
4449 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004450 * Send the dialer code if called from the current default dialer or the caller has
4451 * carrier privilege.
4452 * @param inputCode The dialer code to send
4453 */
4454 @Override
4455 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004456 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004457 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004458 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4459 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004460 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004461 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004462 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004463 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004464
joonhunshin4ac60942023-11-15 15:23:39 +00004465 enforceTelephonyFeatureWithException(callingPackage,
4466 PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode");
4467
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004468 final long identity = Binder.clearCallingIdentity();
4469 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004470 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004471 } finally {
4472 Binder.restoreCallingIdentity(identity);
4473 }
fionaxu235cc5e2017-03-06 22:25:57 -08004474 }
4475
Pengquan Menga1bb6272018-09-06 09:59:22 -07004476 @Override
4477 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004478 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004479 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4480 mApp, subId, "getNetworkSelectionMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004481
4482 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4483 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode");
4484
shilufc958392020-01-20 11:36:01 -08004485 final long identity = Binder.clearCallingIdentity();
4486 try {
4487 if (!isActiveSubscription(subId)) {
4488 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4489 }
4490 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4491 } finally {
4492 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004493 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004494 }
4495
Brad Ebinger35c841c2018-10-01 10:40:55 -07004496 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004497 public boolean isInEmergencySmsMode() {
4498 enforceReadPrivilegedPermission("isInEmergencySmsMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004499
4500 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4501 PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode");
4502
Brad Ebingerb2b65522019-03-15 13:48:47 -07004503 final long identity = Binder.clearCallingIdentity();
4504 try {
4505 for (Phone phone : PhoneFactory.getPhones()) {
4506 if (phone.isInEmergencySmsMode()) {
4507 return true;
4508 }
4509 }
4510 } finally {
4511 Binder.restoreCallingIdentity(identity);
4512 }
4513 return false;
4514 }
4515
shilu366312e2019-12-17 09:28:10 -08004516 /**
4517 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4518 * @param subId The subscription to use to check the configuration.
4519 * @param c The callback that will be used to send the result.
4520 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004521 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004522 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4523 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004524 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004525 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004526
4527 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4528 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4529 "IMS not available on device.");
4530 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004531 final long token = Binder.clearCallingIdentity();
4532 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004533 int slotId = getSlotIndexOrException(subId);
4534 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004535
4536 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4537 if (controller != null) {
4538 ImsManager imsManager = controller.getImsManager(subId);
4539 if (imsManager != null) {
4540 imsManager.addRegistrationCallbackForSubscription(c, subId);
4541 } else {
4542 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4543 }
4544 } else {
4545 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4546 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004547 } catch (ImsException e) {
4548 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004549 } finally {
4550 Binder.restoreCallingIdentity(token);
4551 }
4552 }
4553
shilu366312e2019-12-17 09:28:10 -08004554 /**
4555 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4556 * @param subId The subscription to use to check the configuration.
4557 * @param c The callback that will be used to send the result.
4558 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004559 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004560 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004561 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004562 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004563 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4564 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4565 }
Meng Wangafbc5852019-09-19 17:37:13 -07004566 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004567
Meng Wangafbc5852019-09-19 17:37:13 -07004568 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004569 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4570 if (controller != null) {
4571 ImsManager imsManager = controller.getImsManager(subId);
4572 if (imsManager != null) {
4573 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4574 } else {
4575 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4576 + "is inactive, ignoring unregister.");
4577 // If the ImsManager is not valid, just return, since the callback
4578 // will already have been removed internally.
4579 }
4580 }
Meng Wangafbc5852019-09-19 17:37:13 -07004581 } finally {
4582 Binder.restoreCallingIdentity(token);
4583 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004584 }
4585
Brad Ebingera34a6c22019-10-22 17:36:18 -07004586 /**
Hidayat Khan99ea48f2023-12-11 04:37:45 +00004587 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4588 * @param subId The subscription to use to check the configuration.
4589 * @param c The callback that will be used to send the result.
4590 */
4591 @Override
4592 public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c)
4593 throws RemoteException {
4594 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4595 mApp, subId, "registerImsEmergencyRegistrationCallback");
4596
4597 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4598 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4599 "IMS not available on device.");
4600 }
4601 final long token = Binder.clearCallingIdentity();
4602 try {
4603 int slotId = getSlotIndexOrException(subId);
4604 verifyImsMmTelConfiguredOrThrow(slotId);
4605
4606 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4607 if (controller != null) {
4608 ImsManager imsManager = controller.getImsManager(subId);
4609 if (imsManager != null) {
4610 imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId);
4611 } else {
4612 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4613 }
4614 } else {
4615 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4616 }
4617 } catch (ImsException e) {
4618 throw new ServiceSpecificException(e.getCode());
4619 } finally {
4620 Binder.restoreCallingIdentity(token);
4621 }
4622 }
4623
4624 /**
4625 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4626 * @param subId The subscription to use to check the configuration.
4627 * @param c The callback that will be used to send the result.
4628 */
4629 @Override
4630 public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) {
4631 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4632 mApp, subId, "unregisterImsEmergencyRegistrationCallback");
4633 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4634 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4635 }
4636 final long token = Binder.clearCallingIdentity();
4637
4638 try {
4639 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4640 if (controller != null) {
4641 ImsManager imsManager = controller.getImsManager(subId);
4642 if (imsManager != null) {
4643 imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId);
4644 } else {
4645 Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId
4646 + "is inactive, ignoring unregister.");
4647 // If the ImsManager is not valid, just return, since the callback
4648 // will already have been removed internally.
4649 }
4650 }
4651 } finally {
4652 Binder.restoreCallingIdentity(token);
4653 }
4654 }
4655
4656 /**
Brad Ebingera34a6c22019-10-22 17:36:18 -07004657 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4658 */
4659 @Override
4660 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4661 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4662 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4663 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4664 "IMS not available on device.");
4665 }
4666 final long token = Binder.clearCallingIdentity();
4667 try {
4668 Phone phone = getPhone(subId);
4669 if (phone == null) {
4670 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4671 + subId + "'");
4672 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4673 }
4674 phone.getImsRegistrationState(regState -> {
4675 try {
4676 consumer.accept((regState == null)
4677 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4678 } catch (RemoteException e) {
4679 // Ignore if the remote process is no longer available to call back.
4680 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4681 }
4682 });
4683 } finally {
4684 Binder.restoreCallingIdentity(token);
4685 }
4686 }
4687
4688 /**
4689 * Get the transport type for the IMS service registration state.
4690 */
4691 @Override
4692 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004693 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004694 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004695 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4696 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4697 "IMS not available on device.");
4698 }
4699 final long token = Binder.clearCallingIdentity();
4700 try {
4701 Phone phone = getPhone(subId);
4702 if (phone == null) {
4703 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4704 + subId + "'");
4705 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4706 }
4707 phone.getImsRegistrationTech(regTech -> {
4708 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4709 int regTechConverted = (regTech == null)
4710 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4711 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4712 regTechConverted);
4713 try {
4714 consumer.accept(regTechConverted);
4715 } catch (RemoteException e) {
4716 // Ignore if the remote process is no longer available to call back.
4717 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4718 }
4719 });
4720 } finally {
4721 Binder.restoreCallingIdentity(token);
4722 }
4723 }
4724
shilu366312e2019-12-17 09:28:10 -08004725 /**
4726 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4727 * @param subId The subscription to use to check the configuration.
4728 * @param c The callback that will be used to send the result.
4729 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004730 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004731 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4732 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004733 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004734 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004735 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4736 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4737 "IMS not available on device.");
4738 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004739 final long token = Binder.clearCallingIdentity();
4740 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004741 int slotId = getSlotIndexOrException(subId);
4742 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004743
4744 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4745 if (controller != null) {
4746 ImsManager imsManager = controller.getImsManager(subId);
4747 if (imsManager != null) {
4748 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4749 } else {
4750 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4751 }
4752 } else {
4753 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4754 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004755 } catch (ImsException e) {
4756 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004757 } finally {
4758 Binder.restoreCallingIdentity(token);
4759 }
4760 }
4761
shilu366312e2019-12-17 09:28:10 -08004762 /**
4763 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4764 * @param subId The subscription to use to check the configuration.
4765 * @param c The callback that will be used to send the result.
4766 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004767 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004768 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004769 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004770 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004771 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4772 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4773 }
Meng Wangafbc5852019-09-19 17:37:13 -07004774
4775 final long token = Binder.clearCallingIdentity();
4776 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004777 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4778 if (controller != null) {
4779 ImsManager imsManager = controller.getImsManager(subId);
4780 if (imsManager != null) {
4781 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4782 } else {
4783 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4784 + " is inactive, ignoring unregister.");
4785 // If the ImsManager is not valid, just return, since the callback
4786 // will already have been removed internally.
4787 }
4788 }
Meng Wangafbc5852019-09-19 17:37:13 -07004789 } finally {
4790 Binder.restoreCallingIdentity(token);
4791 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004792 }
4793
4794 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004795 public boolean isCapable(int subId, int capability, int regTech) {
4796 enforceReadPrivilegedPermission("isCapable");
joonhunshin4ac60942023-11-15 15:23:39 +00004797
4798 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4799 FEATURE_TELEPHONY_IMS, "isCapable");
4800
Brad Ebinger35c841c2018-10-01 10:40:55 -07004801 final long token = Binder.clearCallingIdentity();
4802 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004803 int slotId = getSlotIndexOrException(subId);
4804 verifyImsMmTelConfiguredOrThrow(slotId);
4805 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4806 } catch (com.android.ims.ImsException e) {
4807 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4808 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004809 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004810 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4811 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004812 } finally {
4813 Binder.restoreCallingIdentity(token);
4814 }
4815 }
4816
4817 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004818 public boolean isAvailable(int subId, int capability, int regTech) {
4819 enforceReadPrivilegedPermission("isAvailable");
joonhunshin4ac60942023-11-15 15:23:39 +00004820
4821 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4822 FEATURE_TELEPHONY_IMS, "isAvailable");
4823
Brad Ebinger35c841c2018-10-01 10:40:55 -07004824 final long token = Binder.clearCallingIdentity();
4825 try {
4826 Phone phone = getPhone(subId);
4827 if (phone == null) return false;
4828 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004829 } catch (com.android.ims.ImsException e) {
4830 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4831 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004832 } finally {
4833 Binder.restoreCallingIdentity(token);
4834 }
4835 }
4836
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004837 /**
4838 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4839 * subscription.
4840 * @param subId The subscription to use to check the configuration.
4841 * @param callback The callback that will be used to send the result.
4842 * @param capability The MmTelFeature capability that will be used to send the result.
4843 * @param transportType The transport type of the MmTelFeature capability.
4844 */
4845 @Override
4846 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4847 int transportType) {
4848 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004849 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4850 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4851 "IMS not available on device.");
4852 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004853 final long token = Binder.clearCallingIdentity();
4854 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004855 int slotId = getSlotIndex(subId);
4856 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4857 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4858 + subId + "'");
4859 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4860 }
4861 verifyImsMmTelConfiguredOrThrow(slotId);
4862 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4863 transportType, aBoolean -> {
4864 try {
4865 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4866 } catch (RemoteException e) {
4867 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4868 + "running. Ignore");
4869 }
4870 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004871 } catch (ImsException e) {
4872 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004873 } finally {
4874 Binder.restoreCallingIdentity(token);
4875 }
4876 }
4877
shilu366312e2019-12-17 09:28:10 -08004878 /**
4879 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4880 * @param subId The subscription to use to check the configuration.
4881 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004882 @Override
4883 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004884 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004885 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004886
joonhunshin4ac60942023-11-15 15:23:39 +00004887 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4888 FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled");
4889
Brad Ebinger35c841c2018-10-01 10:40:55 -07004890 final long token = Binder.clearCallingIdentity();
4891 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004892 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004893 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004894 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004895 } catch (ImsException e) {
4896 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004897 } finally {
4898 Binder.restoreCallingIdentity(token);
4899 }
4900 }
4901
4902 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004903 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004904 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004905 "setAdvancedCallingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004906
4907 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4908 FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled");
4909
Brad Ebinger35c841c2018-10-01 10:40:55 -07004910 final long identity = Binder.clearCallingIdentity();
4911 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004912 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004913 // This setting doesn't require an active ImsService connection, so do not verify. The
4914 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004915 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004916 } catch (ImsException e) {
4917 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004918 } finally {
4919 Binder.restoreCallingIdentity(identity);
4920 }
4921 }
4922
shilu366312e2019-12-17 09:28:10 -08004923 /**
4924 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4925 * @param subId The subscription to use to check the configuration.
4926 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004927 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004928 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004929 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004930 mApp, subId, "isVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004931
4932 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4933 FEATURE_TELEPHONY_IMS, "isVtSettingEnabled");
4934
Brad Ebinger35c841c2018-10-01 10:40:55 -07004935 final long identity = Binder.clearCallingIdentity();
4936 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004937 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004938 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004939 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004940 } catch (ImsException e) {
4941 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004942 } finally {
4943 Binder.restoreCallingIdentity(identity);
4944 }
4945 }
4946
4947 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004948 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004949 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004950 "setVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004951
4952 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4953 FEATURE_TELEPHONY_IMS, "setVtSettingEnabled");
4954
Brad Ebinger35c841c2018-10-01 10:40:55 -07004955 final long identity = Binder.clearCallingIdentity();
4956 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004957 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004958 // This setting doesn't require an active ImsService connection, so do not verify. The
4959 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004960 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004961 } catch (ImsException e) {
4962 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004963 } finally {
4964 Binder.restoreCallingIdentity(identity);
4965 }
4966 }
4967
shilu366312e2019-12-17 09:28:10 -08004968 /**
4969 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4970 * @param subId The subscription to use to check the configuration.
4971 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004972 @Override
4973 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004974 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004975 mApp, subId, "isVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004976
4977 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4978 FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled");
4979
Brad Ebinger35c841c2018-10-01 10:40:55 -07004980 final long identity = Binder.clearCallingIdentity();
4981 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004982 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004983 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004984 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004985 } catch (ImsException e) {
4986 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004987 } finally {
4988 Binder.restoreCallingIdentity(identity);
4989 }
4990 }
4991
4992 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004993 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004994 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004995 "setVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004996
4997 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4998 FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled");
4999
Brad Ebinger35c841c2018-10-01 10:40:55 -07005000 final long identity = Binder.clearCallingIdentity();
5001 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005002 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005003 // This setting doesn't require an active ImsService connection, so do not verify. The
5004 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005005 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005006 } catch (ImsException e) {
5007 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005008 } finally {
5009 Binder.restoreCallingIdentity(identity);
5010 }
5011 }
5012
shilu366312e2019-12-17 09:28:10 -08005013 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005014 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
5015 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5016 * @param subId The subscription to use to check the configuration.
5017 */
5018 @Override
5019 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005020 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005021 mApp, subId, "isCrossSimCallingEnabledByUser");
joonhunshin4ac60942023-11-15 15:23:39 +00005022
5023 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5024 FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser");
5025
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005026 final long identity = Binder.clearCallingIdentity();
5027 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005028 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005029 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005030 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005031 } catch (ImsException e) {
5032 throw new ServiceSpecificException(e.getCode());
5033 } finally {
5034 Binder.restoreCallingIdentity(identity);
5035 }
5036 }
5037
5038 /**
5039 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
5040 * Requires MODIFY_PHONE_STATE permission.
5041 * @param subId The subscription to use to check the configuration.
5042 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
5043 * false otherwise
5044 */
5045 @Override
5046 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
5047 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5048 "setCrossSimCallingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005049
5050 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5051 FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled");
5052
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005053 final long identity = Binder.clearCallingIdentity();
5054 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005055 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005056 // This setting doesn't require an active ImsService connection, so do not verify. The
5057 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005058 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005059 } catch (ImsException e) {
5060 throw new ServiceSpecificException(e.getCode());
5061 } finally {
5062 Binder.restoreCallingIdentity(identity);
5063 }
5064 }
5065
5066 /**
shilu366312e2019-12-17 09:28:10 -08005067 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5068 * @param subId The subscription to use to check the configuration.
5069 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005070 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07005071
Brad Ebinger35c841c2018-10-01 10:40:55 -07005072 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005073 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005074 mApp, subId, "isVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005075
5076 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5077 FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled");
5078
Brad Ebinger35c841c2018-10-01 10:40:55 -07005079 final long identity = Binder.clearCallingIdentity();
5080 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005081 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005082 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005083 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005084 } catch (ImsException e) {
5085 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005086 } finally {
5087 Binder.restoreCallingIdentity(identity);
5088 }
5089 }
5090
5091 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005092 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005093 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005094 "setVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005095
5096 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5097 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled");
5098
Brad Ebinger35c841c2018-10-01 10:40:55 -07005099 final long identity = Binder.clearCallingIdentity();
5100 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005101 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005102 // This setting doesn't require an active ImsService connection, so do not verify. The
5103 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005104 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005105 } catch (ImsException e) {
5106 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005107 } finally {
5108 Binder.restoreCallingIdentity(identity);
5109 }
5110 }
5111
5112 @Override
5113 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
5114 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5115 "setVoWiFiNonPersistent");
joonhunshin4ac60942023-11-15 15:23:39 +00005116
5117 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5118 FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent");
5119
Brad Ebinger35c841c2018-10-01 10:40:55 -07005120 final long identity = Binder.clearCallingIdentity();
5121 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005122 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005123 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005124 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005125 } catch (ImsException e) {
5126 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005127 } finally {
5128 Binder.restoreCallingIdentity(identity);
5129 }
5130 }
5131
shilu366312e2019-12-17 09:28:10 -08005132 /**
5133 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5134 * @param subId The subscription to use to check the configuration.
5135 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005136 @Override
5137 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005138 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005139 mApp, subId, "getVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005140
5141 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5142 FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting");
5143
Brad Ebinger35c841c2018-10-01 10:40:55 -07005144 final long identity = Binder.clearCallingIdentity();
5145 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005146 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005147 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005148 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005149 } catch (ImsException e) {
5150 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005151 } finally {
5152 Binder.restoreCallingIdentity(identity);
5153 }
5154 }
5155
5156 @Override
5157 public void setVoWiFiModeSetting(int subId, int mode) {
5158 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5159 "setVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005160
5161 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5162 FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting");
5163
Brad Ebinger35c841c2018-10-01 10:40:55 -07005164 final long identity = Binder.clearCallingIdentity();
5165 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005166 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005167 // This setting doesn't require an active ImsService connection, so do not verify. The
5168 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005169 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005170 } catch (ImsException e) {
5171 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005172 } finally {
5173 Binder.restoreCallingIdentity(identity);
5174 }
5175 }
5176
5177 @Override
5178 public int getVoWiFiRoamingModeSetting(int subId) {
5179 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005180
5181 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5182 FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting");
5183
Brad Ebinger35c841c2018-10-01 10:40:55 -07005184 final long identity = Binder.clearCallingIdentity();
5185 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005186 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005187 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005188 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005189 } catch (ImsException e) {
5190 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005191 } finally {
5192 Binder.restoreCallingIdentity(identity);
5193 }
5194 }
5195
5196 @Override
5197 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
5198 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5199 "setVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005200
5201 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5202 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting");
5203
Brad Ebinger35c841c2018-10-01 10:40:55 -07005204 final long identity = Binder.clearCallingIdentity();
5205 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005206 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005207 // This setting doesn't require an active ImsService connection, so do not verify. The
5208 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005209 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005210 } catch (ImsException e) {
5211 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005212 } finally {
5213 Binder.restoreCallingIdentity(identity);
5214 }
5215 }
5216
5217 @Override
5218 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
5219 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5220 "setRttCapabilityEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005221
5222 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5223 FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting");
5224
Brad Ebinger35c841c2018-10-01 10:40:55 -07005225 final long identity = Binder.clearCallingIdentity();
5226 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005227 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005228 // This setting doesn't require an active ImsService connection, so do not verify. The
5229 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005230 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005231 } catch (ImsException e) {
5232 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005233 } finally {
5234 Binder.restoreCallingIdentity(identity);
5235 }
5236 }
5237
shilu366312e2019-12-17 09:28:10 -08005238 /**
5239 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5240 * @param subId The subscription to use to check the configuration.
5241 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005242 @Override
5243 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005244 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005245 mApp, subId, "isTtyOverVolteEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005246
5247 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5248 FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled");
5249
Brad Ebinger35c841c2018-10-01 10:40:55 -07005250 final long identity = Binder.clearCallingIdentity();
5251 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005252 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005253 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005254 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005255 } catch (ImsException e) {
5256 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005257 } finally {
5258 Binder.restoreCallingIdentity(identity);
5259 }
5260 }
5261
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005262 @Override
5263 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5264 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005265
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005266 final long identity = Binder.clearCallingIdentity();
5267 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005268 if (!isImsAvailableOnDevice()) {
5269 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5270 "IMS not available on device.");
5271 }
5272 int slotId = getSlotIndexOrException(subId);
5273 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005274
5275 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5276 if (controller != null) {
5277 ImsManager imsManager = controller.getImsManager(subId);
5278 if (imsManager != null) {
5279 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5280 } else {
5281 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5282 }
5283 } else {
5284 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5285 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005286 } catch (ImsException e) {
5287 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005288 } finally {
5289 Binder.restoreCallingIdentity(identity);
5290 }
5291 }
5292
5293 @Override
5294 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5295 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005296
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005297 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005298 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5299 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5300 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005301 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005302 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5303 if (controller != null) {
5304 ImsManager imsManager = controller.getImsManager(subId);
5305 if (imsManager != null) {
5306 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5307 } else {
5308 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5309 + " is inactive, ignoring unregister.");
5310 // If the ImsManager is not valid, just return, since the callback will already
5311 // have been removed internally.
5312 }
5313 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005314 } finally {
5315 Binder.restoreCallingIdentity(identity);
5316 }
5317 }
5318
joonhunshincffb7fc2021-11-28 07:32:01 +00005319 @Override
5320 public void registerFeatureProvisioningChangedCallback(int subId,
5321 IFeatureProvisioningCallback callback) {
5322 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5323 mApp, subId, "registerFeatureProvisioningChangedCallback");
5324
5325 final long identity = Binder.clearCallingIdentity();
5326 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5327 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5328 }
5329
joonhunshin91bc1952022-04-29 08:47:15 +00005330 try {
5331 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5332 if (controller == null) {
5333 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5334 "Device does not support IMS");
5335 }
5336 controller.addFeatureProvisioningChangedCallback(subId, callback);
5337 } finally {
5338 Binder.restoreCallingIdentity(identity);
5339 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005340 }
5341
5342 @Override
5343 public void unregisterFeatureProvisioningChangedCallback(int subId,
5344 IFeatureProvisioningCallback callback) {
5345 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5346 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5347
5348 final long identity = Binder.clearCallingIdentity();
5349 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5350 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5351 }
5352
joonhunshin91bc1952022-04-29 08:47:15 +00005353 try {
5354 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5355 if (controller == null) {
5356 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5357 return;
5358 }
5359 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5360 } finally {
5361 Binder.restoreCallingIdentity(identity);
5362 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005363 }
allenwtsu99c623b2020-01-03 18:24:23 +08005364
5365 private void checkModifyPhoneStatePermission(int subId, String message) {
5366 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5367 message);
5368 }
5369
allenwtsu99c623b2020-01-03 18:24:23 +08005370 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005371 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005372 boolean isProvisioned) {
5373 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5374
joonhunshin4ac60942023-11-15 15:23:39 +00005375 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5376 FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability");
5377
allenwtsu99c623b2020-01-03 18:24:23 +08005378 final long identity = Binder.clearCallingIdentity();
5379 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005380 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5381 if (controller == null) {
5382 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5383 return;
5384 }
5385 controller.setRcsProvisioningStatusForCapability(
5386 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005387 } finally {
5388 Binder.restoreCallingIdentity(identity);
5389 }
allenwtsu99c623b2020-01-03 18:24:23 +08005390 }
5391
5392
5393 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005394 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5395 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5396 mApp, subId, "getRcsProvisioningStatusForCapability");
5397
joonhunshin4ac60942023-11-15 15:23:39 +00005398 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5399 FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability");
5400
allenwtsu99c623b2020-01-03 18:24:23 +08005401 final long identity = Binder.clearCallingIdentity();
5402 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005403 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5404 if (controller == null) {
5405 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5406
5407 // device does not support IMS, this method will return true always.
5408 return true;
5409 }
5410 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005411 } finally {
5412 Binder.restoreCallingIdentity(identity);
5413 }
5414 }
5415
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005416 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005417 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5418 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005419 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005420
joonhunshin4ac60942023-11-15 15:23:39 +00005421 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5422 FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability");
5423
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005424 final long identity = Binder.clearCallingIdentity();
5425 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005426 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5427 if (controller == null) {
5428 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5429 return;
5430 }
5431 controller.setImsProvisioningStatusForCapability(
5432 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005433 } finally {
5434 Binder.restoreCallingIdentity(identity);
5435 }
5436 }
5437
5438 @Override
5439 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005440 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5441 mApp, subId, "getProvisioningStatusForCapability");
5442
joonhunshin4ac60942023-11-15 15:23:39 +00005443 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5444 FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability");
5445
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005446 final long identity = Binder.clearCallingIdentity();
5447 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005448 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5449 if (controller == null) {
5450 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005451
joonhunshin91bc1952022-04-29 08:47:15 +00005452 // device does not support IMS, this method will return true always.
5453 return true;
5454 }
5455 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005456 } finally {
5457 Binder.restoreCallingIdentity(identity);
5458 }
5459 }
5460
5461 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005462 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5463 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5464 mApp, subId, "isProvisioningRequiredForCapability");
5465
joonhunshin4ac60942023-11-15 15:23:39 +00005466 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5467 FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability");
5468
joonhunshincffb7fc2021-11-28 07:32:01 +00005469 final long identity = Binder.clearCallingIdentity();
5470 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005471 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5472 if (controller == null) {
5473 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5474
5475 // device does not support IMS, this method will return false
5476 return false;
5477 }
5478 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005479 } finally {
5480 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005481 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005482 }
5483
5484 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005485 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5486 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5487 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005488
joonhunshin4ac60942023-11-15 15:23:39 +00005489 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5490 FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability");
5491
joonhunshincffb7fc2021-11-28 07:32:01 +00005492 final long identity = Binder.clearCallingIdentity();
5493 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005494 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5495 if (controller == null) {
5496 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5497
5498 // device does not support IMS, this method will return false
5499 return false;
5500 }
5501 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005502 } finally {
5503 Binder.restoreCallingIdentity(identity);
5504 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005505 }
5506
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005507 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005508 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005509 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5510 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5511 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005512 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5513 mApp, subId, "getImsProvisioningInt");
5514
joonhunshin4ac60942023-11-15 15:23:39 +00005515 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5516 FEATURE_TELEPHONY_IMS, "getImsProvisioningInt");
5517
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005518 final long identity = Binder.clearCallingIdentity();
5519 try {
5520 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005521 int slotId = getSlotIndex(subId);
5522 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5523 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5524 + subId + "' for key:" + key);
5525 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5526 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005527
joonhunshin91bc1952022-04-29 08:47:15 +00005528 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5529 if (controller == null) {
5530 loge("getImsProvisioningInt: Device does not support IMS");
5531
5532 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5533 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5534 }
5535 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005536 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5537 return retVal;
5538 }
5539
calvinpanb5a34062021-02-08 19:59:36 +08005540 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005541 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005542 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5543 + subId + "' for key:" + key);
5544 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005545 } finally {
5546 Binder.restoreCallingIdentity(identity);
5547 }
5548 }
5549
5550 @Override
5551 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005552 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5553 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5554 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005555 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5556 mApp, subId, "getImsProvisioningString");
5557
joonhunshin4ac60942023-11-15 15:23:39 +00005558 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5559 FEATURE_TELEPHONY_IMS, "getImsProvisioningString");
5560
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005561 final long identity = Binder.clearCallingIdentity();
5562 try {
5563 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005564 int slotId = getSlotIndex(subId);
5565 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5566 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5567 + subId + "' for key:" + key);
5568 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5569 }
calvinpanb5a34062021-02-08 19:59:36 +08005570 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005571 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005572 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5573 + subId + "' for key:" + key);
5574 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005575 } finally {
5576 Binder.restoreCallingIdentity(identity);
5577 }
5578 }
5579
5580 @Override
5581 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005582 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5583 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5584 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005585 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5586 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005587
joonhunshin4ac60942023-11-15 15:23:39 +00005588 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5589 FEATURE_TELEPHONY_IMS, "setImsProvisioningInt");
5590
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005591 final long identity = Binder.clearCallingIdentity();
5592 try {
5593 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005594 int slotId = getSlotIndex(subId);
5595 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5596 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5597 + subId + "' for key:" + key);
5598 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5599 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005600
joonhunshin91bc1952022-04-29 08:47:15 +00005601 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5602 if (controller == null) {
5603 loge("setImsProvisioningInt: Device does not support IMS");
5604
5605 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5606 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5607 }
5608 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005609 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5610 return retVal;
5611 }
5612
calvinpanb5a34062021-02-08 19:59:36 +08005613 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5614 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005615 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005616 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005617 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005618 } finally {
5619 Binder.restoreCallingIdentity(identity);
5620 }
5621 }
5622
5623 @Override
5624 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005625 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5626 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5627 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005628 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5629 "setImsProvisioningString");
joonhunshin4ac60942023-11-15 15:23:39 +00005630
5631 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5632 FEATURE_TELEPHONY_IMS, "setImsProvisioningString");
5633
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005634 final long identity = Binder.clearCallingIdentity();
5635 try {
5636 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005637 int slotId = getSlotIndex(subId);
5638 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5639 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5640 + subId + "' for key:" + key);
5641 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5642 }
calvinpanb5a34062021-02-08 19:59:36 +08005643 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5644 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005645 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005646 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005647 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005648 } finally {
5649 Binder.restoreCallingIdentity(identity);
5650 }
5651 }
5652
Brad Ebinger919631e2021-06-02 17:46:35 -07005653 /**
5654 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5655 * for the given slot ID or no ImsResolver instance has been created.
5656 * @param slotId The slot ID that the IMS service is created for.
5657 * @throws ImsException If there is no ImsService configured for this slot.
5658 */
5659 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5660 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5661 ImsFeature.FEATURE_MMTEL)) {
5662 throw new ImsException("This subscription does not support MMTEL over IMS",
5663 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5664 }
5665 }
5666
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005667 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005668 int slotId = SubscriptionManager.getSlotIndex(subId);
5669 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005670 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5671 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005672 }
5673 return slotId;
5674 }
5675
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005676 private int getSlotIndex(int subId) {
5677 int slotId = SubscriptionManager.getSlotIndex(subId);
5678 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5679 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5680 }
5681 return slotId;
5682 }
5683
Wink Saville36469e72014-06-11 15:17:00 -07005684 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005685 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005686 */
5687 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005688 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5689 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005690 try {
5691 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5692 } catch (SecurityException se) {
5693 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5694 throw new SecurityException("Package " + callingPackage + " does not belong to "
5695 + Binder.getCallingUid());
5696 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005697 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005698 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005699 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005700 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005701 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005702 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005703 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005704 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5705 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005706
joonhunshin4ac60942023-11-15 15:23:39 +00005707 enforceTelephonyFeatureWithException(callingPackage,
5708 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber");
5709
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005710 final long identity = Binder.clearCallingIdentity();
5711 try {
5712 final Phone phone = getPhone(subId);
5713 if (phone != null) {
5714 return phone.getServiceState().getDataNetworkType();
5715 } else {
5716 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5717 }
5718 } finally {
5719 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005720 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005721 }
5722
5723 /**
5724 * Returns the data network type
5725 */
5726 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005727 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005728 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005729 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005730 }
5731
5732 /**
5733 * Returns the data network type for a subId
5734 */
5735 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005736 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5737 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005738 String functionName = "getDataNetworkTypeForSubscriber";
5739 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5740 mApp, functionName)) {
5741 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5742 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5743 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5744 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005745 }
5746
joonhunshin4ac60942023-11-15 15:23:39 +00005747 enforceTelephonyFeatureWithException(callingPackage,
5748 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber");
5749
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005750 final long identity = Binder.clearCallingIdentity();
5751 try {
5752 final Phone phone = getPhone(subId);
5753 if (phone != null) {
5754 return phone.getServiceState().getDataNetworkType();
5755 } else {
5756 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5757 }
5758 } finally {
5759 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005760 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005761 }
5762
5763 /**
Wink Saville36469e72014-06-11 15:17:00 -07005764 * Returns the Voice network type for a subId
5765 */
5766 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005767 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5768 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005769 String functionName = "getVoiceNetworkTypeForSubscriber";
5770 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5771 mApp, functionName)) {
5772 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5773 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5774 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5775 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005776 }
5777
joonhunshin4ac60942023-11-15 15:23:39 +00005778 enforceTelephonyFeatureWithException(callingPackage,
5779 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber");
5780
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005781 final long identity = Binder.clearCallingIdentity();
5782 try {
5783 final Phone phone = getPhone(subId);
5784 if (phone != null) {
5785 return phone.getServiceState().getVoiceNetworkType();
5786 } else {
5787 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5788 }
5789 } finally {
5790 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005791 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005792 }
5793
5794 /**
5795 * @return true if a ICC card is present
5796 */
5797 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005798 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005799 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005800 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005801 }
5802
5803 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005804 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005805 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005806 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005807 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00005808 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5809 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex");
5810
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005811 final long identity = Binder.clearCallingIdentity();
5812 try {
5813 final Phone phone = PhoneFactory.getPhone(slotIndex);
5814 if (phone != null) {
5815 return phone.getIccCard().hasIccCard();
5816 } else {
5817 return false;
5818 }
5819 } finally {
5820 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005821 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005822 }
5823
5824 /**
5825 * Return if the current radio is LTE on CDMA. This
5826 * is a tri-state return value as for a period of time
5827 * the mode may be unknown.
5828 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005829 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005830 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005831 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005832 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005833 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005834 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5835 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5836 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005837 }
5838
Sanket Padawe356d7632015-06-22 14:03:32 -07005839 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005840 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5841 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005842 try {
5843 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5844 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005845 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5846 }
5847
joonhunshin4ac60942023-11-15 15:23:39 +00005848 enforceTelephonyFeatureWithException(callingPackage,
5849 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber");
5850
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005851 final long identity = Binder.clearCallingIdentity();
5852 try {
5853 final Phone phone = getPhone(subId);
5854 if (phone == null) {
5855 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5856 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005857 return TelephonyProperties.lte_on_cdma_device()
5858 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005859 }
5860 } finally {
5861 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005862 }
Wink Saville36469e72014-06-11 15:17:00 -07005863 }
5864
Wink Saville36469e72014-06-11 15:17:00 -07005865 /**
5866 * {@hide}
5867 * Returns Default subId, 0 in the case of single standby.
5868 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005869 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005870 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005871 }
5872
Shishir Agrawala9f32182016-04-12 12:00:16 -07005873 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005874 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005875 }
5876
Wink Savilleb564aae2014-10-23 10:18:09 -07005877 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005878 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005879 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005880
Pengquan Menge92a50d2018-09-21 15:54:48 -07005881 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005882 return getSubscriptionManagerService().isActiveSubId(subId,
5883 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005884 }
5885
Ihab Awadf2177b72013-11-25 13:33:23 -08005886 /**
5887 * @see android.telephony.TelephonyManager.WifiCallingChoices
5888 */
5889 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005890 final long identity = Binder.clearCallingIdentity();
5891 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005892 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005893 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5894 getWhenToMakeWifiCallsDefaultPreference());
5895 } finally {
5896 Binder.restoreCallingIdentity(identity);
5897 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005898 }
5899
5900 /**
5901 * @see android.telephony.TelephonyManager.WifiCallingChoices
5902 */
5903 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005904 final long identity = Binder.clearCallingIdentity();
5905 try {
5906 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005907 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005908 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5909 } finally {
5910 Binder.restoreCallingIdentity(identity);
5911 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005912 }
5913
Sailesh Nepald1e68152013-12-12 19:08:02 -08005914 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005915 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005916 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005917 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005918
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005919 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5920 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5921 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005922 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005923 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005924 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005925 }
5926 return PhoneFactory.getPhone(phoneId);
5927 }
5928
Shishir Agrawal566b7612013-10-28 14:41:00 -07005929 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005930 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005931 @NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00005932
Rambo Wanga1782702021-11-10 20:15:19 -08005933 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5934 /*message=*/ "iccOpenLogicalChannel");
5935
5936 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5937 // Verify that the callingPackage in the request belongs to the calling UID
5938 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5939
joonhunshin4ac60942023-11-15 15:23:39 +00005940 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5941 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel");
5942
Rambo Wanga1782702021-11-10 20:15:19 -08005943 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005944 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005945
Rambo Wanga1782702021-11-10 20:15:19 -08005946 private Phone getPhoneFromValidIccLogicalChannelRequest(
5947 @NonNull IccLogicalChannelRequest request, String message) {
5948 Phone phone;
5949 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5950 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5951 mApp, request.subId, message);
5952 phone = getPhoneFromSubId(request.subId);
5953 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5954 enforceModifyPermission();
5955 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5956 } else {
5957 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005958 }
Rambo Wanga1782702021-11-10 20:15:19 -08005959 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005960 }
5961
5962 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005963 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005964 final long identity = Binder.clearCallingIdentity();
5965 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005966 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005967 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005968 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5969 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005970 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5971 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005972 loge("The calling package is not allowed to access ISD-R.");
5973 throw new SecurityException(
5974 "The calling package is not allowed to access ISD-R.");
5975 }
Derek Tan740e1672017-06-27 14:56:27 -07005976 }
Derek Tan740e1672017-06-27 14:56:27 -07005977
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005978 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005979 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5980 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005981 return response;
5982 } finally {
5983 Binder.restoreCallingIdentity(identity);
5984 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005985 }
5986
5987 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005988 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00005989 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5990 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel");
5991
Rambo Wanga1782702021-11-10 20:15:19 -08005992 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5993 /*message=*/"iccCloseLogicalChannel");
5994
5995 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5996
5997 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005998 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005999
Rambo Wanga1782702021-11-10 20:15:19 -08006000 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
6001 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08006002 // before this feature is enabled, this API should only return false if
6003 // the operation fails instead of throwing runtime exception for
6004 // backward-compatibility.
6005 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
6006 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006007 final long identity = Binder.clearCallingIdentity();
6008 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006009 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08006010 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006011 }
Chen Xue9d737e2022-01-01 23:41:31 -08006012 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08006013 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08006014 Boolean success = false;
6015 if (result instanceof RuntimeException) {
6016 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08006017 if (shouldThrowExceptionOnFailure) {
6018 throw (RuntimeException) result;
6019 } else {
6020 return false;
6021 }
Chen Xue9d737e2022-01-01 23:41:31 -08006022 } else if (result instanceof Boolean) {
6023 success = (Boolean) result;
6024 } else {
6025 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
6026 }
Rambo Wanga1782702021-11-10 20:15:19 -08006027 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006028 return success;
6029 } finally {
6030 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006031 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006032 }
6033
6034 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006035 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07006036 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006037 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6038 mApp, subId, "iccTransmitApduLogicalChannel");
joonhunshin4ac60942023-11-15 15:23:39 +00006039
6040 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6041 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel");
6042
Jordan Liu4c733742019-02-28 12:03:40 -08006043 if (DBG) {
6044 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
6045 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
6046 + p3 + " data=" + data);
6047 }
6048 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
6049 command, p1, p2, p3, data);
6050 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006051
Jordan Liu4c733742019-02-28 12:03:40 -08006052 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006053 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006054 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006055 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006056
6057 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6058 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
6059 "iccTransmitApduLogicalChannelBySlot");
6060
Jordan Liu4c733742019-02-28 12:03:40 -08006061 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006062 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006063 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
6064 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006065 }
6066 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006067 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
6068 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006069 }
6070
6071 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
6072 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006073 final long identity = Binder.clearCallingIdentity();
6074 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07006075 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006076 return "";
6077 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006078
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006079 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006080 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
6081 null /* workSource */);
6082 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006083
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006084 // Append the returned status code to the end of the response payload.
6085 String s = Integer.toHexString(
6086 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6087 if (response.payload != null) {
6088 s = IccUtils.bytesToHexString(response.payload) + s;
6089 }
6090 return s;
6091 } finally {
6092 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006093 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006094 }
Jake Hambye994d462014-02-03 13:10:13 -08006095
Evan Charltonc66da362014-05-16 14:06:40 -07006096 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006097 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
6098 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006099 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6100 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006101 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006102
6103 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6104 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel");
6105
Jordan Liu4c733742019-02-28 12:03:40 -08006106 if (DBG) {
6107 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
6108 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
6109 }
6110 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
6111 cla, command, p1, p2, p3, data);
6112 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006113
Jordan Liu4c733742019-02-28 12:03:40 -08006114 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006115 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006116 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006117 enforceModifyPermission();
6118 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006119
6120 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6121 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot");
6122
Jordan Liu4c733742019-02-28 12:03:40 -08006123 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006124 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006125 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
6126 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006127 }
6128
6129 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006130 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
6131 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006132 }
6133
6134 // open APDU basic channel assuming the caller has sufficient permissions
6135 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
6136 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006137 final long identity = Binder.clearCallingIdentity();
6138 try {
6139 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
6140 && TextUtils.equals(ISDR_AID, data)) {
6141 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006142 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6143 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006144 if (bestComponent == null
6145 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
6146 loge("The calling package is not allowed to select ISD-R.");
6147 throw new SecurityException(
6148 "The calling package is not allowed to select ISD-R.");
6149 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006150 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006151
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006152 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006153 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
6154 null /* workSource */);
6155 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006156
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006157 // Append the returned status code to the end of the response payload.
6158 String s = Integer.toHexString(
6159 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6160 if (response.payload != null) {
6161 s = IccUtils.bytesToHexString(response.payload) + s;
6162 }
6163 return s;
6164 } finally {
6165 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006166 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006167 }
6168
6169 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006170 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006171 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006172 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6173 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006174
joonhunshin4ac60942023-11-15 15:23:39 +00006175 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6176 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO");
6177
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006178 final long identity = Binder.clearCallingIdentity();
6179 try {
6180 if (DBG) {
6181 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
6182 + p1 + " " + p2 + " " + p3 + ":" + filePath);
6183 }
6184
6185 IccIoResult response =
6186 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
6187 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
6188 subId);
6189
6190 if (DBG) {
6191 log("Exchange SIM_IO [R]" + response);
6192 }
6193
6194 byte[] result = null;
6195 int length = 2;
6196 if (response.payload != null) {
6197 length = 2 + response.payload.length;
6198 result = new byte[length];
6199 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
6200 } else {
6201 result = new byte[length];
6202 }
6203
6204 result[length - 1] = (byte) response.sw2;
6205 result[length - 2] = (byte) response.sw1;
6206 return result;
6207 } finally {
6208 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006209 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006210 }
6211
Nathan Haroldb3014052017-01-25 15:57:32 -08006212 /**
6213 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
6214 * on a particular subscription
6215 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006216 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
6217 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07006218 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006219 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07006220 return null;
6221 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006222
joonhunshin4ac60942023-11-15 15:23:39 +00006223 enforceTelephonyFeatureWithException(callingPackage,
6224 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns");
6225
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006226 final long identity = Binder.clearCallingIdentity();
6227 try {
6228 if (appType != TelephonyManager.APPTYPE_USIM
6229 && appType != TelephonyManager.APPTYPE_SIM) {
6230 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
6231 return null;
6232 }
6233 Object response = sendRequest(
6234 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
6235 if (response instanceof String[]) {
6236 return (String[]) response;
6237 }
yincheng zhao2737e882019-09-06 17:06:54 -07006238 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006239 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08006240 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006241 } finally {
6242 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08006243 }
Nathan Haroldb3014052017-01-25 15:57:32 -08006244 }
6245
yincheng zhao2737e882019-09-06 17:06:54 -07006246 /**
6247 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
6248 * subscription.
6249 *
6250 * @param subId the id of the subscription.
6251 * @param appType the uicc app type, must be USIM or SIM.
6252 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
6253 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006254 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07006255 * @return number of fplmns that is successfully written to the SIM.
6256 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006257 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
6258 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07006259 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6260 mApp, subId, "setForbiddenPlmns");
6261
joonhunshin4ac60942023-11-15 15:23:39 +00006262 enforceTelephonyFeatureWithException(callingPackage,
6263 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns");
6264
yincheng zhao2737e882019-09-06 17:06:54 -07006265 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
6266 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
6267 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
6268 }
6269 if (fplmns == null) {
6270 throw new IllegalArgumentException("Fplmn List provided is null");
6271 }
6272 for (String fplmn : fplmns) {
6273 if (!CellIdentity.isValidPlmn(fplmn)) {
6274 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
6275 }
6276 }
6277 final long identity = Binder.clearCallingIdentity();
6278 try {
6279 Object response = sendRequest(
6280 CMD_SET_FORBIDDEN_PLMNS,
6281 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
6282 subId);
6283 return (int) response;
6284 } finally {
6285 Binder.restoreCallingIdentity(identity);
6286 }
6287 }
6288
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006289 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006290 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006291 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6292 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07006293
joonhunshin4ac60942023-11-15 15:23:39 +00006294 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6295 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus");
6296
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006297 final long identity = Binder.clearCallingIdentity();
6298 try {
6299 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
6300 if (response.payload == null) {
6301 return "";
6302 }
Evan Charltonc66da362014-05-16 14:06:40 -07006303
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006304 // Append the returned status code to the end of the response payload.
6305 String s = Integer.toHexString(
6306 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6307 s = IccUtils.bytesToHexString(response.payload) + s;
6308 return s;
6309 } finally {
6310 Binder.restoreCallingIdentity(identity);
6311 }
Evan Charltonc66da362014-05-16 14:06:40 -07006312 }
6313
Jake Hambye994d462014-02-03 13:10:13 -08006314 /**
6315 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6316 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6317 *
6318 * @param itemID the ID of the item to read
6319 * @return the NV item as a String, or null on error.
6320 */
6321 @Override
6322 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006323 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006324 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6325 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006326
6327 final long identity = Binder.clearCallingIdentity();
6328 try {
6329 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07006330 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006331 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
6332 return value;
6333 } finally {
6334 Binder.restoreCallingIdentity(identity);
6335 }
Jake Hambye994d462014-02-03 13:10:13 -08006336 }
6337
6338 /**
6339 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6340 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6341 *
6342 * @param itemID the ID of the item to read
6343 * @param itemValue the value to write, as a String
6344 * @return true on success; false on any failure
6345 */
6346 @Override
6347 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006348 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006349 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6350 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006351
6352 final long identity = Binder.clearCallingIdentity();
6353 try {
6354 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6355 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006356 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006357 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6358 return success;
6359 } finally {
6360 Binder.restoreCallingIdentity(identity);
6361 }
Jake Hambye994d462014-02-03 13:10:13 -08006362 }
6363
6364 /**
6365 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6366 * Used for device configuration by some CDMA operators.
6367 *
6368 * @param preferredRoamingList byte array containing the new PRL
6369 * @return true on success; false on any failure
6370 */
6371 @Override
6372 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006373 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6374 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006375
6376 final long identity = Binder.clearCallingIdentity();
6377 try {
6378 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6379 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6380 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6381 return success;
6382 } finally {
6383 Binder.restoreCallingIdentity(identity);
6384 }
Jake Hambye994d462014-02-03 13:10:13 -08006385 }
6386
6387 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006388 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006389 * Used for device configuration by some CDMA operators.
6390 *
chen xu6dac5ab2018-10-26 17:39:23 -07006391 * @param slotIndex - device slot.
6392 *
Jake Hambye994d462014-02-03 13:10:13 -08006393 * @return true on success; false on any failure
6394 */
6395 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006396 public boolean resetModemConfig(int slotIndex) {
6397 Phone phone = PhoneFactory.getPhone(slotIndex);
6398 if (phone != null) {
6399 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6400 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006401
joonhunshin4ac60942023-11-15 15:23:39 +00006402 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6403 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig");
6404
chen xu6dac5ab2018-10-26 17:39:23 -07006405 final long identity = Binder.clearCallingIdentity();
6406 try {
6407 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6408 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6409 return success;
6410 } finally {
6411 Binder.restoreCallingIdentity(identity);
6412 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006413 }
chen xu6dac5ab2018-10-26 17:39:23 -07006414 return false;
6415 }
6416
6417 /**
6418 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6419 *
6420 * @param slotIndex - device slot.
6421 *
6422 * @return true on success; false on any failure
6423 */
6424 @Override
6425 public boolean rebootModem(int slotIndex) {
6426 Phone phone = PhoneFactory.getPhone(slotIndex);
6427 if (phone != null) {
6428 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6429 mApp, phone.getSubId(), "rebootModem");
6430
joonhunshin4ac60942023-11-15 15:23:39 +00006431 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6432 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem");
6433
chen xu6dac5ab2018-10-26 17:39:23 -07006434 final long identity = Binder.clearCallingIdentity();
6435 try {
6436 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6437 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6438 return success;
6439 } finally {
6440 Binder.restoreCallingIdentity(identity);
6441 }
6442 }
6443 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006444 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006445
Brad Ebinger51f743a2017-01-23 13:50:20 -08006446 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006447 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6448 * {@link #disableIms(int)}.
6449 * @param slotIndex device slot.
6450 */
6451 public void resetIms(int slotIndex) {
6452 enforceModifyPermission();
6453
joonhunshin4ac60942023-11-15 15:23:39 +00006454 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6455 PackageManager.FEATURE_TELEPHONY_IMS, "resetIms");
6456
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006457 final long identity = Binder.clearCallingIdentity();
6458 try {
6459 if (mImsResolver == null) {
6460 // may happen if the does not support IMS.
6461 return;
6462 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006463 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006464 } finally {
6465 Binder.restoreCallingIdentity(identity);
6466 }
6467 }
6468
6469 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006470 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6471 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006472 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006473 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006474 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006475
6476 final long identity = Binder.clearCallingIdentity();
6477 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006478 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006479 // may happen if the device does not support IMS.
6480 return;
6481 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006482 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006483 } finally {
6484 Binder.restoreCallingIdentity(identity);
6485 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006486 }
6487
6488 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006489 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6490 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006491 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006492 public void disableIms(int slotId) {
6493 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006494
6495 final long identity = Binder.clearCallingIdentity();
6496 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006497 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006498 // may happen if the device does not support IMS.
6499 return;
6500 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006501 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006502 } finally {
6503 Binder.restoreCallingIdentity(identity);
6504 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006505 }
6506
6507 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006508 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6509 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006510 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006511 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006512 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006513 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006514
6515 final long identity = Binder.clearCallingIdentity();
6516 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006517 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006518 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6519 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006520 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006521 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006522 } finally {
6523 Binder.restoreCallingIdentity(identity);
6524 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006525 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006526 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006527 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6528 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006529 @Override
6530 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006531 enforceModifyPermission();
6532
6533 final long identity = Binder.clearCallingIdentity();
6534 try {
6535 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006536 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006537 } finally {
6538 Binder.restoreCallingIdentity(identity);
6539 }
6540 }
6541
6542 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006543 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006544 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006545 */
6546 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6547 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006548
6549 final long identity = Binder.clearCallingIdentity();
6550 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006551 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006552 // may happen if the device does not support IMS.
6553 return null;
6554 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006555 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006556 } finally {
6557 Binder.restoreCallingIdentity(identity);
6558 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006559 }
6560
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006561 /**
6562 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006563 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006564 */
6565 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6566 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006567
6568 final long identity = Binder.clearCallingIdentity();
6569 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006570 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006571 // may happen if the device does not support IMS.
6572 return null;
6573 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006574 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006575 } finally {
6576 Binder.restoreCallingIdentity(identity);
6577 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006578 }
6579
Brad Ebinger884c07b2018-02-15 16:17:40 -08006580 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006581 * Sets the ImsService Package Name that Telephony will bind to.
6582 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006583 * @param slotIndex the slot ID that the ImsService should bind for.
6584 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006585 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006586 * @param featureTypes An integer array of feature types associated with a packageName.
6587 * @param packageName The name of the package that the current configuration will be replaced
6588 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006589 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006590 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006591 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6592 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006593 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006594 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006595 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006596
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006597 final long identity = Binder.clearCallingIdentity();
6598 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006599 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006600 // may happen if the device does not support IMS.
6601 return false;
6602 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006603 Map<Integer, String> featureConfig = new HashMap<>();
6604 for (int featureType : featureTypes) {
6605 featureConfig.put(featureType, packageName);
6606 }
6607 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6608 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006609 } finally {
6610 Binder.restoreCallingIdentity(identity);
6611 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006612 }
6613
6614 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006615 * Clears any carrier ImsService overrides for the slot index specified that were previously
6616 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6617 *
6618 * This should only be used for testing.
6619 *
6620 * @param slotIndex the slot ID that the ImsService should bind for.
6621 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6622 */
6623 @Override
6624 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006625 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6626 "clearCarrierImsServiceOverride");
6627 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006628 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006629
6630 final long identity = Binder.clearCallingIdentity();
6631 try {
6632 if (mImsResolver == null) {
6633 // may happen if the device does not support IMS.
6634 return false;
6635 }
6636 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6637 } finally {
6638 Binder.restoreCallingIdentity(identity);
6639 }
6640 }
6641
6642 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006643 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006644 *
6645 * @param slotId The slot that the ImsService is associated with.
6646 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6647 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006648 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006649 * @return the package name of the ImsService configuration.
6650 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006651 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6652 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006653 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006654 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6655 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006656
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006657 final long identity = Binder.clearCallingIdentity();
6658 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006659 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006660 // may happen if the device does not support IMS.
6661 return "";
6662 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006663 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006664 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6665 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006666 } finally {
6667 Binder.restoreCallingIdentity(identity);
6668 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006669 }
6670
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006671 /**
6672 * Get the MmTelFeature state associated with the requested subscription id.
6673 * @param subId The subscription that the MmTelFeature is associated with.
6674 * @param callback A callback with an integer containing the
6675 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6676 */
6677 @Override
6678 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6679 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006680 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6681 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6682 "IMS not available on device.");
6683 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006684 final long token = Binder.clearCallingIdentity();
6685 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006686 int slotId = getSlotIndex(subId);
6687 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6688 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6689 + subId + "'");
6690 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6691 }
6692 verifyImsMmTelConfiguredOrThrow(slotId);
6693 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6694 try {
6695 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6696 } catch (RemoteException e) {
6697 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6698 + "Ignore");
6699 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006700 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006701 } catch (ImsException e) {
6702 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006703 } finally {
6704 Binder.restoreCallingIdentity(token);
6705 }
6706 }
6707
Daniel Brightbb5840b2021-01-12 15:48:18 -08006708 /**
6709 * Sets the ims registration state on all valid {@link Phone}s.
6710 */
6711 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006712 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006713
6714 final long identity = Binder.clearCallingIdentity();
6715 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006716 // NOTE: Before S, this method only set the default phone.
6717 for (final Phone phone : PhoneFactory.getPhones()) {
6718 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6719 phone.setImsRegistrationState(registered);
6720 }
6721 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006722 } finally {
6723 Binder.restoreCallingIdentity(identity);
6724 }
Wink Saville36469e72014-06-11 15:17:00 -07006725 }
6726
6727 /**
Stuart Scott54788802015-03-30 13:18:01 -07006728 * Set the network selection mode to automatic.
6729 *
6730 */
6731 @Override
6732 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006733 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6734 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006735
joonhunshin4ac60942023-11-15 15:23:39 +00006736 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6737 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic");
6738
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006739 final long identity = Binder.clearCallingIdentity();
6740 try {
shilufc958392020-01-20 11:36:01 -08006741 if (!isActiveSubscription(subId)) {
6742 return;
6743 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006744 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006745 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6746 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006747 } finally {
6748 Binder.restoreCallingIdentity(identity);
6749 }
Stuart Scott54788802015-03-30 13:18:01 -07006750 }
6751
Jack Yud10cdd42020-09-28 20:28:01 -07006752 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006753 * Ask the radio to connect to the input network and change selection mode to manual.
6754 *
6755 * @param subId the id of the subscription.
6756 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6757 * the operator to attach to.
6758 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6759 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6760 * normal network selection next time.
6761 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006762 */
6763 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006764 public boolean setNetworkSelectionModeManual(
6765 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006766 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6767 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006768
joonhunshin4ac60942023-11-15 15:23:39 +00006769 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6770 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual");
6771
Jack Yu285100e2022-12-02 22:48:35 -08006772 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006773 if (!isActiveSubscription(subId)) {
6774 return false;
6775 }
6776
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006777 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006778 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006779 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006780 if (DBG) {
6781 log("setNetworkSelectionModeManual: subId: " + subId
6782 + " operator: " + operatorInfo);
6783 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006784 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6785 } finally {
6786 Binder.restoreCallingIdentity(identity);
6787 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006788 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006789 /**
shilu84f6e8b2019-12-19 13:58:01 -08006790 * Get the manual network selection
6791 *
6792 * @param subId the id of the subscription.
6793 *
6794 * @return the previously saved user selected PLMN
6795 */
6796 @Override
6797 public String getManualNetworkSelectionPlmn(int subId) {
6798 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006799 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6800 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006801
joonhunshin4ac60942023-11-15 15:23:39 +00006802 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6803 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn");
6804
shilu84f6e8b2019-12-19 13:58:01 -08006805 final long identity = Binder.clearCallingIdentity();
6806 try {
6807 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006808 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006809 }
6810
6811 final Phone phone = getPhone(subId);
6812 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006813 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006814 }
6815 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6816 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006817 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006818 } finally {
6819 Binder.restoreCallingIdentity(identity);
6820 }
6821 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006822
6823 /**
6824 * Scans for available networks.
6825 */
6826 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006827 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6828 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006829 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6830 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006831 LocationAccessPolicy.LocationPermissionResult locationResult =
6832 LocationAccessPolicy.checkLocationPermission(mApp,
6833 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6834 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006835 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006836 .setCallingPid(Binder.getCallingPid())
6837 .setCallingUid(Binder.getCallingUid())
6838 .setMethod("getCellNetworkScanResults")
6839 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006840 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6841 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006842 .build());
6843 switch (locationResult) {
6844 case DENIED_HARD:
6845 throw new SecurityException("Not allowed to access scan results -- location");
6846 case DENIED_SOFT:
6847 return null;
6848 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006849
Pengquan Menga1bb6272018-09-06 09:59:22 -07006850 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006851 try {
6852 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006853 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006854 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006855 } finally {
6856 Binder.restoreCallingIdentity(identity);
6857 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006858 }
6859
6860 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006861 * Get the call forwarding info, given the call forwarding reason.
6862 */
6863 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006864 public void getCallForwarding(int subId, int callForwardingReason,
6865 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006866 enforceReadPrivilegedPermission("getCallForwarding");
joonhunshin4ac60942023-11-15 15:23:39 +00006867
6868 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6869 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding");
6870
Shuo Qian4a594052020-01-23 11:59:30 -08006871 long identity = Binder.clearCallingIdentity();
6872 try {
6873 if (DBG) {
6874 log("getCallForwarding: subId " + subId
6875 + " callForwardingReason" + callForwardingReason);
6876 }
Hall Liu27d24262020-09-18 19:04:59 -07006877
6878 Phone phone = getPhone(subId);
6879 if (phone == null) {
6880 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006881 callback.onError(
6882 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006883 } catch (RemoteException e) {
6884 // ignore
6885 }
6886 return;
6887 }
6888
6889 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6890 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6891 @Override
6892 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6893 try {
6894 callback.onCallForwardingInfoAvailable(info);
6895 } catch (RemoteException e) {
6896 // ignore
6897 }
6898 }
6899
6900 @Override
6901 public void onError(int error) {
6902 try {
6903 callback.onError(error);
6904 } catch (RemoteException e) {
6905 // ignore
6906 }
6907 }
6908 });
6909 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006910 } finally {
6911 Binder.restoreCallingIdentity(identity);
6912 }
6913 }
6914
6915 /**
6916 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6917 * reason, the number to forward, and the timeout before the forwarding is attempted.
6918 */
6919 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006920 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6921 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006922 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006923
6924 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6925 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding");
6926
Shuo Qian4a594052020-01-23 11:59:30 -08006927 long identity = Binder.clearCallingIdentity();
6928 try {
6929 if (DBG) {
6930 log("setCallForwarding: subId " + subId
6931 + " callForwardingInfo" + callForwardingInfo);
6932 }
Hall Liu27d24262020-09-18 19:04:59 -07006933
6934 Phone phone = getPhone(subId);
6935 if (phone == null) {
6936 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006937 callback.accept(
6938 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006939 } catch (RemoteException e) {
6940 // ignore
6941 }
6942 return;
6943 }
6944
6945 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6946 FunctionalUtils.ignoreRemoteException(callback::accept));
6947
6948 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006949 } finally {
6950 Binder.restoreCallingIdentity(identity);
6951 }
6952 }
6953
6954 /**
Hall Liu27d24262020-09-18 19:04:59 -07006955 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006956 */
6957 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006958 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006959 enforceReadPrivilegedPermission("getCallWaitingStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00006960
6961 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6962 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus");
6963
Shuo Qian4a594052020-01-23 11:59:30 -08006964 long identity = Binder.clearCallingIdentity();
6965 try {
Hall Liu27d24262020-09-18 19:04:59 -07006966 Phone phone = getPhone(subId);
6967 if (phone == null) {
6968 try {
6969 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6970 } catch (RemoteException e) {
6971 // ignore
6972 }
6973 return;
6974 }
SongFerngWang0e767992021-03-31 22:08:45 +08006975 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6976 PersistableBundle c = configManager.getConfigForSubId(subId);
6977 boolean requireUssd = c.getBoolean(
6978 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006979
Shuo Qian4a594052020-01-23 11:59:30 -08006980 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006981 if (requireUssd) {
6982 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6983 getSubscriptionCarrierId(subId));
6984 String newUssdCommand = "";
6985 try {
6986 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006987 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006988 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6989 } catch (NullPointerException e) {
6990 loge("Failed to generate USSD number" + e);
6991 }
6992 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6993 mMainThreadHandler, callback, carrierXmlParser,
6994 CarrierXmlParser.SsEntry.SSAction.QUERY);
6995 final String ussdCommand = newUssdCommand;
6996 Executors.newSingleThreadExecutor().execute(() -> {
6997 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6998 });
6999 } else {
7000 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
7001 callback::accept);
7002 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
7003 }
Shuo Qian4a594052020-01-23 11:59:30 -08007004 } finally {
7005 Binder.restoreCallingIdentity(identity);
7006 }
7007 }
7008
7009 /**
Hall Liu27d24262020-09-18 19:04:59 -07007010 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007011 */
7012 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007013 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007014 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007015
7016 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7017 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus");
7018
Shuo Qian4a594052020-01-23 11:59:30 -08007019 long identity = Binder.clearCallingIdentity();
7020 try {
Hall Liu27d24262020-09-18 19:04:59 -07007021 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
7022
7023 Phone phone = getPhone(subId);
7024 if (phone == null) {
7025 try {
7026 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7027 } catch (RemoteException e) {
7028 // ignore
7029 }
7030 return;
7031 }
7032
SongFerngWang0e767992021-03-31 22:08:45 +08007033 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7034 PersistableBundle c = configManager.getConfigForSubId(subId);
7035 boolean requireUssd = c.getBoolean(
7036 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007037
SongFerngWang0e767992021-03-31 22:08:45 +08007038 if (DBG) log("getCallWaitingStatus: subId " + subId);
7039 if (requireUssd) {
7040 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7041 getSubscriptionCarrierId(subId));
7042 CarrierXmlParser.SsEntry.SSAction ssAction =
7043 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
7044 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
7045 String newUssdCommand = "";
7046 try {
7047 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007048 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007049 .makeCommand(ssAction, null);
7050 } catch (NullPointerException e) {
7051 loge("Failed to generate USSD number" + e);
7052 }
7053 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7054 mMainThreadHandler, callback, carrierXmlParser, ssAction);
7055 final String ussdCommand = newUssdCommand;
7056 Executors.newSingleThreadExecutor().execute(() -> {
7057 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7058 });
7059 } else {
7060 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
7061 FunctionalUtils.ignoreRemoteException(callback::accept));
7062
7063 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
7064 }
Shuo Qian4a594052020-01-23 11:59:30 -08007065 } finally {
7066 Binder.restoreCallingIdentity(identity);
7067 }
7068 }
7069
7070 /**
yinxub1bed742017-04-17 11:45:04 -07007071 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07007072 *
yinxub1bed742017-04-17 11:45:04 -07007073 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007074 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
7075 * location related information which will be sent if the caller already possess
7076 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07007077 * @param request contains the radio access networks with bands/channels to scan
7078 * @param messenger callback messenger for scan results or errors
7079 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07007080 * @return the id of the requested scan which can be used to stop the scan.
7081 */
7082 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007083 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
7084 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007085 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007086 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7087 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08007088 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007089 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
7090 if (!renounceFineLocationAccess) {
7091 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007092 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7093 .setCallingPackage(callingPackage)
7094 .setCallingFeatureId(callingFeatureId)
7095 .setCallingPid(Binder.getCallingPid())
7096 .setCallingUid(Binder.getCallingUid())
7097 .setMethod("requestNetworkScan")
7098 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7099 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7100 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7101 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007102 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08007103 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07007104 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
7105 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08007106 if (e != null) {
7107 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
7108 throw e;
7109 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07007110 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08007111 return TelephonyScanManager.INVALID_SCAN_ID;
7112 }
7113 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007114 }
joonhunshin4ac60942023-11-15 15:23:39 +00007115
7116 enforceTelephonyFeatureWithException(callingPackage,
7117 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan");
7118
Hall Liu912dfd32019-04-25 14:02:26 -07007119 int callingUid = Binder.getCallingUid();
7120 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07007121 final long identity = Binder.clearCallingIdentity();
7122 try {
7123 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07007124 renounceFineLocationAccess, request, messenger, binder,
7125 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07007126 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07007127 } finally {
7128 Binder.restoreCallingIdentity(identity);
7129 }
yinxu504e1392017-04-12 16:03:22 -07007130 }
7131
Hall Liub2ac8ef2019-02-28 15:56:23 -08007132 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07007133 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00007134 boolean hasCarrierPriv;
7135 final long identity = Binder.clearCallingIdentity();
7136 try {
7137 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
7138 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
7139 } finally {
7140 Binder.restoreCallingIdentity(identity);
7141 }
Hall Liu558027f2019-05-15 19:14:05 -07007142 boolean hasNetworkScanPermission =
7143 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007144 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07007145
7146 if (!hasCarrierPriv && !hasNetworkScanPermission) {
7147 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
7148 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08007149 }
7150
7151 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
7152 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08007153 if (ras.getChannels() != null && ras.getChannels().length > 0) {
7154 return new SecurityException("Specific channels must not be"
7155 + " scanned without location access.");
7156 }
7157 }
7158 }
7159
Hall Liub2ac8ef2019-02-28 15:56:23 -08007160 return null;
7161 }
7162
yinxu504e1392017-04-12 16:03:22 -07007163 /**
7164 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07007165 *
7166 * @param subId id of the subscription
7167 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07007168 */
7169 @Override
7170 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007171 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7172 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007173
Hall Liu912dfd32019-04-25 14:02:26 -07007174 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007175 final long identity = Binder.clearCallingIdentity();
7176 try {
Hall Liu912dfd32019-04-25 14:02:26 -07007177 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007178 } finally {
7179 Binder.restoreCallingIdentity(identity);
7180 }
yinxu504e1392017-04-12 16:03:22 -07007181 }
7182
7183 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08007184 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07007185 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08007186 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07007187 */
7188 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08007189 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08007190 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007191 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08007192 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007193
joonhunshin4ac60942023-11-15 15:23:39 +00007194 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7195 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask");
7196
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007197 final long identity = Binder.clearCallingIdentity();
7198 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007199 if (DBG) log("getAllowedNetworkTypesBitmask");
7200 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
7201 int networkTypesBitmask = (result != null ? result[0] : -1);
7202 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
7203 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007204 } finally {
7205 Binder.restoreCallingIdentity(identity);
7206 }
Jake Hamby7c27be32014-03-03 13:25:59 -08007207 }
7208
7209 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007210 * Get the allowed network types for certain reason.
7211 *
7212 * @param subId the id of the subscription.
7213 * @param reason the reason the allowed network type change is taking place
7214 * @return the allowed network types.
7215 */
7216 @Override
7217 public long getAllowedNetworkTypesForReason(int subId,
7218 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07007219 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007220 mApp, subId, "getAllowedNetworkTypesForReason");
joonhunshin4ac60942023-11-15 15:23:39 +00007221
7222 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7223 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesForReason");
7224
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007225 final long identity = Binder.clearCallingIdentity();
7226 try {
Jack Yu7247ac82023-03-02 23:52:10 -08007227 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007228 } finally {
7229 Binder.restoreCallingIdentity(identity);
7230 }
7231 }
7232
7233 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07007234 * Enable/Disable E-UTRA-NR Dual Connectivity
7235 * @param subId subscription id of the sim card
7236 * @param nrDualConnectivityState expected NR dual connectivity state
7237 * This can be passed following states
7238 * <ol>
7239 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
7240 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
7241 * <li>Disable NR dual connectivity and force secondary cell to be released
7242 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
7243 * </ol>
7244 * @return operation result.
7245 */
7246 @Override
7247 public int setNrDualConnectivityState(int subId,
7248 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
7249 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7250 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007251 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007252 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7253 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
7254 }
7255
Sooraj Sasindran37444802020-08-11 10:40:43 -07007256 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7257 final long identity = Binder.clearCallingIdentity();
7258 try {
7259 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
7260 nrDualConnectivityState, subId,
7261 workSource);
7262 if (DBG) log("enableNRDualConnectivity result: " + result);
7263 return result;
7264 } finally {
7265 Binder.restoreCallingIdentity(identity);
7266 }
7267 }
7268
7269 /**
7270 * Is E-UTRA-NR Dual Connectivity enabled
7271 * @return true if dual connectivity is enabled else false
7272 */
7273 @Override
7274 public boolean isNrDualConnectivityEnabled(int subId) {
7275 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007276 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07007277 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007278 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007279 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7280 return false;
7281 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07007282 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7283 final long identity = Binder.clearCallingIdentity();
7284 try {
7285 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
7286 null, subId, workSource);
7287 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
7288 return isEnabled;
7289 } finally {
7290 Binder.restoreCallingIdentity(identity);
7291 }
7292 }
7293
7294 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007295 * Set the allowed network types of the device and
7296 * provide the reason triggering the allowed network change.
7297 *
7298 * @param subId the id of the subscription.
7299 * @param reason the reason the allowed network type change is taking place
7300 * @param allowedNetworkTypes the allowed network types.
7301 * @return true on success; false on any failure.
7302 */
7303 @Override
7304 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08007305 @TelephonyManager.AllowedNetworkTypesReason int reason,
7306 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007307 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7308 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007309 // If the caller only has carrier privileges, then they should not be able to override
7310 // any network types which were set for security reasons.
7311 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
7312 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007313 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007314 throw new SecurityException(
7315 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007316 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007317 }
joonhunshin4ac60942023-11-15 15:23:39 +00007318
7319 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7320 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason");
7321
SongFerngWang3ef3e072020-12-21 16:41:52 +08007322 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007323 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08007324 return false;
7325 }
7326 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
7327 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007328 return false;
7329 }
7330
Jack Yu5b494332023-01-23 18:18:04 +00007331 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
7332 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007333
Jack Yue37dd262022-12-16 11:53:37 -08007334 Phone phone = getPhone(subId);
7335 if (phone == null) {
7336 return false;
7337 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007338
Jack Yue37dd262022-12-16 11:53:37 -08007339 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007340 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007341 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08007342 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007343
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007344 final long identity = Binder.clearCallingIdentity();
7345 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007346 Boolean success = (Boolean) sendRequest(
7347 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
7348 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
7349
7350 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
7351 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007352 } finally {
7353 Binder.restoreCallingIdentity(identity);
7354 }
7355 }
7356
7357 /**
Miaoa84611c2019-03-15 09:21:10 +08007358 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08007359 *
Miaoa84611c2019-03-15 09:21:10 +08007360 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07007361 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08007362 * @hide
7363 */
7364 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08007365 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007366 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007367
7368 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7369 PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber");
7370
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007371 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08007372 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007373 try {
Miaoa84611c2019-03-15 09:21:10 +08007374 if (phone != null) {
7375 return phone.hasMatchedTetherApnSetting();
7376 } else {
7377 return false;
7378 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007379 } finally {
7380 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007381 }
Junda Liu475951f2014-11-07 16:45:03 -08007382 }
7383
7384 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007385 * Get the user enabled state of Mobile Data.
7386 *
7387 * TODO: remove and use isUserDataEnabled.
7388 * This can't be removed now because some vendor codes
7389 * calls through ITelephony directly while they should
7390 * use TelephonyManager.
7391 *
7392 * @return true on enabled
7393 */
7394 @Override
7395 public boolean getDataEnabled(int subId) {
7396 return isUserDataEnabled(subId);
7397 }
7398
7399 /**
7400 * Get whether mobile data is enabled per user setting.
7401 *
7402 * There are other factors deciding whether mobile data is actually enabled, but they are
7403 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007404 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007405 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7406 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007407 *
7408 * @return {@code true} if data is enabled else {@code false}
7409 */
7410 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007411 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007412 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007413 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007414 try {
7415 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7416 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007417 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007418 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7419 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007420 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007421 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007422 mApp, subId, functionName);
7423
Robert Greenwalt646120a2014-05-23 11:54:03 -07007424 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007425
7426 final long identity = Binder.clearCallingIdentity();
7427 try {
Jack Yu285100e2022-12-02 22:48:35 -08007428 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007429 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7430 Phone phone = PhoneFactory.getPhone(phoneId);
7431 if (phone != null) {
7432 boolean retVal = phone.isUserDataEnabled();
7433 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7434 return retVal;
7435 } else {
7436 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7437 return false;
7438 }
7439 } finally {
7440 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007441 }
7442 }
7443
7444 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007445 * Checks if the device is capable of mobile data by considering whether whether the
7446 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7447 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007448 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007449 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007450 */
7451 @Override
7452 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007453 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007454 try {
7455 try {
7456 mApp.enforceCallingOrSelfPermission(
7457 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007458 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007459 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007460 try {
7461 mApp.enforceCallingOrSelfPermission(
7462 android.Manifest.permission.READ_PHONE_STATE,
7463 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007464 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007465 mApp.enforceCallingOrSelfPermission(
7466 permission.READ_BASIC_PHONE_STATE, functionName);
7467 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007468 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007469 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007470 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007471 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007472
joonhunshin4ac60942023-11-15 15:23:39 +00007473 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7474 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled");
7475
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007476 final long identity = Binder.clearCallingIdentity();
7477 try {
Jack Yu285100e2022-12-02 22:48:35 -08007478 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007479 Phone phone = PhoneFactory.getPhone(phoneId);
7480 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007481 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007482 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007483 return retVal;
7484 } else {
7485 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7486 return false;
7487 }
7488 } finally {
7489 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007490 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007491 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007492
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007493 /**
7494 * Check if data is enabled for a specific reason
7495 * @param subId Subscription index
7496 * @param reason the reason the data enable change is taking place
7497 * @return {@code true} if the overall data is enabled; {@code false} if not.
7498 */
7499 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007500 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007501 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007502 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007503 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007504 try {
7505 mApp.enforceCallingOrSelfPermission(
7506 android.Manifest.permission.ACCESS_NETWORK_STATE,
7507 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007508 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007509 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7510 functionName);
7511 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007512 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007513 try {
7514 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007515 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007516 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007517 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007518 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007519 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007520 }
7521
joonhunshin4ac60942023-11-15 15:23:39 +00007522 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7523 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007524
7525 final long identity = Binder.clearCallingIdentity();
7526 try {
Jack Yu285100e2022-12-02 22:48:35 -08007527 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007528 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007529 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007530 + " reason=" + reason);
7531 }
7532 Phone phone = PhoneFactory.getPhone(phoneId);
7533 if (phone != null) {
7534 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007535 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007536 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007537 return retVal;
7538 } else {
7539 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007540 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007541 + subId + " retVal=false");
7542 }
7543 return false;
7544 }
7545 } finally {
7546 Binder.restoreCallingIdentity(identity);
7547 }
7548 }
7549
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007550 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007551 public int getCarrierPrivilegeStatus(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00007552 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7553 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus");
7554
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007555 // No permission needed; this only lets the caller inspect their own status.
7556 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007557 }
Junda Liu29340342014-07-10 15:23:27 -07007558
7559 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007560 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007561 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
joonhunshin4ac60942023-11-15 15:23:39 +00007562
7563 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7564 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatusForUid");
7565
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007566 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7567 }
7568
7569 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7570 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007571 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007572 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007573 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7574 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007575 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7576 if (cpt == null) {
7577 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007578 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7579 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007580 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007581 }
7582
7583 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007584 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007585 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
joonhunshin4ac60942023-11-15 15:23:39 +00007586
7587 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7588 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage");
7589
chen xuf7e9fe82019-05-09 19:31:02 -07007590 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007591 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007592 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007593 Phone phone = getPhone(subId);
7594 if (phone == null) {
7595 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7596 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7597 }
7598 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7599 if (cpt == null) {
7600 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007601 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7602 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007603 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007604 }
7605
7606 @Override
7607 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007608 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007609
7610 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7611 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7612 "checkCarrierPrivilegesForPackageAnyPhone");
7613
Rambo Wange7209ce2022-02-23 13:41:02 -08007614 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7615 }
7616
7617 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007618 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007619 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007620 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007621 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007622 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7623 Phone phone = PhoneFactory.getPhone(phoneId);
7624 if (phone == null) {
7625 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007626 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007627 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7628 if (cpt == null) {
7629 continue;
7630 }
7631 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007632 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7633 break;
7634 }
7635 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007636 return result;
Junda Liu29340342014-07-10 15:23:27 -07007637 }
Derek Tan89e89d42014-07-08 17:00:10 -07007638
7639 @Override
Junda Liue64de782015-04-16 17:19:16 -07007640 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007641 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007642
7643 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7644 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7645 "getCarrierPackageNamesForIntentAndPhone");
7646
Rambo Wang8a247eb2022-02-08 21:11:18 +00007647 Phone phone = PhoneFactory.getPhone(phoneId);
7648 if (phone == null) {
7649 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007650 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007651 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7652 if (cpt == null) {
7653 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007654 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007655 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007656 }
7657
Amith Yamasani6e118872016-02-19 12:53:51 -08007658 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007659 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007660 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007661 Phone phone = PhoneFactory.getPhone(phoneId);
7662 if (phone == null) {
7663 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007664 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007665 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7666 if (cpt == null) {
7667 return Collections.emptyList();
7668 }
7669 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007670 }
7671
chen xuf7e9fe82019-05-09 19:31:02 -07007672 @Override
7673 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007674 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
joonhunshin4ac60942023-11-15 15:23:39 +00007675
7676 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7677 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7678 "getPackagesWithCarrierPrivilegesForAllPhones");
7679
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007680 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007681 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007682 try {
7683 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7684 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7685 }
7686 } finally {
7687 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007688 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007689 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007690 }
7691
Rambo Wang6812ffb2022-03-15 16:54:17 -07007692 @Override
7693 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7694 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7695
joonhunshin4ac60942023-11-15 15:23:39 +00007696 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7697 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7698 "getCarrierServicePackageNameForLogicalSlot");
7699
Rambo Wang6812ffb2022-03-15 16:54:17 -07007700 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7701 if (phone == null) {
7702 return null;
7703 }
7704 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7705 if (cpt == null) {
7706 return null;
7707 }
7708 return cpt.getCarrierServicePackageName();
7709 }
7710
Wink Savilleb564aae2014-10-23 10:18:09 -07007711 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007712 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007713 UiccPort port = phone == null ? null : phone.getUiccPort();
7714 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007715 return null;
7716 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007717 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007718 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007719 return null;
7720 }
7721 return iccId;
7722 }
7723
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007724 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007725 public void setCallComposerStatus(int subId, int status) {
7726 enforceModifyPermission();
7727
joonhunshin4ac60942023-11-15 15:23:39 +00007728 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7729 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus");
7730
Shuo Qiane4e11672020-12-15 22:15:33 -08007731 final long identity = Binder.clearCallingIdentity();
7732 try {
7733 Phone phone = getPhone(subId);
7734 if (phone != null) {
7735 Phone defaultPhone = phone.getImsPhone();
7736 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7737 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7738 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007739 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7740 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007741 }
7742 }
Shuo Qian284ae752020-12-22 19:10:14 -08007743 } catch (ImsException e) {
7744 throw new ServiceSpecificException(e.getCode());
7745 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007746 Binder.restoreCallingIdentity(identity);
7747 }
7748 }
7749
7750 @Override
7751 public int getCallComposerStatus(int subId) {
7752 enforceReadPrivilegedPermission("getCallComposerStatus");
7753
joonhunshin4ac60942023-11-15 15:23:39 +00007754 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7755 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus");
7756
Shuo Qiane4e11672020-12-15 22:15:33 -08007757 final long identity = Binder.clearCallingIdentity();
7758 try {
7759 Phone phone = getPhone(subId);
7760 if (phone != null) {
7761 Phone defaultPhone = phone.getImsPhone();
7762 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7763 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7764 return imsPhone.getCallComposerStatus();
7765 }
7766 }
7767 } finally {
7768 Binder.restoreCallingIdentity(identity);
7769 }
7770 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7771 }
7772
7773 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007774 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7775 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007776 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007777 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007778
joonhunshin4ac60942023-11-15 15:23:39 +00007779 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7780 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7781 "setLine1NumberForDisplayForSubscriber");
7782
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007783 final long identity = Binder.clearCallingIdentity();
7784 try {
7785 final String iccId = getIccId(subId);
7786 final Phone phone = getPhone(subId);
7787 if (phone == null) {
7788 return false;
7789 }
7790 final String subscriberId = phone.getSubscriberId();
7791
7792 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007793 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007794 + subscriberId + " to " + number);
7795 }
7796
7797 if (TextUtils.isEmpty(iccId)) {
7798 return false;
7799 }
7800
7801 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7802
7803 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7804 if (alphaTag == null) {
7805 editor.remove(alphaTagPrefKey);
7806 } else {
7807 editor.putString(alphaTagPrefKey, alphaTag);
7808 }
7809
7810 // Record both the line number and IMSI for this ICCID, since we need to
7811 // track all merged IMSIs based on line number
7812 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7813 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7814 if (number == null) {
7815 editor.remove(numberPrefKey);
7816 editor.remove(subscriberPrefKey);
7817 } else {
7818 editor.putString(numberPrefKey, number);
7819 editor.putString(subscriberPrefKey, subscriberId);
7820 }
7821
7822 editor.commit();
7823 return true;
7824 } finally {
7825 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007826 }
Derek Tan7226c842014-07-02 17:42:23 -07007827 }
7828
7829 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007830 public String getLine1NumberForDisplay(int subId, String callingPackage,
7831 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007832 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007833 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007834 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007835 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007836 return null;
7837 }
Derek Tan97ebb422014-09-05 16:55:38 -07007838
joonhunshin4ac60942023-11-15 15:23:39 +00007839 enforceTelephonyFeatureWithException(callingPackage,
7840 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay");
7841
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007842 final long identity = Binder.clearCallingIdentity();
7843 try {
7844 String iccId = getIccId(subId);
7845 if (iccId != null) {
7846 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7847 if (DBG_MERGE) {
7848 log("getLine1NumberForDisplay returning "
7849 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7850 }
7851 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007852 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007853 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7854 return null;
7855 } finally {
7856 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007857 }
Derek Tan7226c842014-07-02 17:42:23 -07007858 }
7859
7860 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007861 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7862 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007863 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007864 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007865 return null;
7866 }
Derek Tan97ebb422014-09-05 16:55:38 -07007867
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007868 final long identity = Binder.clearCallingIdentity();
7869 try {
7870 String iccId = getIccId(subId);
7871 if (iccId != null) {
7872 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7873 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7874 }
7875 return null;
7876 } finally {
7877 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007878 }
Derek Tan7226c842014-07-02 17:42:23 -07007879 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007880
7881 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007882 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7883 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007884 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7885 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007886 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007887 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007888 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007889 return null;
7890 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007891
Jordan Liub49b04b2019-05-06 14:45:15 -07007892 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7893 // the process, where TelephonyManager was instantiated.
7894 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007895 final long identity = Binder.clearCallingIdentity();
7896 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007897 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007898 final TelephonyManager tele = TelephonyManager.from(context);
7899 final SubscriptionManager sub = SubscriptionManager.from(context);
7900
7901 // Figure out what subscribers are currently active
7902 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007903
Jordan Liub49b04b2019-05-06 14:45:15 -07007904 // Only consider subs which match the current subId
7905 // This logic can be simplified. See b/131189269 for progress.
7906 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007907 activeSubscriberIds.add(tele.getSubscriberId(subId));
7908 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007909
7910 // First pass, find a number override for an active subscriber
7911 String mergeNumber = null;
7912 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7913 for (String key : prefs.keySet()) {
7914 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7915 final String subscriberId = (String) prefs.get(key);
7916 if (activeSubscriberIds.contains(subscriberId)) {
7917 final String iccId = key.substring(
7918 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7919 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7920 mergeNumber = (String) prefs.get(numberKey);
7921 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007922 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007923 + " for active subscriber " + subscriberId);
7924 }
7925 if (!TextUtils.isEmpty(mergeNumber)) {
7926 break;
7927 }
7928 }
7929 }
7930 }
7931
7932 // Shortcut when no active merged subscribers
7933 if (TextUtils.isEmpty(mergeNumber)) {
7934 return null;
7935 }
7936
7937 // Second pass, find all subscribers under that line override
7938 final ArraySet<String> result = new ArraySet<>();
7939 for (String key : prefs.keySet()) {
7940 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7941 final String number = (String) prefs.get(key);
7942 if (mergeNumber.equals(number)) {
7943 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7944 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7945 final String subscriberId = (String) prefs.get(subscriberKey);
7946 if (!TextUtils.isEmpty(subscriberId)) {
7947 result.add(subscriberId);
7948 }
7949 }
7950 }
7951 }
7952
7953 final String[] resultArray = result.toArray(new String[result.size()]);
7954 Arrays.sort(resultArray);
7955 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007956 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007957 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7958 }
7959 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007960 } finally {
7961 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007962 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007963 }
7964
7965 @Override
zoey chen38003472019-12-13 17:16:31 +08007966 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7967 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007968
joonhunshin4ac60942023-11-15 15:23:39 +00007969 enforceTelephonyFeatureWithException(callingPackage,
7970 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup");
7971
Malcolm Chen6ca97372019-07-01 16:28:21 -07007972 final long identity = Binder.clearCallingIdentity();
7973 try {
7974 final TelephonyManager telephonyManager = mApp.getSystemService(
7975 TelephonyManager.class);
7976 String subscriberId = telephonyManager.getSubscriberId(subId);
7977 if (subscriberId == null) {
7978 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007979 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007980 + subId);
7981 }
7982 return null;
7983 }
7984
Jack Yu3beaf9d2023-04-14 09:17:27 -07007985 final SubscriptionInfo info = getSubscriptionManagerService()
7986 .getSubscriptionInfo(subId);
7987 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07007988 // If it doesn't belong to any group, return just subscriberId of itself.
7989 if (groupUuid == null) {
7990 return new String[]{subscriberId};
7991 }
7992
7993 // Get all subscriberIds from the group.
7994 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07007995 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
7996 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7997 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007998 for (SubscriptionInfo subInfo : groupInfos) {
7999 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
8000 if (subscriberId != null) {
8001 mergedSubscriberIds.add(subscriberId);
8002 }
8003 }
8004
8005 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
8006 } finally {
8007 Binder.restoreCallingIdentity(identity);
8008
8009 }
8010 }
8011
8012 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008013 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008014 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08008015 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008016
joonhunshin4ac60942023-11-15 15:23:39 +00008017 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8018 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride");
8019
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008020 final long identity = Binder.clearCallingIdentity();
8021 try {
8022 final Phone phone = getPhone(subId);
8023 return phone == null ? false : phone.setOperatorBrandOverride(brand);
8024 } finally {
8025 Binder.restoreCallingIdentity(identity);
8026 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07008027 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05008028
8029 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008030 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008031 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
8032 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008033 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
8034 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008035
8036 final long identity = Binder.clearCallingIdentity();
8037 try {
8038 final Phone phone = getPhone(subId);
8039 if (phone == null) {
8040 return false;
8041 }
8042 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
8043 cdmaNonRoamingList);
8044 } finally {
8045 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008046 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008047 }
8048
8049 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07008050 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008051 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08008052 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008053 if (phone == null) {
8054 return raf;
8055 }
8056
Shuo Qiandee53402020-05-29 14:08:15 -07008057 try {
8058 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008059 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07008060 mApp, phone.getSubId(), "getRadioAccessFamily");
8061 } catch (SecurityException e) {
8062 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
8063 throw e;
8064 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008065
joonhunshin4ac60942023-11-15 15:23:39 +00008066 enforceTelephonyFeatureWithException(callingPackage,
8067 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily");
8068
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008069 final long identity = Binder.clearCallingIdentity();
8070 try {
chen xub97461a2018-10-26 14:17:57 -07008071 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008072 } finally {
8073 Binder.restoreCallingIdentity(identity);
8074 }
chen xub97461a2018-10-26 14:17:57 -07008075 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07008076 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008077
8078 @Override
Hall Liu82694d52020-12-11 18:22:04 -08008079 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08008080 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08008081 try {
8082 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
8083 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008084 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008085 }
8086 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008087 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008088 }
joonhunshin4ac60942023-11-15 15:23:39 +00008089
8090 enforceTelephonyFeatureWithException(callingPackage,
8091 PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture");
8092
Hall Liu82694d52020-12-11 18:22:04 -08008093 RoleManager rm = mApp.getSystemService(RoleManager.class);
8094 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
8095 if (!dialerRoleHolders.contains(callingPackage)) {
8096 throw new SecurityException("App must be the dialer role holder to"
8097 + " upload a call composer pic");
8098 }
8099
8100 Executors.newSingleThreadExecutor().execute(() -> {
8101 ByteArrayOutputStream output = new ByteArrayOutputStream(
8102 (int) TelephonyManager.getMaximumCallComposerPictureSize());
8103 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
8104 boolean readUntilEnd = false;
8105 int totalBytesRead = 0;
8106 byte[] buffer = new byte[16 * 1024];
8107 while (true) {
8108 int numRead;
8109 try {
8110 numRead = input.read(buffer);
8111 } catch (IOException e) {
8112 try {
8113 fd.checkError();
8114 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
8115 null);
8116 } catch (IOException e1) {
8117 // This means that the other side closed explicitly with an error. If this
8118 // happens, log and ignore.
8119 loge("Remote end of call composer picture pipe closed: " + e1);
8120 }
8121 break;
8122 }
8123 if (numRead == -1) {
8124 readUntilEnd = true;
8125 break;
8126 }
8127 totalBytesRead += numRead;
8128 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
8129 loge("Too many bytes read for call composer picture: " + totalBytesRead);
8130 try {
8131 input.close();
8132 } catch (IOException e) {
8133 // ignore
8134 }
8135 break;
8136 }
8137 output.write(buffer, 0, numRead);
8138 }
8139 // Generally, the remote end will close the file descriptors. The only case where we
8140 // close is above, where the picture size is too big.
8141
8142 try {
8143 fd.checkError();
8144 } catch (IOException e) {
8145 loge("Remote end for call composer closed with an error: " + e);
8146 return;
8147 }
8148
Hall Liuaa4211e2021-01-20 15:43:39 -08008149 if (!readUntilEnd) {
8150 loge("Did not finish reading entire image; aborting");
8151 return;
8152 }
Hall Liu82694d52020-12-11 18:22:04 -08008153
Hall Liuaa4211e2021-01-20 15:43:39 -08008154 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
8155 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
8156 new CallComposerPictureTransfer.Factory() {},
8157 imageData,
8158 (result) -> {
8159 if (result.first != null) {
8160 ParcelUuid parcelUuid = new ParcelUuid(result.first);
8161 Bundle outputResult = new Bundle();
8162 outputResult.putParcelable(
8163 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
8164 callback.send(TelephonyManager.CallComposerException.SUCCESS,
8165 outputResult);
8166 } else {
8167 callback.send(result.second, null);
8168 }
8169 }
8170 );
Hall Liu82694d52020-12-11 18:22:04 -08008171 });
8172 }
8173
8174 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07008175 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008176 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07008177 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008178
joonhunshin4ac60942023-11-15 15:23:39 +00008179 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8180 PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling");
8181
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008182 final long identity = Binder.clearCallingIdentity();
8183 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008184 ImsManager.getInstance(defaultPhone.getContext(),
8185 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008186 } finally {
8187 Binder.restoreCallingIdentity(identity);
8188 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008189 }
8190
8191 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008192 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008193 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008194 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
8195 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00008196 return false;
8197 }
Svet Ganovb320e182015-04-16 12:30:10 -07008198
joonhunshin4ac60942023-11-15 15:23:39 +00008199 enforceTelephonyFeatureWithException(callingPackage,
8200 PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled");
8201
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008202 final long identity = Binder.clearCallingIdentity();
8203 try {
8204 // Check the user preference and the system-level IMS setting. Even if the user has
8205 // enabled video calling, if IMS is disabled we aren't able to support video calling.
8206 // In the long run, we may instead need to check if there exists a connection service
8207 // which can support video calling.
8208 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008209 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008210 return imsManager.isVtEnabledByPlatform()
8211 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
8212 && imsManager.isVtEnabledByUser();
8213 } finally {
8214 Binder.restoreCallingIdentity(identity);
8215 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008216 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06008217
Andrew Leea1239f22015-03-02 17:44:07 -08008218 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008219 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
8220 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008221 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008222 mApp, subId, callingPackage, callingFeatureId,
8223 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008224 return false;
8225 }
8226
joonhunshin4ac60942023-11-15 15:23:39 +00008227 enforceTelephonyFeatureWithException(callingPackage,
8228 PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength");
8229
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008230 final long identity = Binder.clearCallingIdentity();
8231 try {
8232 CarrierConfigManager configManager =
8233 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008234 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008235 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
8236 } finally {
8237 Binder.restoreCallingIdentity(identity);
8238 }
Andrew Leea1239f22015-03-02 17:44:07 -08008239 }
8240
8241 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008242 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008243 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008244 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008245 return false;
8246 }
8247
joonhunshin4ac60942023-11-15 15:23:39 +00008248 enforceTelephonyFeatureWithException(callingPackage,
8249 PackageManager.FEATURE_TELEPHONY, "isWorldPhone");
8250
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008251 final long identity = Binder.clearCallingIdentity();
8252 try {
8253 CarrierConfigManager configManager =
8254 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008255 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008256 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
8257 } finally {
8258 Binder.restoreCallingIdentity(identity);
8259 }
Andrew Leea1239f22015-03-02 17:44:07 -08008260 }
8261
Andrew Lee9431b832015-03-09 18:46:45 -07008262 @Override
8263 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008264 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08008265 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07008266 }
8267
8268 @Override
8269 public boolean isHearingAidCompatibilitySupported() {
joonhunshin4ac60942023-11-15 15:23:39 +00008270 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8271 PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported");
8272
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008273 final long identity = Binder.clearCallingIdentity();
8274 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008275 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008276 } finally {
8277 Binder.restoreCallingIdentity(identity);
8278 }
Andrew Lee9431b832015-03-09 18:46:45 -07008279 }
8280
Hall Liuf6668912018-10-31 17:05:23 -07008281 /**
8282 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
8283 * support for the feature and device firmware support.
8284 *
8285 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
8286 */
8287 @Override
8288 public boolean isRttSupported(int subscriptionId) {
joonhunshin4ac60942023-11-15 15:23:39 +00008289 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8290 PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported");
8291
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008292 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008293 final Phone phone = getPhone(subscriptionId);
8294 if (phone == null) {
8295 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
8296 return false;
8297 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008298 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008299 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008300 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
joonhunshin4ac60942023-11-15 15:23:39 +00008301 boolean isDeviceSupported = (phone.getContext().getResources() != null)
8302 ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt)
8303 : false;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008304 return isCarrierSupported && isDeviceSupported;
8305 } finally {
8306 Binder.restoreCallingIdentity(identity);
8307 }
Hall Liu98187582018-01-22 19:15:32 -08008308 }
8309
Hall Liuf6668912018-10-31 17:05:23 -07008310 /**
Hall Liuf2daa022019-07-23 18:39:00 -07008311 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
8312 * RTT setting, will return true if the device and carrier both support RTT.
8313 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07008314 */
8315 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008316 final long identity = Binder.clearCallingIdentity();
8317 try {
joonhunshin4ac60942023-11-15 15:23:39 +00008318 if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) {
8319 if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
8320 return false;
8321 }
8322 }
8323
Hall Liu5bab75c2019-12-11 23:58:20 +00008324 boolean isRttSupported = isRttSupported(subscriptionId);
8325 boolean isUserRttSettingOn = Settings.Secure.getInt(
8326 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
8327 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
8328 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
8329 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008330 } finally {
8331 Binder.restoreCallingIdentity(identity);
8332 }
Hall Liu3ad5f012018-04-06 16:23:39 -07008333 }
8334
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008335 @Deprecated
8336 @Override
8337 public String getDeviceId(String callingPackage) {
8338 return getDeviceIdWithFeature(callingPackage, null);
8339 }
8340
Sanket Padawe7310cc72015-01-14 09:53:20 -08008341 /**
8342 * Returns the unique device ID of phone, for example, the IMEI for
8343 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
8344 *
8345 * <p>Requires Permission:
8346 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
8347 */
8348 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008349 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07008350 try {
8351 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
8352 } catch (SecurityException se) {
8353 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
8354 throw new SecurityException("Package " + callingPackage + " does not belong to "
8355 + Binder.getCallingUid());
8356 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008357 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008358 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008359 return null;
8360 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008361 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008362 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008363 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008364 return null;
8365 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008366
8367 final long identity = Binder.clearCallingIdentity();
8368 try {
8369 return phone.getDeviceId();
8370 } finally {
8371 Binder.restoreCallingIdentity(identity);
8372 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008373 }
8374
Ping Sunc67b7c22016-03-02 19:16:45 +08008375 /**
8376 * {@hide}
8377 * Returns the IMS Registration Status on a particular subid
8378 *
8379 * @param subId
8380 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008381 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008382 Phone phone = getPhone(subId);
8383 if (phone != null) {
8384 return phone.isImsRegistered();
8385 } else {
8386 return false;
8387 }
8388 }
8389
Santos Cordon7a1885b2015-02-03 11:15:19 -08008390 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008391 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008392 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008393 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008394 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008395 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8396 }
8397 final long identity = Binder.clearCallingIdentity();
8398 try {
8399 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8400 } finally {
8401 Binder.restoreCallingIdentity(identity);
8402 }
8403 }
8404
8405 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008406 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008407 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008408 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008409 mApp,
8410 subscriptionId,
8411 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
8412 + subscriptionId);
joonhunshin4ac60942023-11-15 15:23:39 +00008413
8414 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8415 PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId");
8416
Tyler Gunnf70ed162019-04-03 15:28:53 -07008417 final long identity = Binder.clearCallingIdentity();
8418 try {
8419 Phone phone = getPhone(subscriptionId);
8420 if (phone == null) {
8421 return null;
8422 }
8423 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8424 } finally {
8425 Binder.restoreCallingIdentity(identity);
8426 }
8427 }
8428
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008429 /**
8430 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008431 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008432 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008433 final long identity = Binder.clearCallingIdentity();
8434 try {
8435 Phone phone = getPhone(subId);
8436 if (phone != null) {
8437 return phone.isWifiCallingEnabled();
8438 } else {
8439 return false;
8440 }
8441 } finally {
8442 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008443 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008444 }
8445
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008446 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008447 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008448 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008449 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008450 final long identity = Binder.clearCallingIdentity();
8451 try {
8452 Phone phone = getPhone(subId);
8453 if (phone != null) {
8454 return phone.isVideoEnabled();
8455 } else {
8456 return false;
8457 }
8458 } finally {
8459 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008460 }
8461 }
8462
8463 /**
8464 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8465 * defined in {@link ImsRegistrationImplBase}.
8466 */
8467 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008468 final long identity = Binder.clearCallingIdentity();
8469 try {
8470 Phone phone = getPhone(subId);
8471 if (phone != null) {
8472 return phone.getImsRegistrationTech();
8473 } else {
8474 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8475 }
8476 } finally {
8477 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008478 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008479 }
8480
Stuart Scott8eef64f2015-04-08 15:13:54 -07008481 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008482 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008483 enforceSettingsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008484
8485 enforceTelephonyFeatureWithException(callingPackage,
8486 PackageManager.FEATURE_TELEPHONY, "factoryReset");
8487
Stuart Scott981d8582015-04-21 14:09:50 -07008488 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8489 return;
8490 }
Kai Shif70f46f2021-03-03 13:59:46 -08008491 Phone defaultPhone = getDefaultPhone();
8492 if (defaultPhone != null) {
8493 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8494 mApp, getDefaultPhone().getSubId(), "factoryReset");
8495 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008496 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008497
Svet Ganovcc087f82015-05-12 20:35:54 -07008498 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008499 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8500 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008501 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008502 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008503 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008504 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008505 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008506 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08008507 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008508 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008509 // There has been issues when Sms raw table somehow stores orphan
8510 // fragments. They lead to garbled message when new fragments come
8511 // in and combined with those stale ones. In case this happens again,
8512 // user can reset all network settings which will clean up this table.
8513 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008514 // Clean up IMS settings as well here.
8515 int slotId = getSlotIndex(subId);
8516 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
8517 ImsManager.getInstance(mApp, slotId).factoryReset();
8518 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008519
Kai Shif70f46f2021-03-03 13:59:46 -08008520 if (defaultPhone == null) {
8521 return;
8522 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008523 // Erase modem config if erase modem on network setting is enabled.
8524 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8525 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8526 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008527 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008528 }
Kai Shif70f46f2021-03-03 13:59:46 -08008529
8530 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008531 } finally {
8532 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008533 }
8534 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008535
SongFerngWangfd89b102021-05-27 22:44:54 +08008536 @VisibleForTesting
8537 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8538 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8539 return;
8540 }
8541 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8542 RILConstants.PREFERRED_NETWORK_MODE);
8543 SubscriptionManager.setSubscriptionProperty(subId,
8544 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8545 "user=" + defaultNetworkType);
8546 phone.loadAllowedNetworksFromSubscriptionDatabase();
8547 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8548 defaultNetworkType, null);
8549 }
8550
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008551 private void cleanUpSmsRawTable(Context context) {
8552 ContentResolver resolver = context.getContentResolver();
8553 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8554 resolver.delete(uri, null, null);
8555 }
8556
Narayan Kamath1c496c22015-04-16 14:40:19 +01008557 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008558 public String getSimLocaleForSubscriber(int subId) {
8559 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
joonhunshin4ac60942023-11-15 15:23:39 +00008560
8561 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8562 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber");
8563
chen xu5d3637b2019-01-21 23:31:38 -08008564 final Phone phone = getPhone(subId);
8565 if (phone == null) {
8566 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008567 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008568 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008569 final long identity = Binder.clearCallingIdentity();
8570 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008571 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
8572 phone.getContext().getOpPackageName(),
8573 phone.getContext().getAttributionTag());
8574 if (info == null) {
8575 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8576 return null;
chen xu6291c472019-02-04 12:55:53 -08008577 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008578 // Try and fetch the locale from the carrier properties or from the SIM language
8579 // preferences (EF-PL and EF-LI)...
8580 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008581 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008582 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8583 if (localeFromDefaultSim != null) {
8584 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8585 if (DBG) log("Using locale from subId: " + subId + " locale: "
8586 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008587 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008588 } else {
8589 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008590 }
8591 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008592
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008593 // The SIM language preferences only store a language (e.g. fr = French), not an
8594 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8595 // the SIM and carrier preferences does not include a country we add the country
8596 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008597 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008598 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008599 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008600 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008601 }
8602
8603 if (DBG) log("No locale found - returning null");
8604 return null;
8605 } finally {
8606 Binder.restoreCallingIdentity(identity);
8607 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008608 }
8609
tom hsu0b59d292022-09-29 23:49:21 +08008610 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008611 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008612 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008613 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008614 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008615 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8616 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008617 Locale.forLanguageTag(localeTag).getCountry())) {
8618 return localeTag;
8619 }
8620 }
8621 return inputLocale.toLanguageTag();
8622 }
8623
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008624 /**
8625 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8626 */
8627 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008628 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Ling Ma9fa67412023-11-13 14:13:19 -08008629 mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/);
Narayan Kamath1c496c22015-04-16 14:40:19 +01008630 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008631
Gary Jian3aa9a762022-01-24 16:41:19 +08008632 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8633 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008634
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008635 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008636 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8637 * representing the state of the modem.
8638 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008639 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8640 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008641 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008642 */
8643 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008644 public void requestModemActivityInfo(ResultReceiver result) {
8645 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008646
8647 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8648 PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo");
8649
vagdeviaf9a5b92018-08-15 16:01:53 -07008650 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008651
8652 final long identity = Binder.clearCallingIdentity();
8653 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008654 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008655 } finally {
8656 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008657 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008658 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008659
Gary Jian76280a42022-12-07 16:18:33 +08008660 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008661 // less than total activity duration.
8662 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8663 if (info == null) {
8664 return false;
8665 }
8666 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008667 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008668 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8669
Hall Liu49656c02020-10-09 19:00:11 -07008670 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8671
Siddharth Rayb8114062018-06-17 15:02:38 -07008672 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008673 && (info.getSleepTimeMillis() <= activityDurationMs)
8674 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008675 }
8676
Gary Jian3aa9a762022-01-24 16:41:19 +08008677 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8678 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8679 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8680 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8681
8682 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8683 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8684 }
8685
8686 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8687 mLastModemActivityInfo.setReceiveTimeMillis(
8688 rat,
8689 freq,
8690 info.getReceiveTimeMillis(rat, freq)
8691 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8692 }
8693
8694 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8695 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8696 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8697 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8698
8699 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8700 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8701 }
8702 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8703 mLastModemActivityInfo.setReceiveTimeMillis(
8704 rat,
8705 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8706 }
8707
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008708 /**
8709 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8710 * @param info recent ModemActivityInfo
8711 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008712 private void mergeModemActivityInfo(ModemActivityInfo info) {
8713 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008714 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008715 boolean matched;
8716 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8717 matched = false;
8718 int rat = info.getSpecificInfoRat(i);
8719 int freq = info.getSpecificInfoFrequencyRange(i);
8720 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8721 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8722 //if it already exists
8723 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8724 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8725 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8726 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8727 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8728 updateLastModemActivityInfo(info, rat, freq);
8729 matched = true;
8730 }
8731 } else {
8732 updateLastModemActivityInfo(info, rat);
8733 matched = true;
8734 }
8735 }
8736 }
8737
8738 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008739 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008740 new ActivityStatsTechSpecificInfo(
8741 rat,
8742 freq,
8743 info.getTransmitTimeMillis(rat, freq),
8744 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008745 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008746 }
8747 }
8748 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8749 mLastModemActivitySpecificInfo =
8750 new ActivityStatsTechSpecificInfo[merged.size()];
8751 merged.toArray(mLastModemActivitySpecificInfo);
8752
8753 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8754 mLastModemActivityInfo.setSleepTimeMillis(
8755 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008756 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008757 mLastModemActivityInfo.setIdleTimeMillis(
8758 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008759 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008760
8761 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008762 new ModemActivityInfo(
8763 mLastModemActivityInfo.getTimestampMillis(),
8764 mLastModemActivityInfo.getSleepTimeMillis(),
8765 mLastModemActivityInfo.getIdleTimeMillis(),
8766 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008767 }
8768
8769 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8770 ActivityStatsTechSpecificInfo[] info) {
8771 int infoSize = info.length;
8772 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8773 for (int i = 0; i < infoSize; i++) {
8774 ret[i] = new ActivityStatsTechSpecificInfo(
8775 info[i].getRat(), info[i].getFrequencyRange(),
8776 info[i].getTransmitTimeMillis(),
8777 (int) info[i].getReceiveTimeMillis());
8778 }
8779 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008780 }
8781
Jack Yu85bd38a2015-11-09 11:34:32 -08008782 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008783 * Returns the service state information on specified subscription.
8784 */
8785 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008786 public ServiceState getServiceStateForSubscriber(int subId,
8787 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8788 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008789 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008790 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008791 return null;
8792 }
8793
joonhunshin4ac60942023-11-15 15:23:39 +00008794 enforceTelephonyFeatureWithException(callingPackage,
8795 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber");
8796
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008797 boolean hasFinePermission = false;
8798 boolean hasCoarsePermission = false;
8799 if (!renounceFineLocationAccess) {
8800 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8801 LocationAccessPolicy.checkLocationPermission(mApp,
8802 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8803 .setCallingPackage(callingPackage)
8804 .setCallingFeatureId(callingFeatureId)
8805 .setCallingPid(Binder.getCallingPid())
8806 .setCallingUid(Binder.getCallingUid())
8807 .setMethod("getServiceStateForSubscriber")
8808 .setLogAsInfo(true)
8809 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8810 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8811 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8812 .build());
8813 hasFinePermission =
8814 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8815 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008816
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008817 if (!renounceCoarseLocationAccess) {
8818 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8819 LocationAccessPolicy.checkLocationPermission(mApp,
8820 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8821 .setCallingPackage(callingPackage)
8822 .setCallingFeatureId(callingFeatureId)
8823 .setCallingPid(Binder.getCallingPid())
8824 .setCallingUid(Binder.getCallingUid())
8825 .setMethod("getServiceStateForSubscriber")
8826 .setLogAsInfo(true)
8827 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8828 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8829 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8830 .build());
8831 hasCoarsePermission =
8832 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8833 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008834
Jack Yu479f40e2020-10-27 21:29:25 -07008835 final Phone phone = getPhone(subId);
8836 if (phone == null) {
8837 return null;
8838 }
8839
Jordan Liu0f2bc442020-11-18 16:47:37 -08008840 final long identity = Binder.clearCallingIdentity();
8841
Jack Yu479f40e2020-10-27 21:29:25 -07008842 boolean isCallingPackageDataService = phone.getDataServicePackages()
8843 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008844 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008845 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu3beaf9d2023-04-14 09:17:27 -07008846 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8847 .getSubscriptionInfoInternal(subId);
8848 if (subInfo == null || !subInfo.isActive()) {
8849 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8850 + "subId=" + subId);
8851 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008852 }
8853
Hall Liuf19c44f2018-11-27 14:38:17 -08008854 ServiceState ss = phone.getServiceState();
8855
8856 // Scrub out the location info in ServiceState depending on what level of access
8857 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008858 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008859 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8860 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008861 } finally {
8862 Binder.restoreCallingIdentity(identity);
8863 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008864 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008865
8866 /**
8867 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8868 *
8869 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8870 * voicemail ringtone.
8871 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8872 * PhoneAccount.
8873 */
8874 @Override
8875 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008876 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8877 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri");
8878
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008879 final long identity = Binder.clearCallingIdentity();
8880 try {
8881 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8882 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008883 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008884 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008885
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008886 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8887 } finally {
8888 Binder.restoreCallingIdentity(identity);
8889 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008890 }
8891
8892 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008893 * Sets the per-account voicemail ringtone.
8894 *
8895 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8896 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8897 *
8898 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8899 * voicemail ringtone.
8900 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8901 * PhoneAccount.
8902 */
8903 @Override
8904 public void setVoicemailRingtoneUri(String callingPackage,
8905 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008906 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008907 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008908 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8909 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008910 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8911 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8912 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008913 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008914
joonhunshin4ac60942023-11-15 15:23:39 +00008915 enforceTelephonyFeatureWithException(callingPackage,
8916 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri");
8917
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008918 final long identity = Binder.clearCallingIdentity();
8919 try {
8920 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8921 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008922 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008923 }
8924 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8925 } finally {
8926 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008927 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008928 }
8929
8930 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008931 * Returns whether vibration is set for voicemail notification in Phone settings.
8932 *
8933 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8934 * voicemail vibration setting.
8935 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8936 */
8937 @Override
8938 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008939 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8940 PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled");
8941
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008942 final long identity = Binder.clearCallingIdentity();
8943 try {
8944 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8945 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008946 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008947 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008948
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008949 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8950 } finally {
8951 Binder.restoreCallingIdentity(identity);
8952 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008953 }
8954
Youhan Wange64578a2016-05-02 15:32:42 -07008955 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008956 * Sets the per-account voicemail vibration.
8957 *
8958 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8959 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8960 *
8961 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8962 * voicemail vibration setting.
8963 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8964 * specific PhoneAccount.
8965 */
8966 @Override
8967 public void setVoicemailVibrationEnabled(String callingPackage,
8968 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008969 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008970 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008971 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8972 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008973 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8974 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8975 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008976 }
8977
joonhunshin4ac60942023-11-15 15:23:39 +00008978 enforceTelephonyFeatureWithException(callingPackage,
8979 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled");
8980
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008981 final long identity = Binder.clearCallingIdentity();
8982 try {
8983 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8984 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008985 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008986 }
8987 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8988 } finally {
8989 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008990 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008991 }
8992
8993 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008994 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8995 *
8996 * @throws SecurityException if the caller does not have the required permission
8997 */
arunvoddud7401012022-12-15 16:08:12 +00008998 @VisibleForTesting
8999 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07009000 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07009001 message);
Youhan Wange64578a2016-05-02 15:32:42 -07009002 }
9003
9004 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009005 * Make sure either called from same process as self (phone) or IPC caller has send SMS
9006 * permission.
9007 *
9008 * @throws SecurityException if the caller does not have the required permission
9009 */
9010 private void enforceSendSmsPermission() {
9011 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
9012 }
9013
9014 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00009015 * Make sure either called from same process as self (phone) or IPC caller has interact across
9016 * users permission.
9017 *
9018 * @throws SecurityException if the caller does not have the required permission
9019 */
9020 private void enforceInteractAcrossUsersPermission(String message) {
9021 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
9022 }
9023
9024 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009025 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009026 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009027 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009028 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009029 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009030 final long identity = Binder.clearCallingIdentity();
9031 try {
9032 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009033 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009034 if (componentName == null) {
9035 throw new SecurityException(
9036 "Caller not current active visual voicemail package[null]");
9037 }
9038 String vvmPackage = componentName.getPackageName();
9039 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00009040 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009041 }
9042 } finally {
9043 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009044 }
9045 }
9046
9047 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009048 * Return the application ID for the app type.
9049 *
9050 * @param subId the subscription ID that this request applies to.
9051 * @param appType the uicc app type.
9052 * @return Application ID for specificied app type, or null if no uicc.
9053 */
9054 @Override
9055 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009056 enforceReadPrivilegedPermission("getAidForAppType");
joonhunshin4ac60942023-11-15 15:23:39 +00009057
9058 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9059 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType");
9060
Youhan Wange64578a2016-05-02 15:32:42 -07009061 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009062
9063 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07009064 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009065 if (phone == null) {
9066 return null;
9067 }
9068 String aid = null;
9069 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009070 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009071 .getApplicationByType(appType).getAid();
9072 } catch (Exception e) {
9073 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
9074 }
9075 return aid;
9076 } finally {
9077 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07009078 }
Youhan Wange64578a2016-05-02 15:32:42 -07009079 }
9080
Youhan Wang4001d252016-05-11 10:29:41 -07009081 /**
9082 * Return the Electronic Serial Number.
9083 *
9084 * @param subId the subscription ID that this request applies to.
9085 * @return ESN or null if error.
9086 */
9087 @Override
9088 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009089 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07009090 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009091
9092 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07009093 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009094 if (phone == null) {
9095 return null;
9096 }
9097 String esn = null;
9098 try {
9099 esn = phone.getEsn();
9100 } catch (Exception e) {
9101 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
9102 }
9103 return esn;
9104 } finally {
9105 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07009106 }
Youhan Wang4001d252016-05-11 10:29:41 -07009107 }
9108
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009109 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009110 * Return the Preferred Roaming List Version.
9111 *
9112 * @param subId the subscription ID that this request applies to.
9113 * @return PRLVersion or null if error.
9114 */
9115 @Override
9116 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009117 enforceReadPrivilegedPermission("getCdmaPrlVersion");
joonhunshin4ac60942023-11-15 15:23:39 +00009118
9119 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9120 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion");
9121
Youhan Wang66ad5d72016-07-18 17:56:58 -07009122 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009123
9124 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009125 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009126 if (phone == null) {
9127 return null;
9128 }
9129 String cdmaPrlVersion = null;
9130 try {
9131 cdmaPrlVersion = phone.getCdmaPrlVersion();
9132 } catch (Exception e) {
9133 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9134 }
9135 return cdmaPrlVersion;
9136 } finally {
9137 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009138 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009139 }
9140
9141 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009142 * Get snapshot of Telephony histograms
9143 * @return List of Telephony histograms
9144 * @hide
9145 */
9146 @Override
9147 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009148 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9149 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009150
9151 final long identity = Binder.clearCallingIdentity();
9152 try {
9153 return RIL.getTelephonyRILTimingHistograms();
9154 } finally {
9155 Binder.restoreCallingIdentity(identity);
9156 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009157 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009158
9159 /**
9160 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009161 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9162 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009163 * Require system privileges. In the future we may add this to carrier APIs.
9164 *
Michele Berionne482f8202018-11-27 18:57:59 -08009165 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009166 */
9167 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009168 @TelephonyManager.SetCarrierRestrictionResult
9169 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009170 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009171
9172 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9173 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers");
9174
vagdeviaf9a5b92018-08-15 16:01:53 -07009175 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009176
Michele Berionne482f8202018-11-27 18:57:59 -08009177 if (carrierRestrictionRules == null) {
9178 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009179 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009180
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009181 final long identity = Binder.clearCallingIdentity();
9182 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009183 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009184 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009185 } finally {
9186 Binder.restoreCallingIdentity(identity);
9187 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009188 }
9189
9190 /**
9191 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009192 * Get the allowed carrier list and the excluded carrier list, including the priority between
9193 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009194 * Require system privileges. In the future we may add this to carrier APIs.
9195 *
Michele Berionne482f8202018-11-27 18:57:59 -08009196 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009197 */
9198 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009199 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009200 enforceReadPrivilegedPermission("getAllowedCarriers");
joonhunshin4ac60942023-11-15 15:23:39 +00009201
9202 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9203 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers");
9204
vagdeviaf9a5b92018-08-15 16:01:53 -07009205 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009206
9207 final long identity = Binder.clearCallingIdentity();
9208 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009209 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9210 if (response instanceof CarrierRestrictionRules) {
9211 return (CarrierRestrictionRules) response;
9212 }
9213 // Response is an Exception of some kind,
9214 // which is signalled to the user as a NULL retval
9215 return null;
9216 } catch (Exception e) {
9217 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9218 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009219 } finally {
9220 Binder.restoreCallingIdentity(identity);
9221 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009222 }
9223
fionaxu59545b42016-05-25 15:53:37 -07009224 /**
arunvoddud7401012022-12-15 16:08:12 +00009225 * Fetches the carrier restriction status of the device and sends the status to the caller
9226 * through the callback.
9227 *
9228 * @param callback The callback that will be used to send the result.
9229 * @throws SecurityException if the caller does not have the required permission/privileges or
9230 * the caller is not allowlisted.
9231 */
9232 @Override
9233 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
9234 enforceReadPermission("getCarrierRestrictionStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00009235
9236 enforceTelephonyFeatureWithException(packageName,
9237 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierRestrictionStatus");
9238
arunvoddud7401012022-12-15 16:08:12 +00009239 int carrierId = validateCallerAndGetCarrierId(packageName);
9240 if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) {
9241 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9242 throw new SecurityException("Not an authorized caller");
9243 }
9244 final long identity = Binder.clearCallingIdentity();
9245 try {
9246 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
9247 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId);
9248 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9249 } finally {
9250 Binder.restoreCallingIdentity(identity);
9251 }
9252 }
9253
arunvoddu567f2b42023-04-25 17:22:00 +00009254 @Override
9255 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
9256 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
9257 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9258 return allowListInfo.getShaIdList(pkgName, carrierId);
9259 }
9260
arunvoddud7401012022-12-15 16:08:12 +00009261 @VisibleForTesting
9262 public int validateCallerAndGetCarrierId(String packageName) {
9263 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9264 return allowListInfo.validateCallerAndGetCarrierId(packageName);
9265 }
9266
9267 /**
fionaxu59545b42016-05-25 15:53:37 -07009268 * Action set from carrier signalling broadcast receivers to enable/disable radio
9269 * @param subId the subscription ID that this action applies to.
9270 * @param enabled control enable or disable radio.
9271 * {@hide}
9272 */
9273 @Override
9274 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9275 enforceModifyPermission();
9276 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009277
9278 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009279 if (phone == null) {
9280 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9281 return;
9282 }
9283 try {
9284 phone.carrierActionSetRadioEnabled(enabled);
9285 } catch (Exception e) {
9286 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009287 } finally {
9288 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009289 }
9290 }
9291
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009292 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009293 * Enable or disable Voice over NR (VoNR)
9294 * @param subId the subscription ID that this action applies to.
9295 * @param enabled enable or disable VoNR.
9296 * @return operation result.
9297 */
9298 @Override
9299 public int setVoNrEnabled(int subId, boolean enabled) {
9300 enforceModifyPermission();
9301 final Phone phone = getPhone(subId);
9302
9303 final long identity = Binder.clearCallingIdentity();
9304 if (phone == null) {
9305 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9306 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9307 }
9308
9309 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9310 try {
9311 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9312 workSource);
9313 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009314
9315 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9316 if (DBG) {
9317 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9318 }
9319 SubscriptionManager.setSubscriptionProperty(
9320 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9321 (enabled ? "1" : "0"));
9322 }
9323
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009324 return result;
9325 } finally {
9326 Binder.restoreCallingIdentity(identity);
9327 }
9328 }
9329
9330 /**
9331 * Is voice over NR enabled
9332 * @return true if VoNR is enabled else false
9333 */
9334 @Override
9335 public boolean isVoNrEnabled(int subId) {
9336 enforceReadPrivilegedPermission("isVoNrEnabled");
9337 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9338 final long identity = Binder.clearCallingIdentity();
9339 try {
9340 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9341 null, subId, workSource);
9342 if (DBG) log("isVoNrEnabled: " + isEnabled);
9343 return isEnabled;
9344 } finally {
9345 Binder.restoreCallingIdentity(identity);
9346 }
9347 }
9348
9349 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009350 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9351 * network status based on which carrier apps could apply actions accordingly,
9352 * enable/disable default url handler for example.
9353 *
9354 * @param subId the subscription ID that this action applies to.
9355 * @param report control start/stop reporting the default network status.
9356 * {@hide}
9357 */
9358 @Override
9359 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9360 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009361
9362 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9363 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
9364 "carrierActionReportDefaultNetworkStatus");
9365
fionaxu8da9cb12017-05-23 15:02:46 -07009366 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009367
9368 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009369 if (phone == null) {
9370 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9371 return;
9372 }
9373 try {
9374 phone.carrierActionReportDefaultNetworkStatus(report);
9375 } catch (Exception e) {
9376 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009377 } finally {
9378 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009379 }
9380 }
9381
9382 /**
fionaxud9622282017-07-17 17:51:30 -07009383 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9384 * @param subId the subscription ID that this action applies to.
9385 * {@hide}
9386 */
9387 @Override
9388 public void carrierActionResetAll(int subId) {
9389 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009390
9391 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9392 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll");
9393
fionaxud9622282017-07-17 17:51:30 -07009394 final Phone phone = getPhone(subId);
9395 if (phone == null) {
9396 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9397 return;
9398 }
9399 try {
9400 phone.carrierActionResetAll();
9401 } catch (Exception e) {
9402 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9403 }
9404 }
9405
9406 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009407 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9408 * bug report is being generated.
9409 */
9410 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009411 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009412 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9413 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009414 writer.println("Permission Denial: can't dump Phone from pid="
9415 + Binder.getCallingPid()
9416 + ", uid=" + Binder.getCallingUid()
9417 + "without permission "
9418 + android.Manifest.permission.DUMP);
9419 return;
9420 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009421 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009422 }
Jack Yueb89b242016-06-22 13:27:47 -07009423
Brad Ebingerdac2f002018-04-03 15:17:52 -07009424 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009425 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9426 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9427 @NonNull String[] args) {
9428 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9429 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009430 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009431 }
9432
Jack Yueb89b242016-06-22 13:27:47 -07009433 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009434 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009435 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009436 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009437 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009438 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009439 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009440 */
9441 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009442 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009443 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009444 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9445 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9446 try {
9447 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009448 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009449 } catch (SecurityException se) {
9450 enforceModifyPermission();
9451 }
9452 } else {
9453 enforceModifyPermission();
9454 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009455
Nate Myrenae97d192023-06-09 15:22:31 -07009456 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
9457 && null != callingPackage && opEnableMobileDataByUser()) {
9458 mAppOps.noteOp(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER, Binder.getCallingUid(),
9459 callingPackage, null, null);
9460 }
9461
joonhunshin4ac60942023-11-15 15:23:39 +00009462 enforceTelephonyFeatureWithException(callingPackage,
9463 PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason");
9464
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009465 final long identity = Binder.clearCallingIdentity();
9466 try {
9467 Phone phone = getPhone(subId);
9468 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009469 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9470 phone.carrierActionSetMeteredApnsEnabled(enabled);
9471 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07009472 phone.getDataSettingsManager().setDataEnabled(
9473 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009474 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009475 }
9476 } finally {
9477 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009478 }
9479 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009480
9481 /**
9482 * Get Client request stats
9483 * @return List of Client Request Stats
9484 * @hide
9485 */
9486 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009487 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9488 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009489 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009490 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009491 return null;
9492 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009493 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009494
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009495 final long identity = Binder.clearCallingIdentity();
9496 try {
9497 if (phone != null) {
9498 return phone.getClientRequestStats();
9499 }
9500
9501 return null;
9502 } finally {
9503 Binder.restoreCallingIdentity(identity);
9504 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009505 }
9506
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009507 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009508 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009509 if (uid == Process.ROOT_UID && packageName == null) {
9510 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9511 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9512 // exception. ROOT_UID seems not to have a valid package name returned by
9513 // PackageManager, so just fake it here to avoid issues when running telephony shell
9514 // commands that plumb through the RIL as root, like so:
9515 // $ adb root
9516 // $ adb shell cmd phone ...
9517 packageName = "root";
9518 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009519 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009520 }
Jack Yueb4124c2017-02-16 15:32:43 -08009521
9522 /**
Grace Chen70990072017-03-24 17:21:30 -07009523 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009524 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009525 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009526 * @param state State of SIM (power down, power up, pass through)
9527 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9528 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9529 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009530 *
9531 **/
9532 @Override
Grace Chen70990072017-03-24 17:21:30 -07009533 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009534 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009535
9536 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9537 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot");
9538
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009539 Phone phone = PhoneFactory.getPhone(slotIndex);
9540
vagdeviaf9a5b92018-08-15 16:01:53 -07009541 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9542
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009543 final long identity = Binder.clearCallingIdentity();
9544 try {
9545 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009546 phone.setSimPowerState(state, null, workSource);
9547 }
9548 } finally {
9549 Binder.restoreCallingIdentity(identity);
9550 }
9551 }
9552
9553 /**
9554 * Set SIM card power state.
9555 *
9556 * @param slotIndex SIM slot id.
9557 * @param state State of SIM (power down, power up, pass through)
9558 * @param callback callback to trigger after success or failure
9559 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9560 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9561 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9562 *
9563 **/
9564 @Override
9565 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9566 IIntegerConsumer callback) {
9567 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009568
9569 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9570 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
9571 "setSimPowerStateForSlotWithCallback");
9572
Jordan Liu109698e2020-11-24 14:50:34 -08009573 Phone phone = PhoneFactory.getPhone(slotIndex);
9574
9575 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9576
9577 final long identity = Binder.clearCallingIdentity();
9578 try {
9579 if (phone != null) {
9580 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9581 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009582 }
9583 } finally {
9584 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009585 }
9586 }
Shuo Qiandd210312017-04-12 22:11:33 +00009587
Tyler Gunn65d45c22017-06-05 11:22:26 -07009588 private boolean isUssdApiAllowed(int subId) {
9589 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009590 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009591 if (configManager == null) {
9592 return false;
9593 }
9594 PersistableBundle pb = configManager.getConfigForSubId(subId);
9595 if (pb == null) {
9596 return false;
9597 }
9598 return pb.getBoolean(
9599 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9600 }
9601
Shuo Qiandd210312017-04-12 22:11:33 +00009602 /**
Ling Mac28f0212023-03-24 16:07:15 -07009603 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00009604 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07009605 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00009606 */
goneil9c5f4872017-12-05 14:07:56 -08009607 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009608 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009609 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
joonhunshin4ac60942023-11-15 15:23:39 +00009610
9611 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9612 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode");
9613
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009614 final long identity = Binder.clearCallingIdentity();
9615 try {
Ling Mac28f0212023-03-24 16:07:15 -07009616 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009617 } finally {
9618 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009619 }
9620 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009621
9622 /**
9623 * Get the current signal strength information for the given subscription.
9624 * Because this information is not updated when the device is in a low power state
9625 * it should not be relied-upon to be current.
9626 * @param subId Subscription index
9627 * @return the most recent cached signal strength info from the modem
9628 */
9629 @Override
9630 public SignalStrength getSignalStrength(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00009631 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9632 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength");
9633
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009634 final long identity = Binder.clearCallingIdentity();
9635 try {
9636 Phone p = getPhone(subId);
9637 if (p == null) {
9638 return null;
9639 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009640
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009641 return p.getSignalStrength();
9642 } finally {
9643 Binder.restoreCallingIdentity(identity);
9644 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009645 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009646
Pengquan Meng77b7f132018-08-22 14:49:57 -07009647 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009648 * Get the current modem radio state for the given slot.
9649 * @param slotIndex slot index.
9650 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009651 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009652 * @return the current radio power state from the modem
9653 */
9654 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009655 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009656 Phone phone = PhoneFactory.getPhone(slotIndex);
9657 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009658 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9659 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009660 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9661 }
9662
joonhunshin4ac60942023-11-15 15:23:39 +00009663 enforceTelephonyFeatureWithException(callingPackage,
9664 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState");
9665
Chen Xuf792fd62018-10-17 17:54:36 +00009666 final long identity = Binder.clearCallingIdentity();
9667 try {
9668 return phone.getRadioPowerState();
9669 } finally {
9670 Binder.restoreCallingIdentity(identity);
9671 }
9672 }
9673 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9674 }
9675
9676 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009677 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9678 *
9679 * <p>Requires one of the following permissions:
9680 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009681 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009682 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9683 * privileges.
9684 *
9685 * @param subId subscription id
9686 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9687 * {@code false}.
9688 */
9689 @Override
9690 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009691 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009692 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009693 try {
9694 mApp.enforceCallingOrSelfPermission(
9695 android.Manifest.permission.ACCESS_NETWORK_STATE,
9696 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009697 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009698 mApp.enforceCallingOrSelfPermission(
9699 permission.READ_BASIC_PHONE_STATE, functionName);
9700 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009701 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009702 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009703 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009704 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009705
joonhunshin4ac60942023-11-15 15:23:39 +00009706 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9707 PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled");
9708
Pengquan Menga1bb6272018-09-06 09:59:22 -07009709 boolean isEnabled = false;
9710 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009711 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009712 Phone phone = getPhone(subId);
9713 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009714 } finally {
9715 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009716 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009717 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009718 }
9719
9720
9721 /**
9722 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9723 *
9724 * <p> Requires permission:
9725 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9726 * privileges.
9727 *
9728 * @param subId subscription id
9729 * @param isEnabled {@code true} means enable, {@code false} means disable.
9730 */
9731 @Override
9732 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009733 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9734 mApp, subId, "setDataRoamingEnabled");
9735
joonhunshin4ac60942023-11-15 15:23:39 +00009736 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9737 PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled");
9738
Pengquan Menga1bb6272018-09-06 09:59:22 -07009739 final long identity = Binder.clearCallingIdentity();
9740 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009741 Phone phone = getPhone(subId);
9742 if (phone != null) {
9743 phone.setDataRoamingEnabled(isEnabled);
9744 }
9745 } finally {
9746 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009747 }
9748 }
9749
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009750 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009751 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009752 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009753 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009754 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009755
joonhunshin4ac60942023-11-15 15:23:39 +00009756 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9757 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed");
9758
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009759 boolean isAllowed = true;
9760 final long identity = Binder.clearCallingIdentity();
9761 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009762 Phone phone = getPhone(subId);
9763 if (phone != null) {
9764 isAllowed = phone.isCspPlmnEnabled();
9765 }
9766 } finally {
9767 Binder.restoreCallingIdentity(identity);
9768 }
9769 return isAllowed;
9770 }
9771
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009772 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9773 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009774 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009775 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009776 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009777 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9778 if (phone == null) {
9779 return false;
9780 }
9781 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9782 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9783 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009784 }
9785
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009786 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009787 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009788 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009789 mApp.getSystemService(AppOpsManager.class)
9790 .checkPackage(Binder.getCallingUid(), callingPackage);
9791
Jordan Liu1e142fc2019-04-22 15:10:43 -07009792 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009793 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009794 try {
9795 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009796 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009797 } catch (SecurityException e) {
9798 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9799 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009800 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009801 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009802 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009803 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009804 }
joonhunshin4ac60942023-11-15 15:23:39 +00009805
9806 enforceTelephonyFeatureWithException(callingPackage,
9807 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo");
9808
sandeepjsb6c87872021-09-27 15:34:44 +00009809 // checking compatibility, if calling app's target SDK is T and beyond.
9810 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9811 Binder.getCallingUid())) {
9812 isIccIdAccessRestricted = true;
9813 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009814 final long identity = Binder.clearCallingIdentity();
9815 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009816 UiccController uiccController = UiccController.getInstance();
9817 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009818 if (hasReadPermission) {
9819 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009820 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009821
9822 // Remove private info if the caller doesn't have access
9823 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9824 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009825 //setting the value after compatibility check
9826 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009827 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9828 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009829 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009830 if (card == null) {
9831 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009832 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009833 continue;
9834 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009835 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9836 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009837 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009838 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009839 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009840 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9841 for (UiccPortInfo portInfo : portInfos) {
9842 UiccPort port = uiccController.getUiccPortForSlot(
9843 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9844 if (port == null) {
9845 // assume no access if port is null
9846 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9847 continue;
9848 }
9849 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9850 uiccPortInfos.add(portInfo);
9851 } else {
9852 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9853 }
9854 }
9855 filteredInfos.add(new UiccCardInfo(
9856 cardInfo.isEuicc(),
9857 cardInfo.getCardId(),
9858 null,
9859 cardInfo.getPhysicalSlotIndex(),
9860 cardInfo.isRemovable(),
9861 cardInfo.isMultipleEnabledProfilesSupported(),
9862 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009863 }
9864 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009865 } finally {
9866 Binder.restoreCallingIdentity(identity);
9867 }
9868 }
9869
sandeepjsb6c87872021-09-27 15:34:44 +00009870 /**
9871 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9872 * generally private and require carrier privileges to view.
9873 *
9874 * @hide
9875 */
9876 @NonNull
9877 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9878 List<UiccPortInfo> portinfo = new ArrayList<>();
9879 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9880 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9881 }
9882 return new UiccCardInfo(
9883 cardInfo.isEuicc(),
9884 cardInfo.getCardId(),
9885 null,
9886 cardInfo.getPhysicalSlotIndex(),
9887 cardInfo.isRemovable(),
9888 cardInfo.isMultipleEnabledProfilesSupported(),
9889 portinfo
9890 );
9891 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009892
sandeepjsb6c87872021-09-27 15:34:44 +00009893 /**
9894 * @hide
9895 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9896 * These values are generally private and require carrier privileges to view.
9897 */
9898 @NonNull
9899 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9900 return new UiccPortInfo(
9901 UiccPortInfo.ICCID_REDACTED,
9902 portInfo.getPortIndex(),
9903 portInfo.getLogicalSlotIndex(),
9904 portInfo.isActive()
9905 );
9906 }
9907 @Override
9908 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009909 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009910 mApp.getSystemService(AppOpsManager.class)
9911 .checkPackage(Binder.getCallingUid(), callingPackage);
9912
sandeepjsb6c87872021-09-27 15:34:44 +00009913 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009914
Aman Guptaf3c90b32022-03-17 04:54:16 +00009915 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9916 // we are reading iccId which is PII data.
9917 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009918
joonhunshin4ac60942023-11-15 15:23:39 +00009919 enforceTelephonyFeatureWithException(callingPackage,
9920 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo");
9921
sandeepjsb6c87872021-09-27 15:34:44 +00009922 // checking compatibility, if calling app's target SDK is T and beyond.
9923 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9924 Binder.getCallingUid())) {
9925 isLogicalSlotAccessRestricted = true;
9926 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009927 final long identity = Binder.clearCallingIdentity();
9928 try {
9929 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009930 if (slots == null || slots.length == 0) {
9931 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009932 return null;
9933 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009934 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9935 for (int i = 0; i < slots.length; i++) {
9936 UiccSlot slot = slots[i];
9937 if (slot == null) {
9938 continue;
9939 }
9940
Jordan Liu7be7e652019-05-06 18:55:02 +00009941 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009942 UiccCard card = slot.getUiccCard();
9943 if (card != null) {
9944 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009945 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009946 cardId = slot.getEid();
9947 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009948 // If cardId is null, use iccId of default port as cardId.
9949 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009950 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009951 }
9952
Jordan Liu857451f2019-05-09 16:35:35 -07009953 if (cardId != null) {
9954 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9955 // if cardId is an EID, it's all digits so this is fine
9956 cardId = IccUtils.stripTrailingFs(cardId);
9957 }
9958
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009959 int cardState = 0;
9960 switch (slot.getCardState()) {
9961 case CARDSTATE_ABSENT:
9962 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9963 break;
9964 case CARDSTATE_PRESENT:
9965 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9966 break;
9967 case CARDSTATE_ERROR:
9968 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9969 break;
9970 case CARDSTATE_RESTRICTED:
9971 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9972 break;
9973 default:
9974 break;
9975
9976 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009977 List<UiccPortInfo> portInfos = new ArrayList<>();
9978 int[] portIndexes = slot.getPortList();
9979 for (int portIdx : portIndexes) {
9980 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009981 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009982 portInfos.add(new UiccPortInfo(iccId, portIdx,
9983 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009984 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009985 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009986 slot.isEuicc(),
9987 cardId,
9988 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009989 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009990 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009991 //setting the value after compatibility check
9992 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009993 }
9994 return infos;
9995 } finally {
9996 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009997 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009998 }
9999
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010000 /* Returns null if doesn't have read permission or carrier privilege access. */
10001 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
10002 boolean hasReadPermission) {
10003 String iccId = slot.getIccId(portIndex);
10004 if (hasReadPermission) { // if has read permission
10005 return iccId;
10006 } else {
10007 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
10008 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
10009 // if no read permission, checking carrier privilege access
10010 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
10011 return iccId;
10012 }
10013 }
10014 }
10015 // No read permission or carrier privilege access.
10016 return UiccPortInfo.ICCID_REDACTED;
10017 }
10018
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010019 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010020 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010021 public boolean switchSlots(int[] physicalSlots) {
10022 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010023
joonhunshin4ac60942023-11-15 15:23:39 +000010024 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10025 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots");
10026
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010027 final long identity = Binder.clearCallingIdentity();
10028 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010029 List<UiccSlotMapping> slotMappings = new ArrayList<>();
10030 for (int i = 0; i < physicalSlots.length; i++) {
10031 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
10032 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
10033 physicalSlots[i], i));
10034 }
10035 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010036 } finally {
10037 Binder.restoreCallingIdentity(identity);
10038 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010039 }
Jack Yu4c988042018-02-27 15:30:01 -080010040
10041 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010042 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
10043 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
10044 enforceModifyPermission();
10045
joonhunshin4ac60942023-11-15 15:23:39 +000010046 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10047 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping");
10048
sandeepjsb6c87872021-09-27 15:34:44 +000010049 final long identity = Binder.clearCallingIdentity();
10050 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010051 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +000010052 } finally {
10053 Binder.restoreCallingIdentity(identity);
10054 }
10055 }
10056
10057 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -080010058 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
joonhunshin4ac60942023-11-15 15:23:39 +000010059 enforceTelephonyFeatureWithException(callingPackage,
10060 PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc");
10061
Jordan Liu7de49fa2018-12-06 14:48:49 -080010062 final long identity = Binder.clearCallingIdentity();
10063 try {
10064 return UiccController.getInstance().getCardIdForDefaultEuicc();
10065 } finally {
10066 Binder.restoreCallingIdentity(identity);
10067 }
10068 }
10069
Pengquan Meng85728fb2018-03-12 16:31:21 -070010070 /**
goneil47ffb6e2018-04-06 15:40:58 -070010071 * A test API to reload the UICC profile.
10072 *
10073 * <p>Requires that the calling app has permission
10074 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
10075 * @hide
10076 */
10077 @Override
10078 public void refreshUiccProfile(int subId) {
10079 enforceModifyPermission();
10080
10081 final long identity = Binder.clearCallingIdentity();
10082 try {
10083 Phone phone = getPhone(subId);
10084 if (phone == null) {
10085 return;
10086 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010087 UiccPort uiccPort = phone.getUiccPort();
10088 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -070010089 return;
10090 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010091 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -070010092 if (uiccProfile == null) {
10093 return;
10094 }
10095 uiccProfile.refresh();
10096 } finally {
10097 Binder.restoreCallingIdentity(identity);
10098 }
10099 }
10100
10101 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010102 * Returns false if the mobile data is disabled by default, otherwise return true.
10103 */
10104 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010105 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010106 }
10107
10108 /**
10109 * Returns true if the data roaming is enabled by default, i.e the system property
10110 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
10111 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
10112 */
10113 private boolean getDefaultDataRoamingEnabled(int subId) {
10114 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010115 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -070010116 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010117 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
10118 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
10119 return isDataRoamingEnabled;
10120 }
10121
10122 /**
10123 * Returns the default network type for the given {@code subId}, if the default network type is
10124 * not set, return {@link Phone#PREFERRED_NT_MODE}.
10125 */
10126 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010127 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -080010128 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +090010129 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
10130 return list.get(phoneId);
10131 }
10132 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -070010133 }
fionaxua13278b2018-03-21 00:08:13 -070010134
10135 @Override
10136 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -070010137 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -070010138 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010139
10140 final long identity = Binder.clearCallingIdentity();
10141 try {
10142 final Phone phone = getPhone(subId);
10143 if (phone == null) {
10144 loge("setCarrierTestOverride fails with invalid subId: " + subId);
10145 return;
10146 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -080010147 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10148 if (cpt != null) {
10149 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
10150 }
10151 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -070010152 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
10153 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -070010154 if (carrierPrivilegeRules == null) {
10155 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
10156 } else {
10157 mCarrierPrivilegeTestOverrideSubIds.add(subId);
10158 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010159 } finally {
10160 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010161 }
fionaxua13278b2018-03-21 00:08:13 -070010162 }
10163
10164 @Override
Benedict Wong66477622023-02-03 23:30:57 +000010165 public void setCarrierServicePackageOverride(
10166 int subId, String carrierServicePackage, String callingPackage) {
10167 TelephonyPermissions.enforceShellOnly(
10168 Binder.getCallingUid(), "setCarrierServicePackageOverride");
10169
Benedict Wong66477622023-02-03 23:30:57 +000010170 final long identity = Binder.clearCallingIdentity();
10171 try {
10172 final Phone phone = getPhone(subId);
10173 if (phone == null || phone.getSubId() != subId) {
10174 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
10175 throw new IllegalArgumentException("No phone for subid");
10176 }
10177 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10178 if (cpt == null) {
10179 loge("setCarrierServicePackageOverride failed with no CPT for phone");
10180 throw new IllegalStateException("No CPT for phone");
10181 }
10182 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
10183 } finally {
10184 Binder.restoreCallingIdentity(identity);
10185 }
10186 }
10187
10188 @Override
fionaxua13278b2018-03-21 00:08:13 -070010189 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -070010190 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010191
10192 final long identity = Binder.clearCallingIdentity();
10193 try {
10194 final Phone phone = getPhone(subId);
10195 if (phone == null) {
10196 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
10197 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
10198 }
10199 return phone.getCarrierIdListVersion();
10200 } finally {
10201 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010202 }
fionaxua13278b2018-03-21 00:08:13 -070010203 }
Malcolm Chen2c63d402018-08-14 16:00:53 -070010204
10205 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010206 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
10207 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010208 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010209 mApp, subId, callingPackage, callingFeatureId,
10210 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010211 return -1;
10212 }
10213
10214 final long identity = Binder.clearCallingIdentity();
10215 try {
10216 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10217 } finally {
10218 Binder.restoreCallingIdentity(identity);
10219 }
10220 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010221
10222 @Override
10223 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +080010224 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010225 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010226 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010227
joonhunshin4ac60942023-11-15 15:23:39 +000010228 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10229 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode");
10230
Pengquan Menga1bb6272018-09-06 09:59:22 -070010231 final long identity = Binder.clearCallingIdentity();
10232 try {
10233 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10234 } finally {
10235 Binder.restoreCallingIdentity(identity);
10236 }
10237 }
10238
10239 @Override
10240 public boolean setCdmaRoamingMode(int subId, int mode) {
10241 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10242 mApp, subId, "setCdmaRoamingMode");
10243
joonhunshin4ac60942023-11-15 15:23:39 +000010244 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10245 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode");
10246
Pengquan Menga1bb6272018-09-06 09:59:22 -070010247 final long identity = Binder.clearCallingIdentity();
10248 try {
10249 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10250 } finally {
10251 Binder.restoreCallingIdentity(identity);
10252 }
10253 }
10254
10255 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010256 public int getCdmaSubscriptionMode(int subId) {
10257 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010258 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010259 mApp, subId, "getCdmaSubscriptionMode");
10260
joonhunshin4ac60942023-11-15 15:23:39 +000010261 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10262 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode");
10263
Sarah Chinbaab1432020-10-28 13:46:24 -070010264 final long identity = Binder.clearCallingIdentity();
10265 try {
10266 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10267 } finally {
10268 Binder.restoreCallingIdentity(identity);
10269 }
10270 }
10271
10272 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010273 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10274 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10275 mApp, subId, "setCdmaSubscriptionMode");
10276
joonhunshin4ac60942023-11-15 15:23:39 +000010277 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10278 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode");
10279
Pengquan Menga1bb6272018-09-06 09:59:22 -070010280 final long identity = Binder.clearCallingIdentity();
10281 try {
10282 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10283 } finally {
10284 Binder.restoreCallingIdentity(identity);
10285 }
10286 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010287
sqianc5eccab2018-10-19 18:46:41 -070010288 @Override
sqian8c685422019-02-22 15:55:18 -080010289 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010290 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010291 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010292 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10293 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010294 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10295 }
joonhunshin4ac60942023-11-15 15:23:39 +000010296
10297 enforceTelephonyFeatureWithException(callingPackage,
10298 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList");
10299
sqian11b7a0e2018-12-05 18:48:28 -080010300 final long identity = Binder.clearCallingIdentity();
10301 try {
sqian854d44b2018-12-12 16:48:18 -080010302 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10303 for (Phone phone: PhoneFactory.getPhones()) {
10304 if (phone.getEmergencyNumberTracker() != null
10305 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10306 emergencyNumberListInternal.put(
10307 phone.getSubId(),
10308 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10309 }
sqian11b7a0e2018-12-05 18:48:28 -080010310 }
sqian854d44b2018-12-12 16:48:18 -080010311 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010312 } finally {
10313 Binder.restoreCallingIdentity(identity);
10314 }
sqianc5eccab2018-10-19 18:46:41 -070010315 }
10316
10317 @Override
sqian8c685422019-02-22 15:55:18 -080010318 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010319 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010320 if (!exactMatch) {
10321 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010322 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010323 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010324 }
joonhunshin4ac60942023-11-15 15:23:39 +000010325
10326 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10327 PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber");
10328
sqian11b7a0e2018-12-05 18:48:28 -080010329 final long identity = Binder.clearCallingIdentity();
10330 try {
sqian854d44b2018-12-12 16:48:18 -080010331 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010332 //Note: we ignore passed in param exactMatch. We can remove it once
10333 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010334 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010335 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010336 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010337 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010338 }
sqian11b7a0e2018-12-05 18:48:28 -080010339 }
10340 return false;
10341 } finally {
10342 Binder.restoreCallingIdentity(identity);
10343 }
10344 }
10345
sqianf4ca7ed2019-01-15 18:32:07 -080010346 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010347 * Start emergency callback mode for GsmCdmaPhone for testing.
10348 */
10349 @Override
10350 public void startEmergencyCallbackMode() {
10351 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10352 "startEmergencyCallbackMode");
10353 enforceModifyPermission();
10354 final long identity = Binder.clearCallingIdentity();
10355 try {
10356 for (Phone phone : PhoneFactory.getPhones()) {
10357 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10358 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10359 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10360 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10361 gsmCdmaPhone.obtainMessage(
10362 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10363 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10364 }
10365 }
10366 } finally {
10367 Binder.restoreCallingIdentity(identity);
10368 }
10369 }
10370
10371 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010372 * Update emergency number list for test mode.
10373 */
10374 @Override
10375 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10376 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10377 "updateEmergencyNumberListTestMode");
10378
10379 final long identity = Binder.clearCallingIdentity();
10380 try {
10381 for (Phone phone: PhoneFactory.getPhones()) {
10382 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10383 if (tracker != null) {
10384 tracker.executeEmergencyNumberTestModeCommand(action, num);
10385 }
10386 }
10387 } finally {
10388 Binder.restoreCallingIdentity(identity);
10389 }
10390 }
10391
10392 /**
10393 * Get the full emergency number list for test mode.
10394 */
10395 @Override
10396 public List<String> getEmergencyNumberListTestMode() {
10397 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10398 "getEmergencyNumberListTestMode");
10399
10400 final long identity = Binder.clearCallingIdentity();
10401 try {
10402 Set<String> emergencyNumbers = new HashSet<>();
10403 for (Phone phone: PhoneFactory.getPhones()) {
10404 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10405 if (tracker != null) {
10406 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10407 emergencyNumbers.add(num.getNumber());
10408 }
10409 }
10410 }
10411 return new ArrayList<>(emergencyNumbers);
10412 } finally {
10413 Binder.restoreCallingIdentity(identity);
10414 }
10415 }
10416
chen xud6b45bd2018-10-30 22:27:10 -070010417 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010418 public int getEmergencyNumberDbVersion(int subId) {
10419 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10420
joonhunshin4ac60942023-11-15 15:23:39 +000010421 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10422 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion");
10423
Shuo Qian3b6ee772019-11-13 17:43:31 -080010424 final long identity = Binder.clearCallingIdentity();
10425 try {
10426 final Phone phone = getPhone(subId);
10427 if (phone == null) {
10428 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10429 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10430 }
10431 return phone.getEmergencyNumberDbVersion();
10432 } finally {
10433 Binder.restoreCallingIdentity(identity);
10434 }
10435 }
10436
10437 @Override
10438 public void notifyOtaEmergencyNumberDbInstalled() {
10439 enforceModifyPermission();
10440
joonhunshin4ac60942023-11-15 15:23:39 +000010441 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10442 PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled");
10443
Shuo Qian3b6ee772019-11-13 17:43:31 -080010444 final long identity = Binder.clearCallingIdentity();
10445 try {
10446 for (Phone phone: PhoneFactory.getPhones()) {
10447 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10448 if (tracker != null) {
10449 tracker.updateOtaEmergencyNumberDatabase();
10450 }
10451 }
10452 } finally {
10453 Binder.restoreCallingIdentity(identity);
10454 }
10455 }
10456
10457 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010458 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010459 enforceActiveEmergencySessionPermission();
10460
joonhunshin4ac60942023-11-15 15:23:39 +000010461 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10462 PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath");
10463
Shuo Qian3b6ee772019-11-13 17:43:31 -080010464 final long identity = Binder.clearCallingIdentity();
10465 try {
10466 for (Phone phone: PhoneFactory.getPhones()) {
10467 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10468 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010469 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10470 }
10471 }
10472 } finally {
10473 Binder.restoreCallingIdentity(identity);
10474 }
10475 }
10476
10477 @Override
10478 public void resetOtaEmergencyNumberDbFilePath() {
10479 enforceActiveEmergencySessionPermission();
10480
joonhunshin4ac60942023-11-15 15:23:39 +000010481 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10482 PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath");
10483
Shuo Qianc373f112020-03-05 17:55:34 -080010484 final long identity = Binder.clearCallingIdentity();
10485 try {
10486 for (Phone phone: PhoneFactory.getPhones()) {
10487 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10488 if (tracker != null) {
10489 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010490 }
10491 }
10492 } finally {
10493 Binder.restoreCallingIdentity(identity);
10494 }
10495 }
10496
10497 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010498 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10499 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10500 Phone phone = getPhone(subId);
10501 if (phone == null) {
10502 return null;
10503 }
10504 final long identity = Binder.clearCallingIdentity();
10505 try {
10506 UiccProfile profile = UiccController.getInstance()
10507 .getUiccProfileForPhone(phone.getPhoneId());
10508 if (profile != null) {
10509 return profile.getCertsFromCarrierPrivilegeAccessRules();
10510 }
10511 } finally {
10512 Binder.restoreCallingIdentity(identity);
10513 }
10514 return null;
10515 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010516
10517 /**
10518 * Enable or disable a modem stack.
10519 */
10520 @Override
10521 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10522 enforceModifyPermission();
10523
joonhunshin4ac60942023-11-15 15:23:39 +000010524 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10525 PackageManager.FEATURE_TELEPHONY, "enableModemForSlot");
10526
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010527 final long identity = Binder.clearCallingIdentity();
10528 try {
10529 Phone phone = PhoneFactory.getPhone(slotIndex);
10530 if (phone == null) {
10531 return false;
10532 } else {
10533 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10534 }
10535 } finally {
10536 Binder.restoreCallingIdentity(identity);
10537 }
10538 }
Michelecea4cf22018-12-21 15:00:11 -080010539
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010540 /**
10541 * Whether a modem stack is enabled or not.
10542 */
10543 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010544 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10545 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010546 Phone phone = PhoneFactory.getPhone(slotIndex);
10547 if (phone == null) return false;
10548
10549 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010550 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10551 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010552 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10553 }
10554
joonhunshin4ac60942023-11-15 15:23:39 +000010555 enforceTelephonyFeatureWithException(callingPackage,
10556 PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot");
10557
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010558 final long identity = Binder.clearCallingIdentity();
10559 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010560 try {
10561 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10562 } catch (NoSuchElementException ex) {
10563 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10564 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010565 } finally {
10566 Binder.restoreCallingIdentity(identity);
10567 }
10568 }
10569
Michelecea4cf22018-12-21 15:00:11 -080010570 @Override
Michele0ea7d782019-03-19 14:58:42 -070010571 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010572 enforceModifyPermission();
10573
joonhunshin4ac60942023-11-15 15:23:39 +000010574 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10575 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction");
10576
Michelecea4cf22018-12-21 15:00:11 -080010577 final long identity = Binder.clearCallingIdentity();
10578 try {
10579 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010580 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010581 .commit();
10582 } finally {
10583 Binder.restoreCallingIdentity(identity);
10584 }
10585 }
10586
10587 @Override
Michele0ea7d782019-03-19 14:58:42 -070010588 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010589 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010590 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010591 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10592 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010593 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010594 }
Michelecea4cf22018-12-21 15:00:11 -080010595
joonhunshin4ac60942023-11-15 15:23:39 +000010596 enforceTelephonyFeatureWithException(callingPackage,
10597 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported");
10598
Michelecea4cf22018-12-21 15:00:11 -080010599 final long identity = Binder.clearCallingIdentity();
10600 try {
Michele0ea7d782019-03-19 14:58:42 -070010601 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010602 } finally {
10603 Binder.restoreCallingIdentity(identity);
10604 }
10605 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010606
Michele0ea7d782019-03-19 14:58:42 -070010607 @TelephonyManager.IsMultiSimSupportedResult
10608 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010609 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10610 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10611 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010612 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10613 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010614 }
10615 // Check if the hardware supports multisim functionality. If usage of multisim is not
10616 // supported by the modem, indicate that it is restricted.
10617 PhoneCapability staticCapability =
10618 mPhoneConfigurationManager.getStaticPhoneCapability();
10619 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010620 loge("isMultiSimSupportedInternal: no static configuration available");
10621 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010622 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010623 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010624 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10625 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010626 }
10627 // Check if support of multiple SIMs is restricted by carrier
10628 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010629 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010630 }
10631
Michele0ea7d782019-03-19 14:58:42 -070010632 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010633 }
10634
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010635 /**
10636 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010637 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10638 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10639 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010640 * @param numOfSims number of active sims we want to switch to
10641 */
10642 @Override
10643 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010644 if (numOfSims == 1) {
10645 enforceModifyPermission();
10646 } else {
10647 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10648 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10649 }
joonhunshin4ac60942023-11-15 15:23:39 +000010650
10651 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10652 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig");
10653
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010654 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010655
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010656 try {
Michele30b57b22019-03-01 12:01:14 -080010657 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010658 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010659 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10660 return;
10661 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010662 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10663 } finally {
10664 Binder.restoreCallingIdentity(identity);
10665 }
10666 }
10667
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010668 @Override
10669 public boolean isApplicationOnUicc(int subId, int appType) {
10670 enforceReadPrivilegedPermission("isApplicationOnUicc");
joonhunshin4ac60942023-11-15 15:23:39 +000010671
10672 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10673 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc");
10674
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010675 Phone phone = getPhone(subId);
10676 if (phone == null) {
10677 return false;
10678 }
10679 final long identity = Binder.clearCallingIdentity();
10680 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010681 UiccPort uiccPort = phone.getUiccPort();
10682 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010683 return false;
10684 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010685 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010686 if (uiccProfile == null) {
10687 return false;
10688 }
10689 if (TelephonyManager.APPTYPE_SIM <= appType
10690 && appType <= TelephonyManager.APPTYPE_ISIM) {
10691 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10692 }
10693 return false;
10694 } finally {
10695 Binder.restoreCallingIdentity(identity);
10696 }
10697 }
10698
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010699 /**
chen xub4baa772019-04-03 10:23:41 -070010700 * Get whether making changes to modem configurations will trigger reboot.
10701 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010702 */
10703 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010704 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10705 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010706 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010707 mApp, subId, callingPackage, callingFeatureId,
10708 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010709 return false;
10710 }
joonhunshin4ac60942023-11-15 15:23:39 +000010711
10712 enforceTelephonyFeatureWithException(callingPackage,
10713 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
10714 "doesSwitchMultiSimConfigTriggerReboot");
10715
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010716 final long identity = Binder.clearCallingIdentity();
10717 try {
10718 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10719 } finally {
10720 Binder.restoreCallingIdentity(identity);
10721 }
10722 }
10723
Nathan Harold29f5f052019-02-15 13:41:57 -080010724 private void updateModemStateMetrics() {
10725 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10726 // TODO: check the state for each modem if the api is ready.
10727 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10728 }
10729
Pengquan Meng3889a572019-01-23 11:16:29 -080010730 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010731 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010732 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010733 // Verify that the callingPackage belongs to the calling UID
10734 mApp.getSystemService(AppOpsManager.class)
10735 .checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000010736
10737 enforceTelephonyFeatureWithException(callingPackage,
10738 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping");
10739
Pengquan Meng3889a572019-01-23 11:16:29 -080010740 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010741 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010742 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010743 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10744 if (slotInfos != null) {
10745 for (int i = 0; i < slotInfos.length; i++) {
10746 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10747 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10748 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10749 portInfo.getLogicalSlotIndex()));
10750 }
10751 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010752 }
10753 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010754 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010755 } finally {
10756 Binder.restoreCallingIdentity(identity);
10757 }
10758 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010759
10760 /**
10761 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010762 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010763 */
jimsunf9ec1622022-09-13 21:18:43 +080010764 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010765 @Override
10766 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010767 return getHalVersion(HAL_SERVICE_RADIO);
10768 }
10769
10770 /**
10771 * Get the HAL Version of a specific service
10772 */
10773 @Override
10774 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010775 Phone phone = getDefaultPhone();
10776 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010777 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010778 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10779 return hv.major * 100 + hv.minor;
10780 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010781
10782 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010783 * Get the current calling package name.
sangyun097dcf72024-01-04 10:35:49 +090010784 *
10785 * @return the current calling package name, or null if there is no known package.
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010786 */
10787 @Override
sangyun097dcf72024-01-04 10:35:49 +090010788 public @Nullable String getCurrentPackageName() {
10789 PackageManager pm = mApp.getPackageManager();
10790 String[] packageNames = pm == null ? null : pm.getPackagesForUid(Binder.getCallingUid());
10791 return packageNames == null ? null : packageNames[0];
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010792 }
10793
10794 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010795 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10796 * corresponding network requests on a subId.
10797 *
10798 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010799 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010800 * 2) APN is un-metered for this subscription, or
10801 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010802 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010803 *
10804 * @return whether data is allowed for a apn type.
10805 *
10806 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010807 */
10808 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010809 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010810 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10811 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010812
joonhunshin4ac60942023-11-15 15:23:39 +000010813 enforceTelephonyFeatureWithException(callingPackage,
10814 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn");
10815
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010816 // Now that all security checks passes, perform the operation as ourselves.
10817 final long identity = Binder.clearCallingIdentity();
10818 try {
10819 Phone phone = getPhone(subId);
10820 if (phone == null) return false;
10821
Jack Yu27422a52022-03-21 10:38:05 -070010822 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010823 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010824 isMetered = phone.getDataNetworkController().getDataConfigManager()
10825 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10826 phone.getServiceState().getDataRoaming());
10827 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010828 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010829 } finally {
10830 Binder.restoreCallingIdentity(identity);
10831 }
10832 }
10833
10834 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010835 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010836 enforceReadPrivilegedPermission("isApnMetered");
10837
joonhunshin4ac60942023-11-15 15:23:39 +000010838 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10839 PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered");
10840
Malcolm Chene5ad5792019-04-18 13:51:02 -070010841 // Now that all security checks passes, perform the operation as ourselves.
10842 final long identity = Binder.clearCallingIdentity();
10843 try {
10844 Phone phone = getPhone(subId);
10845 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010846 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10847 DataUtils.apnTypeToNetworkCapability(apnType),
10848 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010849 } finally {
10850 Binder.restoreCallingIdentity(identity);
10851 }
10852 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010853
10854 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010855 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10856 int subscriptionId, IBooleanConsumer resultCallback) {
10857 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +000010858
10859 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10860 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels");
10861
Hall Liu73f5d362020-01-20 13:42:00 -080010862 long token = Binder.clearCallingIdentity();
10863 try {
10864 Phone phone = getPhone(subscriptionId);
10865 if (phone == null) {
10866 try {
10867 if (resultCallback != null) {
10868 resultCallback.accept(false);
10869 }
10870 } catch (RemoteException e) {
10871 // ignore
10872 }
10873 return;
10874 }
10875 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10876 Pair.create(specifiers, (x) -> {
10877 try {
10878 if (resultCallback != null) {
10879 resultCallback.accept(x);
10880 }
10881 } catch (RemoteException e) {
10882 // ignore
10883 }
10884 });
10885 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10886 } finally {
10887 Binder.restoreCallingIdentity(token);
10888 }
10889 }
10890
10891 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010892 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10893 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010894 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010895 mApp, subId, "getSystemSelectionChannels");
joonhunshin4ac60942023-11-15 15:23:39 +000010896
10897 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10898 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels");
10899
Sarah Chin679c08a2020-11-18 13:39:35 -080010900 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10901 final long identity = Binder.clearCallingIdentity();
10902 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010903 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10904 if (result instanceof IllegalStateException) {
10905 throw (IllegalStateException) result;
10906 }
10907 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010908 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10909 return specifiers;
10910 } finally {
10911 Binder.restoreCallingIdentity(identity);
10912 }
10913 }
10914
10915 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010916 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010917 enforceReadPrivilegedPermission("isMvnoMatched");
joonhunshin4ac60942023-11-15 15:23:39 +000010918
10919 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10920 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched");
10921
Jack Yu8b766fc2022-03-21 09:42:33 -070010922 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010923 }
10924
10925 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010926 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10927 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010928 if (callingPackage == null) {
10929 callingPackage = getCurrentPackageName();
10930 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010931 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10932 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010933 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10934 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010935 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10936 }
10937 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10938 Intent intent = new Intent();
10939 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10940 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10941 // Bring up choose default SMS subscription dialog right now
10942 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10943 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10944 mApp.startActivity(intent);
10945 }
chen xud5ca2d52019-05-28 15:20:57 -070010946
10947 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010948 public void showSwitchToManagedProfileDialog() {
10949 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000010950 try {
10951 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
10952 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
10953 // for work telephony.
10954 Intent intent = new Intent(Intent.ACTION_SENDTO);
10955 intent.setData(Uri.parse("smsto:"));
10956 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10957 mApp.startActivity(intent);
10958 } catch (ActivityNotFoundException e) {
10959 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
10960 Intent intent = new Intent();
10961 intent.setClass(mApp, ErrorDialogActivity.class);
10962 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10963 mApp.startActivity(intent);
10964 }
Ayush Sharma787854b2022-12-12 14:55:02 +000010965 }
10966
10967 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010968 public String getMmsUAProfUrl(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000010969 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10970 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl");
10971
chen xud5ca2d52019-05-28 15:20:57 -070010972 //TODO investigate if this API should require proper permission check in R b/133791609
10973 final long identity = Binder.clearCallingIdentity();
10974 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010975 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10976 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10977 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10978 return carrierUAProfUrl;
10979 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010980 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10981 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010982 } finally {
10983 Binder.restoreCallingIdentity(identity);
10984 }
10985 }
10986
10987 @Override
10988 public String getMmsUserAgent(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000010989 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10990 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent");
10991
chen xud5ca2d52019-05-28 15:20:57 -070010992 //TODO investigate if this API should require proper permission check in R b/133791609
10993 final long identity = Binder.clearCallingIdentity();
10994 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010995 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10996 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10997 if (!TextUtils.isEmpty(carrierUserAgent)) {
10998 return carrierUserAgent;
10999 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011000 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11001 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070011002 } finally {
11003 Binder.restoreCallingIdentity(identity);
11004 }
11005 }
Jack Yub07d4972019-05-28 16:12:25 -070011006
11007 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070011008 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
11009 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070011010
joonhunshin4ac60942023-11-15 15:23:39 +000011011 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11012 PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled");
11013
Jack Yub07d4972019-05-28 16:12:25 -070011014 final long identity = Binder.clearCallingIdentity();
11015 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011016 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070011017 if (phone == null) return false;
11018
Ling Maf188d502022-09-16 15:22:36 -070011019 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070011020 } finally {
11021 Binder.restoreCallingIdentity(identity);
11022 }
11023 }
11024
11025 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080011026 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070011027 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080011028 enforceModifyPermission();
11029
joonhunshin4ac60942023-11-15 15:23:39 +000011030 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11031 PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled");
11032
changbettyd5c246e2019-12-24 15:40:37 +080011033 final long identity = Binder.clearCallingIdentity();
11034 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011035 Phone phone = getPhone(subscriptionId);
11036 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080011037
Ling Maf188d502022-09-16 15:22:36 -070011038 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080011039 } finally {
11040 Binder.restoreCallingIdentity(identity);
11041 }
11042 }
11043
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011044 /**
Hall Liu746e03c2020-09-25 11:13:49 -070011045 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011046 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
11047 * otherwise.
11048 */
11049 @Override
11050 public void setCepEnabled(boolean isCepEnabled) {
11051 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
11052
11053 final long identity = Binder.clearCallingIdentity();
11054 try {
11055 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
11056 for (Phone phone : PhoneFactory.getPhones()) {
11057 Phone defaultPhone = phone.getImsPhone();
11058 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
11059 ImsPhone imsPhone = (ImsPhone) defaultPhone;
11060 ImsPhoneCallTracker imsPhoneCallTracker =
11061 (ImsPhoneCallTracker) imsPhone.getCallTracker();
11062 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
11063 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
11064 + imsPhone.getMsisdn());
11065 }
11066 }
11067 } finally {
11068 Binder.restoreCallingIdentity(identity);
11069 }
11070 }
allenwtsu46dcc572020-01-08 18:24:03 +080011071
11072 /**
11073 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
11074 *
11075 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
11076 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
11077 * before being read.
11078 */
11079 @Override
11080 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
11081 isCompressed) {
11082 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11083 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011084 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11085 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11086 }
joonhunshin4ac60942023-11-15 15:23:39 +000011087
11088 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11089 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11090 Binder.getCallingUserHandle())) {
11091 if (!isImsAvailableOnDevice()) {
11092 // ProvisioningManager can not handle ServiceSpecificException.
11093 // Throw the IllegalStateException and annotate ProvisioningManager.
11094 throw new IllegalStateException("IMS not available on device.");
11095 }
11096 } else {
11097 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11098 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11099 "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011100 }
11101
11102 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080011103 try {
Hui Wang761a6682020-10-31 05:12:53 +000011104 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
11105 } finally {
11106 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080011107 }
11108 }
zoey chene02881a2019-12-30 16:11:23 +080011109
11110 @Override
11111 public boolean isIccLockEnabled(int subId) {
11112 enforceReadPrivilegedPermission("isIccLockEnabled");
11113
joonhunshin4ac60942023-11-15 15:23:39 +000011114 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11115 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled");
11116
zoey chene02881a2019-12-30 16:11:23 +080011117 // Now that all security checks passes, perform the operation as ourselves.
11118 final long identity = Binder.clearCallingIdentity();
11119 try {
11120 Phone phone = getPhone(subId);
11121 if (phone != null && phone.getIccCard() != null) {
11122 return phone.getIccCard().getIccLockEnabled();
11123 } else {
11124 return false;
11125 }
11126 } finally {
11127 Binder.restoreCallingIdentity(identity);
11128 }
11129 }
11130
11131 /**
11132 * Set the ICC pin lock enabled or disabled.
11133 *
11134 * @return an integer representing the status of IccLock enabled or disabled in the following
11135 * three cases:
11136 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
11137 * successfully.
11138 * - Positive number and zero for remaining password attempts.
11139 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11140 *
11141 */
11142 @Override
11143 public int setIccLockEnabled(int subId, boolean enabled, String password) {
11144 enforceModifyPermission();
11145
joonhunshin4ac60942023-11-15 15:23:39 +000011146 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11147 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled");
11148
zoey chene02881a2019-12-30 16:11:23 +080011149 Phone phone = getPhone(subId);
11150 if (phone == null) {
11151 return 0;
11152 }
11153 // Now that all security checks passes, perform the operation as ourselves.
11154 final long identity = Binder.clearCallingIdentity();
11155 try {
11156 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
11157 new Pair<Boolean, String>(enabled, password), phone, null);
11158 return attemptsRemaining;
11159
11160 } catch (Exception e) {
11161 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
11162 } finally {
11163 Binder.restoreCallingIdentity(identity);
11164 }
11165 return 0;
11166 }
11167
11168 /**
11169 * Change the ICC password used in ICC pin lock.
11170 *
11171 * @return an integer representing the status of IccLock changed in the following three cases:
11172 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
11173 * - Positive number and zero for remaining password attempts.
11174 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11175 *
11176 */
11177 @Override
11178 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
11179 enforceModifyPermission();
11180
joonhunshin4ac60942023-11-15 15:23:39 +000011181 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11182 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword");
11183
zoey chene02881a2019-12-30 16:11:23 +080011184 Phone phone = getPhone(subId);
11185 if (phone == null) {
11186 return 0;
11187 }
11188 // Now that all security checks passes, perform the operation as ourselves.
11189 final long identity = Binder.clearCallingIdentity();
11190 try {
11191 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
11192 new Pair<String, String>(oldPassword, newPassword), phone, null);
11193 return attemptsRemaining;
11194
11195 } catch (Exception e) {
11196 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
11197 } finally {
11198 Binder.restoreCallingIdentity(identity);
11199 }
11200 return 0;
11201 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080011202
11203 /**
11204 * Request for receiving user activity notification
11205 */
11206 @Override
11207 public void requestUserActivityNotification() {
11208 if (!mNotifyUserActivity.get()
11209 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
11210 mNotifyUserActivity.set(true);
11211 }
11212 }
11213
11214 /**
11215 * Called when userActivity is signalled in the power manager.
11216 * This is safe to call from any thread, with any window manager locks held or not.
11217 */
11218 @Override
11219 public void userActivity() {
11220 // ***************************************
11221 // * Inherited from PhoneWindowManager *
11222 // ***************************************
11223 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
11224 // WITH ITS LOCKS HELD.
11225 //
11226 // This code must be VERY careful about the locks
11227 // it acquires.
11228 // In fact, the current code acquires way too many,
11229 // and probably has lurking deadlocks.
11230
11231 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
11232 throw new SecurityException("Only the OS may call notifyUserActivity()");
11233 }
11234
11235 if (mNotifyUserActivity.getAndSet(false)) {
11236 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
11237 USER_ACTIVITY_NOTIFICATION_DELAY);
11238 }
11239 }
Malcolm Chen4639c562020-04-13 11:59:40 -070011240
11241 @Override
11242 public boolean canConnectTo5GInDsdsMode() {
11243 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
11244 }
Jack Yud10cdd42020-09-28 20:28:01 -070011245
11246 @Override
11247 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
11248 String callingFeatureId) {
11249 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
11250 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
11251 throw new SecurityException("Requires READ_PHONE_STATE permission.");
11252 }
11253
joonhunshin4ac60942023-11-15 15:23:39 +000011254 enforceTelephonyFeatureWithException(callingPackage,
11255 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns");
11256
Jack Yud10cdd42020-09-28 20:28:01 -070011257 Phone phone = getPhone(subId);
11258 if (phone == null) {
11259 throw new RuntimeException("phone is not available");
11260 }
11261 // Now that all security checks passes, perform the operation as ourselves.
11262 final long identity = Binder.clearCallingIdentity();
11263 try {
11264 return phone.getEquivalentHomePlmns();
11265 } finally {
11266 Binder.restoreCallingIdentity(identity);
11267 }
11268 }
Daniel Bright59e67312020-11-13 11:49:37 -080011269
11270 @Override
11271 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011272 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
joonhunshin4ac60942023-11-15 15:23:39 +000011273 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11274 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
11275 "isRadioInterfaceCapabilitySupported");
11276
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011277 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080011278 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080011279 if (radioInterfaceCapabilities == null) {
11280 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080011281 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011282 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080011283 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011284
Hui Wang641e81c2020-10-12 12:14:23 -070011285 @Override
11286 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
11287 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000011288 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
11289 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11290 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
11291 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11292 Manifest.permission.MODIFY_PHONE_STATE);
joonhunshin4ac60942023-11-15 15:23:39 +000011293
11294 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11295 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest");
11296
Hui Wang641e81c2020-10-12 12:14:23 -070011297 if (DBG) {
11298 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
11299 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
11300 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
11301 }
11302
11303 if (!SubscriptionManager.isValidSubscriptionId(subId)
11304 || appType < TelephonyManager.APPTYPE_UNKNOWN
11305 || appType > TelephonyManager.APPTYPE_ISIM
11306 || nafUrl == null || securityProtocol == null || callback == null) {
11307 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
11308 if (callback != null) {
11309 try {
11310 callback.onAuthenticationFailure(
11311 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
11312 } catch (RemoteException exception) {
11313 log("Fail to notify onAuthenticationFailure due to " + exception);
11314 }
11315 return;
11316 }
11317 }
11318
11319 final long token = Binder.clearCallingIdentity();
11320 try {
11321 getGbaManager(subId).bootstrapAuthenticationRequest(
11322 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011323 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070011324 } finally {
11325 Binder.restoreCallingIdentity(token);
11326 }
11327 }
11328
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011329 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011330 * Attempts to set the radio power state for all phones for thermal reason.
11331 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011332 * requested radio power state will actually be set. See {@link
11333 * PhoneInternalInterface#setRadioPowerForReason} for more details.
11334 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011335 * @param enable {@code true} if trying to turn radio on.
11336 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
11337 * false}.
11338 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011339 private boolean setRadioPowerForThermal(boolean enable) {
11340 boolean isPhoneAvailable = false;
11341 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
11342 Phone phone = PhoneFactory.getPhone(i);
11343 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011344 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011345 isPhoneAvailable = true;
11346 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011347 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011348
11349 // return true if successfully informed the phone object about the thermal radio power
11350 // request.
11351 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011352 }
11353
11354 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011355 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011356 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11357 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11358 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11359 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11360 throw new IllegalArgumentException("modem does not support data throttling");
11361 }
11362
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011363 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11364 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011365 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011366 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11367 }
11368
Sarah Chinecc78c42022-03-31 21:16:48 -070011369 setDataEnabledForReason(
11370 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011371
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011372 if (isDataThrottlingSupported) {
11373 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011374 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011375 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11376 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11377 } else if (thermalMitigationResult
11378 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011379 log("Modem likely does not support data throttling on secondary carrier. Data " +
11380 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11381 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011382 }
11383 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011384 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011385
11386 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011387 }
11388
Jack Nudelman644b91a2021-03-12 14:09:48 -080011389 private static List<String> getThermalMitigationAllowlist(Context context) {
11390 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11391 for (String pckg : context.getResources()
11392 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11393 sThermalMitigationAllowlistedPackages.add(pckg);
11394 }
11395 }
11396
11397 return sThermalMitigationAllowlistedPackages;
11398 }
11399
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011400 private boolean isAnyPhoneInEmergencyState() {
11401 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11402 if (tm.isInEmergencyCall()) {
11403 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11404 return true;
11405 }
11406 for (Phone phone : PhoneFactory.getPhones()) {
11407 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11408 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011409 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11410 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011411 return true;
11412 }
11413 }
11414
11415 return false;
11416 }
11417
Jack Nudelman644b91a2021-03-12 14:09:48 -080011418 /**
11419 * Used by shell commands to add an authorized package name for thermal mitigation.
11420 * @param packageName name of package to be allowlisted
11421 * @param context
11422 */
11423 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11424 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11425 sThermalMitigationAllowlistedPackages.add(packageName);
11426 }
11427
11428 /**
11429 * Used by shell commands to remove an authorized package name for thermal mitigation.
11430 * @param packageName name of package to remove from allowlist
11431 * @param context
11432 */
11433 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11434 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11435 sThermalMitigationAllowlistedPackages.remove(packageName);
11436 }
11437
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011438 /**
11439 * Thermal mitigation request to control functionalities at modem.
11440 *
11441 * @param subId the id of the subscription.
11442 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011443 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011444 *
11445 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11446 */
11447 @Override
11448 @ThermalMitigationResult
11449 public int sendThermalMitigationRequest(
11450 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011451 ThermalMitigationRequest thermalMitigationRequest,
11452 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011453 enforceModifyPermission();
11454
Jack Nudelman644b91a2021-03-12 14:09:48 -080011455 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000011456
11457 enforceTelephonyFeatureWithException(callingPackage,
11458 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest");
11459
Jack Nudelman644b91a2021-03-12 14:09:48 -080011460 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11461 .contains(callingPackage)) {
11462 throw new SecurityException("Calling package must be configured in the device config. "
11463 + "calling package: " + callingPackage);
11464 }
11465
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011466 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11467 final long identity = Binder.clearCallingIdentity();
11468
11469 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11470 try {
11471 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11472 switch (thermalMitigationAction) {
11473 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11474 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011475 handleDataThrottlingRequest(subId,
11476 thermalMitigationRequest.getDataThrottlingRequest(),
11477 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011478 break;
11479 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11480 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11481 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11482 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11483 }
11484
11485 // Ensure that radio is on. If not able to power on due to phone being
11486 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011487 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011488 thermalMitigationResult =
11489 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11490 break;
11491 }
11492
11493 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011494 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011495 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11496 break;
11497 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11498 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11499 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11500 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11501 }
11502
11503 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11504 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011505 Phone phone = getPhone(subId);
11506 if (phone == null) {
11507 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011508 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011509 break;
11510 }
11511
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011512 TelephonyConnectionService service =
11513 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011514 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011515 Log.e(LOG_TAG, "An emergency call is pending");
11516 thermalMitigationResult =
11517 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11518 break;
11519 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011520 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011521 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011522 break;
11523 }
11524 } else {
11525 thermalMitigationResult =
11526 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11527 break;
11528 }
11529
11530 // Turn radio off. If not able to power off due to phone being unavailable,
11531 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011532 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011533 thermalMitigationResult =
11534 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11535 break;
11536 }
11537 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011538 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011539 break;
11540 default:
11541 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11542 + "not exist. Requested action: " + thermalMitigationAction);
11543 }
11544 } catch (IllegalArgumentException e) {
11545 throw e;
11546 } catch (Exception e) {
11547 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11548 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11549 } finally {
11550 Binder.restoreCallingIdentity(identity);
11551 }
11552
11553 if (DBG) {
11554 log("thermalMitigationRequest returning with thermalMitigationResult: "
11555 + thermalMitigationResult);
11556 }
11557
11558 return thermalMitigationResult;
11559 }
Hui Wang641e81c2020-10-12 12:14:23 -070011560
11561 /**
11562 * Set the GbaService Package Name that Telephony will bind to.
11563 *
11564 * @param subId The sim that the GbaService is associated with.
11565 * @param packageName The name of the package to be replaced with.
11566 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11567 */
11568 @Override
11569 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11570 enforceModifyPermission();
11571
11572 final long identity = Binder.clearCallingIdentity();
11573 try {
11574 return getGbaManager(subId).overrideServicePackage(packageName);
11575 } finally {
11576 Binder.restoreCallingIdentity(identity);
11577 }
11578 }
11579
11580 /**
11581 * Return the package name of the currently bound GbaService.
11582 *
11583 * @param subId The sim that the GbaService is associated with.
11584 * @return the package name of the GbaService configuration, null if GBA is not supported.
11585 */
11586 @Override
11587 public String getBoundGbaService(int subId) {
11588 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11589
11590 final long identity = Binder.clearCallingIdentity();
11591 try {
11592 return getGbaManager(subId).getServicePackage();
11593 } finally {
11594 Binder.restoreCallingIdentity(identity);
11595 }
11596 }
11597
11598 /**
11599 * Set the release time for telephony to unbind GbaService.
11600 *
11601 * @param subId The sim that the GbaService is associated with.
11602 * @param interval The release time to unbind GbaService by millisecond.
11603 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11604 */
11605 @Override
11606 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11607 enforceModifyPermission();
11608
11609 final long identity = Binder.clearCallingIdentity();
11610 try {
11611 return getGbaManager(subId).overrideReleaseTime(interval);
11612 } finally {
11613 Binder.restoreCallingIdentity(identity);
11614 }
11615 }
11616
11617 /**
11618 * Return the release time for telephony to unbind GbaService.
11619 *
11620 * @param subId The sim that the GbaService is associated with.
11621 * @return The release time to unbind GbaService by millisecond.
11622 */
11623 @Override
11624 public int getGbaReleaseTime(int subId) {
11625 enforceReadPrivilegedPermission("getGbaReleaseTime");
11626
11627 final long identity = Binder.clearCallingIdentity();
11628 try {
11629 return getGbaManager(subId).getReleaseTime();
11630 } finally {
11631 Binder.restoreCallingIdentity(identity);
11632 }
11633 }
11634
11635 private GbaManager getGbaManager(int subId) {
11636 GbaManager instance = GbaManager.getInstance(subId);
11637 if (instance == null) {
11638 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11639 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11640 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11641 }
11642 return instance;
11643 }
Hui Wang761a6682020-10-31 05:12:53 +000011644
11645 /**
11646 * indicate whether the device and the carrier can support
11647 * RCS VoLTE single registration.
11648 */
11649 @Override
11650 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011651 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11652 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11653 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11654 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011655
11656 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11657 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11658 }
11659
11660 final long identity = Binder.clearCallingIdentity();
11661 try {
11662 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11663 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011664 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11665 if (isCapable != null) {
11666 return isCapable;
11667 }
Hui Wang761a6682020-10-31 05:12:53 +000011668 }
Hui Wang67af90e2021-06-04 16:57:15 -070011669 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11670 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011671 } finally {
11672 Binder.restoreCallingIdentity(identity);
11673 }
11674 }
11675
11676 /**
11677 * Register RCS provisioning callback.
11678 */
11679 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011680 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011681 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011682 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011683 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011684 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11685 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011686
11687 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11688 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11689 }
joonhunshin4ac60942023-11-15 15:23:39 +000011690 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11691 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11692 Binder.getCallingUserHandle())) {
11693 if (!isImsAvailableOnDevice()) {
11694 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11695 "IMS not available on device.");
11696 }
11697 } else {
11698 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11699 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011700 }
11701
11702 final long identity = Binder.clearCallingIdentity();
11703 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011704 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011705 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011706 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11707 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011708 }
Hui Wang761a6682020-10-31 05:12:53 +000011709 } finally {
11710 Binder.restoreCallingIdentity(identity);
11711 }
11712 }
11713
11714 /**
11715 * Unregister RCS provisioning callback.
11716 */
11717 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011718 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011719 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011720 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011721 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011722 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11723 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011724
11725 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11726 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11727 }
joonhunshin4ac60942023-11-15 15:23:39 +000011728
11729 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11730 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11731 Binder.getCallingUserHandle())) {
11732 if (!isImsAvailableOnDevice()) {
11733 // operation failed silently
11734 Rlog.w(LOG_TAG, "IMS not available on device.");
11735 return;
11736 }
11737 } else {
11738 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11739 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11740 "unregisterRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011741 }
11742
11743 final long identity = Binder.clearCallingIdentity();
11744 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011745 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011746 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011747 } finally {
11748 Binder.restoreCallingIdentity(identity);
11749 }
11750 }
11751
11752 /**
11753 * trigger RCS reconfiguration.
11754 */
11755 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011756 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11757 "triggerRcsReconfiguration",
11758 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011759
11760 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11761 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11762 }
joonhunshin4ac60942023-11-15 15:23:39 +000011763 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11764 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11765 Binder.getCallingUserHandle())) {
11766 if (!isImsAvailableOnDevice()) {
11767 // ProvisioningManager can not handle ServiceSpecificException.
11768 // Throw the IllegalStateException and annotate ProvisioningManager.
11769 throw new IllegalStateException("IMS not available on device.");
11770 }
11771 } else {
11772 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11773 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011774 }
11775
11776 final long identity = Binder.clearCallingIdentity();
11777 try {
11778 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11779 } finally {
11780 Binder.restoreCallingIdentity(identity);
11781 }
11782 }
11783
11784 /**
11785 * Provide the client configuration parameters of the RCS application.
11786 */
11787 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011788 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11789 "setRcsClientConfiguration",
11790 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011791
11792 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11793 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11794 }
joonhunshin4ac60942023-11-15 15:23:39 +000011795 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11796 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11797 Binder.getCallingUserHandle())) {
11798 if (!isImsAvailableOnDevice()) {
11799 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11800 "IMS not available on device.");
11801 }
11802 } else {
11803 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11804 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011805 }
11806
11807 final long identity = Binder.clearCallingIdentity();
11808
11809 try {
11810 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11811 if (configBinder == null) {
11812 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011813 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11814 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011815 } else {
11816 configBinder.setRcsClientConfiguration(rcc);
11817 }
joonhunshin3e154242021-09-17 06:33:39 +000011818
11819 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11820 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011821 } catch (RemoteException e) {
11822 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011823 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11824 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011825 } finally {
11826 Binder.restoreCallingIdentity(identity);
11827 }
11828 }
11829
11830 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011831 * Enables or disables the test mode for RCS VoLTE single registration.
11832 */
11833 @Override
11834 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11835 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11836 "setRcsSingleRegistrationTestModeEnabled");
11837
11838 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11839 }
11840
11841 /**
11842 * Gets the test mode for RCS VoLTE single registration.
11843 */
11844 @Override
11845 public boolean getRcsSingleRegistrationTestModeEnabled() {
11846 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11847 "getRcsSingleRegistrationTestModeEnabled");
11848
11849 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11850 }
11851
11852 /**
Hui Wang761a6682020-10-31 05:12:53 +000011853 * Overrides the config of RCS VoLTE single registration enabled for the device.
11854 */
11855 @Override
11856 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11857 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11858 "setDeviceSingleRegistrationEnabledOverride");
11859 enforceModifyPermission();
11860
11861 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11862 : Boolean.parseBoolean(enabledStr);
11863 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011864 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011865 }
11866
11867 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011868 * Sends a device to device communication message. Only usable via shell.
11869 * @param message message to send.
11870 * @param value message value.
11871 */
11872 @Override
11873 public void sendDeviceToDeviceMessage(int message, int value) {
11874 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011875 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011876 enforceModifyPermission();
11877
11878 final long identity = Binder.clearCallingIdentity();
11879 try {
11880 TelephonyConnectionService service =
11881 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11882 if (service == null) {
11883 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11884 return;
11885 }
11886 service.sendTestDeviceToDeviceMessage(message, value);
11887 } finally {
11888 Binder.restoreCallingIdentity(identity);
11889 }
11890 }
11891
Tyler Gunnbabbda02021-02-10 11:05:02 -080011892 /**
11893 * Sets the specified device to device transport active.
11894 * @param transport The transport to set active.
11895 */
11896 @Override
11897 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11898 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11899 "setActiveDeviceToDeviceTransport");
11900 enforceModifyPermission();
11901
11902 final long identity = Binder.clearCallingIdentity();
11903 try {
11904 TelephonyConnectionService service =
11905 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11906 if (service == null) {
11907 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11908 return;
11909 }
11910 service.setActiveDeviceToDeviceTransport(transport);
11911 } finally {
11912 Binder.restoreCallingIdentity(identity);
11913 }
11914 }
Tyler Gunn92479152021-01-20 16:30:10 -080011915
Tyler Gunnd4339262021-05-03 14:46:49 -070011916 @Override
11917 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11918 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11919 "setDeviceToDeviceForceEnabled");
11920
11921 final long identity = Binder.clearCallingIdentity();
11922 try {
11923 Arrays.stream(PhoneFactory.getPhones()).forEach(
11924 p -> {
11925 Phone thePhone = p.getImsPhone();
11926 if (thePhone != null && thePhone instanceof ImsPhone) {
11927 ImsPhone imsPhone = (ImsPhone) thePhone;
11928 CallTracker tracker = imsPhone.getCallTracker();
11929 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11930 ImsPhoneCallTracker imsPhoneCallTracker =
11931 (ImsPhoneCallTracker) tracker;
11932 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11933 }
11934 }
11935 }
11936 );
11937 } finally {
11938 Binder.restoreCallingIdentity(identity);
11939 }
11940 }
11941
Tyler Gunn92479152021-01-20 16:30:10 -080011942 /**
Hui Wang761a6682020-10-31 05:12:53 +000011943 * Gets the config of RCS VoLTE single registration enabled for the device.
11944 */
11945 @Override
11946 public boolean getDeviceSingleRegistrationEnabled() {
11947 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11948 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11949 }
11950
11951 /**
11952 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11953 */
11954 @Override
11955 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11956 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11957 "setCarrierSingleRegistrationEnabledOverride");
11958 enforceModifyPermission();
11959
11960 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11961 : Boolean.parseBoolean(enabledStr);
11962 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11963 subId, enabled);
11964 }
11965
11966 /**
11967 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11968 */
11969 @Override
11970 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11971 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11972 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11973 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011974
11975 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011976 * Overrides the ims feature validation result
11977 */
11978 @Override
11979 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11980 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11981 "setImsFeatureValidationOverride");
11982
11983 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11984 : Boolean.parseBoolean(enabledStr);
11985 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11986 subId, enabled);
11987 }
11988
11989 /**
11990 * Gets the ims feature validation override value
11991 */
11992 @Override
11993 public boolean getImsFeatureValidationOverride(int subId) {
11994 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11995 "getImsFeatureValidationOverride");
11996 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11997 }
11998
11999 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080012000 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
12001 * their mobile plan.
12002 */
12003 @Override
12004 public String getMobileProvisioningUrl() {
12005 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
12006 final long identity = Binder.clearCallingIdentity();
12007 try {
12008 return getDefaultPhone().getMobileProvisioningUrl();
12009 } finally {
12010 Binder.restoreCallingIdentity(identity);
12011 }
12012 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012013
James.cf Linbcdf8b32021-01-14 16:44:13 +080012014 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080012015 * Get the EAB contact from the EAB database.
12016 */
12017 @Override
12018 public String getContactFromEab(String contact) {
12019 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
12020 enforceModifyPermission();
12021 final long identity = Binder.clearCallingIdentity();
12022 try {
12023 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
12024 } finally {
12025 Binder.restoreCallingIdentity(identity);
12026 }
12027 }
12028
12029 /**
Calvin Pana1434322021-07-01 19:27:01 +080012030 * Get the EAB capability from the EAB database.
12031 */
12032 @Override
12033 public String getCapabilityFromEab(String contact) {
12034 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
12035 enforceModifyPermission();
12036 final long identity = Binder.clearCallingIdentity();
12037 try {
12038 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
12039 } finally {
12040 Binder.restoreCallingIdentity(identity);
12041 }
12042 }
12043
12044 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080012045 * Remove the EAB contacts from the EAB database.
12046 */
12047 @Override
12048 public int removeContactFromEab(int subId, String contacts) {
12049 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
12050 enforceModifyPermission();
12051 final long identity = Binder.clearCallingIdentity();
12052 try {
12053 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
12054 } finally {
12055 Binder.restoreCallingIdentity(identity);
12056 }
12057 }
12058
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012059 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080012060 public boolean getDeviceUceEnabled() {
12061 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
12062 final long identity = Binder.clearCallingIdentity();
12063 try {
12064 return mApp.getDeviceUceEnabled();
12065 } finally {
12066 Binder.restoreCallingIdentity(identity);
12067 }
12068 }
12069
12070 @Override
12071 public void setDeviceUceEnabled(boolean isEnabled) {
12072 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
12073 final long identity = Binder.clearCallingIdentity();
12074 try {
12075 mApp.setDeviceUceEnabled(isEnabled);
12076 } finally {
12077 Binder.restoreCallingIdentity(identity);
12078 }
12079 }
12080
Brad Ebinger14d467f2021-02-12 06:18:28 +000012081 /**
12082 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
12083 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12084 */
12085 // Used for SHELL command only right now.
12086 @Override
12087 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
12088 List<String> featureTags) {
12089 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12090 "addUceRegistrationOverrideShell");
12091 final long identity = Binder.clearCallingIdentity();
12092 try {
12093 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
12094 new ArraySet<>(featureTags));
12095 } catch (ImsException e) {
12096 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12097 } finally {
12098 Binder.restoreCallingIdentity(identity);
12099 }
12100 }
12101
12102 /**
12103 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
12104 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12105 */
12106 // Used for SHELL command only right now.
12107 @Override
12108 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
12109 List<String> featureTags) {
12110 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12111 "removeUceRegistrationOverrideShell");
12112 final long identity = Binder.clearCallingIdentity();
12113 try {
12114 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
12115 new ArraySet<>(featureTags));
12116 } catch (ImsException e) {
12117 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12118 } finally {
12119 Binder.restoreCallingIdentity(identity);
12120 }
12121 }
12122
12123 /**
12124 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
12125 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12126 */
12127 // Used for SHELL command only right now.
12128 @Override
12129 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
12130 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12131 "clearUceRegistrationOverrideShell");
12132 final long identity = Binder.clearCallingIdentity();
12133 try {
12134 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
12135 } catch (ImsException e) {
12136 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12137 } finally {
12138 Binder.restoreCallingIdentity(identity);
12139 }
12140 }
12141
12142 /**
12143 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12144 */
12145 // Used for SHELL command only right now.
12146 @Override
12147 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
12148 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12149 "getLatestRcsContactUceCapabilityShell");
12150 final long identity = Binder.clearCallingIdentity();
12151 try {
12152 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
12153 } catch (ImsException e) {
12154 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12155 } finally {
12156 Binder.restoreCallingIdentity(identity);
12157 }
12158 }
12159
12160 /**
12161 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
12162 * device does not have an active PUBLISH.
12163 */
12164 // Used for SHELL command only right now.
12165 @Override
12166 public String getLastUcePidfXmlShell(int subId) {
12167 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
12168 final long identity = Binder.clearCallingIdentity();
12169 try {
12170 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
12171 } catch (ImsException e) {
12172 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12173 } finally {
12174 Binder.restoreCallingIdentity(identity);
12175 }
12176 }
12177
James.cf Line8713a42021-04-29 16:04:26 +080012178 /**
12179 * Remove UCE requests cannot be sent to the network status.
12180 */
12181 // Used for SHELL command only right now.
12182 @Override
12183 public boolean removeUceRequestDisallowedStatus(int subId) {
12184 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
12185 final long identity = Binder.clearCallingIdentity();
12186 try {
12187 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
12188 } catch (ImsException e) {
12189 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12190 } finally {
12191 Binder.restoreCallingIdentity(identity);
12192 }
12193 }
12194
James.cf Lin18bb9002021-05-25 01:37:38 +080012195 /**
12196 * Remove UCE requests cannot be sent to the network status.
12197 */
12198 // Used for SHELL command only.
12199 @Override
12200 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
12201 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
12202 final long identity = Binder.clearCallingIdentity();
12203 try {
12204 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
12205 } catch (ImsException e) {
12206 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12207 } finally {
12208 Binder.restoreCallingIdentity(identity);
12209 }
12210 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000012211
James.cf Lin4b784aa2021-01-31 03:25:15 +080012212 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012213 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12214 String callingPackage) {
12215 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12216 mApp, subId, "setSignalStrengthUpdateRequest");
12217
joonhunshin4ac60942023-11-15 15:23:39 +000012218 enforceTelephonyFeatureWithException(callingPackage,
12219 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest");
12220
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012221 final int callingUid = Binder.getCallingUid();
12222 // Verify that tha callingPackage belongs to the calling UID
12223 mApp.getSystemService(AppOpsManager.class)
12224 .checkPackage(callingUid, callingPackage);
12225
Rambo Wang3607f502021-02-01 21:51:40 -080012226 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012227
12228 final long identity = Binder.clearCallingIdentity();
12229 try {
12230 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
12231 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12232
12233 if (result instanceof IllegalStateException) {
12234 throw (IllegalStateException) result;
12235 }
12236 } finally {
12237 Binder.restoreCallingIdentity(identity);
12238 }
12239 }
12240
12241 @Override
12242 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12243 String callingPackage) {
12244 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12245 mApp, subId, "clearSignalStrengthUpdateRequest");
12246
joonhunshin4ac60942023-11-15 15:23:39 +000012247 enforceTelephonyFeatureWithException(callingPackage,
12248 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest");
12249
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012250 final int callingUid = Binder.getCallingUid();
12251 // Verify that tha callingPackage belongs to the calling UID
12252 mApp.getSystemService(AppOpsManager.class)
12253 .checkPackage(callingUid, callingPackage);
12254
12255 final long identity = Binder.clearCallingIdentity();
12256 try {
12257 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
12258 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12259
12260 if (result instanceof IllegalStateException) {
12261 throw (IllegalStateException) result;
12262 }
12263 } finally {
12264 Binder.restoreCallingIdentity(identity);
12265 }
12266 }
12267
Rambo Wang3607f502021-02-01 21:51:40 -080012268 private static void validateSignalStrengthUpdateRequest(Context context,
12269 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012270 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
12271 // phone/system process do not have further restriction on request
12272 return;
12273 }
12274
12275 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080012276 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012277 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080012278 context.enforceCallingOrSelfPermission(
12279 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
12280 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012281 }
12282
12283 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000012284 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012285 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012286 || info.isEnabled()) {
12287 throw new IllegalArgumentException(
12288 "Only system can set hide fields in SignalThresholdInfo");
12289 }
12290
12291 // Thresholds length for each RAN need in range. This has been validated in
12292 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
12293 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
12294 final int[] thresholds = info.getThresholds();
12295 Objects.requireNonNull(thresholds);
12296 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
12297 || thresholds.length
12298 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
12299 throw new IllegalArgumentException(
12300 "thresholds length is out of range: " + thresholds.length);
12301 }
12302 }
12303 }
SongFerngWang8236caa2021-01-17 21:51:44 +080012304
12305 /**
12306 * Gets the current phone capability.
12307 *
12308 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
12309 * @return the PhoneCapability which describes the data connection capability of modem.
12310 * It's used to evaluate possible phone config change, for example from single
12311 * SIM device to multi-SIM device.
12312 */
12313 @Override
12314 public PhoneCapability getPhoneCapability() {
12315 enforceReadPrivilegedPermission("getPhoneCapability");
joonhunshin4ac60942023-11-15 15:23:39 +000012316
12317 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12318 PackageManager.FEATURE_TELEPHONY, "getPhoneCapability");
12319
SongFerngWang8236caa2021-01-17 21:51:44 +080012320 final long identity = Binder.clearCallingIdentity();
12321 try {
12322 return mPhoneConfigurationManager.getCurrentPhoneCapability();
12323 } finally {
12324 Binder.restoreCallingIdentity(identity);
12325 }
12326 }
Michele Berionne5e411512020-11-13 02:36:59 +000012327
12328 /**
12329 * Prepare TelephonyManager for an unattended reboot. The reboot is
12330 * required to be done shortly after the API is invoked.
12331 */
12332 @Override
12333 @TelephonyManager.PrepareUnattendedRebootResult
12334 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012335 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000012336 enforceRebootPermission();
12337
joonhunshin4ac60942023-11-15 15:23:39 +000012338 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12339 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot");
12340
Michele Berionne5e411512020-11-13 02:36:59 +000012341 final long identity = Binder.clearCallingIdentity();
12342 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012343 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000012344 } finally {
12345 Binder.restoreCallingIdentity(identity);
12346 }
12347 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012348
12349 /**
12350 * Request to get the current slicing configuration including URSP rules and
12351 * NSSAIs (configured, allowed and rejected).
12352 *
12353 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
12354 */
12355 @Override
12356 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000012357 TelephonyPermissions
12358 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
12359 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012360
joonhunshin4ac60942023-11-15 15:23:39 +000012361 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12362 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
12363 "getSlicingConfig");
12364
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012365 final long identity = Binder.clearCallingIdentity();
12366 try {
12367 Phone phone = getDefaultPhone();
12368 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
12369 } finally {
12370 Binder.restoreCallingIdentity(identity);
12371 }
12372 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012373
12374 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070012375 * Check whether the given premium capability is available for purchase from the carrier.
12376 *
12377 * @param capability The premium capability to check.
12378 * @param subId The subId to check the premium capability for.
12379 *
12380 * @return Whether the given premium capability is available to purchase.
12381 */
12382 @Override
12383 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
12384 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12385 mApp, "isPremiumCapabilityAvailableForPurchase")) {
12386 log("Premium capability "
12387 + TelephonyManager.convertPremiumCapabilityToString(capability)
12388 + " is not available for purchase due to missing permissions.");
12389 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
12390 + "permission READ_BASIC_PHONE_STATE.");
12391 }
12392
joonhunshin4ac60942023-11-15 15:23:39 +000012393 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12394 PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase");
12395
Sarah Chin2ec39f62022-08-31 17:03:26 -070012396 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080012397 if (phone == null) {
12398 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12399 return false;
12400 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012401 final long identity = Binder.clearCallingIdentity();
12402 try {
Sarah Chincc5446f2023-10-23 17:57:19 -070012403 return SlicePurchaseController.getInstance(phone, mFeatureFlags)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012404 .isPremiumCapabilityAvailableForPurchase(capability);
12405 } finally {
12406 Binder.restoreCallingIdentity(identity);
12407 }
12408 }
12409
12410 /**
12411 * Purchase the given premium capability from the carrier.
12412 *
12413 * @param capability The premium capability to purchase.
12414 * @param callback The result of the purchase request.
12415 * @param subId The subId to purchase the premium capability for.
12416 */
12417 @Override
12418 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12419 log("purchasePremiumCapability: capability="
12420 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12421 + getCurrentPackageName());
12422
12423 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12424 mApp, "purchasePremiumCapability")) {
12425 log("purchasePremiumCapability "
12426 + TelephonyManager.convertPremiumCapabilityToString(capability)
12427 + " failed due to missing permissions.");
12428 throw new SecurityException("purchasePremiumCapability requires permission "
12429 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012430 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12431 mApp, "purchasePremiumCapability")) {
12432 log("purchasePremiumCapability "
12433 + TelephonyManager.convertPremiumCapabilityToString(capability)
12434 + " failed due to missing permissions.");
12435 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012436 }
12437
joonhunshin4ac60942023-11-15 15:23:39 +000012438 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12439 PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability");
12440
Sarah Chin2ec39f62022-08-31 17:03:26 -070012441 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012442 if (phone == null) {
12443 try {
12444 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12445 callback.accept(result);
12446 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12447 } catch (RemoteException e) {
12448 String logStr = "Purchase premium capability "
12449 + TelephonyManager.convertPremiumCapabilityToString(capability)
12450 + " failed due to RemoteException handling null phone: " + e;
12451 if (DBG) log(logStr);
12452 AnomalyReporter.reportAnomaly(
12453 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12454 }
12455 return;
12456 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012457
12458 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012459 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012460 callingProcess = mApp.getPackageManager().getApplicationInfo(
12461 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070012462 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012463 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012464 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012465
12466 boolean isVisible = false;
12467 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12468 if (am != null) {
12469 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12470 if (processes != null) {
12471 for (ActivityManager.RunningAppProcessInfo process : processes) {
12472 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070012473 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080012474 if (process.processName.equals(callingProcess) && process.importance
12475 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12476 isVisible = true;
12477 break;
12478 }
12479 }
12480 }
12481 }
12482
12483 if (!isVisible) {
12484 try {
12485 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12486 callback.accept(result);
12487 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12488 } catch (RemoteException e) {
12489 String logStr = "Purchase premium capability "
12490 + TelephonyManager.convertPremiumCapabilityToString(capability)
12491 + " failed due to RemoteException handling background application: " + e;
12492 if (DBG) log(logStr);
12493 AnomalyReporter.reportAnomaly(
12494 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12495 }
12496 return;
12497 }
12498
Sarah Chin71b3a852022-09-28 15:54:19 -070012499 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012500 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012501 }
12502
12503 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012504 * Register an IMS connection state callback
12505 */
12506 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012507 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12508 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012509 if (feature == ImsFeature.FEATURE_MMTEL) {
12510 // ImsMmTelManager
12511 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12512 TelephonyPermissions
12513 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12514 mApp, subId, "registerImsStateCallback");
12515 } else if (feature == ImsFeature.FEATURE_RCS) {
12516 // ImsRcsManager or SipDelegateManager
12517 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12518 Binder.getCallingUid(), "registerImsStateCallback",
12519 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12520 Manifest.permission.READ_PRECISE_PHONE_STATE,
12521 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12522 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12523 }
12524
12525 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12526 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12527 "IMS not available on device.");
12528 }
12529
12530 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12531 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12532 }
12533
12534 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12535 if (controller == null) {
12536 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12537 "IMS not available on device.");
12538 }
12539
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012540 if (callingPackage == null) {
12541 callingPackage = getCurrentPackageName();
12542 }
12543
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012544 final long token = Binder.clearCallingIdentity();
12545 try {
12546 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012547 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012548 } catch (ImsException e) {
12549 throw new ServiceSpecificException(e.getCode());
12550 } finally {
12551 Binder.restoreCallingIdentity(token);
12552 }
12553 }
12554
12555 /**
12556 * Unregister an IMS connection state callback
12557 */
12558 @Override
12559 public void unregisterImsStateCallback(IImsStateCallback cb) {
12560 final long token = Binder.clearCallingIdentity();
12561 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12562 if (controller == null) {
12563 return;
12564 }
12565 try {
12566 controller.unregisterImsStateCallback(cb);
12567 } finally {
12568 Binder.restoreCallingIdentity(token);
12569 }
12570 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012571
12572 /**
12573 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12574 *
12575 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012576 * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012577 * SecurityException.
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012578 *
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012579 * If there is current registered network this value will be same as the registered cell
12580 * identity. If the device goes out of service the previous cell identity is cached and
12581 * will be returned. If the cache age of the Cell identity is more than 24 hours
12582 * it will be cleared and null will be returned.
12583 *
12584 */
12585 @Override
12586 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12587 String callingFeatureId) {
12588 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12589 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12590 LocationAccessPolicy.checkLocationPermission(mApp,
12591 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12592 .setCallingPackage(callingPackage)
12593 .setCallingFeatureId(callingFeatureId)
12594 .setCallingPid(Binder.getCallingPid())
12595 .setCallingUid(Binder.getCallingUid())
12596 .setMethod("getLastKnownCellIdentity")
12597 .setLogAsInfo(true)
12598 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12599 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12600 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12601 .build());
12602
12603 boolean hasFinePermission =
12604 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12605 if (!hasFinePermission
12606 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12607 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012608 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012609 }
12610
12611 final long identity = Binder.clearCallingIdentity();
12612 try {
Ling Mac28f0212023-03-24 16:07:15 -070012613 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012614 if (sst == null) return null;
12615 return sst.getLastKnownCellIdentity();
12616 } finally {
12617 Binder.restoreCallingIdentity(identity);
12618 }
12619 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012620
jimsun3b9ccac2021-10-26 15:01:23 +080012621 /**
12622 * Sets the modem service class Name that Telephony will bind to.
12623 *
12624 * @param serviceName The class name of the modem service.
12625 * @return true if the operation is succeed, otherwise false.
12626 */
12627 public boolean setModemService(String serviceName) {
12628 Log.d(LOG_TAG, "setModemService - " + serviceName);
12629 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12630 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012631 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12632 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012633 return mPhoneConfigurationManager.setModemService(serviceName);
12634 }
12635
12636 /**
12637 * Return the class name of the currently bounded modem service.
12638 *
12639 * @return the class name of the modem service.
12640 */
12641 public String getModemService() {
12642 String result;
12643 Log.d(LOG_TAG, "getModemService");
12644 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12645 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012646 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012647 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12648 "getModemService");
12649 result = mPhoneConfigurationManager.getModemService();
12650 Log.d(LOG_TAG, "result = " + result);
12651 return result;
12652 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012653
Hakjun Choi3ee81112023-12-19 15:40:58 +000012654 /**
12655 * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources,
12656 * including carrier config, entitlement server, and config update.
12657 *
12658 * @param subId subId The subscription ID of the carrier.
12659 *
12660 * @return List of plmns for carrier satellite service. If no plmn is available, empty list will
12661 * be returned.
12662 *
12663 * @throws SecurityException if the caller doesn't have the required permission.
12664 */
Hakjun Choi74c16be2024-01-19 08:18:09 +000012665 @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) {
12666 enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier");
Hakjun Choi3ee81112023-12-19 15:40:58 +000012667 final long identity = Binder.clearCallingIdentity();
12668 try {
Hakjun Choi74c16be2024-01-19 08:18:09 +000012669 return mSatelliteController.getSatellitePlmnsForCarrier(subId);
Hakjun Choi3ee81112023-12-19 15:40:58 +000012670 } finally {
12671 Binder.restoreCallingIdentity(identity);
12672 }
12673 }
12674
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012675 @Override
12676 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12677 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12678 mApp.enforceCallingOrSelfPermission(
12679 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12680 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12681
12682 final long identity = Binder.clearCallingIdentity();
12683 try {
12684 Phone phone = getPhone(subId);
12685 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012686 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12687 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012688 phone.setVoiceServiceStateOverride(hasService);
12689 } finally {
12690 Binder.restoreCallingIdentity(identity);
12691 }
12692 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012693
12694 /**
12695 * set removable eSIM as default eUICC.
12696 *
12697 * @hide
12698 */
12699 @Override
12700 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12701 enforceModifyPermission();
12702 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12703
12704 final long identity = Binder.clearCallingIdentity();
12705 try {
12706 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12707 } finally {
12708 Binder.restoreCallingIdentity(identity);
12709 }
12710 }
12711
12712 /**
12713 * Returns whether the removable eSIM is default eUICC or not.
12714 *
12715 * @hide
12716 */
12717 @Override
12718 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12719 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12720 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12721
12722 final long identity = Binder.clearCallingIdentity();
12723 try {
12724 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12725 } finally {
12726 Binder.restoreCallingIdentity(identity);
12727 }
12728 }
12729
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012730 /**
12731 * Get the component name of the default app to direct respond-via-message intent for the
12732 * user associated with this subscription, update the cache if there is no respond-via-message
12733 * application currently configured for this user.
12734 * @return component name of the app and class to direct Respond Via Message intent to, or
12735 * {@code null} if the functionality is not supported.
12736 * @hide
12737 */
12738 @Override
12739 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12740 boolean updateIfNeeded) {
12741 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012742
joonhunshin4ac60942023-11-15 15:23:39 +000012743 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12744 PackageManager.FEATURE_TELEPHONY_MESSAGING,
12745 "getDefaultRespondViaMessageApplication");
12746
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012747 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12748
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012749 UserHandle userHandle = null;
12750 final long identity = Binder.clearCallingIdentity();
12751 try {
12752 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12753 } finally {
12754 Binder.restoreCallingIdentity(identity);
12755 }
12756 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12757 updateIfNeeded, userHandle);
12758 }
Jack Yuf5badd92022-12-08 00:50:53 -080012759
12760 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012761 * Set whether the device is able to connect with null ciphering or integrity
12762 * algorithms. This is a global setting and will apply to all active subscriptions
12763 * and all new subscriptions after this.
12764 *
12765 * @param enabled when true, null cipher and integrity algorithms are allowed.
12766 * @hide
12767 */
12768 @Override
12769 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12770 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12771 enforceModifyPermission();
12772 checkForNullCipherAndIntegritySupport();
12773
12774 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12775 // for listening to these preference changes and applying them immediately.
12776 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12777 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12778 editor.apply();
12779
12780 for (Phone phone: PhoneFactory.getPhones()) {
12781 phone.handleNullCipherEnabledChange();
12782 }
12783 }
12784
12785
12786 /**
12787 * Get whether the device is able to connect with null ciphering or integrity
12788 * algorithms. Note that this retrieves the phone-global preference and not
12789 * the state of the radio.
12790 *
12791 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12792 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12793 * version for this feature.
12794 * @hide
12795 */
12796 @Override
12797 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12798 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12799 enforceReadPermission();
12800 checkForNullCipherAndIntegritySupport();
12801 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12802 }
12803
12804 private void checkForNullCipherAndIntegritySupport() {
12805 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12806 throw new UnsupportedOperationException(
12807 "Null cipher and integrity operations require HAL 2.1 or above");
12808 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012809 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12810 throw new UnsupportedOperationException(
12811 "Null cipher and integrity operations unsupported by modem");
12812 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012813 }
12814
Gil Cukierman06403e12023-11-29 16:33:03 +000012815 private void checkForIdentifierDisclosureNotificationSupport() {
12816 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) {
12817 throw new UnsupportedOperationException(
12818 "Cellular identifier disclosure transparency operations require HAL 2.2 or "
12819 + "above");
12820 }
12821 if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) {
12822 throw new UnsupportedOperationException(
12823 "Cellular identifier disclosure transparency operations unsupported by modem");
12824 }
12825 }
12826
Michael Groover826b71d2023-12-21 22:08:06 -060012827 private void checkForNullCipherNotificationSupport() {
12828 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) {
12829 throw new UnsupportedOperationException(
12830 "Null cipher notification operations require HAL 2.2 or above");
12831 }
12832 if (!getDefaultPhone().isNullCipherNotificationSupported()) {
12833 throw new UnsupportedOperationException(
12834 "Null cipher notification operations unsupported by modem");
12835 }
12836 }
12837
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012838 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012839 * Get the SIM state for the slot index.
12840 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12841 *
12842 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12843 */
12844 @Override
12845 @SimState
12846 public int getSimStateForSlotIndex(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +000012847 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12848 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex");
12849
Jack Yuf5badd92022-12-08 00:50:53 -080012850 IccCardConstants.State simState;
12851 if (slotIndex < 0) {
12852 simState = IccCardConstants.State.UNKNOWN;
12853 } else {
12854 Phone phone = null;
12855 try {
12856 phone = PhoneFactory.getPhone(slotIndex);
12857 } catch (IllegalStateException e) {
12858 // ignore
12859 }
12860 if (phone == null) {
12861 simState = IccCardConstants.State.UNKNOWN;
12862 } else {
12863 IccCard icc = phone.getIccCard();
12864 if (icc == null) {
12865 simState = IccCardConstants.State.UNKNOWN;
12866 } else {
12867 simState = icc.getState();
12868 }
12869 }
12870 }
12871 return simState.ordinal();
12872 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012873
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012874 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
12875 boolean enableLogcat,
12876 long logcatStartTimestampMillis, boolean enableTelecomDump,
12877 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012878 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012879 TelephonyManager.EmergencyCallDiagnosticParams.Builder edpBuilder =
12880 new TelephonyManager.EmergencyCallDiagnosticParams.Builder();
12881 edpBuilder
12882 .setTelecomDumpSysCollectionEnabled(enableTelecomDump)
12883 .setTelephonyDumpSysCollectionEnabled(enableTelephonyDump);
12884 if (enableLogcat) {
12885 edpBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis);
12886 }
12887 TelephonyManager.EmergencyCallDiagnosticParams edp = edpBuilder.build();
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012888 Log.d(LOG_TAG, "persisting with Params " + edp.toString());
12889 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
12890 Executors.newCachedThreadPool(), db,
12891 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
12892 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), edp, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012893 }
12894
12895 /**
12896 * Request telephony to persist state for debugging emergency call failures.
12897 *
12898 * @param dropBoxTag Tag to use when persisting data to dropbox service.
12899 * @param enableLogcat whether to collect logcat output
12900 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
12901 * @param enableTelecomDump whether to collect telecom dumpsys
12902 * @param enableTelephonyDump whether to collect telephony dumpsys
12903 */
12904 @Override
12905 @RequiresPermission(android.Manifest.permission.DUMP)
12906 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
12907 long logcatStartTimestampMillis, boolean enableTelecomDump,
12908 boolean enableTelephonyDump) {
12909 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
12910 "persistEmergencyCallDiagnosticData");
12911 final long identity = Binder.clearCallingIdentity();
12912 try {
12913 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
12914 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
12915
12916 } finally {
12917 Binder.restoreCallingIdentity(identity);
12918 }
12919 }
12920
Hui Wang9b5793a2022-12-05 14:38:06 -060012921 /**
12922 * Get current cell broadcast ranges.
12923 */
12924 @Override
12925 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12926 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12927 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12928 "getCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012929
12930 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12931 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges");
12932
Hui Wang9b5793a2022-12-05 14:38:06 -060012933 final long identity = Binder.clearCallingIdentity();
12934 try {
12935 return getPhone(subId).getCellBroadcastIdRanges();
12936 } finally {
12937 Binder.restoreCallingIdentity(identity);
12938 }
12939 }
12940
12941 /**
12942 * Set reception of cell broadcast messages with the list of the given ranges
12943 *
12944 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12945 */
12946 @Override
12947 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12948 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12949 @Nullable IIntegerConsumer callback) {
12950 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12951 "setCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012952
12953 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12954 PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges");
12955
Hui Wang9b5793a2022-12-05 14:38:06 -060012956 final long identity = Binder.clearCallingIdentity();
12957 try {
12958 Phone phone = getPhoneFromSubId(subId);
12959 if (DBG) {
12960 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12961 }
12962 phone.setCellBroadcastIdRanges(ranges, result -> {
12963 if (callback != null) {
12964 try {
12965 callback.accept(result);
12966 } catch (RemoteException e) {
12967 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12968 }
12969 }
12970 });
12971 } finally {
12972 Binder.restoreCallingIdentity(identity);
12973 }
12974 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012975
12976 /**
12977 * Returns whether the device supports the domain selection service.
12978 *
12979 * @return {@code true} if the device supports the domain selection service.
12980 */
12981 @Override
12982 public boolean isDomainSelectionSupported() {
12983 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12984 "isDomainSelectionSupported");
12985
12986 final long identity = Binder.clearCallingIdentity();
12987 try {
12988 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12989 } finally {
12990 Binder.restoreCallingIdentity(identity);
12991 }
12992 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012993
12994 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012995 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
12996 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
12997 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080012998 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012999 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chinabf081b2023-03-09 23:00:57 -080013000 * @param enableSatellite {@code true} to enable the satellite modem and
13001 * {@code false} to disable.
13002 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
13003 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080013004 *
13005 * @throws SecurityException if the caller doesn't have the required permission.
13006 */
13007 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013008 public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode,
13009 @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013010 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013011 if (enableSatellite) {
13012 ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) {
13013 @Override
13014 protected void onReceiveResult(int resultCode, Bundle resultData) {
13015 Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode
13016 + ", resultData=" + resultData);
13017 boolean isAllowed = false;
13018 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(
13019 callback::accept);
13020 if (resultCode == SATELLITE_RESULT_SUCCESS) {
13021 if (resultData != null
13022 && resultData.containsKey(KEY_SATELLITE_COMMUNICATION_ALLOWED)) {
13023 isAllowed = resultData.getBoolean(KEY_SATELLITE_COMMUNICATION_ALLOWED);
13024 } else {
13025 loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist.");
13026 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013027 } else {
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013028 result.accept(resultCode);
13029 return;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013030 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013031 if (isAllowed) {
13032 mSatelliteController.requestSatelliteEnabled(
13033 subId, enableSatellite, enableDemoMode, callback);
13034 } else {
13035 result.accept(SATELLITE_RESULT_ACCESS_BARRED);
13036 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013037 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013038 };
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013039 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013040 subId, resultReceiver);
13041 } else {
13042 // No need to check if satellite is allowed at current location when disabling satellite
13043 mSatelliteController.requestSatelliteEnabled(
13044 subId, enableSatellite, enableDemoMode, callback);
13045 }
Sarah Chin503828c2023-02-01 23:54:20 -080013046 }
13047
13048 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013049 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080013050 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013051 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013052 * @param result The result receiver that returns whether the satellite modem is enabled
13053 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013054 *
13055 * @throws SecurityException if the caller doesn't have the required permission.
13056 */
13057 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013058 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
13059 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013060 mSatelliteController.requestIsSatelliteEnabled(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013061 }
13062
13063 /**
Sarah Chin43457982023-02-15 17:50:38 -080013064 * Request to get whether the satellite service demo mode is enabled.
13065 *
13066 * @param subId The subId of the subscription to check whether the satellite demo mode
13067 * is enabled for.
13068 * @param result The result receiver that returns whether the satellite demo mode is enabled
13069 * if the request is successful or an error code if the request failed.
13070 *
13071 * @throws SecurityException if the caller doesn't have the required permission.
13072 */
13073 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013074 public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
13075 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
13076 mSatelliteController.requestIsDemoModeEnabled(subId, result);
Sarah Chin43457982023-02-15 17:50:38 -080013077 }
13078
13079 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013080 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080013081 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013082 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013083 * @param result The result receiver that returns whether the satellite service is supported on
13084 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013085 */
13086 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013087 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013088 mSatelliteController.requestIsSatelliteSupported(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013089 }
13090
13091 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013092 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080013093 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013094 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013095 * @param result The result receiver that returns the {@link SatelliteCapabilities}
13096 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013097 *
13098 * @throws SecurityException if the caller doesn't have required permission.
13099 */
13100 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013101 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
13102 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013103 mSatelliteController.requestSatelliteCapabilities(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013104 }
13105
13106 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013107 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013108 * This can be called by the pointing UI when the user starts pointing to the satellite.
13109 * Modem should continue to report the pointing input as the device or satellite moves.
13110 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013111 * @param subId The subId of the subscription to start satellite transmission updates for.
13112 * @param resultCallback The callback to get the result of the request.
13113 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080013114 *
13115 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013116 */
13117 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013118 public void startSatelliteTransmissionUpdates(int subId,
13119 @NonNull IIntegerConsumer resultCallback,
13120 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13121 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
13122 mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080013123 }
13124
13125 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013126 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013127 * This can be called by the pointing UI when the user stops pointing to the satellite.
13128 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013129 * @param subId The subId of the subscription to stop satellite transmission updates for.
13130 * @param resultCallback The callback to get the result of the request.
13131 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
13132 * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080013133 *
13134 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013135 */
13136 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013137 public void stopSatelliteTransmissionUpdates(int subId,
13138 @NonNull IIntegerConsumer resultCallback,
13139 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13140 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
13141 mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013142 }
13143
13144 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013145 * Register the subscription with a satellite provider.
13146 * This is needed to register the subscription if the provider allows dynamic registration.
13147 *
13148 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013149 * @param token The token to be used as a unique identifier for provisioning with satellite
13150 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013151 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080013152 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013153 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013154 * @return The signal transport used by the caller to cancel the provision request,
13155 * or {@code null} if the request failed.
13156 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013157 * @throws SecurityException if the caller doesn't have the required permission.
13158 */
13159 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013160 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013161 @NonNull String token, @NonNull byte[] provisionData,
13162 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013163 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013164 return mSatelliteController.provisionSatelliteService(subId, token, provisionData,
13165 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013166 }
13167
13168 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013169 * Unregister the device/subscription with the satellite provider.
13170 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013171 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013172 * should report as deprovisioned.
13173 *
13174 * @param subId The subId of the subscription to be deprovisioned.
13175 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080013176 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013177 *
13178 * @throws SecurityException if the caller doesn't have the required permission.
13179 */
13180 @Override
13181 public void deprovisionSatelliteService(int subId,
13182 @NonNull String token, @NonNull IIntegerConsumer callback) {
13183 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013184 mSatelliteController.deprovisionSatelliteService(subId, token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013185 }
13186
13187 /**
Sarah Chin43457982023-02-15 17:50:38 -080013188 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013189 *
Sarah Chin43457982023-02-15 17:50:38 -080013190 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013191 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013192 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013193 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013194 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013195 * @throws SecurityException if the caller doesn't have the required permission.
13196 */
13197 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013198 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
13199 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013200 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013201 return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013202 }
13203
13204 /**
Sarah Chin43457982023-02-15 17:50:38 -080013205 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013206 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013207 *
Sarah Chin43457982023-02-15 17:50:38 -080013208 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013209 * @param callback The callback that was passed to
13210 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013211 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013212 * @throws SecurityException if the caller doesn't have the required permission.
13213 */
13214 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013215 public void unregisterForSatelliteProvisionStateChanged(
13216 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013217 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013218 mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013219 }
13220
13221 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013222 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013223 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013224 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013225 * @param result The result receiver that returns whether the device is provisioned with a
13226 * satellite provider if the request is successful or an error code if the
13227 * request failed.
13228 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013229 * @throws SecurityException if the caller doesn't have the required permission.
13230 */
13231 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013232 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
13233 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013234 mSatelliteController.requestIsSatelliteProvisioned(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013235 }
13236
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013237 /**
Sarah Chin43457982023-02-15 17:50:38 -080013238 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013239 *
Sarah Chin43457982023-02-15 17:50:38 -080013240 * @param subId The subId of the subscription to register for satellite modem state changed.
13241 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080013242 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013243 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013244 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013245 * @throws SecurityException if the caller doesn't have the required permission.
13246 */
13247 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013248 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013249 @NonNull ISatelliteModemStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080013250 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013251 return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013252 }
13253
13254 /**
Sarah Chin43457982023-02-15 17:50:38 -080013255 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013256 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013257 *
Sarah Chin43457982023-02-15 17:50:38 -080013258 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080013259 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013260 * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013261 *
13262 * @throws SecurityException if the caller doesn't have the required permission.
13263 */
13264 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013265 public void unregisterForModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013266 @NonNull ISatelliteModemStateCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013267 enforceSatelliteCommunicationPermission("unregisterForModemStateChanged");
13268 mSatelliteController.unregisterForModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013269 }
13270
13271 /**
13272 * Register to receive incoming datagrams over satellite.
13273 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013274 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Sarah Chindf715ec2023-02-13 13:46:24 -080013275 * @param callback The callback to handle incoming datagrams over satellite.
13276 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013277 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013278 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013279 * @throws SecurityException if the caller doesn't have the required permission.
13280 */
13281 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013282 @SatelliteManager.SatelliteResult public int registerForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013283 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013284 enforceSatelliteCommunicationPermission("registerForIncomingDatagram");
13285 return mSatelliteController.registerForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013286 }
13287
13288 /**
13289 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013290 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013291 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013292 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
13293 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013294 * {@link #registerForIncomingDatagram(int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013295 *
13296 * @throws SecurityException if the caller doesn't have the required permission.
13297 */
13298 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013299 public void unregisterForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013300 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013301 enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram");
13302 mSatelliteController.unregisterForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013303 }
13304
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013305 /**
13306 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013307 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013308 * This method requests modem to check if there are any pending datagrams to be received over
13309 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000013310 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080013311 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013312 * @param subId The subId of the subscription used for receiving datagrams.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013313 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013314 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013315 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013316 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013317 public void pollPendingDatagrams(int subId, IIntegerConsumer callback) {
13318 enforceSatelliteCommunicationPermission("pollPendingDatagrams");
13319 mSatelliteController.pollPendingDatagrams(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013320 }
13321
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013322 /**
13323 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013324 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013325 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
13326 * input to this method. Datagram received here will be passed down to modem without any
13327 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080013328 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013329 * @param subId The subId of the subscription to send satellite datagrams for.
13330 * @param datagramType datagram type indicating whether the datagram is of type
13331 * SOS_SMS or LOCATION_SHARING.
13332 * @param datagram encoded gateway datagram which is encrypted by the caller.
13333 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000013334 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
13335 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013336 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013337 *
13338 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013339 */
13340 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013341 public void sendDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000013342 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
13343 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013344 enforceSatelliteCommunicationPermission("sendDatagram");
13345 mSatelliteController.sendDatagram(subId, datagramType, datagram, needFullScreenPointingUI,
13346 callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013347 }
13348
Sarah Chindf715ec2023-02-13 13:46:24 -080013349 /**
13350 * Request to get whether satellite communication is allowed for the current location.
13351 *
13352 * @param subId The subId of the subscription to check whether satellite communication is
13353 * allowed for the current location for.
13354 * @param result The result receiver that returns whether satellite communication is allowed
13355 * for the current location if the request is successful or an error code
13356 * if the request failed.
13357 *
13358 * @throws SecurityException if the caller doesn't have the required permission.
13359 */
13360 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013361 public void requestIsCommunicationAllowedForCurrentLocation(int subId,
Sarah Chindf715ec2023-02-13 13:46:24 -080013362 @NonNull ResultReceiver result) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013363 enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation");
13364 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(subId,
13365 result);
Sarah Chindf715ec2023-02-13 13:46:24 -080013366 }
13367
13368 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013369 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080013370 *
Sarah Chin5f57c582023-02-14 04:16:10 -080013371 * @param subId The subId to get the time after which the satellite will be visible for.
13372 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080013373 * be visible if the request is successful or an error code if the request failed.
13374 *
13375 * @throws SecurityException if the caller doesn't have the required permission.
13376 */
13377 @Override
13378 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
13379 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013380 mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013381 }
13382
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013383 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013384 * Inform that Device is aligned to satellite for demo mode.
13385 *
13386 * @param subId The subId to get the time after which the satellite will be visible for.
13387 * @param isAligned {@code true} Device is aligned with the satellite for demo mode
13388 * {@code false} Device fails to align with the satellite for demo mode.
13389 *
13390 * @throws SecurityException if the caller doesn't have required permission.
13391 */
13392 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
13393
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013394 public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) {
Hakjun Choiae365972023-04-25 11:00:31 +000013395 enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite");
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013396 mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned);
Hakjun Choiae365972023-04-25 11:00:31 +000013397 }
13398
13399 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000013400 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
13401 * by modem.
13402 *
13403 * @param subId The subId of the subscription to request for.
13404 * @param reason Reason for disallowing satellite communication for carrier.
13405 * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the
13406 * operation.
13407 *
13408 * @throws SecurityException if the caller doesn't have required permission.
13409 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013410 public void addAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013411 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13412 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013413 enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013414 final long identity = Binder.clearCallingIdentity();
13415 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013416 mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013417 } finally {
13418 Binder.restoreCallingIdentity(identity);
13419 }
13420 }
13421
13422 /**
13423 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
13424 * by modem.
13425 *
13426 * @param subId The subId of the subscription to request for.
13427 * @param reason Reason for disallowing satellite communication.
13428 * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the
13429 * operation.
13430 *
13431 * @throws SecurityException if the caller doesn't have required permission.
13432 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013433 public void removeAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013434 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13435 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013436 enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013437 final long identity = Binder.clearCallingIdentity();
13438 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013439 mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013440 } finally {
13441 Binder.restoreCallingIdentity(identity);
13442 }
13443 }
13444
13445 /**
13446 * Get reasons for disallowing satellite communication, as requested by
13447 * {@link #addSatelliteAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
13448 *
13449 * @param subId The subId of the subscription to request for.
13450 *
13451 * @return Integer array of reasons for disallowing satellite communication.
13452 *
13453 * @throws SecurityException if the caller doesn't have the required permission.
13454 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013455 public @NonNull int[] getAttachRestrictionReasonsForCarrier(
Hakjun Choicb39db92023-07-14 15:51:12 +000013456 int subId) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013457 enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013458 final long identity = Binder.clearCallingIdentity();
13459 try {
13460 Set<Integer> reasonSet =
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013461 mSatelliteController.getAttachRestrictionReasonsForCarrier(subId);
Hakjun Choicb39db92023-07-14 15:51:12 +000013462 return reasonSet.stream().mapToInt(i->i).toArray();
13463 } finally {
13464 Binder.restoreCallingIdentity(identity);
13465 }
13466 }
13467
13468 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000013469 * Request to get the signal strength of the satellite connection.
13470 *
13471 * @param subId The subId of the subscription to request for.
13472 * @param result Result receiver to get the error code of the request and the current signal
13473 * strength of the satellite connection.
13474 *
13475 * @throws SecurityException if the caller doesn't have required permission.
13476 */
13477 @Override
13478 public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) {
13479 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
13480 final long identity = Binder.clearCallingIdentity();
13481 try {
13482 mSatelliteController.requestNtnSignalStrength(subId, result);
13483 } finally {
13484 Binder.restoreCallingIdentity(identity);
13485 }
13486 }
13487
13488 /**
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013489 * Registers for NTN signal strength changed from satellite modem. If the registration operation
13490 * is not successful, a {@link ServiceSpecificException} that contains
13491 * {@link SatelliteManager.SatelliteResult} will be thrown.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013492 *
13493 * @param subId The subId of the subscription to request for.
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013494 * @param callback The callback to handle the NTN signal strength changed event. If the
13495 * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged(
13496 * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of
13497 * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial
13498 * network has changed.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013499 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013500 * @throws SecurityException If the caller doesn't have the required permission.
13501 * @throws ServiceSpecificException If the callback registration operation fails.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013502 */
13503 @Override
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013504 public void registerForNtnSignalStrengthChanged(int subId,
13505 @NonNull INtnSignalStrengthCallback callback) throws RemoteException {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013506 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
13507 final long identity = Binder.clearCallingIdentity();
13508 try {
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013509 mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013510 } finally {
13511 Binder.restoreCallingIdentity(identity);
13512 }
13513 }
13514
13515 /**
13516 * Unregisters for NTN signal strength changed from satellite modem.
13517 * If callback was not registered before, the request will be ignored.
13518 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013519 * @param subId The subId of the subscription to unregister for listening NTN signal strength
13520 * changed event.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013521 * @param callback The callback that was passed to
13522 * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)}
13523 *
13524 * @throws SecurityException if the caller doesn't have the required permission.
13525 */
13526 @Override
13527 public void unregisterForNtnSignalStrengthChanged(
13528 int subId, @NonNull INtnSignalStrengthCallback callback) {
13529 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
13530 final long identity = Binder.clearCallingIdentity();
13531 try {
13532 mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback);
13533 } finally {
13534 Binder.restoreCallingIdentity(identity);
13535 }
13536 }
13537
13538 /**
Hakjun Choi8d96a562023-10-26 15:01:40 +000013539 * Registers for satellite capabilities change event from the satellite service.
13540 *
13541 * @param subId The subId of the subscription to request for.
13542 * @param callback The callback to handle the satellite capabilities changed event.
13543 *
13544 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13545 *
13546 * @throws SecurityException if the caller doesn't have required permission.
13547 */
13548 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013549 @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged(
Hakjun Choi8d96a562023-10-26 15:01:40 +000013550 int subId, @NonNull ISatelliteCapabilitiesCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013551 enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013552 final long identity = Binder.clearCallingIdentity();
13553 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013554 return mSatelliteController.registerForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013555 } finally {
13556 Binder.restoreCallingIdentity(identity);
13557 }
13558 }
13559
13560 /**
13561 * Unregisters for satellite capabilities change event from the satellite service.
13562 * If callback was not registered before, the request will be ignored.
13563 *
13564 * @param subId The subId of the subscription to unregister for satellite capabilities change.
13565 * @param callback The callback that was passed to.
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013566 * {@link #registerForCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}.
Hakjun Choi8d96a562023-10-26 15:01:40 +000013567 *
13568 * @throws SecurityException if the caller doesn't have required permission.
13569 */
13570 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013571 public void unregisterForCapabilitiesChanged(int subId,
13572 @NonNull ISatelliteCapabilitiesCallback callback) {
13573 enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013574 final long identity = Binder.clearCallingIdentity();
13575 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013576 mSatelliteController.unregisterForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013577 } finally {
13578 Binder.restoreCallingIdentity(identity);
13579 }
13580 }
13581
13582 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013583 * This API can be used by only CTS to update satellite vendor service package name.
13584 *
13585 * @param servicePackageName The package name of the satellite vendor service.
13586 * @return {@code true} if the satellite vendor service is set successfully,
13587 * {@code false} otherwise.
13588 */
13589 public boolean setSatelliteServicePackageName(String servicePackageName) {
13590 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName);
13591 TelephonyPermissions.enforceShellOnly(
13592 Binder.getCallingUid(), "setSatelliteServicePackageName");
13593 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13594 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13595 "setSatelliteServicePackageName");
13596 return mSatelliteController.setSatelliteServicePackageName(servicePackageName);
13597 }
13598
13599 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070013600 * This API can be used by only CTS to update satellite gateway service package name.
13601 *
13602 * @param servicePackageName The package name of the satellite gateway service.
13603 * @return {@code true} if the satellite gateway service is set successfully,
13604 * {@code false} otherwise.
13605 */
13606 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
13607 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
13608 TelephonyPermissions.enforceShellOnly(
13609 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
13610 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13611 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13612 "setSatelliteGatewayServicePackageName");
13613 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
13614 }
13615
13616 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070013617 * This API can be used by only CTS to update satellite pointing UI app package and class names.
13618 *
13619 * @param packageName The package name of the satellite pointing UI app.
13620 * @param className The class name of the satellite pointing UI app.
13621 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
13622 * {@code false} otherwise.
13623 */
13624 public boolean setSatellitePointingUiClassName(
13625 @Nullable String packageName, @Nullable String className) {
13626 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
13627 + ", className=" + className);
13628 TelephonyPermissions.enforceShellOnly(
13629 Binder.getCallingUid(), "setSatellitePointingUiClassName");
13630 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13631 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13632 "setSatelliteGatewayServicePackageName");
13633 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
13634 }
13635
13636 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070013637 * This API can be used by only CTS to update the timeout duration in milliseconds that
13638 * satellite should stay at listening mode to wait for the next incoming page before disabling
13639 * listening mode.
13640 *
13641 * @param timeoutMillis The timeout duration in millisecond.
13642 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13643 */
13644 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
13645 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
13646 TelephonyPermissions.enforceShellOnly(
13647 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
13648 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13649 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13650 "setSatelliteListeningTimeoutDuration");
13651 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
13652 }
13653
13654 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013655 * This API can be used by only CTS to update the timeout duration in milliseconds whether
13656 * the device is aligned with the satellite for demo mode
13657 *
13658 * @param timeoutMillis The timeout duration in millisecond.
13659 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13660 */
13661 public boolean setSatelliteDeviceAlignedTimeoutDuration(long timeoutMillis) {
13662 Log.d(LOG_TAG, "setDeviceAlignedTimeoutDuration - " + timeoutMillis);
13663 TelephonyPermissions.enforceShellOnly(
13664 Binder.getCallingUid(), "setDeviceAlignedTimeoutDuration");
13665 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13666 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13667 "setDeviceAlignedTimeoutDuration");
13668 return mSatelliteController.setSatelliteDeviceAlignedTimeoutDuration(timeoutMillis);
13669 }
13670
13671 /**
Thomas Nguyen11a051f2023-10-25 10:14:55 -070013672 * This API can be used in only testing to override connectivity status in monitoring emergency
13673 * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.
13674 *
13675 * @param handoverType The type of handover from emergency call to satellite messaging. Use one
13676 * of the following values to enable the override:
13677 * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS
13678 * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911
13679 * To disable the override, use -1 for handoverType.
13680 * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer
13681 * delaySeconds after the emergency call starts.
13682 * @return {@code true} if the handover type is set successfully, {@code false} otherwise.
13683 */
13684 public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) {
13685 Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType);
13686 TelephonyPermissions.enforceShellOnly(
13687 Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType");
13688 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13689 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13690 "setEmergencyCallToSatelliteHandoverType");
13691 return mSatelliteController.setEmergencyCallToSatelliteHandoverType(
13692 handoverType, delaySeconds);
13693 }
13694
13695 /**
Thomas Nguyen3d602742024-01-19 11:29:35 -080013696 * This API can be used in only testing to override oem-enabled satellite provision status.
13697 *
13698 * @param reset {@code true} mean the overriding status should not be used, {@code false}
13699 * otherwise.
13700 * @param isProvisioned The overriding provision status.
13701 * @return {@code true} if the provision status is set successfully, {@code false} otherwise.
13702 */
13703 public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) {
13704 Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset
13705 + ", isProvisioned=" + isProvisioned);
13706 TelephonyPermissions.enforceShellOnly(
13707 Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus");
13708 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13709 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13710 "setOemEnabledSatelliteProvisionStatus");
13711 return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned);
13712 }
13713
13714 /**
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013715 * This API should be used by only CTS tests to forcefully set telephony country codes.
13716 *
13717 * @return {@code true} if the country code is set successfully, {@code false} otherwise.
13718 */
13719 public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes,
13720 Map cachedNetworkCountryCodes, String locationCountryCode,
13721 long locationCountryCodeTimestampNanos) {
13722 Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes="
13723 + String.join(", ", currentNetworkCountryCodes)
13724 + ", locationCountryCode=" + locationCountryCode
13725 + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos
13726 + ", reset=" + reset + ", cachedNetworkCountryCodes="
13727 + String.join(", ", cachedNetworkCountryCodes.keySet()));
13728 TelephonyPermissions.enforceShellOnly(
13729 Binder.getCallingUid(), "setCachedLocationCountryCode");
13730 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13731 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13732 "setCachedLocationCountryCode");
13733 return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext()).setCountryCodes(
13734 reset, currentNetworkCountryCodes, cachedNetworkCountryCodes, locationCountryCode,
13735 locationCountryCodeTimestampNanos);
13736 }
13737
13738 /**
13739 * This API should be used by only CTS tests to override the overlay configs of satellite
13740 * access controller.
13741 *
13742 * @param reset {@code true} mean the overridden configs should not be used, {@code false}
13743 * otherwise.
13744 * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise.
13745 */
13746 public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed,
13747 String s2CellFile, long locationFreshDurationNanos,
13748 List<String> satelliteCountryCodes) {
13749 Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset
13750 + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile
13751 + ", locationFreshDurationNanos=" + locationFreshDurationNanos
13752 + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null)
13753 ? String.join(", ", satelliteCountryCodes) : null));
13754 TelephonyPermissions.enforceShellOnly(
13755 Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs");
13756 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13757 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13758 "setSatelliteAccessControlOverlayConfigs");
13759 return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset, isAllowed,
13760 s2CellFile, locationFreshDurationNanos, satelliteCountryCodes);
13761 }
13762
13763 /**
Hakjun Choibc6ce992023-11-07 16:04:33 +000013764 * This API can be used by only CTS to override the cached value for the device overlay config
13765 * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether
13766 * outgoing satellite datagrams should be sent to modem in demo mode.
13767 *
13768 * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to
13769 * satellite modem or not.
13770 *
13771 * @return {@code true} if the operation is successful, {@code false} otherwise.
13772 */
13773 public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) {
13774 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
13775 Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is "
13776 + "disabled");
13777 return false;
13778 }
13779 Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode");
13780 TelephonyPermissions.enforceShellOnly(
13781 Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode");
13782 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13783 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13784 "setShouldSendDatagramToModemInDemoMode");
13785 return mSatelliteController.setShouldSendDatagramToModemInDemoMode(
13786 shouldSendToModemInDemoMode);
13787 }
13788
13789 /**
Hunsuk Choi13078be2023-09-13 10:55:21 +000013790 * Sets the service defined in ComponentName to be bound.
13791 *
13792 * This should only be used for testing.
13793 * @return {@code true} if the DomainSelectionService to bind to was set,
13794 * {@code false} otherwise.
13795 */
13796 @Override
13797 public boolean setDomainSelectionServiceOverride(ComponentName componentName) {
13798 Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName);
13799
13800 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
13801 "setDomainSelectionServiceOverride");
13802 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13803 getDefaultSubscription(), "setDomainSelectionServiceOverride");
13804
13805 final long identity = Binder.clearCallingIdentity();
13806 try {
13807 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13808 return DomainSelectionResolver.getInstance()
13809 .setDomainSelectionServiceOverride(componentName);
13810 }
13811 } finally {
13812 Binder.restoreCallingIdentity(identity);
13813 }
13814 return false;
13815 }
13816
13817 /**
13818 * Clears the DomainSelectionService override.
13819 *
13820 * This should only be used for testing.
13821 * @return {@code true} if the DomainSelectionService override was cleared,
13822 * {@code false} otherwise.
13823 */
13824 @Override
13825 public boolean clearDomainSelectionServiceOverride() {
13826 Log.i(LOG_TAG, "clearDomainSelectionServiceOverride");
13827
13828 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
13829 "clearDomainSelectionServiceOverride");
13830 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13831 getDefaultSubscription(), "clearDomainSelectionServiceOverride");
13832
13833 final long identity = Binder.clearCallingIdentity();
13834 try {
13835 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13836 return DomainSelectionResolver.getInstance()
13837 .clearDomainSelectionServiceOverride();
13838 }
13839 } finally {
13840 Binder.restoreCallingIdentity(identity);
13841 }
13842 return false;
13843 }
13844
13845 /**
Gil Cukierman06403e12023-11-29 16:33:03 +000013846 * Enable or disable notifications sent for cellular identifier disclosure events.
13847 *
13848 * Disclosure events are defined as instances where a device has sent a cellular identifier
13849 * on the Non-access stratum (NAS) before a security context is established. As a result the
13850 * identifier is sent in the clear, which has privacy implications for the user.
13851 *
13852 * @param enable if notifications about disclosure events should be enabled
13853 * @throws SecurityException if the caller does not have the required privileges
13854 * @throws UnsupportedOperationException if the modem does not support this feature.
13855 */
13856 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000013857 public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) {
Gil Cukierman06403e12023-11-29 16:33:03 +000013858 enforceModifyPermission();
13859 checkForIdentifierDisclosureNotificationSupport();
13860
13861 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
13862 editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable);
13863 editor.apply();
13864
13865 // Each phone instance is responsible for updating its respective modem immediately
13866 // after we've made a preference change.
13867 for (Phone phone : PhoneFactory.getPhones()) {
13868 phone.handleIdentifierDisclosureNotificationPreferenceChange();
13869 }
13870 }
13871
13872 /**
13873 * Get whether or not cellular identifier disclosure notifications are enabled.
13874 *
13875 * @throws SecurityException if the caller does not have the required privileges
13876 * @throws UnsupportedOperationException if the modem does not support this feature.
13877 */
13878 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000013879 public boolean isCellularIdentifierDisclosureNotificationsEnabled() {
Gil Cukierman06403e12023-11-29 16:33:03 +000013880 enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled");
13881 checkForIdentifierDisclosureNotificationSupport();
13882 return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled();
13883 }
13884
13885 /**
Michael Groover826b71d2023-12-21 22:08:06 -060013886 * Enables or disables notifications sent when cellular null cipher or integrity algorithms
13887 * are in use by the cellular modem.
13888 *
13889 * @throws IllegalStateException if the Telephony process is not currently available
13890 * @throws SecurityException if the caller does not have the required privileges
13891 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
13892 * and integrity algorithms in use
13893 * @hide
13894 */
13895 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Michael Grooverae447b22024-01-24 22:35:46 -060013896 public void setNullCipherNotificationsEnabled(boolean enable) {
Michael Groover826b71d2023-12-21 22:08:06 -060013897 enforceModifyPermission();
13898 checkForNullCipherNotificationSupport();
13899
13900 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
13901 editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable);
13902 editor.apply();
13903
13904 // Each phone instance is responsible for updating its respective modem immediately
13905 // after a preference change.
13906 for (Phone phone : PhoneFactory.getPhones()) {
13907 phone.handleNullCipherNotificationPreferenceChanged();
13908 }
13909 }
13910
13911 /**
13912 * Get whether notifications are enabled for null cipher or integrity algorithms in use by the
13913 * cellular modem.
13914 *
13915 * @throws IllegalStateException if the Telephony process is not currently available
13916 * @throws SecurityException if the caller does not have the required privileges
13917 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
13918 * and integrity algorithms in use
13919 * @hide
13920 */
13921 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
13922 public boolean isNullCipherNotificationsEnabled() {
13923 enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled");
13924 checkForNullCipherNotificationSupport();
13925 return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled();
13926 }
13927
13928 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000013929 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
13930 *
13931 * <p>This method behaves in one of the following ways:
13932 * <ul>
13933 * <li>return true : if the calling package has the appop permission {@link
13934 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
13935 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
13936 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
13937 * Owner device identifier access check, or the calling package has carrier privileges</>
13938 * <li>throw SecurityException: if the caller does not meet any of the requirements.
13939 * </ul>
13940 */
13941 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
13942 String callingPackage, @Nullable String callingFeatureId, String message) {
13943 for (Phone phone : PhoneFactory.getPhones()) {
13944 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
13945 phone.getSubId(), callingPackage, callingFeatureId, message)) {
13946 return true;
13947 }
13948 }
13949 return false;
13950 }
arunvoddud7401012022-12-15 16:08:12 +000013951
13952 /**
Jack Yufa8ed012023-02-11 15:42:28 -080013953 * @return The subscription manager service instance.
13954 */
13955 public SubscriptionManagerService getSubscriptionManagerService() {
13956 return SubscriptionManagerService.getInstance();
13957 }
13958
13959 /**
arunvoddud7401012022-12-15 16:08:12 +000013960 * Class binds the consumer[callback] and carrierId.
13961 */
13962 private static class CallerCallbackInfo {
13963 private final Consumer<Integer> mConsumer;
13964 private final int mCarrierId;
13965
13966 public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) {
13967 mConsumer = consumer;
13968 mCarrierId = carrierId;
13969 }
13970
13971 public Consumer<Integer> getConsumer() {
13972 return mConsumer;
13973 }
13974
13975 public int getCarrierId() {
13976 return mCarrierId;
13977 }
13978 }
joonhunshin4ac60942023-11-15 15:23:39 +000013979
13980 /*
13981 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
13982 * But the context that is passed in is unused if the phone app is already alive.
13983 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
13984 */
13985 @VisibleForTesting
13986 public void setPackageManager(PackageManager packageManager) {
13987 mPackageManager = packageManager;
13988 }
13989
13990 /*
13991 * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags.
13992 * But the FeatureFlags that is passed in is unused if the phone app is already alive.
13993 * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test.
13994 */
13995 @VisibleForTesting
13996 public void setFeatureFlags(FeatureFlags featureFlags) {
13997 mFeatureFlags = featureFlags;
13998 }
13999
14000 /**
14001 * Make sure the device has required telephony feature
14002 *
14003 * @throws UnsupportedOperationException if the device does not have required telephony feature
14004 */
14005 private void enforceTelephonyFeatureWithException(@Nullable String callingPackage,
14006 @NonNull String telephonyFeature, @NonNull String methodName) {
14007 if (callingPackage == null || mPackageManager == null) {
14008 return;
14009 }
14010
14011 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
14012 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage,
14013 Binder.getCallingUserHandle())) {
14014 return;
14015 }
14016
14017 if (!mPackageManager.hasSystemFeature(telephonyFeature)) {
14018 throw new UnsupportedOperationException(
14019 methodName + " is unsupported without " + telephonyFeature);
14020 }
14021 }
Jack Yufa8ed012023-02-11 15:42:28 -080014022}