blob: 2b8c2acf9defa2ca379054c0d4281c7da9b1ee9d [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;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800159import android.telephony.satellite.ISatelliteProvisionStateCallback;
160import android.telephony.satellite.ISatelliteStateCallback;
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;
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000415
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700416 /** The singleton instance. */
417 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800418 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700419
Sarah Chin4beb2b72023-02-14 14:47:54 -0800420 private final PhoneGlobals mApp;
joonhunshin4ac60942023-11-15 15:23:39 +0000421 private FeatureFlags mFeatureFlags;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800422 private final CallManager mCM;
423 private final ImsResolver mImsResolver;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000424
425 private final SatelliteController mSatelliteController;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800426 private final SatelliteAccessController mSatelliteAccessController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800427 private final UserManager mUserManager;
428 private final AppOpsManager mAppOps;
429 private final MainThreadHandler mMainThreadHandler;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800430 private final SharedPreferences mTelephonySharedPreferences;
431 private final PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800432 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
joonhunshin4ac60942023-11-15 15:23:39 +0000433 private PackageManager mPackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700434
Peter Wangdafb9ac2020-01-15 14:13:38 -0800435 /** User Activity */
Sarah Chin4beb2b72023-02-14 14:47:54 -0800436 private final AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800437 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800438 private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800439
Derek Tan97ebb422014-09-05 16:55:38 -0700440 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
441 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800442 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800443 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700444
Michelecea4cf22018-12-21 15:00:11 -0800445 // String to store multi SIM allowed
446 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
447
Derek Tan740e1672017-06-27 14:56:27 -0700448 // The AID of ISD-R.
449 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
450
yinxub1bed742017-04-17 11:45:04 -0700451 private NetworkScanRequestTracker mNetworkScanRequestTracker;
452
David Kelly5e06a7f2018-03-12 14:10:59 +0000453 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
454 private static final int MANUFACTURER_CODE_LENGTH = 8;
455
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800456 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800457 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800458
Sarah Chin2ec39f62022-08-31 17:03:26 -0700459 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
460 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
461
Derek Tan89e89d42014-07-08 17:00:10 -0700462 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700463 * Experiment flag to enable erase modem config on reset network, default value is false
464 */
465 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
466 "reset_network_erase_modem_config_enabled";
467
Rambo Wang0f050d82021-02-12 11:43:36 -0800468 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800469
Gary Jian76280a42022-12-07 16:18:33 +0800470 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
471
sandeepjsb6c87872021-09-27 15:34:44 +0000472 /**
473 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
474 * one ICCID active at the same time.
475 * Apps should use below API signatures if targeting SDK is T and beyond.
476 *
477 * @hide
478 */
479 @ChangeId
480 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
481 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800482
Naina Nallurid63128d2019-09-17 14:10:30 -0700483 /**
Chen Xu540470b2021-12-14 17:15:47 -0800484 * Apps targeting on Android T and beyond will get exception whenever icc close channel
485 * operation fails.
486 */
487 @ChangeId
488 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
489 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
490
491 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700492 * A request object to use for transmitting data to an ICC.
493 */
494 private static final class IccAPDUArgument {
495 public int channel, cla, command, p1, p2, p3;
496 public String data;
497
498 public IccAPDUArgument(int channel, int cla, int command,
499 int p1, int p2, int p3, String data) {
500 this.channel = channel;
501 this.cla = cla;
502 this.command = command;
503 this.p1 = p1;
504 this.p2 = p2;
505 this.p3 = p3;
506 this.data = data;
507 }
508 }
509
510 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700511 * A request object to use for transmitting data to an ICC.
512 */
513 private static final class ManualNetworkSelectionArgument {
514 public OperatorInfo operatorInfo;
515 public boolean persistSelection;
516
517 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
518 this.operatorInfo = operatorInfo;
519 this.persistSelection = persistSelection;
520 }
521 }
522
Sarah Chin71b3a852022-09-28 15:54:19 -0700523 private static final class PurchasePremiumCapabilityArgument {
524 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700525 public @NonNull IIntegerConsumer callback;
526
527 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800528 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700529 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700530 this.callback = callback;
531 }
532 }
533
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700534 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700535 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
536 * request after sending. The main thread will notify the request when it is complete.
537 */
538 private static final class MainThreadRequest {
539 /** The argument to use for the request */
540 public Object argument;
541 /** The result of the request that is run on the main thread */
542 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800543 // The subscriber id that this request applies to. Defaults to
544 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
545 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700546
Nathan Harold92bed182018-10-12 18:16:49 -0700547 // In cases where subId is unavailable, the caller needs to specify the phone.
548 public Phone phone;
549
vagdeviaf9a5b92018-08-15 16:01:53 -0700550 public WorkSource workSource;
551
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700552 public MainThreadRequest(Object argument) {
553 this.argument = argument;
554 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800555
Nathan Harold92bed182018-10-12 18:16:49 -0700556 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
557 this.argument = argument;
558 if (phone != null) {
559 this.phone = phone;
560 }
561 this.workSource = workSource;
562 }
563
vagdeviaf9a5b92018-08-15 16:01:53 -0700564 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800565 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800566 if (subId != null) {
567 this.subId = subId;
568 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700569 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800570 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700571 }
572
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800573 private static final class IncomingThirdPartyCallArgs {
574 public final ComponentName component;
575 public final String callId;
576 public final String callerDisplayName;
577
578 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
579 String callerDisplayName) {
580 this.component = component;
581 this.callId = callId;
582 this.callerDisplayName = callerDisplayName;
583 }
584 }
585
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700586 /**
587 * A handler that processes messages on the main thread in the phone process. Since many
588 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
589 * inbound binder threads to the main thread in the phone process. The Binder thread
590 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
591 * on, which will be notified when the operation completes and will contain the result of the
592 * request.
593 *
594 * <p>If a MainThreadRequest object is provided in the msg.obj field,
595 * note that request.result must be set to something non-null for the calling thread to
596 * unblock.
597 */
598 private final class MainThreadHandler extends Handler {
599 @Override
600 public void handleMessage(Message msg) {
601 MainThreadRequest request;
602 Message onCompleted;
603 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000604 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700605 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800606 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700607
608 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700609 case CMD_HANDLE_USSD_REQUEST: {
610 request = (MainThreadRequest) msg.obj;
611 final Phone phone = getPhoneFromRequest(request);
612 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800613 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700614 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700615
Pengquan Menga1bb6272018-09-06 09:59:22 -0700616 if (!isUssdApiAllowed(request.subId)) {
617 // Carrier does not support use of this API, return failure.
618 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
619 UssdResponse response = new UssdResponse(ussdRequest, null);
620 Bundle returnData = new Bundle();
621 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
622 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700623
Pengquan Menga1bb6272018-09-06 09:59:22 -0700624 request.result = true;
625 notifyRequester(request);
626 return;
627 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700628
Pengquan Menga1bb6272018-09-06 09:59:22 -0700629 try {
630 request.result = phone != null
631 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
632 } catch (CallStateException cse) {
633 request.result = false;
634 }
635 // Wake up the requesting thread
636 notifyRequester(request);
637 break;
pkanwar32d516d2016-10-14 19:37:38 -0700638 }
639
Yorke Lee716f67e2015-06-17 15:39:16 -0700640 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700641 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700642 final Phone phone = getPhoneFromRequest(request);
643 request.result = phone != null ?
644 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
645 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700646 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700647 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700648 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700649 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700650
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700651 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700652 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700653 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000654 uiccPort = getUiccPortFromRequest(request);
655 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700656 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800657 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700658 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700659 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700660 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800661 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000662 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800663 iccArgument.channel, iccArgument.cla, iccArgument.command,
664 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
665 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700666 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700667 break;
668
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700669 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700670 ar = (AsyncResult) msg.obj;
671 request = (MainThreadRequest) ar.userObj;
672 if (ar.exception == null && ar.result != null) {
673 request.result = ar.result;
674 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800675 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700676 if (ar.result == null) {
677 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800678 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700679 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800680 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700681 } else {
682 loge("iccTransmitApduLogicalChannel: Unknown exception");
683 }
684 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700685 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700686 break;
687
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700688 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
689 request = (MainThreadRequest) msg.obj;
690 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000691 uiccPort = getUiccPortFromRequest(request);
692 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700693 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800694 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700695 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700696 } else {
697 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800698 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000699 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800700 iccArgument.cla, iccArgument.command, iccArgument.p1,
701 iccArgument.p2,
702 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700703 }
704 break;
705
706 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
707 ar = (AsyncResult) msg.obj;
708 request = (MainThreadRequest) ar.userObj;
709 if (ar.exception == null && ar.result != null) {
710 request.result = ar.result;
711 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800712 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700713 if (ar.result == null) {
714 loge("iccTransmitApduBasicChannel: Empty response");
715 } else if (ar.exception instanceof CommandException) {
716 loge("iccTransmitApduBasicChannel: CommandException: " +
717 ar.exception);
718 } else {
719 loge("iccTransmitApduBasicChannel: Unknown exception");
720 }
721 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700722 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700723 break;
724
725 case CMD_EXCHANGE_SIM_IO:
726 request = (MainThreadRequest) msg.obj;
727 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000728 uiccPort = getUiccPortFromRequest(request);
729 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700730 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800731 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700732 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700733 } else {
734 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
735 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000736 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700737 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
738 iccArgument.data, onCompleted);
739 }
740 break;
741
742 case EVENT_EXCHANGE_SIM_IO_DONE:
743 ar = (AsyncResult) msg.obj;
744 request = (MainThreadRequest) ar.userObj;
745 if (ar.exception == null && ar.result != null) {
746 request.result = ar.result;
747 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800748 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700749 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700750 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700751 break;
752
Derek Tan4d5e5c12014-02-04 11:54:58 -0800753 case CMD_SEND_ENVELOPE:
754 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000755 uiccPort = getUiccPortFromRequest(request);
756 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700757 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800758 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700759 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700760 } else {
761 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800762 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700763 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800764 break;
765
766 case EVENT_SEND_ENVELOPE_DONE:
767 ar = (AsyncResult) msg.obj;
768 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700769 if (ar.exception == null && ar.result != null) {
770 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800771 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800772 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700773 if (ar.result == null) {
774 loge("sendEnvelopeWithStatus: Empty response");
775 } else if (ar.exception instanceof CommandException) {
776 loge("sendEnvelopeWithStatus: CommandException: " +
777 ar.exception);
778 } else {
779 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
780 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800781 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700782 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800783 break;
784
Shishir Agrawal566b7612013-10-28 14:41:00 -0700785 case CMD_OPEN_CHANNEL:
786 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000787 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800788 IccLogicalChannelRequest openChannelRequest =
789 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000790 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700791 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800792 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800793 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700794 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700795 } else {
796 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800797 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
798 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700799 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700800 break;
801
802 case EVENT_OPEN_CHANNEL_DONE:
803 ar = (AsyncResult) msg.obj;
804 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700805 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700806 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700807 int[] result = (int[]) ar.result;
808 int channelId = result[0];
809 byte[] selectResponse = null;
810 if (result.length > 1) {
811 selectResponse = new byte[result.length - 1];
812 for (int i = 1; i < result.length; ++i) {
813 selectResponse[i - 1] = (byte) result[i];
814 }
815 }
816 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800817 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800818
819 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700820 if (uiccPort == null) {
821 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
822 } else {
823 IccLogicalChannelRequest channelRequest =
824 (IccLogicalChannelRequest) request.argument;
825 channelRequest.channel = channelId;
826 uiccPort.onLogicalChannelOpened(channelRequest);
827 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700828 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700829 if (ar.result == null) {
830 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700831 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700832 if (ar.exception != null) {
833 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
834 }
835
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700836 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700837 if (ar.exception instanceof CommandException) {
838 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800839 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700840 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700841 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700842 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700843 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700844 }
845 }
846 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800847 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700848 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700849 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700850 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700851 break;
852
853 case CMD_CLOSE_CHANNEL:
854 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000855 uiccPort = getUiccPortFromRequest(request);
856 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700857 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800858 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800859 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800860 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700861 } else {
862 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000863 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700864 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700865 break;
866
867 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800868 ar = (AsyncResult) msg.obj;
869 request = (MainThreadRequest) ar.userObj;
870 if (ar.exception == null) {
871 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800872 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700873 if (uiccPort == null) {
874 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
875 } else {
876 final int channelId = (Integer) request.argument;
877 uiccPort.onLogicalChannelClosed(channelId);
878 }
Chen Xu540470b2021-12-14 17:15:47 -0800879 } else {
880 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800881 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800882 if (ar.exception instanceof CommandException) {
883 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
884 CommandException.Error error =
885 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800886 if (error == CommandException.Error.INVALID_ARGUMENTS) {
887 // should only throw exceptions from the binder threads.
888 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800889 "iccCloseLogicalChannel: invalid argument ");
890 }
891 } else {
892 loge("iccCloseLogicalChannel: Unknown exception");
893 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800894 request.result = (exception != null) ? exception :
895 new IllegalStateException(
896 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800897 }
898 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800899 break;
900
901 case CMD_NV_READ_ITEM:
902 request = (MainThreadRequest) msg.obj;
903 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800904 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
905 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800906 break;
907
908 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700909 ar = (AsyncResult) msg.obj;
910 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800911 if (ar.exception == null && ar.result != null) {
912 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700913 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800914 request.result = "";
915 if (ar.result == null) {
916 loge("nvReadItem: Empty response");
917 } else if (ar.exception instanceof CommandException) {
918 loge("nvReadItem: CommandException: " +
919 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700920 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800921 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700922 }
923 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700924 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700925 break;
926
Jake Hambye994d462014-02-03 13:10:13 -0800927 case CMD_NV_WRITE_ITEM:
928 request = (MainThreadRequest) msg.obj;
929 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
930 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800931 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700932 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800933 break;
934
935 case EVENT_NV_WRITE_ITEM_DONE:
936 handleNullReturnEvent(msg, "nvWriteItem");
937 break;
938
939 case CMD_NV_WRITE_CDMA_PRL:
940 request = (MainThreadRequest) msg.obj;
941 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800942 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800943 break;
944
945 case EVENT_NV_WRITE_CDMA_PRL_DONE:
946 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
947 break;
948
chen xu6dac5ab2018-10-26 17:39:23 -0700949 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800950 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700951 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800952 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800953 break;
954
chen xu6dac5ab2018-10-26 17:39:23 -0700955 case EVENT_RESET_MODEM_CONFIG_DONE:
956 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800957 break;
958
Sooraj Sasindran37444802020-08-11 10:40:43 -0700959 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
960 request = (MainThreadRequest) msg.obj;
961 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
962 request);
963 Phone phone = getPhoneFromRequest(request);
964 if (phone != null) {
965 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
966 } else {
967 loge("isNRDualConnectivityEnabled: No phone object");
968 request.result = false;
969 notifyRequester(request);
970 }
971 break;
972 }
973
974 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
975 ar = (AsyncResult) msg.obj;
976 request = (MainThreadRequest) ar.userObj;
977 if (ar.exception == null && ar.result != null) {
978 request.result = ar.result;
979 } else {
980 // request.result must be set to something non-null
981 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700982 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700983 request.result = ar.result;
984 } else {
985 request.result = false;
986 }
987 if (ar.result == null) {
988 loge("isNRDualConnectivityEnabled: Empty response");
989 } else if (ar.exception instanceof CommandException) {
990 loge("isNRDualConnectivityEnabled: CommandException: "
991 + ar.exception);
992 } else {
993 loge("isNRDualConnectivityEnabled: Unknown exception");
994 }
995 }
996 notifyRequester(request);
997 break;
998
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700999 case CMD_IS_VONR_ENABLED: {
1000 request = (MainThreadRequest) msg.obj;
1001 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
1002 request);
1003 Phone phone = getPhoneFromRequest(request);
1004 if (phone != null) {
1005 phone.isVoNrEnabled(onCompleted, request.workSource);
1006 } else {
1007 loge("isVoNrEnabled: No phone object");
1008 request.result = false;
1009 notifyRequester(request);
1010 }
1011 break;
1012 }
1013
1014 case EVENT_IS_VONR_ENABLED_DONE:
1015 ar = (AsyncResult) msg.obj;
1016 request = (MainThreadRequest) ar.userObj;
1017 if (ar.exception == null && ar.result != null) {
1018 request.result = ar.result;
1019 } else {
1020 // request.result must be set to something non-null
1021 // for the calling thread to unblock
1022 if (ar.result != null) {
1023 request.result = ar.result;
1024 } else {
1025 request.result = false;
1026 }
1027 if (ar.result == null) {
1028 loge("isVoNrEnabled: Empty response");
1029 } else if (ar.exception instanceof CommandException) {
1030 loge("isVoNrEnabled: CommandException: "
1031 + ar.exception);
1032 } else {
1033 loge("isVoNrEnabled: Unknown exception");
1034 }
1035 }
1036 notifyRequester(request);
1037 break;
1038
Sooraj Sasindran37444802020-08-11 10:40:43 -07001039 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1040 request = (MainThreadRequest) msg.obj;
1041 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1042 Phone phone = getPhoneFromRequest(request);
1043 if (phone != null) {
1044 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1045 request.workSource);
1046 } else {
1047 loge("enableNrDualConnectivity: No phone object");
1048 request.result =
1049 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1050 notifyRequester(request);
1051 }
1052 break;
1053 }
1054
1055 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1056 ar = (AsyncResult) msg.obj;
1057 request = (MainThreadRequest) ar.userObj;
1058 if (ar.exception == null) {
1059 request.result =
1060 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1061 } else {
1062 request.result =
1063 TelephonyManager
1064 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1065 if (ar.exception instanceof CommandException) {
1066 CommandException.Error error =
1067 ((CommandException) (ar.exception)).getCommandError();
1068 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1069 request.result =
1070 TelephonyManager
1071 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001072 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1073 request.result =
1074 TelephonyManager
1075 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001076 }
1077 loge("enableNrDualConnectivity" + ": CommandException: "
1078 + ar.exception);
1079 } else {
1080 loge("enableNrDualConnectivity" + ": Unknown exception");
1081 }
1082 }
1083 notifyRequester(request);
1084 break;
1085 }
1086
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001087 case CMD_ENABLE_VONR: {
1088 request = (MainThreadRequest) msg.obj;
1089 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1090 Phone phone = getPhoneFromRequest(request);
1091 if (phone != null) {
1092 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1093 request.workSource);
1094 } else {
1095 loge("setVoNrEnabled: No phone object");
1096 request.result =
1097 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1098 notifyRequester(request);
1099 }
1100 break;
1101 }
1102
1103 case EVENT_ENABLE_VONR_DONE: {
1104 ar = (AsyncResult) msg.obj;
1105 request = (MainThreadRequest) ar.userObj;
1106 if (ar.exception == null) {
1107 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1108 } else {
1109 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1110 if (ar.exception instanceof CommandException) {
1111 CommandException.Error error =
1112 ((CommandException) (ar.exception)).getCommandError();
1113 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1114 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1115 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1116 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1117 } else {
1118 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1119 }
1120 loge("setVoNrEnabled" + ": CommandException: "
1121 + ar.exception);
1122 } else {
1123 loge("setVoNrEnabled" + ": Unknown exception");
1124 }
1125 }
1126 notifyRequester(request);
1127 break;
1128 }
1129
SongFerngWang3ef3e072020-12-21 16:41:52 +08001130 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001131 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001132 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1133 request);
1134 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001135 break;
1136
SongFerngWang3ef3e072020-12-21 16:41:52 +08001137 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001138 ar = (AsyncResult) msg.obj;
1139 request = (MainThreadRequest) ar.userObj;
1140 if (ar.exception == null && ar.result != null) {
1141 request.result = ar.result; // Integer
1142 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301143 // request.result must be set to something non-null
1144 // for the calling thread to unblock
1145 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001146 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001147 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001148 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001149 loge("getAllowedNetworkTypesBitmask: CommandException: "
1150 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001151 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001152 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001153 }
1154 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001155 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001156 break;
1157
SongFerngWang3ef3e072020-12-21 16:41:52 +08001158 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001159 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001160 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1161 request);
1162 Pair<Integer, Long> reasonWithNetworkTypes =
1163 (Pair<Integer, Long>) request.argument;
1164 getPhoneFromRequest(request).setAllowedNetworkTypes(
1165 reasonWithNetworkTypes.first,
1166 reasonWithNetworkTypes.second,
1167 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001168 break;
1169
SongFerngWang3ef3e072020-12-21 16:41:52 +08001170 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1171 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001172 break;
1173
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001174 case CMD_SET_VOICEMAIL_NUMBER:
1175 request = (MainThreadRequest) msg.obj;
1176 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1177 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001178 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1179 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001180 break;
1181
1182 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1183 handleNullReturnEvent(msg, "setVoicemailNumber");
1184 break;
1185
Stuart Scott54788802015-03-30 13:18:01 -07001186 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1187 request = (MainThreadRequest) msg.obj;
1188 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1189 request);
1190 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1191 break;
1192
1193 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1194 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1195 break;
1196
Shishir Agrawal302c8692015-06-19 13:49:39 -07001197 case CMD_PERFORM_NETWORK_SCAN:
1198 request = (MainThreadRequest) msg.obj;
1199 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1200 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1201 break;
1202
Hall Liu27d24262020-09-18 19:04:59 -07001203 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001204 request = (MainThreadRequest) msg.obj;
1205 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001206 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1207 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1208 request.argument;
1209 int callForwardingReason = args.first;
1210 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001211 break;
Hall Liu27d24262020-09-18 19:04:59 -07001212 }
1213 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001214 ar = (AsyncResult) msg.obj;
1215 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001216 TelephonyManager.CallForwardingInfoCallback callback =
1217 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1218 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001219 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001220 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001221 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1222 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1223 // Service Class is a bit mask per 3gpp 27.007. Search for
1224 // any service for voice call.
1225 if ((callForwardInfo.serviceClass
1226 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001227 callForwardingInfo = new CallForwardingInfo(
1228 callForwardInfo.status
1229 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001230 callForwardInfo.reason,
1231 callForwardInfo.number,
1232 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001233 break;
1234 }
1235 }
1236 // Didn't find a call forward info for voice call.
1237 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001238 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1239 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001240 }
Hall Liu27d24262020-09-18 19:04:59 -07001241 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001242 } else {
1243 if (ar.result == null) {
1244 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1245 }
1246 if (ar.exception != null) {
1247 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1248 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001249 int errorCode = TelephonyManager
1250 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001251 if (ar.exception instanceof CommandException) {
1252 CommandException.Error error =
1253 ((CommandException) (ar.exception)).getCommandError();
1254 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001255 errorCode = TelephonyManager
1256 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001257 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001258 errorCode = TelephonyManager
1259 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001260 }
1261 }
Hall Liu27d24262020-09-18 19:04:59 -07001262 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001263 }
Shuo Qian4a594052020-01-23 11:59:30 -08001264 break;
Hall Liu27d24262020-09-18 19:04:59 -07001265 }
Shuo Qian4a594052020-01-23 11:59:30 -08001266
Hall Liu27d24262020-09-18 19:04:59 -07001267 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001268 request = (MainThreadRequest) msg.obj;
1269 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001270 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001271 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001272 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1273 request.argument).first;
1274 request.phone.setCallForwardingOption(
1275 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001276 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001277 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001278 callForwardingInfoToSet.getReason(),
1279 callForwardingInfoToSet.getNumber(),
1280 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1281 break;
Hall Liu27d24262020-09-18 19:04:59 -07001282 }
Shuo Qian4a594052020-01-23 11:59:30 -08001283
Hall Liu27d24262020-09-18 19:04:59 -07001284 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001285 ar = (AsyncResult) msg.obj;
1286 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001287 Consumer<Integer> callback =
1288 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1289 request.argument).second;
1290 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001291 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001292 int errorCode = TelephonyManager.CallForwardingInfoCallback
1293 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001294 if (ar.exception instanceof CommandException) {
1295 CommandException.Error error =
1296 ((CommandException) (ar.exception)).getCommandError();
1297 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001298 errorCode = TelephonyManager.CallForwardingInfoCallback
1299 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001300 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001301 errorCode = TelephonyManager.CallForwardingInfoCallback
1302 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001303 }
1304 }
1305 callback.accept(errorCode);
1306 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001307 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001308 }
Shuo Qian4a594052020-01-23 11:59:30 -08001309 break;
Hall Liu27d24262020-09-18 19:04:59 -07001310 }
Shuo Qian4a594052020-01-23 11:59:30 -08001311
Hall Liu27d24262020-09-18 19:04:59 -07001312 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001313 request = (MainThreadRequest) msg.obj;
1314 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1315 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1316 break;
Hall Liu27d24262020-09-18 19:04:59 -07001317 }
Shuo Qian4a594052020-01-23 11:59:30 -08001318
Hall Liu27d24262020-09-18 19:04:59 -07001319 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001320 ar = (AsyncResult) msg.obj;
1321 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001322 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001323 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001324 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001325 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001326 // Service Class is a bit mask per 3gpp 27.007.
1327 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001328 if (callForwardResults.length > 1
1329 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001330 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001331 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001332 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1333 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001334 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001335 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001336 }
1337 } else {
1338 if (ar.result == null) {
1339 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1340 }
1341 if (ar.exception != null) {
1342 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1343 }
1344 if (ar.exception instanceof CommandException) {
1345 CommandException.Error error =
1346 ((CommandException) (ar.exception)).getCommandError();
1347 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001348 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001349 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001350 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1351 callWaitingStatus =
1352 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001353 }
1354 }
1355 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001356 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001357 break;
Hall Liu27d24262020-09-18 19:04:59 -07001358 }
Shuo Qian4a594052020-01-23 11:59:30 -08001359
Hall Liu27d24262020-09-18 19:04:59 -07001360 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001361 request = (MainThreadRequest) msg.obj;
1362 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001363 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1364 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001365 break;
Hall Liu27d24262020-09-18 19:04:59 -07001366 }
Shuo Qian4a594052020-01-23 11:59:30 -08001367
Hall Liu27d24262020-09-18 19:04:59 -07001368 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001369 ar = (AsyncResult) msg.obj;
1370 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001371 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1372 Consumer<Integer> callback =
1373 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1374 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001375 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001376 if (ar.exception instanceof CommandException) {
1377 CommandException.Error error =
1378 ((CommandException) (ar.exception)).getCommandError();
1379 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1380 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001381 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1382 callback.accept(
1383 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001384 } else {
1385 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1386 }
1387 } else {
1388 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1389 }
1390 } else {
1391 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1392 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001393 }
Shuo Qian4a594052020-01-23 11:59:30 -08001394 break;
Hall Liu27d24262020-09-18 19:04:59 -07001395 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001396 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1397 ar = (AsyncResult) msg.obj;
1398 request = (MainThreadRequest) ar.userObj;
1399 CellNetworkScanResult cellScanResult;
1400 if (ar.exception == null && ar.result != null) {
1401 cellScanResult = new CellNetworkScanResult(
1402 CellNetworkScanResult.STATUS_SUCCESS,
1403 (List<OperatorInfo>) ar.result);
1404 } else {
1405 if (ar.result == null) {
1406 loge("getCellNetworkScanResults: Empty response");
1407 }
1408 if (ar.exception != null) {
1409 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1410 }
1411 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1412 if (ar.exception instanceof CommandException) {
1413 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001414 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001415 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1416 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1417 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1418 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1419 }
1420 }
1421 cellScanResult = new CellNetworkScanResult(errorCode, null);
1422 }
1423 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001424 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001425 break;
1426
1427 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1428 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001429 ManualNetworkSelectionArgument selArg =
1430 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001431 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1432 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001433 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1434 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001435 break;
1436
1437 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001438 ar = (AsyncResult) msg.obj;
1439 request = (MainThreadRequest) ar.userObj;
1440 if (ar.exception == null) {
1441 request.result = true;
1442 } else {
1443 request.result = false;
1444 loge("setNetworkSelectionModeManual " + ar.exception);
1445 }
1446 notifyRequester(request);
1447 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001448 break;
1449
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001450 case CMD_GET_MODEM_ACTIVITY_INFO:
1451 request = (MainThreadRequest) msg.obj;
1452 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001453 if (defaultPhone != null) {
1454 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001455 } else {
1456 ResultReceiver result = (ResultReceiver) request.argument;
1457 Bundle bundle = new Bundle();
1458 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001459 new ModemActivityInfo(0, 0, 0,
1460 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001461 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001462 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001463 break;
1464
Hall Liud0f208c2020-10-14 16:54:44 -07001465 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001466 ar = (AsyncResult) msg.obj;
1467 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001468 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001469 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001470 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001471 if (mLastModemActivityInfo == null) {
1472 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1473 mLastModemActivitySpecificInfo[0] =
1474 new ActivityStatsTechSpecificInfo(
1475 0,
1476 0,
1477 new int[ModemActivityInfo.getNumTxPowerLevels()],
1478 0);
1479 mLastModemActivityInfo =
1480 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1481 }
1482
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001483 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001484 // Update the last modem activity info and the result of the request.
1485 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1486 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001487 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001488 } else {
1489 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001490 }
Kai Shi917fdc62022-11-28 14:01:02 -08001491 // This is needed to decouple ret from mLastModemActivityInfo
1492 // We don't want to return mLastModemActivityInfo which is updated
1493 // inside mergeModemActivityInfo()
1494 ret = new ModemActivityInfo(
1495 mLastModemActivityInfo.getTimestampMillis(),
1496 mLastModemActivityInfo.getSleepTimeMillis(),
1497 mLastModemActivityInfo.getIdleTimeMillis(),
1498 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001499
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001500 } else {
1501 if (ar.result == null) {
1502 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001503 error = TelephonyManager.ModemActivityInfoException
1504 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001505 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001506 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001507 error = TelephonyManager.ModemActivityInfoException
1508 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001509 } else {
1510 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001511 error = TelephonyManager.ModemActivityInfoException
1512 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001513 }
1514 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001515 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001516 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001517 bundle.putParcelable(
1518 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001519 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001520 } else {
1521 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1522 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001523 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001524 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001525 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001526 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001527
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001528 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001529 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001530 CarrierRestrictionRules argument =
1531 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001532 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001533 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001534 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001535 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001536
1537 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1538 ar = (AsyncResult) msg.obj;
1539 request = (MainThreadRequest) ar.userObj;
1540 if (ar.exception == null && ar.result != null) {
1541 request.result = ar.result;
1542 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001543 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1544 if (ar.exception instanceof CommandException) {
1545 loge("setAllowedCarriers: CommandException: " + ar.exception);
1546 CommandException.Error error =
1547 ((CommandException) (ar.exception)).getCommandError();
1548 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1549 request.result =
1550 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1551 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001552 } else {
1553 loge("setAllowedCarriers: Unknown exception");
1554 }
1555 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001556 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001557 break;
1558
1559 case CMD_GET_ALLOWED_CARRIERS:
1560 request = (MainThreadRequest) msg.obj;
1561 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001562 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001563 break;
1564
1565 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1566 ar = (AsyncResult) msg.obj;
1567 request = (MainThreadRequest) ar.userObj;
1568 if (ar.exception == null && ar.result != null) {
1569 request.result = ar.result;
1570 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001571 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001572 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001573 if (ar.result == null) {
1574 loge("getAllowedCarriers: Empty response");
1575 } else if (ar.exception instanceof CommandException) {
1576 loge("getAllowedCarriers: CommandException: " +
1577 ar.exception);
1578 } else {
1579 loge("getAllowedCarriers: Unknown exception");
1580 }
1581 }
arunvoddud7401012022-12-15 16:08:12 +00001582 if (request.argument != null) {
1583 // This is for the implementation of carrierRestrictionStatus.
1584 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1585 Consumer<Integer> callback = callbackInfo.getConsumer();
1586 int callerCarrierId = callbackInfo.getCarrierId();
1587 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1588 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1589 CarrierRestrictionRules carrierRestrictionRules =
1590 (CarrierRestrictionRules) ar.result;
1591 int carrierId = -1;
1592 try {
1593 CarrierIdentifier carrierIdentifier =
1594 carrierRestrictionRules.getAllowedCarriers().get(0);
1595 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1596 carrierIdentifier);
1597 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1598 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1599 }
1600 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
1601 if (carrierId != -1 && callerCarrierId == carrierId && lockStatus
1602 == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001603 lockStatus = TelephonyManager
1604 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001605 }
1606 } else {
1607 Rlog.e(LOG_TAG,
1608 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1609 }
1610 callback.accept(lockStatus);
1611 } else {
1612 // This is for the implementation of getAllowedCarriers.
1613 notifyRequester(request);
1614 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001615 break;
1616
Nathan Haroldb3014052017-01-25 15:57:32 -08001617 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1618 ar = (AsyncResult) msg.obj;
1619 request = (MainThreadRequest) ar.userObj;
1620 if (ar.exception == null && ar.result != null) {
1621 request.result = ar.result;
1622 } else {
1623 request.result = new IllegalArgumentException(
1624 "Failed to retrieve Forbidden Plmns");
1625 if (ar.result == null) {
1626 loge("getForbiddenPlmns: Empty response");
1627 } else {
1628 loge("getForbiddenPlmns: Unknown exception");
1629 }
1630 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001631 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001632 break;
1633
1634 case CMD_GET_FORBIDDEN_PLMNS:
1635 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001636 uiccPort = getUiccPortFromRequest(request);
1637 if (uiccPort == null) {
1638 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001639 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001640 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001641 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001642 break;
1643 }
1644 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001645 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001646 if (uiccApp == null) {
1647 loge("getForbiddenPlmns() no app with specified type -- "
1648 + appType);
1649 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001650 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001651 break;
1652 } else {
1653 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1654 + " specified type -- " + appType);
1655 }
1656 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1657 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001658 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001659 break;
1660
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001661 case CMD_SWITCH_SLOTS:
1662 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001663 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001664 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001665 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001666 break;
1667
1668 case EVENT_SWITCH_SLOTS_DONE:
1669 ar = (AsyncResult) msg.obj;
1670 request = (MainThreadRequest) ar.userObj;
1671 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001672 notifyRequester(request);
1673 break;
1674 case CMD_GET_NETWORK_SELECTION_MODE:
1675 request = (MainThreadRequest) msg.obj;
1676 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1677 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1678 break;
1679
1680 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1681 ar = (AsyncResult) msg.obj;
1682 request = (MainThreadRequest) ar.userObj;
1683 if (ar.exception != null) {
1684 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1685 } else {
1686 int mode = ((int[]) ar.result)[0];
1687 if (mode == 0) {
1688 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1689 } else {
1690 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1691 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001692 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001693 notifyRequester(request);
1694 break;
1695 case CMD_GET_CDMA_ROAMING_MODE:
1696 request = (MainThreadRequest) msg.obj;
1697 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1698 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1699 break;
1700 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1701 ar = (AsyncResult) msg.obj;
1702 request = (MainThreadRequest) ar.userObj;
1703 if (ar.exception != null) {
1704 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1705 } else {
1706 request.result = ((int[]) ar.result)[0];
1707 }
1708 notifyRequester(request);
1709 break;
1710 case CMD_SET_CDMA_ROAMING_MODE:
1711 request = (MainThreadRequest) msg.obj;
1712 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1713 int mode = (int) request.argument;
1714 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1715 break;
1716 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1717 ar = (AsyncResult) msg.obj;
1718 request = (MainThreadRequest) ar.userObj;
1719 request.result = ar.exception == null;
1720 notifyRequester(request);
1721 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001722 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1723 request = (MainThreadRequest) msg.obj;
1724 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1725 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1726 break;
1727 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1728 ar = (AsyncResult) msg.obj;
1729 request = (MainThreadRequest) ar.userObj;
1730 if (ar.exception != null) {
1731 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1732 } else {
1733 request.result = ((int[]) ar.result)[0];
1734 }
1735 notifyRequester(request);
1736 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001737 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1738 request = (MainThreadRequest) msg.obj;
1739 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1740 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001741 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1742 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001743 break;
1744 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1745 ar = (AsyncResult) msg.obj;
1746 request = (MainThreadRequest) ar.userObj;
1747 request.result = ar.exception == null;
1748 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001749 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001750 case CMD_GET_ALL_CELL_INFO:
1751 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001752 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001753 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001754 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001755 case EVENT_GET_ALL_CELL_INFO_DONE:
1756 ar = (AsyncResult) msg.obj;
1757 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001758 // If a timeout occurs, the response will be null
1759 request.result = (ar.exception == null && ar.result != null)
1760 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001761 synchronized (request) {
1762 request.notifyAll();
1763 }
1764 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001765 case CMD_REQUEST_CELL_INFO_UPDATE:
1766 request = (MainThreadRequest) msg.obj;
1767 request.phone.requestCellInfoUpdate(request.workSource,
1768 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1769 break;
1770 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1771 ar = (AsyncResult) msg.obj;
1772 request = (MainThreadRequest) ar.userObj;
1773 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1774 try {
1775 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001776 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001777 cb.onError(
1778 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1779 ar.exception.getClass().getName(),
1780 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001781 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001782 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001783 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001784 } else {
1785 // use the result as returned
1786 cb.onCellInfo((List<CellInfo>) ar.result);
1787 }
1788 } catch (RemoteException re) {
1789 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1790 }
1791 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001792 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001793 request = (MainThreadRequest) msg.obj;
1794 WorkSource ws = (WorkSource) request.argument;
1795 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001796 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001797 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001798 }
1799 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001800 ar = (AsyncResult) msg.obj;
1801 request = (MainThreadRequest) ar.userObj;
1802 if (ar.exception == null) {
1803 request.result = ar.result;
1804 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001805 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001806 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001807 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001808 }
1809
1810 synchronized (request) {
1811 request.notifyAll();
1812 }
1813 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001814 }
chen xu6dac5ab2018-10-26 17:39:23 -07001815 case CMD_MODEM_REBOOT:
1816 request = (MainThreadRequest) msg.obj;
1817 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001818 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001819 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001820 case EVENT_CMD_MODEM_REBOOT_DONE:
1821 handleNullReturnEvent(msg, "rebootModem");
1822 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001823 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001824 request = (MainThreadRequest) msg.obj;
1825 boolean enable = (boolean) request.argument;
1826 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001827 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001828 PhoneConfigurationManager.getInstance()
1829 .enablePhone(request.phone, enable, onCompleted);
1830 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001831 }
Michele Berionne5e411512020-11-13 02:36:59 +00001832 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001833 ar = (AsyncResult) msg.obj;
1834 request = (MainThreadRequest) ar.userObj;
1835 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001836 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001837 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001838 if ((boolean) request.result) {
1839 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1840 updateModemStateMetrics();
1841 } else {
1842 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1843 + ar.exception);
1844 }
1845 notifyRequester(request);
1846 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001847 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001848 case CMD_GET_MODEM_STATUS:
1849 request = (MainThreadRequest) msg.obj;
1850 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1851 PhoneConfigurationManager.getInstance()
1852 .getPhoneStatusFromModem(request.phone, onCompleted);
1853 break;
1854 case EVENT_GET_MODEM_STATUS_DONE:
1855 ar = (AsyncResult) msg.obj;
1856 request = (MainThreadRequest) ar.userObj;
1857 int id = request.phone.getPhoneId();
1858 if (ar.exception == null && ar.result != null) {
1859 request.result = ar.result;
1860 //update the cache as modem status has changed
1861 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1862 (boolean) request.result);
1863 } else {
1864 // Return true if modem status cannot be retrieved. For most cases,
1865 // modem status is on. And for older version modems, GET_MODEM_STATUS
1866 // and disable modem are not supported. Modem is always on.
1867 // TODO: this should be fixed in R to support a third
1868 // status UNKNOWN b/131631629
1869 request.result = true;
1870 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1871 + ar.exception);
1872 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001873 notifyRequester(request);
1874 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001875 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1876 request = (MainThreadRequest) msg.obj;
1877 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1878 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1879 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1880 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1881 break;
1882 }
1883 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1884 ar = (AsyncResult) msg.obj;
1885 request = (MainThreadRequest) ar.userObj;
1886 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1887 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1888 args.second.accept(ar.exception == null);
1889 notifyRequester(request);
1890 break;
1891 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001892 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1893 request = (MainThreadRequest) msg.obj;
1894 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1895 Phone phone = getPhoneFromRequest(request);
1896 if (phone != null) {
1897 phone.getSystemSelectionChannels(onCompleted);
1898 } else {
1899 loge("getSystemSelectionChannels: No phone object");
1900 request.result = new ArrayList<RadioAccessSpecifier>();
1901 notifyRequester(request);
1902 }
1903 break;
1904 }
1905 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1906 ar = (AsyncResult) msg.obj;
1907 request = (MainThreadRequest) ar.userObj;
1908 if (ar.exception == null && ar.result != null) {
1909 request.result = ar.result;
1910 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001911 request.result = new IllegalStateException(
1912 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001913 if (ar.result == null) {
1914 loge("getSystemSelectionChannels: Empty response");
1915 } else {
1916 loge("getSystemSelectionChannels: Unknown exception");
1917 }
1918 }
1919 notifyRequester(request);
1920 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001921 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1922 ar = (AsyncResult) msg.obj;
1923 request = (MainThreadRequest) ar.userObj;
1924 if (ar.exception == null && ar.result != null) {
1925 request.result = ar.result;
1926 } else {
1927 request.result = -1;
1928 loge("Failed to set Forbidden Plmns");
1929 if (ar.result == null) {
1930 loge("setForbidenPlmns: Empty response");
1931 } else if (ar.exception != null) {
1932 loge("setForbiddenPlmns: Exception: " + ar.exception);
1933 request.result = -1;
1934 } else {
1935 loge("setForbiddenPlmns: Unknown exception");
1936 }
1937 }
1938 notifyRequester(request);
1939 break;
1940 case CMD_SET_FORBIDDEN_PLMNS:
1941 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001942 uiccPort = getUiccPortFromRequest(request);
1943 if (uiccPort == null) {
1944 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001945 request.result = -1;
1946 notifyRequester(request);
1947 break;
1948 }
1949 Pair<Integer, List<String>> setFplmnsArgs =
1950 (Pair<Integer, List<String>>) request.argument;
1951 appType = setFplmnsArgs.first;
1952 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001953 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001954 if (uiccApp == null) {
1955 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1956 request.result = -1;
1957 loge("Failed to get UICC App");
1958 notifyRequester(request);
1959 } else {
1960 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1961 ((SIMRecords) uiccApp.getIccRecords())
1962 .setForbiddenPlmns(onCompleted, fplmns);
1963 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001964 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001965 case CMD_ERASE_MODEM_CONFIG:
1966 request = (MainThreadRequest) msg.obj;
1967 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1968 defaultPhone.eraseModemConfig(onCompleted);
1969 break;
1970 case EVENT_ERASE_MODEM_CONFIG_DONE:
1971 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001972 break;
zoey chene02881a2019-12-30 16:11:23 +08001973
Kai Shif70f46f2021-03-03 13:59:46 -08001974 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1975 request = (MainThreadRequest) msg.obj;
1976 request.result = defaultPhone.eraseDataInSharedPreferences();
1977 notifyRequester(request);
1978 break;
1979
zoey chene02881a2019-12-30 16:11:23 +08001980 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1981 request = (MainThreadRequest) msg.obj;
1982 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1983 Pair<String, String> changed = (Pair<String, String>) request.argument;
1984 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1985 changed.first, changed.second, onCompleted);
1986 break;
1987 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1988 ar = (AsyncResult) msg.obj;
1989 request = (MainThreadRequest) ar.userObj;
1990 if (ar.exception == null) {
1991 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001992 // If the operation is successful, update the PIN storage
1993 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1994 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001995 UiccController.getInstance().getPinStorage()
1996 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001997 } else {
1998 request.result = msg.arg1;
1999 }
2000 notifyRequester(request);
2001 break;
2002
Michele Berionne5e411512020-11-13 02:36:59 +00002003 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08002004 request = (MainThreadRequest) msg.obj;
2005 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
2006 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2007 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2008 enabled.first, enabled.second, onCompleted);
2009 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002010 }
zoey chene02881a2019-12-30 16:11:23 +08002011 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2012 ar = (AsyncResult) msg.obj;
2013 request = (MainThreadRequest) ar.userObj;
2014 if (ar.exception == null) {
2015 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002016 // If the operation is successful, update the PIN storage
2017 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2018 int phoneId = getPhoneFromRequest(request).getPhoneId();
2019 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002020 UiccController.getInstance().getPinStorage()
2021 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002022 } else {
2023 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2024 }
zoey chene02881a2019-12-30 16:11:23 +08002025 } else {
2026 request.result = msg.arg1;
2027 }
Michele Berionne5e411512020-11-13 02:36:59 +00002028
2029
zoey chene02881a2019-12-30 16:11:23 +08002030 notifyRequester(request);
2031 break;
2032
Peter Wangdafb9ac2020-01-15 14:13:38 -08002033 case MSG_NOTIFY_USER_ACTIVITY:
2034 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002035 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002036 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2037 getDefaultPhone().getContext().sendBroadcastAsUser(
2038 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2039 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002040
2041 case CMD_SET_DATA_THROTTLING: {
2042 request = (MainThreadRequest) msg.obj;
2043 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2044 DataThrottlingRequest dataThrottlingRequest =
2045 (DataThrottlingRequest) request.argument;
2046 Phone phone = getPhoneFromRequest(request);
2047 if (phone != null) {
2048 phone.setDataThrottling(onCompleted,
2049 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2050 dataThrottlingRequest.getCompletionDurationMillis());
2051 } else {
2052 loge("setDataThrottling: No phone object");
2053 request.result =
2054 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2055 notifyRequester(request);
2056 }
2057
2058 break;
2059 }
2060 case EVENT_SET_DATA_THROTTLING_DONE:
2061 ar = (AsyncResult) msg.obj;
2062 request = (MainThreadRequest) ar.userObj;
2063
2064 if (ar.exception == null) {
2065 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2066 } else if (ar.exception instanceof CommandException) {
2067 loge("setDataThrottling: CommandException: " + ar.exception);
2068 CommandException.Error error =
2069 ((CommandException) (ar.exception)).getCommandError();
2070
2071 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2072 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002073 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002074 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2075 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002076 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2077 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002078 } else {
2079 request.result =
2080 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2081 }
2082 } else {
2083 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2084 }
2085 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2086 notifyRequester(request);
2087 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002088
2089 case CMD_SET_SIM_POWER: {
2090 request = (MainThreadRequest) msg.obj;
2091 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2092 request = (MainThreadRequest) msg.obj;
2093 int stateToSet =
2094 ((Pair<Integer, IIntegerConsumer>)
2095 request.argument).first;
2096 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2097 break;
2098 }
2099 case EVENT_SET_SIM_POWER_DONE: {
2100 ar = (AsyncResult) msg.obj;
2101 request = (MainThreadRequest) ar.userObj;
2102 IIntegerConsumer callback =
2103 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2104 if (ar.exception != null) {
2105 loge("setSimPower exception: " + ar.exception);
2106 int errorCode = TelephonyManager.CallForwardingInfoCallback
2107 .RESULT_ERROR_UNKNOWN;
2108 if (ar.exception instanceof CommandException) {
2109 CommandException.Error error =
2110 ((CommandException) (ar.exception)).getCommandError();
2111 if (error == CommandException.Error.SIM_ERR) {
2112 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2113 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2114 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2115 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2116 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2117 } else {
2118 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2119 }
2120 }
2121 try {
2122 callback.accept(errorCode);
2123 } catch (RemoteException e) {
2124 // Ignore if the remote process is no longer available to call back.
2125 Log.w(LOG_TAG, "setSimPower: callback not available.");
2126 }
2127 } else {
2128 try {
2129 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2130 } catch (RemoteException e) {
2131 // Ignore if the remote process is no longer available to call back.
2132 Log.w(LOG_TAG, "setSimPower: callback not available.");
2133 }
2134 }
2135 break;
2136 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002137 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2138 request = (MainThreadRequest) msg.obj;
2139
2140 final Phone phone = getPhoneFromRequest(request);
2141 if (phone == null || phone.getServiceStateTracker() == null) {
2142 request.result = new IllegalStateException("Phone or SST is null");
2143 notifyRequester(request);
2144 break;
2145 }
2146
2147 Pair<Integer, SignalStrengthUpdateRequest> pair =
2148 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2149 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2150 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002151 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002152 request.subId, pair.first /*callingUid*/,
2153 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002154 break;
2155 }
2156 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2157 ar = (AsyncResult) msg.obj;
2158 request = (MainThreadRequest) ar.userObj;
2159 // request.result will be the exception of ar if present, true otherwise.
2160 // Be cautious not to leave result null which will wait() forever
2161 request.result = ar.exception != null ? ar.exception : true;
2162 notifyRequester(request);
2163 break;
2164 }
2165 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2166 request = (MainThreadRequest) msg.obj;
2167
2168 Phone phone = getPhoneFromRequest(request);
2169 if (phone == null || phone.getServiceStateTracker() == null) {
2170 request.result = new IllegalStateException("Phone or SST is null");
2171 notifyRequester(request);
2172 break;
2173 }
2174
2175 Pair<Integer, SignalStrengthUpdateRequest> pair =
2176 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2177 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2178 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002179 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002180 request.subId, pair.first /*callingUid*/,
2181 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002182 break;
2183 }
2184 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2185 ar = (AsyncResult) msg.obj;
2186 request = (MainThreadRequest) ar.userObj;
2187 request.result = ar.exception != null ? ar.exception : true;
2188 notifyRequester(request);
2189 break;
2190 }
Jordan Liu109698e2020-11-24 14:50:34 -08002191
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002192 case CMD_GET_SLICING_CONFIG: {
2193 request = (MainThreadRequest) msg.obj;
2194 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2195 request.phone.getSlicingConfig(onCompleted);
2196 break;
2197 }
2198 case EVENT_GET_SLICING_CONFIG_DONE: {
2199 ar = (AsyncResult) msg.obj;
2200 request = (MainThreadRequest) ar.userObj;
2201 ResultReceiver result = (ResultReceiver) request.argument;
2202
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002203 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002204 Bundle bundle = new Bundle();
2205 int resultCode = 0;
2206 if (ar.exception != null) {
2207 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2208 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002209 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002210 } else if (ar.result == null) {
2211 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002212 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002213 } else {
2214 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002215 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2216 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002217 }
2218
2219 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002220 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002221 }
2222 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2223 result.send(resultCode, bundle);
2224 notifyRequester(request);
2225 break;
2226 }
2227
Sarah Chin71b3a852022-09-28 15:54:19 -07002228 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002229 request = (MainThreadRequest) msg.obj;
2230 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002231 PurchasePremiumCapabilityArgument arg =
2232 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chincc5446f2023-10-23 17:57:19 -07002233 SlicePurchaseController.getInstance(request.phone, mFeatureFlags)
2234 .purchasePremiumCapability(arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002235 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002236 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002237
Sarah Chin71b3a852022-09-28 15:54:19 -07002238 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002239 ar = (AsyncResult) msg.obj;
2240 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002241 PurchasePremiumCapabilityArgument arg =
2242 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002243 try {
2244 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002245 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002246 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002247 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chinff8b1802023-04-11 14:22:14 -07002248 + ", result="
Sarah Chin2ec39f62022-08-31 17:03:26 -07002249 + TelephonyManager.convertPurchaseResultToString(result));
2250 } catch (RemoteException e) {
2251 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002252 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002253 + " failed: " + e;
2254 if (DBG) log(logStr);
2255 AnomalyReporter.reportAnomaly(
2256 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2257 }
2258 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002259 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002260
Michele Berionne5e411512020-11-13 02:36:59 +00002261 case CMD_PREPARE_UNATTENDED_REBOOT:
2262 request = (MainThreadRequest) msg.obj;
2263 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002264 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002265 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002266 notifyRequester(request);
2267 break;
2268
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002269 default:
2270 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2271 break;
2272 }
2273 }
Jake Hambye994d462014-02-03 13:10:13 -08002274
Pengquan Menga1bb6272018-09-06 09:59:22 -07002275 private void notifyRequester(MainThreadRequest request) {
2276 synchronized (request) {
2277 request.notifyAll();
2278 }
2279 }
2280
Jake Hambye994d462014-02-03 13:10:13 -08002281 private void handleNullReturnEvent(Message msg, String command) {
2282 AsyncResult ar = (AsyncResult) msg.obj;
2283 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2284 if (ar.exception == null) {
2285 request.result = true;
2286 } else {
2287 request.result = false;
2288 if (ar.exception instanceof CommandException) {
2289 loge(command + ": CommandException: " + ar.exception);
2290 } else {
2291 loge(command + ": Unknown exception");
2292 }
2293 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002294 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002295 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002296 }
2297
2298 /**
2299 * Posts the specified command to be executed on the main thread,
2300 * waits for the request to complete, and returns the result.
2301 * @see #sendRequestAsync
2302 */
2303 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002304 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2305 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002306 }
2307
2308 /**
2309 * Posts the specified command to be executed on the main thread,
2310 * waits for the request to complete, and returns the result.
2311 * @see #sendRequestAsync
2312 */
2313 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2314 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002315 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002316 }
2317
2318 /**
2319 * Posts the specified command to be executed on the main thread,
2320 * waits for the request to complete, and returns the result.
2321 * @see #sendRequestAsync
2322 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002323 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002324 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2325 }
2326
2327 /**
2328 * Posts the specified command to be executed on the main thread,
2329 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2330 * if not timeout or null otherwise.
2331 * @see #sendRequestAsync
2332 */
2333 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2334 long timeoutInMs) {
2335 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002336 }
2337
2338 /**
2339 * Posts the specified command to be executed on the main thread,
2340 * waits for the request to complete, and returns the result.
2341 * @see #sendRequestAsync
2342 */
Nathan Harold92bed182018-10-12 18:16:49 -07002343 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002344 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002345 }
2346
2347 /**
2348 * Posts the specified command to be executed on the main thread,
2349 * waits for the request to complete, and returns the result.
2350 * @see #sendRequestAsync
2351 */
2352 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002353 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2354 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002355 }
2356
2357 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002358 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2359 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2360 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002361 * @see #sendRequestAsync
2362 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002363 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2364 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002365 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2366 throw new RuntimeException("This method will deadlock if called from the main thread.");
2367 }
2368
Nathan Harold92bed182018-10-12 18:16:49 -07002369 MainThreadRequest request = null;
2370 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2371 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2372 } else if (phone != null) {
2373 request = new MainThreadRequest(argument, phone, workSource);
2374 } else {
2375 request = new MainThreadRequest(argument, subId, workSource);
2376 }
2377
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002378 Message msg = mMainThreadHandler.obtainMessage(command, request);
2379 msg.sendToTarget();
2380
Rambo Wang0f050d82021-02-12 11:43:36 -08002381
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002382 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002383 if (timeoutInMs >= 0) {
2384 // Wait for at least timeoutInMs before returning null request result
2385 long now = SystemClock.elapsedRealtime();
2386 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002387 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002388 try {
2389 request.wait(deadline - now);
2390 } catch (InterruptedException e) {
2391 // Do nothing, go back and check if request is completed or timeout
2392 } finally {
2393 now = SystemClock.elapsedRealtime();
2394 }
2395 }
2396 } else {
2397 // Wait for the request to complete
2398 while (request.result == null) {
2399 try {
2400 request.wait();
2401 } catch (InterruptedException e) {
2402 // Do nothing, go back and wait until the request is complete
2403 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002404 }
2405 }
2406 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002407 if (request.result == null) {
2408 Log.wtf(LOG_TAG,
2409 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2410 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002411 return request.result;
2412 }
2413
2414 /**
2415 * Asynchronous ("fire and forget") version of sendRequest():
2416 * Posts the specified command to be executed on the main thread, and
2417 * returns immediately.
2418 * @see #sendRequest
2419 */
2420 private void sendRequestAsync(int command) {
2421 mMainThreadHandler.sendEmptyMessage(command);
2422 }
2423
2424 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002425 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002426 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002427 */
2428 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002429 sendRequestAsync(command, argument, null, null);
2430 }
2431
2432 /**
2433 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2434 * @see {@link #sendRequest(int,Object)}
2435 */
2436 private void sendRequestAsync(
2437 int command, Object argument, Phone phone, WorkSource workSource) {
2438 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002439 Message msg = mMainThreadHandler.obtainMessage(command, request);
2440 msg.sendToTarget();
2441 }
2442
2443 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002444 * Initialize the singleton PhoneInterfaceManager instance.
2445 * This is only done once, at startup, from PhoneApp.onCreate().
2446 */
Sarah Chincc5446f2023-10-23 17:57:19 -07002447 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002448 synchronized (PhoneInterfaceManager.class) {
2449 if (sInstance == null) {
Sarah Chincc5446f2023-10-23 17:57:19 -07002450 sInstance = new PhoneInterfaceManager(app, featureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002451 } else {
2452 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2453 }
2454 return sInstance;
2455 }
2456 }
2457
2458 /** Private constructor; @see init() */
Sarah Chincc5446f2023-10-23 17:57:19 -07002459 private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002460 mApp = app;
Sarah Chincc5446f2023-10-23 17:57:19 -07002461 mFeatureFlags = featureFlags;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002462 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002463 mImsResolver = ImsResolver.getInstance();
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +00002464 mSatelliteController = SatelliteController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002465 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002466 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2467 mMainThreadHandler = new MainThreadHandler();
Sarah Chin4beb2b72023-02-14 14:47:54 -08002468 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002469 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002470 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002471 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002472 mNotifyUserActivity = new AtomicBoolean(false);
joonhunshin4ac60942023-11-15 15:23:39 +00002473 mPackageManager = app.getPackageManager();
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -08002474 mSatelliteAccessController = SatelliteAccessController.getOrCreateInstance(
2475 getDefaultPhone().getContext(), featureFlags);
Tyler Gunn64144d92022-03-17 14:16:41 -07002476 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002477 publish();
arunvoddud7401012022-12-15 16:08:12 +00002478 CarrierAllowListInfo.loadInstance(mApp);
Hyosun Kim240214a2023-11-02 13:30:15 +00002479
2480 // Create the SatelliteEntitlementController singleton, for using the get the
2481 // entitlementStatus for satellite service.
2482 SatelliteEntitlementController.make(mApp, mFeatureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002483 }
2484
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002485 @VisibleForTesting
2486 public SharedPreferences getSharedPreferences() {
2487 return mTelephonySharedPreferences;
2488 }
2489
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002490 /**
2491 * Get the default phone for this device.
2492 */
2493 @VisibleForTesting
2494 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002495 Phone thePhone = getPhone(getDefaultSubscription());
2496 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2497 }
2498
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002499 private void publish() {
2500 if (DBG) log("publish: " + this);
2501
Peter Wangc035ce42020-01-08 21:00:22 -08002502 TelephonyFrameworkInitializer
2503 .getTelephonyServiceManager()
2504 .getTelephonyServiceRegisterer()
2505 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002506 }
2507
Stuart Scott584921c2015-01-15 17:10:34 -08002508 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002509 if (request.phone != null) {
2510 return request.phone;
2511 } else {
2512 return getPhoneFromSubId(request.subId);
2513 }
2514 }
2515
2516 private Phone getPhoneFromSubId(int subId) {
2517 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2518 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002519 }
2520
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002521 /**
2522 * Get phone object associated with a subscription.
2523 * Return default phone if phone object associated with subscription is null
2524 * @param subId - subscriptionId
2525 * @return phone object associated with a subscription or default phone if null.
2526 */
Ling Mac28f0212023-03-24 16:07:15 -07002527 private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) {
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002528 Phone phone = getPhoneFromSubId(subId);
2529 if (phone == null) {
Ling Mac28f0212023-03-24 16:07:15 -07002530 loge("Called with invalid subId: " + subId + ". Retrying with default phone.");
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002531 phone = getDefaultPhone();
2532 }
2533 return phone;
2534 }
2535
Rambo Wange53e07d2022-05-10 13:01:13 -07002536 @Nullable
2537 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002538 Phone phone = getPhoneFromRequest(request);
2539 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002540 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002541 }
2542
Ling Mac28f0212023-03-24 16:07:15 -07002543 /**
2544 * @param subId The sub Id that associates the phone. If the device has no active SIM, passing
2545 * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <=
2546 * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}.
2547 * @return The Phone associated the sub Id
2548 */
2549 private @Nullable Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002550 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002551 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002552
Kai Shif70f46f2021-03-03 13:59:46 -08002553 private void sendEraseModemConfig(@NonNull Phone phone) {
2554 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2555 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2556 }
2557
2558 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2559 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2560 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002561 }
2562
Peter Wang44b186e2020-01-13 23:33:09 -08002563 private boolean isImsAvailableOnDevice() {
2564 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2565 if (pm == null) {
2566 // For some reason package manger is not available.. This will fail internally anyway,
2567 // so do not throw error and allow.
2568 return true;
2569 }
2570 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2571 }
2572
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002573 public void dial(String number) {
joonhunshin4ac60942023-11-15 15:23:39 +00002574 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2575 PackageManager.FEATURE_TELEPHONY_CALLING, "dial");
2576
Wink Savilleadd7cc52014-09-08 14:23:09 -07002577 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002578 }
2579
Wink Savilleb564aae2014-10-23 10:18:09 -07002580 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002581 if (DBG) log("dial: " + number);
2582 // No permission check needed here: This is just a wrapper around the
2583 // ACTION_DIAL intent, which is available to any app since it puts up
2584 // the UI before it does anything.
2585
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002586 final long identity = Binder.clearCallingIdentity();
2587 try {
2588 String url = createTelUrl(number);
2589 if (url == null) {
2590 return;
2591 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002592
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002593 // PENDING: should we just silently fail if phone is offhook or ringing?
2594 PhoneConstants.State state = mCM.getState(subId);
2595 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2596 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2597 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2598 mApp.startActivity(intent);
2599 }
2600 } finally {
2601 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002602 }
2603 }
2604
2605 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002606 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002607 }
2608
Wink Savilleb564aae2014-10-23 10:18:09 -07002609 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002610 if (DBG) log("call: " + number);
2611
2612 // This is just a wrapper around the ACTION_CALL intent, but we still
2613 // need to do a permission check since we're calling startActivity()
2614 // from the context of the phone app.
2615 enforceCallPermission();
2616
Jordan Liu1617b712019-07-10 15:06:26 -07002617 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002618 != AppOpsManager.MODE_ALLOWED) {
2619 return;
2620 }
2621
joonhunshin4ac60942023-11-15 15:23:39 +00002622 enforceTelephonyFeatureWithException(callingPackage,
2623 PackageManager.FEATURE_TELEPHONY_CALLING, "call");
2624
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002625 final long identity = Binder.clearCallingIdentity();
2626 try {
2627 String url = createTelUrl(number);
2628 if (url == null) {
2629 return;
2630 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002631
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002632 boolean isValid = false;
2633 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2634 if (slist != null) {
2635 for (SubscriptionInfo subInfoRecord : slist) {
2636 if (subInfoRecord.getSubscriptionId() == subId) {
2637 isValid = true;
2638 break;
2639 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002640 }
Wink Saville08874612014-08-31 19:19:58 -07002641 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002642 if (!isValid) {
2643 return;
2644 }
Wink Saville08874612014-08-31 19:19:58 -07002645
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002646 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2647 intent.putExtra(SUBSCRIPTION_KEY, subId);
2648 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2649 mApp.startActivity(intent);
2650 } finally {
2651 Binder.restoreCallingIdentity(identity);
2652 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002653 }
2654
Wink Savilleb564aae2014-10-23 10:18:09 -07002655 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002656 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002657 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2658 }
2659
Wink Savilleb564aae2014-10-23 10:18:09 -07002660 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002661 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002662 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2663 }
2664
Wink Savilleb564aae2014-10-23 10:18:09 -07002665 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002666 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002667
joonhunshin4ac60942023-11-15 15:23:39 +00002668 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2669 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
2670 "supplyPinReportResultForSubscriber");
2671
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002672 final long identity = Binder.clearCallingIdentity();
2673 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002674 Phone phone = getPhone(subId);
2675 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002676 checkSimPin.start();
2677 return checkSimPin.unlockSim(null, pin);
2678 } finally {
2679 Binder.restoreCallingIdentity(identity);
2680 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002681 }
2682
Wink Savilleb564aae2014-10-23 10:18:09 -07002683 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002684 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002685
joonhunshin4ac60942023-11-15 15:23:39 +00002686 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2687 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "supplyPukForSubscriber");
2688
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002689 final long identity = Binder.clearCallingIdentity();
2690 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002691 Phone phone = getPhone(subId);
2692 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002693 checkSimPuk.start();
2694 return checkSimPuk.unlockSim(puk, pin);
2695 } finally {
2696 Binder.restoreCallingIdentity(identity);
2697 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002698 }
2699
2700 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002701 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002702 * a synchronous one.
2703 */
2704 private static class UnlockSim extends Thread {
2705
2706 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002707 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002708
2709 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002710 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2711 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002712
2713 // For replies from SimCard interface
2714 private Handler mHandler;
2715
2716 // For async handler to identify request type
2717 private static final int SUPPLY_PIN_COMPLETE = 100;
2718
Michele Berionne5e411512020-11-13 02:36:59 +00002719 UnlockSim(int phoneId, IccCard simCard) {
2720 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002721 mSimCard = simCard;
2722 }
2723
2724 @Override
2725 public void run() {
2726 Looper.prepare();
2727 synchronized (UnlockSim.this) {
2728 mHandler = new Handler() {
2729 @Override
2730 public void handleMessage(Message msg) {
2731 AsyncResult ar = (AsyncResult) msg.obj;
2732 switch (msg.what) {
2733 case SUPPLY_PIN_COMPLETE:
2734 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2735 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002736 mRetryCount = msg.arg1;
2737 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002738 CommandException.Error error = null;
2739 if (ar.exception instanceof CommandException) {
2740 error = ((CommandException) (ar.exception))
2741 .getCommandError();
2742 }
2743 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07002744 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002745 } else if (error == CommandException.Error.ABORTED) {
2746 /* When UiccCardApp dispose, handle message and return
2747 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08002748 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002749 } else {
2750 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2751 }
2752 } else {
2753 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2754 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002755 mDone = true;
2756 UnlockSim.this.notifyAll();
2757 }
2758 break;
2759 }
2760 }
2761 };
2762 UnlockSim.this.notifyAll();
2763 }
2764 Looper.loop();
2765 }
2766
2767 /*
2768 * Use PIN or PUK to unlock SIM card
2769 *
2770 * If PUK is null, unlock SIM card with PIN
2771 *
2772 * If PUK is not null, unlock SIM card with PUK and set PIN code
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302773 *
2774 * Besides, since it is reused in class level, the thread's looper will be stopped to avoid
2775 * its thread leak.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002776 */
Wink Saville9de0f752013-10-22 19:04:03 -07002777 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002778
2779 while (mHandler == null) {
2780 try {
2781 wait();
2782 } catch (InterruptedException e) {
2783 Thread.currentThread().interrupt();
2784 }
2785 }
2786 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2787
2788 if (puk == null) {
2789 mSimCard.supplyPin(pin, callback);
2790 } else {
2791 mSimCard.supplyPuk(puk, pin, callback);
2792 }
2793
2794 while (!mDone) {
2795 try {
2796 Log.d(LOG_TAG, "wait for done");
2797 wait();
2798 } catch (InterruptedException e) {
2799 // Restore the interrupted status
2800 Thread.currentThread().interrupt();
2801 }
2802 }
2803 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002804 int[] resultArray = new int[2];
2805 resultArray[0] = mResult;
2806 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002807
2808 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002809 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002810 }
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302811 // This instance is no longer reused, so quit its thread's looper.
2812 mHandler.getLooper().quitSafely();
Michele Berionne5e411512020-11-13 02:36:59 +00002813
Wink Saville9de0f752013-10-22 19:04:03 -07002814 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002815 }
2816 }
2817
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002818 /**
2819 * This method has been removed due to privacy and stability concerns.
2820 */
2821 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002822 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002823 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2824 return;
Wink Saville36469e72014-06-11 15:17:00 -07002825 }
2826
Nathan Harold1f889d82020-06-04 17:05:26 -07002827 @Override
2828 public void updateServiceLocationWithPackageName(String callingPackage) {
2829 mApp.getSystemService(AppOpsManager.class)
2830 .checkPackage(Binder.getCallingUid(), callingPackage);
2831
Nathan Haroldf096d982020-11-18 17:18:06 -08002832 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002833 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2834 // Callers targeting S have no business invoking this method.
2835 return;
2836 }
2837
2838 LocationAccessPolicy.LocationPermissionResult locationResult =
2839 LocationAccessPolicy.checkLocationPermission(mApp,
2840 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2841 .setCallingPackage(callingPackage)
2842 .setCallingFeatureId(null)
2843 .setCallingPid(Binder.getCallingPid())
2844 .setCallingUid(Binder.getCallingUid())
2845 .setMethod("updateServiceLocation")
2846 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2847 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2848 .build());
2849 // Apps that lack location permission have no business calling this method;
2850 // however, because no permission was declared in the public API, denials must
2851 // all be "soft".
2852 switch (locationResult) {
2853 case DENIED_HARD: /* fall through */
2854 case DENIED_SOFT:
2855 return;
2856 }
2857
2858 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002859 final long identity = Binder.clearCallingIdentity();
2860 try {
Ling Mac28f0212023-03-24 16:07:15 -07002861 getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002862 } finally {
2863 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002864 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002865 }
2866
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002867 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002868 @Override
2869 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002870 return isRadioOnWithFeature(callingPackage, null);
2871 }
2872
2873
2874 @Override
2875 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2876 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2877 callingFeatureId);
2878 }
2879
2880 @Deprecated
2881 @Override
2882 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2883 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002884 }
2885
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002886 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002887 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2888 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002889 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002890 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002891 return false;
2892 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002893
joonhunshin4ac60942023-11-15 15:23:39 +00002894 enforceTelephonyFeatureWithException(callingPackage,
2895 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isRadioOnWithFeature");
2896
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002897 final long identity = Binder.clearCallingIdentity();
2898 try {
2899 return isRadioOnForSubscriber(subId);
2900 } finally {
2901 Binder.restoreCallingIdentity(identity);
2902 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002903 }
2904
2905 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002906 final long identity = Binder.clearCallingIdentity();
2907 try {
2908 final Phone phone = getPhone(subId);
2909 if (phone != null) {
2910 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2911 } else {
2912 return false;
2913 }
2914 } finally {
2915 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002916 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002917 }
2918
2919 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002920 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002921 }
Wink Saville36469e72014-06-11 15:17:00 -07002922
Wink Savilleb564aae2014-10-23 10:18:09 -07002923 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002924 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002925
joonhunshin4ac60942023-11-15 15:23:39 +00002926 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2927 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "toggleRadioOnOffForSubscriber");
2928
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002929 final long identity = Binder.clearCallingIdentity();
2930 try {
2931 final Phone phone = getPhone(subId);
2932 if (phone != null) {
2933 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2934 }
2935 } finally {
2936 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002937 }
Wink Saville36469e72014-06-11 15:17:00 -07002938 }
2939
2940 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002941 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002942 }
2943
Wink Savilleb564aae2014-10-23 10:18:09 -07002944 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002945 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002946
2947 final long identity = Binder.clearCallingIdentity();
2948 try {
2949 final Phone phone = getPhone(subId);
2950 if (phone == null) {
2951 return false;
2952 }
2953 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2954 toggleRadioOnOffForSubscriber(subId);
2955 }
2956 return true;
2957 } finally {
2958 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002959 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002960 }
Wink Saville36469e72014-06-11 15:17:00 -07002961
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002962 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002963 enforceReadPrivilegedPermission("needMobileRadioShutdown");
joonhunshin4ac60942023-11-15 15:23:39 +00002964
2965 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2966 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needMobileRadioShutdown");
2967
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002968 /*
2969 * If any of the Radios are available, it will need to be
2970 * shutdown. So return true if any Radio is available.
2971 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002972 final long identity = Binder.clearCallingIdentity();
2973 try {
2974 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2975 Phone phone = PhoneFactory.getPhone(i);
2976 if (phone != null && phone.isRadioAvailable()) return true;
2977 }
2978 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2979 return false;
2980 } finally {
2981 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002982 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002983 }
2984
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002985 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002986 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002987 enforceModifyPermission();
2988
joonhunshin4ac60942023-11-15 15:23:39 +00002989 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2990 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "shutdownMobileRadios");
2991
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002992 final long identity = Binder.clearCallingIdentity();
2993 try {
2994 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2995 logv("Shutting down Phone " + i);
2996 shutdownRadioUsingPhoneId(i);
2997 }
2998 } finally {
2999 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003000 }
3001 }
3002
3003 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003004 Phone phone = PhoneFactory.getPhone(phoneId);
3005 if (phone != null && phone.isRadioAvailable()) {
3006 phone.shutdownRadio();
3007 }
3008 }
3009
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003010 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07003011 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003012
Ling Ma83dc5ea2023-01-12 15:06:04 -08003013 if (!turnOn) {
3014 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
3015 }
3016
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003017 final long identity = Binder.clearCallingIdentity();
3018 try {
3019 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
3020 if (defaultPhone != null) {
3021 defaultPhone.setRadioPower(turnOn);
3022 return true;
3023 } else {
3024 loge("There's no default phone.");
3025 return false;
3026 }
3027 } finally {
3028 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07003029 }
Wink Saville36469e72014-06-11 15:17:00 -07003030 }
3031
Wink Savilleb564aae2014-10-23 10:18:09 -07003032 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003033 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003034
Ling Ma83dc5ea2023-01-12 15:06:04 -08003035 if (!turnOn) {
3036 log("setRadioPowerForSubscriber off: subId=" + subId
3037 + ",callingPackage=" + getCurrentPackageName());
3038 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003039 final long identity = Binder.clearCallingIdentity();
3040 try {
3041 final Phone phone = getPhone(subId);
3042 if (phone != null) {
3043 phone.setRadioPower(turnOn);
3044 return true;
3045 } else {
3046 return false;
3047 }
3048 } finally {
3049 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003050 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003051 }
3052
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003053 /**
3054 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3055 * no reason to power it off. When any of the voters want to power it off, it will be turned
3056 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3057 * powering it off, and these radio off votes will be cleared.
3058 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3059 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3060 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3061 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3062 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3063 * check its vote.
3064 *
3065 * @param subId The subscription ID.
3066 * @param reason The reason for powering off radio.
3067 * @return true on success and false on failure.
3068 */
3069 public boolean requestRadioPowerOffForReason(int subId,
3070 @TelephonyManager.RadioPowerReason int reason) {
3071 enforceModifyPermission();
3072
joonhunshin4ac60942023-11-15 15:23:39 +00003073 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3074 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestRadioPowerOffForReason");
3075
Ling Ma83dc5ea2023-01-12 15:06:04 -08003076 log("requestRadioPowerOffForReason: subId=" + subId
3077 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003078 final long identity = Binder.clearCallingIdentity();
3079 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003080 boolean result = false;
3081 for (Phone phone : PhoneFactory.getPhones()) {
3082 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003083 phone.setRadioPowerForReason(false, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003084 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003085 if (!result) {
3086 loge("requestRadioPowerOffForReason: no phone exists");
3087 }
3088 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003089 } finally {
3090 Binder.restoreCallingIdentity(identity);
3091 }
3092 }
3093
3094 /**
3095 * Remove the vote on powering off the radio for a reason, as requested by
3096 * {@link requestRadioPowerOffForReason}.
3097 *
3098 * @param subId The subscription ID.
3099 * @param reason The reason for powering off radio.
3100 * @return true on success and false on failure.
3101 */
3102 public boolean clearRadioPowerOffForReason(int subId,
3103 @TelephonyManager.RadioPowerReason int reason) {
3104 enforceModifyPermission();
3105
joonhunshin4ac60942023-11-15 15:23:39 +00003106 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3107 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearRadioPowerOffForReason");
3108
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003109 final long identity = Binder.clearCallingIdentity();
3110 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003111 boolean result = false;
3112 for (Phone phone : PhoneFactory.getPhones()) {
3113 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003114 phone.setRadioPowerForReason(true, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003115 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003116 if (!result) {
3117 loge("clearRadioPowerOffForReason: no phone exists");
3118 }
3119 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003120 } finally {
3121 Binder.restoreCallingIdentity(identity);
3122 }
3123 }
3124
3125 /**
3126 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3127 *
3128 * @param subId The subscription ID.
3129 * @param callingPackage The package making the call.
3130 * @param callingFeatureId The feature in the package.
3131 * @return List of reasons for powering off radio.
3132 */
3133 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3134 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3135
joonhunshin4ac60942023-11-15 15:23:39 +00003136 enforceTelephonyFeatureWithException(callingPackage,
3137 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerOffReasons");
3138
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003139 final long identity = Binder.clearCallingIdentity();
3140 List result = new ArrayList();
3141 try {
3142 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3143 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3144 return result;
3145 }
3146
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003147 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003148 if (phone != null) {
3149 result.addAll(phone.getRadioPowerOffReasons());
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003150 } else {
3151 loge("getRadioPowerOffReasons: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003152 }
3153 } finally {
3154 Binder.restoreCallingIdentity(identity);
3155 }
3156 return result;
3157 }
3158
Wink Saville36469e72014-06-11 15:17:00 -07003159 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003160 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003161 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003162 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003163
joonhunshin4ac60942023-11-15 15:23:39 +00003164 enforceTelephonyFeatureWithException(callingPackage,
3165 PackageManager.FEATURE_TELEPHONY_DATA, "enableDataConnectivity");
3166
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003167 final long identity = Binder.clearCallingIdentity();
3168 try {
Jack Yu285100e2022-12-02 22:48:35 -08003169 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003170 final Phone phone = getPhone(subId);
3171 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003172 phone.getDataSettingsManager().setDataEnabled(
3173 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003174 return true;
3175 } else {
3176 return false;
3177 }
3178 } finally {
3179 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003180 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003181 }
3182
Wink Saville36469e72014-06-11 15:17:00 -07003183 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003184 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003185 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003186 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003187
joonhunshin4ac60942023-11-15 15:23:39 +00003188 enforceTelephonyFeatureWithException(callingPackage,
3189 PackageManager.FEATURE_TELEPHONY_DATA, "disableDataConnectivity");
3190
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003191 final long identity = Binder.clearCallingIdentity();
3192 try {
Jack Yu285100e2022-12-02 22:48:35 -08003193 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003194 final Phone phone = getPhone(subId);
3195 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003196 phone.getDataSettingsManager().setDataEnabled(
3197 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003198 return true;
3199 } else {
3200 return false;
3201 }
3202 } finally {
3203 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003204 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003205 }
3206
Sanket Padawe356d7632015-06-22 14:03:32 -07003207 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003208 public boolean isDataConnectivityPossible(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003209 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3210 PackageManager.FEATURE_TELEPHONY_DATA, "isDataConnectivityPossible");
3211
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003212 final long identity = Binder.clearCallingIdentity();
3213 try {
3214 final Phone phone = getPhone(subId);
3215 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003216 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003217 } else {
3218 return false;
3219 }
3220 } finally {
3221 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003222 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003223 }
3224
3225 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003226 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003227 }
3228
pkanwarae03a6b2016-11-06 20:37:09 -08003229 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003230 enforceCallPermission();
3231
joonhunshin4ac60942023-11-15 15:23:39 +00003232 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3233 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "handleUssdRequest");
3234
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003235 final long identity = Binder.clearCallingIdentity();
3236 try {
3237 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3238 return;
3239 }
3240 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3241 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3242 } finally {
3243 Binder.restoreCallingIdentity(identity);
3244 }
pkanwar32d516d2016-10-14 19:37:38 -07003245 };
3246
Wink Savilleb564aae2014-10-23 10:18:09 -07003247 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003248 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003249
joonhunshin4ac60942023-11-15 15:23:39 +00003250 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3251 PackageManager.FEATURE_TELEPHONY_CALLING, "handlePinMmiForSubscriber");
3252
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003253 final long identity = Binder.clearCallingIdentity();
3254 try {
3255 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3256 return false;
3257 }
3258 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3259 } finally {
3260 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003261 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003262 }
3263
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003264 /**
3265 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3266 * tag on getCallState Binder call.
3267 */
3268 @Deprecated
3269 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003270 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003271 if (CompatChanges.isChangeEnabled(
3272 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3273 Binder.getCallingUid())) {
3274 // Do not allow this API to be called on API version 31+, it should only be
3275 // called on old apps using this Binder call directly.
3276 throw new SecurityException("This method can only be used for applications "
3277 + "targeting API version 30 or less.");
3278 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003279 final long identity = Binder.clearCallingIdentity();
3280 try {
Ling Mac28f0212023-03-24 16:07:15 -07003281 Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription());
3282 return PhoneConstantConversions.convertCallState(phone.getState());
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003283 } finally {
3284 Binder.restoreCallingIdentity(identity);
3285 }
3286 }
3287
3288 @Override
3289 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3290 if (CompatChanges.isChangeEnabled(
3291 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3292 Binder.getCallingUid())) {
3293 // Check READ_PHONE_STATE for API version 31+
3294 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3295 featureId, "getCallStateForSubscription")) {
3296 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3297 + "targeting API level 31+.");
3298 }
3299 }
joonhunshin4ac60942023-11-15 15:23:39 +00003300
3301 enforceTelephonyFeatureWithException(callingPackage,
3302 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallStateForSubscription");
3303
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003304 final long identity = Binder.clearCallingIdentity();
3305 try {
3306 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003307 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3308 PhoneConstantConversions.convertCallState(phone.getState());
3309 } finally {
3310 Binder.restoreCallingIdentity(identity);
3311 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003312 }
3313
Sanket Padawe356d7632015-06-22 14:03:32 -07003314 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003315 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003316 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003317 }
3318
3319 @Override
3320 public int getDataStateForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003321 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3322 PackageManager.FEATURE_TELEPHONY_DATA, "getDataStateForSubId");
3323
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003324 final long identity = Binder.clearCallingIdentity();
3325 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003326 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003327 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003328 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003329 } else {
3330 return PhoneConstantConversions.convertDataState(
3331 PhoneConstants.DataState.DISCONNECTED);
3332 }
3333 } finally {
3334 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003335 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003336 }
3337
Sanket Padawe356d7632015-06-22 14:03:32 -07003338 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003339 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003340 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003341 }
3342
3343 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003344 public @DataActivityType int getDataActivityForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003345 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3346 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivityForSubId");
3347
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003348 final long identity = Binder.clearCallingIdentity();
3349 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003350 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003351 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003352 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003353 } else {
3354 return TelephonyManager.DATA_ACTIVITY_NONE;
3355 }
3356 } finally {
3357 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003358 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003359 }
3360
3361 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003362 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003363 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003364 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003365
3366 LocationAccessPolicy.LocationPermissionResult locationResult =
3367 LocationAccessPolicy.checkLocationPermission(mApp,
3368 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3369 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003370 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003371 .setCallingPid(Binder.getCallingPid())
3372 .setCallingUid(Binder.getCallingUid())
3373 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003374 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003375 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3376 .build());
3377 switch (locationResult) {
3378 case DENIED_HARD:
3379 throw new SecurityException("Not allowed to access cell location");
3380 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003381 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3382 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003383 }
3384
joonhunshin4ac60942023-11-15 15:23:39 +00003385 enforceTelephonyFeatureWithException(callingPackage,
3386 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getCellLocation");
3387
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003388 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003389 final long identity = Binder.clearCallingIdentity();
3390 try {
3391 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003392 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003393 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003394 } finally {
3395 Binder.restoreCallingIdentity(identity);
3396 }
Svetoslav64fad262015-04-14 14:35:21 -07003397 }
3398
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003399 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003400 public String getNetworkCountryIsoForPhone(int phoneId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003401 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3402 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkCountryIsoForPhone");
3403
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003404 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3405 // registered cell info, so return a NULL country instead.
3406 final long identity = Binder.clearCallingIdentity();
3407 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003408 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3409 // Get default phone in this case.
3410 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3411 }
Jack Yu285100e2022-12-02 22:48:35 -08003412 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003413 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003414 if (phone == null) return "";
3415 ServiceStateTracker sst = phone.getServiceStateTracker();
3416 if (sst == null) return "";
3417 LocaleTracker lt = sst.getLocaleTracker();
3418 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003419 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003420 } finally {
3421 Binder.restoreCallingIdentity(identity);
3422 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003423 }
3424
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003425 /**
3426 * This method was removed due to potential issues caused by performing partial
3427 * updates of service state, and lack of a credible use case.
3428 *
3429 * This has the ability to break the telephony implementation by disabling notification of
3430 * changes in device connectivity. DO NOT USE THIS!
3431 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003432 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003433 public void enableLocationUpdates() {
3434 mApp.enforceCallingOrSelfPermission(
3435 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003436 }
3437
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003438 /**
3439 * This method was removed due to potential issues caused by performing partial
3440 * updates of service state, and lack of a credible use case.
3441 *
3442 * This has the ability to break the telephony implementation by disabling notification of
3443 * changes in device connectivity. DO NOT USE THIS!
3444 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003445 @Override
3446 public void disableLocationUpdates() {
3447 mApp.enforceCallingOrSelfPermission(
3448 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003449 }
3450
3451 @Override
3452 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003453 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3454 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003455 try {
3456 mApp.getSystemService(AppOpsManager.class)
3457 .checkPackage(Binder.getCallingUid(), callingPackage);
3458 } catch (SecurityException e) {
3459 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3460 throw e;
3461 }
3462
Nathan Haroldf096d982020-11-18 17:18:06 -08003463 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003464 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3465 throw new SecurityException(
3466 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3467 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003468
Jordan Liu1617b712019-07-10 15:06:26 -07003469 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003470 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3471 return null;
3472 }
Svetoslav64fad262015-04-14 14:35:21 -07003473
joonhunshin4ac60942023-11-15 15:23:39 +00003474 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3475 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNeighboringCellInfo");
3476
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003477 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003478
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003479 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003480 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003481
Nathan Haroldf180aac2018-06-01 18:43:55 -07003482 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3483 for (CellInfo ci : info) {
3484 if (ci instanceof CellInfoGsm) {
3485 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3486 } else if (ci instanceof CellInfoWcdma) {
3487 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3488 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003489 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003490 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003491 }
3492
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003493 private List<CellInfo> getCachedCellInfo() {
3494 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3495 for (Phone phone : PhoneFactory.getPhones()) {
3496 List<CellInfo> info = phone.getAllCellInfo();
3497 if (info != null) cellInfos.addAll(info);
3498 }
3499 return cellInfos;
3500 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003501
3502 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003503 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003504 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003505 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003506
3507 LocationAccessPolicy.LocationPermissionResult locationResult =
3508 LocationAccessPolicy.checkLocationPermission(mApp,
3509 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3510 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003511 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003512 .setCallingPid(Binder.getCallingPid())
3513 .setCallingUid(Binder.getCallingUid())
3514 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003515 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003516 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3517 .build());
3518 switch (locationResult) {
3519 case DENIED_HARD:
3520 throw new SecurityException("Not allowed to access cell info");
3521 case DENIED_SOFT:
3522 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003523 }
3524
Nathan Haroldf096d982020-11-18 17:18:06 -08003525 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003526 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3527 return getCachedCellInfo();
3528 }
3529
joonhunshin4ac60942023-11-15 15:23:39 +00003530 enforceTelephonyFeatureWithException(callingPackage,
3531 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllCellInfo");
3532
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003533 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003534 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003535 final long identity = Binder.clearCallingIdentity();
3536 try {
3537 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3538 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003539 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003540 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003541 if (info != null) cellInfos.addAll(info);
3542 }
3543 return cellInfos;
3544 } finally {
3545 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003546 }
3547 }
3548
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003549 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003550 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3551 String callingFeatureId) {
3552 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3553 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003554 }
3555
3556 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003557 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3558 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003559 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003560 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003561 }
3562
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003563 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3564 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003565 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003566 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003567
3568 LocationAccessPolicy.LocationPermissionResult locationResult =
3569 LocationAccessPolicy.checkLocationPermission(mApp,
3570 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3571 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003572 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003573 .setCallingPid(Binder.getCallingPid())
3574 .setCallingUid(Binder.getCallingUid())
3575 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003576 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3577 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003578 .build());
3579 switch (locationResult) {
3580 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003581 if (TelephonyPermissions
3582 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003583 // Safetynet logging for b/154934934
3584 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3585 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003586 throw new SecurityException("Not allowed to access cell info");
3587 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003588 if (TelephonyPermissions
3589 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003590 // Safetynet logging for b/154934934
3591 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3592 }
Nathan Harold5320c422019-05-09 10:26:08 -07003593 try {
3594 cb.onCellInfo(new ArrayList<CellInfo>());
3595 } catch (RemoteException re) {
3596 // Drop without consequences
3597 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003598 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003599 }
3600
joonhunshin4ac60942023-11-15 15:23:39 +00003601 enforceTelephonyFeatureWithException(callingPackage,
3602 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestCellInfoUpdateInternal");
Nathan Harolda939a962019-05-09 10:13:47 -07003603
3604 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003605 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3606
3607 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3608 }
3609
3610 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003611 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003612 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003613 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003614
3615 final long identity = Binder.clearCallingIdentity();
3616 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003617 Phone phone = getPhone(subId);
3618 if (phone == null) {
3619 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3620 } else {
3621 phone.setCellInfoListRate(rateInMillis, workSource);
3622 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003623 } finally {
3624 Binder.restoreCallingIdentity(identity);
3625 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003626 }
3627
Shishir Agrawala9f32182016-04-12 12:00:16 -07003628 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003629 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003630 Phone phone = PhoneFactory.getPhone(slotIndex);
3631 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003632 return null;
3633 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003634 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003635 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003636 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003637 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003638 return null;
3639 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003640
joonhunshin4ac60942023-11-15 15:23:39 +00003641 enforceTelephonyFeatureWithException(callingPackage,
3642 PackageManager.FEATURE_TELEPHONY_GSM, "getImeiForSlot");
3643
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003644 final long identity = Binder.clearCallingIdentity();
3645 try {
3646 return phone.getImei();
3647 } finally {
3648 Binder.restoreCallingIdentity(identity);
3649 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003650 }
3651
3652 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003653 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3654 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3655 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3656 callingFeatureId, "getPrimaryImei")) {
3657 throw new SecurityException("Caller does not have permission");
3658 }
joonhunshin4ac60942023-11-15 15:23:39 +00003659
3660 enforceTelephonyFeatureWithException(callingPackage,
3661 PackageManager.FEATURE_TELEPHONY_GSM, "getPrimaryImei");
3662
arunvoddud5c6ce02022-12-11 06:03:12 +00003663 final long identity = Binder.clearCallingIdentity();
3664 try {
3665 for (Phone phone : PhoneFactory.getPhones()) {
3666 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3667 return phone.getImei();
3668 }
3669 }
3670 throw new UnsupportedOperationException("Operation not supported");
3671 } finally {
3672 Binder.restoreCallingIdentity(identity);
3673 }
3674 }
3675
3676 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003677 public String getTypeAllocationCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003678 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3679 PackageManager.FEATURE_TELEPHONY_GSM, "getTypeAllocationCodeForSlot");
3680
David Kelly5e06a7f2018-03-12 14:10:59 +00003681 Phone phone = PhoneFactory.getPhone(slotIndex);
3682 String tac = null;
3683 if (phone != null) {
3684 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003685 try {
3686 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3687 } catch (IndexOutOfBoundsException e) {
3688 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3689 return null;
3690 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003691 }
3692 return tac;
3693 }
3694
3695 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003696 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003697 try {
3698 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3699 } catch (SecurityException se) {
3700 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3701 throw new SecurityException("Package " + callingPackage + " does not belong to "
3702 + Binder.getCallingUid());
3703 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003704 Phone phone = PhoneFactory.getPhone(slotIndex);
3705 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003706 return null;
3707 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003708
Jeff Davidson913390f2018-02-23 17:11:49 -08003709 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003710 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003711 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003712 return null;
3713 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003714
joonhunshin4ac60942023-11-15 15:23:39 +00003715 enforceTelephonyFeatureWithException(callingPackage,
3716 PackageManager.FEATURE_TELEPHONY_CDMA, "getMeidForSlot");
3717
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003718 final long identity = Binder.clearCallingIdentity();
3719 try {
3720 return phone.getMeid();
3721 } finally {
3722 Binder.restoreCallingIdentity(identity);
3723 }
Jack Yu2af8d712017-03-15 17:14:14 -07003724 }
3725
3726 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003727 public String getManufacturerCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003728 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3729 PackageManager.FEATURE_TELEPHONY_CDMA, "getManufacturerCodeForSlot");
3730
David Kelly5e06a7f2018-03-12 14:10:59 +00003731 Phone phone = PhoneFactory.getPhone(slotIndex);
3732 String manufacturerCode = null;
3733 if (phone != null) {
3734 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003735 try {
3736 manufacturerCode =
3737 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3738 } catch (IndexOutOfBoundsException e) {
3739 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3740 return null;
3741 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003742 }
3743 return manufacturerCode;
3744 }
3745
3746 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003747 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3748 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003749 Phone phone = PhoneFactory.getPhone(slotIndex);
3750 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003751 return null;
3752 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003753 int subId = phone.getSubId();
3754 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003755 mApp, subId, callingPackage, callingFeatureId,
3756 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003757 return null;
3758 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003759
joonhunshin4ac60942023-11-15 15:23:39 +00003760 enforceTelephonyFeatureWithException(callingPackage,
3761 PackageManager.FEATURE_TELEPHONY, "getDeviceSoftwareVersionForSlot");
3762
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003763 final long identity = Binder.clearCallingIdentity();
3764 try {
3765 return phone.getDeviceSvn();
3766 } finally {
3767 Binder.restoreCallingIdentity(identity);
3768 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003769 }
3770
fionaxu43304da2017-11-27 22:51:16 -08003771 @Override
3772 public int getSubscriptionCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003773 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3774 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierId");
3775
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003776 final long identity = Binder.clearCallingIdentity();
3777 try {
3778 final Phone phone = getPhone(subId);
3779 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3780 } finally {
3781 Binder.restoreCallingIdentity(identity);
3782 }
fionaxu43304da2017-11-27 22:51:16 -08003783 }
3784
3785 @Override
3786 public String getSubscriptionCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003787 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3788 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierName");
3789
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003790 final long identity = Binder.clearCallingIdentity();
3791 try {
3792 final Phone phone = getPhone(subId);
3793 return phone == null ? null : phone.getCarrierName();
3794 } finally {
3795 Binder.restoreCallingIdentity(identity);
3796 }
fionaxu43304da2017-11-27 22:51:16 -08003797 }
3798
calvinpanffe225e2018-11-01 19:43:06 +08003799 @Override
chen xu0026ca62019-03-06 15:28:50 -08003800 public int getSubscriptionSpecificCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003801 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3802 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionSpecificCarrierId");
3803
chen xu25637222018-11-04 17:17:00 -08003804 final long identity = Binder.clearCallingIdentity();
3805 try {
3806 final Phone phone = getPhone(subId);
3807 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003808 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003809 } finally {
3810 Binder.restoreCallingIdentity(identity);
3811 }
3812 }
3813
3814 @Override
chen xu0026ca62019-03-06 15:28:50 -08003815 public String getSubscriptionSpecificCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003816 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3817 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
3818 "getSubscriptionSpecificCarrierName");
3819
chen xu25637222018-11-04 17:17:00 -08003820 final long identity = Binder.clearCallingIdentity();
3821 try {
3822 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003823 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003824 } finally {
3825 Binder.restoreCallingIdentity(identity);
3826 }
3827 }
3828
chen xu651eec72018-11-11 19:03:44 -08003829 @Override
chen xu864e11c2018-12-06 22:10:03 -08003830 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3831 if (!isSubscriptionMccMnc) {
3832 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3833 }
chen xu651eec72018-11-11 19:03:44 -08003834 final Phone phone = PhoneFactory.getPhone(slotIndex);
3835 if (phone == null) {
3836 return TelephonyManager.UNKNOWN_CARRIER_ID;
3837 }
joonhunshin4ac60942023-11-15 15:23:39 +00003838
3839 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3840 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromMccMnc");
3841
chen xu651eec72018-11-11 19:03:44 -08003842 final long identity = Binder.clearCallingIdentity();
3843 try {
3844 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3845 } finally {
3846 Binder.restoreCallingIdentity(identity);
3847 }
3848 }
3849
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003850 //
3851 // Internal helper methods.
3852 //
3853
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003854 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003855 * Make sure the caller is the calling package itself
3856 *
3857 * @throws SecurityException if the caller is not the calling package
3858 */
3859 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3860 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003861 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3862 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003863 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003864 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003865 } catch (PackageManager.NameNotFoundException e) {
3866 // packageUid is -1
3867 }
3868 if (packageUid != callingUid) {
3869 throw new SecurityException(message + ": Package " + callingPackage
3870 + " does not belong to " + callingUid);
3871 }
3872 }
3873
3874 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003875 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3876 *
3877 * @throws SecurityException if the caller does not have the required permission
3878 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003879 @VisibleForTesting
3880 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003881 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3882 }
3883
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003884 /**
arunvoddud7401012022-12-15 16:08:12 +00003885 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003886 *
3887 * @throws SecurityException if the caller does not have the required permission
3888 */
3889 @VisibleForTesting
3890 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003891 enforceReadPermission(null);
3892 }
3893
3894 /**
3895 * Make sure the caller has the READ_PHONE_STATE permissions.
3896 *
3897 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3898 */
3899 @VisibleForTesting
3900 public void enforceReadPermission(String msg) {
3901 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003902 }
3903
Shuo Qian3b6ee772019-11-13 17:43:31 -08003904 private void enforceActiveEmergencySessionPermission() {
3905 mApp.enforceCallingOrSelfPermission(
3906 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3907 }
3908
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003909 /**
3910 * Make sure the caller has the CALL_PHONE permission.
3911 *
3912 * @throws SecurityException if the caller does not have the required permission
3913 */
3914 private void enforceCallPermission() {
3915 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3916 }
3917
paulhu5a773602019-08-23 19:17:33 +08003918 private void enforceSettingsPermission() {
3919 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003920 }
3921
Michele Berionne5e411512020-11-13 02:36:59 +00003922 private void enforceRebootPermission() {
3923 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3924 }
3925
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003926 /**
3927 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3928 * @param message - log message to print.
3929 * @throws SecurityException if the caller does not have the required permission
3930 */
3931 private void enforceSatelliteCommunicationPermission(String message) {
3932 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3933 }
3934
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003935 private String createTelUrl(String number) {
3936 if (TextUtils.isEmpty(number)) {
3937 return null;
3938 }
3939
Jake Hambye994d462014-02-03 13:10:13 -08003940 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003941 }
3942
Ihab Awadf9e92732013-12-05 18:02:52 -08003943 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003944 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003945 }
3946
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003947 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003948 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003949 }
3950
Ihab Awadf9e92732013-12-05 18:02:52 -08003951 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003952 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003953 }
3954
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003955 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003956 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003957 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003958 }
3959
Sanket Padawe356d7632015-06-22 14:03:32 -07003960 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003961 public int getActivePhoneTypeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003962 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3963 PackageManager.FEATURE_TELEPHONY, "getActivePhoneTypeForSlot");
3964
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003965 final long identity = Binder.clearCallingIdentity();
3966 try {
3967 final Phone phone = PhoneFactory.getPhone(slotIndex);
3968 if (phone == null) {
3969 return PhoneConstants.PHONE_TYPE_NONE;
3970 } else {
3971 return phone.getPhoneType();
3972 }
3973 } finally {
3974 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003975 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003976 }
3977
3978 /**
3979 * Returns the CDMA ERI icon index to display
3980 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003981 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003982 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3983 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3984 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003985 }
3986
Sanket Padawe356d7632015-06-22 14:03:32 -07003987 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003988 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3989 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003990 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003991 mApp, subId, callingPackage, callingFeatureId,
3992 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003993 return -1;
3994 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003995
joonhunshin4ac60942023-11-15 15:23:39 +00003996 enforceTelephonyFeatureWithException(callingPackage,
3997 PackageManager.FEATURE_TELEPHONY_CDMA,
3998 "getCdmaEriIconIndexForSubscriber");
3999
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004000 final long identity = Binder.clearCallingIdentity();
4001 try {
4002 final Phone phone = getPhone(subId);
4003 if (phone != null) {
4004 return phone.getCdmaEriIconIndex();
4005 } else {
4006 return -1;
4007 }
4008 } finally {
4009 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004010 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004011 }
4012
4013 /**
4014 * Returns the CDMA ERI icon mode,
4015 * 0 - ON
4016 * 1 - FLASHING
4017 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004018 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004019 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
4020 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
4021 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004022 }
4023
Sanket Padawe356d7632015-06-22 14:03:32 -07004024 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004025 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
4026 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004027 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004028 mApp, subId, callingPackage, callingFeatureId,
4029 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004030 return -1;
4031 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004032
4033 final long identity = Binder.clearCallingIdentity();
4034 try {
4035 final Phone phone = getPhone(subId);
4036 if (phone != null) {
4037 return phone.getCdmaEriIconMode();
4038 } else {
4039 return -1;
4040 }
4041 } finally {
4042 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004043 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004044 }
4045
4046 /**
4047 * Returns the CDMA ERI text,
4048 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004049 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004050 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
4051 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
4052 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004053 }
4054
Sanket Padawe356d7632015-06-22 14:03:32 -07004055 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004056 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
4057 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004058 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004059 mApp, subId, callingPackage, callingFeatureId,
4060 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004061 return null;
4062 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004063
4064 final long identity = Binder.clearCallingIdentity();
4065 try {
4066 final Phone phone = getPhone(subId);
4067 if (phone != null) {
4068 return phone.getCdmaEriText();
4069 } else {
4070 return null;
4071 }
4072 } finally {
4073 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004074 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004075 }
4076
4077 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07004078 * Returns the CDMA MDN.
4079 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004080 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004081 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004082 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4083 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004084
joonhunshin4ac60942023-11-15 15:23:39 +00004085 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4086 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMdn");
4087
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004088 final long identity = Binder.clearCallingIdentity();
4089 try {
4090 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004091 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004092 return phone.getLine1Number();
4093 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004094 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004095 return null;
4096 }
4097 } finally {
4098 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004099 }
4100 }
4101
4102 /**
4103 * Returns the CDMA MIN.
4104 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004105 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004106 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004107 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4108 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004109
joonhunshin4ac60942023-11-15 15:23:39 +00004110 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4111 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMin");
4112
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004113 final long identity = Binder.clearCallingIdentity();
4114 try {
4115 final Phone phone = getPhone(subId);
4116 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
4117 return phone.getCdmaMin();
4118 } else {
4119 return null;
4120 }
4121 } finally {
4122 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004123 }
4124 }
4125
Hall Liud892bec2018-11-30 14:51:45 -08004126 @Override
4127 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
4128 INumberVerificationCallback callback, String callingPackage) {
4129 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
4130 != PERMISSION_GRANTED) {
4131 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
4132 }
4133 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4134
4135 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
4136 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08004137 throw new SecurityException("Calling package must be configured in the device config: "
4138 + "calling package: " + callingPackage
4139 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004140 }
4141
joonhunshin4ac60942023-11-15 15:23:39 +00004142 enforceTelephonyFeatureWithException(callingPackage,
4143 PackageManager.FEATURE_TELEPHONY_CALLING, "requestNumberVerification");
4144
Hall Liud892bec2018-11-30 14:51:45 -08004145 if (range == null) {
4146 throw new NullPointerException("Range must be non-null");
4147 }
4148
4149 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004150 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004151
4152 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4153 }
4154
Junda Liuca05d5d2014-08-14 22:36:34 -07004155 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004156 * Returns true if CDMA provisioning needs to run.
4157 */
4158 public boolean needsOtaServiceProvisioning() {
joonhunshin4ac60942023-11-15 15:23:39 +00004159 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4160 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needsOtaServiceProvisioning");
4161
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004162 final long identity = Binder.clearCallingIdentity();
4163 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004164 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004165 } finally {
4166 Binder.restoreCallingIdentity(identity);
4167 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004168 }
4169
4170 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004171 * Sets the voice mail number of a given subId.
4172 */
4173 @Override
4174 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004175 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4176 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004177
joonhunshin4ac60942023-11-15 15:23:39 +00004178 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4179 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceMailNumber");
4180
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004181 final long identity = Binder.clearCallingIdentity();
4182 try {
4183 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4184 new Pair<String, String>(alphaTag, number), new Integer(subId));
4185 return success;
4186 } finally {
4187 Binder.restoreCallingIdentity(identity);
4188 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004189 }
4190
Ta-wei Yen87c49842016-05-13 21:19:52 -07004191 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004192 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4193 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004194 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4195 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004196 if (!TextUtils.equals(callingPackage, systemDialer)) {
4197 throw new SecurityException("caller must be system dialer");
4198 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004199
joonhunshin4ac60942023-11-15 15:23:39 +00004200 enforceTelephonyFeatureWithException(callingPackage,
4201 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailSettings");
4202
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004203 final long identity = Binder.clearCallingIdentity();
4204 try {
4205 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4206 if (phoneAccountHandle == null) {
4207 return null;
4208 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004209 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004210 } finally {
4211 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004212 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004213 }
4214
4215 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004216 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4217 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004218 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004219 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004220 mApp, subId, callingPackage, callingFeatureId,
4221 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004222 return null;
4223 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004224
joonhunshin4ac60942023-11-15 15:23:39 +00004225 enforceTelephonyFeatureWithException(callingPackage,
4226 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailPackageName");
4227
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004228 final long identity = Binder.clearCallingIdentity();
4229 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004230 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004231 } finally {
4232 Binder.restoreCallingIdentity(identity);
4233 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004234 }
4235
4236 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004237 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4238 VisualVoicemailSmsFilterSettings settings) {
4239 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004240
joonhunshin4ac60942023-11-15 15:23:39 +00004241 enforceTelephonyFeatureWithException(callingPackage,
4242 PackageManager.FEATURE_TELEPHONY_CALLING, "enableVisualVoicemailSmsFilter");
4243
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004244 final long identity = Binder.clearCallingIdentity();
4245 try {
4246 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004247 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004248 } finally {
4249 Binder.restoreCallingIdentity(identity);
4250 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004251 }
4252
4253 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004254 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4255 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004256
joonhunshin4ac60942023-11-15 15:23:39 +00004257 enforceTelephonyFeatureWithException(callingPackage,
4258 PackageManager.FEATURE_TELEPHONY_CALLING, "disableVisualVoicemailSmsFilter");
4259
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004260 final long identity = Binder.clearCallingIdentity();
4261 try {
4262 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004263 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004264 } finally {
4265 Binder.restoreCallingIdentity(identity);
4266 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004267 }
4268
4269 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004270 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4271 String callingPackage, int subId) {
4272 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004273
4274 final long identity = Binder.clearCallingIdentity();
4275 try {
4276 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004277 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004278 } finally {
4279 Binder.restoreCallingIdentity(identity);
4280 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004281 }
4282
4283 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004284 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004285 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004286
4287 final long identity = Binder.clearCallingIdentity();
4288 try {
4289 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004290 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004291 } finally {
4292 Binder.restoreCallingIdentity(identity);
4293 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004294 }
4295
4296 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004297 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4298 String callingAttributionTag, int subId, String number, int port, String text,
4299 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004300 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004301 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004302 enforceSendSmsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00004303
4304 enforceTelephonyFeatureWithException(callingPackage,
4305 PackageManager.FEATURE_TELEPHONY_CALLING, "sendVisualVoicemailSmsForSubscriber");
4306
Amit Mahajandccb3f12019-05-13 13:48:32 -07004307 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004308 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4309 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004310 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004311
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004312 /**
fionaxu0152e512016-11-14 13:36:14 -08004313 * Sets the voice activation state of a given subId.
4314 */
4315 @Override
4316 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004317 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4318 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004319
joonhunshin4ac60942023-11-15 15:23:39 +00004320 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4321 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState");
4322
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004323 final long identity = Binder.clearCallingIdentity();
4324 try {
4325 final Phone phone = getPhone(subId);
4326 if (phone != null) {
4327 phone.setVoiceActivationState(activationState);
4328 } else {
4329 loge("setVoiceActivationState fails with invalid subId: " + subId);
4330 }
4331 } finally {
4332 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004333 }
4334 }
4335
4336 /**
4337 * Sets the data activation state of a given subId.
4338 */
4339 @Override
4340 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004341 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4342 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004343
joonhunshin4ac60942023-11-15 15:23:39 +00004344 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4345 PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState");
4346
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004347 final long identity = Binder.clearCallingIdentity();
4348 try {
4349 final Phone phone = getPhone(subId);
4350 if (phone != null) {
4351 phone.setDataActivationState(activationState);
4352 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004353 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004354 }
4355 } finally {
4356 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004357 }
4358 }
4359
4360 /**
4361 * Returns the voice activation state of a given subId.
4362 */
4363 @Override
4364 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004365 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004366
joonhunshin4ac60942023-11-15 15:23:39 +00004367 enforceTelephonyFeatureWithException(callingPackage,
4368 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState");
4369
fionaxu0152e512016-11-14 13:36:14 -08004370 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004371 final long identity = Binder.clearCallingIdentity();
4372 try {
4373 if (phone != null) {
4374 return phone.getVoiceActivationState();
4375 } else {
4376 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4377 }
4378 } finally {
4379 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004380 }
4381 }
4382
4383 /**
4384 * Returns the data activation state of a given subId.
4385 */
4386 @Override
4387 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004388 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004389
joonhunshin4ac60942023-11-15 15:23:39 +00004390 enforceTelephonyFeatureWithException(callingPackage,
4391 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState");
4392
fionaxu0152e512016-11-14 13:36:14 -08004393 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004394 final long identity = Binder.clearCallingIdentity();
4395 try {
4396 if (phone != null) {
4397 return phone.getDataActivationState();
4398 } else {
4399 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4400 }
4401 } finally {
4402 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004403 }
4404 }
4405
4406 /**
Wink Saville36469e72014-06-11 15:17:00 -07004407 * Returns the unread count of voicemails for a subId
4408 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004409 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004410 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4411 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004412 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004413 mApp, subId, callingPackage, callingFeatureId,
4414 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004415 return 0;
4416 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004417 final long identity = Binder.clearCallingIdentity();
4418 try {
4419 final Phone phone = getPhone(subId);
4420 if (phone != null) {
4421 return phone.getVoiceMessageCount();
4422 } else {
4423 return 0;
4424 }
4425 } finally {
4426 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004427 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004428 }
4429
4430 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004431 * returns true, if the device is in a state where both voice and data
4432 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004433 */
4434 @Override
4435 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00004436 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4437 PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed");
4438
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004439 final long identity = Binder.clearCallingIdentity();
4440 try {
Ling Mac28f0212023-03-24 16:07:15 -07004441 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004442 } finally {
4443 Binder.restoreCallingIdentity(identity);
4444 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004445 }
4446
4447 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004448 * Send the dialer code if called from the current default dialer or the caller has
4449 * carrier privilege.
4450 * @param inputCode The dialer code to send
4451 */
4452 @Override
4453 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004454 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004455 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004456 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4457 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004458 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004459 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004460 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004461 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004462
joonhunshin4ac60942023-11-15 15:23:39 +00004463 enforceTelephonyFeatureWithException(callingPackage,
4464 PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode");
4465
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004466 final long identity = Binder.clearCallingIdentity();
4467 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004468 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004469 } finally {
4470 Binder.restoreCallingIdentity(identity);
4471 }
fionaxu235cc5e2017-03-06 22:25:57 -08004472 }
4473
Pengquan Menga1bb6272018-09-06 09:59:22 -07004474 @Override
4475 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004476 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004477 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4478 mApp, subId, "getNetworkSelectionMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004479
4480 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4481 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode");
4482
shilufc958392020-01-20 11:36:01 -08004483 final long identity = Binder.clearCallingIdentity();
4484 try {
4485 if (!isActiveSubscription(subId)) {
4486 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4487 }
4488 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4489 } finally {
4490 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004491 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004492 }
4493
Brad Ebinger35c841c2018-10-01 10:40:55 -07004494 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004495 public boolean isInEmergencySmsMode() {
4496 enforceReadPrivilegedPermission("isInEmergencySmsMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004497
4498 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4499 PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode");
4500
Brad Ebingerb2b65522019-03-15 13:48:47 -07004501 final long identity = Binder.clearCallingIdentity();
4502 try {
4503 for (Phone phone : PhoneFactory.getPhones()) {
4504 if (phone.isInEmergencySmsMode()) {
4505 return true;
4506 }
4507 }
4508 } finally {
4509 Binder.restoreCallingIdentity(identity);
4510 }
4511 return false;
4512 }
4513
shilu366312e2019-12-17 09:28:10 -08004514 /**
4515 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4516 * @param subId The subscription to use to check the configuration.
4517 * @param c The callback that will be used to send the result.
4518 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004519 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004520 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4521 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004522 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004523 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004524
4525 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4526 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4527 "IMS not available on device.");
4528 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004529 final long token = Binder.clearCallingIdentity();
4530 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004531 int slotId = getSlotIndexOrException(subId);
4532 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004533
4534 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4535 if (controller != null) {
4536 ImsManager imsManager = controller.getImsManager(subId);
4537 if (imsManager != null) {
4538 imsManager.addRegistrationCallbackForSubscription(c, subId);
4539 } else {
4540 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4541 }
4542 } else {
4543 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4544 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004545 } catch (ImsException e) {
4546 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004547 } finally {
4548 Binder.restoreCallingIdentity(token);
4549 }
4550 }
4551
shilu366312e2019-12-17 09:28:10 -08004552 /**
4553 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4554 * @param subId The subscription to use to check the configuration.
4555 * @param c The callback that will be used to send the result.
4556 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004557 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004558 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004559 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004560 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004561 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4562 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4563 }
Meng Wangafbc5852019-09-19 17:37:13 -07004564 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004565
Meng Wangafbc5852019-09-19 17:37:13 -07004566 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004567 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4568 if (controller != null) {
4569 ImsManager imsManager = controller.getImsManager(subId);
4570 if (imsManager != null) {
4571 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4572 } else {
4573 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4574 + "is inactive, ignoring unregister.");
4575 // If the ImsManager is not valid, just return, since the callback
4576 // will already have been removed internally.
4577 }
4578 }
Meng Wangafbc5852019-09-19 17:37:13 -07004579 } finally {
4580 Binder.restoreCallingIdentity(token);
4581 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004582 }
4583
Brad Ebingera34a6c22019-10-22 17:36:18 -07004584 /**
Hidayat Khan99ea48f2023-12-11 04:37:45 +00004585 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4586 * @param subId The subscription to use to check the configuration.
4587 * @param c The callback that will be used to send the result.
4588 */
4589 @Override
4590 public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c)
4591 throws RemoteException {
4592 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4593 mApp, subId, "registerImsEmergencyRegistrationCallback");
4594
4595 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4596 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4597 "IMS not available on device.");
4598 }
4599 final long token = Binder.clearCallingIdentity();
4600 try {
4601 int slotId = getSlotIndexOrException(subId);
4602 verifyImsMmTelConfiguredOrThrow(slotId);
4603
4604 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4605 if (controller != null) {
4606 ImsManager imsManager = controller.getImsManager(subId);
4607 if (imsManager != null) {
4608 imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId);
4609 } else {
4610 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4611 }
4612 } else {
4613 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4614 }
4615 } catch (ImsException e) {
4616 throw new ServiceSpecificException(e.getCode());
4617 } finally {
4618 Binder.restoreCallingIdentity(token);
4619 }
4620 }
4621
4622 /**
4623 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4624 * @param subId The subscription to use to check the configuration.
4625 * @param c The callback that will be used to send the result.
4626 */
4627 @Override
4628 public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) {
4629 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4630 mApp, subId, "unregisterImsEmergencyRegistrationCallback");
4631 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4632 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4633 }
4634 final long token = Binder.clearCallingIdentity();
4635
4636 try {
4637 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4638 if (controller != null) {
4639 ImsManager imsManager = controller.getImsManager(subId);
4640 if (imsManager != null) {
4641 imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId);
4642 } else {
4643 Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId
4644 + "is inactive, ignoring unregister.");
4645 // If the ImsManager is not valid, just return, since the callback
4646 // will already have been removed internally.
4647 }
4648 }
4649 } finally {
4650 Binder.restoreCallingIdentity(token);
4651 }
4652 }
4653
4654 /**
Brad Ebingera34a6c22019-10-22 17:36:18 -07004655 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4656 */
4657 @Override
4658 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4659 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4660 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4661 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4662 "IMS not available on device.");
4663 }
4664 final long token = Binder.clearCallingIdentity();
4665 try {
4666 Phone phone = getPhone(subId);
4667 if (phone == null) {
4668 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4669 + subId + "'");
4670 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4671 }
4672 phone.getImsRegistrationState(regState -> {
4673 try {
4674 consumer.accept((regState == null)
4675 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4676 } catch (RemoteException e) {
4677 // Ignore if the remote process is no longer available to call back.
4678 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4679 }
4680 });
4681 } finally {
4682 Binder.restoreCallingIdentity(token);
4683 }
4684 }
4685
4686 /**
4687 * Get the transport type for the IMS service registration state.
4688 */
4689 @Override
4690 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004691 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004692 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004693 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4694 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4695 "IMS not available on device.");
4696 }
4697 final long token = Binder.clearCallingIdentity();
4698 try {
4699 Phone phone = getPhone(subId);
4700 if (phone == null) {
4701 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4702 + subId + "'");
4703 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4704 }
4705 phone.getImsRegistrationTech(regTech -> {
4706 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4707 int regTechConverted = (regTech == null)
4708 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4709 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4710 regTechConverted);
4711 try {
4712 consumer.accept(regTechConverted);
4713 } catch (RemoteException e) {
4714 // Ignore if the remote process is no longer available to call back.
4715 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4716 }
4717 });
4718 } finally {
4719 Binder.restoreCallingIdentity(token);
4720 }
4721 }
4722
shilu366312e2019-12-17 09:28:10 -08004723 /**
4724 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4725 * @param subId The subscription to use to check the configuration.
4726 * @param c The callback that will be used to send the result.
4727 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004728 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004729 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4730 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004731 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004732 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004733 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4734 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4735 "IMS not available on device.");
4736 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004737 final long token = Binder.clearCallingIdentity();
4738 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004739 int slotId = getSlotIndexOrException(subId);
4740 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004741
4742 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4743 if (controller != null) {
4744 ImsManager imsManager = controller.getImsManager(subId);
4745 if (imsManager != null) {
4746 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4747 } else {
4748 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4749 }
4750 } else {
4751 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4752 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004753 } catch (ImsException e) {
4754 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004755 } finally {
4756 Binder.restoreCallingIdentity(token);
4757 }
4758 }
4759
shilu366312e2019-12-17 09:28:10 -08004760 /**
4761 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4762 * @param subId The subscription to use to check the configuration.
4763 * @param c The callback that will be used to send the result.
4764 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004765 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004766 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004767 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004768 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004769 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4770 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4771 }
Meng Wangafbc5852019-09-19 17:37:13 -07004772
4773 final long token = Binder.clearCallingIdentity();
4774 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004775 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4776 if (controller != null) {
4777 ImsManager imsManager = controller.getImsManager(subId);
4778 if (imsManager != null) {
4779 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4780 } else {
4781 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4782 + " is inactive, ignoring unregister.");
4783 // If the ImsManager is not valid, just return, since the callback
4784 // will already have been removed internally.
4785 }
4786 }
Meng Wangafbc5852019-09-19 17:37:13 -07004787 } finally {
4788 Binder.restoreCallingIdentity(token);
4789 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004790 }
4791
4792 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004793 public boolean isCapable(int subId, int capability, int regTech) {
4794 enforceReadPrivilegedPermission("isCapable");
joonhunshin4ac60942023-11-15 15:23:39 +00004795
4796 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4797 FEATURE_TELEPHONY_IMS, "isCapable");
4798
Brad Ebinger35c841c2018-10-01 10:40:55 -07004799 final long token = Binder.clearCallingIdentity();
4800 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004801 int slotId = getSlotIndexOrException(subId);
4802 verifyImsMmTelConfiguredOrThrow(slotId);
4803 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4804 } catch (com.android.ims.ImsException e) {
4805 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4806 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004807 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004808 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4809 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004810 } finally {
4811 Binder.restoreCallingIdentity(token);
4812 }
4813 }
4814
4815 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004816 public boolean isAvailable(int subId, int capability, int regTech) {
4817 enforceReadPrivilegedPermission("isAvailable");
joonhunshin4ac60942023-11-15 15:23:39 +00004818
4819 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4820 FEATURE_TELEPHONY_IMS, "isAvailable");
4821
Brad Ebinger35c841c2018-10-01 10:40:55 -07004822 final long token = Binder.clearCallingIdentity();
4823 try {
4824 Phone phone = getPhone(subId);
4825 if (phone == null) return false;
4826 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004827 } catch (com.android.ims.ImsException e) {
4828 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4829 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004830 } finally {
4831 Binder.restoreCallingIdentity(token);
4832 }
4833 }
4834
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004835 /**
4836 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4837 * subscription.
4838 * @param subId The subscription to use to check the configuration.
4839 * @param callback The callback that will be used to send the result.
4840 * @param capability The MmTelFeature capability that will be used to send the result.
4841 * @param transportType The transport type of the MmTelFeature capability.
4842 */
4843 @Override
4844 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4845 int transportType) {
4846 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004847 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4848 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4849 "IMS not available on device.");
4850 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004851 final long token = Binder.clearCallingIdentity();
4852 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004853 int slotId = getSlotIndex(subId);
4854 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4855 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4856 + subId + "'");
4857 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4858 }
4859 verifyImsMmTelConfiguredOrThrow(slotId);
4860 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4861 transportType, aBoolean -> {
4862 try {
4863 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4864 } catch (RemoteException e) {
4865 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4866 + "running. Ignore");
4867 }
4868 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004869 } catch (ImsException e) {
4870 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004871 } finally {
4872 Binder.restoreCallingIdentity(token);
4873 }
4874 }
4875
shilu366312e2019-12-17 09:28:10 -08004876 /**
4877 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4878 * @param subId The subscription to use to check the configuration.
4879 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004880 @Override
4881 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004882 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004883 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004884
joonhunshin4ac60942023-11-15 15:23:39 +00004885 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4886 FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled");
4887
Brad Ebinger35c841c2018-10-01 10:40:55 -07004888 final long token = Binder.clearCallingIdentity();
4889 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004890 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004891 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004892 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004893 } catch (ImsException e) {
4894 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004895 } finally {
4896 Binder.restoreCallingIdentity(token);
4897 }
4898 }
4899
4900 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004901 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004902 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004903 "setAdvancedCallingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004904
4905 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4906 FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled");
4907
Brad Ebinger35c841c2018-10-01 10:40:55 -07004908 final long identity = Binder.clearCallingIdentity();
4909 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004910 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004911 // This setting doesn't require an active ImsService connection, so do not verify. The
4912 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004913 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004914 } catch (ImsException e) {
4915 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004916 } finally {
4917 Binder.restoreCallingIdentity(identity);
4918 }
4919 }
4920
shilu366312e2019-12-17 09:28:10 -08004921 /**
4922 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4923 * @param subId The subscription to use to check the configuration.
4924 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004925 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004926 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004927 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004928 mApp, subId, "isVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004929
4930 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4931 FEATURE_TELEPHONY_IMS, "isVtSettingEnabled");
4932
Brad Ebinger35c841c2018-10-01 10:40:55 -07004933 final long identity = Binder.clearCallingIdentity();
4934 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004935 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004936 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004937 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004938 } catch (ImsException e) {
4939 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004940 } finally {
4941 Binder.restoreCallingIdentity(identity);
4942 }
4943 }
4944
4945 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004946 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004947 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004948 "setVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004949
4950 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4951 FEATURE_TELEPHONY_IMS, "setVtSettingEnabled");
4952
Brad Ebinger35c841c2018-10-01 10:40:55 -07004953 final long identity = Binder.clearCallingIdentity();
4954 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004955 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004956 // This setting doesn't require an active ImsService connection, so do not verify. The
4957 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004958 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004959 } catch (ImsException e) {
4960 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004961 } finally {
4962 Binder.restoreCallingIdentity(identity);
4963 }
4964 }
4965
shilu366312e2019-12-17 09:28:10 -08004966 /**
4967 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4968 * @param subId The subscription to use to check the configuration.
4969 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004970 @Override
4971 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004972 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004973 mApp, subId, "isVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004974
4975 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4976 FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled");
4977
Brad Ebinger35c841c2018-10-01 10:40:55 -07004978 final long identity = Binder.clearCallingIdentity();
4979 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004980 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004981 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004982 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004983 } catch (ImsException e) {
4984 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004985 } finally {
4986 Binder.restoreCallingIdentity(identity);
4987 }
4988 }
4989
4990 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004991 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004992 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004993 "setVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004994
4995 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4996 FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled");
4997
Brad Ebinger35c841c2018-10-01 10:40:55 -07004998 final long identity = Binder.clearCallingIdentity();
4999 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005000 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005001 // This setting doesn't require an active ImsService connection, so do not verify. The
5002 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005003 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005004 } catch (ImsException e) {
5005 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005006 } finally {
5007 Binder.restoreCallingIdentity(identity);
5008 }
5009 }
5010
shilu366312e2019-12-17 09:28:10 -08005011 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005012 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
5013 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5014 * @param subId The subscription to use to check the configuration.
5015 */
5016 @Override
5017 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005018 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005019 mApp, subId, "isCrossSimCallingEnabledByUser");
joonhunshin4ac60942023-11-15 15:23:39 +00005020
5021 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5022 FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser");
5023
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005024 final long identity = Binder.clearCallingIdentity();
5025 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005026 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005027 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005028 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005029 } catch (ImsException e) {
5030 throw new ServiceSpecificException(e.getCode());
5031 } finally {
5032 Binder.restoreCallingIdentity(identity);
5033 }
5034 }
5035
5036 /**
5037 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
5038 * Requires MODIFY_PHONE_STATE permission.
5039 * @param subId The subscription to use to check the configuration.
5040 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
5041 * false otherwise
5042 */
5043 @Override
5044 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
5045 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5046 "setCrossSimCallingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005047
5048 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5049 FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled");
5050
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005051 final long identity = Binder.clearCallingIdentity();
5052 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005053 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005054 // This setting doesn't require an active ImsService connection, so do not verify. The
5055 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005056 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005057 } catch (ImsException e) {
5058 throw new ServiceSpecificException(e.getCode());
5059 } finally {
5060 Binder.restoreCallingIdentity(identity);
5061 }
5062 }
5063
5064 /**
shilu366312e2019-12-17 09:28:10 -08005065 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5066 * @param subId The subscription to use to check the configuration.
5067 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005068 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07005069
Brad Ebinger35c841c2018-10-01 10:40:55 -07005070 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005071 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005072 mApp, subId, "isVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005073
5074 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5075 FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled");
5076
Brad Ebinger35c841c2018-10-01 10:40:55 -07005077 final long identity = Binder.clearCallingIdentity();
5078 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005079 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005080 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005081 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005082 } catch (ImsException e) {
5083 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005084 } finally {
5085 Binder.restoreCallingIdentity(identity);
5086 }
5087 }
5088
5089 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005090 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005091 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005092 "setVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005093
5094 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5095 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled");
5096
Brad Ebinger35c841c2018-10-01 10:40:55 -07005097 final long identity = Binder.clearCallingIdentity();
5098 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005099 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005100 // This setting doesn't require an active ImsService connection, so do not verify. The
5101 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005102 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005103 } catch (ImsException e) {
5104 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005105 } finally {
5106 Binder.restoreCallingIdentity(identity);
5107 }
5108 }
5109
5110 @Override
5111 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
5112 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5113 "setVoWiFiNonPersistent");
joonhunshin4ac60942023-11-15 15:23:39 +00005114
5115 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5116 FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent");
5117
Brad Ebinger35c841c2018-10-01 10:40:55 -07005118 final long identity = Binder.clearCallingIdentity();
5119 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005120 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005121 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005122 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005123 } catch (ImsException e) {
5124 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005125 } finally {
5126 Binder.restoreCallingIdentity(identity);
5127 }
5128 }
5129
shilu366312e2019-12-17 09:28:10 -08005130 /**
5131 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5132 * @param subId The subscription to use to check the configuration.
5133 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005134 @Override
5135 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005136 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005137 mApp, subId, "getVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005138
5139 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5140 FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting");
5141
Brad Ebinger35c841c2018-10-01 10:40:55 -07005142 final long identity = Binder.clearCallingIdentity();
5143 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005144 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005145 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005146 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005147 } catch (ImsException e) {
5148 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005149 } finally {
5150 Binder.restoreCallingIdentity(identity);
5151 }
5152 }
5153
5154 @Override
5155 public void setVoWiFiModeSetting(int subId, int mode) {
5156 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5157 "setVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005158
5159 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5160 FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting");
5161
Brad Ebinger35c841c2018-10-01 10:40:55 -07005162 final long identity = Binder.clearCallingIdentity();
5163 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005164 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005165 // This setting doesn't require an active ImsService connection, so do not verify. The
5166 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005167 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005168 } catch (ImsException e) {
5169 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005170 } finally {
5171 Binder.restoreCallingIdentity(identity);
5172 }
5173 }
5174
5175 @Override
5176 public int getVoWiFiRoamingModeSetting(int subId) {
5177 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005178
5179 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5180 FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting");
5181
Brad Ebinger35c841c2018-10-01 10:40:55 -07005182 final long identity = Binder.clearCallingIdentity();
5183 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005184 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005185 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005186 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005187 } catch (ImsException e) {
5188 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005189 } finally {
5190 Binder.restoreCallingIdentity(identity);
5191 }
5192 }
5193
5194 @Override
5195 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
5196 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5197 "setVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005198
5199 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5200 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting");
5201
Brad Ebinger35c841c2018-10-01 10:40:55 -07005202 final long identity = Binder.clearCallingIdentity();
5203 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005204 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005205 // This setting doesn't require an active ImsService connection, so do not verify. The
5206 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005207 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005208 } catch (ImsException e) {
5209 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005210 } finally {
5211 Binder.restoreCallingIdentity(identity);
5212 }
5213 }
5214
5215 @Override
5216 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
5217 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5218 "setRttCapabilityEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005219
5220 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5221 FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting");
5222
Brad Ebinger35c841c2018-10-01 10:40:55 -07005223 final long identity = Binder.clearCallingIdentity();
5224 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005225 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005226 // This setting doesn't require an active ImsService connection, so do not verify. The
5227 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005228 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005229 } catch (ImsException e) {
5230 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005231 } finally {
5232 Binder.restoreCallingIdentity(identity);
5233 }
5234 }
5235
shilu366312e2019-12-17 09:28:10 -08005236 /**
5237 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5238 * @param subId The subscription to use to check the configuration.
5239 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005240 @Override
5241 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005242 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005243 mApp, subId, "isTtyOverVolteEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005244
5245 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5246 FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled");
5247
Brad Ebinger35c841c2018-10-01 10:40:55 -07005248 final long identity = Binder.clearCallingIdentity();
5249 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005250 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005251 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005252 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005253 } catch (ImsException e) {
5254 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005255 } finally {
5256 Binder.restoreCallingIdentity(identity);
5257 }
5258 }
5259
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005260 @Override
5261 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5262 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005263
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005264 final long identity = Binder.clearCallingIdentity();
5265 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005266 if (!isImsAvailableOnDevice()) {
5267 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5268 "IMS not available on device.");
5269 }
5270 int slotId = getSlotIndexOrException(subId);
5271 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005272
5273 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5274 if (controller != null) {
5275 ImsManager imsManager = controller.getImsManager(subId);
5276 if (imsManager != null) {
5277 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5278 } else {
5279 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5280 }
5281 } else {
5282 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5283 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005284 } catch (ImsException e) {
5285 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005286 } finally {
5287 Binder.restoreCallingIdentity(identity);
5288 }
5289 }
5290
5291 @Override
5292 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5293 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005294
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005295 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005296 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5297 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5298 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005299 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005300 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5301 if (controller != null) {
5302 ImsManager imsManager = controller.getImsManager(subId);
5303 if (imsManager != null) {
5304 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5305 } else {
5306 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5307 + " is inactive, ignoring unregister.");
5308 // If the ImsManager is not valid, just return, since the callback will already
5309 // have been removed internally.
5310 }
5311 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005312 } finally {
5313 Binder.restoreCallingIdentity(identity);
5314 }
5315 }
5316
joonhunshincffb7fc2021-11-28 07:32:01 +00005317 @Override
5318 public void registerFeatureProvisioningChangedCallback(int subId,
5319 IFeatureProvisioningCallback callback) {
5320 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5321 mApp, subId, "registerFeatureProvisioningChangedCallback");
5322
5323 final long identity = Binder.clearCallingIdentity();
5324 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5325 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5326 }
5327
joonhunshin91bc1952022-04-29 08:47:15 +00005328 try {
5329 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5330 if (controller == null) {
5331 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5332 "Device does not support IMS");
5333 }
5334 controller.addFeatureProvisioningChangedCallback(subId, callback);
5335 } finally {
5336 Binder.restoreCallingIdentity(identity);
5337 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005338 }
5339
5340 @Override
5341 public void unregisterFeatureProvisioningChangedCallback(int subId,
5342 IFeatureProvisioningCallback callback) {
5343 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5344 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5345
5346 final long identity = Binder.clearCallingIdentity();
5347 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5348 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5349 }
5350
joonhunshin91bc1952022-04-29 08:47:15 +00005351 try {
5352 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5353 if (controller == null) {
5354 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5355 return;
5356 }
5357 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5358 } finally {
5359 Binder.restoreCallingIdentity(identity);
5360 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005361 }
allenwtsu99c623b2020-01-03 18:24:23 +08005362
5363 private void checkModifyPhoneStatePermission(int subId, String message) {
5364 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5365 message);
5366 }
5367
allenwtsu99c623b2020-01-03 18:24:23 +08005368 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005369 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005370 boolean isProvisioned) {
5371 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5372
joonhunshin4ac60942023-11-15 15:23:39 +00005373 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5374 FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability");
5375
allenwtsu99c623b2020-01-03 18:24:23 +08005376 final long identity = Binder.clearCallingIdentity();
5377 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005378 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5379 if (controller == null) {
5380 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5381 return;
5382 }
5383 controller.setRcsProvisioningStatusForCapability(
5384 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005385 } finally {
5386 Binder.restoreCallingIdentity(identity);
5387 }
allenwtsu99c623b2020-01-03 18:24:23 +08005388 }
5389
5390
5391 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005392 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5393 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5394 mApp, subId, "getRcsProvisioningStatusForCapability");
5395
joonhunshin4ac60942023-11-15 15:23:39 +00005396 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5397 FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability");
5398
allenwtsu99c623b2020-01-03 18:24:23 +08005399 final long identity = Binder.clearCallingIdentity();
5400 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005401 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5402 if (controller == null) {
5403 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5404
5405 // device does not support IMS, this method will return true always.
5406 return true;
5407 }
5408 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005409 } finally {
5410 Binder.restoreCallingIdentity(identity);
5411 }
5412 }
5413
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005414 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005415 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5416 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005417 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005418
joonhunshin4ac60942023-11-15 15:23:39 +00005419 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5420 FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability");
5421
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005422 final long identity = Binder.clearCallingIdentity();
5423 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005424 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5425 if (controller == null) {
5426 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5427 return;
5428 }
5429 controller.setImsProvisioningStatusForCapability(
5430 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005431 } finally {
5432 Binder.restoreCallingIdentity(identity);
5433 }
5434 }
5435
5436 @Override
5437 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005438 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5439 mApp, subId, "getProvisioningStatusForCapability");
5440
joonhunshin4ac60942023-11-15 15:23:39 +00005441 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5442 FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability");
5443
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005444 final long identity = Binder.clearCallingIdentity();
5445 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005446 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5447 if (controller == null) {
5448 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005449
joonhunshin91bc1952022-04-29 08:47:15 +00005450 // device does not support IMS, this method will return true always.
5451 return true;
5452 }
5453 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005454 } finally {
5455 Binder.restoreCallingIdentity(identity);
5456 }
5457 }
5458
5459 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005460 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5461 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5462 mApp, subId, "isProvisioningRequiredForCapability");
5463
joonhunshin4ac60942023-11-15 15:23:39 +00005464 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5465 FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability");
5466
joonhunshincffb7fc2021-11-28 07:32:01 +00005467 final long identity = Binder.clearCallingIdentity();
5468 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005469 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5470 if (controller == null) {
5471 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5472
5473 // device does not support IMS, this method will return false
5474 return false;
5475 }
5476 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005477 } finally {
5478 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005479 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005480 }
5481
5482 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005483 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5484 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5485 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005486
joonhunshin4ac60942023-11-15 15:23:39 +00005487 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5488 FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability");
5489
joonhunshincffb7fc2021-11-28 07:32:01 +00005490 final long identity = Binder.clearCallingIdentity();
5491 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005492 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5493 if (controller == null) {
5494 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5495
5496 // device does not support IMS, this method will return false
5497 return false;
5498 }
5499 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005500 } finally {
5501 Binder.restoreCallingIdentity(identity);
5502 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005503 }
5504
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005505 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005506 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005507 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5508 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5509 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005510 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5511 mApp, subId, "getImsProvisioningInt");
5512
joonhunshin4ac60942023-11-15 15:23:39 +00005513 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5514 FEATURE_TELEPHONY_IMS, "getImsProvisioningInt");
5515
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005516 final long identity = Binder.clearCallingIdentity();
5517 try {
5518 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005519 int slotId = getSlotIndex(subId);
5520 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5521 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5522 + subId + "' for key:" + key);
5523 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5524 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005525
joonhunshin91bc1952022-04-29 08:47:15 +00005526 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5527 if (controller == null) {
5528 loge("getImsProvisioningInt: Device does not support IMS");
5529
5530 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5531 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5532 }
5533 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005534 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5535 return retVal;
5536 }
5537
calvinpanb5a34062021-02-08 19:59:36 +08005538 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005539 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005540 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5541 + subId + "' for key:" + key);
5542 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005543 } finally {
5544 Binder.restoreCallingIdentity(identity);
5545 }
5546 }
5547
5548 @Override
5549 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005550 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5551 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5552 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005553 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5554 mApp, subId, "getImsProvisioningString");
5555
joonhunshin4ac60942023-11-15 15:23:39 +00005556 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5557 FEATURE_TELEPHONY_IMS, "getImsProvisioningString");
5558
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005559 final long identity = Binder.clearCallingIdentity();
5560 try {
5561 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005562 int slotId = getSlotIndex(subId);
5563 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5564 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5565 + subId + "' for key:" + key);
5566 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5567 }
calvinpanb5a34062021-02-08 19:59:36 +08005568 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005569 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005570 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5571 + subId + "' for key:" + key);
5572 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005573 } finally {
5574 Binder.restoreCallingIdentity(identity);
5575 }
5576 }
5577
5578 @Override
5579 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005580 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5581 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5582 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005583 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5584 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005585
joonhunshin4ac60942023-11-15 15:23:39 +00005586 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5587 FEATURE_TELEPHONY_IMS, "setImsProvisioningInt");
5588
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005589 final long identity = Binder.clearCallingIdentity();
5590 try {
5591 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005592 int slotId = getSlotIndex(subId);
5593 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5594 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5595 + subId + "' for key:" + key);
5596 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5597 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005598
joonhunshin91bc1952022-04-29 08:47:15 +00005599 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5600 if (controller == null) {
5601 loge("setImsProvisioningInt: Device does not support IMS");
5602
5603 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5604 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5605 }
5606 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005607 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5608 return retVal;
5609 }
5610
calvinpanb5a34062021-02-08 19:59:36 +08005611 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5612 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005613 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005614 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005615 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005616 } finally {
5617 Binder.restoreCallingIdentity(identity);
5618 }
5619 }
5620
5621 @Override
5622 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005623 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5624 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5625 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005626 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5627 "setImsProvisioningString");
joonhunshin4ac60942023-11-15 15:23:39 +00005628
5629 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5630 FEATURE_TELEPHONY_IMS, "setImsProvisioningString");
5631
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005632 final long identity = Binder.clearCallingIdentity();
5633 try {
5634 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005635 int slotId = getSlotIndex(subId);
5636 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5637 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5638 + subId + "' for key:" + key);
5639 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5640 }
calvinpanb5a34062021-02-08 19:59:36 +08005641 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5642 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005643 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005644 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005645 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005646 } finally {
5647 Binder.restoreCallingIdentity(identity);
5648 }
5649 }
5650
Brad Ebinger919631e2021-06-02 17:46:35 -07005651 /**
5652 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5653 * for the given slot ID or no ImsResolver instance has been created.
5654 * @param slotId The slot ID that the IMS service is created for.
5655 * @throws ImsException If there is no ImsService configured for this slot.
5656 */
5657 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5658 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5659 ImsFeature.FEATURE_MMTEL)) {
5660 throw new ImsException("This subscription does not support MMTEL over IMS",
5661 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5662 }
5663 }
5664
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005665 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005666 int slotId = SubscriptionManager.getSlotIndex(subId);
5667 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005668 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5669 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005670 }
5671 return slotId;
5672 }
5673
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005674 private int getSlotIndex(int subId) {
5675 int slotId = SubscriptionManager.getSlotIndex(subId);
5676 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5677 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5678 }
5679 return slotId;
5680 }
5681
Wink Saville36469e72014-06-11 15:17:00 -07005682 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005683 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005684 */
5685 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005686 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5687 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005688 try {
5689 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5690 } catch (SecurityException se) {
5691 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5692 throw new SecurityException("Package " + callingPackage + " does not belong to "
5693 + Binder.getCallingUid());
5694 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005695 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005696 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005697 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005698 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005699 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005700 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005701 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005702 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5703 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005704
joonhunshin4ac60942023-11-15 15:23:39 +00005705 enforceTelephonyFeatureWithException(callingPackage,
5706 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber");
5707
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005708 final long identity = Binder.clearCallingIdentity();
5709 try {
5710 final Phone phone = getPhone(subId);
5711 if (phone != null) {
5712 return phone.getServiceState().getDataNetworkType();
5713 } else {
5714 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5715 }
5716 } finally {
5717 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005718 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005719 }
5720
5721 /**
5722 * Returns the data network type
5723 */
5724 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005725 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005726 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005727 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005728 }
5729
5730 /**
5731 * Returns the data network type for a subId
5732 */
5733 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005734 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5735 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005736 String functionName = "getDataNetworkTypeForSubscriber";
5737 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5738 mApp, functionName)) {
5739 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5740 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5741 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5742 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005743 }
5744
joonhunshin4ac60942023-11-15 15:23:39 +00005745 enforceTelephonyFeatureWithException(callingPackage,
5746 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber");
5747
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005748 final long identity = Binder.clearCallingIdentity();
5749 try {
5750 final Phone phone = getPhone(subId);
5751 if (phone != null) {
5752 return phone.getServiceState().getDataNetworkType();
5753 } else {
5754 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5755 }
5756 } finally {
5757 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005758 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005759 }
5760
5761 /**
Wink Saville36469e72014-06-11 15:17:00 -07005762 * Returns the Voice network type for a subId
5763 */
5764 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005765 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5766 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005767 String functionName = "getVoiceNetworkTypeForSubscriber";
5768 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5769 mApp, functionName)) {
5770 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5771 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5772 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5773 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005774 }
5775
joonhunshin4ac60942023-11-15 15:23:39 +00005776 enforceTelephonyFeatureWithException(callingPackage,
5777 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber");
5778
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005779 final long identity = Binder.clearCallingIdentity();
5780 try {
5781 final Phone phone = getPhone(subId);
5782 if (phone != null) {
5783 return phone.getServiceState().getVoiceNetworkType();
5784 } else {
5785 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5786 }
5787 } finally {
5788 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005789 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005790 }
5791
5792 /**
5793 * @return true if a ICC card is present
5794 */
5795 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005796 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005797 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005798 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005799 }
5800
5801 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005802 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005803 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005804 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005805 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00005806 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5807 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex");
5808
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005809 final long identity = Binder.clearCallingIdentity();
5810 try {
5811 final Phone phone = PhoneFactory.getPhone(slotIndex);
5812 if (phone != null) {
5813 return phone.getIccCard().hasIccCard();
5814 } else {
5815 return false;
5816 }
5817 } finally {
5818 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005819 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005820 }
5821
5822 /**
5823 * Return if the current radio is LTE on CDMA. This
5824 * is a tri-state return value as for a period of time
5825 * the mode may be unknown.
5826 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005827 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005828 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005829 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005830 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005831 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005832 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5833 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5834 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005835 }
5836
Sanket Padawe356d7632015-06-22 14:03:32 -07005837 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005838 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5839 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005840 try {
5841 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5842 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005843 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5844 }
5845
joonhunshin4ac60942023-11-15 15:23:39 +00005846 enforceTelephonyFeatureWithException(callingPackage,
5847 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber");
5848
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005849 final long identity = Binder.clearCallingIdentity();
5850 try {
5851 final Phone phone = getPhone(subId);
5852 if (phone == null) {
5853 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5854 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005855 return TelephonyProperties.lte_on_cdma_device()
5856 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005857 }
5858 } finally {
5859 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005860 }
Wink Saville36469e72014-06-11 15:17:00 -07005861 }
5862
Wink Saville36469e72014-06-11 15:17:00 -07005863 /**
5864 * {@hide}
5865 * Returns Default subId, 0 in the case of single standby.
5866 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005867 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005868 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005869 }
5870
Shishir Agrawala9f32182016-04-12 12:00:16 -07005871 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005872 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005873 }
5874
Wink Savilleb564aae2014-10-23 10:18:09 -07005875 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005876 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005877 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005878
Pengquan Menge92a50d2018-09-21 15:54:48 -07005879 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005880 return getSubscriptionManagerService().isActiveSubId(subId,
5881 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005882 }
5883
Ihab Awadf2177b72013-11-25 13:33:23 -08005884 /**
5885 * @see android.telephony.TelephonyManager.WifiCallingChoices
5886 */
5887 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005888 final long identity = Binder.clearCallingIdentity();
5889 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005890 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005891 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5892 getWhenToMakeWifiCallsDefaultPreference());
5893 } finally {
5894 Binder.restoreCallingIdentity(identity);
5895 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005896 }
5897
5898 /**
5899 * @see android.telephony.TelephonyManager.WifiCallingChoices
5900 */
5901 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005902 final long identity = Binder.clearCallingIdentity();
5903 try {
5904 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005905 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005906 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5907 } finally {
5908 Binder.restoreCallingIdentity(identity);
5909 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005910 }
5911
Sailesh Nepald1e68152013-12-12 19:08:02 -08005912 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005913 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005914 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005915 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005916
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005917 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5918 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5919 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005920 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005921 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005922 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005923 }
5924 return PhoneFactory.getPhone(phoneId);
5925 }
5926
Shishir Agrawal566b7612013-10-28 14:41:00 -07005927 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005928 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005929 @NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00005930
Rambo Wanga1782702021-11-10 20:15:19 -08005931 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5932 /*message=*/ "iccOpenLogicalChannel");
5933
5934 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5935 // Verify that the callingPackage in the request belongs to the calling UID
5936 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5937
joonhunshin4ac60942023-11-15 15:23:39 +00005938 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5939 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel");
5940
Rambo Wanga1782702021-11-10 20:15:19 -08005941 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005942 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005943
Rambo Wanga1782702021-11-10 20:15:19 -08005944 private Phone getPhoneFromValidIccLogicalChannelRequest(
5945 @NonNull IccLogicalChannelRequest request, String message) {
5946 Phone phone;
5947 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5948 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5949 mApp, request.subId, message);
5950 phone = getPhoneFromSubId(request.subId);
5951 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5952 enforceModifyPermission();
5953 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5954 } else {
5955 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005956 }
Rambo Wanga1782702021-11-10 20:15:19 -08005957 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005958 }
5959
5960 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005961 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005962 final long identity = Binder.clearCallingIdentity();
5963 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005964 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005965 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005966 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5967 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005968 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5969 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005970 loge("The calling package is not allowed to access ISD-R.");
5971 throw new SecurityException(
5972 "The calling package is not allowed to access ISD-R.");
5973 }
Derek Tan740e1672017-06-27 14:56:27 -07005974 }
Derek Tan740e1672017-06-27 14:56:27 -07005975
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005976 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005977 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5978 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005979 return response;
5980 } finally {
5981 Binder.restoreCallingIdentity(identity);
5982 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005983 }
5984
5985 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005986 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00005987 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5988 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel");
5989
Rambo Wanga1782702021-11-10 20:15:19 -08005990 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5991 /*message=*/"iccCloseLogicalChannel");
5992
5993 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5994
5995 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005996 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005997
Rambo Wanga1782702021-11-10 20:15:19 -08005998 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5999 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08006000 // before this feature is enabled, this API should only return false if
6001 // the operation fails instead of throwing runtime exception for
6002 // backward-compatibility.
6003 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
6004 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006005 final long identity = Binder.clearCallingIdentity();
6006 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006007 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08006008 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006009 }
Chen Xue9d737e2022-01-01 23:41:31 -08006010 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08006011 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08006012 Boolean success = false;
6013 if (result instanceof RuntimeException) {
6014 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08006015 if (shouldThrowExceptionOnFailure) {
6016 throw (RuntimeException) result;
6017 } else {
6018 return false;
6019 }
Chen Xue9d737e2022-01-01 23:41:31 -08006020 } else if (result instanceof Boolean) {
6021 success = (Boolean) result;
6022 } else {
6023 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
6024 }
Rambo Wanga1782702021-11-10 20:15:19 -08006025 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006026 return success;
6027 } finally {
6028 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006029 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006030 }
6031
6032 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006033 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07006034 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006035 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6036 mApp, subId, "iccTransmitApduLogicalChannel");
joonhunshin4ac60942023-11-15 15:23:39 +00006037
6038 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6039 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel");
6040
Jordan Liu4c733742019-02-28 12:03:40 -08006041 if (DBG) {
6042 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
6043 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
6044 + p3 + " data=" + data);
6045 }
6046 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
6047 command, p1, p2, p3, data);
6048 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006049
Jordan Liu4c733742019-02-28 12:03:40 -08006050 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006051 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006052 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006053 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006054
6055 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6056 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
6057 "iccTransmitApduLogicalChannelBySlot");
6058
Jordan Liu4c733742019-02-28 12:03:40 -08006059 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006060 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006061 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
6062 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006063 }
6064 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006065 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
6066 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006067 }
6068
6069 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
6070 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006071 final long identity = Binder.clearCallingIdentity();
6072 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07006073 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006074 return "";
6075 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006076
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006077 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006078 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
6079 null /* workSource */);
6080 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006081
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006082 // Append the returned status code to the end of the response payload.
6083 String s = Integer.toHexString(
6084 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6085 if (response.payload != null) {
6086 s = IccUtils.bytesToHexString(response.payload) + s;
6087 }
6088 return s;
6089 } finally {
6090 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006091 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006092 }
Jake Hambye994d462014-02-03 13:10:13 -08006093
Evan Charltonc66da362014-05-16 14:06:40 -07006094 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006095 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
6096 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006097 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6098 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006099 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006100
6101 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6102 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel");
6103
Jordan Liu4c733742019-02-28 12:03:40 -08006104 if (DBG) {
6105 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
6106 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
6107 }
6108 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
6109 cla, command, p1, p2, p3, data);
6110 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006111
Jordan Liu4c733742019-02-28 12:03:40 -08006112 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006113 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006114 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006115 enforceModifyPermission();
6116 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006117
6118 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6119 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot");
6120
Jordan Liu4c733742019-02-28 12:03:40 -08006121 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006122 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006123 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
6124 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006125 }
6126
6127 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006128 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
6129 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006130 }
6131
6132 // open APDU basic channel assuming the caller has sufficient permissions
6133 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
6134 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006135 final long identity = Binder.clearCallingIdentity();
6136 try {
6137 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
6138 && TextUtils.equals(ISDR_AID, data)) {
6139 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006140 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6141 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006142 if (bestComponent == null
6143 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
6144 loge("The calling package is not allowed to select ISD-R.");
6145 throw new SecurityException(
6146 "The calling package is not allowed to select ISD-R.");
6147 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006148 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006149
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006150 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006151 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
6152 null /* workSource */);
6153 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006154
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006155 // Append the returned status code to the end of the response payload.
6156 String s = Integer.toHexString(
6157 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6158 if (response.payload != null) {
6159 s = IccUtils.bytesToHexString(response.payload) + s;
6160 }
6161 return s;
6162 } finally {
6163 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006164 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006165 }
6166
6167 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006168 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006169 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006170 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6171 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006172
joonhunshin4ac60942023-11-15 15:23:39 +00006173 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6174 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO");
6175
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006176 final long identity = Binder.clearCallingIdentity();
6177 try {
6178 if (DBG) {
6179 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
6180 + p1 + " " + p2 + " " + p3 + ":" + filePath);
6181 }
6182
6183 IccIoResult response =
6184 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
6185 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
6186 subId);
6187
6188 if (DBG) {
6189 log("Exchange SIM_IO [R]" + response);
6190 }
6191
6192 byte[] result = null;
6193 int length = 2;
6194 if (response.payload != null) {
6195 length = 2 + response.payload.length;
6196 result = new byte[length];
6197 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
6198 } else {
6199 result = new byte[length];
6200 }
6201
6202 result[length - 1] = (byte) response.sw2;
6203 result[length - 2] = (byte) response.sw1;
6204 return result;
6205 } finally {
6206 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006207 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006208 }
6209
Nathan Haroldb3014052017-01-25 15:57:32 -08006210 /**
6211 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
6212 * on a particular subscription
6213 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006214 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
6215 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07006216 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006217 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07006218 return null;
6219 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006220
joonhunshin4ac60942023-11-15 15:23:39 +00006221 enforceTelephonyFeatureWithException(callingPackage,
6222 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns");
6223
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006224 final long identity = Binder.clearCallingIdentity();
6225 try {
6226 if (appType != TelephonyManager.APPTYPE_USIM
6227 && appType != TelephonyManager.APPTYPE_SIM) {
6228 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
6229 return null;
6230 }
6231 Object response = sendRequest(
6232 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
6233 if (response instanceof String[]) {
6234 return (String[]) response;
6235 }
yincheng zhao2737e882019-09-06 17:06:54 -07006236 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006237 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08006238 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006239 } finally {
6240 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08006241 }
Nathan Haroldb3014052017-01-25 15:57:32 -08006242 }
6243
yincheng zhao2737e882019-09-06 17:06:54 -07006244 /**
6245 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
6246 * subscription.
6247 *
6248 * @param subId the id of the subscription.
6249 * @param appType the uicc app type, must be USIM or SIM.
6250 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
6251 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006252 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07006253 * @return number of fplmns that is successfully written to the SIM.
6254 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006255 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
6256 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07006257 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6258 mApp, subId, "setForbiddenPlmns");
6259
joonhunshin4ac60942023-11-15 15:23:39 +00006260 enforceTelephonyFeatureWithException(callingPackage,
6261 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns");
6262
yincheng zhao2737e882019-09-06 17:06:54 -07006263 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
6264 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
6265 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
6266 }
6267 if (fplmns == null) {
6268 throw new IllegalArgumentException("Fplmn List provided is null");
6269 }
6270 for (String fplmn : fplmns) {
6271 if (!CellIdentity.isValidPlmn(fplmn)) {
6272 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
6273 }
6274 }
6275 final long identity = Binder.clearCallingIdentity();
6276 try {
6277 Object response = sendRequest(
6278 CMD_SET_FORBIDDEN_PLMNS,
6279 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
6280 subId);
6281 return (int) response;
6282 } finally {
6283 Binder.restoreCallingIdentity(identity);
6284 }
6285 }
6286
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006287 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006288 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006289 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6290 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07006291
joonhunshin4ac60942023-11-15 15:23:39 +00006292 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6293 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus");
6294
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006295 final long identity = Binder.clearCallingIdentity();
6296 try {
6297 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
6298 if (response.payload == null) {
6299 return "";
6300 }
Evan Charltonc66da362014-05-16 14:06:40 -07006301
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006302 // Append the returned status code to the end of the response payload.
6303 String s = Integer.toHexString(
6304 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6305 s = IccUtils.bytesToHexString(response.payload) + s;
6306 return s;
6307 } finally {
6308 Binder.restoreCallingIdentity(identity);
6309 }
Evan Charltonc66da362014-05-16 14:06:40 -07006310 }
6311
Jake Hambye994d462014-02-03 13:10:13 -08006312 /**
6313 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6314 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6315 *
6316 * @param itemID the ID of the item to read
6317 * @return the NV item as a String, or null on error.
6318 */
6319 @Override
6320 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006321 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006322 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6323 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006324
6325 final long identity = Binder.clearCallingIdentity();
6326 try {
6327 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07006328 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006329 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
6330 return value;
6331 } finally {
6332 Binder.restoreCallingIdentity(identity);
6333 }
Jake Hambye994d462014-02-03 13:10:13 -08006334 }
6335
6336 /**
6337 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6338 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6339 *
6340 * @param itemID the ID of the item to read
6341 * @param itemValue the value to write, as a String
6342 * @return true on success; false on any failure
6343 */
6344 @Override
6345 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006346 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006347 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6348 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006349
6350 final long identity = Binder.clearCallingIdentity();
6351 try {
6352 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6353 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006354 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006355 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6356 return success;
6357 } finally {
6358 Binder.restoreCallingIdentity(identity);
6359 }
Jake Hambye994d462014-02-03 13:10:13 -08006360 }
6361
6362 /**
6363 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6364 * Used for device configuration by some CDMA operators.
6365 *
6366 * @param preferredRoamingList byte array containing the new PRL
6367 * @return true on success; false on any failure
6368 */
6369 @Override
6370 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006371 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6372 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006373
6374 final long identity = Binder.clearCallingIdentity();
6375 try {
6376 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6377 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6378 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6379 return success;
6380 } finally {
6381 Binder.restoreCallingIdentity(identity);
6382 }
Jake Hambye994d462014-02-03 13:10:13 -08006383 }
6384
6385 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006386 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006387 * Used for device configuration by some CDMA operators.
6388 *
chen xu6dac5ab2018-10-26 17:39:23 -07006389 * @param slotIndex - device slot.
6390 *
Jake Hambye994d462014-02-03 13:10:13 -08006391 * @return true on success; false on any failure
6392 */
6393 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006394 public boolean resetModemConfig(int slotIndex) {
6395 Phone phone = PhoneFactory.getPhone(slotIndex);
6396 if (phone != null) {
6397 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6398 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006399
joonhunshin4ac60942023-11-15 15:23:39 +00006400 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6401 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig");
6402
chen xu6dac5ab2018-10-26 17:39:23 -07006403 final long identity = Binder.clearCallingIdentity();
6404 try {
6405 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6406 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6407 return success;
6408 } finally {
6409 Binder.restoreCallingIdentity(identity);
6410 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006411 }
chen xu6dac5ab2018-10-26 17:39:23 -07006412 return false;
6413 }
6414
6415 /**
6416 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6417 *
6418 * @param slotIndex - device slot.
6419 *
6420 * @return true on success; false on any failure
6421 */
6422 @Override
6423 public boolean rebootModem(int slotIndex) {
6424 Phone phone = PhoneFactory.getPhone(slotIndex);
6425 if (phone != null) {
6426 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6427 mApp, phone.getSubId(), "rebootModem");
6428
joonhunshin4ac60942023-11-15 15:23:39 +00006429 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6430 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem");
6431
chen xu6dac5ab2018-10-26 17:39:23 -07006432 final long identity = Binder.clearCallingIdentity();
6433 try {
6434 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6435 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6436 return success;
6437 } finally {
6438 Binder.restoreCallingIdentity(identity);
6439 }
6440 }
6441 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006442 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006443
Brad Ebinger51f743a2017-01-23 13:50:20 -08006444 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006445 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6446 * {@link #disableIms(int)}.
6447 * @param slotIndex device slot.
6448 */
6449 public void resetIms(int slotIndex) {
6450 enforceModifyPermission();
6451
joonhunshin4ac60942023-11-15 15:23:39 +00006452 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6453 PackageManager.FEATURE_TELEPHONY_IMS, "resetIms");
6454
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006455 final long identity = Binder.clearCallingIdentity();
6456 try {
6457 if (mImsResolver == null) {
6458 // may happen if the does not support IMS.
6459 return;
6460 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006461 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006462 } finally {
6463 Binder.restoreCallingIdentity(identity);
6464 }
6465 }
6466
6467 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006468 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6469 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006470 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006471 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006472 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006473
6474 final long identity = Binder.clearCallingIdentity();
6475 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006476 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006477 // may happen if the device does not support IMS.
6478 return;
6479 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006480 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006481 } finally {
6482 Binder.restoreCallingIdentity(identity);
6483 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006484 }
6485
6486 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006487 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6488 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006489 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006490 public void disableIms(int slotId) {
6491 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006492
6493 final long identity = Binder.clearCallingIdentity();
6494 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006495 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006496 // may happen if the device does not support IMS.
6497 return;
6498 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006499 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006500 } finally {
6501 Binder.restoreCallingIdentity(identity);
6502 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006503 }
6504
6505 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006506 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6507 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006508 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006509 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006510 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006511 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006512
6513 final long identity = Binder.clearCallingIdentity();
6514 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006515 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006516 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6517 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006518 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006519 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006520 } finally {
6521 Binder.restoreCallingIdentity(identity);
6522 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006523 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006524 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006525 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6526 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006527 @Override
6528 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006529 enforceModifyPermission();
6530
6531 final long identity = Binder.clearCallingIdentity();
6532 try {
6533 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006534 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006535 } finally {
6536 Binder.restoreCallingIdentity(identity);
6537 }
6538 }
6539
6540 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006541 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006542 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006543 */
6544 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6545 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006546
6547 final long identity = Binder.clearCallingIdentity();
6548 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006549 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006550 // may happen if the device does not support IMS.
6551 return null;
6552 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006553 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006554 } finally {
6555 Binder.restoreCallingIdentity(identity);
6556 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006557 }
6558
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006559 /**
6560 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006561 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006562 */
6563 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6564 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006565
6566 final long identity = Binder.clearCallingIdentity();
6567 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006568 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006569 // may happen if the device does not support IMS.
6570 return null;
6571 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006572 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006573 } finally {
6574 Binder.restoreCallingIdentity(identity);
6575 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006576 }
6577
Brad Ebinger884c07b2018-02-15 16:17:40 -08006578 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006579 * Sets the ImsService Package Name that Telephony will bind to.
6580 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006581 * @param slotIndex the slot ID that the ImsService should bind for.
6582 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006583 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006584 * @param featureTypes An integer array of feature types associated with a packageName.
6585 * @param packageName The name of the package that the current configuration will be replaced
6586 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006587 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006588 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006589 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6590 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006591 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006592 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006593 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006594
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006595 final long identity = Binder.clearCallingIdentity();
6596 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006597 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006598 // may happen if the device does not support IMS.
6599 return false;
6600 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006601 Map<Integer, String> featureConfig = new HashMap<>();
6602 for (int featureType : featureTypes) {
6603 featureConfig.put(featureType, packageName);
6604 }
6605 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6606 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006607 } finally {
6608 Binder.restoreCallingIdentity(identity);
6609 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006610 }
6611
6612 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006613 * Clears any carrier ImsService overrides for the slot index specified that were previously
6614 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6615 *
6616 * This should only be used for testing.
6617 *
6618 * @param slotIndex the slot ID that the ImsService should bind for.
6619 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6620 */
6621 @Override
6622 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006623 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6624 "clearCarrierImsServiceOverride");
6625 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006626 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006627
6628 final long identity = Binder.clearCallingIdentity();
6629 try {
6630 if (mImsResolver == null) {
6631 // may happen if the device does not support IMS.
6632 return false;
6633 }
6634 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6635 } finally {
6636 Binder.restoreCallingIdentity(identity);
6637 }
6638 }
6639
6640 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006641 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006642 *
6643 * @param slotId The slot that the ImsService is associated with.
6644 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6645 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006646 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006647 * @return the package name of the ImsService configuration.
6648 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006649 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6650 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006651 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006652 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6653 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006654
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006655 final long identity = Binder.clearCallingIdentity();
6656 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006657 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006658 // may happen if the device does not support IMS.
6659 return "";
6660 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006661 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006662 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6663 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006664 } finally {
6665 Binder.restoreCallingIdentity(identity);
6666 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006667 }
6668
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006669 /**
6670 * Get the MmTelFeature state associated with the requested subscription id.
6671 * @param subId The subscription that the MmTelFeature is associated with.
6672 * @param callback A callback with an integer containing the
6673 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6674 */
6675 @Override
6676 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6677 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006678 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6679 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6680 "IMS not available on device.");
6681 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006682 final long token = Binder.clearCallingIdentity();
6683 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006684 int slotId = getSlotIndex(subId);
6685 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6686 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6687 + subId + "'");
6688 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6689 }
6690 verifyImsMmTelConfiguredOrThrow(slotId);
6691 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6692 try {
6693 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6694 } catch (RemoteException e) {
6695 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6696 + "Ignore");
6697 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006698 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006699 } catch (ImsException e) {
6700 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006701 } finally {
6702 Binder.restoreCallingIdentity(token);
6703 }
6704 }
6705
Daniel Brightbb5840b2021-01-12 15:48:18 -08006706 /**
6707 * Sets the ims registration state on all valid {@link Phone}s.
6708 */
6709 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006710 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006711
6712 final long identity = Binder.clearCallingIdentity();
6713 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006714 // NOTE: Before S, this method only set the default phone.
6715 for (final Phone phone : PhoneFactory.getPhones()) {
6716 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6717 phone.setImsRegistrationState(registered);
6718 }
6719 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006720 } finally {
6721 Binder.restoreCallingIdentity(identity);
6722 }
Wink Saville36469e72014-06-11 15:17:00 -07006723 }
6724
6725 /**
Stuart Scott54788802015-03-30 13:18:01 -07006726 * Set the network selection mode to automatic.
6727 *
6728 */
6729 @Override
6730 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006731 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6732 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006733
joonhunshin4ac60942023-11-15 15:23:39 +00006734 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6735 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic");
6736
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006737 final long identity = Binder.clearCallingIdentity();
6738 try {
shilufc958392020-01-20 11:36:01 -08006739 if (!isActiveSubscription(subId)) {
6740 return;
6741 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006742 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006743 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6744 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006745 } finally {
6746 Binder.restoreCallingIdentity(identity);
6747 }
Stuart Scott54788802015-03-30 13:18:01 -07006748 }
6749
Jack Yud10cdd42020-09-28 20:28:01 -07006750 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006751 * Ask the radio to connect to the input network and change selection mode to manual.
6752 *
6753 * @param subId the id of the subscription.
6754 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6755 * the operator to attach to.
6756 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6757 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6758 * normal network selection next time.
6759 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006760 */
6761 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006762 public boolean setNetworkSelectionModeManual(
6763 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006764 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6765 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006766
joonhunshin4ac60942023-11-15 15:23:39 +00006767 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6768 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual");
6769
Jack Yu285100e2022-12-02 22:48:35 -08006770 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006771 if (!isActiveSubscription(subId)) {
6772 return false;
6773 }
6774
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006775 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006776 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006777 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006778 if (DBG) {
6779 log("setNetworkSelectionModeManual: subId: " + subId
6780 + " operator: " + operatorInfo);
6781 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006782 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6783 } finally {
6784 Binder.restoreCallingIdentity(identity);
6785 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006786 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006787 /**
shilu84f6e8b2019-12-19 13:58:01 -08006788 * Get the manual network selection
6789 *
6790 * @param subId the id of the subscription.
6791 *
6792 * @return the previously saved user selected PLMN
6793 */
6794 @Override
6795 public String getManualNetworkSelectionPlmn(int subId) {
6796 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006797 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6798 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006799
joonhunshin4ac60942023-11-15 15:23:39 +00006800 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6801 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn");
6802
shilu84f6e8b2019-12-19 13:58:01 -08006803 final long identity = Binder.clearCallingIdentity();
6804 try {
6805 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006806 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006807 }
6808
6809 final Phone phone = getPhone(subId);
6810 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006811 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006812 }
6813 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6814 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006815 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006816 } finally {
6817 Binder.restoreCallingIdentity(identity);
6818 }
6819 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006820
6821 /**
6822 * Scans for available networks.
6823 */
6824 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006825 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6826 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006827 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6828 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006829 LocationAccessPolicy.LocationPermissionResult locationResult =
6830 LocationAccessPolicy.checkLocationPermission(mApp,
6831 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6832 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006833 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006834 .setCallingPid(Binder.getCallingPid())
6835 .setCallingUid(Binder.getCallingUid())
6836 .setMethod("getCellNetworkScanResults")
6837 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006838 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6839 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006840 .build());
6841 switch (locationResult) {
6842 case DENIED_HARD:
6843 throw new SecurityException("Not allowed to access scan results -- location");
6844 case DENIED_SOFT:
6845 return null;
6846 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006847
Pengquan Menga1bb6272018-09-06 09:59:22 -07006848 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006849 try {
6850 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006851 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006852 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006853 } finally {
6854 Binder.restoreCallingIdentity(identity);
6855 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006856 }
6857
6858 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006859 * Get the call forwarding info, given the call forwarding reason.
6860 */
6861 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006862 public void getCallForwarding(int subId, int callForwardingReason,
6863 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006864 enforceReadPrivilegedPermission("getCallForwarding");
joonhunshin4ac60942023-11-15 15:23:39 +00006865
6866 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6867 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding");
6868
Shuo Qian4a594052020-01-23 11:59:30 -08006869 long identity = Binder.clearCallingIdentity();
6870 try {
6871 if (DBG) {
6872 log("getCallForwarding: subId " + subId
6873 + " callForwardingReason" + callForwardingReason);
6874 }
Hall Liu27d24262020-09-18 19:04:59 -07006875
6876 Phone phone = getPhone(subId);
6877 if (phone == null) {
6878 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006879 callback.onError(
6880 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006881 } catch (RemoteException e) {
6882 // ignore
6883 }
6884 return;
6885 }
6886
6887 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6888 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6889 @Override
6890 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6891 try {
6892 callback.onCallForwardingInfoAvailable(info);
6893 } catch (RemoteException e) {
6894 // ignore
6895 }
6896 }
6897
6898 @Override
6899 public void onError(int error) {
6900 try {
6901 callback.onError(error);
6902 } catch (RemoteException e) {
6903 // ignore
6904 }
6905 }
6906 });
6907 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006908 } finally {
6909 Binder.restoreCallingIdentity(identity);
6910 }
6911 }
6912
6913 /**
6914 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6915 * reason, the number to forward, and the timeout before the forwarding is attempted.
6916 */
6917 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006918 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6919 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006920 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006921
6922 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6923 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding");
6924
Shuo Qian4a594052020-01-23 11:59:30 -08006925 long identity = Binder.clearCallingIdentity();
6926 try {
6927 if (DBG) {
6928 log("setCallForwarding: subId " + subId
6929 + " callForwardingInfo" + callForwardingInfo);
6930 }
Hall Liu27d24262020-09-18 19:04:59 -07006931
6932 Phone phone = getPhone(subId);
6933 if (phone == null) {
6934 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006935 callback.accept(
6936 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006937 } catch (RemoteException e) {
6938 // ignore
6939 }
6940 return;
6941 }
6942
6943 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6944 FunctionalUtils.ignoreRemoteException(callback::accept));
6945
6946 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006947 } finally {
6948 Binder.restoreCallingIdentity(identity);
6949 }
6950 }
6951
6952 /**
Hall Liu27d24262020-09-18 19:04:59 -07006953 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006954 */
6955 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006956 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006957 enforceReadPrivilegedPermission("getCallWaitingStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00006958
6959 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6960 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus");
6961
Shuo Qian4a594052020-01-23 11:59:30 -08006962 long identity = Binder.clearCallingIdentity();
6963 try {
Hall Liu27d24262020-09-18 19:04:59 -07006964 Phone phone = getPhone(subId);
6965 if (phone == null) {
6966 try {
6967 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6968 } catch (RemoteException e) {
6969 // ignore
6970 }
6971 return;
6972 }
SongFerngWang0e767992021-03-31 22:08:45 +08006973 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6974 PersistableBundle c = configManager.getConfigForSubId(subId);
6975 boolean requireUssd = c.getBoolean(
6976 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006977
Shuo Qian4a594052020-01-23 11:59:30 -08006978 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006979 if (requireUssd) {
6980 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6981 getSubscriptionCarrierId(subId));
6982 String newUssdCommand = "";
6983 try {
6984 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006985 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006986 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6987 } catch (NullPointerException e) {
6988 loge("Failed to generate USSD number" + e);
6989 }
6990 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6991 mMainThreadHandler, callback, carrierXmlParser,
6992 CarrierXmlParser.SsEntry.SSAction.QUERY);
6993 final String ussdCommand = newUssdCommand;
6994 Executors.newSingleThreadExecutor().execute(() -> {
6995 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6996 });
6997 } else {
6998 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6999 callback::accept);
7000 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
7001 }
Shuo Qian4a594052020-01-23 11:59:30 -08007002 } finally {
7003 Binder.restoreCallingIdentity(identity);
7004 }
7005 }
7006
7007 /**
Hall Liu27d24262020-09-18 19:04:59 -07007008 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007009 */
7010 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007011 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007012 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007013
7014 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7015 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus");
7016
Shuo Qian4a594052020-01-23 11:59:30 -08007017 long identity = Binder.clearCallingIdentity();
7018 try {
Hall Liu27d24262020-09-18 19:04:59 -07007019 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
7020
7021 Phone phone = getPhone(subId);
7022 if (phone == null) {
7023 try {
7024 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7025 } catch (RemoteException e) {
7026 // ignore
7027 }
7028 return;
7029 }
7030
SongFerngWang0e767992021-03-31 22:08:45 +08007031 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7032 PersistableBundle c = configManager.getConfigForSubId(subId);
7033 boolean requireUssd = c.getBoolean(
7034 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007035
SongFerngWang0e767992021-03-31 22:08:45 +08007036 if (DBG) log("getCallWaitingStatus: subId " + subId);
7037 if (requireUssd) {
7038 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7039 getSubscriptionCarrierId(subId));
7040 CarrierXmlParser.SsEntry.SSAction ssAction =
7041 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
7042 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
7043 String newUssdCommand = "";
7044 try {
7045 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007046 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007047 .makeCommand(ssAction, null);
7048 } catch (NullPointerException e) {
7049 loge("Failed to generate USSD number" + e);
7050 }
7051 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7052 mMainThreadHandler, callback, carrierXmlParser, ssAction);
7053 final String ussdCommand = newUssdCommand;
7054 Executors.newSingleThreadExecutor().execute(() -> {
7055 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7056 });
7057 } else {
7058 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
7059 FunctionalUtils.ignoreRemoteException(callback::accept));
7060
7061 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
7062 }
Shuo Qian4a594052020-01-23 11:59:30 -08007063 } finally {
7064 Binder.restoreCallingIdentity(identity);
7065 }
7066 }
7067
7068 /**
yinxub1bed742017-04-17 11:45:04 -07007069 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07007070 *
yinxub1bed742017-04-17 11:45:04 -07007071 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007072 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
7073 * location related information which will be sent if the caller already possess
7074 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07007075 * @param request contains the radio access networks with bands/channels to scan
7076 * @param messenger callback messenger for scan results or errors
7077 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07007078 * @return the id of the requested scan which can be used to stop the scan.
7079 */
7080 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007081 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
7082 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007083 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007084 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7085 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08007086 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007087 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
7088 if (!renounceFineLocationAccess) {
7089 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007090 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7091 .setCallingPackage(callingPackage)
7092 .setCallingFeatureId(callingFeatureId)
7093 .setCallingPid(Binder.getCallingPid())
7094 .setCallingUid(Binder.getCallingUid())
7095 .setMethod("requestNetworkScan")
7096 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7097 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7098 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7099 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007100 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08007101 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07007102 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
7103 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08007104 if (e != null) {
7105 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
7106 throw e;
7107 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07007108 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08007109 return TelephonyScanManager.INVALID_SCAN_ID;
7110 }
7111 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007112 }
joonhunshin4ac60942023-11-15 15:23:39 +00007113
7114 enforceTelephonyFeatureWithException(callingPackage,
7115 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan");
7116
Hall Liu912dfd32019-04-25 14:02:26 -07007117 int callingUid = Binder.getCallingUid();
7118 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07007119 final long identity = Binder.clearCallingIdentity();
7120 try {
7121 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07007122 renounceFineLocationAccess, request, messenger, binder,
7123 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07007124 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07007125 } finally {
7126 Binder.restoreCallingIdentity(identity);
7127 }
yinxu504e1392017-04-12 16:03:22 -07007128 }
7129
Hall Liub2ac8ef2019-02-28 15:56:23 -08007130 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07007131 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00007132 boolean hasCarrierPriv;
7133 final long identity = Binder.clearCallingIdentity();
7134 try {
7135 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
7136 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
7137 } finally {
7138 Binder.restoreCallingIdentity(identity);
7139 }
Hall Liu558027f2019-05-15 19:14:05 -07007140 boolean hasNetworkScanPermission =
7141 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007142 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07007143
7144 if (!hasCarrierPriv && !hasNetworkScanPermission) {
7145 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
7146 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08007147 }
7148
7149 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
7150 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08007151 if (ras.getChannels() != null && ras.getChannels().length > 0) {
7152 return new SecurityException("Specific channels must not be"
7153 + " scanned without location access.");
7154 }
7155 }
7156 }
7157
Hall Liub2ac8ef2019-02-28 15:56:23 -08007158 return null;
7159 }
7160
yinxu504e1392017-04-12 16:03:22 -07007161 /**
7162 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07007163 *
7164 * @param subId id of the subscription
7165 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07007166 */
7167 @Override
7168 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007169 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7170 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007171
Hall Liu912dfd32019-04-25 14:02:26 -07007172 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007173 final long identity = Binder.clearCallingIdentity();
7174 try {
Hall Liu912dfd32019-04-25 14:02:26 -07007175 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007176 } finally {
7177 Binder.restoreCallingIdentity(identity);
7178 }
yinxu504e1392017-04-12 16:03:22 -07007179 }
7180
7181 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08007182 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07007183 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08007184 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07007185 */
7186 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08007187 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08007188 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007189 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08007190 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007191
joonhunshin4ac60942023-11-15 15:23:39 +00007192 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7193 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask");
7194
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007195 final long identity = Binder.clearCallingIdentity();
7196 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007197 if (DBG) log("getAllowedNetworkTypesBitmask");
7198 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
7199 int networkTypesBitmask = (result != null ? result[0] : -1);
7200 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
7201 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007202 } finally {
7203 Binder.restoreCallingIdentity(identity);
7204 }
Jake Hamby7c27be32014-03-03 13:25:59 -08007205 }
7206
7207 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007208 * Get the allowed network types for certain reason.
7209 *
7210 * @param subId the id of the subscription.
7211 * @param reason the reason the allowed network type change is taking place
7212 * @return the allowed network types.
7213 */
7214 @Override
7215 public long getAllowedNetworkTypesForReason(int subId,
7216 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07007217 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007218 mApp, subId, "getAllowedNetworkTypesForReason");
joonhunshin4ac60942023-11-15 15:23:39 +00007219
7220 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7221 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesForReason");
7222
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007223 final long identity = Binder.clearCallingIdentity();
7224 try {
Jack Yu7247ac82023-03-02 23:52:10 -08007225 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007226 } finally {
7227 Binder.restoreCallingIdentity(identity);
7228 }
7229 }
7230
7231 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07007232 * Enable/Disable E-UTRA-NR Dual Connectivity
7233 * @param subId subscription id of the sim card
7234 * @param nrDualConnectivityState expected NR dual connectivity state
7235 * This can be passed following states
7236 * <ol>
7237 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
7238 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
7239 * <li>Disable NR dual connectivity and force secondary cell to be released
7240 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
7241 * </ol>
7242 * @return operation result.
7243 */
7244 @Override
7245 public int setNrDualConnectivityState(int subId,
7246 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
7247 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7248 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007249 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007250 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7251 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
7252 }
7253
Sooraj Sasindran37444802020-08-11 10:40:43 -07007254 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7255 final long identity = Binder.clearCallingIdentity();
7256 try {
7257 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
7258 nrDualConnectivityState, subId,
7259 workSource);
7260 if (DBG) log("enableNRDualConnectivity result: " + result);
7261 return result;
7262 } finally {
7263 Binder.restoreCallingIdentity(identity);
7264 }
7265 }
7266
7267 /**
7268 * Is E-UTRA-NR Dual Connectivity enabled
7269 * @return true if dual connectivity is enabled else false
7270 */
7271 @Override
7272 public boolean isNrDualConnectivityEnabled(int subId) {
7273 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007274 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07007275 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007276 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007277 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7278 return false;
7279 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07007280 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7281 final long identity = Binder.clearCallingIdentity();
7282 try {
7283 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
7284 null, subId, workSource);
7285 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
7286 return isEnabled;
7287 } finally {
7288 Binder.restoreCallingIdentity(identity);
7289 }
7290 }
7291
7292 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007293 * Set the allowed network types of the device and
7294 * provide the reason triggering the allowed network change.
7295 *
7296 * @param subId the id of the subscription.
7297 * @param reason the reason the allowed network type change is taking place
7298 * @param allowedNetworkTypes the allowed network types.
7299 * @return true on success; false on any failure.
7300 */
7301 @Override
7302 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08007303 @TelephonyManager.AllowedNetworkTypesReason int reason,
7304 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007305 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7306 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007307 // If the caller only has carrier privileges, then they should not be able to override
7308 // any network types which were set for security reasons.
7309 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
7310 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007311 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007312 throw new SecurityException(
7313 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007314 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007315 }
joonhunshin4ac60942023-11-15 15:23:39 +00007316
7317 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7318 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason");
7319
SongFerngWang3ef3e072020-12-21 16:41:52 +08007320 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007321 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08007322 return false;
7323 }
7324 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
7325 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007326 return false;
7327 }
7328
Jack Yu5b494332023-01-23 18:18:04 +00007329 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
7330 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007331
Jack Yue37dd262022-12-16 11:53:37 -08007332 Phone phone = getPhone(subId);
7333 if (phone == null) {
7334 return false;
7335 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007336
Jack Yue37dd262022-12-16 11:53:37 -08007337 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007338 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007339 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08007340 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007341
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007342 final long identity = Binder.clearCallingIdentity();
7343 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007344 Boolean success = (Boolean) sendRequest(
7345 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
7346 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
7347
7348 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
7349 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007350 } finally {
7351 Binder.restoreCallingIdentity(identity);
7352 }
7353 }
7354
7355 /**
Miaoa84611c2019-03-15 09:21:10 +08007356 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08007357 *
Miaoa84611c2019-03-15 09:21:10 +08007358 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07007359 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08007360 * @hide
7361 */
7362 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08007363 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007364 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007365
7366 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7367 PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber");
7368
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007369 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08007370 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007371 try {
Miaoa84611c2019-03-15 09:21:10 +08007372 if (phone != null) {
7373 return phone.hasMatchedTetherApnSetting();
7374 } else {
7375 return false;
7376 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007377 } finally {
7378 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007379 }
Junda Liu475951f2014-11-07 16:45:03 -08007380 }
7381
7382 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007383 * Get the user enabled state of Mobile Data.
7384 *
7385 * TODO: remove and use isUserDataEnabled.
7386 * This can't be removed now because some vendor codes
7387 * calls through ITelephony directly while they should
7388 * use TelephonyManager.
7389 *
7390 * @return true on enabled
7391 */
7392 @Override
7393 public boolean getDataEnabled(int subId) {
7394 return isUserDataEnabled(subId);
7395 }
7396
7397 /**
7398 * Get whether mobile data is enabled per user setting.
7399 *
7400 * There are other factors deciding whether mobile data is actually enabled, but they are
7401 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007402 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007403 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7404 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007405 *
7406 * @return {@code true} if data is enabled else {@code false}
7407 */
7408 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007409 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007410 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007411 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007412 try {
7413 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7414 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007415 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007416 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7417 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007418 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007419 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007420 mApp, subId, functionName);
7421
Robert Greenwalt646120a2014-05-23 11:54:03 -07007422 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007423
7424 final long identity = Binder.clearCallingIdentity();
7425 try {
Jack Yu285100e2022-12-02 22:48:35 -08007426 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007427 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7428 Phone phone = PhoneFactory.getPhone(phoneId);
7429 if (phone != null) {
7430 boolean retVal = phone.isUserDataEnabled();
7431 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7432 return retVal;
7433 } else {
7434 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7435 return false;
7436 }
7437 } finally {
7438 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007439 }
7440 }
7441
7442 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007443 * Checks if the device is capable of mobile data by considering whether whether the
7444 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7445 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007446 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007447 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007448 */
7449 @Override
7450 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007451 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007452 try {
7453 try {
7454 mApp.enforceCallingOrSelfPermission(
7455 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007456 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007457 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007458 try {
7459 mApp.enforceCallingOrSelfPermission(
7460 android.Manifest.permission.READ_PHONE_STATE,
7461 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007462 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007463 mApp.enforceCallingOrSelfPermission(
7464 permission.READ_BASIC_PHONE_STATE, functionName);
7465 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007466 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007467 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007468 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007469 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007470
joonhunshin4ac60942023-11-15 15:23:39 +00007471 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7472 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled");
7473
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007474 final long identity = Binder.clearCallingIdentity();
7475 try {
Jack Yu285100e2022-12-02 22:48:35 -08007476 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007477 Phone phone = PhoneFactory.getPhone(phoneId);
7478 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007479 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007480 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007481 return retVal;
7482 } else {
7483 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7484 return false;
7485 }
7486 } finally {
7487 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007488 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007489 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007490
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007491 /**
7492 * Check if data is enabled for a specific reason
7493 * @param subId Subscription index
7494 * @param reason the reason the data enable change is taking place
7495 * @return {@code true} if the overall data is enabled; {@code false} if not.
7496 */
7497 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007498 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007499 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007500 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007501 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007502 try {
7503 mApp.enforceCallingOrSelfPermission(
7504 android.Manifest.permission.ACCESS_NETWORK_STATE,
7505 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007506 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007507 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7508 functionName);
7509 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007510 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007511 try {
7512 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007513 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007514 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007515 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007516 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007517 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007518 }
7519
joonhunshin4ac60942023-11-15 15:23:39 +00007520 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7521 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007522
7523 final long identity = Binder.clearCallingIdentity();
7524 try {
Jack Yu285100e2022-12-02 22:48:35 -08007525 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007526 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007527 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007528 + " reason=" + reason);
7529 }
7530 Phone phone = PhoneFactory.getPhone(phoneId);
7531 if (phone != null) {
7532 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007533 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007534 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007535 return retVal;
7536 } else {
7537 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007538 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007539 + subId + " retVal=false");
7540 }
7541 return false;
7542 }
7543 } finally {
7544 Binder.restoreCallingIdentity(identity);
7545 }
7546 }
7547
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007548 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007549 public int getCarrierPrivilegeStatus(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00007550 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7551 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus");
7552
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007553 // No permission needed; this only lets the caller inspect their own status.
7554 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007555 }
Junda Liu29340342014-07-10 15:23:27 -07007556
7557 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007558 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007559 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
joonhunshin4ac60942023-11-15 15:23:39 +00007560
7561 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7562 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatusForUid");
7563
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007564 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7565 }
7566
7567 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7568 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007569 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007570 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007571 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7572 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007573 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7574 if (cpt == null) {
7575 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007576 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7577 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007578 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007579 }
7580
7581 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007582 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007583 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
joonhunshin4ac60942023-11-15 15:23:39 +00007584
7585 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7586 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage");
7587
chen xuf7e9fe82019-05-09 19:31:02 -07007588 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007589 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007590 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007591 Phone phone = getPhone(subId);
7592 if (phone == null) {
7593 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7594 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7595 }
7596 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7597 if (cpt == null) {
7598 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007599 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7600 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007601 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007602 }
7603
7604 @Override
7605 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007606 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007607
7608 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7609 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7610 "checkCarrierPrivilegesForPackageAnyPhone");
7611
Rambo Wange7209ce2022-02-23 13:41:02 -08007612 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7613 }
7614
7615 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007616 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007617 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007618 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007619 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007620 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7621 Phone phone = PhoneFactory.getPhone(phoneId);
7622 if (phone == null) {
7623 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007624 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007625 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7626 if (cpt == null) {
7627 continue;
7628 }
7629 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007630 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7631 break;
7632 }
7633 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007634 return result;
Junda Liu29340342014-07-10 15:23:27 -07007635 }
Derek Tan89e89d42014-07-08 17:00:10 -07007636
7637 @Override
Junda Liue64de782015-04-16 17:19:16 -07007638 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007639 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007640
7641 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7642 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7643 "getCarrierPackageNamesForIntentAndPhone");
7644
Rambo Wang8a247eb2022-02-08 21:11:18 +00007645 Phone phone = PhoneFactory.getPhone(phoneId);
7646 if (phone == null) {
7647 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007648 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007649 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7650 if (cpt == null) {
7651 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007652 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007653 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007654 }
7655
Amith Yamasani6e118872016-02-19 12:53:51 -08007656 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007657 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007658 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007659 Phone phone = PhoneFactory.getPhone(phoneId);
7660 if (phone == null) {
7661 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007662 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007663 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7664 if (cpt == null) {
7665 return Collections.emptyList();
7666 }
7667 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007668 }
7669
chen xuf7e9fe82019-05-09 19:31:02 -07007670 @Override
7671 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007672 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
joonhunshin4ac60942023-11-15 15:23:39 +00007673
7674 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7675 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7676 "getPackagesWithCarrierPrivilegesForAllPhones");
7677
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007678 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007679 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007680 try {
7681 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7682 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7683 }
7684 } finally {
7685 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007686 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007687 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007688 }
7689
Rambo Wang6812ffb2022-03-15 16:54:17 -07007690 @Override
7691 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7692 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7693
joonhunshin4ac60942023-11-15 15:23:39 +00007694 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7695 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7696 "getCarrierServicePackageNameForLogicalSlot");
7697
Rambo Wang6812ffb2022-03-15 16:54:17 -07007698 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7699 if (phone == null) {
7700 return null;
7701 }
7702 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7703 if (cpt == null) {
7704 return null;
7705 }
7706 return cpt.getCarrierServicePackageName();
7707 }
7708
Wink Savilleb564aae2014-10-23 10:18:09 -07007709 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007710 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007711 UiccPort port = phone == null ? null : phone.getUiccPort();
7712 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007713 return null;
7714 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007715 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007716 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007717 return null;
7718 }
7719 return iccId;
7720 }
7721
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007722 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007723 public void setCallComposerStatus(int subId, int status) {
7724 enforceModifyPermission();
7725
joonhunshin4ac60942023-11-15 15:23:39 +00007726 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7727 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus");
7728
Shuo Qiane4e11672020-12-15 22:15:33 -08007729 final long identity = Binder.clearCallingIdentity();
7730 try {
7731 Phone phone = getPhone(subId);
7732 if (phone != null) {
7733 Phone defaultPhone = phone.getImsPhone();
7734 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7735 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7736 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007737 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7738 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007739 }
7740 }
Shuo Qian284ae752020-12-22 19:10:14 -08007741 } catch (ImsException e) {
7742 throw new ServiceSpecificException(e.getCode());
7743 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007744 Binder.restoreCallingIdentity(identity);
7745 }
7746 }
7747
7748 @Override
7749 public int getCallComposerStatus(int subId) {
7750 enforceReadPrivilegedPermission("getCallComposerStatus");
7751
joonhunshin4ac60942023-11-15 15:23:39 +00007752 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7753 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus");
7754
Shuo Qiane4e11672020-12-15 22:15:33 -08007755 final long identity = Binder.clearCallingIdentity();
7756 try {
7757 Phone phone = getPhone(subId);
7758 if (phone != null) {
7759 Phone defaultPhone = phone.getImsPhone();
7760 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7761 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7762 return imsPhone.getCallComposerStatus();
7763 }
7764 }
7765 } finally {
7766 Binder.restoreCallingIdentity(identity);
7767 }
7768 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7769 }
7770
7771 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007772 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7773 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007774 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007775 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007776
joonhunshin4ac60942023-11-15 15:23:39 +00007777 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7778 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7779 "setLine1NumberForDisplayForSubscriber");
7780
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007781 final long identity = Binder.clearCallingIdentity();
7782 try {
7783 final String iccId = getIccId(subId);
7784 final Phone phone = getPhone(subId);
7785 if (phone == null) {
7786 return false;
7787 }
7788 final String subscriberId = phone.getSubscriberId();
7789
7790 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007791 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007792 + subscriberId + " to " + number);
7793 }
7794
7795 if (TextUtils.isEmpty(iccId)) {
7796 return false;
7797 }
7798
7799 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7800
7801 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7802 if (alphaTag == null) {
7803 editor.remove(alphaTagPrefKey);
7804 } else {
7805 editor.putString(alphaTagPrefKey, alphaTag);
7806 }
7807
7808 // Record both the line number and IMSI for this ICCID, since we need to
7809 // track all merged IMSIs based on line number
7810 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7811 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7812 if (number == null) {
7813 editor.remove(numberPrefKey);
7814 editor.remove(subscriberPrefKey);
7815 } else {
7816 editor.putString(numberPrefKey, number);
7817 editor.putString(subscriberPrefKey, subscriberId);
7818 }
7819
7820 editor.commit();
7821 return true;
7822 } finally {
7823 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007824 }
Derek Tan7226c842014-07-02 17:42:23 -07007825 }
7826
7827 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007828 public String getLine1NumberForDisplay(int subId, String callingPackage,
7829 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007830 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007831 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007832 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007833 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007834 return null;
7835 }
Derek Tan97ebb422014-09-05 16:55:38 -07007836
joonhunshin4ac60942023-11-15 15:23:39 +00007837 enforceTelephonyFeatureWithException(callingPackage,
7838 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay");
7839
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007840 final long identity = Binder.clearCallingIdentity();
7841 try {
7842 String iccId = getIccId(subId);
7843 if (iccId != null) {
7844 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7845 if (DBG_MERGE) {
7846 log("getLine1NumberForDisplay returning "
7847 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7848 }
7849 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007850 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007851 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7852 return null;
7853 } finally {
7854 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007855 }
Derek Tan7226c842014-07-02 17:42:23 -07007856 }
7857
7858 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007859 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7860 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007861 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007862 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007863 return null;
7864 }
Derek Tan97ebb422014-09-05 16:55:38 -07007865
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007866 final long identity = Binder.clearCallingIdentity();
7867 try {
7868 String iccId = getIccId(subId);
7869 if (iccId != null) {
7870 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7871 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7872 }
7873 return null;
7874 } finally {
7875 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007876 }
Derek Tan7226c842014-07-02 17:42:23 -07007877 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007878
7879 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007880 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7881 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007882 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7883 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007884 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007885 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007886 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007887 return null;
7888 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007889
Jordan Liub49b04b2019-05-06 14:45:15 -07007890 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7891 // the process, where TelephonyManager was instantiated.
7892 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007893 final long identity = Binder.clearCallingIdentity();
7894 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007895 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007896 final TelephonyManager tele = TelephonyManager.from(context);
7897 final SubscriptionManager sub = SubscriptionManager.from(context);
7898
7899 // Figure out what subscribers are currently active
7900 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007901
Jordan Liub49b04b2019-05-06 14:45:15 -07007902 // Only consider subs which match the current subId
7903 // This logic can be simplified. See b/131189269 for progress.
7904 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007905 activeSubscriberIds.add(tele.getSubscriberId(subId));
7906 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007907
7908 // First pass, find a number override for an active subscriber
7909 String mergeNumber = null;
7910 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7911 for (String key : prefs.keySet()) {
7912 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7913 final String subscriberId = (String) prefs.get(key);
7914 if (activeSubscriberIds.contains(subscriberId)) {
7915 final String iccId = key.substring(
7916 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7917 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7918 mergeNumber = (String) prefs.get(numberKey);
7919 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007920 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007921 + " for active subscriber " + subscriberId);
7922 }
7923 if (!TextUtils.isEmpty(mergeNumber)) {
7924 break;
7925 }
7926 }
7927 }
7928 }
7929
7930 // Shortcut when no active merged subscribers
7931 if (TextUtils.isEmpty(mergeNumber)) {
7932 return null;
7933 }
7934
7935 // Second pass, find all subscribers under that line override
7936 final ArraySet<String> result = new ArraySet<>();
7937 for (String key : prefs.keySet()) {
7938 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7939 final String number = (String) prefs.get(key);
7940 if (mergeNumber.equals(number)) {
7941 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7942 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7943 final String subscriberId = (String) prefs.get(subscriberKey);
7944 if (!TextUtils.isEmpty(subscriberId)) {
7945 result.add(subscriberId);
7946 }
7947 }
7948 }
7949 }
7950
7951 final String[] resultArray = result.toArray(new String[result.size()]);
7952 Arrays.sort(resultArray);
7953 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007954 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007955 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7956 }
7957 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007958 } finally {
7959 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007960 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007961 }
7962
7963 @Override
zoey chen38003472019-12-13 17:16:31 +08007964 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7965 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007966
joonhunshin4ac60942023-11-15 15:23:39 +00007967 enforceTelephonyFeatureWithException(callingPackage,
7968 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup");
7969
Malcolm Chen6ca97372019-07-01 16:28:21 -07007970 final long identity = Binder.clearCallingIdentity();
7971 try {
7972 final TelephonyManager telephonyManager = mApp.getSystemService(
7973 TelephonyManager.class);
7974 String subscriberId = telephonyManager.getSubscriberId(subId);
7975 if (subscriberId == null) {
7976 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007977 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007978 + subId);
7979 }
7980 return null;
7981 }
7982
Jack Yu3beaf9d2023-04-14 09:17:27 -07007983 final SubscriptionInfo info = getSubscriptionManagerService()
7984 .getSubscriptionInfo(subId);
7985 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07007986 // If it doesn't belong to any group, return just subscriberId of itself.
7987 if (groupUuid == null) {
7988 return new String[]{subscriberId};
7989 }
7990
7991 // Get all subscriberIds from the group.
7992 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07007993 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
7994 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7995 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007996 for (SubscriptionInfo subInfo : groupInfos) {
7997 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7998 if (subscriberId != null) {
7999 mergedSubscriberIds.add(subscriberId);
8000 }
8001 }
8002
8003 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
8004 } finally {
8005 Binder.restoreCallingIdentity(identity);
8006
8007 }
8008 }
8009
8010 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008011 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008012 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08008013 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008014
joonhunshin4ac60942023-11-15 15:23:39 +00008015 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8016 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride");
8017
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008018 final long identity = Binder.clearCallingIdentity();
8019 try {
8020 final Phone phone = getPhone(subId);
8021 return phone == null ? false : phone.setOperatorBrandOverride(brand);
8022 } finally {
8023 Binder.restoreCallingIdentity(identity);
8024 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07008025 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05008026
8027 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008028 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008029 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
8030 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008031 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
8032 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008033
8034 final long identity = Binder.clearCallingIdentity();
8035 try {
8036 final Phone phone = getPhone(subId);
8037 if (phone == null) {
8038 return false;
8039 }
8040 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
8041 cdmaNonRoamingList);
8042 } finally {
8043 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008044 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008045 }
8046
8047 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07008048 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008049 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08008050 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008051 if (phone == null) {
8052 return raf;
8053 }
8054
Shuo Qiandee53402020-05-29 14:08:15 -07008055 try {
8056 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008057 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07008058 mApp, phone.getSubId(), "getRadioAccessFamily");
8059 } catch (SecurityException e) {
8060 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
8061 throw e;
8062 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008063
joonhunshin4ac60942023-11-15 15:23:39 +00008064 enforceTelephonyFeatureWithException(callingPackage,
8065 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily");
8066
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008067 final long identity = Binder.clearCallingIdentity();
8068 try {
chen xub97461a2018-10-26 14:17:57 -07008069 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008070 } finally {
8071 Binder.restoreCallingIdentity(identity);
8072 }
chen xub97461a2018-10-26 14:17:57 -07008073 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07008074 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008075
8076 @Override
Hall Liu82694d52020-12-11 18:22:04 -08008077 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08008078 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08008079 try {
8080 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
8081 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008082 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008083 }
8084 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008085 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008086 }
joonhunshin4ac60942023-11-15 15:23:39 +00008087
8088 enforceTelephonyFeatureWithException(callingPackage,
8089 PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture");
8090
Hall Liu82694d52020-12-11 18:22:04 -08008091 RoleManager rm = mApp.getSystemService(RoleManager.class);
8092 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
8093 if (!dialerRoleHolders.contains(callingPackage)) {
8094 throw new SecurityException("App must be the dialer role holder to"
8095 + " upload a call composer pic");
8096 }
8097
8098 Executors.newSingleThreadExecutor().execute(() -> {
8099 ByteArrayOutputStream output = new ByteArrayOutputStream(
8100 (int) TelephonyManager.getMaximumCallComposerPictureSize());
8101 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
8102 boolean readUntilEnd = false;
8103 int totalBytesRead = 0;
8104 byte[] buffer = new byte[16 * 1024];
8105 while (true) {
8106 int numRead;
8107 try {
8108 numRead = input.read(buffer);
8109 } catch (IOException e) {
8110 try {
8111 fd.checkError();
8112 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
8113 null);
8114 } catch (IOException e1) {
8115 // This means that the other side closed explicitly with an error. If this
8116 // happens, log and ignore.
8117 loge("Remote end of call composer picture pipe closed: " + e1);
8118 }
8119 break;
8120 }
8121 if (numRead == -1) {
8122 readUntilEnd = true;
8123 break;
8124 }
8125 totalBytesRead += numRead;
8126 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
8127 loge("Too many bytes read for call composer picture: " + totalBytesRead);
8128 try {
8129 input.close();
8130 } catch (IOException e) {
8131 // ignore
8132 }
8133 break;
8134 }
8135 output.write(buffer, 0, numRead);
8136 }
8137 // Generally, the remote end will close the file descriptors. The only case where we
8138 // close is above, where the picture size is too big.
8139
8140 try {
8141 fd.checkError();
8142 } catch (IOException e) {
8143 loge("Remote end for call composer closed with an error: " + e);
8144 return;
8145 }
8146
Hall Liuaa4211e2021-01-20 15:43:39 -08008147 if (!readUntilEnd) {
8148 loge("Did not finish reading entire image; aborting");
8149 return;
8150 }
Hall Liu82694d52020-12-11 18:22:04 -08008151
Hall Liuaa4211e2021-01-20 15:43:39 -08008152 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
8153 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
8154 new CallComposerPictureTransfer.Factory() {},
8155 imageData,
8156 (result) -> {
8157 if (result.first != null) {
8158 ParcelUuid parcelUuid = new ParcelUuid(result.first);
8159 Bundle outputResult = new Bundle();
8160 outputResult.putParcelable(
8161 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
8162 callback.send(TelephonyManager.CallComposerException.SUCCESS,
8163 outputResult);
8164 } else {
8165 callback.send(result.second, null);
8166 }
8167 }
8168 );
Hall Liu82694d52020-12-11 18:22:04 -08008169 });
8170 }
8171
8172 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07008173 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008174 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07008175 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008176
joonhunshin4ac60942023-11-15 15:23:39 +00008177 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8178 PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling");
8179
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008180 final long identity = Binder.clearCallingIdentity();
8181 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008182 ImsManager.getInstance(defaultPhone.getContext(),
8183 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008184 } finally {
8185 Binder.restoreCallingIdentity(identity);
8186 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008187 }
8188
8189 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008190 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008191 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008192 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
8193 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00008194 return false;
8195 }
Svet Ganovb320e182015-04-16 12:30:10 -07008196
joonhunshin4ac60942023-11-15 15:23:39 +00008197 enforceTelephonyFeatureWithException(callingPackage,
8198 PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled");
8199
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008200 final long identity = Binder.clearCallingIdentity();
8201 try {
8202 // Check the user preference and the system-level IMS setting. Even if the user has
8203 // enabled video calling, if IMS is disabled we aren't able to support video calling.
8204 // In the long run, we may instead need to check if there exists a connection service
8205 // which can support video calling.
8206 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008207 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008208 return imsManager.isVtEnabledByPlatform()
8209 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
8210 && imsManager.isVtEnabledByUser();
8211 } finally {
8212 Binder.restoreCallingIdentity(identity);
8213 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008214 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06008215
Andrew Leea1239f22015-03-02 17:44:07 -08008216 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008217 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
8218 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008219 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008220 mApp, subId, callingPackage, callingFeatureId,
8221 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008222 return false;
8223 }
8224
joonhunshin4ac60942023-11-15 15:23:39 +00008225 enforceTelephonyFeatureWithException(callingPackage,
8226 PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength");
8227
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008228 final long identity = Binder.clearCallingIdentity();
8229 try {
8230 CarrierConfigManager configManager =
8231 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008232 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008233 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
8234 } finally {
8235 Binder.restoreCallingIdentity(identity);
8236 }
Andrew Leea1239f22015-03-02 17:44:07 -08008237 }
8238
8239 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008240 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008241 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008242 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008243 return false;
8244 }
8245
joonhunshin4ac60942023-11-15 15:23:39 +00008246 enforceTelephonyFeatureWithException(callingPackage,
8247 PackageManager.FEATURE_TELEPHONY, "isWorldPhone");
8248
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008249 final long identity = Binder.clearCallingIdentity();
8250 try {
8251 CarrierConfigManager configManager =
8252 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008253 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008254 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
8255 } finally {
8256 Binder.restoreCallingIdentity(identity);
8257 }
Andrew Leea1239f22015-03-02 17:44:07 -08008258 }
8259
Andrew Lee9431b832015-03-09 18:46:45 -07008260 @Override
8261 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008262 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08008263 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07008264 }
8265
8266 @Override
8267 public boolean isHearingAidCompatibilitySupported() {
joonhunshin4ac60942023-11-15 15:23:39 +00008268 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8269 PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported");
8270
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008271 final long identity = Binder.clearCallingIdentity();
8272 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008273 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008274 } finally {
8275 Binder.restoreCallingIdentity(identity);
8276 }
Andrew Lee9431b832015-03-09 18:46:45 -07008277 }
8278
Hall Liuf6668912018-10-31 17:05:23 -07008279 /**
8280 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
8281 * support for the feature and device firmware support.
8282 *
8283 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
8284 */
8285 @Override
8286 public boolean isRttSupported(int subscriptionId) {
joonhunshin4ac60942023-11-15 15:23:39 +00008287 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8288 PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported");
8289
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008290 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008291 final Phone phone = getPhone(subscriptionId);
8292 if (phone == null) {
8293 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
8294 return false;
8295 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008296 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008297 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008298 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
joonhunshin4ac60942023-11-15 15:23:39 +00008299 boolean isDeviceSupported = (phone.getContext().getResources() != null)
8300 ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt)
8301 : false;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008302 return isCarrierSupported && isDeviceSupported;
8303 } finally {
8304 Binder.restoreCallingIdentity(identity);
8305 }
Hall Liu98187582018-01-22 19:15:32 -08008306 }
8307
Hall Liuf6668912018-10-31 17:05:23 -07008308 /**
Hall Liuf2daa022019-07-23 18:39:00 -07008309 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
8310 * RTT setting, will return true if the device and carrier both support RTT.
8311 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07008312 */
8313 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008314 final long identity = Binder.clearCallingIdentity();
8315 try {
joonhunshin4ac60942023-11-15 15:23:39 +00008316 if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) {
8317 if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
8318 return false;
8319 }
8320 }
8321
Hall Liu5bab75c2019-12-11 23:58:20 +00008322 boolean isRttSupported = isRttSupported(subscriptionId);
8323 boolean isUserRttSettingOn = Settings.Secure.getInt(
8324 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
8325 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
8326 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
8327 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008328 } finally {
8329 Binder.restoreCallingIdentity(identity);
8330 }
Hall Liu3ad5f012018-04-06 16:23:39 -07008331 }
8332
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008333 @Deprecated
8334 @Override
8335 public String getDeviceId(String callingPackage) {
8336 return getDeviceIdWithFeature(callingPackage, null);
8337 }
8338
Sanket Padawe7310cc72015-01-14 09:53:20 -08008339 /**
8340 * Returns the unique device ID of phone, for example, the IMEI for
8341 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
8342 *
8343 * <p>Requires Permission:
8344 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
8345 */
8346 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008347 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07008348 try {
8349 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
8350 } catch (SecurityException se) {
8351 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
8352 throw new SecurityException("Package " + callingPackage + " does not belong to "
8353 + Binder.getCallingUid());
8354 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008355 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008356 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008357 return null;
8358 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008359 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008360 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008361 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008362 return null;
8363 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008364
8365 final long identity = Binder.clearCallingIdentity();
8366 try {
8367 return phone.getDeviceId();
8368 } finally {
8369 Binder.restoreCallingIdentity(identity);
8370 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008371 }
8372
Ping Sunc67b7c22016-03-02 19:16:45 +08008373 /**
8374 * {@hide}
8375 * Returns the IMS Registration Status on a particular subid
8376 *
8377 * @param subId
8378 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008379 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008380 Phone phone = getPhone(subId);
8381 if (phone != null) {
8382 return phone.isImsRegistered();
8383 } else {
8384 return false;
8385 }
8386 }
8387
Santos Cordon7a1885b2015-02-03 11:15:19 -08008388 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008389 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008390 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008391 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008392 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008393 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8394 }
8395 final long identity = Binder.clearCallingIdentity();
8396 try {
8397 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8398 } finally {
8399 Binder.restoreCallingIdentity(identity);
8400 }
8401 }
8402
8403 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008404 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008405 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008406 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008407 mApp,
8408 subscriptionId,
8409 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
8410 + subscriptionId);
joonhunshin4ac60942023-11-15 15:23:39 +00008411
8412 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8413 PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId");
8414
Tyler Gunnf70ed162019-04-03 15:28:53 -07008415 final long identity = Binder.clearCallingIdentity();
8416 try {
8417 Phone phone = getPhone(subscriptionId);
8418 if (phone == null) {
8419 return null;
8420 }
8421 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8422 } finally {
8423 Binder.restoreCallingIdentity(identity);
8424 }
8425 }
8426
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008427 /**
8428 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008429 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008430 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008431 final long identity = Binder.clearCallingIdentity();
8432 try {
8433 Phone phone = getPhone(subId);
8434 if (phone != null) {
8435 return phone.isWifiCallingEnabled();
8436 } else {
8437 return false;
8438 }
8439 } finally {
8440 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008441 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008442 }
8443
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008444 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008445 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008446 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008447 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008448 final long identity = Binder.clearCallingIdentity();
8449 try {
8450 Phone phone = getPhone(subId);
8451 if (phone != null) {
8452 return phone.isVideoEnabled();
8453 } else {
8454 return false;
8455 }
8456 } finally {
8457 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008458 }
8459 }
8460
8461 /**
8462 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8463 * defined in {@link ImsRegistrationImplBase}.
8464 */
8465 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008466 final long identity = Binder.clearCallingIdentity();
8467 try {
8468 Phone phone = getPhone(subId);
8469 if (phone != null) {
8470 return phone.getImsRegistrationTech();
8471 } else {
8472 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8473 }
8474 } finally {
8475 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008476 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008477 }
8478
Stuart Scott8eef64f2015-04-08 15:13:54 -07008479 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008480 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008481 enforceSettingsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008482
8483 enforceTelephonyFeatureWithException(callingPackage,
8484 PackageManager.FEATURE_TELEPHONY, "factoryReset");
8485
Stuart Scott981d8582015-04-21 14:09:50 -07008486 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8487 return;
8488 }
Kai Shif70f46f2021-03-03 13:59:46 -08008489 Phone defaultPhone = getDefaultPhone();
8490 if (defaultPhone != null) {
8491 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8492 mApp, getDefaultPhone().getSubId(), "factoryReset");
8493 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008494 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008495
Svet Ganovcc087f82015-05-12 20:35:54 -07008496 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008497 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8498 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008499 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008500 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008501 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008502 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008503 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008504 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08008505 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008506 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008507 // There has been issues when Sms raw table somehow stores orphan
8508 // fragments. They lead to garbled message when new fragments come
8509 // in and combined with those stale ones. In case this happens again,
8510 // user can reset all network settings which will clean up this table.
8511 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008512 // Clean up IMS settings as well here.
8513 int slotId = getSlotIndex(subId);
8514 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
8515 ImsManager.getInstance(mApp, slotId).factoryReset();
8516 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008517
Kai Shif70f46f2021-03-03 13:59:46 -08008518 if (defaultPhone == null) {
8519 return;
8520 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008521 // Erase modem config if erase modem on network setting is enabled.
8522 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8523 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8524 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008525 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008526 }
Kai Shif70f46f2021-03-03 13:59:46 -08008527
8528 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008529 } finally {
8530 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008531 }
8532 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008533
SongFerngWangfd89b102021-05-27 22:44:54 +08008534 @VisibleForTesting
8535 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8536 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8537 return;
8538 }
8539 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8540 RILConstants.PREFERRED_NETWORK_MODE);
8541 SubscriptionManager.setSubscriptionProperty(subId,
8542 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8543 "user=" + defaultNetworkType);
8544 phone.loadAllowedNetworksFromSubscriptionDatabase();
8545 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8546 defaultNetworkType, null);
8547 }
8548
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008549 private void cleanUpSmsRawTable(Context context) {
8550 ContentResolver resolver = context.getContentResolver();
8551 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8552 resolver.delete(uri, null, null);
8553 }
8554
Narayan Kamath1c496c22015-04-16 14:40:19 +01008555 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008556 public String getSimLocaleForSubscriber(int subId) {
8557 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
joonhunshin4ac60942023-11-15 15:23:39 +00008558
8559 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8560 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber");
8561
chen xu5d3637b2019-01-21 23:31:38 -08008562 final Phone phone = getPhone(subId);
8563 if (phone == null) {
8564 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008565 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008566 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008567 final long identity = Binder.clearCallingIdentity();
8568 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008569 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
8570 phone.getContext().getOpPackageName(),
8571 phone.getContext().getAttributionTag());
8572 if (info == null) {
8573 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8574 return null;
chen xu6291c472019-02-04 12:55:53 -08008575 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008576 // Try and fetch the locale from the carrier properties or from the SIM language
8577 // preferences (EF-PL and EF-LI)...
8578 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008579 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008580 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8581 if (localeFromDefaultSim != null) {
8582 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8583 if (DBG) log("Using locale from subId: " + subId + " locale: "
8584 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008585 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008586 } else {
8587 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008588 }
8589 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008590
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008591 // The SIM language preferences only store a language (e.g. fr = French), not an
8592 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8593 // the SIM and carrier preferences does not include a country we add the country
8594 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008595 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008596 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008597 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008598 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008599 }
8600
8601 if (DBG) log("No locale found - returning null");
8602 return null;
8603 } finally {
8604 Binder.restoreCallingIdentity(identity);
8605 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008606 }
8607
tom hsu0b59d292022-09-29 23:49:21 +08008608 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008609 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008610 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008611 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008612 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008613 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8614 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008615 Locale.forLanguageTag(localeTag).getCountry())) {
8616 return localeTag;
8617 }
8618 }
8619 return inputLocale.toLanguageTag();
8620 }
8621
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008622 /**
8623 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8624 */
8625 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008626 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Ling Ma9fa67412023-11-13 14:13:19 -08008627 mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/);
Narayan Kamath1c496c22015-04-16 14:40:19 +01008628 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008629
Gary Jian3aa9a762022-01-24 16:41:19 +08008630 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8631 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008632
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008633 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008634 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8635 * representing the state of the modem.
8636 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008637 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8638 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008639 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008640 */
8641 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008642 public void requestModemActivityInfo(ResultReceiver result) {
8643 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008644
8645 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8646 PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo");
8647
vagdeviaf9a5b92018-08-15 16:01:53 -07008648 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008649
8650 final long identity = Binder.clearCallingIdentity();
8651 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008652 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008653 } finally {
8654 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008655 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008656 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008657
Gary Jian76280a42022-12-07 16:18:33 +08008658 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008659 // less than total activity duration.
8660 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8661 if (info == null) {
8662 return false;
8663 }
8664 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008665 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008666 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8667
Hall Liu49656c02020-10-09 19:00:11 -07008668 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8669
Siddharth Rayb8114062018-06-17 15:02:38 -07008670 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008671 && (info.getSleepTimeMillis() <= activityDurationMs)
8672 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008673 }
8674
Gary Jian3aa9a762022-01-24 16:41:19 +08008675 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8676 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8677 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8678 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8679
8680 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8681 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8682 }
8683
8684 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8685 mLastModemActivityInfo.setReceiveTimeMillis(
8686 rat,
8687 freq,
8688 info.getReceiveTimeMillis(rat, freq)
8689 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8690 }
8691
8692 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8693 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8694 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8695 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8696
8697 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8698 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8699 }
8700 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8701 mLastModemActivityInfo.setReceiveTimeMillis(
8702 rat,
8703 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8704 }
8705
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008706 /**
8707 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8708 * @param info recent ModemActivityInfo
8709 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008710 private void mergeModemActivityInfo(ModemActivityInfo info) {
8711 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008712 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008713 boolean matched;
8714 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8715 matched = false;
8716 int rat = info.getSpecificInfoRat(i);
8717 int freq = info.getSpecificInfoFrequencyRange(i);
8718 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8719 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8720 //if it already exists
8721 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8722 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8723 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8724 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8725 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8726 updateLastModemActivityInfo(info, rat, freq);
8727 matched = true;
8728 }
8729 } else {
8730 updateLastModemActivityInfo(info, rat);
8731 matched = true;
8732 }
8733 }
8734 }
8735
8736 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008737 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008738 new ActivityStatsTechSpecificInfo(
8739 rat,
8740 freq,
8741 info.getTransmitTimeMillis(rat, freq),
8742 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008743 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008744 }
8745 }
8746 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8747 mLastModemActivitySpecificInfo =
8748 new ActivityStatsTechSpecificInfo[merged.size()];
8749 merged.toArray(mLastModemActivitySpecificInfo);
8750
8751 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8752 mLastModemActivityInfo.setSleepTimeMillis(
8753 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008754 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008755 mLastModemActivityInfo.setIdleTimeMillis(
8756 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008757 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008758
8759 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008760 new ModemActivityInfo(
8761 mLastModemActivityInfo.getTimestampMillis(),
8762 mLastModemActivityInfo.getSleepTimeMillis(),
8763 mLastModemActivityInfo.getIdleTimeMillis(),
8764 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008765 }
8766
8767 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8768 ActivityStatsTechSpecificInfo[] info) {
8769 int infoSize = info.length;
8770 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8771 for (int i = 0; i < infoSize; i++) {
8772 ret[i] = new ActivityStatsTechSpecificInfo(
8773 info[i].getRat(), info[i].getFrequencyRange(),
8774 info[i].getTransmitTimeMillis(),
8775 (int) info[i].getReceiveTimeMillis());
8776 }
8777 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008778 }
8779
Jack Yu85bd38a2015-11-09 11:34:32 -08008780 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008781 * Returns the service state information on specified subscription.
8782 */
8783 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008784 public ServiceState getServiceStateForSubscriber(int subId,
8785 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8786 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008787 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008788 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008789 return null;
8790 }
8791
joonhunshin4ac60942023-11-15 15:23:39 +00008792 enforceTelephonyFeatureWithException(callingPackage,
8793 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber");
8794
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008795 boolean hasFinePermission = false;
8796 boolean hasCoarsePermission = false;
8797 if (!renounceFineLocationAccess) {
8798 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8799 LocationAccessPolicy.checkLocationPermission(mApp,
8800 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8801 .setCallingPackage(callingPackage)
8802 .setCallingFeatureId(callingFeatureId)
8803 .setCallingPid(Binder.getCallingPid())
8804 .setCallingUid(Binder.getCallingUid())
8805 .setMethod("getServiceStateForSubscriber")
8806 .setLogAsInfo(true)
8807 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8808 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8809 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8810 .build());
8811 hasFinePermission =
8812 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8813 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008814
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008815 if (!renounceCoarseLocationAccess) {
8816 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8817 LocationAccessPolicy.checkLocationPermission(mApp,
8818 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8819 .setCallingPackage(callingPackage)
8820 .setCallingFeatureId(callingFeatureId)
8821 .setCallingPid(Binder.getCallingPid())
8822 .setCallingUid(Binder.getCallingUid())
8823 .setMethod("getServiceStateForSubscriber")
8824 .setLogAsInfo(true)
8825 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8826 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8827 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8828 .build());
8829 hasCoarsePermission =
8830 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8831 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008832
Jack Yu479f40e2020-10-27 21:29:25 -07008833 final Phone phone = getPhone(subId);
8834 if (phone == null) {
8835 return null;
8836 }
8837
Jordan Liu0f2bc442020-11-18 16:47:37 -08008838 final long identity = Binder.clearCallingIdentity();
8839
Jack Yu479f40e2020-10-27 21:29:25 -07008840 boolean isCallingPackageDataService = phone.getDataServicePackages()
8841 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008842 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008843 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu3beaf9d2023-04-14 09:17:27 -07008844 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8845 .getSubscriptionInfoInternal(subId);
8846 if (subInfo == null || !subInfo.isActive()) {
8847 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8848 + "subId=" + subId);
8849 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008850 }
8851
Hall Liuf19c44f2018-11-27 14:38:17 -08008852 ServiceState ss = phone.getServiceState();
8853
8854 // Scrub out the location info in ServiceState depending on what level of access
8855 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008856 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008857 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8858 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008859 } finally {
8860 Binder.restoreCallingIdentity(identity);
8861 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008862 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008863
8864 /**
8865 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8866 *
8867 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8868 * voicemail ringtone.
8869 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8870 * PhoneAccount.
8871 */
8872 @Override
8873 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008874 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8875 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri");
8876
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008877 final long identity = Binder.clearCallingIdentity();
8878 try {
8879 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8880 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008881 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008882 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008883
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008884 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8885 } finally {
8886 Binder.restoreCallingIdentity(identity);
8887 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008888 }
8889
8890 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008891 * Sets the per-account voicemail ringtone.
8892 *
8893 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8894 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8895 *
8896 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8897 * voicemail ringtone.
8898 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8899 * PhoneAccount.
8900 */
8901 @Override
8902 public void setVoicemailRingtoneUri(String callingPackage,
8903 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008904 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008905 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008906 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8907 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008908 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8909 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8910 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008911 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008912
joonhunshin4ac60942023-11-15 15:23:39 +00008913 enforceTelephonyFeatureWithException(callingPackage,
8914 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri");
8915
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008916 final long identity = Binder.clearCallingIdentity();
8917 try {
8918 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8919 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008920 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008921 }
8922 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8923 } finally {
8924 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008925 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008926 }
8927
8928 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008929 * Returns whether vibration is set for voicemail notification in Phone settings.
8930 *
8931 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8932 * voicemail vibration setting.
8933 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8934 */
8935 @Override
8936 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008937 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8938 PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled");
8939
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008940 final long identity = Binder.clearCallingIdentity();
8941 try {
8942 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8943 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008944 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008945 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008946
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008947 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8948 } finally {
8949 Binder.restoreCallingIdentity(identity);
8950 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008951 }
8952
Youhan Wange64578a2016-05-02 15:32:42 -07008953 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008954 * Sets the per-account voicemail vibration.
8955 *
8956 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8957 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8958 *
8959 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8960 * voicemail vibration setting.
8961 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8962 * specific PhoneAccount.
8963 */
8964 @Override
8965 public void setVoicemailVibrationEnabled(String callingPackage,
8966 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008967 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008968 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008969 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8970 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008971 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8972 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8973 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008974 }
8975
joonhunshin4ac60942023-11-15 15:23:39 +00008976 enforceTelephonyFeatureWithException(callingPackage,
8977 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled");
8978
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008979 final long identity = Binder.clearCallingIdentity();
8980 try {
8981 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8982 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008983 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008984 }
8985 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8986 } finally {
8987 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008988 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008989 }
8990
8991 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008992 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8993 *
8994 * @throws SecurityException if the caller does not have the required permission
8995 */
arunvoddud7401012022-12-15 16:08:12 +00008996 @VisibleForTesting
8997 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008998 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008999 message);
Youhan Wange64578a2016-05-02 15:32:42 -07009000 }
9001
9002 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009003 * Make sure either called from same process as self (phone) or IPC caller has send SMS
9004 * permission.
9005 *
9006 * @throws SecurityException if the caller does not have the required permission
9007 */
9008 private void enforceSendSmsPermission() {
9009 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
9010 }
9011
9012 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00009013 * Make sure either called from same process as self (phone) or IPC caller has interact across
9014 * users permission.
9015 *
9016 * @throws SecurityException if the caller does not have the required permission
9017 */
9018 private void enforceInteractAcrossUsersPermission(String message) {
9019 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
9020 }
9021
9022 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009023 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009024 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009025 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009026 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009027 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009028 final long identity = Binder.clearCallingIdentity();
9029 try {
9030 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009031 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009032 if (componentName == null) {
9033 throw new SecurityException(
9034 "Caller not current active visual voicemail package[null]");
9035 }
9036 String vvmPackage = componentName.getPackageName();
9037 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00009038 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009039 }
9040 } finally {
9041 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009042 }
9043 }
9044
9045 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009046 * Return the application ID for the app type.
9047 *
9048 * @param subId the subscription ID that this request applies to.
9049 * @param appType the uicc app type.
9050 * @return Application ID for specificied app type, or null if no uicc.
9051 */
9052 @Override
9053 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009054 enforceReadPrivilegedPermission("getAidForAppType");
joonhunshin4ac60942023-11-15 15:23:39 +00009055
9056 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9057 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType");
9058
Youhan Wange64578a2016-05-02 15:32:42 -07009059 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009060
9061 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07009062 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009063 if (phone == null) {
9064 return null;
9065 }
9066 String aid = null;
9067 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009068 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009069 .getApplicationByType(appType).getAid();
9070 } catch (Exception e) {
9071 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
9072 }
9073 return aid;
9074 } finally {
9075 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07009076 }
Youhan Wange64578a2016-05-02 15:32:42 -07009077 }
9078
Youhan Wang4001d252016-05-11 10:29:41 -07009079 /**
9080 * Return the Electronic Serial Number.
9081 *
9082 * @param subId the subscription ID that this request applies to.
9083 * @return ESN or null if error.
9084 */
9085 @Override
9086 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009087 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07009088 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009089
9090 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07009091 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009092 if (phone == null) {
9093 return null;
9094 }
9095 String esn = null;
9096 try {
9097 esn = phone.getEsn();
9098 } catch (Exception e) {
9099 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
9100 }
9101 return esn;
9102 } finally {
9103 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07009104 }
Youhan Wang4001d252016-05-11 10:29:41 -07009105 }
9106
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009107 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009108 * Return the Preferred Roaming List Version.
9109 *
9110 * @param subId the subscription ID that this request applies to.
9111 * @return PRLVersion or null if error.
9112 */
9113 @Override
9114 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009115 enforceReadPrivilegedPermission("getCdmaPrlVersion");
joonhunshin4ac60942023-11-15 15:23:39 +00009116
9117 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9118 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion");
9119
Youhan Wang66ad5d72016-07-18 17:56:58 -07009120 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009121
9122 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009123 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009124 if (phone == null) {
9125 return null;
9126 }
9127 String cdmaPrlVersion = null;
9128 try {
9129 cdmaPrlVersion = phone.getCdmaPrlVersion();
9130 } catch (Exception e) {
9131 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9132 }
9133 return cdmaPrlVersion;
9134 } finally {
9135 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009136 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009137 }
9138
9139 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009140 * Get snapshot of Telephony histograms
9141 * @return List of Telephony histograms
9142 * @hide
9143 */
9144 @Override
9145 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009146 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9147 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009148
9149 final long identity = Binder.clearCallingIdentity();
9150 try {
9151 return RIL.getTelephonyRILTimingHistograms();
9152 } finally {
9153 Binder.restoreCallingIdentity(identity);
9154 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009155 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009156
9157 /**
9158 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009159 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9160 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009161 * Require system privileges. In the future we may add this to carrier APIs.
9162 *
Michele Berionne482f8202018-11-27 18:57:59 -08009163 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009164 */
9165 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009166 @TelephonyManager.SetCarrierRestrictionResult
9167 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009168 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009169
9170 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9171 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers");
9172
vagdeviaf9a5b92018-08-15 16:01:53 -07009173 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009174
Michele Berionne482f8202018-11-27 18:57:59 -08009175 if (carrierRestrictionRules == null) {
9176 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009177 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009178
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009179 final long identity = Binder.clearCallingIdentity();
9180 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009181 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009182 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009183 } finally {
9184 Binder.restoreCallingIdentity(identity);
9185 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009186 }
9187
9188 /**
9189 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009190 * Get the allowed carrier list and the excluded carrier list, including the priority between
9191 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009192 * Require system privileges. In the future we may add this to carrier APIs.
9193 *
Michele Berionne482f8202018-11-27 18:57:59 -08009194 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009195 */
9196 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009197 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009198 enforceReadPrivilegedPermission("getAllowedCarriers");
joonhunshin4ac60942023-11-15 15:23:39 +00009199
9200 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9201 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers");
9202
vagdeviaf9a5b92018-08-15 16:01:53 -07009203 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009204
9205 final long identity = Binder.clearCallingIdentity();
9206 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009207 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9208 if (response instanceof CarrierRestrictionRules) {
9209 return (CarrierRestrictionRules) response;
9210 }
9211 // Response is an Exception of some kind,
9212 // which is signalled to the user as a NULL retval
9213 return null;
9214 } catch (Exception e) {
9215 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9216 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009217 } finally {
9218 Binder.restoreCallingIdentity(identity);
9219 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009220 }
9221
fionaxu59545b42016-05-25 15:53:37 -07009222 /**
arunvoddud7401012022-12-15 16:08:12 +00009223 * Fetches the carrier restriction status of the device and sends the status to the caller
9224 * through the callback.
9225 *
9226 * @param callback The callback that will be used to send the result.
9227 * @throws SecurityException if the caller does not have the required permission/privileges or
9228 * the caller is not allowlisted.
9229 */
9230 @Override
9231 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
9232 enforceReadPermission("getCarrierRestrictionStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00009233
9234 enforceTelephonyFeatureWithException(packageName,
9235 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierRestrictionStatus");
9236
arunvoddud7401012022-12-15 16:08:12 +00009237 int carrierId = validateCallerAndGetCarrierId(packageName);
9238 if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) {
9239 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9240 throw new SecurityException("Not an authorized caller");
9241 }
9242 final long identity = Binder.clearCallingIdentity();
9243 try {
9244 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
9245 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId);
9246 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9247 } finally {
9248 Binder.restoreCallingIdentity(identity);
9249 }
9250 }
9251
arunvoddu567f2b42023-04-25 17:22:00 +00009252 @Override
9253 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
9254 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
9255 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9256 return allowListInfo.getShaIdList(pkgName, carrierId);
9257 }
9258
arunvoddud7401012022-12-15 16:08:12 +00009259 @VisibleForTesting
9260 public int validateCallerAndGetCarrierId(String packageName) {
9261 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9262 return allowListInfo.validateCallerAndGetCarrierId(packageName);
9263 }
9264
9265 /**
fionaxu59545b42016-05-25 15:53:37 -07009266 * Action set from carrier signalling broadcast receivers to enable/disable radio
9267 * @param subId the subscription ID that this action applies to.
9268 * @param enabled control enable or disable radio.
9269 * {@hide}
9270 */
9271 @Override
9272 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9273 enforceModifyPermission();
9274 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009275
9276 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009277 if (phone == null) {
9278 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9279 return;
9280 }
9281 try {
9282 phone.carrierActionSetRadioEnabled(enabled);
9283 } catch (Exception e) {
9284 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009285 } finally {
9286 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009287 }
9288 }
9289
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009290 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009291 * Enable or disable Voice over NR (VoNR)
9292 * @param subId the subscription ID that this action applies to.
9293 * @param enabled enable or disable VoNR.
9294 * @return operation result.
9295 */
9296 @Override
9297 public int setVoNrEnabled(int subId, boolean enabled) {
9298 enforceModifyPermission();
9299 final Phone phone = getPhone(subId);
9300
9301 final long identity = Binder.clearCallingIdentity();
9302 if (phone == null) {
9303 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9304 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9305 }
9306
9307 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9308 try {
9309 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9310 workSource);
9311 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009312
9313 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9314 if (DBG) {
9315 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9316 }
9317 SubscriptionManager.setSubscriptionProperty(
9318 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9319 (enabled ? "1" : "0"));
9320 }
9321
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009322 return result;
9323 } finally {
9324 Binder.restoreCallingIdentity(identity);
9325 }
9326 }
9327
9328 /**
9329 * Is voice over NR enabled
9330 * @return true if VoNR is enabled else false
9331 */
9332 @Override
9333 public boolean isVoNrEnabled(int subId) {
9334 enforceReadPrivilegedPermission("isVoNrEnabled");
9335 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9336 final long identity = Binder.clearCallingIdentity();
9337 try {
9338 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9339 null, subId, workSource);
9340 if (DBG) log("isVoNrEnabled: " + isEnabled);
9341 return isEnabled;
9342 } finally {
9343 Binder.restoreCallingIdentity(identity);
9344 }
9345 }
9346
9347 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009348 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9349 * network status based on which carrier apps could apply actions accordingly,
9350 * enable/disable default url handler for example.
9351 *
9352 * @param subId the subscription ID that this action applies to.
9353 * @param report control start/stop reporting the default network status.
9354 * {@hide}
9355 */
9356 @Override
9357 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9358 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009359
9360 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9361 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
9362 "carrierActionReportDefaultNetworkStatus");
9363
fionaxu8da9cb12017-05-23 15:02:46 -07009364 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009365
9366 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009367 if (phone == null) {
9368 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9369 return;
9370 }
9371 try {
9372 phone.carrierActionReportDefaultNetworkStatus(report);
9373 } catch (Exception e) {
9374 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009375 } finally {
9376 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009377 }
9378 }
9379
9380 /**
fionaxud9622282017-07-17 17:51:30 -07009381 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9382 * @param subId the subscription ID that this action applies to.
9383 * {@hide}
9384 */
9385 @Override
9386 public void carrierActionResetAll(int subId) {
9387 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009388
9389 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9390 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll");
9391
fionaxud9622282017-07-17 17:51:30 -07009392 final Phone phone = getPhone(subId);
9393 if (phone == null) {
9394 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9395 return;
9396 }
9397 try {
9398 phone.carrierActionResetAll();
9399 } catch (Exception e) {
9400 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9401 }
9402 }
9403
9404 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009405 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9406 * bug report is being generated.
9407 */
9408 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009409 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009410 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9411 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009412 writer.println("Permission Denial: can't dump Phone from pid="
9413 + Binder.getCallingPid()
9414 + ", uid=" + Binder.getCallingUid()
9415 + "without permission "
9416 + android.Manifest.permission.DUMP);
9417 return;
9418 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009419 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009420 }
Jack Yueb89b242016-06-22 13:27:47 -07009421
Brad Ebingerdac2f002018-04-03 15:17:52 -07009422 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009423 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9424 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9425 @NonNull String[] args) {
9426 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9427 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009428 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009429 }
9430
Jack Yueb89b242016-06-22 13:27:47 -07009431 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009432 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009433 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009434 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009435 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009436 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009437 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009438 */
9439 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009440 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009441 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009442 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9443 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9444 try {
9445 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009446 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009447 } catch (SecurityException se) {
9448 enforceModifyPermission();
9449 }
9450 } else {
9451 enforceModifyPermission();
9452 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009453
Nate Myrenae97d192023-06-09 15:22:31 -07009454 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
9455 && null != callingPackage && opEnableMobileDataByUser()) {
9456 mAppOps.noteOp(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER, Binder.getCallingUid(),
9457 callingPackage, null, null);
9458 }
9459
joonhunshin4ac60942023-11-15 15:23:39 +00009460 enforceTelephonyFeatureWithException(callingPackage,
9461 PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason");
9462
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009463 final long identity = Binder.clearCallingIdentity();
9464 try {
9465 Phone phone = getPhone(subId);
9466 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009467 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9468 phone.carrierActionSetMeteredApnsEnabled(enabled);
9469 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07009470 phone.getDataSettingsManager().setDataEnabled(
9471 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009472 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009473 }
9474 } finally {
9475 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009476 }
9477 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009478
9479 /**
9480 * Get Client request stats
9481 * @return List of Client Request Stats
9482 * @hide
9483 */
9484 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009485 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9486 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009487 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009488 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009489 return null;
9490 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009491 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009492
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009493 final long identity = Binder.clearCallingIdentity();
9494 try {
9495 if (phone != null) {
9496 return phone.getClientRequestStats();
9497 }
9498
9499 return null;
9500 } finally {
9501 Binder.restoreCallingIdentity(identity);
9502 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009503 }
9504
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009505 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009506 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009507 if (uid == Process.ROOT_UID && packageName == null) {
9508 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9509 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9510 // exception. ROOT_UID seems not to have a valid package name returned by
9511 // PackageManager, so just fake it here to avoid issues when running telephony shell
9512 // commands that plumb through the RIL as root, like so:
9513 // $ adb root
9514 // $ adb shell cmd phone ...
9515 packageName = "root";
9516 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009517 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009518 }
Jack Yueb4124c2017-02-16 15:32:43 -08009519
9520 /**
Grace Chen70990072017-03-24 17:21:30 -07009521 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009522 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009523 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009524 * @param state State of SIM (power down, power up, pass through)
9525 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9526 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9527 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009528 *
9529 **/
9530 @Override
Grace Chen70990072017-03-24 17:21:30 -07009531 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009532 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009533
9534 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9535 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot");
9536
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009537 Phone phone = PhoneFactory.getPhone(slotIndex);
9538
vagdeviaf9a5b92018-08-15 16:01:53 -07009539 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9540
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009541 final long identity = Binder.clearCallingIdentity();
9542 try {
9543 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009544 phone.setSimPowerState(state, null, workSource);
9545 }
9546 } finally {
9547 Binder.restoreCallingIdentity(identity);
9548 }
9549 }
9550
9551 /**
9552 * Set SIM card power state.
9553 *
9554 * @param slotIndex SIM slot id.
9555 * @param state State of SIM (power down, power up, pass through)
9556 * @param callback callback to trigger after success or failure
9557 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9558 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9559 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9560 *
9561 **/
9562 @Override
9563 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9564 IIntegerConsumer callback) {
9565 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009566
9567 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9568 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
9569 "setSimPowerStateForSlotWithCallback");
9570
Jordan Liu109698e2020-11-24 14:50:34 -08009571 Phone phone = PhoneFactory.getPhone(slotIndex);
9572
9573 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9574
9575 final long identity = Binder.clearCallingIdentity();
9576 try {
9577 if (phone != null) {
9578 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9579 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009580 }
9581 } finally {
9582 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009583 }
9584 }
Shuo Qiandd210312017-04-12 22:11:33 +00009585
Tyler Gunn65d45c22017-06-05 11:22:26 -07009586 private boolean isUssdApiAllowed(int subId) {
9587 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009588 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009589 if (configManager == null) {
9590 return false;
9591 }
9592 PersistableBundle pb = configManager.getConfigForSubId(subId);
9593 if (pb == null) {
9594 return false;
9595 }
9596 return pb.getBoolean(
9597 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9598 }
9599
Shuo Qiandd210312017-04-12 22:11:33 +00009600 /**
Ling Mac28f0212023-03-24 16:07:15 -07009601 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00009602 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07009603 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00009604 */
goneil9c5f4872017-12-05 14:07:56 -08009605 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009606 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009607 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
joonhunshin4ac60942023-11-15 15:23:39 +00009608
9609 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9610 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode");
9611
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009612 final long identity = Binder.clearCallingIdentity();
9613 try {
Ling Mac28f0212023-03-24 16:07:15 -07009614 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009615 } finally {
9616 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009617 }
9618 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009619
9620 /**
9621 * Get the current signal strength information for the given subscription.
9622 * Because this information is not updated when the device is in a low power state
9623 * it should not be relied-upon to be current.
9624 * @param subId Subscription index
9625 * @return the most recent cached signal strength info from the modem
9626 */
9627 @Override
9628 public SignalStrength getSignalStrength(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00009629 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9630 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength");
9631
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009632 final long identity = Binder.clearCallingIdentity();
9633 try {
9634 Phone p = getPhone(subId);
9635 if (p == null) {
9636 return null;
9637 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009638
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009639 return p.getSignalStrength();
9640 } finally {
9641 Binder.restoreCallingIdentity(identity);
9642 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009643 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009644
Pengquan Meng77b7f132018-08-22 14:49:57 -07009645 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009646 * Get the current modem radio state for the given slot.
9647 * @param slotIndex slot index.
9648 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009649 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009650 * @return the current radio power state from the modem
9651 */
9652 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009653 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009654 Phone phone = PhoneFactory.getPhone(slotIndex);
9655 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009656 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9657 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009658 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9659 }
9660
joonhunshin4ac60942023-11-15 15:23:39 +00009661 enforceTelephonyFeatureWithException(callingPackage,
9662 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState");
9663
Chen Xuf792fd62018-10-17 17:54:36 +00009664 final long identity = Binder.clearCallingIdentity();
9665 try {
9666 return phone.getRadioPowerState();
9667 } finally {
9668 Binder.restoreCallingIdentity(identity);
9669 }
9670 }
9671 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9672 }
9673
9674 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009675 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9676 *
9677 * <p>Requires one of the following permissions:
9678 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009679 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009680 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9681 * privileges.
9682 *
9683 * @param subId subscription id
9684 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9685 * {@code false}.
9686 */
9687 @Override
9688 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009689 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009690 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009691 try {
9692 mApp.enforceCallingOrSelfPermission(
9693 android.Manifest.permission.ACCESS_NETWORK_STATE,
9694 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009695 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009696 mApp.enforceCallingOrSelfPermission(
9697 permission.READ_BASIC_PHONE_STATE, functionName);
9698 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009699 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009700 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009701 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009702 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009703
joonhunshin4ac60942023-11-15 15:23:39 +00009704 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9705 PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled");
9706
Pengquan Menga1bb6272018-09-06 09:59:22 -07009707 boolean isEnabled = false;
9708 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009709 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009710 Phone phone = getPhone(subId);
9711 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009712 } finally {
9713 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009714 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009715 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009716 }
9717
9718
9719 /**
9720 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9721 *
9722 * <p> Requires permission:
9723 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9724 * privileges.
9725 *
9726 * @param subId subscription id
9727 * @param isEnabled {@code true} means enable, {@code false} means disable.
9728 */
9729 @Override
9730 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009731 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9732 mApp, subId, "setDataRoamingEnabled");
9733
joonhunshin4ac60942023-11-15 15:23:39 +00009734 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9735 PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled");
9736
Pengquan Menga1bb6272018-09-06 09:59:22 -07009737 final long identity = Binder.clearCallingIdentity();
9738 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009739 Phone phone = getPhone(subId);
9740 if (phone != null) {
9741 phone.setDataRoamingEnabled(isEnabled);
9742 }
9743 } finally {
9744 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009745 }
9746 }
9747
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009748 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009749 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009750 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009751 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009752 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009753
joonhunshin4ac60942023-11-15 15:23:39 +00009754 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9755 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed");
9756
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009757 boolean isAllowed = true;
9758 final long identity = Binder.clearCallingIdentity();
9759 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009760 Phone phone = getPhone(subId);
9761 if (phone != null) {
9762 isAllowed = phone.isCspPlmnEnabled();
9763 }
9764 } finally {
9765 Binder.restoreCallingIdentity(identity);
9766 }
9767 return isAllowed;
9768 }
9769
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009770 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9771 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009772 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009773 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009774 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009775 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9776 if (phone == null) {
9777 return false;
9778 }
9779 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9780 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9781 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009782 }
9783
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009784 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009785 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009786 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009787 mApp.getSystemService(AppOpsManager.class)
9788 .checkPackage(Binder.getCallingUid(), callingPackage);
9789
Jordan Liu1e142fc2019-04-22 15:10:43 -07009790 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009791 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009792 try {
9793 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009794 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009795 } catch (SecurityException e) {
9796 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9797 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009798 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009799 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009800 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009801 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009802 }
joonhunshin4ac60942023-11-15 15:23:39 +00009803
9804 enforceTelephonyFeatureWithException(callingPackage,
9805 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo");
9806
sandeepjsb6c87872021-09-27 15:34:44 +00009807 // checking compatibility, if calling app's target SDK is T and beyond.
9808 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9809 Binder.getCallingUid())) {
9810 isIccIdAccessRestricted = true;
9811 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009812 final long identity = Binder.clearCallingIdentity();
9813 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009814 UiccController uiccController = UiccController.getInstance();
9815 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009816 if (hasReadPermission) {
9817 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009818 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009819
9820 // Remove private info if the caller doesn't have access
9821 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9822 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009823 //setting the value after compatibility check
9824 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009825 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9826 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009827 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009828 if (card == null) {
9829 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009830 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009831 continue;
9832 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009833 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9834 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009835 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009836 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009837 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009838 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9839 for (UiccPortInfo portInfo : portInfos) {
9840 UiccPort port = uiccController.getUiccPortForSlot(
9841 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9842 if (port == null) {
9843 // assume no access if port is null
9844 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9845 continue;
9846 }
9847 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9848 uiccPortInfos.add(portInfo);
9849 } else {
9850 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9851 }
9852 }
9853 filteredInfos.add(new UiccCardInfo(
9854 cardInfo.isEuicc(),
9855 cardInfo.getCardId(),
9856 null,
9857 cardInfo.getPhysicalSlotIndex(),
9858 cardInfo.isRemovable(),
9859 cardInfo.isMultipleEnabledProfilesSupported(),
9860 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009861 }
9862 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009863 } finally {
9864 Binder.restoreCallingIdentity(identity);
9865 }
9866 }
9867
sandeepjsb6c87872021-09-27 15:34:44 +00009868 /**
9869 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9870 * generally private and require carrier privileges to view.
9871 *
9872 * @hide
9873 */
9874 @NonNull
9875 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9876 List<UiccPortInfo> portinfo = new ArrayList<>();
9877 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9878 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9879 }
9880 return new UiccCardInfo(
9881 cardInfo.isEuicc(),
9882 cardInfo.getCardId(),
9883 null,
9884 cardInfo.getPhysicalSlotIndex(),
9885 cardInfo.isRemovable(),
9886 cardInfo.isMultipleEnabledProfilesSupported(),
9887 portinfo
9888 );
9889 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009890
sandeepjsb6c87872021-09-27 15:34:44 +00009891 /**
9892 * @hide
9893 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9894 * These values are generally private and require carrier privileges to view.
9895 */
9896 @NonNull
9897 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9898 return new UiccPortInfo(
9899 UiccPortInfo.ICCID_REDACTED,
9900 portInfo.getPortIndex(),
9901 portInfo.getLogicalSlotIndex(),
9902 portInfo.isActive()
9903 );
9904 }
9905 @Override
9906 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009907 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009908 mApp.getSystemService(AppOpsManager.class)
9909 .checkPackage(Binder.getCallingUid(), callingPackage);
9910
sandeepjsb6c87872021-09-27 15:34:44 +00009911 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009912
Aman Guptaf3c90b32022-03-17 04:54:16 +00009913 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9914 // we are reading iccId which is PII data.
9915 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009916
joonhunshin4ac60942023-11-15 15:23:39 +00009917 enforceTelephonyFeatureWithException(callingPackage,
9918 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo");
9919
sandeepjsb6c87872021-09-27 15:34:44 +00009920 // checking compatibility, if calling app's target SDK is T and beyond.
9921 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9922 Binder.getCallingUid())) {
9923 isLogicalSlotAccessRestricted = true;
9924 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009925 final long identity = Binder.clearCallingIdentity();
9926 try {
9927 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009928 if (slots == null || slots.length == 0) {
9929 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009930 return null;
9931 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009932 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9933 for (int i = 0; i < slots.length; i++) {
9934 UiccSlot slot = slots[i];
9935 if (slot == null) {
9936 continue;
9937 }
9938
Jordan Liu7be7e652019-05-06 18:55:02 +00009939 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009940 UiccCard card = slot.getUiccCard();
9941 if (card != null) {
9942 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009943 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009944 cardId = slot.getEid();
9945 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009946 // If cardId is null, use iccId of default port as cardId.
9947 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009948 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009949 }
9950
Jordan Liu857451f2019-05-09 16:35:35 -07009951 if (cardId != null) {
9952 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9953 // if cardId is an EID, it's all digits so this is fine
9954 cardId = IccUtils.stripTrailingFs(cardId);
9955 }
9956
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009957 int cardState = 0;
9958 switch (slot.getCardState()) {
9959 case CARDSTATE_ABSENT:
9960 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9961 break;
9962 case CARDSTATE_PRESENT:
9963 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9964 break;
9965 case CARDSTATE_ERROR:
9966 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9967 break;
9968 case CARDSTATE_RESTRICTED:
9969 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9970 break;
9971 default:
9972 break;
9973
9974 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009975 List<UiccPortInfo> portInfos = new ArrayList<>();
9976 int[] portIndexes = slot.getPortList();
9977 for (int portIdx : portIndexes) {
9978 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009979 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009980 portInfos.add(new UiccPortInfo(iccId, portIdx,
9981 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009982 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009983 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009984 slot.isEuicc(),
9985 cardId,
9986 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009987 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009988 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009989 //setting the value after compatibility check
9990 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009991 }
9992 return infos;
9993 } finally {
9994 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009995 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009996 }
9997
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009998 /* Returns null if doesn't have read permission or carrier privilege access. */
9999 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
10000 boolean hasReadPermission) {
10001 String iccId = slot.getIccId(portIndex);
10002 if (hasReadPermission) { // if has read permission
10003 return iccId;
10004 } else {
10005 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
10006 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
10007 // if no read permission, checking carrier privilege access
10008 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
10009 return iccId;
10010 }
10011 }
10012 }
10013 // No read permission or carrier privilege access.
10014 return UiccPortInfo.ICCID_REDACTED;
10015 }
10016
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010017 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010018 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010019 public boolean switchSlots(int[] physicalSlots) {
10020 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010021
joonhunshin4ac60942023-11-15 15:23:39 +000010022 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10023 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots");
10024
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010025 final long identity = Binder.clearCallingIdentity();
10026 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010027 List<UiccSlotMapping> slotMappings = new ArrayList<>();
10028 for (int i = 0; i < physicalSlots.length; i++) {
10029 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
10030 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
10031 physicalSlots[i], i));
10032 }
10033 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010034 } finally {
10035 Binder.restoreCallingIdentity(identity);
10036 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010037 }
Jack Yu4c988042018-02-27 15:30:01 -080010038
10039 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010040 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
10041 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
10042 enforceModifyPermission();
10043
joonhunshin4ac60942023-11-15 15:23:39 +000010044 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10045 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping");
10046
sandeepjsb6c87872021-09-27 15:34:44 +000010047 final long identity = Binder.clearCallingIdentity();
10048 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010049 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +000010050 } finally {
10051 Binder.restoreCallingIdentity(identity);
10052 }
10053 }
10054
10055 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -080010056 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
joonhunshin4ac60942023-11-15 15:23:39 +000010057 enforceTelephonyFeatureWithException(callingPackage,
10058 PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc");
10059
Jordan Liu7de49fa2018-12-06 14:48:49 -080010060 final long identity = Binder.clearCallingIdentity();
10061 try {
10062 return UiccController.getInstance().getCardIdForDefaultEuicc();
10063 } finally {
10064 Binder.restoreCallingIdentity(identity);
10065 }
10066 }
10067
Pengquan Meng85728fb2018-03-12 16:31:21 -070010068 /**
goneil47ffb6e2018-04-06 15:40:58 -070010069 * A test API to reload the UICC profile.
10070 *
10071 * <p>Requires that the calling app has permission
10072 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
10073 * @hide
10074 */
10075 @Override
10076 public void refreshUiccProfile(int subId) {
10077 enforceModifyPermission();
10078
10079 final long identity = Binder.clearCallingIdentity();
10080 try {
10081 Phone phone = getPhone(subId);
10082 if (phone == null) {
10083 return;
10084 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010085 UiccPort uiccPort = phone.getUiccPort();
10086 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -070010087 return;
10088 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010089 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -070010090 if (uiccProfile == null) {
10091 return;
10092 }
10093 uiccProfile.refresh();
10094 } finally {
10095 Binder.restoreCallingIdentity(identity);
10096 }
10097 }
10098
10099 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010100 * Returns false if the mobile data is disabled by default, otherwise return true.
10101 */
10102 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010103 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010104 }
10105
10106 /**
10107 * Returns true if the data roaming is enabled by default, i.e the system property
10108 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
10109 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
10110 */
10111 private boolean getDefaultDataRoamingEnabled(int subId) {
10112 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010113 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -070010114 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010115 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
10116 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
10117 return isDataRoamingEnabled;
10118 }
10119
10120 /**
10121 * Returns the default network type for the given {@code subId}, if the default network type is
10122 * not set, return {@link Phone#PREFERRED_NT_MODE}.
10123 */
10124 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010125 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -080010126 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +090010127 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
10128 return list.get(phoneId);
10129 }
10130 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -070010131 }
fionaxua13278b2018-03-21 00:08:13 -070010132
10133 @Override
10134 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -070010135 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -070010136 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010137
10138 final long identity = Binder.clearCallingIdentity();
10139 try {
10140 final Phone phone = getPhone(subId);
10141 if (phone == null) {
10142 loge("setCarrierTestOverride fails with invalid subId: " + subId);
10143 return;
10144 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -080010145 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10146 if (cpt != null) {
10147 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
10148 }
10149 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -070010150 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
10151 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -070010152 if (carrierPrivilegeRules == null) {
10153 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
10154 } else {
10155 mCarrierPrivilegeTestOverrideSubIds.add(subId);
10156 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010157 } finally {
10158 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010159 }
fionaxua13278b2018-03-21 00:08:13 -070010160 }
10161
10162 @Override
Benedict Wong66477622023-02-03 23:30:57 +000010163 public void setCarrierServicePackageOverride(
10164 int subId, String carrierServicePackage, String callingPackage) {
10165 TelephonyPermissions.enforceShellOnly(
10166 Binder.getCallingUid(), "setCarrierServicePackageOverride");
10167
Benedict Wong66477622023-02-03 23:30:57 +000010168 final long identity = Binder.clearCallingIdentity();
10169 try {
10170 final Phone phone = getPhone(subId);
10171 if (phone == null || phone.getSubId() != subId) {
10172 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
10173 throw new IllegalArgumentException("No phone for subid");
10174 }
10175 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10176 if (cpt == null) {
10177 loge("setCarrierServicePackageOverride failed with no CPT for phone");
10178 throw new IllegalStateException("No CPT for phone");
10179 }
10180 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
10181 } finally {
10182 Binder.restoreCallingIdentity(identity);
10183 }
10184 }
10185
10186 @Override
fionaxua13278b2018-03-21 00:08:13 -070010187 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -070010188 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010189
10190 final long identity = Binder.clearCallingIdentity();
10191 try {
10192 final Phone phone = getPhone(subId);
10193 if (phone == null) {
10194 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
10195 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
10196 }
10197 return phone.getCarrierIdListVersion();
10198 } finally {
10199 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010200 }
fionaxua13278b2018-03-21 00:08:13 -070010201 }
Malcolm Chen2c63d402018-08-14 16:00:53 -070010202
10203 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010204 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
10205 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010206 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010207 mApp, subId, callingPackage, callingFeatureId,
10208 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010209 return -1;
10210 }
10211
10212 final long identity = Binder.clearCallingIdentity();
10213 try {
10214 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10215 } finally {
10216 Binder.restoreCallingIdentity(identity);
10217 }
10218 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010219
10220 @Override
10221 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +080010222 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010223 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010224 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010225
joonhunshin4ac60942023-11-15 15:23:39 +000010226 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10227 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode");
10228
Pengquan Menga1bb6272018-09-06 09:59:22 -070010229 final long identity = Binder.clearCallingIdentity();
10230 try {
10231 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10232 } finally {
10233 Binder.restoreCallingIdentity(identity);
10234 }
10235 }
10236
10237 @Override
10238 public boolean setCdmaRoamingMode(int subId, int mode) {
10239 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10240 mApp, subId, "setCdmaRoamingMode");
10241
joonhunshin4ac60942023-11-15 15:23:39 +000010242 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10243 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode");
10244
Pengquan Menga1bb6272018-09-06 09:59:22 -070010245 final long identity = Binder.clearCallingIdentity();
10246 try {
10247 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10248 } finally {
10249 Binder.restoreCallingIdentity(identity);
10250 }
10251 }
10252
10253 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010254 public int getCdmaSubscriptionMode(int subId) {
10255 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010256 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010257 mApp, subId, "getCdmaSubscriptionMode");
10258
joonhunshin4ac60942023-11-15 15:23:39 +000010259 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10260 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode");
10261
Sarah Chinbaab1432020-10-28 13:46:24 -070010262 final long identity = Binder.clearCallingIdentity();
10263 try {
10264 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10265 } finally {
10266 Binder.restoreCallingIdentity(identity);
10267 }
10268 }
10269
10270 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010271 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10272 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10273 mApp, subId, "setCdmaSubscriptionMode");
10274
joonhunshin4ac60942023-11-15 15:23:39 +000010275 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10276 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode");
10277
Pengquan Menga1bb6272018-09-06 09:59:22 -070010278 final long identity = Binder.clearCallingIdentity();
10279 try {
10280 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10281 } finally {
10282 Binder.restoreCallingIdentity(identity);
10283 }
10284 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010285
sqianc5eccab2018-10-19 18:46:41 -070010286 @Override
sqian8c685422019-02-22 15:55:18 -080010287 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010288 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010289 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010290 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10291 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010292 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10293 }
joonhunshin4ac60942023-11-15 15:23:39 +000010294
10295 enforceTelephonyFeatureWithException(callingPackage,
10296 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList");
10297
sqian11b7a0e2018-12-05 18:48:28 -080010298 final long identity = Binder.clearCallingIdentity();
10299 try {
sqian854d44b2018-12-12 16:48:18 -080010300 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10301 for (Phone phone: PhoneFactory.getPhones()) {
10302 if (phone.getEmergencyNumberTracker() != null
10303 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10304 emergencyNumberListInternal.put(
10305 phone.getSubId(),
10306 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10307 }
sqian11b7a0e2018-12-05 18:48:28 -080010308 }
sqian854d44b2018-12-12 16:48:18 -080010309 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010310 } finally {
10311 Binder.restoreCallingIdentity(identity);
10312 }
sqianc5eccab2018-10-19 18:46:41 -070010313 }
10314
10315 @Override
sqian8c685422019-02-22 15:55:18 -080010316 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010317 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010318 if (!exactMatch) {
10319 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010320 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010321 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010322 }
joonhunshin4ac60942023-11-15 15:23:39 +000010323
10324 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10325 PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber");
10326
sqian11b7a0e2018-12-05 18:48:28 -080010327 final long identity = Binder.clearCallingIdentity();
10328 try {
sqian854d44b2018-12-12 16:48:18 -080010329 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010330 //Note: we ignore passed in param exactMatch. We can remove it once
10331 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010332 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010333 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010334 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010335 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010336 }
sqian11b7a0e2018-12-05 18:48:28 -080010337 }
10338 return false;
10339 } finally {
10340 Binder.restoreCallingIdentity(identity);
10341 }
10342 }
10343
sqianf4ca7ed2019-01-15 18:32:07 -080010344 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010345 * Start emergency callback mode for GsmCdmaPhone for testing.
10346 */
10347 @Override
10348 public void startEmergencyCallbackMode() {
10349 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10350 "startEmergencyCallbackMode");
10351 enforceModifyPermission();
10352 final long identity = Binder.clearCallingIdentity();
10353 try {
10354 for (Phone phone : PhoneFactory.getPhones()) {
10355 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10356 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10357 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10358 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10359 gsmCdmaPhone.obtainMessage(
10360 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10361 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10362 }
10363 }
10364 } finally {
10365 Binder.restoreCallingIdentity(identity);
10366 }
10367 }
10368
10369 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010370 * Update emergency number list for test mode.
10371 */
10372 @Override
10373 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10374 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10375 "updateEmergencyNumberListTestMode");
10376
10377 final long identity = Binder.clearCallingIdentity();
10378 try {
10379 for (Phone phone: PhoneFactory.getPhones()) {
10380 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10381 if (tracker != null) {
10382 tracker.executeEmergencyNumberTestModeCommand(action, num);
10383 }
10384 }
10385 } finally {
10386 Binder.restoreCallingIdentity(identity);
10387 }
10388 }
10389
10390 /**
10391 * Get the full emergency number list for test mode.
10392 */
10393 @Override
10394 public List<String> getEmergencyNumberListTestMode() {
10395 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10396 "getEmergencyNumberListTestMode");
10397
10398 final long identity = Binder.clearCallingIdentity();
10399 try {
10400 Set<String> emergencyNumbers = new HashSet<>();
10401 for (Phone phone: PhoneFactory.getPhones()) {
10402 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10403 if (tracker != null) {
10404 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10405 emergencyNumbers.add(num.getNumber());
10406 }
10407 }
10408 }
10409 return new ArrayList<>(emergencyNumbers);
10410 } finally {
10411 Binder.restoreCallingIdentity(identity);
10412 }
10413 }
10414
chen xud6b45bd2018-10-30 22:27:10 -070010415 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010416 public int getEmergencyNumberDbVersion(int subId) {
10417 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10418
joonhunshin4ac60942023-11-15 15:23:39 +000010419 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10420 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion");
10421
Shuo Qian3b6ee772019-11-13 17:43:31 -080010422 final long identity = Binder.clearCallingIdentity();
10423 try {
10424 final Phone phone = getPhone(subId);
10425 if (phone == null) {
10426 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10427 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10428 }
10429 return phone.getEmergencyNumberDbVersion();
10430 } finally {
10431 Binder.restoreCallingIdentity(identity);
10432 }
10433 }
10434
10435 @Override
10436 public void notifyOtaEmergencyNumberDbInstalled() {
10437 enforceModifyPermission();
10438
joonhunshin4ac60942023-11-15 15:23:39 +000010439 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10440 PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled");
10441
Shuo Qian3b6ee772019-11-13 17:43:31 -080010442 final long identity = Binder.clearCallingIdentity();
10443 try {
10444 for (Phone phone: PhoneFactory.getPhones()) {
10445 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10446 if (tracker != null) {
10447 tracker.updateOtaEmergencyNumberDatabase();
10448 }
10449 }
10450 } finally {
10451 Binder.restoreCallingIdentity(identity);
10452 }
10453 }
10454
10455 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010456 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010457 enforceActiveEmergencySessionPermission();
10458
joonhunshin4ac60942023-11-15 15:23:39 +000010459 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10460 PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath");
10461
Shuo Qian3b6ee772019-11-13 17:43:31 -080010462 final long identity = Binder.clearCallingIdentity();
10463 try {
10464 for (Phone phone: PhoneFactory.getPhones()) {
10465 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10466 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010467 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10468 }
10469 }
10470 } finally {
10471 Binder.restoreCallingIdentity(identity);
10472 }
10473 }
10474
10475 @Override
10476 public void resetOtaEmergencyNumberDbFilePath() {
10477 enforceActiveEmergencySessionPermission();
10478
joonhunshin4ac60942023-11-15 15:23:39 +000010479 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10480 PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath");
10481
Shuo Qianc373f112020-03-05 17:55:34 -080010482 final long identity = Binder.clearCallingIdentity();
10483 try {
10484 for (Phone phone: PhoneFactory.getPhones()) {
10485 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10486 if (tracker != null) {
10487 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010488 }
10489 }
10490 } finally {
10491 Binder.restoreCallingIdentity(identity);
10492 }
10493 }
10494
10495 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010496 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10497 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10498 Phone phone = getPhone(subId);
10499 if (phone == null) {
10500 return null;
10501 }
10502 final long identity = Binder.clearCallingIdentity();
10503 try {
10504 UiccProfile profile = UiccController.getInstance()
10505 .getUiccProfileForPhone(phone.getPhoneId());
10506 if (profile != null) {
10507 return profile.getCertsFromCarrierPrivilegeAccessRules();
10508 }
10509 } finally {
10510 Binder.restoreCallingIdentity(identity);
10511 }
10512 return null;
10513 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010514
10515 /**
10516 * Enable or disable a modem stack.
10517 */
10518 @Override
10519 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10520 enforceModifyPermission();
10521
joonhunshin4ac60942023-11-15 15:23:39 +000010522 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10523 PackageManager.FEATURE_TELEPHONY, "enableModemForSlot");
10524
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010525 final long identity = Binder.clearCallingIdentity();
10526 try {
10527 Phone phone = PhoneFactory.getPhone(slotIndex);
10528 if (phone == null) {
10529 return false;
10530 } else {
10531 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10532 }
10533 } finally {
10534 Binder.restoreCallingIdentity(identity);
10535 }
10536 }
Michelecea4cf22018-12-21 15:00:11 -080010537
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010538 /**
10539 * Whether a modem stack is enabled or not.
10540 */
10541 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010542 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10543 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010544 Phone phone = PhoneFactory.getPhone(slotIndex);
10545 if (phone == null) return false;
10546
10547 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010548 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10549 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010550 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10551 }
10552
joonhunshin4ac60942023-11-15 15:23:39 +000010553 enforceTelephonyFeatureWithException(callingPackage,
10554 PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot");
10555
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010556 final long identity = Binder.clearCallingIdentity();
10557 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010558 try {
10559 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10560 } catch (NoSuchElementException ex) {
10561 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10562 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010563 } finally {
10564 Binder.restoreCallingIdentity(identity);
10565 }
10566 }
10567
Michelecea4cf22018-12-21 15:00:11 -080010568 @Override
Michele0ea7d782019-03-19 14:58:42 -070010569 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010570 enforceModifyPermission();
10571
joonhunshin4ac60942023-11-15 15:23:39 +000010572 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10573 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction");
10574
Michelecea4cf22018-12-21 15:00:11 -080010575 final long identity = Binder.clearCallingIdentity();
10576 try {
10577 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010578 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010579 .commit();
10580 } finally {
10581 Binder.restoreCallingIdentity(identity);
10582 }
10583 }
10584
10585 @Override
Michele0ea7d782019-03-19 14:58:42 -070010586 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010587 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010588 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010589 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10590 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010591 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010592 }
Michelecea4cf22018-12-21 15:00:11 -080010593
joonhunshin4ac60942023-11-15 15:23:39 +000010594 enforceTelephonyFeatureWithException(callingPackage,
10595 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported");
10596
Michelecea4cf22018-12-21 15:00:11 -080010597 final long identity = Binder.clearCallingIdentity();
10598 try {
Michele0ea7d782019-03-19 14:58:42 -070010599 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010600 } finally {
10601 Binder.restoreCallingIdentity(identity);
10602 }
10603 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010604
Michele0ea7d782019-03-19 14:58:42 -070010605 @TelephonyManager.IsMultiSimSupportedResult
10606 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010607 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10608 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10609 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010610 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10611 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010612 }
10613 // Check if the hardware supports multisim functionality. If usage of multisim is not
10614 // supported by the modem, indicate that it is restricted.
10615 PhoneCapability staticCapability =
10616 mPhoneConfigurationManager.getStaticPhoneCapability();
10617 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010618 loge("isMultiSimSupportedInternal: no static configuration available");
10619 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010620 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010621 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010622 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10623 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010624 }
10625 // Check if support of multiple SIMs is restricted by carrier
10626 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010627 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010628 }
10629
Michele0ea7d782019-03-19 14:58:42 -070010630 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010631 }
10632
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010633 /**
10634 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010635 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10636 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10637 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010638 * @param numOfSims number of active sims we want to switch to
10639 */
10640 @Override
10641 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010642 if (numOfSims == 1) {
10643 enforceModifyPermission();
10644 } else {
10645 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10646 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10647 }
joonhunshin4ac60942023-11-15 15:23:39 +000010648
10649 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10650 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig");
10651
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010652 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010653
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010654 try {
Michele30b57b22019-03-01 12:01:14 -080010655 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010656 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010657 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10658 return;
10659 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010660 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10661 } finally {
10662 Binder.restoreCallingIdentity(identity);
10663 }
10664 }
10665
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010666 @Override
10667 public boolean isApplicationOnUicc(int subId, int appType) {
10668 enforceReadPrivilegedPermission("isApplicationOnUicc");
joonhunshin4ac60942023-11-15 15:23:39 +000010669
10670 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10671 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc");
10672
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010673 Phone phone = getPhone(subId);
10674 if (phone == null) {
10675 return false;
10676 }
10677 final long identity = Binder.clearCallingIdentity();
10678 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010679 UiccPort uiccPort = phone.getUiccPort();
10680 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010681 return false;
10682 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010683 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010684 if (uiccProfile == null) {
10685 return false;
10686 }
10687 if (TelephonyManager.APPTYPE_SIM <= appType
10688 && appType <= TelephonyManager.APPTYPE_ISIM) {
10689 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10690 }
10691 return false;
10692 } finally {
10693 Binder.restoreCallingIdentity(identity);
10694 }
10695 }
10696
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010697 /**
chen xub4baa772019-04-03 10:23:41 -070010698 * Get whether making changes to modem configurations will trigger reboot.
10699 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010700 */
10701 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010702 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10703 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010704 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010705 mApp, subId, callingPackage, callingFeatureId,
10706 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010707 return false;
10708 }
joonhunshin4ac60942023-11-15 15:23:39 +000010709
10710 enforceTelephonyFeatureWithException(callingPackage,
10711 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
10712 "doesSwitchMultiSimConfigTriggerReboot");
10713
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010714 final long identity = Binder.clearCallingIdentity();
10715 try {
10716 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10717 } finally {
10718 Binder.restoreCallingIdentity(identity);
10719 }
10720 }
10721
Nathan Harold29f5f052019-02-15 13:41:57 -080010722 private void updateModemStateMetrics() {
10723 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10724 // TODO: check the state for each modem if the api is ready.
10725 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10726 }
10727
Pengquan Meng3889a572019-01-23 11:16:29 -080010728 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010729 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010730 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010731 // Verify that the callingPackage belongs to the calling UID
10732 mApp.getSystemService(AppOpsManager.class)
10733 .checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000010734
10735 enforceTelephonyFeatureWithException(callingPackage,
10736 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping");
10737
Pengquan Meng3889a572019-01-23 11:16:29 -080010738 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010739 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010740 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010741 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10742 if (slotInfos != null) {
10743 for (int i = 0; i < slotInfos.length; i++) {
10744 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10745 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10746 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10747 portInfo.getLogicalSlotIndex()));
10748 }
10749 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010750 }
10751 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010752 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010753 } finally {
10754 Binder.restoreCallingIdentity(identity);
10755 }
10756 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010757
10758 /**
10759 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010760 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010761 */
jimsunf9ec1622022-09-13 21:18:43 +080010762 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010763 @Override
10764 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010765 return getHalVersion(HAL_SERVICE_RADIO);
10766 }
10767
10768 /**
10769 * Get the HAL Version of a specific service
10770 */
10771 @Override
10772 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010773 Phone phone = getDefaultPhone();
10774 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010775 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010776 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10777 return hv.major * 100 + hv.minor;
10778 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010779
10780 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010781 * Get the current calling package name.
sangyun097dcf72024-01-04 10:35:49 +090010782 *
10783 * @return the current calling package name, or null if there is no known package.
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010784 */
10785 @Override
sangyun097dcf72024-01-04 10:35:49 +090010786 public @Nullable String getCurrentPackageName() {
10787 PackageManager pm = mApp.getPackageManager();
10788 String[] packageNames = pm == null ? null : pm.getPackagesForUid(Binder.getCallingUid());
10789 return packageNames == null ? null : packageNames[0];
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010790 }
10791
10792 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010793 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10794 * corresponding network requests on a subId.
10795 *
10796 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010797 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010798 * 2) APN is un-metered for this subscription, or
10799 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010800 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010801 *
10802 * @return whether data is allowed for a apn type.
10803 *
10804 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010805 */
10806 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010807 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010808 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10809 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010810
joonhunshin4ac60942023-11-15 15:23:39 +000010811 enforceTelephonyFeatureWithException(callingPackage,
10812 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn");
10813
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010814 // Now that all security checks passes, perform the operation as ourselves.
10815 final long identity = Binder.clearCallingIdentity();
10816 try {
10817 Phone phone = getPhone(subId);
10818 if (phone == null) return false;
10819
Jack Yu27422a52022-03-21 10:38:05 -070010820 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010821 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010822 isMetered = phone.getDataNetworkController().getDataConfigManager()
10823 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10824 phone.getServiceState().getDataRoaming());
10825 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010826 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010827 } finally {
10828 Binder.restoreCallingIdentity(identity);
10829 }
10830 }
10831
10832 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010833 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010834 enforceReadPrivilegedPermission("isApnMetered");
10835
joonhunshin4ac60942023-11-15 15:23:39 +000010836 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10837 PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered");
10838
Malcolm Chene5ad5792019-04-18 13:51:02 -070010839 // Now that all security checks passes, perform the operation as ourselves.
10840 final long identity = Binder.clearCallingIdentity();
10841 try {
10842 Phone phone = getPhone(subId);
10843 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010844 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10845 DataUtils.apnTypeToNetworkCapability(apnType),
10846 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010847 } finally {
10848 Binder.restoreCallingIdentity(identity);
10849 }
10850 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010851
10852 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010853 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10854 int subscriptionId, IBooleanConsumer resultCallback) {
10855 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +000010856
10857 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10858 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels");
10859
Hall Liu73f5d362020-01-20 13:42:00 -080010860 long token = Binder.clearCallingIdentity();
10861 try {
10862 Phone phone = getPhone(subscriptionId);
10863 if (phone == null) {
10864 try {
10865 if (resultCallback != null) {
10866 resultCallback.accept(false);
10867 }
10868 } catch (RemoteException e) {
10869 // ignore
10870 }
10871 return;
10872 }
10873 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10874 Pair.create(specifiers, (x) -> {
10875 try {
10876 if (resultCallback != null) {
10877 resultCallback.accept(x);
10878 }
10879 } catch (RemoteException e) {
10880 // ignore
10881 }
10882 });
10883 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10884 } finally {
10885 Binder.restoreCallingIdentity(token);
10886 }
10887 }
10888
10889 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010890 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10891 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010892 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010893 mApp, subId, "getSystemSelectionChannels");
joonhunshin4ac60942023-11-15 15:23:39 +000010894
10895 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10896 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels");
10897
Sarah Chin679c08a2020-11-18 13:39:35 -080010898 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10899 final long identity = Binder.clearCallingIdentity();
10900 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010901 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10902 if (result instanceof IllegalStateException) {
10903 throw (IllegalStateException) result;
10904 }
10905 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010906 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10907 return specifiers;
10908 } finally {
10909 Binder.restoreCallingIdentity(identity);
10910 }
10911 }
10912
10913 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010914 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010915 enforceReadPrivilegedPermission("isMvnoMatched");
joonhunshin4ac60942023-11-15 15:23:39 +000010916
10917 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10918 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched");
10919
Jack Yu8b766fc2022-03-21 09:42:33 -070010920 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010921 }
10922
10923 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010924 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10925 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010926 if (callingPackage == null) {
10927 callingPackage = getCurrentPackageName();
10928 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010929 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10930 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010931 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10932 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010933 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10934 }
10935 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10936 Intent intent = new Intent();
10937 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10938 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10939 // Bring up choose default SMS subscription dialog right now
10940 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10941 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10942 mApp.startActivity(intent);
10943 }
chen xud5ca2d52019-05-28 15:20:57 -070010944
10945 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010946 public void showSwitchToManagedProfileDialog() {
10947 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000010948 try {
10949 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
10950 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
10951 // for work telephony.
10952 Intent intent = new Intent(Intent.ACTION_SENDTO);
10953 intent.setData(Uri.parse("smsto:"));
10954 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10955 mApp.startActivity(intent);
10956 } catch (ActivityNotFoundException e) {
10957 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
10958 Intent intent = new Intent();
10959 intent.setClass(mApp, ErrorDialogActivity.class);
10960 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10961 mApp.startActivity(intent);
10962 }
Ayush Sharma787854b2022-12-12 14:55:02 +000010963 }
10964
10965 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010966 public String getMmsUAProfUrl(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000010967 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10968 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl");
10969
chen xud5ca2d52019-05-28 15:20:57 -070010970 //TODO investigate if this API should require proper permission check in R b/133791609
10971 final long identity = Binder.clearCallingIdentity();
10972 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010973 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10974 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10975 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10976 return carrierUAProfUrl;
10977 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010978 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10979 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010980 } finally {
10981 Binder.restoreCallingIdentity(identity);
10982 }
10983 }
10984
10985 @Override
10986 public String getMmsUserAgent(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000010987 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10988 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent");
10989
chen xud5ca2d52019-05-28 15:20:57 -070010990 //TODO investigate if this API should require proper permission check in R b/133791609
10991 final long identity = Binder.clearCallingIdentity();
10992 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010993 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10994 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10995 if (!TextUtils.isEmpty(carrierUserAgent)) {
10996 return carrierUserAgent;
10997 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010998 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10999 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070011000 } finally {
11001 Binder.restoreCallingIdentity(identity);
11002 }
11003 }
Jack Yub07d4972019-05-28 16:12:25 -070011004
11005 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070011006 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
11007 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070011008
joonhunshin4ac60942023-11-15 15:23:39 +000011009 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11010 PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled");
11011
Jack Yub07d4972019-05-28 16:12:25 -070011012 final long identity = Binder.clearCallingIdentity();
11013 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011014 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070011015 if (phone == null) return false;
11016
Ling Maf188d502022-09-16 15:22:36 -070011017 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070011018 } finally {
11019 Binder.restoreCallingIdentity(identity);
11020 }
11021 }
11022
11023 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080011024 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070011025 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080011026 enforceModifyPermission();
11027
joonhunshin4ac60942023-11-15 15:23:39 +000011028 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11029 PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled");
11030
changbettyd5c246e2019-12-24 15:40:37 +080011031 final long identity = Binder.clearCallingIdentity();
11032 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011033 Phone phone = getPhone(subscriptionId);
11034 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080011035
Ling Maf188d502022-09-16 15:22:36 -070011036 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080011037 } finally {
11038 Binder.restoreCallingIdentity(identity);
11039 }
11040 }
11041
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011042 /**
Hall Liu746e03c2020-09-25 11:13:49 -070011043 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011044 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
11045 * otherwise.
11046 */
11047 @Override
11048 public void setCepEnabled(boolean isCepEnabled) {
11049 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
11050
11051 final long identity = Binder.clearCallingIdentity();
11052 try {
11053 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
11054 for (Phone phone : PhoneFactory.getPhones()) {
11055 Phone defaultPhone = phone.getImsPhone();
11056 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
11057 ImsPhone imsPhone = (ImsPhone) defaultPhone;
11058 ImsPhoneCallTracker imsPhoneCallTracker =
11059 (ImsPhoneCallTracker) imsPhone.getCallTracker();
11060 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
11061 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
11062 + imsPhone.getMsisdn());
11063 }
11064 }
11065 } finally {
11066 Binder.restoreCallingIdentity(identity);
11067 }
11068 }
allenwtsu46dcc572020-01-08 18:24:03 +080011069
11070 /**
11071 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
11072 *
11073 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
11074 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
11075 * before being read.
11076 */
11077 @Override
11078 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
11079 isCompressed) {
11080 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11081 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011082 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11083 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11084 }
joonhunshin4ac60942023-11-15 15:23:39 +000011085
11086 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11087 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11088 Binder.getCallingUserHandle())) {
11089 if (!isImsAvailableOnDevice()) {
11090 // ProvisioningManager can not handle ServiceSpecificException.
11091 // Throw the IllegalStateException and annotate ProvisioningManager.
11092 throw new IllegalStateException("IMS not available on device.");
11093 }
11094 } else {
11095 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11096 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11097 "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011098 }
11099
11100 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080011101 try {
Hui Wang761a6682020-10-31 05:12:53 +000011102 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
11103 } finally {
11104 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080011105 }
11106 }
zoey chene02881a2019-12-30 16:11:23 +080011107
11108 @Override
11109 public boolean isIccLockEnabled(int subId) {
11110 enforceReadPrivilegedPermission("isIccLockEnabled");
11111
joonhunshin4ac60942023-11-15 15:23:39 +000011112 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11113 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled");
11114
zoey chene02881a2019-12-30 16:11:23 +080011115 // Now that all security checks passes, perform the operation as ourselves.
11116 final long identity = Binder.clearCallingIdentity();
11117 try {
11118 Phone phone = getPhone(subId);
11119 if (phone != null && phone.getIccCard() != null) {
11120 return phone.getIccCard().getIccLockEnabled();
11121 } else {
11122 return false;
11123 }
11124 } finally {
11125 Binder.restoreCallingIdentity(identity);
11126 }
11127 }
11128
11129 /**
11130 * Set the ICC pin lock enabled or disabled.
11131 *
11132 * @return an integer representing the status of IccLock enabled or disabled in the following
11133 * three cases:
11134 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
11135 * successfully.
11136 * - Positive number and zero for remaining password attempts.
11137 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11138 *
11139 */
11140 @Override
11141 public int setIccLockEnabled(int subId, boolean enabled, String password) {
11142 enforceModifyPermission();
11143
joonhunshin4ac60942023-11-15 15:23:39 +000011144 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11145 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled");
11146
zoey chene02881a2019-12-30 16:11:23 +080011147 Phone phone = getPhone(subId);
11148 if (phone == null) {
11149 return 0;
11150 }
11151 // Now that all security checks passes, perform the operation as ourselves.
11152 final long identity = Binder.clearCallingIdentity();
11153 try {
11154 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
11155 new Pair<Boolean, String>(enabled, password), phone, null);
11156 return attemptsRemaining;
11157
11158 } catch (Exception e) {
11159 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
11160 } finally {
11161 Binder.restoreCallingIdentity(identity);
11162 }
11163 return 0;
11164 }
11165
11166 /**
11167 * Change the ICC password used in ICC pin lock.
11168 *
11169 * @return an integer representing the status of IccLock changed in the following three cases:
11170 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
11171 * - Positive number and zero for remaining password attempts.
11172 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11173 *
11174 */
11175 @Override
11176 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
11177 enforceModifyPermission();
11178
joonhunshin4ac60942023-11-15 15:23:39 +000011179 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11180 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword");
11181
zoey chene02881a2019-12-30 16:11:23 +080011182 Phone phone = getPhone(subId);
11183 if (phone == null) {
11184 return 0;
11185 }
11186 // Now that all security checks passes, perform the operation as ourselves.
11187 final long identity = Binder.clearCallingIdentity();
11188 try {
11189 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
11190 new Pair<String, String>(oldPassword, newPassword), phone, null);
11191 return attemptsRemaining;
11192
11193 } catch (Exception e) {
11194 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
11195 } finally {
11196 Binder.restoreCallingIdentity(identity);
11197 }
11198 return 0;
11199 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080011200
11201 /**
11202 * Request for receiving user activity notification
11203 */
11204 @Override
11205 public void requestUserActivityNotification() {
11206 if (!mNotifyUserActivity.get()
11207 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
11208 mNotifyUserActivity.set(true);
11209 }
11210 }
11211
11212 /**
11213 * Called when userActivity is signalled in the power manager.
11214 * This is safe to call from any thread, with any window manager locks held or not.
11215 */
11216 @Override
11217 public void userActivity() {
11218 // ***************************************
11219 // * Inherited from PhoneWindowManager *
11220 // ***************************************
11221 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
11222 // WITH ITS LOCKS HELD.
11223 //
11224 // This code must be VERY careful about the locks
11225 // it acquires.
11226 // In fact, the current code acquires way too many,
11227 // and probably has lurking deadlocks.
11228
11229 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
11230 throw new SecurityException("Only the OS may call notifyUserActivity()");
11231 }
11232
11233 if (mNotifyUserActivity.getAndSet(false)) {
11234 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
11235 USER_ACTIVITY_NOTIFICATION_DELAY);
11236 }
11237 }
Malcolm Chen4639c562020-04-13 11:59:40 -070011238
11239 @Override
11240 public boolean canConnectTo5GInDsdsMode() {
11241 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
11242 }
Jack Yud10cdd42020-09-28 20:28:01 -070011243
11244 @Override
11245 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
11246 String callingFeatureId) {
11247 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
11248 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
11249 throw new SecurityException("Requires READ_PHONE_STATE permission.");
11250 }
11251
joonhunshin4ac60942023-11-15 15:23:39 +000011252 enforceTelephonyFeatureWithException(callingPackage,
11253 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns");
11254
Jack Yud10cdd42020-09-28 20:28:01 -070011255 Phone phone = getPhone(subId);
11256 if (phone == null) {
11257 throw new RuntimeException("phone is not available");
11258 }
11259 // Now that all security checks passes, perform the operation as ourselves.
11260 final long identity = Binder.clearCallingIdentity();
11261 try {
11262 return phone.getEquivalentHomePlmns();
11263 } finally {
11264 Binder.restoreCallingIdentity(identity);
11265 }
11266 }
Daniel Bright59e67312020-11-13 11:49:37 -080011267
11268 @Override
11269 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011270 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
joonhunshin4ac60942023-11-15 15:23:39 +000011271 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11272 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
11273 "isRadioInterfaceCapabilitySupported");
11274
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011275 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080011276 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080011277 if (radioInterfaceCapabilities == null) {
11278 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080011279 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011280 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080011281 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011282
Hui Wang641e81c2020-10-12 12:14:23 -070011283 @Override
11284 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
11285 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000011286 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
11287 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11288 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
11289 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11290 Manifest.permission.MODIFY_PHONE_STATE);
joonhunshin4ac60942023-11-15 15:23:39 +000011291
11292 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11293 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest");
11294
Hui Wang641e81c2020-10-12 12:14:23 -070011295 if (DBG) {
11296 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
11297 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
11298 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
11299 }
11300
11301 if (!SubscriptionManager.isValidSubscriptionId(subId)
11302 || appType < TelephonyManager.APPTYPE_UNKNOWN
11303 || appType > TelephonyManager.APPTYPE_ISIM
11304 || nafUrl == null || securityProtocol == null || callback == null) {
11305 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
11306 if (callback != null) {
11307 try {
11308 callback.onAuthenticationFailure(
11309 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
11310 } catch (RemoteException exception) {
11311 log("Fail to notify onAuthenticationFailure due to " + exception);
11312 }
11313 return;
11314 }
11315 }
11316
11317 final long token = Binder.clearCallingIdentity();
11318 try {
11319 getGbaManager(subId).bootstrapAuthenticationRequest(
11320 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011321 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070011322 } finally {
11323 Binder.restoreCallingIdentity(token);
11324 }
11325 }
11326
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011327 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011328 * Attempts to set the radio power state for all phones for thermal reason.
11329 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011330 * requested radio power state will actually be set. See {@link
11331 * PhoneInternalInterface#setRadioPowerForReason} for more details.
11332 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011333 * @param enable {@code true} if trying to turn radio on.
11334 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
11335 * false}.
11336 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011337 private boolean setRadioPowerForThermal(boolean enable) {
11338 boolean isPhoneAvailable = false;
11339 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
11340 Phone phone = PhoneFactory.getPhone(i);
11341 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011342 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011343 isPhoneAvailable = true;
11344 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011345 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011346
11347 // return true if successfully informed the phone object about the thermal radio power
11348 // request.
11349 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011350 }
11351
11352 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011353 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011354 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11355 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11356 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11357 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11358 throw new IllegalArgumentException("modem does not support data throttling");
11359 }
11360
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011361 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11362 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011363 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011364 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11365 }
11366
Sarah Chinecc78c42022-03-31 21:16:48 -070011367 setDataEnabledForReason(
11368 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011369
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011370 if (isDataThrottlingSupported) {
11371 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011372 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011373 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11374 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11375 } else if (thermalMitigationResult
11376 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011377 log("Modem likely does not support data throttling on secondary carrier. Data " +
11378 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11379 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011380 }
11381 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011382 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011383
11384 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011385 }
11386
Jack Nudelman644b91a2021-03-12 14:09:48 -080011387 private static List<String> getThermalMitigationAllowlist(Context context) {
11388 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11389 for (String pckg : context.getResources()
11390 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11391 sThermalMitigationAllowlistedPackages.add(pckg);
11392 }
11393 }
11394
11395 return sThermalMitigationAllowlistedPackages;
11396 }
11397
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011398 private boolean isAnyPhoneInEmergencyState() {
11399 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11400 if (tm.isInEmergencyCall()) {
11401 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11402 return true;
11403 }
11404 for (Phone phone : PhoneFactory.getPhones()) {
11405 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11406 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011407 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11408 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011409 return true;
11410 }
11411 }
11412
11413 return false;
11414 }
11415
Jack Nudelman644b91a2021-03-12 14:09:48 -080011416 /**
11417 * Used by shell commands to add an authorized package name for thermal mitigation.
11418 * @param packageName name of package to be allowlisted
11419 * @param context
11420 */
11421 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11422 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11423 sThermalMitigationAllowlistedPackages.add(packageName);
11424 }
11425
11426 /**
11427 * Used by shell commands to remove an authorized package name for thermal mitigation.
11428 * @param packageName name of package to remove from allowlist
11429 * @param context
11430 */
11431 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11432 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11433 sThermalMitigationAllowlistedPackages.remove(packageName);
11434 }
11435
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011436 /**
11437 * Thermal mitigation request to control functionalities at modem.
11438 *
11439 * @param subId the id of the subscription.
11440 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011441 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011442 *
11443 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11444 */
11445 @Override
11446 @ThermalMitigationResult
11447 public int sendThermalMitigationRequest(
11448 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011449 ThermalMitigationRequest thermalMitigationRequest,
11450 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011451 enforceModifyPermission();
11452
Jack Nudelman644b91a2021-03-12 14:09:48 -080011453 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000011454
11455 enforceTelephonyFeatureWithException(callingPackage,
11456 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest");
11457
Jack Nudelman644b91a2021-03-12 14:09:48 -080011458 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11459 .contains(callingPackage)) {
11460 throw new SecurityException("Calling package must be configured in the device config. "
11461 + "calling package: " + callingPackage);
11462 }
11463
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011464 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11465 final long identity = Binder.clearCallingIdentity();
11466
11467 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11468 try {
11469 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11470 switch (thermalMitigationAction) {
11471 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11472 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011473 handleDataThrottlingRequest(subId,
11474 thermalMitigationRequest.getDataThrottlingRequest(),
11475 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011476 break;
11477 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11478 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11479 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11480 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11481 }
11482
11483 // Ensure that radio is on. If not able to power on due to phone being
11484 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011485 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011486 thermalMitigationResult =
11487 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11488 break;
11489 }
11490
11491 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011492 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011493 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11494 break;
11495 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11496 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11497 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11498 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11499 }
11500
11501 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11502 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011503 Phone phone = getPhone(subId);
11504 if (phone == null) {
11505 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011506 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011507 break;
11508 }
11509
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011510 TelephonyConnectionService service =
11511 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011512 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011513 Log.e(LOG_TAG, "An emergency call is pending");
11514 thermalMitigationResult =
11515 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11516 break;
11517 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011518 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011519 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011520 break;
11521 }
11522 } else {
11523 thermalMitigationResult =
11524 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11525 break;
11526 }
11527
11528 // Turn radio off. If not able to power off due to phone being unavailable,
11529 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011530 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011531 thermalMitigationResult =
11532 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11533 break;
11534 }
11535 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011536 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011537 break;
11538 default:
11539 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11540 + "not exist. Requested action: " + thermalMitigationAction);
11541 }
11542 } catch (IllegalArgumentException e) {
11543 throw e;
11544 } catch (Exception e) {
11545 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11546 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11547 } finally {
11548 Binder.restoreCallingIdentity(identity);
11549 }
11550
11551 if (DBG) {
11552 log("thermalMitigationRequest returning with thermalMitigationResult: "
11553 + thermalMitigationResult);
11554 }
11555
11556 return thermalMitigationResult;
11557 }
Hui Wang641e81c2020-10-12 12:14:23 -070011558
11559 /**
11560 * Set the GbaService Package Name that Telephony will bind to.
11561 *
11562 * @param subId The sim that the GbaService is associated with.
11563 * @param packageName The name of the package to be replaced with.
11564 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11565 */
11566 @Override
11567 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11568 enforceModifyPermission();
11569
11570 final long identity = Binder.clearCallingIdentity();
11571 try {
11572 return getGbaManager(subId).overrideServicePackage(packageName);
11573 } finally {
11574 Binder.restoreCallingIdentity(identity);
11575 }
11576 }
11577
11578 /**
11579 * Return the package name of the currently bound GbaService.
11580 *
11581 * @param subId The sim that the GbaService is associated with.
11582 * @return the package name of the GbaService configuration, null if GBA is not supported.
11583 */
11584 @Override
11585 public String getBoundGbaService(int subId) {
11586 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11587
11588 final long identity = Binder.clearCallingIdentity();
11589 try {
11590 return getGbaManager(subId).getServicePackage();
11591 } finally {
11592 Binder.restoreCallingIdentity(identity);
11593 }
11594 }
11595
11596 /**
11597 * Set the release time for telephony to unbind GbaService.
11598 *
11599 * @param subId The sim that the GbaService is associated with.
11600 * @param interval The release time to unbind GbaService by millisecond.
11601 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11602 */
11603 @Override
11604 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11605 enforceModifyPermission();
11606
11607 final long identity = Binder.clearCallingIdentity();
11608 try {
11609 return getGbaManager(subId).overrideReleaseTime(interval);
11610 } finally {
11611 Binder.restoreCallingIdentity(identity);
11612 }
11613 }
11614
11615 /**
11616 * Return the release time for telephony to unbind GbaService.
11617 *
11618 * @param subId The sim that the GbaService is associated with.
11619 * @return The release time to unbind GbaService by millisecond.
11620 */
11621 @Override
11622 public int getGbaReleaseTime(int subId) {
11623 enforceReadPrivilegedPermission("getGbaReleaseTime");
11624
11625 final long identity = Binder.clearCallingIdentity();
11626 try {
11627 return getGbaManager(subId).getReleaseTime();
11628 } finally {
11629 Binder.restoreCallingIdentity(identity);
11630 }
11631 }
11632
11633 private GbaManager getGbaManager(int subId) {
11634 GbaManager instance = GbaManager.getInstance(subId);
11635 if (instance == null) {
11636 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11637 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11638 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11639 }
11640 return instance;
11641 }
Hui Wang761a6682020-10-31 05:12:53 +000011642
11643 /**
11644 * indicate whether the device and the carrier can support
11645 * RCS VoLTE single registration.
11646 */
11647 @Override
11648 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011649 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11650 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11651 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11652 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011653
11654 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11655 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11656 }
11657
11658 final long identity = Binder.clearCallingIdentity();
11659 try {
11660 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11661 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011662 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11663 if (isCapable != null) {
11664 return isCapable;
11665 }
Hui Wang761a6682020-10-31 05:12:53 +000011666 }
Hui Wang67af90e2021-06-04 16:57:15 -070011667 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11668 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011669 } finally {
11670 Binder.restoreCallingIdentity(identity);
11671 }
11672 }
11673
11674 /**
11675 * Register RCS provisioning callback.
11676 */
11677 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011678 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011679 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011680 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011681 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011682 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11683 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011684
11685 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11686 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11687 }
joonhunshin4ac60942023-11-15 15:23:39 +000011688 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11689 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11690 Binder.getCallingUserHandle())) {
11691 if (!isImsAvailableOnDevice()) {
11692 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11693 "IMS not available on device.");
11694 }
11695 } else {
11696 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11697 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011698 }
11699
11700 final long identity = Binder.clearCallingIdentity();
11701 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011702 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011703 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011704 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11705 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011706 }
Hui Wang761a6682020-10-31 05:12:53 +000011707 } finally {
11708 Binder.restoreCallingIdentity(identity);
11709 }
11710 }
11711
11712 /**
11713 * Unregister RCS provisioning callback.
11714 */
11715 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011716 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011717 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011718 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011719 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011720 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11721 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011722
11723 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11724 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11725 }
joonhunshin4ac60942023-11-15 15:23:39 +000011726
11727 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11728 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11729 Binder.getCallingUserHandle())) {
11730 if (!isImsAvailableOnDevice()) {
11731 // operation failed silently
11732 Rlog.w(LOG_TAG, "IMS not available on device.");
11733 return;
11734 }
11735 } else {
11736 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11737 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11738 "unregisterRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011739 }
11740
11741 final long identity = Binder.clearCallingIdentity();
11742 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011743 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011744 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011745 } finally {
11746 Binder.restoreCallingIdentity(identity);
11747 }
11748 }
11749
11750 /**
11751 * trigger RCS reconfiguration.
11752 */
11753 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011754 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11755 "triggerRcsReconfiguration",
11756 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011757
11758 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11759 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11760 }
joonhunshin4ac60942023-11-15 15:23:39 +000011761 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11762 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11763 Binder.getCallingUserHandle())) {
11764 if (!isImsAvailableOnDevice()) {
11765 // ProvisioningManager can not handle ServiceSpecificException.
11766 // Throw the IllegalStateException and annotate ProvisioningManager.
11767 throw new IllegalStateException("IMS not available on device.");
11768 }
11769 } else {
11770 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11771 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011772 }
11773
11774 final long identity = Binder.clearCallingIdentity();
11775 try {
11776 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11777 } finally {
11778 Binder.restoreCallingIdentity(identity);
11779 }
11780 }
11781
11782 /**
11783 * Provide the client configuration parameters of the RCS application.
11784 */
11785 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011786 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11787 "setRcsClientConfiguration",
11788 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011789
11790 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11791 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11792 }
joonhunshin4ac60942023-11-15 15:23:39 +000011793 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11794 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11795 Binder.getCallingUserHandle())) {
11796 if (!isImsAvailableOnDevice()) {
11797 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11798 "IMS not available on device.");
11799 }
11800 } else {
11801 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11802 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011803 }
11804
11805 final long identity = Binder.clearCallingIdentity();
11806
11807 try {
11808 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11809 if (configBinder == null) {
11810 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011811 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11812 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011813 } else {
11814 configBinder.setRcsClientConfiguration(rcc);
11815 }
joonhunshin3e154242021-09-17 06:33:39 +000011816
11817 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11818 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011819 } catch (RemoteException e) {
11820 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011821 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11822 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011823 } finally {
11824 Binder.restoreCallingIdentity(identity);
11825 }
11826 }
11827
11828 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011829 * Enables or disables the test mode for RCS VoLTE single registration.
11830 */
11831 @Override
11832 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11833 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11834 "setRcsSingleRegistrationTestModeEnabled");
11835
11836 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11837 }
11838
11839 /**
11840 * Gets the test mode for RCS VoLTE single registration.
11841 */
11842 @Override
11843 public boolean getRcsSingleRegistrationTestModeEnabled() {
11844 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11845 "getRcsSingleRegistrationTestModeEnabled");
11846
11847 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11848 }
11849
11850 /**
Hui Wang761a6682020-10-31 05:12:53 +000011851 * Overrides the config of RCS VoLTE single registration enabled for the device.
11852 */
11853 @Override
11854 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11855 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11856 "setDeviceSingleRegistrationEnabledOverride");
11857 enforceModifyPermission();
11858
11859 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11860 : Boolean.parseBoolean(enabledStr);
11861 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011862 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011863 }
11864
11865 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011866 * Sends a device to device communication message. Only usable via shell.
11867 * @param message message to send.
11868 * @param value message value.
11869 */
11870 @Override
11871 public void sendDeviceToDeviceMessage(int message, int value) {
11872 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011873 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011874 enforceModifyPermission();
11875
11876 final long identity = Binder.clearCallingIdentity();
11877 try {
11878 TelephonyConnectionService service =
11879 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11880 if (service == null) {
11881 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11882 return;
11883 }
11884 service.sendTestDeviceToDeviceMessage(message, value);
11885 } finally {
11886 Binder.restoreCallingIdentity(identity);
11887 }
11888 }
11889
Tyler Gunnbabbda02021-02-10 11:05:02 -080011890 /**
11891 * Sets the specified device to device transport active.
11892 * @param transport The transport to set active.
11893 */
11894 @Override
11895 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11896 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11897 "setActiveDeviceToDeviceTransport");
11898 enforceModifyPermission();
11899
11900 final long identity = Binder.clearCallingIdentity();
11901 try {
11902 TelephonyConnectionService service =
11903 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11904 if (service == null) {
11905 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11906 return;
11907 }
11908 service.setActiveDeviceToDeviceTransport(transport);
11909 } finally {
11910 Binder.restoreCallingIdentity(identity);
11911 }
11912 }
Tyler Gunn92479152021-01-20 16:30:10 -080011913
Tyler Gunnd4339262021-05-03 14:46:49 -070011914 @Override
11915 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11916 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11917 "setDeviceToDeviceForceEnabled");
11918
11919 final long identity = Binder.clearCallingIdentity();
11920 try {
11921 Arrays.stream(PhoneFactory.getPhones()).forEach(
11922 p -> {
11923 Phone thePhone = p.getImsPhone();
11924 if (thePhone != null && thePhone instanceof ImsPhone) {
11925 ImsPhone imsPhone = (ImsPhone) thePhone;
11926 CallTracker tracker = imsPhone.getCallTracker();
11927 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11928 ImsPhoneCallTracker imsPhoneCallTracker =
11929 (ImsPhoneCallTracker) tracker;
11930 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11931 }
11932 }
11933 }
11934 );
11935 } finally {
11936 Binder.restoreCallingIdentity(identity);
11937 }
11938 }
11939
Tyler Gunn92479152021-01-20 16:30:10 -080011940 /**
Hui Wang761a6682020-10-31 05:12:53 +000011941 * Gets the config of RCS VoLTE single registration enabled for the device.
11942 */
11943 @Override
11944 public boolean getDeviceSingleRegistrationEnabled() {
11945 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11946 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11947 }
11948
11949 /**
11950 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11951 */
11952 @Override
11953 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11954 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11955 "setCarrierSingleRegistrationEnabledOverride");
11956 enforceModifyPermission();
11957
11958 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11959 : Boolean.parseBoolean(enabledStr);
11960 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11961 subId, enabled);
11962 }
11963
11964 /**
11965 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11966 */
11967 @Override
11968 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11969 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11970 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11971 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011972
11973 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011974 * Overrides the ims feature validation result
11975 */
11976 @Override
11977 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11978 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11979 "setImsFeatureValidationOverride");
11980
11981 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11982 : Boolean.parseBoolean(enabledStr);
11983 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11984 subId, enabled);
11985 }
11986
11987 /**
11988 * Gets the ims feature validation override value
11989 */
11990 @Override
11991 public boolean getImsFeatureValidationOverride(int subId) {
11992 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11993 "getImsFeatureValidationOverride");
11994 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11995 }
11996
11997 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011998 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11999 * their mobile plan.
12000 */
12001 @Override
12002 public String getMobileProvisioningUrl() {
12003 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
12004 final long identity = Binder.clearCallingIdentity();
12005 try {
12006 return getDefaultPhone().getMobileProvisioningUrl();
12007 } finally {
12008 Binder.restoreCallingIdentity(identity);
12009 }
12010 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012011
James.cf Linbcdf8b32021-01-14 16:44:13 +080012012 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080012013 * Get the EAB contact from the EAB database.
12014 */
12015 @Override
12016 public String getContactFromEab(String contact) {
12017 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
12018 enforceModifyPermission();
12019 final long identity = Binder.clearCallingIdentity();
12020 try {
12021 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
12022 } finally {
12023 Binder.restoreCallingIdentity(identity);
12024 }
12025 }
12026
12027 /**
Calvin Pana1434322021-07-01 19:27:01 +080012028 * Get the EAB capability from the EAB database.
12029 */
12030 @Override
12031 public String getCapabilityFromEab(String contact) {
12032 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
12033 enforceModifyPermission();
12034 final long identity = Binder.clearCallingIdentity();
12035 try {
12036 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
12037 } finally {
12038 Binder.restoreCallingIdentity(identity);
12039 }
12040 }
12041
12042 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080012043 * Remove the EAB contacts from the EAB database.
12044 */
12045 @Override
12046 public int removeContactFromEab(int subId, String contacts) {
12047 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
12048 enforceModifyPermission();
12049 final long identity = Binder.clearCallingIdentity();
12050 try {
12051 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
12052 } finally {
12053 Binder.restoreCallingIdentity(identity);
12054 }
12055 }
12056
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012057 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080012058 public boolean getDeviceUceEnabled() {
12059 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
12060 final long identity = Binder.clearCallingIdentity();
12061 try {
12062 return mApp.getDeviceUceEnabled();
12063 } finally {
12064 Binder.restoreCallingIdentity(identity);
12065 }
12066 }
12067
12068 @Override
12069 public void setDeviceUceEnabled(boolean isEnabled) {
12070 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
12071 final long identity = Binder.clearCallingIdentity();
12072 try {
12073 mApp.setDeviceUceEnabled(isEnabled);
12074 } finally {
12075 Binder.restoreCallingIdentity(identity);
12076 }
12077 }
12078
Brad Ebinger14d467f2021-02-12 06:18:28 +000012079 /**
12080 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
12081 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12082 */
12083 // Used for SHELL command only right now.
12084 @Override
12085 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
12086 List<String> featureTags) {
12087 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12088 "addUceRegistrationOverrideShell");
12089 final long identity = Binder.clearCallingIdentity();
12090 try {
12091 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
12092 new ArraySet<>(featureTags));
12093 } catch (ImsException e) {
12094 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12095 } finally {
12096 Binder.restoreCallingIdentity(identity);
12097 }
12098 }
12099
12100 /**
12101 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
12102 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12103 */
12104 // Used for SHELL command only right now.
12105 @Override
12106 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
12107 List<String> featureTags) {
12108 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12109 "removeUceRegistrationOverrideShell");
12110 final long identity = Binder.clearCallingIdentity();
12111 try {
12112 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
12113 new ArraySet<>(featureTags));
12114 } catch (ImsException e) {
12115 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12116 } finally {
12117 Binder.restoreCallingIdentity(identity);
12118 }
12119 }
12120
12121 /**
12122 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
12123 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12124 */
12125 // Used for SHELL command only right now.
12126 @Override
12127 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
12128 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12129 "clearUceRegistrationOverrideShell");
12130 final long identity = Binder.clearCallingIdentity();
12131 try {
12132 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
12133 } catch (ImsException e) {
12134 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12135 } finally {
12136 Binder.restoreCallingIdentity(identity);
12137 }
12138 }
12139
12140 /**
12141 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12142 */
12143 // Used for SHELL command only right now.
12144 @Override
12145 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
12146 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12147 "getLatestRcsContactUceCapabilityShell");
12148 final long identity = Binder.clearCallingIdentity();
12149 try {
12150 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
12151 } catch (ImsException e) {
12152 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12153 } finally {
12154 Binder.restoreCallingIdentity(identity);
12155 }
12156 }
12157
12158 /**
12159 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
12160 * device does not have an active PUBLISH.
12161 */
12162 // Used for SHELL command only right now.
12163 @Override
12164 public String getLastUcePidfXmlShell(int subId) {
12165 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
12166 final long identity = Binder.clearCallingIdentity();
12167 try {
12168 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
12169 } catch (ImsException e) {
12170 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12171 } finally {
12172 Binder.restoreCallingIdentity(identity);
12173 }
12174 }
12175
James.cf Line8713a42021-04-29 16:04:26 +080012176 /**
12177 * Remove UCE requests cannot be sent to the network status.
12178 */
12179 // Used for SHELL command only right now.
12180 @Override
12181 public boolean removeUceRequestDisallowedStatus(int subId) {
12182 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
12183 final long identity = Binder.clearCallingIdentity();
12184 try {
12185 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
12186 } catch (ImsException e) {
12187 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12188 } finally {
12189 Binder.restoreCallingIdentity(identity);
12190 }
12191 }
12192
James.cf Lin18bb9002021-05-25 01:37:38 +080012193 /**
12194 * Remove UCE requests cannot be sent to the network status.
12195 */
12196 // Used for SHELL command only.
12197 @Override
12198 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
12199 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
12200 final long identity = Binder.clearCallingIdentity();
12201 try {
12202 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
12203 } catch (ImsException e) {
12204 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12205 } finally {
12206 Binder.restoreCallingIdentity(identity);
12207 }
12208 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000012209
James.cf Lin4b784aa2021-01-31 03:25:15 +080012210 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012211 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12212 String callingPackage) {
12213 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12214 mApp, subId, "setSignalStrengthUpdateRequest");
12215
joonhunshin4ac60942023-11-15 15:23:39 +000012216 enforceTelephonyFeatureWithException(callingPackage,
12217 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest");
12218
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012219 final int callingUid = Binder.getCallingUid();
12220 // Verify that tha callingPackage belongs to the calling UID
12221 mApp.getSystemService(AppOpsManager.class)
12222 .checkPackage(callingUid, callingPackage);
12223
Rambo Wang3607f502021-02-01 21:51:40 -080012224 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012225
12226 final long identity = Binder.clearCallingIdentity();
12227 try {
12228 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
12229 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12230
12231 if (result instanceof IllegalStateException) {
12232 throw (IllegalStateException) result;
12233 }
12234 } finally {
12235 Binder.restoreCallingIdentity(identity);
12236 }
12237 }
12238
12239 @Override
12240 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12241 String callingPackage) {
12242 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12243 mApp, subId, "clearSignalStrengthUpdateRequest");
12244
joonhunshin4ac60942023-11-15 15:23:39 +000012245 enforceTelephonyFeatureWithException(callingPackage,
12246 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest");
12247
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012248 final int callingUid = Binder.getCallingUid();
12249 // Verify that tha callingPackage belongs to the calling UID
12250 mApp.getSystemService(AppOpsManager.class)
12251 .checkPackage(callingUid, callingPackage);
12252
12253 final long identity = Binder.clearCallingIdentity();
12254 try {
12255 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
12256 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12257
12258 if (result instanceof IllegalStateException) {
12259 throw (IllegalStateException) result;
12260 }
12261 } finally {
12262 Binder.restoreCallingIdentity(identity);
12263 }
12264 }
12265
Rambo Wang3607f502021-02-01 21:51:40 -080012266 private static void validateSignalStrengthUpdateRequest(Context context,
12267 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012268 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
12269 // phone/system process do not have further restriction on request
12270 return;
12271 }
12272
12273 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080012274 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012275 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080012276 context.enforceCallingOrSelfPermission(
12277 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
12278 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012279 }
12280
12281 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000012282 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012283 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012284 || info.isEnabled()) {
12285 throw new IllegalArgumentException(
12286 "Only system can set hide fields in SignalThresholdInfo");
12287 }
12288
12289 // Thresholds length for each RAN need in range. This has been validated in
12290 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
12291 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
12292 final int[] thresholds = info.getThresholds();
12293 Objects.requireNonNull(thresholds);
12294 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
12295 || thresholds.length
12296 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
12297 throw new IllegalArgumentException(
12298 "thresholds length is out of range: " + thresholds.length);
12299 }
12300 }
12301 }
SongFerngWang8236caa2021-01-17 21:51:44 +080012302
12303 /**
12304 * Gets the current phone capability.
12305 *
12306 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
12307 * @return the PhoneCapability which describes the data connection capability of modem.
12308 * It's used to evaluate possible phone config change, for example from single
12309 * SIM device to multi-SIM device.
12310 */
12311 @Override
12312 public PhoneCapability getPhoneCapability() {
12313 enforceReadPrivilegedPermission("getPhoneCapability");
joonhunshin4ac60942023-11-15 15:23:39 +000012314
12315 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12316 PackageManager.FEATURE_TELEPHONY, "getPhoneCapability");
12317
SongFerngWang8236caa2021-01-17 21:51:44 +080012318 final long identity = Binder.clearCallingIdentity();
12319 try {
12320 return mPhoneConfigurationManager.getCurrentPhoneCapability();
12321 } finally {
12322 Binder.restoreCallingIdentity(identity);
12323 }
12324 }
Michele Berionne5e411512020-11-13 02:36:59 +000012325
12326 /**
12327 * Prepare TelephonyManager for an unattended reboot. The reboot is
12328 * required to be done shortly after the API is invoked.
12329 */
12330 @Override
12331 @TelephonyManager.PrepareUnattendedRebootResult
12332 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012333 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000012334 enforceRebootPermission();
12335
joonhunshin4ac60942023-11-15 15:23:39 +000012336 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12337 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot");
12338
Michele Berionne5e411512020-11-13 02:36:59 +000012339 final long identity = Binder.clearCallingIdentity();
12340 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012341 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000012342 } finally {
12343 Binder.restoreCallingIdentity(identity);
12344 }
12345 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012346
12347 /**
12348 * Request to get the current slicing configuration including URSP rules and
12349 * NSSAIs (configured, allowed and rejected).
12350 *
12351 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
12352 */
12353 @Override
12354 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000012355 TelephonyPermissions
12356 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
12357 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012358
joonhunshin4ac60942023-11-15 15:23:39 +000012359 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12360 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
12361 "getSlicingConfig");
12362
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012363 final long identity = Binder.clearCallingIdentity();
12364 try {
12365 Phone phone = getDefaultPhone();
12366 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
12367 } finally {
12368 Binder.restoreCallingIdentity(identity);
12369 }
12370 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012371
12372 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070012373 * Check whether the given premium capability is available for purchase from the carrier.
12374 *
12375 * @param capability The premium capability to check.
12376 * @param subId The subId to check the premium capability for.
12377 *
12378 * @return Whether the given premium capability is available to purchase.
12379 */
12380 @Override
12381 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
12382 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12383 mApp, "isPremiumCapabilityAvailableForPurchase")) {
12384 log("Premium capability "
12385 + TelephonyManager.convertPremiumCapabilityToString(capability)
12386 + " is not available for purchase due to missing permissions.");
12387 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
12388 + "permission READ_BASIC_PHONE_STATE.");
12389 }
12390
joonhunshin4ac60942023-11-15 15:23:39 +000012391 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12392 PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase");
12393
Sarah Chin2ec39f62022-08-31 17:03:26 -070012394 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080012395 if (phone == null) {
12396 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12397 return false;
12398 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012399 final long identity = Binder.clearCallingIdentity();
12400 try {
Sarah Chincc5446f2023-10-23 17:57:19 -070012401 return SlicePurchaseController.getInstance(phone, mFeatureFlags)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012402 .isPremiumCapabilityAvailableForPurchase(capability);
12403 } finally {
12404 Binder.restoreCallingIdentity(identity);
12405 }
12406 }
12407
12408 /**
12409 * Purchase the given premium capability from the carrier.
12410 *
12411 * @param capability The premium capability to purchase.
12412 * @param callback The result of the purchase request.
12413 * @param subId The subId to purchase the premium capability for.
12414 */
12415 @Override
12416 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12417 log("purchasePremiumCapability: capability="
12418 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12419 + getCurrentPackageName());
12420
12421 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12422 mApp, "purchasePremiumCapability")) {
12423 log("purchasePremiumCapability "
12424 + TelephonyManager.convertPremiumCapabilityToString(capability)
12425 + " failed due to missing permissions.");
12426 throw new SecurityException("purchasePremiumCapability requires permission "
12427 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012428 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12429 mApp, "purchasePremiumCapability")) {
12430 log("purchasePremiumCapability "
12431 + TelephonyManager.convertPremiumCapabilityToString(capability)
12432 + " failed due to missing permissions.");
12433 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012434 }
12435
joonhunshin4ac60942023-11-15 15:23:39 +000012436 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12437 PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability");
12438
Sarah Chin2ec39f62022-08-31 17:03:26 -070012439 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012440 if (phone == null) {
12441 try {
12442 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12443 callback.accept(result);
12444 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12445 } catch (RemoteException e) {
12446 String logStr = "Purchase premium capability "
12447 + TelephonyManager.convertPremiumCapabilityToString(capability)
12448 + " failed due to RemoteException handling null phone: " + e;
12449 if (DBG) log(logStr);
12450 AnomalyReporter.reportAnomaly(
12451 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12452 }
12453 return;
12454 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012455
12456 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012457 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012458 callingProcess = mApp.getPackageManager().getApplicationInfo(
12459 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070012460 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012461 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012462 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012463
12464 boolean isVisible = false;
12465 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12466 if (am != null) {
12467 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12468 if (processes != null) {
12469 for (ActivityManager.RunningAppProcessInfo process : processes) {
12470 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070012471 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080012472 if (process.processName.equals(callingProcess) && process.importance
12473 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12474 isVisible = true;
12475 break;
12476 }
12477 }
12478 }
12479 }
12480
12481 if (!isVisible) {
12482 try {
12483 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12484 callback.accept(result);
12485 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12486 } catch (RemoteException e) {
12487 String logStr = "Purchase premium capability "
12488 + TelephonyManager.convertPremiumCapabilityToString(capability)
12489 + " failed due to RemoteException handling background application: " + e;
12490 if (DBG) log(logStr);
12491 AnomalyReporter.reportAnomaly(
12492 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12493 }
12494 return;
12495 }
12496
Sarah Chin71b3a852022-09-28 15:54:19 -070012497 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012498 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012499 }
12500
12501 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012502 * Register an IMS connection state callback
12503 */
12504 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012505 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12506 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012507 if (feature == ImsFeature.FEATURE_MMTEL) {
12508 // ImsMmTelManager
12509 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12510 TelephonyPermissions
12511 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12512 mApp, subId, "registerImsStateCallback");
12513 } else if (feature == ImsFeature.FEATURE_RCS) {
12514 // ImsRcsManager or SipDelegateManager
12515 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12516 Binder.getCallingUid(), "registerImsStateCallback",
12517 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12518 Manifest.permission.READ_PRECISE_PHONE_STATE,
12519 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12520 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12521 }
12522
12523 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12524 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12525 "IMS not available on device.");
12526 }
12527
12528 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12529 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12530 }
12531
12532 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12533 if (controller == null) {
12534 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12535 "IMS not available on device.");
12536 }
12537
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012538 if (callingPackage == null) {
12539 callingPackage = getCurrentPackageName();
12540 }
12541
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012542 final long token = Binder.clearCallingIdentity();
12543 try {
12544 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012545 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012546 } catch (ImsException e) {
12547 throw new ServiceSpecificException(e.getCode());
12548 } finally {
12549 Binder.restoreCallingIdentity(token);
12550 }
12551 }
12552
12553 /**
12554 * Unregister an IMS connection state callback
12555 */
12556 @Override
12557 public void unregisterImsStateCallback(IImsStateCallback cb) {
12558 final long token = Binder.clearCallingIdentity();
12559 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12560 if (controller == null) {
12561 return;
12562 }
12563 try {
12564 controller.unregisterImsStateCallback(cb);
12565 } finally {
12566 Binder.restoreCallingIdentity(token);
12567 }
12568 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012569
12570 /**
12571 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12572 *
12573 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
12574 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
12575 * SecurityException.
12576 * If there is current registered network this value will be same as the registered cell
12577 * identity. If the device goes out of service the previous cell identity is cached and
12578 * will be returned. If the cache age of the Cell identity is more than 24 hours
12579 * it will be cleared and null will be returned.
12580 *
12581 */
12582 @Override
12583 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12584 String callingFeatureId) {
12585 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12586 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12587 LocationAccessPolicy.checkLocationPermission(mApp,
12588 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12589 .setCallingPackage(callingPackage)
12590 .setCallingFeatureId(callingFeatureId)
12591 .setCallingPid(Binder.getCallingPid())
12592 .setCallingUid(Binder.getCallingUid())
12593 .setMethod("getLastKnownCellIdentity")
12594 .setLogAsInfo(true)
12595 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12596 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12597 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12598 .build());
12599
12600 boolean hasFinePermission =
12601 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12602 if (!hasFinePermission
12603 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12604 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012605 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012606 }
12607
12608 final long identity = Binder.clearCallingIdentity();
12609 try {
Ling Mac28f0212023-03-24 16:07:15 -070012610 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012611 if (sst == null) return null;
12612 return sst.getLastKnownCellIdentity();
12613 } finally {
12614 Binder.restoreCallingIdentity(identity);
12615 }
12616 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012617
jimsun3b9ccac2021-10-26 15:01:23 +080012618 /**
12619 * Sets the modem service class Name that Telephony will bind to.
12620 *
12621 * @param serviceName The class name of the modem service.
12622 * @return true if the operation is succeed, otherwise false.
12623 */
12624 public boolean setModemService(String serviceName) {
12625 Log.d(LOG_TAG, "setModemService - " + serviceName);
12626 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12627 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012628 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12629 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012630 return mPhoneConfigurationManager.setModemService(serviceName);
12631 }
12632
12633 /**
12634 * Return the class name of the currently bounded modem service.
12635 *
12636 * @return the class name of the modem service.
12637 */
12638 public String getModemService() {
12639 String result;
12640 Log.d(LOG_TAG, "getModemService");
12641 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12642 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012643 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012644 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12645 "getModemService");
12646 result = mPhoneConfigurationManager.getModemService();
12647 Log.d(LOG_TAG, "result = " + result);
12648 return result;
12649 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012650
12651 @Override
12652 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12653 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12654 mApp.enforceCallingOrSelfPermission(
12655 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12656 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12657
12658 final long identity = Binder.clearCallingIdentity();
12659 try {
12660 Phone phone = getPhone(subId);
12661 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012662 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12663 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012664 phone.setVoiceServiceStateOverride(hasService);
12665 } finally {
12666 Binder.restoreCallingIdentity(identity);
12667 }
12668 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012669
12670 /**
12671 * set removable eSIM as default eUICC.
12672 *
12673 * @hide
12674 */
12675 @Override
12676 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12677 enforceModifyPermission();
12678 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12679
12680 final long identity = Binder.clearCallingIdentity();
12681 try {
12682 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12683 } finally {
12684 Binder.restoreCallingIdentity(identity);
12685 }
12686 }
12687
12688 /**
12689 * Returns whether the removable eSIM is default eUICC or not.
12690 *
12691 * @hide
12692 */
12693 @Override
12694 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12695 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12696 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12697
12698 final long identity = Binder.clearCallingIdentity();
12699 try {
12700 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12701 } finally {
12702 Binder.restoreCallingIdentity(identity);
12703 }
12704 }
12705
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012706 /**
12707 * Get the component name of the default app to direct respond-via-message intent for the
12708 * user associated with this subscription, update the cache if there is no respond-via-message
12709 * application currently configured for this user.
12710 * @return component name of the app and class to direct Respond Via Message intent to, or
12711 * {@code null} if the functionality is not supported.
12712 * @hide
12713 */
12714 @Override
12715 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12716 boolean updateIfNeeded) {
12717 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012718
joonhunshin4ac60942023-11-15 15:23:39 +000012719 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12720 PackageManager.FEATURE_TELEPHONY_MESSAGING,
12721 "getDefaultRespondViaMessageApplication");
12722
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012723 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12724
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012725 UserHandle userHandle = null;
12726 final long identity = Binder.clearCallingIdentity();
12727 try {
12728 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12729 } finally {
12730 Binder.restoreCallingIdentity(identity);
12731 }
12732 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12733 updateIfNeeded, userHandle);
12734 }
Jack Yuf5badd92022-12-08 00:50:53 -080012735
12736 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012737 * Set whether the device is able to connect with null ciphering or integrity
12738 * algorithms. This is a global setting and will apply to all active subscriptions
12739 * and all new subscriptions after this.
12740 *
12741 * @param enabled when true, null cipher and integrity algorithms are allowed.
12742 * @hide
12743 */
12744 @Override
12745 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12746 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12747 enforceModifyPermission();
12748 checkForNullCipherAndIntegritySupport();
12749
12750 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12751 // for listening to these preference changes and applying them immediately.
12752 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12753 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12754 editor.apply();
12755
12756 for (Phone phone: PhoneFactory.getPhones()) {
12757 phone.handleNullCipherEnabledChange();
12758 }
12759 }
12760
12761
12762 /**
12763 * Get whether the device is able to connect with null ciphering or integrity
12764 * algorithms. Note that this retrieves the phone-global preference and not
12765 * the state of the radio.
12766 *
12767 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12768 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12769 * version for this feature.
12770 * @hide
12771 */
12772 @Override
12773 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12774 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12775 enforceReadPermission();
12776 checkForNullCipherAndIntegritySupport();
12777 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12778 }
12779
12780 private void checkForNullCipherAndIntegritySupport() {
12781 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12782 throw new UnsupportedOperationException(
12783 "Null cipher and integrity operations require HAL 2.1 or above");
12784 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012785 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12786 throw new UnsupportedOperationException(
12787 "Null cipher and integrity operations unsupported by modem");
12788 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012789 }
12790
Gil Cukierman06403e12023-11-29 16:33:03 +000012791 private void checkForIdentifierDisclosureNotificationSupport() {
12792 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) {
12793 throw new UnsupportedOperationException(
12794 "Cellular identifier disclosure transparency operations require HAL 2.2 or "
12795 + "above");
12796 }
12797 if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) {
12798 throw new UnsupportedOperationException(
12799 "Cellular identifier disclosure transparency operations unsupported by modem");
12800 }
12801 }
12802
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012803 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012804 * Get the SIM state for the slot index.
12805 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12806 *
12807 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12808 */
12809 @Override
12810 @SimState
12811 public int getSimStateForSlotIndex(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +000012812 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12813 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex");
12814
Jack Yuf5badd92022-12-08 00:50:53 -080012815 IccCardConstants.State simState;
12816 if (slotIndex < 0) {
12817 simState = IccCardConstants.State.UNKNOWN;
12818 } else {
12819 Phone phone = null;
12820 try {
12821 phone = PhoneFactory.getPhone(slotIndex);
12822 } catch (IllegalStateException e) {
12823 // ignore
12824 }
12825 if (phone == null) {
12826 simState = IccCardConstants.State.UNKNOWN;
12827 } else {
12828 IccCard icc = phone.getIccCard();
12829 if (icc == null) {
12830 simState = IccCardConstants.State.UNKNOWN;
12831 } else {
12832 simState = icc.getState();
12833 }
12834 }
12835 }
12836 return simState.ordinal();
12837 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012838
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012839 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
12840 boolean enableLogcat,
12841 long logcatStartTimestampMillis, boolean enableTelecomDump,
12842 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012843 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
12844 TelephonyManager.EmergencyCallDiagnosticParams edp =
12845 new TelephonyManager.EmergencyCallDiagnosticParams();
12846 edp.setLogcatCollection(enableLogcat, logcatStartTimestampMillis);
12847 edp.setTelephonyDumpSysCollection(enableTelephonyDump);
12848 edp.setTelecomDumpSysCollection(enableTelecomDump);
12849 Log.d(LOG_TAG, "persisting with Params " + edp.toString());
12850 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
12851 Executors.newCachedThreadPool(), db,
12852 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
12853 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), edp, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012854 }
12855
12856 /**
12857 * Request telephony to persist state for debugging emergency call failures.
12858 *
12859 * @param dropBoxTag Tag to use when persisting data to dropbox service.
12860 * @param enableLogcat whether to collect logcat output
12861 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
12862 * @param enableTelecomDump whether to collect telecom dumpsys
12863 * @param enableTelephonyDump whether to collect telephony dumpsys
12864 */
12865 @Override
12866 @RequiresPermission(android.Manifest.permission.DUMP)
12867 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
12868 long logcatStartTimestampMillis, boolean enableTelecomDump,
12869 boolean enableTelephonyDump) {
12870 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
12871 "persistEmergencyCallDiagnosticData");
12872 final long identity = Binder.clearCallingIdentity();
12873 try {
12874 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
12875 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
12876
12877 } finally {
12878 Binder.restoreCallingIdentity(identity);
12879 }
12880 }
12881
Hui Wang9b5793a2022-12-05 14:38:06 -060012882 /**
12883 * Get current cell broadcast ranges.
12884 */
12885 @Override
12886 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12887 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12888 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12889 "getCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012890
12891 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12892 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges");
12893
Hui Wang9b5793a2022-12-05 14:38:06 -060012894 final long identity = Binder.clearCallingIdentity();
12895 try {
12896 return getPhone(subId).getCellBroadcastIdRanges();
12897 } finally {
12898 Binder.restoreCallingIdentity(identity);
12899 }
12900 }
12901
12902 /**
12903 * Set reception of cell broadcast messages with the list of the given ranges
12904 *
12905 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12906 */
12907 @Override
12908 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12909 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12910 @Nullable IIntegerConsumer callback) {
12911 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12912 "setCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012913
12914 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12915 PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges");
12916
Hui Wang9b5793a2022-12-05 14:38:06 -060012917 final long identity = Binder.clearCallingIdentity();
12918 try {
12919 Phone phone = getPhoneFromSubId(subId);
12920 if (DBG) {
12921 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12922 }
12923 phone.setCellBroadcastIdRanges(ranges, result -> {
12924 if (callback != null) {
12925 try {
12926 callback.accept(result);
12927 } catch (RemoteException e) {
12928 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12929 }
12930 }
12931 });
12932 } finally {
12933 Binder.restoreCallingIdentity(identity);
12934 }
12935 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012936
12937 /**
12938 * Returns whether the device supports the domain selection service.
12939 *
12940 * @return {@code true} if the device supports the domain selection service.
12941 */
12942 @Override
12943 public boolean isDomainSelectionSupported() {
12944 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12945 "isDomainSelectionSupported");
12946
12947 final long identity = Binder.clearCallingIdentity();
12948 try {
12949 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12950 } finally {
12951 Binder.restoreCallingIdentity(identity);
12952 }
12953 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012954
12955 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012956 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
12957 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
12958 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080012959 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012960 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chinabf081b2023-03-09 23:00:57 -080012961 * @param enableSatellite {@code true} to enable the satellite modem and
12962 * {@code false} to disable.
12963 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
12964 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080012965 *
12966 * @throws SecurityException if the caller doesn't have the required permission.
12967 */
12968 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012969 public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode,
12970 @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012971 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080012972 ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) {
12973 @Override
12974 protected void onReceiveResult(int resultCode, Bundle resultData) {
12975 Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode
12976 + ", resultData=" + resultData);
12977 boolean isAllowed = false;
12978 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept);
12979 if (resultCode == SATELLITE_RESULT_SUCCESS) {
12980 if (resultData != null
12981 && resultData.containsKey(KEY_SATELLITE_COMMUNICATION_ALLOWED)) {
12982 isAllowed = resultData.getBoolean(KEY_SATELLITE_COMMUNICATION_ALLOWED);
12983 } else {
12984 loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist.");
12985 }
12986 } else {
12987 result.accept(resultCode);
12988 return;
12989 }
12990 if (isAllowed) {
12991 mSatelliteController.requestSatelliteEnabled(
12992 subId, enableSatellite, enableDemoMode, callback);
12993 } else {
12994 result.accept(SATELLITE_RESULT_ACCESS_BARRED);
12995 }
12996 }
12997 };
12998 mSatelliteAccessController.requestIsSatelliteCommunicationAllowedForCurrentLocation(
12999 subId, resultReceiver);
Sarah Chin503828c2023-02-01 23:54:20 -080013000 }
13001
13002 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013003 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080013004 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013005 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013006 * @param result The result receiver that returns whether the satellite modem is enabled
13007 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013008 *
13009 * @throws SecurityException if the caller doesn't have the required permission.
13010 */
13011 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013012 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
13013 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013014 mSatelliteController.requestIsSatelliteEnabled(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013015 }
13016
13017 /**
Sarah Chin43457982023-02-15 17:50:38 -080013018 * Request to get whether the satellite service demo mode is enabled.
13019 *
13020 * @param subId The subId of the subscription to check whether the satellite demo mode
13021 * is enabled for.
13022 * @param result The result receiver that returns whether the satellite demo mode is enabled
13023 * if the request is successful or an error code if the request failed.
13024 *
13025 * @throws SecurityException if the caller doesn't have the required permission.
13026 */
13027 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013028 public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
13029 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
13030 mSatelliteController.requestIsDemoModeEnabled(subId, result);
Sarah Chin43457982023-02-15 17:50:38 -080013031 }
13032
13033 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013034 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080013035 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013036 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013037 * @param result The result receiver that returns whether the satellite service is supported on
13038 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013039 */
13040 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013041 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013042 mSatelliteController.requestIsSatelliteSupported(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013043 }
13044
13045 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013046 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080013047 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013048 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013049 * @param result The result receiver that returns the {@link SatelliteCapabilities}
13050 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013051 *
13052 * @throws SecurityException if the caller doesn't have required permission.
13053 */
13054 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013055 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
13056 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013057 mSatelliteController.requestSatelliteCapabilities(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013058 }
13059
13060 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013061 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013062 * This can be called by the pointing UI when the user starts pointing to the satellite.
13063 * Modem should continue to report the pointing input as the device or satellite moves.
13064 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013065 * @param subId The subId of the subscription to start satellite transmission updates for.
13066 * @param resultCallback The callback to get the result of the request.
13067 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080013068 *
13069 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013070 */
13071 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013072 public void startSatelliteTransmissionUpdates(int subId,
13073 @NonNull IIntegerConsumer resultCallback,
13074 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13075 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
13076 mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080013077 }
13078
13079 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013080 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013081 * This can be called by the pointing UI when the user stops pointing to the satellite.
13082 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013083 * @param subId The subId of the subscription to stop satellite transmission updates for.
13084 * @param resultCallback The callback to get the result of the request.
13085 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
13086 * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080013087 *
13088 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013089 */
13090 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013091 public void stopSatelliteTransmissionUpdates(int subId,
13092 @NonNull IIntegerConsumer resultCallback,
13093 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13094 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
13095 mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013096 }
13097
13098 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013099 * Register the subscription with a satellite provider.
13100 * This is needed to register the subscription if the provider allows dynamic registration.
13101 *
13102 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013103 * @param token The token to be used as a unique identifier for provisioning with satellite
13104 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013105 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080013106 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013107 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013108 * @return The signal transport used by the caller to cancel the provision request,
13109 * or {@code null} if the request failed.
13110 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013111 * @throws SecurityException if the caller doesn't have the required permission.
13112 */
13113 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013114 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013115 @NonNull String token, @NonNull byte[] provisionData,
13116 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013117 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013118 return mSatelliteController.provisionSatelliteService(subId, token, provisionData,
13119 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013120 }
13121
13122 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013123 * Unregister the device/subscription with the satellite provider.
13124 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013125 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013126 * should report as deprovisioned.
13127 *
13128 * @param subId The subId of the subscription to be deprovisioned.
13129 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080013130 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013131 *
13132 * @throws SecurityException if the caller doesn't have the required permission.
13133 */
13134 @Override
13135 public void deprovisionSatelliteService(int subId,
13136 @NonNull String token, @NonNull IIntegerConsumer callback) {
13137 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013138 mSatelliteController.deprovisionSatelliteService(subId, token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013139 }
13140
13141 /**
Sarah Chin43457982023-02-15 17:50:38 -080013142 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013143 *
Sarah Chin43457982023-02-15 17:50:38 -080013144 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013145 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013146 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013147 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013148 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013149 * @throws SecurityException if the caller doesn't have the required permission.
13150 */
13151 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013152 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
13153 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013154 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013155 return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013156 }
13157
13158 /**
Sarah Chin43457982023-02-15 17:50:38 -080013159 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013160 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013161 *
Sarah Chin43457982023-02-15 17:50:38 -080013162 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013163 * @param callback The callback that was passed to
13164 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013165 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013166 * @throws SecurityException if the caller doesn't have the required permission.
13167 */
13168 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013169 public void unregisterForSatelliteProvisionStateChanged(
13170 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013171 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013172 mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013173 }
13174
13175 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013176 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013177 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013178 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013179 * @param result The result receiver that returns whether the device is provisioned with a
13180 * satellite provider if the request is successful or an error code if the
13181 * request failed.
13182 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013183 * @throws SecurityException if the caller doesn't have the required permission.
13184 */
13185 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013186 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
13187 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013188 mSatelliteController.requestIsSatelliteProvisioned(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013189 }
13190
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013191 /**
Sarah Chin43457982023-02-15 17:50:38 -080013192 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013193 *
Sarah Chin43457982023-02-15 17:50:38 -080013194 * @param subId The subId of the subscription to register for satellite modem state changed.
13195 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080013196 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013197 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013198 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013199 * @throws SecurityException if the caller doesn't have the required permission.
13200 */
13201 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013202 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013203 @NonNull ISatelliteStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080013204 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013205 return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013206 }
13207
13208 /**
Sarah Chin43457982023-02-15 17:50:38 -080013209 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013210 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013211 *
Sarah Chin43457982023-02-15 17:50:38 -080013212 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080013213 * @param callback The callback that was passed to
Sarah Chin43457982023-02-15 17:50:38 -080013214 * {@link #registerForSatelliteModemStateChanged(int, ISatelliteStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013215 *
13216 * @throws SecurityException if the caller doesn't have the required permission.
13217 */
13218 @Override
Sarah Chin43457982023-02-15 17:50:38 -080013219 public void unregisterForSatelliteModemStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013220 @NonNull ISatelliteStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080013221 enforceSatelliteCommunicationPermission("unregisterForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013222 mSatelliteController.unregisterForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013223 }
13224
13225 /**
13226 * Register to receive incoming datagrams over satellite.
13227 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013228 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Sarah Chindf715ec2023-02-13 13:46:24 -080013229 * @param callback The callback to handle incoming datagrams over satellite.
13230 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013231 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013232 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013233 * @throws SecurityException if the caller doesn't have the required permission.
13234 */
13235 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013236 @SatelliteManager.SatelliteResult public int registerForSatelliteDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013237 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013238 enforceSatelliteCommunicationPermission("registerForSatelliteDatagram");
Sarah Chinabf081b2023-03-09 23:00:57 -080013239 return mSatelliteController.registerForSatelliteDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013240 }
13241
13242 /**
13243 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013244 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013245 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013246 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
13247 * @param callback The callback that was passed to
Sarah Chinabf081b2023-03-09 23:00:57 -080013248 * {@link #registerForSatelliteDatagram(int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013249 *
13250 * @throws SecurityException if the caller doesn't have the required permission.
13251 */
13252 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013253 public void unregisterForSatelliteDatagram(int subId,
13254 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013255 enforceSatelliteCommunicationPermission("unregisterForSatelliteDatagram");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013256 mSatelliteController.unregisterForSatelliteDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013257 }
13258
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013259 /**
13260 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013261 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013262 * This method requests modem to check if there are any pending datagrams to be received over
13263 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000013264 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080013265 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013266 * @param subId The subId of the subscription used for receiving datagrams.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013267 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013268 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013269 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013270 */
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013271 @Override
13272 public void pollPendingSatelliteDatagrams(int subId, IIntegerConsumer callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013273 enforceSatelliteCommunicationPermission("pollPendingSatelliteDatagrams");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013274 mSatelliteController.pollPendingSatelliteDatagrams(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013275 }
13276
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013277 /**
13278 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013279 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013280 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
13281 * input to this method. Datagram received here will be passed down to modem without any
13282 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080013283 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013284 * @param subId The subId of the subscription to send satellite datagrams for.
13285 * @param datagramType datagram type indicating whether the datagram is of type
13286 * SOS_SMS or LOCATION_SHARING.
13287 * @param datagram encoded gateway datagram which is encrypted by the caller.
13288 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000013289 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
13290 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013291 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013292 *
13293 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013294 */
13295 @Override
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000013296 public void sendSatelliteDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
13297 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
13298 @NonNull IIntegerConsumer callback) {
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013299 enforceSatelliteCommunicationPermission("sendSatelliteDatagram");
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000013300 mSatelliteController.sendSatelliteDatagram(subId, datagramType, datagram,
13301 needFullScreenPointingUI, callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013302 }
13303
Sarah Chindf715ec2023-02-13 13:46:24 -080013304 /**
13305 * Request to get whether satellite communication is allowed for the current location.
13306 *
13307 * @param subId The subId of the subscription to check whether satellite communication is
13308 * allowed for the current location for.
13309 * @param result The result receiver that returns whether satellite communication is allowed
13310 * for the current location if the request is successful or an error code
13311 * if the request failed.
13312 *
13313 * @throws SecurityException if the caller doesn't have the required permission.
13314 */
13315 @Override
13316 public void requestIsSatelliteCommunicationAllowedForCurrentLocation(int subId,
13317 @NonNull ResultReceiver result) {
13318 enforceSatelliteCommunicationPermission(
13319 "requestIsSatelliteCommunicationAllowedForCurrentLocation");
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013320 mSatelliteAccessController.requestIsSatelliteCommunicationAllowedForCurrentLocation(
13321 subId, result);
Sarah Chindf715ec2023-02-13 13:46:24 -080013322 }
13323
13324 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013325 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080013326 *
Sarah Chin5f57c582023-02-14 04:16:10 -080013327 * @param subId The subId to get the time after which the satellite will be visible for.
13328 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080013329 * be visible if the request is successful or an error code if the request failed.
13330 *
13331 * @throws SecurityException if the caller doesn't have the required permission.
13332 */
13333 @Override
13334 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
13335 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013336 mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013337 }
13338
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013339 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013340 * Inform that Device is aligned to satellite for demo mode.
13341 *
13342 * @param subId The subId to get the time after which the satellite will be visible for.
13343 * @param isAligned {@code true} Device is aligned with the satellite for demo mode
13344 * {@code false} Device fails to align with the satellite for demo mode.
13345 *
13346 * @throws SecurityException if the caller doesn't have required permission.
13347 */
13348 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
13349
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013350 public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) {
Hakjun Choiae365972023-04-25 11:00:31 +000013351 enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite");
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013352 mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned);
Hakjun Choiae365972023-04-25 11:00:31 +000013353 }
13354
13355 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000013356 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
13357 * by modem.
13358 *
13359 * @param subId The subId of the subscription to request for.
13360 * @param reason Reason for disallowing satellite communication for carrier.
13361 * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the
13362 * operation.
13363 *
13364 * @throws SecurityException if the caller doesn't have required permission.
13365 */
13366 public void addSatelliteAttachRestrictionForCarrier(int subId,
13367 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13368 @NonNull IIntegerConsumer callback) {
13369 enforceSatelliteCommunicationPermission("addSatelliteAttachRestrictionForCarrier");
13370 final long identity = Binder.clearCallingIdentity();
13371 try {
13372 mSatelliteController.addSatelliteAttachRestrictionForCarrier(subId, reason, callback);
13373 } finally {
13374 Binder.restoreCallingIdentity(identity);
13375 }
13376 }
13377
13378 /**
13379 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
13380 * by modem.
13381 *
13382 * @param subId The subId of the subscription to request for.
13383 * @param reason Reason for disallowing satellite communication.
13384 * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the
13385 * operation.
13386 *
13387 * @throws SecurityException if the caller doesn't have required permission.
13388 */
13389 public void removeSatelliteAttachRestrictionForCarrier(int subId,
13390 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13391 @NonNull IIntegerConsumer callback) {
13392 enforceSatelliteCommunicationPermission("removeSatelliteAttachRestrictionForCarrier");
13393 final long identity = Binder.clearCallingIdentity();
13394 try {
13395 mSatelliteController.removeSatelliteAttachRestrictionForCarrier(subId, reason,
13396 callback);
13397 } finally {
13398 Binder.restoreCallingIdentity(identity);
13399 }
13400 }
13401
13402 /**
13403 * Get reasons for disallowing satellite communication, as requested by
13404 * {@link #addSatelliteAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
13405 *
13406 * @param subId The subId of the subscription to request for.
13407 *
13408 * @return Integer array of reasons for disallowing satellite communication.
13409 *
13410 * @throws SecurityException if the caller doesn't have the required permission.
13411 */
13412 public @NonNull int[] getSatelliteAttachRestrictionReasonsForCarrier(
13413 int subId) {
13414 enforceSatelliteCommunicationPermission("getSatelliteAttachRestrictionReasonsForCarrier");
13415 final long identity = Binder.clearCallingIdentity();
13416 try {
13417 Set<Integer> reasonSet =
13418 mSatelliteController.getSatelliteAttachRestrictionReasonsForCarrier(subId);
13419 return reasonSet.stream().mapToInt(i->i).toArray();
13420 } finally {
13421 Binder.restoreCallingIdentity(identity);
13422 }
13423 }
13424
13425 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000013426 * Request to get the signal strength of the satellite connection.
13427 *
13428 * @param subId The subId of the subscription to request for.
13429 * @param result Result receiver to get the error code of the request and the current signal
13430 * strength of the satellite connection.
13431 *
13432 * @throws SecurityException if the caller doesn't have required permission.
13433 */
13434 @Override
13435 public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) {
13436 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
13437 final long identity = Binder.clearCallingIdentity();
13438 try {
13439 mSatelliteController.requestNtnSignalStrength(subId, result);
13440 } finally {
13441 Binder.restoreCallingIdentity(identity);
13442 }
13443 }
13444
13445 /**
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013446 * Registers for NTN signal strength changed from satellite modem. If the registration operation
13447 * is not successful, a {@link ServiceSpecificException} that contains
13448 * {@link SatelliteManager.SatelliteResult} will be thrown.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013449 *
13450 * @param subId The subId of the subscription to request for.
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013451 * @param callback The callback to handle the NTN signal strength changed event. If the
13452 * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged(
13453 * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of
13454 * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial
13455 * network has changed.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013456 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013457 * @throws SecurityException If the caller doesn't have the required permission.
13458 * @throws ServiceSpecificException If the callback registration operation fails.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013459 */
13460 @Override
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013461 public void registerForNtnSignalStrengthChanged(int subId,
13462 @NonNull INtnSignalStrengthCallback callback) throws RemoteException {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013463 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
13464 final long identity = Binder.clearCallingIdentity();
13465 try {
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013466 mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013467 } finally {
13468 Binder.restoreCallingIdentity(identity);
13469 }
13470 }
13471
13472 /**
13473 * Unregisters for NTN signal strength changed from satellite modem.
13474 * If callback was not registered before, the request will be ignored.
13475 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013476 * @param subId The subId of the subscription to unregister for listening NTN signal strength
13477 * changed event.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013478 * @param callback The callback that was passed to
13479 * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)}
13480 *
13481 * @throws SecurityException if the caller doesn't have the required permission.
13482 */
13483 @Override
13484 public void unregisterForNtnSignalStrengthChanged(
13485 int subId, @NonNull INtnSignalStrengthCallback callback) {
13486 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
13487 final long identity = Binder.clearCallingIdentity();
13488 try {
13489 mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback);
13490 } finally {
13491 Binder.restoreCallingIdentity(identity);
13492 }
13493 }
13494
13495 /**
Hakjun Choi8d96a562023-10-26 15:01:40 +000013496 * Registers for satellite capabilities change event from the satellite service.
13497 *
13498 * @param subId The subId of the subscription to request for.
13499 * @param callback The callback to handle the satellite capabilities changed event.
13500 *
13501 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13502 *
13503 * @throws SecurityException if the caller doesn't have required permission.
13504 */
13505 @Override
13506 @SatelliteManager.SatelliteResult public int registerForSatelliteCapabilitiesChanged(
13507 int subId, @NonNull ISatelliteCapabilitiesCallback callback) {
13508 enforceSatelliteCommunicationPermission("registerForSatelliteCapabilitiesChanged");
13509 final long identity = Binder.clearCallingIdentity();
13510 try {
13511 return mSatelliteController.registerForSatelliteCapabilitiesChanged(subId, callback);
13512 } finally {
13513 Binder.restoreCallingIdentity(identity);
13514 }
13515 }
13516
13517 /**
13518 * Unregisters for satellite capabilities change event from the satellite service.
13519 * If callback was not registered before, the request will be ignored.
13520 *
13521 * @param subId The subId of the subscription to unregister for satellite capabilities change.
13522 * @param callback The callback that was passed to.
13523 * {@link #registerForSatelliteCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}.
13524 *
13525 * @throws SecurityException if the caller doesn't have required permission.
13526 */
13527 @Override
13528 public void unregisterForSatelliteCapabilitiesChanged(
13529 int subId, @NonNull ISatelliteCapabilitiesCallback callback) {
13530 enforceSatelliteCommunicationPermission("unregisterForSatelliteCapabilitiesChanged");
13531 final long identity = Binder.clearCallingIdentity();
13532 try {
13533 mSatelliteController.unregisterForSatelliteCapabilitiesChanged(subId, callback);
13534 } finally {
13535 Binder.restoreCallingIdentity(identity);
13536 }
13537 }
13538
13539 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013540 * This API can be used by only CTS to update satellite vendor service package name.
13541 *
13542 * @param servicePackageName The package name of the satellite vendor service.
13543 * @return {@code true} if the satellite vendor service is set successfully,
13544 * {@code false} otherwise.
13545 */
13546 public boolean setSatelliteServicePackageName(String servicePackageName) {
13547 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName);
13548 TelephonyPermissions.enforceShellOnly(
13549 Binder.getCallingUid(), "setSatelliteServicePackageName");
13550 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13551 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13552 "setSatelliteServicePackageName");
13553 return mSatelliteController.setSatelliteServicePackageName(servicePackageName);
13554 }
13555
13556 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070013557 * This API can be used by only CTS to update satellite gateway service package name.
13558 *
13559 * @param servicePackageName The package name of the satellite gateway service.
13560 * @return {@code true} if the satellite gateway service is set successfully,
13561 * {@code false} otherwise.
13562 */
13563 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
13564 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
13565 TelephonyPermissions.enforceShellOnly(
13566 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
13567 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13568 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13569 "setSatelliteGatewayServicePackageName");
13570 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
13571 }
13572
13573 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070013574 * This API can be used by only CTS to update satellite pointing UI app package and class names.
13575 *
13576 * @param packageName The package name of the satellite pointing UI app.
13577 * @param className The class name of the satellite pointing UI app.
13578 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
13579 * {@code false} otherwise.
13580 */
13581 public boolean setSatellitePointingUiClassName(
13582 @Nullable String packageName, @Nullable String className) {
13583 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
13584 + ", className=" + className);
13585 TelephonyPermissions.enforceShellOnly(
13586 Binder.getCallingUid(), "setSatellitePointingUiClassName");
13587 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13588 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13589 "setSatelliteGatewayServicePackageName");
13590 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
13591 }
13592
13593 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070013594 * This API can be used by only CTS to update the timeout duration in milliseconds that
13595 * satellite should stay at listening mode to wait for the next incoming page before disabling
13596 * listening mode.
13597 *
13598 * @param timeoutMillis The timeout duration in millisecond.
13599 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13600 */
13601 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
13602 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
13603 TelephonyPermissions.enforceShellOnly(
13604 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
13605 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13606 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13607 "setSatelliteListeningTimeoutDuration");
13608 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
13609 }
13610
13611 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013612 * This API can be used by only CTS to update the timeout duration in milliseconds whether
13613 * the device is aligned with the satellite for demo mode
13614 *
13615 * @param timeoutMillis The timeout duration in millisecond.
13616 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13617 */
13618 public boolean setSatelliteDeviceAlignedTimeoutDuration(long timeoutMillis) {
13619 Log.d(LOG_TAG, "setDeviceAlignedTimeoutDuration - " + timeoutMillis);
13620 TelephonyPermissions.enforceShellOnly(
13621 Binder.getCallingUid(), "setDeviceAlignedTimeoutDuration");
13622 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13623 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13624 "setDeviceAlignedTimeoutDuration");
13625 return mSatelliteController.setSatelliteDeviceAlignedTimeoutDuration(timeoutMillis);
13626 }
13627
13628 /**
Thomas Nguyen11a051f2023-10-25 10:14:55 -070013629 * This API can be used in only testing to override connectivity status in monitoring emergency
13630 * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.
13631 *
13632 * @param handoverType The type of handover from emergency call to satellite messaging. Use one
13633 * of the following values to enable the override:
13634 * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS
13635 * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911
13636 * To disable the override, use -1 for handoverType.
13637 * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer
13638 * delaySeconds after the emergency call starts.
13639 * @return {@code true} if the handover type is set successfully, {@code false} otherwise.
13640 */
13641 public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) {
13642 Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType);
13643 TelephonyPermissions.enforceShellOnly(
13644 Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType");
13645 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13646 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13647 "setEmergencyCallToSatelliteHandoverType");
13648 return mSatelliteController.setEmergencyCallToSatelliteHandoverType(
13649 handoverType, delaySeconds);
13650 }
13651
13652 /**
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013653 * This API should be used by only CTS tests to forcefully set telephony country codes.
13654 *
13655 * @return {@code true} if the country code is set successfully, {@code false} otherwise.
13656 */
13657 public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes,
13658 Map cachedNetworkCountryCodes, String locationCountryCode,
13659 long locationCountryCodeTimestampNanos) {
13660 Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes="
13661 + String.join(", ", currentNetworkCountryCodes)
13662 + ", locationCountryCode=" + locationCountryCode
13663 + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos
13664 + ", reset=" + reset + ", cachedNetworkCountryCodes="
13665 + String.join(", ", cachedNetworkCountryCodes.keySet()));
13666 TelephonyPermissions.enforceShellOnly(
13667 Binder.getCallingUid(), "setCachedLocationCountryCode");
13668 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13669 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13670 "setCachedLocationCountryCode");
13671 return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext()).setCountryCodes(
13672 reset, currentNetworkCountryCodes, cachedNetworkCountryCodes, locationCountryCode,
13673 locationCountryCodeTimestampNanos);
13674 }
13675
13676 /**
13677 * This API should be used by only CTS tests to override the overlay configs of satellite
13678 * access controller.
13679 *
13680 * @param reset {@code true} mean the overridden configs should not be used, {@code false}
13681 * otherwise.
13682 * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise.
13683 */
13684 public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed,
13685 String s2CellFile, long locationFreshDurationNanos,
13686 List<String> satelliteCountryCodes) {
13687 Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset
13688 + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile
13689 + ", locationFreshDurationNanos=" + locationFreshDurationNanos
13690 + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null)
13691 ? String.join(", ", satelliteCountryCodes) : null));
13692 TelephonyPermissions.enforceShellOnly(
13693 Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs");
13694 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13695 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13696 "setSatelliteAccessControlOverlayConfigs");
13697 return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset, isAllowed,
13698 s2CellFile, locationFreshDurationNanos, satelliteCountryCodes);
13699 }
13700
13701 /**
Hakjun Choibc6ce992023-11-07 16:04:33 +000013702 * This API can be used by only CTS to override the cached value for the device overlay config
13703 * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether
13704 * outgoing satellite datagrams should be sent to modem in demo mode.
13705 *
13706 * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to
13707 * satellite modem or not.
13708 *
13709 * @return {@code true} if the operation is successful, {@code false} otherwise.
13710 */
13711 public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) {
13712 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
13713 Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is "
13714 + "disabled");
13715 return false;
13716 }
13717 Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode");
13718 TelephonyPermissions.enforceShellOnly(
13719 Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode");
13720 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13721 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13722 "setShouldSendDatagramToModemInDemoMode");
13723 return mSatelliteController.setShouldSendDatagramToModemInDemoMode(
13724 shouldSendToModemInDemoMode);
13725 }
13726
13727 /**
Gil Cukierman06403e12023-11-29 16:33:03 +000013728 * Enable or disable notifications sent for cellular identifier disclosure events.
13729 *
13730 * Disclosure events are defined as instances where a device has sent a cellular identifier
13731 * on the Non-access stratum (NAS) before a security context is established. As a result the
13732 * identifier is sent in the clear, which has privacy implications for the user.
13733 *
13734 * @param enable if notifications about disclosure events should be enabled
13735 * @throws SecurityException if the caller does not have the required privileges
13736 * @throws UnsupportedOperationException if the modem does not support this feature.
13737 */
13738 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000013739 public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) {
Gil Cukierman06403e12023-11-29 16:33:03 +000013740 enforceModifyPermission();
13741 checkForIdentifierDisclosureNotificationSupport();
13742
13743 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
13744 editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable);
13745 editor.apply();
13746
13747 // Each phone instance is responsible for updating its respective modem immediately
13748 // after we've made a preference change.
13749 for (Phone phone : PhoneFactory.getPhones()) {
13750 phone.handleIdentifierDisclosureNotificationPreferenceChange();
13751 }
13752 }
13753
13754 /**
13755 * Get whether or not cellular identifier disclosure notifications are enabled.
13756 *
13757 * @throws SecurityException if the caller does not have the required privileges
13758 * @throws UnsupportedOperationException if the modem does not support this feature.
13759 */
13760 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000013761 public boolean isCellularIdentifierDisclosureNotificationsEnabled() {
Gil Cukierman06403e12023-11-29 16:33:03 +000013762 enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled");
13763 checkForIdentifierDisclosureNotificationSupport();
13764 return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled();
13765 }
13766
13767 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000013768 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
13769 *
13770 * <p>This method behaves in one of the following ways:
13771 * <ul>
13772 * <li>return true : if the calling package has the appop permission {@link
13773 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
13774 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
13775 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
13776 * Owner device identifier access check, or the calling package has carrier privileges</>
13777 * <li>throw SecurityException: if the caller does not meet any of the requirements.
13778 * </ul>
13779 */
13780 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
13781 String callingPackage, @Nullable String callingFeatureId, String message) {
13782 for (Phone phone : PhoneFactory.getPhones()) {
13783 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
13784 phone.getSubId(), callingPackage, callingFeatureId, message)) {
13785 return true;
13786 }
13787 }
13788 return false;
13789 }
arunvoddud7401012022-12-15 16:08:12 +000013790
13791 /**
Jack Yufa8ed012023-02-11 15:42:28 -080013792 * @return The subscription manager service instance.
13793 */
13794 public SubscriptionManagerService getSubscriptionManagerService() {
13795 return SubscriptionManagerService.getInstance();
13796 }
13797
13798 /**
arunvoddud7401012022-12-15 16:08:12 +000013799 * Class binds the consumer[callback] and carrierId.
13800 */
13801 private static class CallerCallbackInfo {
13802 private final Consumer<Integer> mConsumer;
13803 private final int mCarrierId;
13804
13805 public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) {
13806 mConsumer = consumer;
13807 mCarrierId = carrierId;
13808 }
13809
13810 public Consumer<Integer> getConsumer() {
13811 return mConsumer;
13812 }
13813
13814 public int getCarrierId() {
13815 return mCarrierId;
13816 }
13817 }
joonhunshin4ac60942023-11-15 15:23:39 +000013818
13819 /*
13820 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
13821 * But the context that is passed in is unused if the phone app is already alive.
13822 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
13823 */
13824 @VisibleForTesting
13825 public void setPackageManager(PackageManager packageManager) {
13826 mPackageManager = packageManager;
13827 }
13828
13829 /*
13830 * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags.
13831 * But the FeatureFlags that is passed in is unused if the phone app is already alive.
13832 * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test.
13833 */
13834 @VisibleForTesting
13835 public void setFeatureFlags(FeatureFlags featureFlags) {
13836 mFeatureFlags = featureFlags;
13837 }
13838
13839 /**
13840 * Make sure the device has required telephony feature
13841 *
13842 * @throws UnsupportedOperationException if the device does not have required telephony feature
13843 */
13844 private void enforceTelephonyFeatureWithException(@Nullable String callingPackage,
13845 @NonNull String telephonyFeature, @NonNull String methodName) {
13846 if (callingPackage == null || mPackageManager == null) {
13847 return;
13848 }
13849
13850 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
13851 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage,
13852 Binder.getCallingUserHandle())) {
13853 return;
13854 }
13855
13856 if (!mPackageManager.hasSystemFeature(telephonyFeature)) {
13857 throw new UnsupportedOperationException(
13858 methodName + " is unsupported without " + telephonyFeature);
13859 }
13860 }
Jack Yufa8ed012023-02-11 15:42:28 -080013861}