blob: d8d8450aa84be0e5c3ea1b6ab2eb3bff6aabb853 [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;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700251import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700252import com.android.phone.slice.SlicePurchaseController;
arunvoddud7401012022-12-15 16:08:12 +0000253import com.android.phone.utils.CarrierAllowListInfo;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700254import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800255import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700256import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700257import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800258import com.android.services.telephony.TelecomAccountRegistry;
259import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800260import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800261
Hall Liu82694d52020-12-11 18:22:04 -0800262import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700263import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800264import java.io.IOException;
265import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700266import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700267import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800268import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000269import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800270import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800271import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800272import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800273import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100274import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800275import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700276import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800277import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800278import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700279import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800280import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800281import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800282import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700283
284/**
285 * Implementation of the ITelephony interface.
286 */
Santos Cordon117fee72014-05-16 17:56:12 -0700287public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700288 private static final String LOG_TAG = "PhoneInterfaceManager";
289 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
290 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800291 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700292
293 // Message codes used with mMainThreadHandler
294 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700295 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
296 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700297 private static final int CMD_OPEN_CHANNEL = 9;
298 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
299 private static final int CMD_CLOSE_CHANNEL = 11;
300 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800301 private static final int CMD_NV_READ_ITEM = 13;
302 private static final int EVENT_NV_READ_ITEM_DONE = 14;
303 private static final int CMD_NV_WRITE_ITEM = 15;
304 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
305 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
306 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700307 private static final int CMD_RESET_MODEM_CONFIG = 19;
308 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800309 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
310 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800311 private static final int CMD_SEND_ENVELOPE = 25;
312 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700313 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
314 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
315 private static final int CMD_EXCHANGE_SIM_IO = 31;
316 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800317 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
318 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700319 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
320 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700321 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
322 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700323 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
324 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
325 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
326 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700327 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
328 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
329 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
330 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700331 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800332 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
333 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000334 private static final int CMD_SWITCH_SLOTS = 50;
335 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700336 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
337 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
338 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
339 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
340 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
341 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
342 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
343 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700344 private static final int CMD_GET_ALL_CELL_INFO = 60;
345 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
346 private static final int CMD_GET_CELL_LOCATION = 62;
347 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700348 private static final int CMD_MODEM_REBOOT = 64;
349 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700350 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
351 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800352 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
353 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700354 private static final int CMD_GET_MODEM_STATUS = 70;
355 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700356 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
357 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700358 private static final int CMD_ERASE_MODEM_CONFIG = 74;
359 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800360 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
361 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
362 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
363 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800364 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
365 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800366 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800367 private static final int CMD_GET_CALL_FORWARDING = 83;
368 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
369 private static final int CMD_SET_CALL_FORWARDING = 85;
370 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
371 private static final int CMD_GET_CALL_WAITING = 87;
372 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
373 private static final int CMD_SET_CALL_WAITING = 89;
374 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700375 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
376 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
377 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
378 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700379 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
380 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800381 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
382 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800383 private static final int CMD_SET_DATA_THROTTLING = 99;
384 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800385 private static final int CMD_SET_SIM_POWER = 101;
386 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800387 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
388 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
389 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
390 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800391 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
392 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000393 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800394 private static final int CMD_GET_SLICING_CONFIG = 110;
395 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800396 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700397 private static final int CMD_ENABLE_VONR = 113;
398 private static final int EVENT_ENABLE_VONR_DONE = 114;
399 private static final int CMD_IS_VONR_ENABLED = 115;
400 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700401 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
402 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000403
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800404 // Parameters of select command.
405 private static final int SELECT_COMMAND = 0xA4;
406 private static final int SELECT_P1 = 0x04;
407 private static final int SELECT_P2 = 0;
408 private static final int SELECT_P3 = 0x10;
409
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000410 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
411 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
Gil Cukierman06403e12023-11-29 16:33:03 +0000412 // Cellular identifier disclosure transparency was added in IRadioNetwork 2.2
413 private static final int MIN_IDENTIFIER_DISCLOSURE_VERSION = 202;
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000414
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700415 /** The singleton instance. */
416 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800417 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700418
Sarah Chin4beb2b72023-02-14 14:47:54 -0800419 private final PhoneGlobals mApp;
joonhunshin4ac60942023-11-15 15:23:39 +0000420 private FeatureFlags mFeatureFlags;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800421 private final CallManager mCM;
422 private final ImsResolver mImsResolver;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000423
424 private final SatelliteController mSatelliteController;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800425 private final SatelliteAccessController mSatelliteAccessController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800426 private final UserManager mUserManager;
427 private final AppOpsManager mAppOps;
428 private final MainThreadHandler mMainThreadHandler;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800429 private final SharedPreferences mTelephonySharedPreferences;
430 private final PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800431 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
joonhunshin4ac60942023-11-15 15:23:39 +0000432 private PackageManager mPackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700433
Peter Wangdafb9ac2020-01-15 14:13:38 -0800434 /** User Activity */
Sarah Chin4beb2b72023-02-14 14:47:54 -0800435 private final AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800436 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800437 private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800438
Derek Tan97ebb422014-09-05 16:55:38 -0700439 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
440 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800441 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800442 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700443
Michelecea4cf22018-12-21 15:00:11 -0800444 // String to store multi SIM allowed
445 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
446
Derek Tan740e1672017-06-27 14:56:27 -0700447 // The AID of ISD-R.
448 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
449
yinxub1bed742017-04-17 11:45:04 -0700450 private NetworkScanRequestTracker mNetworkScanRequestTracker;
451
David Kelly5e06a7f2018-03-12 14:10:59 +0000452 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
453 private static final int MANUFACTURER_CODE_LENGTH = 8;
454
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800455 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800456 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800457
Sarah Chin2ec39f62022-08-31 17:03:26 -0700458 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
459 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
460
Derek Tan89e89d42014-07-08 17:00:10 -0700461 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700462 * Experiment flag to enable erase modem config on reset network, default value is false
463 */
464 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
465 "reset_network_erase_modem_config_enabled";
466
Rambo Wang0f050d82021-02-12 11:43:36 -0800467 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800468
Gary Jian76280a42022-12-07 16:18:33 +0800469 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
470
sandeepjsb6c87872021-09-27 15:34:44 +0000471 /**
472 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
473 * one ICCID active at the same time.
474 * Apps should use below API signatures if targeting SDK is T and beyond.
475 *
476 * @hide
477 */
478 @ChangeId
479 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
480 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800481
Naina Nallurid63128d2019-09-17 14:10:30 -0700482 /**
Chen Xu540470b2021-12-14 17:15:47 -0800483 * Apps targeting on Android T and beyond will get exception whenever icc close channel
484 * operation fails.
485 */
486 @ChangeId
487 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
488 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
489
490 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700491 * A request object to use for transmitting data to an ICC.
492 */
493 private static final class IccAPDUArgument {
494 public int channel, cla, command, p1, p2, p3;
495 public String data;
496
497 public IccAPDUArgument(int channel, int cla, int command,
498 int p1, int p2, int p3, String data) {
499 this.channel = channel;
500 this.cla = cla;
501 this.command = command;
502 this.p1 = p1;
503 this.p2 = p2;
504 this.p3 = p3;
505 this.data = data;
506 }
507 }
508
509 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700510 * A request object to use for transmitting data to an ICC.
511 */
512 private static final class ManualNetworkSelectionArgument {
513 public OperatorInfo operatorInfo;
514 public boolean persistSelection;
515
516 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
517 this.operatorInfo = operatorInfo;
518 this.persistSelection = persistSelection;
519 }
520 }
521
Sarah Chin71b3a852022-09-28 15:54:19 -0700522 private static final class PurchasePremiumCapabilityArgument {
523 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700524 public @NonNull IIntegerConsumer callback;
525
526 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800527 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700528 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700529 this.callback = callback;
530 }
531 }
532
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700533 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700534 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
535 * request after sending. The main thread will notify the request when it is complete.
536 */
537 private static final class MainThreadRequest {
538 /** The argument to use for the request */
539 public Object argument;
540 /** The result of the request that is run on the main thread */
541 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800542 // The subscriber id that this request applies to. Defaults to
543 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
544 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700545
Nathan Harold92bed182018-10-12 18:16:49 -0700546 // In cases where subId is unavailable, the caller needs to specify the phone.
547 public Phone phone;
548
vagdeviaf9a5b92018-08-15 16:01:53 -0700549 public WorkSource workSource;
550
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700551 public MainThreadRequest(Object argument) {
552 this.argument = argument;
553 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800554
Nathan Harold92bed182018-10-12 18:16:49 -0700555 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
556 this.argument = argument;
557 if (phone != null) {
558 this.phone = phone;
559 }
560 this.workSource = workSource;
561 }
562
vagdeviaf9a5b92018-08-15 16:01:53 -0700563 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800564 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800565 if (subId != null) {
566 this.subId = subId;
567 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700568 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800569 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700570 }
571
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800572 private static final class IncomingThirdPartyCallArgs {
573 public final ComponentName component;
574 public final String callId;
575 public final String callerDisplayName;
576
577 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
578 String callerDisplayName) {
579 this.component = component;
580 this.callId = callId;
581 this.callerDisplayName = callerDisplayName;
582 }
583 }
584
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700585 /**
586 * A handler that processes messages on the main thread in the phone process. Since many
587 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
588 * inbound binder threads to the main thread in the phone process. The Binder thread
589 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
590 * on, which will be notified when the operation completes and will contain the result of the
591 * request.
592 *
593 * <p>If a MainThreadRequest object is provided in the msg.obj field,
594 * note that request.result must be set to something non-null for the calling thread to
595 * unblock.
596 */
597 private final class MainThreadHandler extends Handler {
598 @Override
599 public void handleMessage(Message msg) {
600 MainThreadRequest request;
601 Message onCompleted;
602 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000603 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700604 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800605 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700606
607 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700608 case CMD_HANDLE_USSD_REQUEST: {
609 request = (MainThreadRequest) msg.obj;
610 final Phone phone = getPhoneFromRequest(request);
611 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800612 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700613 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700614
Pengquan Menga1bb6272018-09-06 09:59:22 -0700615 if (!isUssdApiAllowed(request.subId)) {
616 // Carrier does not support use of this API, return failure.
617 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
618 UssdResponse response = new UssdResponse(ussdRequest, null);
619 Bundle returnData = new Bundle();
620 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
621 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700622
Pengquan Menga1bb6272018-09-06 09:59:22 -0700623 request.result = true;
624 notifyRequester(request);
625 return;
626 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700627
Pengquan Menga1bb6272018-09-06 09:59:22 -0700628 try {
629 request.result = phone != null
630 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
631 } catch (CallStateException cse) {
632 request.result = false;
633 }
634 // Wake up the requesting thread
635 notifyRequester(request);
636 break;
pkanwar32d516d2016-10-14 19:37:38 -0700637 }
638
Yorke Lee716f67e2015-06-17 15:39:16 -0700639 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700640 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700641 final Phone phone = getPhoneFromRequest(request);
642 request.result = phone != null ?
643 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
644 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700645 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700646 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700647 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700648 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700649
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700650 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700651 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700652 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000653 uiccPort = getUiccPortFromRequest(request);
654 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700655 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800656 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700657 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700658 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700659 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800660 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000661 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800662 iccArgument.channel, iccArgument.cla, iccArgument.command,
663 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
664 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700665 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700666 break;
667
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700668 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700669 ar = (AsyncResult) msg.obj;
670 request = (MainThreadRequest) ar.userObj;
671 if (ar.exception == null && ar.result != null) {
672 request.result = ar.result;
673 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800674 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700675 if (ar.result == null) {
676 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800677 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700678 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800679 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700680 } else {
681 loge("iccTransmitApduLogicalChannel: Unknown exception");
682 }
683 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700684 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700685 break;
686
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700687 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
688 request = (MainThreadRequest) msg.obj;
689 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000690 uiccPort = getUiccPortFromRequest(request);
691 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700692 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800693 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700694 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700695 } else {
696 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800697 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000698 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800699 iccArgument.cla, iccArgument.command, iccArgument.p1,
700 iccArgument.p2,
701 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700702 }
703 break;
704
705 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
706 ar = (AsyncResult) msg.obj;
707 request = (MainThreadRequest) ar.userObj;
708 if (ar.exception == null && ar.result != null) {
709 request.result = ar.result;
710 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800711 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700712 if (ar.result == null) {
713 loge("iccTransmitApduBasicChannel: Empty response");
714 } else if (ar.exception instanceof CommandException) {
715 loge("iccTransmitApduBasicChannel: CommandException: " +
716 ar.exception);
717 } else {
718 loge("iccTransmitApduBasicChannel: Unknown exception");
719 }
720 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700721 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700722 break;
723
724 case CMD_EXCHANGE_SIM_IO:
725 request = (MainThreadRequest) msg.obj;
726 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000727 uiccPort = getUiccPortFromRequest(request);
728 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700729 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800730 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700731 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700732 } else {
733 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
734 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000735 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700736 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
737 iccArgument.data, onCompleted);
738 }
739 break;
740
741 case EVENT_EXCHANGE_SIM_IO_DONE:
742 ar = (AsyncResult) msg.obj;
743 request = (MainThreadRequest) ar.userObj;
744 if (ar.exception == null && ar.result != null) {
745 request.result = ar.result;
746 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800747 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700748 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700749 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700750 break;
751
Derek Tan4d5e5c12014-02-04 11:54:58 -0800752 case CMD_SEND_ENVELOPE:
753 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000754 uiccPort = getUiccPortFromRequest(request);
755 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700756 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800757 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700758 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700759 } else {
760 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800761 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700762 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800763 break;
764
765 case EVENT_SEND_ENVELOPE_DONE:
766 ar = (AsyncResult) msg.obj;
767 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700768 if (ar.exception == null && ar.result != null) {
769 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800770 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800771 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700772 if (ar.result == null) {
773 loge("sendEnvelopeWithStatus: Empty response");
774 } else if (ar.exception instanceof CommandException) {
775 loge("sendEnvelopeWithStatus: CommandException: " +
776 ar.exception);
777 } else {
778 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
779 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800780 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700781 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800782 break;
783
Shishir Agrawal566b7612013-10-28 14:41:00 -0700784 case CMD_OPEN_CHANNEL:
785 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000786 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800787 IccLogicalChannelRequest openChannelRequest =
788 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000789 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700790 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800791 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800792 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700793 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700794 } else {
795 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800796 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
797 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700798 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700799 break;
800
801 case EVENT_OPEN_CHANNEL_DONE:
802 ar = (AsyncResult) msg.obj;
803 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700804 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700805 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700806 int[] result = (int[]) ar.result;
807 int channelId = result[0];
808 byte[] selectResponse = null;
809 if (result.length > 1) {
810 selectResponse = new byte[result.length - 1];
811 for (int i = 1; i < result.length; ++i) {
812 selectResponse[i - 1] = (byte) result[i];
813 }
814 }
815 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800816 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800817
818 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700819 if (uiccPort == null) {
820 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
821 } else {
822 IccLogicalChannelRequest channelRequest =
823 (IccLogicalChannelRequest) request.argument;
824 channelRequest.channel = channelId;
825 uiccPort.onLogicalChannelOpened(channelRequest);
826 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700827 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700828 if (ar.result == null) {
829 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700830 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700831 if (ar.exception != null) {
832 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
833 }
834
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700835 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700836 if (ar.exception instanceof CommandException) {
837 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800838 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700839 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700840 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700841 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700842 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700843 }
844 }
845 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800846 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700847 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700848 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700849 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700850 break;
851
852 case CMD_CLOSE_CHANNEL:
853 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000854 uiccPort = getUiccPortFromRequest(request);
855 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700856 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800857 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800858 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800859 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700860 } else {
861 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000862 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700863 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700864 break;
865
866 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800867 ar = (AsyncResult) msg.obj;
868 request = (MainThreadRequest) ar.userObj;
869 if (ar.exception == null) {
870 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800871 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700872 if (uiccPort == null) {
873 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
874 } else {
875 final int channelId = (Integer) request.argument;
876 uiccPort.onLogicalChannelClosed(channelId);
877 }
Chen Xu540470b2021-12-14 17:15:47 -0800878 } else {
879 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800880 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800881 if (ar.exception instanceof CommandException) {
882 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
883 CommandException.Error error =
884 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800885 if (error == CommandException.Error.INVALID_ARGUMENTS) {
886 // should only throw exceptions from the binder threads.
887 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800888 "iccCloseLogicalChannel: invalid argument ");
889 }
890 } else {
891 loge("iccCloseLogicalChannel: Unknown exception");
892 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800893 request.result = (exception != null) ? exception :
894 new IllegalStateException(
895 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800896 }
897 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800898 break;
899
900 case CMD_NV_READ_ITEM:
901 request = (MainThreadRequest) msg.obj;
902 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800903 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
904 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800905 break;
906
907 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700908 ar = (AsyncResult) msg.obj;
909 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800910 if (ar.exception == null && ar.result != null) {
911 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700912 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800913 request.result = "";
914 if (ar.result == null) {
915 loge("nvReadItem: Empty response");
916 } else if (ar.exception instanceof CommandException) {
917 loge("nvReadItem: CommandException: " +
918 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700919 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800920 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700921 }
922 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700923 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700924 break;
925
Jake Hambye994d462014-02-03 13:10:13 -0800926 case CMD_NV_WRITE_ITEM:
927 request = (MainThreadRequest) msg.obj;
928 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
929 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800930 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700931 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800932 break;
933
934 case EVENT_NV_WRITE_ITEM_DONE:
935 handleNullReturnEvent(msg, "nvWriteItem");
936 break;
937
938 case CMD_NV_WRITE_CDMA_PRL:
939 request = (MainThreadRequest) msg.obj;
940 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800941 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800942 break;
943
944 case EVENT_NV_WRITE_CDMA_PRL_DONE:
945 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
946 break;
947
chen xu6dac5ab2018-10-26 17:39:23 -0700948 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800949 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700950 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800951 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800952 break;
953
chen xu6dac5ab2018-10-26 17:39:23 -0700954 case EVENT_RESET_MODEM_CONFIG_DONE:
955 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800956 break;
957
Sooraj Sasindran37444802020-08-11 10:40:43 -0700958 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
959 request = (MainThreadRequest) msg.obj;
960 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
961 request);
962 Phone phone = getPhoneFromRequest(request);
963 if (phone != null) {
964 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
965 } else {
966 loge("isNRDualConnectivityEnabled: No phone object");
967 request.result = false;
968 notifyRequester(request);
969 }
970 break;
971 }
972
973 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
974 ar = (AsyncResult) msg.obj;
975 request = (MainThreadRequest) ar.userObj;
976 if (ar.exception == null && ar.result != null) {
977 request.result = ar.result;
978 } else {
979 // request.result must be set to something non-null
980 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700981 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700982 request.result = ar.result;
983 } else {
984 request.result = false;
985 }
986 if (ar.result == null) {
987 loge("isNRDualConnectivityEnabled: Empty response");
988 } else if (ar.exception instanceof CommandException) {
989 loge("isNRDualConnectivityEnabled: CommandException: "
990 + ar.exception);
991 } else {
992 loge("isNRDualConnectivityEnabled: Unknown exception");
993 }
994 }
995 notifyRequester(request);
996 break;
997
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700998 case CMD_IS_VONR_ENABLED: {
999 request = (MainThreadRequest) msg.obj;
1000 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
1001 request);
1002 Phone phone = getPhoneFromRequest(request);
1003 if (phone != null) {
1004 phone.isVoNrEnabled(onCompleted, request.workSource);
1005 } else {
1006 loge("isVoNrEnabled: No phone object");
1007 request.result = false;
1008 notifyRequester(request);
1009 }
1010 break;
1011 }
1012
1013 case EVENT_IS_VONR_ENABLED_DONE:
1014 ar = (AsyncResult) msg.obj;
1015 request = (MainThreadRequest) ar.userObj;
1016 if (ar.exception == null && ar.result != null) {
1017 request.result = ar.result;
1018 } else {
1019 // request.result must be set to something non-null
1020 // for the calling thread to unblock
1021 if (ar.result != null) {
1022 request.result = ar.result;
1023 } else {
1024 request.result = false;
1025 }
1026 if (ar.result == null) {
1027 loge("isVoNrEnabled: Empty response");
1028 } else if (ar.exception instanceof CommandException) {
1029 loge("isVoNrEnabled: CommandException: "
1030 + ar.exception);
1031 } else {
1032 loge("isVoNrEnabled: Unknown exception");
1033 }
1034 }
1035 notifyRequester(request);
1036 break;
1037
Sooraj Sasindran37444802020-08-11 10:40:43 -07001038 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1039 request = (MainThreadRequest) msg.obj;
1040 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1041 Phone phone = getPhoneFromRequest(request);
1042 if (phone != null) {
1043 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1044 request.workSource);
1045 } else {
1046 loge("enableNrDualConnectivity: No phone object");
1047 request.result =
1048 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1049 notifyRequester(request);
1050 }
1051 break;
1052 }
1053
1054 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1055 ar = (AsyncResult) msg.obj;
1056 request = (MainThreadRequest) ar.userObj;
1057 if (ar.exception == null) {
1058 request.result =
1059 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1060 } else {
1061 request.result =
1062 TelephonyManager
1063 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1064 if (ar.exception instanceof CommandException) {
1065 CommandException.Error error =
1066 ((CommandException) (ar.exception)).getCommandError();
1067 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1068 request.result =
1069 TelephonyManager
1070 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001071 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1072 request.result =
1073 TelephonyManager
1074 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001075 }
1076 loge("enableNrDualConnectivity" + ": CommandException: "
1077 + ar.exception);
1078 } else {
1079 loge("enableNrDualConnectivity" + ": Unknown exception");
1080 }
1081 }
1082 notifyRequester(request);
1083 break;
1084 }
1085
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001086 case CMD_ENABLE_VONR: {
1087 request = (MainThreadRequest) msg.obj;
1088 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1089 Phone phone = getPhoneFromRequest(request);
1090 if (phone != null) {
1091 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1092 request.workSource);
1093 } else {
1094 loge("setVoNrEnabled: No phone object");
1095 request.result =
1096 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1097 notifyRequester(request);
1098 }
1099 break;
1100 }
1101
1102 case EVENT_ENABLE_VONR_DONE: {
1103 ar = (AsyncResult) msg.obj;
1104 request = (MainThreadRequest) ar.userObj;
1105 if (ar.exception == null) {
1106 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1107 } else {
1108 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1109 if (ar.exception instanceof CommandException) {
1110 CommandException.Error error =
1111 ((CommandException) (ar.exception)).getCommandError();
1112 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1113 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1114 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1115 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1116 } else {
1117 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1118 }
1119 loge("setVoNrEnabled" + ": CommandException: "
1120 + ar.exception);
1121 } else {
1122 loge("setVoNrEnabled" + ": Unknown exception");
1123 }
1124 }
1125 notifyRequester(request);
1126 break;
1127 }
1128
SongFerngWang3ef3e072020-12-21 16:41:52 +08001129 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001130 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001131 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1132 request);
1133 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001134 break;
1135
SongFerngWang3ef3e072020-12-21 16:41:52 +08001136 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001137 ar = (AsyncResult) msg.obj;
1138 request = (MainThreadRequest) ar.userObj;
1139 if (ar.exception == null && ar.result != null) {
1140 request.result = ar.result; // Integer
1141 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301142 // request.result must be set to something non-null
1143 // for the calling thread to unblock
1144 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001145 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001146 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001147 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001148 loge("getAllowedNetworkTypesBitmask: CommandException: "
1149 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001150 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001151 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001152 }
1153 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001154 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001155 break;
1156
SongFerngWang3ef3e072020-12-21 16:41:52 +08001157 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001158 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001159 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1160 request);
1161 Pair<Integer, Long> reasonWithNetworkTypes =
1162 (Pair<Integer, Long>) request.argument;
1163 getPhoneFromRequest(request).setAllowedNetworkTypes(
1164 reasonWithNetworkTypes.first,
1165 reasonWithNetworkTypes.second,
1166 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001167 break;
1168
SongFerngWang3ef3e072020-12-21 16:41:52 +08001169 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1170 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001171 break;
1172
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001173 case CMD_SET_VOICEMAIL_NUMBER:
1174 request = (MainThreadRequest) msg.obj;
1175 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1176 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001177 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1178 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001179 break;
1180
1181 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1182 handleNullReturnEvent(msg, "setVoicemailNumber");
1183 break;
1184
Stuart Scott54788802015-03-30 13:18:01 -07001185 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1186 request = (MainThreadRequest) msg.obj;
1187 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1188 request);
1189 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1190 break;
1191
1192 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1193 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1194 break;
1195
Shishir Agrawal302c8692015-06-19 13:49:39 -07001196 case CMD_PERFORM_NETWORK_SCAN:
1197 request = (MainThreadRequest) msg.obj;
1198 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1199 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1200 break;
1201
Hall Liu27d24262020-09-18 19:04:59 -07001202 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001203 request = (MainThreadRequest) msg.obj;
1204 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001205 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1206 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1207 request.argument;
1208 int callForwardingReason = args.first;
1209 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001210 break;
Hall Liu27d24262020-09-18 19:04:59 -07001211 }
1212 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001213 ar = (AsyncResult) msg.obj;
1214 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001215 TelephonyManager.CallForwardingInfoCallback callback =
1216 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1217 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001218 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001219 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001220 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1221 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1222 // Service Class is a bit mask per 3gpp 27.007. Search for
1223 // any service for voice call.
1224 if ((callForwardInfo.serviceClass
1225 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001226 callForwardingInfo = new CallForwardingInfo(
1227 callForwardInfo.status
1228 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001229 callForwardInfo.reason,
1230 callForwardInfo.number,
1231 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001232 break;
1233 }
1234 }
1235 // Didn't find a call forward info for voice call.
1236 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001237 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1238 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001239 }
Hall Liu27d24262020-09-18 19:04:59 -07001240 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001241 } else {
1242 if (ar.result == null) {
1243 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1244 }
1245 if (ar.exception != null) {
1246 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1247 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001248 int errorCode = TelephonyManager
1249 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001250 if (ar.exception instanceof CommandException) {
1251 CommandException.Error error =
1252 ((CommandException) (ar.exception)).getCommandError();
1253 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001254 errorCode = TelephonyManager
1255 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001256 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001257 errorCode = TelephonyManager
1258 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001259 }
1260 }
Hall Liu27d24262020-09-18 19:04:59 -07001261 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001262 }
Shuo Qian4a594052020-01-23 11:59:30 -08001263 break;
Hall Liu27d24262020-09-18 19:04:59 -07001264 }
Shuo Qian4a594052020-01-23 11:59:30 -08001265
Hall Liu27d24262020-09-18 19:04:59 -07001266 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001267 request = (MainThreadRequest) msg.obj;
1268 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001269 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001270 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001271 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1272 request.argument).first;
1273 request.phone.setCallForwardingOption(
1274 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001275 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001276 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001277 callForwardingInfoToSet.getReason(),
1278 callForwardingInfoToSet.getNumber(),
1279 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1280 break;
Hall Liu27d24262020-09-18 19:04:59 -07001281 }
Shuo Qian4a594052020-01-23 11:59:30 -08001282
Hall Liu27d24262020-09-18 19:04:59 -07001283 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001284 ar = (AsyncResult) msg.obj;
1285 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001286 Consumer<Integer> callback =
1287 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1288 request.argument).second;
1289 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001290 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001291 int errorCode = TelephonyManager.CallForwardingInfoCallback
1292 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001293 if (ar.exception instanceof CommandException) {
1294 CommandException.Error error =
1295 ((CommandException) (ar.exception)).getCommandError();
1296 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001297 errorCode = TelephonyManager.CallForwardingInfoCallback
1298 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001299 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001300 errorCode = TelephonyManager.CallForwardingInfoCallback
1301 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001302 }
1303 }
1304 callback.accept(errorCode);
1305 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001306 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001307 }
Shuo Qian4a594052020-01-23 11:59:30 -08001308 break;
Hall Liu27d24262020-09-18 19:04:59 -07001309 }
Shuo Qian4a594052020-01-23 11:59:30 -08001310
Hall Liu27d24262020-09-18 19:04:59 -07001311 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001312 request = (MainThreadRequest) msg.obj;
1313 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1314 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1315 break;
Hall Liu27d24262020-09-18 19:04:59 -07001316 }
Shuo Qian4a594052020-01-23 11:59:30 -08001317
Hall Liu27d24262020-09-18 19:04:59 -07001318 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001319 ar = (AsyncResult) msg.obj;
1320 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001321 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001322 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001323 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001324 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001325 // Service Class is a bit mask per 3gpp 27.007.
1326 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001327 if (callForwardResults.length > 1
1328 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001329 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001330 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001331 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1332 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001333 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001334 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001335 }
1336 } else {
1337 if (ar.result == null) {
1338 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1339 }
1340 if (ar.exception != null) {
1341 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1342 }
1343 if (ar.exception instanceof CommandException) {
1344 CommandException.Error error =
1345 ((CommandException) (ar.exception)).getCommandError();
1346 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001347 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001348 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001349 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1350 callWaitingStatus =
1351 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001352 }
1353 }
1354 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001355 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001356 break;
Hall Liu27d24262020-09-18 19:04:59 -07001357 }
Shuo Qian4a594052020-01-23 11:59:30 -08001358
Hall Liu27d24262020-09-18 19:04:59 -07001359 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001360 request = (MainThreadRequest) msg.obj;
1361 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001362 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1363 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001364 break;
Hall Liu27d24262020-09-18 19:04:59 -07001365 }
Shuo Qian4a594052020-01-23 11:59:30 -08001366
Hall Liu27d24262020-09-18 19:04:59 -07001367 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001368 ar = (AsyncResult) msg.obj;
1369 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001370 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1371 Consumer<Integer> callback =
1372 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1373 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001374 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001375 if (ar.exception instanceof CommandException) {
1376 CommandException.Error error =
1377 ((CommandException) (ar.exception)).getCommandError();
1378 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1379 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001380 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1381 callback.accept(
1382 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001383 } else {
1384 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1385 }
1386 } else {
1387 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1388 }
1389 } else {
1390 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1391 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001392 }
Shuo Qian4a594052020-01-23 11:59:30 -08001393 break;
Hall Liu27d24262020-09-18 19:04:59 -07001394 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001395 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1396 ar = (AsyncResult) msg.obj;
1397 request = (MainThreadRequest) ar.userObj;
1398 CellNetworkScanResult cellScanResult;
1399 if (ar.exception == null && ar.result != null) {
1400 cellScanResult = new CellNetworkScanResult(
1401 CellNetworkScanResult.STATUS_SUCCESS,
1402 (List<OperatorInfo>) ar.result);
1403 } else {
1404 if (ar.result == null) {
1405 loge("getCellNetworkScanResults: Empty response");
1406 }
1407 if (ar.exception != null) {
1408 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1409 }
1410 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1411 if (ar.exception instanceof CommandException) {
1412 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001413 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001414 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1415 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1416 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1417 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1418 }
1419 }
1420 cellScanResult = new CellNetworkScanResult(errorCode, null);
1421 }
1422 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001423 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001424 break;
1425
1426 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1427 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001428 ManualNetworkSelectionArgument selArg =
1429 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001430 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1431 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001432 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1433 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001434 break;
1435
1436 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001437 ar = (AsyncResult) msg.obj;
1438 request = (MainThreadRequest) ar.userObj;
1439 if (ar.exception == null) {
1440 request.result = true;
1441 } else {
1442 request.result = false;
1443 loge("setNetworkSelectionModeManual " + ar.exception);
1444 }
1445 notifyRequester(request);
1446 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001447 break;
1448
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001449 case CMD_GET_MODEM_ACTIVITY_INFO:
1450 request = (MainThreadRequest) msg.obj;
1451 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001452 if (defaultPhone != null) {
1453 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001454 } else {
1455 ResultReceiver result = (ResultReceiver) request.argument;
1456 Bundle bundle = new Bundle();
1457 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001458 new ModemActivityInfo(0, 0, 0,
1459 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001460 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001461 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001462 break;
1463
Hall Liud0f208c2020-10-14 16:54:44 -07001464 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001465 ar = (AsyncResult) msg.obj;
1466 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001467 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001468 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001469 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001470 if (mLastModemActivityInfo == null) {
1471 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1472 mLastModemActivitySpecificInfo[0] =
1473 new ActivityStatsTechSpecificInfo(
1474 0,
1475 0,
1476 new int[ModemActivityInfo.getNumTxPowerLevels()],
1477 0);
1478 mLastModemActivityInfo =
1479 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1480 }
1481
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001482 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001483 // Update the last modem activity info and the result of the request.
1484 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1485 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001486 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001487 } else {
1488 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001489 }
Kai Shi917fdc62022-11-28 14:01:02 -08001490 // This is needed to decouple ret from mLastModemActivityInfo
1491 // We don't want to return mLastModemActivityInfo which is updated
1492 // inside mergeModemActivityInfo()
1493 ret = new ModemActivityInfo(
1494 mLastModemActivityInfo.getTimestampMillis(),
1495 mLastModemActivityInfo.getSleepTimeMillis(),
1496 mLastModemActivityInfo.getIdleTimeMillis(),
1497 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001498
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001499 } else {
1500 if (ar.result == null) {
1501 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001502 error = TelephonyManager.ModemActivityInfoException
1503 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001504 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001505 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001506 error = TelephonyManager.ModemActivityInfoException
1507 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001508 } else {
1509 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001510 error = TelephonyManager.ModemActivityInfoException
1511 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001512 }
1513 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001514 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001515 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001516 bundle.putParcelable(
1517 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001518 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001519 } else {
1520 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1521 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001522 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001523 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001524 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001525 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001526
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001527 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001528 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001529 CarrierRestrictionRules argument =
1530 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001531 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001532 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001533 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001534 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001535
1536 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1537 ar = (AsyncResult) msg.obj;
1538 request = (MainThreadRequest) ar.userObj;
1539 if (ar.exception == null && ar.result != null) {
1540 request.result = ar.result;
1541 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001542 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1543 if (ar.exception instanceof CommandException) {
1544 loge("setAllowedCarriers: CommandException: " + ar.exception);
1545 CommandException.Error error =
1546 ((CommandException) (ar.exception)).getCommandError();
1547 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1548 request.result =
1549 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1550 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001551 } else {
1552 loge("setAllowedCarriers: Unknown exception");
1553 }
1554 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001555 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001556 break;
1557
1558 case CMD_GET_ALLOWED_CARRIERS:
1559 request = (MainThreadRequest) msg.obj;
1560 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001561 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001562 break;
1563
1564 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1565 ar = (AsyncResult) msg.obj;
1566 request = (MainThreadRequest) ar.userObj;
1567 if (ar.exception == null && ar.result != null) {
1568 request.result = ar.result;
1569 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001570 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001571 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001572 if (ar.result == null) {
1573 loge("getAllowedCarriers: Empty response");
1574 } else if (ar.exception instanceof CommandException) {
1575 loge("getAllowedCarriers: CommandException: " +
1576 ar.exception);
1577 } else {
1578 loge("getAllowedCarriers: Unknown exception");
1579 }
1580 }
arunvoddud7401012022-12-15 16:08:12 +00001581 if (request.argument != null) {
1582 // This is for the implementation of carrierRestrictionStatus.
1583 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1584 Consumer<Integer> callback = callbackInfo.getConsumer();
1585 int callerCarrierId = callbackInfo.getCarrierId();
1586 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1587 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1588 CarrierRestrictionRules carrierRestrictionRules =
1589 (CarrierRestrictionRules) ar.result;
1590 int carrierId = -1;
1591 try {
1592 CarrierIdentifier carrierIdentifier =
1593 carrierRestrictionRules.getAllowedCarriers().get(0);
1594 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1595 carrierIdentifier);
1596 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1597 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1598 }
1599 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
1600 if (carrierId != -1 && callerCarrierId == carrierId && lockStatus
1601 == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001602 lockStatus = TelephonyManager
1603 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001604 }
1605 } else {
1606 Rlog.e(LOG_TAG,
1607 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1608 }
1609 callback.accept(lockStatus);
1610 } else {
1611 // This is for the implementation of getAllowedCarriers.
1612 notifyRequester(request);
1613 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001614 break;
1615
Nathan Haroldb3014052017-01-25 15:57:32 -08001616 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1617 ar = (AsyncResult) msg.obj;
1618 request = (MainThreadRequest) ar.userObj;
1619 if (ar.exception == null && ar.result != null) {
1620 request.result = ar.result;
1621 } else {
1622 request.result = new IllegalArgumentException(
1623 "Failed to retrieve Forbidden Plmns");
1624 if (ar.result == null) {
1625 loge("getForbiddenPlmns: Empty response");
1626 } else {
1627 loge("getForbiddenPlmns: Unknown exception");
1628 }
1629 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001630 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001631 break;
1632
1633 case CMD_GET_FORBIDDEN_PLMNS:
1634 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001635 uiccPort = getUiccPortFromRequest(request);
1636 if (uiccPort == null) {
1637 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001638 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001639 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001640 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001641 break;
1642 }
1643 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001644 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001645 if (uiccApp == null) {
1646 loge("getForbiddenPlmns() no app with specified type -- "
1647 + appType);
1648 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001649 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001650 break;
1651 } else {
1652 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1653 + " specified type -- " + appType);
1654 }
1655 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1656 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001657 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001658 break;
1659
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001660 case CMD_SWITCH_SLOTS:
1661 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001662 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001663 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001664 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001665 break;
1666
1667 case EVENT_SWITCH_SLOTS_DONE:
1668 ar = (AsyncResult) msg.obj;
1669 request = (MainThreadRequest) ar.userObj;
1670 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001671 notifyRequester(request);
1672 break;
1673 case CMD_GET_NETWORK_SELECTION_MODE:
1674 request = (MainThreadRequest) msg.obj;
1675 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1676 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1677 break;
1678
1679 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1680 ar = (AsyncResult) msg.obj;
1681 request = (MainThreadRequest) ar.userObj;
1682 if (ar.exception != null) {
1683 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1684 } else {
1685 int mode = ((int[]) ar.result)[0];
1686 if (mode == 0) {
1687 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1688 } else {
1689 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1690 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001691 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001692 notifyRequester(request);
1693 break;
1694 case CMD_GET_CDMA_ROAMING_MODE:
1695 request = (MainThreadRequest) msg.obj;
1696 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1697 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1698 break;
1699 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1700 ar = (AsyncResult) msg.obj;
1701 request = (MainThreadRequest) ar.userObj;
1702 if (ar.exception != null) {
1703 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1704 } else {
1705 request.result = ((int[]) ar.result)[0];
1706 }
1707 notifyRequester(request);
1708 break;
1709 case CMD_SET_CDMA_ROAMING_MODE:
1710 request = (MainThreadRequest) msg.obj;
1711 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1712 int mode = (int) request.argument;
1713 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1714 break;
1715 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1716 ar = (AsyncResult) msg.obj;
1717 request = (MainThreadRequest) ar.userObj;
1718 request.result = ar.exception == null;
1719 notifyRequester(request);
1720 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001721 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1722 request = (MainThreadRequest) msg.obj;
1723 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1724 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1725 break;
1726 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1727 ar = (AsyncResult) msg.obj;
1728 request = (MainThreadRequest) ar.userObj;
1729 if (ar.exception != null) {
1730 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1731 } else {
1732 request.result = ((int[]) ar.result)[0];
1733 }
1734 notifyRequester(request);
1735 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001736 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1737 request = (MainThreadRequest) msg.obj;
1738 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1739 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001740 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1741 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001742 break;
1743 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1744 ar = (AsyncResult) msg.obj;
1745 request = (MainThreadRequest) ar.userObj;
1746 request.result = ar.exception == null;
1747 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001748 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001749 case CMD_GET_ALL_CELL_INFO:
1750 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001751 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001752 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001753 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001754 case EVENT_GET_ALL_CELL_INFO_DONE:
1755 ar = (AsyncResult) msg.obj;
1756 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001757 // If a timeout occurs, the response will be null
1758 request.result = (ar.exception == null && ar.result != null)
1759 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001760 synchronized (request) {
1761 request.notifyAll();
1762 }
1763 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001764 case CMD_REQUEST_CELL_INFO_UPDATE:
1765 request = (MainThreadRequest) msg.obj;
1766 request.phone.requestCellInfoUpdate(request.workSource,
1767 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1768 break;
1769 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1770 ar = (AsyncResult) msg.obj;
1771 request = (MainThreadRequest) ar.userObj;
1772 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1773 try {
1774 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001775 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001776 cb.onError(
1777 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1778 ar.exception.getClass().getName(),
1779 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001780 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001781 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001782 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001783 } else {
1784 // use the result as returned
1785 cb.onCellInfo((List<CellInfo>) ar.result);
1786 }
1787 } catch (RemoteException re) {
1788 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1789 }
1790 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001791 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001792 request = (MainThreadRequest) msg.obj;
1793 WorkSource ws = (WorkSource) request.argument;
1794 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001795 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001796 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001797 }
1798 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001799 ar = (AsyncResult) msg.obj;
1800 request = (MainThreadRequest) ar.userObj;
1801 if (ar.exception == null) {
1802 request.result = ar.result;
1803 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001804 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001805 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001806 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001807 }
1808
1809 synchronized (request) {
1810 request.notifyAll();
1811 }
1812 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001813 }
chen xu6dac5ab2018-10-26 17:39:23 -07001814 case CMD_MODEM_REBOOT:
1815 request = (MainThreadRequest) msg.obj;
1816 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001817 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001818 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001819 case EVENT_CMD_MODEM_REBOOT_DONE:
1820 handleNullReturnEvent(msg, "rebootModem");
1821 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001822 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001823 request = (MainThreadRequest) msg.obj;
1824 boolean enable = (boolean) request.argument;
1825 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001826 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001827 PhoneConfigurationManager.getInstance()
1828 .enablePhone(request.phone, enable, onCompleted);
1829 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001830 }
Michele Berionne5e411512020-11-13 02:36:59 +00001831 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001832 ar = (AsyncResult) msg.obj;
1833 request = (MainThreadRequest) ar.userObj;
1834 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001835 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001836 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001837 if ((boolean) request.result) {
1838 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1839 updateModemStateMetrics();
1840 } else {
1841 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1842 + ar.exception);
1843 }
1844 notifyRequester(request);
1845 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001846 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001847 case CMD_GET_MODEM_STATUS:
1848 request = (MainThreadRequest) msg.obj;
1849 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1850 PhoneConfigurationManager.getInstance()
1851 .getPhoneStatusFromModem(request.phone, onCompleted);
1852 break;
1853 case EVENT_GET_MODEM_STATUS_DONE:
1854 ar = (AsyncResult) msg.obj;
1855 request = (MainThreadRequest) ar.userObj;
1856 int id = request.phone.getPhoneId();
1857 if (ar.exception == null && ar.result != null) {
1858 request.result = ar.result;
1859 //update the cache as modem status has changed
1860 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1861 (boolean) request.result);
1862 } else {
1863 // Return true if modem status cannot be retrieved. For most cases,
1864 // modem status is on. And for older version modems, GET_MODEM_STATUS
1865 // and disable modem are not supported. Modem is always on.
1866 // TODO: this should be fixed in R to support a third
1867 // status UNKNOWN b/131631629
1868 request.result = true;
1869 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1870 + ar.exception);
1871 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001872 notifyRequester(request);
1873 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001874 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1875 request = (MainThreadRequest) msg.obj;
1876 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1877 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1878 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1879 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1880 break;
1881 }
1882 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1883 ar = (AsyncResult) msg.obj;
1884 request = (MainThreadRequest) ar.userObj;
1885 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1886 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1887 args.second.accept(ar.exception == null);
1888 notifyRequester(request);
1889 break;
1890 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001891 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1892 request = (MainThreadRequest) msg.obj;
1893 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1894 Phone phone = getPhoneFromRequest(request);
1895 if (phone != null) {
1896 phone.getSystemSelectionChannels(onCompleted);
1897 } else {
1898 loge("getSystemSelectionChannels: No phone object");
1899 request.result = new ArrayList<RadioAccessSpecifier>();
1900 notifyRequester(request);
1901 }
1902 break;
1903 }
1904 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1905 ar = (AsyncResult) msg.obj;
1906 request = (MainThreadRequest) ar.userObj;
1907 if (ar.exception == null && ar.result != null) {
1908 request.result = ar.result;
1909 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001910 request.result = new IllegalStateException(
1911 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001912 if (ar.result == null) {
1913 loge("getSystemSelectionChannels: Empty response");
1914 } else {
1915 loge("getSystemSelectionChannels: Unknown exception");
1916 }
1917 }
1918 notifyRequester(request);
1919 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001920 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1921 ar = (AsyncResult) msg.obj;
1922 request = (MainThreadRequest) ar.userObj;
1923 if (ar.exception == null && ar.result != null) {
1924 request.result = ar.result;
1925 } else {
1926 request.result = -1;
1927 loge("Failed to set Forbidden Plmns");
1928 if (ar.result == null) {
1929 loge("setForbidenPlmns: Empty response");
1930 } else if (ar.exception != null) {
1931 loge("setForbiddenPlmns: Exception: " + ar.exception);
1932 request.result = -1;
1933 } else {
1934 loge("setForbiddenPlmns: Unknown exception");
1935 }
1936 }
1937 notifyRequester(request);
1938 break;
1939 case CMD_SET_FORBIDDEN_PLMNS:
1940 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001941 uiccPort = getUiccPortFromRequest(request);
1942 if (uiccPort == null) {
1943 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001944 request.result = -1;
1945 notifyRequester(request);
1946 break;
1947 }
1948 Pair<Integer, List<String>> setFplmnsArgs =
1949 (Pair<Integer, List<String>>) request.argument;
1950 appType = setFplmnsArgs.first;
1951 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001952 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001953 if (uiccApp == null) {
1954 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1955 request.result = -1;
1956 loge("Failed to get UICC App");
1957 notifyRequester(request);
1958 } else {
1959 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1960 ((SIMRecords) uiccApp.getIccRecords())
1961 .setForbiddenPlmns(onCompleted, fplmns);
1962 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001963 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001964 case CMD_ERASE_MODEM_CONFIG:
1965 request = (MainThreadRequest) msg.obj;
1966 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1967 defaultPhone.eraseModemConfig(onCompleted);
1968 break;
1969 case EVENT_ERASE_MODEM_CONFIG_DONE:
1970 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001971 break;
zoey chene02881a2019-12-30 16:11:23 +08001972
Kai Shif70f46f2021-03-03 13:59:46 -08001973 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1974 request = (MainThreadRequest) msg.obj;
1975 request.result = defaultPhone.eraseDataInSharedPreferences();
1976 notifyRequester(request);
1977 break;
1978
zoey chene02881a2019-12-30 16:11:23 +08001979 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1980 request = (MainThreadRequest) msg.obj;
1981 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1982 Pair<String, String> changed = (Pair<String, String>) request.argument;
1983 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1984 changed.first, changed.second, onCompleted);
1985 break;
1986 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1987 ar = (AsyncResult) msg.obj;
1988 request = (MainThreadRequest) ar.userObj;
1989 if (ar.exception == null) {
1990 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001991 // If the operation is successful, update the PIN storage
1992 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1993 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001994 UiccController.getInstance().getPinStorage()
1995 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001996 } else {
1997 request.result = msg.arg1;
1998 }
1999 notifyRequester(request);
2000 break;
2001
Michele Berionne5e411512020-11-13 02:36:59 +00002002 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08002003 request = (MainThreadRequest) msg.obj;
2004 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
2005 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2006 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2007 enabled.first, enabled.second, onCompleted);
2008 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002009 }
zoey chene02881a2019-12-30 16:11:23 +08002010 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2011 ar = (AsyncResult) msg.obj;
2012 request = (MainThreadRequest) ar.userObj;
2013 if (ar.exception == null) {
2014 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002015 // If the operation is successful, update the PIN storage
2016 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2017 int phoneId = getPhoneFromRequest(request).getPhoneId();
2018 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002019 UiccController.getInstance().getPinStorage()
2020 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002021 } else {
2022 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2023 }
zoey chene02881a2019-12-30 16:11:23 +08002024 } else {
2025 request.result = msg.arg1;
2026 }
Michele Berionne5e411512020-11-13 02:36:59 +00002027
2028
zoey chene02881a2019-12-30 16:11:23 +08002029 notifyRequester(request);
2030 break;
2031
Peter Wangdafb9ac2020-01-15 14:13:38 -08002032 case MSG_NOTIFY_USER_ACTIVITY:
2033 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002034 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002035 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2036 getDefaultPhone().getContext().sendBroadcastAsUser(
2037 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2038 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002039
2040 case CMD_SET_DATA_THROTTLING: {
2041 request = (MainThreadRequest) msg.obj;
2042 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2043 DataThrottlingRequest dataThrottlingRequest =
2044 (DataThrottlingRequest) request.argument;
2045 Phone phone = getPhoneFromRequest(request);
2046 if (phone != null) {
2047 phone.setDataThrottling(onCompleted,
2048 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2049 dataThrottlingRequest.getCompletionDurationMillis());
2050 } else {
2051 loge("setDataThrottling: No phone object");
2052 request.result =
2053 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2054 notifyRequester(request);
2055 }
2056
2057 break;
2058 }
2059 case EVENT_SET_DATA_THROTTLING_DONE:
2060 ar = (AsyncResult) msg.obj;
2061 request = (MainThreadRequest) ar.userObj;
2062
2063 if (ar.exception == null) {
2064 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2065 } else if (ar.exception instanceof CommandException) {
2066 loge("setDataThrottling: CommandException: " + ar.exception);
2067 CommandException.Error error =
2068 ((CommandException) (ar.exception)).getCommandError();
2069
2070 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2071 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002072 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002073 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2074 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002075 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2076 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002077 } else {
2078 request.result =
2079 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2080 }
2081 } else {
2082 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2083 }
2084 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2085 notifyRequester(request);
2086 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002087
2088 case CMD_SET_SIM_POWER: {
2089 request = (MainThreadRequest) msg.obj;
2090 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2091 request = (MainThreadRequest) msg.obj;
2092 int stateToSet =
2093 ((Pair<Integer, IIntegerConsumer>)
2094 request.argument).first;
2095 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2096 break;
2097 }
2098 case EVENT_SET_SIM_POWER_DONE: {
2099 ar = (AsyncResult) msg.obj;
2100 request = (MainThreadRequest) ar.userObj;
2101 IIntegerConsumer callback =
2102 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2103 if (ar.exception != null) {
2104 loge("setSimPower exception: " + ar.exception);
2105 int errorCode = TelephonyManager.CallForwardingInfoCallback
2106 .RESULT_ERROR_UNKNOWN;
2107 if (ar.exception instanceof CommandException) {
2108 CommandException.Error error =
2109 ((CommandException) (ar.exception)).getCommandError();
2110 if (error == CommandException.Error.SIM_ERR) {
2111 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2112 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2113 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2114 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2115 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2116 } else {
2117 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2118 }
2119 }
2120 try {
2121 callback.accept(errorCode);
2122 } catch (RemoteException e) {
2123 // Ignore if the remote process is no longer available to call back.
2124 Log.w(LOG_TAG, "setSimPower: callback not available.");
2125 }
2126 } else {
2127 try {
2128 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2129 } catch (RemoteException e) {
2130 // Ignore if the remote process is no longer available to call back.
2131 Log.w(LOG_TAG, "setSimPower: callback not available.");
2132 }
2133 }
2134 break;
2135 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002136 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2137 request = (MainThreadRequest) msg.obj;
2138
2139 final Phone phone = getPhoneFromRequest(request);
2140 if (phone == null || phone.getServiceStateTracker() == null) {
2141 request.result = new IllegalStateException("Phone or SST is null");
2142 notifyRequester(request);
2143 break;
2144 }
2145
2146 Pair<Integer, SignalStrengthUpdateRequest> pair =
2147 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2148 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2149 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002150 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002151 request.subId, pair.first /*callingUid*/,
2152 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002153 break;
2154 }
2155 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2156 ar = (AsyncResult) msg.obj;
2157 request = (MainThreadRequest) ar.userObj;
2158 // request.result will be the exception of ar if present, true otherwise.
2159 // Be cautious not to leave result null which will wait() forever
2160 request.result = ar.exception != null ? ar.exception : true;
2161 notifyRequester(request);
2162 break;
2163 }
2164 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2165 request = (MainThreadRequest) msg.obj;
2166
2167 Phone phone = getPhoneFromRequest(request);
2168 if (phone == null || phone.getServiceStateTracker() == null) {
2169 request.result = new IllegalStateException("Phone or SST is null");
2170 notifyRequester(request);
2171 break;
2172 }
2173
2174 Pair<Integer, SignalStrengthUpdateRequest> pair =
2175 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2176 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2177 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002178 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002179 request.subId, pair.first /*callingUid*/,
2180 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002181 break;
2182 }
2183 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2184 ar = (AsyncResult) msg.obj;
2185 request = (MainThreadRequest) ar.userObj;
2186 request.result = ar.exception != null ? ar.exception : true;
2187 notifyRequester(request);
2188 break;
2189 }
Jordan Liu109698e2020-11-24 14:50:34 -08002190
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002191 case CMD_GET_SLICING_CONFIG: {
2192 request = (MainThreadRequest) msg.obj;
2193 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2194 request.phone.getSlicingConfig(onCompleted);
2195 break;
2196 }
2197 case EVENT_GET_SLICING_CONFIG_DONE: {
2198 ar = (AsyncResult) msg.obj;
2199 request = (MainThreadRequest) ar.userObj;
2200 ResultReceiver result = (ResultReceiver) request.argument;
2201
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002202 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002203 Bundle bundle = new Bundle();
2204 int resultCode = 0;
2205 if (ar.exception != null) {
2206 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2207 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002208 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002209 } else if (ar.result == null) {
2210 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002211 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002212 } else {
2213 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002214 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2215 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002216 }
2217
2218 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002219 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002220 }
2221 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2222 result.send(resultCode, bundle);
2223 notifyRequester(request);
2224 break;
2225 }
2226
Sarah Chin71b3a852022-09-28 15:54:19 -07002227 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002228 request = (MainThreadRequest) msg.obj;
2229 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002230 PurchasePremiumCapabilityArgument arg =
2231 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chincc5446f2023-10-23 17:57:19 -07002232 SlicePurchaseController.getInstance(request.phone, mFeatureFlags)
2233 .purchasePremiumCapability(arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002234 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002235 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002236
Sarah Chin71b3a852022-09-28 15:54:19 -07002237 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002238 ar = (AsyncResult) msg.obj;
2239 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002240 PurchasePremiumCapabilityArgument arg =
2241 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002242 try {
2243 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002244 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002245 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002246 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chinff8b1802023-04-11 14:22:14 -07002247 + ", result="
Sarah Chin2ec39f62022-08-31 17:03:26 -07002248 + TelephonyManager.convertPurchaseResultToString(result));
2249 } catch (RemoteException e) {
2250 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002251 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002252 + " failed: " + e;
2253 if (DBG) log(logStr);
2254 AnomalyReporter.reportAnomaly(
2255 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2256 }
2257 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002258 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002259
Michele Berionne5e411512020-11-13 02:36:59 +00002260 case CMD_PREPARE_UNATTENDED_REBOOT:
2261 request = (MainThreadRequest) msg.obj;
2262 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002263 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002264 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002265 notifyRequester(request);
2266 break;
2267
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002268 default:
2269 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2270 break;
2271 }
2272 }
Jake Hambye994d462014-02-03 13:10:13 -08002273
Pengquan Menga1bb6272018-09-06 09:59:22 -07002274 private void notifyRequester(MainThreadRequest request) {
2275 synchronized (request) {
2276 request.notifyAll();
2277 }
2278 }
2279
Jake Hambye994d462014-02-03 13:10:13 -08002280 private void handleNullReturnEvent(Message msg, String command) {
2281 AsyncResult ar = (AsyncResult) msg.obj;
2282 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2283 if (ar.exception == null) {
2284 request.result = true;
2285 } else {
2286 request.result = false;
2287 if (ar.exception instanceof CommandException) {
2288 loge(command + ": CommandException: " + ar.exception);
2289 } else {
2290 loge(command + ": Unknown exception");
2291 }
2292 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002293 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002294 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002295 }
2296
2297 /**
2298 * Posts the specified command to be executed on the main thread,
2299 * waits for the request to complete, and returns the result.
2300 * @see #sendRequestAsync
2301 */
2302 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002303 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2304 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002305 }
2306
2307 /**
2308 * Posts the specified command to be executed on the main thread,
2309 * waits for the request to complete, and returns the result.
2310 * @see #sendRequestAsync
2311 */
2312 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2313 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002314 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002315 }
2316
2317 /**
2318 * Posts the specified command to be executed on the main thread,
2319 * waits for the request to complete, and returns the result.
2320 * @see #sendRequestAsync
2321 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002322 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002323 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2324 }
2325
2326 /**
2327 * Posts the specified command to be executed on the main thread,
2328 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2329 * if not timeout or null otherwise.
2330 * @see #sendRequestAsync
2331 */
2332 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2333 long timeoutInMs) {
2334 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002335 }
2336
2337 /**
2338 * Posts the specified command to be executed on the main thread,
2339 * waits for the request to complete, and returns the result.
2340 * @see #sendRequestAsync
2341 */
Nathan Harold92bed182018-10-12 18:16:49 -07002342 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002343 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002344 }
2345
2346 /**
2347 * Posts the specified command to be executed on the main thread,
2348 * waits for the request to complete, and returns the result.
2349 * @see #sendRequestAsync
2350 */
2351 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002352 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2353 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002354 }
2355
2356 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002357 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2358 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2359 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002360 * @see #sendRequestAsync
2361 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002362 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2363 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002364 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2365 throw new RuntimeException("This method will deadlock if called from the main thread.");
2366 }
2367
Nathan Harold92bed182018-10-12 18:16:49 -07002368 MainThreadRequest request = null;
2369 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2370 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2371 } else if (phone != null) {
2372 request = new MainThreadRequest(argument, phone, workSource);
2373 } else {
2374 request = new MainThreadRequest(argument, subId, workSource);
2375 }
2376
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002377 Message msg = mMainThreadHandler.obtainMessage(command, request);
2378 msg.sendToTarget();
2379
Rambo Wang0f050d82021-02-12 11:43:36 -08002380
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002381 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002382 if (timeoutInMs >= 0) {
2383 // Wait for at least timeoutInMs before returning null request result
2384 long now = SystemClock.elapsedRealtime();
2385 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002386 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002387 try {
2388 request.wait(deadline - now);
2389 } catch (InterruptedException e) {
2390 // Do nothing, go back and check if request is completed or timeout
2391 } finally {
2392 now = SystemClock.elapsedRealtime();
2393 }
2394 }
2395 } else {
2396 // Wait for the request to complete
2397 while (request.result == null) {
2398 try {
2399 request.wait();
2400 } catch (InterruptedException e) {
2401 // Do nothing, go back and wait until the request is complete
2402 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002403 }
2404 }
2405 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002406 if (request.result == null) {
2407 Log.wtf(LOG_TAG,
2408 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2409 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002410 return request.result;
2411 }
2412
2413 /**
2414 * Asynchronous ("fire and forget") version of sendRequest():
2415 * Posts the specified command to be executed on the main thread, and
2416 * returns immediately.
2417 * @see #sendRequest
2418 */
2419 private void sendRequestAsync(int command) {
2420 mMainThreadHandler.sendEmptyMessage(command);
2421 }
2422
2423 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002424 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002425 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002426 */
2427 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002428 sendRequestAsync(command, argument, null, null);
2429 }
2430
2431 /**
2432 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2433 * @see {@link #sendRequest(int,Object)}
2434 */
2435 private void sendRequestAsync(
2436 int command, Object argument, Phone phone, WorkSource workSource) {
2437 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002438 Message msg = mMainThreadHandler.obtainMessage(command, request);
2439 msg.sendToTarget();
2440 }
2441
2442 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002443 * Initialize the singleton PhoneInterfaceManager instance.
2444 * This is only done once, at startup, from PhoneApp.onCreate().
2445 */
Sarah Chincc5446f2023-10-23 17:57:19 -07002446 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002447 synchronized (PhoneInterfaceManager.class) {
2448 if (sInstance == null) {
Sarah Chincc5446f2023-10-23 17:57:19 -07002449 sInstance = new PhoneInterfaceManager(app, featureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002450 } else {
2451 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2452 }
2453 return sInstance;
2454 }
2455 }
2456
2457 /** Private constructor; @see init() */
Sarah Chincc5446f2023-10-23 17:57:19 -07002458 private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002459 mApp = app;
Sarah Chincc5446f2023-10-23 17:57:19 -07002460 mFeatureFlags = featureFlags;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002461 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002462 mImsResolver = ImsResolver.getInstance();
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +00002463 mSatelliteController = SatelliteController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002464 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002465 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2466 mMainThreadHandler = new MainThreadHandler();
Sarah Chin4beb2b72023-02-14 14:47:54 -08002467 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002468 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002469 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002470 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002471 mNotifyUserActivity = new AtomicBoolean(false);
joonhunshin4ac60942023-11-15 15:23:39 +00002472 mPackageManager = app.getPackageManager();
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -08002473 mSatelliteAccessController = SatelliteAccessController.getOrCreateInstance(
2474 getDefaultPhone().getContext(), featureFlags);
Tyler Gunn64144d92022-03-17 14:16:41 -07002475 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002476 publish();
arunvoddud7401012022-12-15 16:08:12 +00002477 CarrierAllowListInfo.loadInstance(mApp);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002478 }
2479
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002480 @VisibleForTesting
2481 public SharedPreferences getSharedPreferences() {
2482 return mTelephonySharedPreferences;
2483 }
2484
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002485 /**
2486 * Get the default phone for this device.
2487 */
2488 @VisibleForTesting
2489 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002490 Phone thePhone = getPhone(getDefaultSubscription());
2491 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2492 }
2493
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002494 private void publish() {
2495 if (DBG) log("publish: " + this);
2496
Peter Wangc035ce42020-01-08 21:00:22 -08002497 TelephonyFrameworkInitializer
2498 .getTelephonyServiceManager()
2499 .getTelephonyServiceRegisterer()
2500 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002501 }
2502
Stuart Scott584921c2015-01-15 17:10:34 -08002503 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002504 if (request.phone != null) {
2505 return request.phone;
2506 } else {
2507 return getPhoneFromSubId(request.subId);
2508 }
2509 }
2510
2511 private Phone getPhoneFromSubId(int subId) {
2512 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2513 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002514 }
2515
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002516 /**
2517 * Get phone object associated with a subscription.
2518 * Return default phone if phone object associated with subscription is null
2519 * @param subId - subscriptionId
2520 * @return phone object associated with a subscription or default phone if null.
2521 */
Ling Mac28f0212023-03-24 16:07:15 -07002522 private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) {
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002523 Phone phone = getPhoneFromSubId(subId);
2524 if (phone == null) {
Ling Mac28f0212023-03-24 16:07:15 -07002525 loge("Called with invalid subId: " + subId + ". Retrying with default phone.");
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002526 phone = getDefaultPhone();
2527 }
2528 return phone;
2529 }
2530
Rambo Wange53e07d2022-05-10 13:01:13 -07002531 @Nullable
2532 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002533 Phone phone = getPhoneFromRequest(request);
2534 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002535 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002536 }
2537
Ling Mac28f0212023-03-24 16:07:15 -07002538 /**
2539 * @param subId The sub Id that associates the phone. If the device has no active SIM, passing
2540 * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <=
2541 * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}.
2542 * @return The Phone associated the sub Id
2543 */
2544 private @Nullable Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002545 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002546 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002547
Kai Shif70f46f2021-03-03 13:59:46 -08002548 private void sendEraseModemConfig(@NonNull Phone phone) {
2549 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2550 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2551 }
2552
2553 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2554 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2555 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002556 }
2557
Peter Wang44b186e2020-01-13 23:33:09 -08002558 private boolean isImsAvailableOnDevice() {
2559 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2560 if (pm == null) {
2561 // For some reason package manger is not available.. This will fail internally anyway,
2562 // so do not throw error and allow.
2563 return true;
2564 }
2565 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2566 }
2567
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002568 public void dial(String number) {
joonhunshin4ac60942023-11-15 15:23:39 +00002569 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2570 PackageManager.FEATURE_TELEPHONY_CALLING, "dial");
2571
Wink Savilleadd7cc52014-09-08 14:23:09 -07002572 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002573 }
2574
Wink Savilleb564aae2014-10-23 10:18:09 -07002575 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002576 if (DBG) log("dial: " + number);
2577 // No permission check needed here: This is just a wrapper around the
2578 // ACTION_DIAL intent, which is available to any app since it puts up
2579 // the UI before it does anything.
2580
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002581 final long identity = Binder.clearCallingIdentity();
2582 try {
2583 String url = createTelUrl(number);
2584 if (url == null) {
2585 return;
2586 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002587
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002588 // PENDING: should we just silently fail if phone is offhook or ringing?
2589 PhoneConstants.State state = mCM.getState(subId);
2590 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2591 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2592 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2593 mApp.startActivity(intent);
2594 }
2595 } finally {
2596 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002597 }
2598 }
2599
2600 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002601 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002602 }
2603
Wink Savilleb564aae2014-10-23 10:18:09 -07002604 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002605 if (DBG) log("call: " + number);
2606
2607 // This is just a wrapper around the ACTION_CALL intent, but we still
2608 // need to do a permission check since we're calling startActivity()
2609 // from the context of the phone app.
2610 enforceCallPermission();
2611
Jordan Liu1617b712019-07-10 15:06:26 -07002612 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002613 != AppOpsManager.MODE_ALLOWED) {
2614 return;
2615 }
2616
joonhunshin4ac60942023-11-15 15:23:39 +00002617 enforceTelephonyFeatureWithException(callingPackage,
2618 PackageManager.FEATURE_TELEPHONY_CALLING, "call");
2619
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002620 final long identity = Binder.clearCallingIdentity();
2621 try {
2622 String url = createTelUrl(number);
2623 if (url == null) {
2624 return;
2625 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002626
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002627 boolean isValid = false;
2628 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2629 if (slist != null) {
2630 for (SubscriptionInfo subInfoRecord : slist) {
2631 if (subInfoRecord.getSubscriptionId() == subId) {
2632 isValid = true;
2633 break;
2634 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002635 }
Wink Saville08874612014-08-31 19:19:58 -07002636 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002637 if (!isValid) {
2638 return;
2639 }
Wink Saville08874612014-08-31 19:19:58 -07002640
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002641 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2642 intent.putExtra(SUBSCRIPTION_KEY, subId);
2643 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2644 mApp.startActivity(intent);
2645 } finally {
2646 Binder.restoreCallingIdentity(identity);
2647 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002648 }
2649
Wink Savilleb564aae2014-10-23 10:18:09 -07002650 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002651 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002652 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2653 }
2654
Wink Savilleb564aae2014-10-23 10:18:09 -07002655 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002656 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, 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 int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002661 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002662
joonhunshin4ac60942023-11-15 15:23:39 +00002663 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2664 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
2665 "supplyPinReportResultForSubscriber");
2666
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002667 final long identity = Binder.clearCallingIdentity();
2668 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002669 Phone phone = getPhone(subId);
2670 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002671 checkSimPin.start();
2672 return checkSimPin.unlockSim(null, pin);
2673 } finally {
2674 Binder.restoreCallingIdentity(identity);
2675 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002676 }
2677
Wink Savilleb564aae2014-10-23 10:18:09 -07002678 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002679 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002680
joonhunshin4ac60942023-11-15 15:23:39 +00002681 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2682 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "supplyPukForSubscriber");
2683
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002684 final long identity = Binder.clearCallingIdentity();
2685 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002686 Phone phone = getPhone(subId);
2687 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002688 checkSimPuk.start();
2689 return checkSimPuk.unlockSim(puk, pin);
2690 } finally {
2691 Binder.restoreCallingIdentity(identity);
2692 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002693 }
2694
2695 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002696 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002697 * a synchronous one.
2698 */
2699 private static class UnlockSim extends Thread {
2700
2701 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002702 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002703
2704 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002705 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2706 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002707
2708 // For replies from SimCard interface
2709 private Handler mHandler;
2710
2711 // For async handler to identify request type
2712 private static final int SUPPLY_PIN_COMPLETE = 100;
2713
Michele Berionne5e411512020-11-13 02:36:59 +00002714 UnlockSim(int phoneId, IccCard simCard) {
2715 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002716 mSimCard = simCard;
2717 }
2718
2719 @Override
2720 public void run() {
2721 Looper.prepare();
2722 synchronized (UnlockSim.this) {
2723 mHandler = new Handler() {
2724 @Override
2725 public void handleMessage(Message msg) {
2726 AsyncResult ar = (AsyncResult) msg.obj;
2727 switch (msg.what) {
2728 case SUPPLY_PIN_COMPLETE:
2729 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2730 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002731 mRetryCount = msg.arg1;
2732 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002733 CommandException.Error error = null;
2734 if (ar.exception instanceof CommandException) {
2735 error = ((CommandException) (ar.exception))
2736 .getCommandError();
2737 }
2738 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07002739 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002740 } else if (error == CommandException.Error.ABORTED) {
2741 /* When UiccCardApp dispose, handle message and return
2742 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08002743 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002744 } else {
2745 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2746 }
2747 } else {
2748 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2749 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002750 mDone = true;
2751 UnlockSim.this.notifyAll();
2752 }
2753 break;
2754 }
2755 }
2756 };
2757 UnlockSim.this.notifyAll();
2758 }
2759 Looper.loop();
2760 }
2761
2762 /*
2763 * Use PIN or PUK to unlock SIM card
2764 *
2765 * If PUK is null, unlock SIM card with PIN
2766 *
2767 * If PUK is not null, unlock SIM card with PUK and set PIN code
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302768 *
2769 * Besides, since it is reused in class level, the thread's looper will be stopped to avoid
2770 * its thread leak.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002771 */
Wink Saville9de0f752013-10-22 19:04:03 -07002772 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002773
2774 while (mHandler == null) {
2775 try {
2776 wait();
2777 } catch (InterruptedException e) {
2778 Thread.currentThread().interrupt();
2779 }
2780 }
2781 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2782
2783 if (puk == null) {
2784 mSimCard.supplyPin(pin, callback);
2785 } else {
2786 mSimCard.supplyPuk(puk, pin, callback);
2787 }
2788
2789 while (!mDone) {
2790 try {
2791 Log.d(LOG_TAG, "wait for done");
2792 wait();
2793 } catch (InterruptedException e) {
2794 // Restore the interrupted status
2795 Thread.currentThread().interrupt();
2796 }
2797 }
2798 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002799 int[] resultArray = new int[2];
2800 resultArray[0] = mResult;
2801 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002802
2803 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002804 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002805 }
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302806 // This instance is no longer reused, so quit its thread's looper.
2807 mHandler.getLooper().quitSafely();
Michele Berionne5e411512020-11-13 02:36:59 +00002808
Wink Saville9de0f752013-10-22 19:04:03 -07002809 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002810 }
2811 }
2812
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002813 /**
2814 * This method has been removed due to privacy and stability concerns.
2815 */
2816 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002817 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002818 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2819 return;
Wink Saville36469e72014-06-11 15:17:00 -07002820 }
2821
Nathan Harold1f889d82020-06-04 17:05:26 -07002822 @Override
2823 public void updateServiceLocationWithPackageName(String callingPackage) {
2824 mApp.getSystemService(AppOpsManager.class)
2825 .checkPackage(Binder.getCallingUid(), callingPackage);
2826
Nathan Haroldf096d982020-11-18 17:18:06 -08002827 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002828 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2829 // Callers targeting S have no business invoking this method.
2830 return;
2831 }
2832
2833 LocationAccessPolicy.LocationPermissionResult locationResult =
2834 LocationAccessPolicy.checkLocationPermission(mApp,
2835 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2836 .setCallingPackage(callingPackage)
2837 .setCallingFeatureId(null)
2838 .setCallingPid(Binder.getCallingPid())
2839 .setCallingUid(Binder.getCallingUid())
2840 .setMethod("updateServiceLocation")
2841 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2842 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2843 .build());
2844 // Apps that lack location permission have no business calling this method;
2845 // however, because no permission was declared in the public API, denials must
2846 // all be "soft".
2847 switch (locationResult) {
2848 case DENIED_HARD: /* fall through */
2849 case DENIED_SOFT:
2850 return;
2851 }
2852
2853 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002854 final long identity = Binder.clearCallingIdentity();
2855 try {
Ling Mac28f0212023-03-24 16:07:15 -07002856 getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002857 } finally {
2858 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002859 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002860 }
2861
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002862 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002863 @Override
2864 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002865 return isRadioOnWithFeature(callingPackage, null);
2866 }
2867
2868
2869 @Override
2870 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2871 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2872 callingFeatureId);
2873 }
2874
2875 @Deprecated
2876 @Override
2877 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2878 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002879 }
2880
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002881 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002882 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2883 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002884 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002885 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002886 return false;
2887 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002888
joonhunshin4ac60942023-11-15 15:23:39 +00002889 enforceTelephonyFeatureWithException(callingPackage,
2890 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isRadioOnWithFeature");
2891
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002892 final long identity = Binder.clearCallingIdentity();
2893 try {
2894 return isRadioOnForSubscriber(subId);
2895 } finally {
2896 Binder.restoreCallingIdentity(identity);
2897 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002898 }
2899
2900 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002901 final long identity = Binder.clearCallingIdentity();
2902 try {
2903 final Phone phone = getPhone(subId);
2904 if (phone != null) {
2905 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2906 } else {
2907 return false;
2908 }
2909 } finally {
2910 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002911 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002912 }
2913
2914 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002915 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002916 }
Wink Saville36469e72014-06-11 15:17:00 -07002917
Wink Savilleb564aae2014-10-23 10:18:09 -07002918 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002919 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002920
joonhunshin4ac60942023-11-15 15:23:39 +00002921 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2922 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "toggleRadioOnOffForSubscriber");
2923
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002924 final long identity = Binder.clearCallingIdentity();
2925 try {
2926 final Phone phone = getPhone(subId);
2927 if (phone != null) {
2928 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2929 }
2930 } finally {
2931 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002932 }
Wink Saville36469e72014-06-11 15:17:00 -07002933 }
2934
2935 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002936 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002937 }
2938
Wink Savilleb564aae2014-10-23 10:18:09 -07002939 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002940 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002941
2942 final long identity = Binder.clearCallingIdentity();
2943 try {
2944 final Phone phone = getPhone(subId);
2945 if (phone == null) {
2946 return false;
2947 }
2948 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2949 toggleRadioOnOffForSubscriber(subId);
2950 }
2951 return true;
2952 } finally {
2953 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002954 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002955 }
Wink Saville36469e72014-06-11 15:17:00 -07002956
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002957 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002958 enforceReadPrivilegedPermission("needMobileRadioShutdown");
joonhunshin4ac60942023-11-15 15:23:39 +00002959
2960 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2961 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needMobileRadioShutdown");
2962
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002963 /*
2964 * If any of the Radios are available, it will need to be
2965 * shutdown. So return true if any Radio is available.
2966 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002967 final long identity = Binder.clearCallingIdentity();
2968 try {
2969 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2970 Phone phone = PhoneFactory.getPhone(i);
2971 if (phone != null && phone.isRadioAvailable()) return true;
2972 }
2973 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2974 return false;
2975 } finally {
2976 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002977 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002978 }
2979
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002980 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002981 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002982 enforceModifyPermission();
2983
joonhunshin4ac60942023-11-15 15:23:39 +00002984 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2985 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "shutdownMobileRadios");
2986
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002987 final long identity = Binder.clearCallingIdentity();
2988 try {
2989 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2990 logv("Shutting down Phone " + i);
2991 shutdownRadioUsingPhoneId(i);
2992 }
2993 } finally {
2994 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002995 }
2996 }
2997
2998 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002999 Phone phone = PhoneFactory.getPhone(phoneId);
3000 if (phone != null && phone.isRadioAvailable()) {
3001 phone.shutdownRadio();
3002 }
3003 }
3004
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003005 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07003006 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003007
Ling Ma83dc5ea2023-01-12 15:06:04 -08003008 if (!turnOn) {
3009 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
3010 }
3011
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003012 final long identity = Binder.clearCallingIdentity();
3013 try {
3014 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
3015 if (defaultPhone != null) {
3016 defaultPhone.setRadioPower(turnOn);
3017 return true;
3018 } else {
3019 loge("There's no default phone.");
3020 return false;
3021 }
3022 } finally {
3023 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07003024 }
Wink Saville36469e72014-06-11 15:17:00 -07003025 }
3026
Wink Savilleb564aae2014-10-23 10:18:09 -07003027 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003028 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003029
Ling Ma83dc5ea2023-01-12 15:06:04 -08003030 if (!turnOn) {
3031 log("setRadioPowerForSubscriber off: subId=" + subId
3032 + ",callingPackage=" + getCurrentPackageName());
3033 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003034 final long identity = Binder.clearCallingIdentity();
3035 try {
3036 final Phone phone = getPhone(subId);
3037 if (phone != null) {
3038 phone.setRadioPower(turnOn);
3039 return true;
3040 } else {
3041 return false;
3042 }
3043 } finally {
3044 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003045 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003046 }
3047
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003048 /**
3049 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3050 * no reason to power it off. When any of the voters want to power it off, it will be turned
3051 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3052 * powering it off, and these radio off votes will be cleared.
3053 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3054 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3055 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3056 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3057 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3058 * check its vote.
3059 *
3060 * @param subId The subscription ID.
3061 * @param reason The reason for powering off radio.
3062 * @return true on success and false on failure.
3063 */
3064 public boolean requestRadioPowerOffForReason(int subId,
3065 @TelephonyManager.RadioPowerReason int reason) {
3066 enforceModifyPermission();
3067
joonhunshin4ac60942023-11-15 15:23:39 +00003068 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3069 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestRadioPowerOffForReason");
3070
Ling Ma83dc5ea2023-01-12 15:06:04 -08003071 log("requestRadioPowerOffForReason: subId=" + subId
3072 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003073 final long identity = Binder.clearCallingIdentity();
3074 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003075 boolean result = false;
3076 for (Phone phone : PhoneFactory.getPhones()) {
3077 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003078 phone.setRadioPowerForReason(false, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003079 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003080 if (!result) {
3081 loge("requestRadioPowerOffForReason: no phone exists");
3082 }
3083 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003084 } finally {
3085 Binder.restoreCallingIdentity(identity);
3086 }
3087 }
3088
3089 /**
3090 * Remove the vote on powering off the radio for a reason, as requested by
3091 * {@link requestRadioPowerOffForReason}.
3092 *
3093 * @param subId The subscription ID.
3094 * @param reason The reason for powering off radio.
3095 * @return true on success and false on failure.
3096 */
3097 public boolean clearRadioPowerOffForReason(int subId,
3098 @TelephonyManager.RadioPowerReason int reason) {
3099 enforceModifyPermission();
3100
joonhunshin4ac60942023-11-15 15:23:39 +00003101 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3102 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearRadioPowerOffForReason");
3103
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003104 final long identity = Binder.clearCallingIdentity();
3105 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003106 boolean result = false;
3107 for (Phone phone : PhoneFactory.getPhones()) {
3108 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003109 phone.setRadioPowerForReason(true, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003110 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003111 if (!result) {
3112 loge("clearRadioPowerOffForReason: no phone exists");
3113 }
3114 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003115 } finally {
3116 Binder.restoreCallingIdentity(identity);
3117 }
3118 }
3119
3120 /**
3121 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3122 *
3123 * @param subId The subscription ID.
3124 * @param callingPackage The package making the call.
3125 * @param callingFeatureId The feature in the package.
3126 * @return List of reasons for powering off radio.
3127 */
3128 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3129 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3130
joonhunshin4ac60942023-11-15 15:23:39 +00003131 enforceTelephonyFeatureWithException(callingPackage,
3132 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerOffReasons");
3133
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003134 final long identity = Binder.clearCallingIdentity();
3135 List result = new ArrayList();
3136 try {
3137 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3138 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3139 return result;
3140 }
3141
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003142 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003143 if (phone != null) {
3144 result.addAll(phone.getRadioPowerOffReasons());
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003145 } else {
3146 loge("getRadioPowerOffReasons: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003147 }
3148 } finally {
3149 Binder.restoreCallingIdentity(identity);
3150 }
3151 return result;
3152 }
3153
Wink Saville36469e72014-06-11 15:17:00 -07003154 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003155 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003156 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003157 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003158
joonhunshin4ac60942023-11-15 15:23:39 +00003159 enforceTelephonyFeatureWithException(callingPackage,
3160 PackageManager.FEATURE_TELEPHONY_DATA, "enableDataConnectivity");
3161
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003162 final long identity = Binder.clearCallingIdentity();
3163 try {
Jack Yu285100e2022-12-02 22:48:35 -08003164 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003165 final Phone phone = getPhone(subId);
3166 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003167 phone.getDataSettingsManager().setDataEnabled(
3168 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003169 return true;
3170 } else {
3171 return false;
3172 }
3173 } finally {
3174 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003175 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003176 }
3177
Wink Saville36469e72014-06-11 15:17:00 -07003178 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003179 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003180 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003181 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003182
joonhunshin4ac60942023-11-15 15:23:39 +00003183 enforceTelephonyFeatureWithException(callingPackage,
3184 PackageManager.FEATURE_TELEPHONY_DATA, "disableDataConnectivity");
3185
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003186 final long identity = Binder.clearCallingIdentity();
3187 try {
Jack Yu285100e2022-12-02 22:48:35 -08003188 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003189 final Phone phone = getPhone(subId);
3190 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003191 phone.getDataSettingsManager().setDataEnabled(
3192 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003193 return true;
3194 } else {
3195 return false;
3196 }
3197 } finally {
3198 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003199 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003200 }
3201
Sanket Padawe356d7632015-06-22 14:03:32 -07003202 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003203 public boolean isDataConnectivityPossible(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003204 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3205 PackageManager.FEATURE_TELEPHONY_DATA, "isDataConnectivityPossible");
3206
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003207 final long identity = Binder.clearCallingIdentity();
3208 try {
3209 final Phone phone = getPhone(subId);
3210 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003211 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003212 } else {
3213 return false;
3214 }
3215 } finally {
3216 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003217 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003218 }
3219
3220 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003221 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003222 }
3223
pkanwarae03a6b2016-11-06 20:37:09 -08003224 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003225 enforceCallPermission();
3226
joonhunshin4ac60942023-11-15 15:23:39 +00003227 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3228 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "handleUssdRequest");
3229
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003230 final long identity = Binder.clearCallingIdentity();
3231 try {
3232 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3233 return;
3234 }
3235 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3236 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3237 } finally {
3238 Binder.restoreCallingIdentity(identity);
3239 }
pkanwar32d516d2016-10-14 19:37:38 -07003240 };
3241
Wink Savilleb564aae2014-10-23 10:18:09 -07003242 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003243 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003244
joonhunshin4ac60942023-11-15 15:23:39 +00003245 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3246 PackageManager.FEATURE_TELEPHONY_CALLING, "handlePinMmiForSubscriber");
3247
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003248 final long identity = Binder.clearCallingIdentity();
3249 try {
3250 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3251 return false;
3252 }
3253 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3254 } finally {
3255 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003256 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003257 }
3258
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003259 /**
3260 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3261 * tag on getCallState Binder call.
3262 */
3263 @Deprecated
3264 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003265 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003266 if (CompatChanges.isChangeEnabled(
3267 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3268 Binder.getCallingUid())) {
3269 // Do not allow this API to be called on API version 31+, it should only be
3270 // called on old apps using this Binder call directly.
3271 throw new SecurityException("This method can only be used for applications "
3272 + "targeting API version 30 or less.");
3273 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003274 final long identity = Binder.clearCallingIdentity();
3275 try {
Ling Mac28f0212023-03-24 16:07:15 -07003276 Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription());
3277 return PhoneConstantConversions.convertCallState(phone.getState());
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003278 } finally {
3279 Binder.restoreCallingIdentity(identity);
3280 }
3281 }
3282
3283 @Override
3284 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3285 if (CompatChanges.isChangeEnabled(
3286 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3287 Binder.getCallingUid())) {
3288 // Check READ_PHONE_STATE for API version 31+
3289 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3290 featureId, "getCallStateForSubscription")) {
3291 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3292 + "targeting API level 31+.");
3293 }
3294 }
joonhunshin4ac60942023-11-15 15:23:39 +00003295
3296 enforceTelephonyFeatureWithException(callingPackage,
3297 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallStateForSubscription");
3298
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003299 final long identity = Binder.clearCallingIdentity();
3300 try {
3301 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003302 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3303 PhoneConstantConversions.convertCallState(phone.getState());
3304 } finally {
3305 Binder.restoreCallingIdentity(identity);
3306 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003307 }
3308
Sanket Padawe356d7632015-06-22 14:03:32 -07003309 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003310 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003311 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003312 }
3313
3314 @Override
3315 public int getDataStateForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003316 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3317 PackageManager.FEATURE_TELEPHONY_DATA, "getDataStateForSubId");
3318
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003319 final long identity = Binder.clearCallingIdentity();
3320 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003321 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003322 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003323 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003324 } else {
3325 return PhoneConstantConversions.convertDataState(
3326 PhoneConstants.DataState.DISCONNECTED);
3327 }
3328 } finally {
3329 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003330 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003331 }
3332
Sanket Padawe356d7632015-06-22 14:03:32 -07003333 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003334 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003335 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003336 }
3337
3338 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003339 public @DataActivityType int getDataActivityForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003340 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3341 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivityForSubId");
3342
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003343 final long identity = Binder.clearCallingIdentity();
3344 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003345 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003346 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003347 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003348 } else {
3349 return TelephonyManager.DATA_ACTIVITY_NONE;
3350 }
3351 } finally {
3352 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003353 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003354 }
3355
3356 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003357 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003358 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003359 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003360
3361 LocationAccessPolicy.LocationPermissionResult locationResult =
3362 LocationAccessPolicy.checkLocationPermission(mApp,
3363 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3364 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003365 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003366 .setCallingPid(Binder.getCallingPid())
3367 .setCallingUid(Binder.getCallingUid())
3368 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003369 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003370 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3371 .build());
3372 switch (locationResult) {
3373 case DENIED_HARD:
3374 throw new SecurityException("Not allowed to access cell location");
3375 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003376 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3377 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003378 }
3379
joonhunshin4ac60942023-11-15 15:23:39 +00003380 enforceTelephonyFeatureWithException(callingPackage,
3381 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getCellLocation");
3382
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003383 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003384 final long identity = Binder.clearCallingIdentity();
3385 try {
3386 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003387 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003388 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003389 } finally {
3390 Binder.restoreCallingIdentity(identity);
3391 }
Svetoslav64fad262015-04-14 14:35:21 -07003392 }
3393
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003394 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003395 public String getNetworkCountryIsoForPhone(int phoneId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003396 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3397 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkCountryIsoForPhone");
3398
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003399 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3400 // registered cell info, so return a NULL country instead.
3401 final long identity = Binder.clearCallingIdentity();
3402 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003403 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3404 // Get default phone in this case.
3405 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3406 }
Jack Yu285100e2022-12-02 22:48:35 -08003407 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003408 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003409 if (phone == null) return "";
3410 ServiceStateTracker sst = phone.getServiceStateTracker();
3411 if (sst == null) return "";
3412 LocaleTracker lt = sst.getLocaleTracker();
3413 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003414 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003415 } finally {
3416 Binder.restoreCallingIdentity(identity);
3417 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003418 }
3419
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003420 /**
3421 * This method was removed due to potential issues caused by performing partial
3422 * updates of service state, and lack of a credible use case.
3423 *
3424 * This has the ability to break the telephony implementation by disabling notification of
3425 * changes in device connectivity. DO NOT USE THIS!
3426 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003427 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003428 public void enableLocationUpdates() {
3429 mApp.enforceCallingOrSelfPermission(
3430 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003431 }
3432
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003433 /**
3434 * This method was removed due to potential issues caused by performing partial
3435 * updates of service state, and lack of a credible use case.
3436 *
3437 * This has the ability to break the telephony implementation by disabling notification of
3438 * changes in device connectivity. DO NOT USE THIS!
3439 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003440 @Override
3441 public void disableLocationUpdates() {
3442 mApp.enforceCallingOrSelfPermission(
3443 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003444 }
3445
3446 @Override
3447 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003448 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3449 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003450 try {
3451 mApp.getSystemService(AppOpsManager.class)
3452 .checkPackage(Binder.getCallingUid(), callingPackage);
3453 } catch (SecurityException e) {
3454 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3455 throw e;
3456 }
3457
Nathan Haroldf096d982020-11-18 17:18:06 -08003458 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003459 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3460 throw new SecurityException(
3461 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3462 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003463
Jordan Liu1617b712019-07-10 15:06:26 -07003464 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003465 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3466 return null;
3467 }
Svetoslav64fad262015-04-14 14:35:21 -07003468
joonhunshin4ac60942023-11-15 15:23:39 +00003469 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3470 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNeighboringCellInfo");
3471
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003472 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003473
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003474 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003475 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003476
Nathan Haroldf180aac2018-06-01 18:43:55 -07003477 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3478 for (CellInfo ci : info) {
3479 if (ci instanceof CellInfoGsm) {
3480 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3481 } else if (ci instanceof CellInfoWcdma) {
3482 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3483 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003484 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003485 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003486 }
3487
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003488 private List<CellInfo> getCachedCellInfo() {
3489 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3490 for (Phone phone : PhoneFactory.getPhones()) {
3491 List<CellInfo> info = phone.getAllCellInfo();
3492 if (info != null) cellInfos.addAll(info);
3493 }
3494 return cellInfos;
3495 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003496
3497 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003498 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003499 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003500 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003501
3502 LocationAccessPolicy.LocationPermissionResult locationResult =
3503 LocationAccessPolicy.checkLocationPermission(mApp,
3504 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3505 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003506 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003507 .setCallingPid(Binder.getCallingPid())
3508 .setCallingUid(Binder.getCallingUid())
3509 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003510 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003511 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3512 .build());
3513 switch (locationResult) {
3514 case DENIED_HARD:
3515 throw new SecurityException("Not allowed to access cell info");
3516 case DENIED_SOFT:
3517 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003518 }
3519
Nathan Haroldf096d982020-11-18 17:18:06 -08003520 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003521 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3522 return getCachedCellInfo();
3523 }
3524
joonhunshin4ac60942023-11-15 15:23:39 +00003525 enforceTelephonyFeatureWithException(callingPackage,
3526 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllCellInfo");
3527
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003528 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003529 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003530 final long identity = Binder.clearCallingIdentity();
3531 try {
3532 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3533 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003534 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003535 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003536 if (info != null) cellInfos.addAll(info);
3537 }
3538 return cellInfos;
3539 } finally {
3540 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003541 }
3542 }
3543
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003544 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003545 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3546 String callingFeatureId) {
3547 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3548 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003549 }
3550
3551 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003552 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3553 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003554 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003555 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003556 }
3557
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003558 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3559 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003560 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003561 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003562
3563 LocationAccessPolicy.LocationPermissionResult locationResult =
3564 LocationAccessPolicy.checkLocationPermission(mApp,
3565 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3566 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003567 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003568 .setCallingPid(Binder.getCallingPid())
3569 .setCallingUid(Binder.getCallingUid())
3570 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003571 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3572 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003573 .build());
3574 switch (locationResult) {
3575 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003576 if (TelephonyPermissions
3577 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003578 // Safetynet logging for b/154934934
3579 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3580 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003581 throw new SecurityException("Not allowed to access cell info");
3582 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003583 if (TelephonyPermissions
3584 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003585 // Safetynet logging for b/154934934
3586 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3587 }
Nathan Harold5320c422019-05-09 10:26:08 -07003588 try {
3589 cb.onCellInfo(new ArrayList<CellInfo>());
3590 } catch (RemoteException re) {
3591 // Drop without consequences
3592 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003593 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003594 }
3595
joonhunshin4ac60942023-11-15 15:23:39 +00003596 enforceTelephonyFeatureWithException(callingPackage,
3597 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestCellInfoUpdateInternal");
Nathan Harolda939a962019-05-09 10:13:47 -07003598
3599 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003600 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3601
3602 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3603 }
3604
3605 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003606 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003607 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003608 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003609
3610 final long identity = Binder.clearCallingIdentity();
3611 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003612 Phone phone = getPhone(subId);
3613 if (phone == null) {
3614 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3615 } else {
3616 phone.setCellInfoListRate(rateInMillis, workSource);
3617 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003618 } finally {
3619 Binder.restoreCallingIdentity(identity);
3620 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003621 }
3622
Shishir Agrawala9f32182016-04-12 12:00:16 -07003623 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003624 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003625 Phone phone = PhoneFactory.getPhone(slotIndex);
3626 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003627 return null;
3628 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003629 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003630 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003631 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003632 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003633 return null;
3634 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003635
joonhunshin4ac60942023-11-15 15:23:39 +00003636 enforceTelephonyFeatureWithException(callingPackage,
3637 PackageManager.FEATURE_TELEPHONY_GSM, "getImeiForSlot");
3638
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003639 final long identity = Binder.clearCallingIdentity();
3640 try {
3641 return phone.getImei();
3642 } finally {
3643 Binder.restoreCallingIdentity(identity);
3644 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003645 }
3646
3647 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003648 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3649 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3650 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3651 callingFeatureId, "getPrimaryImei")) {
3652 throw new SecurityException("Caller does not have permission");
3653 }
joonhunshin4ac60942023-11-15 15:23:39 +00003654
3655 enforceTelephonyFeatureWithException(callingPackage,
3656 PackageManager.FEATURE_TELEPHONY_GSM, "getPrimaryImei");
3657
arunvoddud5c6ce02022-12-11 06:03:12 +00003658 final long identity = Binder.clearCallingIdentity();
3659 try {
3660 for (Phone phone : PhoneFactory.getPhones()) {
3661 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3662 return phone.getImei();
3663 }
3664 }
3665 throw new UnsupportedOperationException("Operation not supported");
3666 } finally {
3667 Binder.restoreCallingIdentity(identity);
3668 }
3669 }
3670
3671 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003672 public String getTypeAllocationCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003673 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3674 PackageManager.FEATURE_TELEPHONY_GSM, "getTypeAllocationCodeForSlot");
3675
David Kelly5e06a7f2018-03-12 14:10:59 +00003676 Phone phone = PhoneFactory.getPhone(slotIndex);
3677 String tac = null;
3678 if (phone != null) {
3679 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003680 try {
3681 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3682 } catch (IndexOutOfBoundsException e) {
3683 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3684 return null;
3685 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003686 }
3687 return tac;
3688 }
3689
3690 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003691 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003692 try {
3693 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3694 } catch (SecurityException se) {
3695 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3696 throw new SecurityException("Package " + callingPackage + " does not belong to "
3697 + Binder.getCallingUid());
3698 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003699 Phone phone = PhoneFactory.getPhone(slotIndex);
3700 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003701 return null;
3702 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003703
Jeff Davidson913390f2018-02-23 17:11:49 -08003704 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003705 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003706 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003707 return null;
3708 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003709
joonhunshin4ac60942023-11-15 15:23:39 +00003710 enforceTelephonyFeatureWithException(callingPackage,
3711 PackageManager.FEATURE_TELEPHONY_CDMA, "getMeidForSlot");
3712
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003713 final long identity = Binder.clearCallingIdentity();
3714 try {
3715 return phone.getMeid();
3716 } finally {
3717 Binder.restoreCallingIdentity(identity);
3718 }
Jack Yu2af8d712017-03-15 17:14:14 -07003719 }
3720
3721 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003722 public String getManufacturerCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003723 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3724 PackageManager.FEATURE_TELEPHONY_CDMA, "getManufacturerCodeForSlot");
3725
David Kelly5e06a7f2018-03-12 14:10:59 +00003726 Phone phone = PhoneFactory.getPhone(slotIndex);
3727 String manufacturerCode = null;
3728 if (phone != null) {
3729 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003730 try {
3731 manufacturerCode =
3732 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3733 } catch (IndexOutOfBoundsException e) {
3734 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3735 return null;
3736 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003737 }
3738 return manufacturerCode;
3739 }
3740
3741 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003742 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3743 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003744 Phone phone = PhoneFactory.getPhone(slotIndex);
3745 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003746 return null;
3747 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003748 int subId = phone.getSubId();
3749 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003750 mApp, subId, callingPackage, callingFeatureId,
3751 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003752 return null;
3753 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003754
joonhunshin4ac60942023-11-15 15:23:39 +00003755 enforceTelephonyFeatureWithException(callingPackage,
3756 PackageManager.FEATURE_TELEPHONY, "getDeviceSoftwareVersionForSlot");
3757
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003758 final long identity = Binder.clearCallingIdentity();
3759 try {
3760 return phone.getDeviceSvn();
3761 } finally {
3762 Binder.restoreCallingIdentity(identity);
3763 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003764 }
3765
fionaxu43304da2017-11-27 22:51:16 -08003766 @Override
3767 public int getSubscriptionCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003768 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3769 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierId");
3770
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003771 final long identity = Binder.clearCallingIdentity();
3772 try {
3773 final Phone phone = getPhone(subId);
3774 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3775 } finally {
3776 Binder.restoreCallingIdentity(identity);
3777 }
fionaxu43304da2017-11-27 22:51:16 -08003778 }
3779
3780 @Override
3781 public String getSubscriptionCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003782 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3783 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierName");
3784
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003785 final long identity = Binder.clearCallingIdentity();
3786 try {
3787 final Phone phone = getPhone(subId);
3788 return phone == null ? null : phone.getCarrierName();
3789 } finally {
3790 Binder.restoreCallingIdentity(identity);
3791 }
fionaxu43304da2017-11-27 22:51:16 -08003792 }
3793
calvinpanffe225e2018-11-01 19:43:06 +08003794 @Override
chen xu0026ca62019-03-06 15:28:50 -08003795 public int getSubscriptionSpecificCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003796 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3797 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionSpecificCarrierId");
3798
chen xu25637222018-11-04 17:17:00 -08003799 final long identity = Binder.clearCallingIdentity();
3800 try {
3801 final Phone phone = getPhone(subId);
3802 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003803 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003804 } finally {
3805 Binder.restoreCallingIdentity(identity);
3806 }
3807 }
3808
3809 @Override
chen xu0026ca62019-03-06 15:28:50 -08003810 public String getSubscriptionSpecificCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003811 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3812 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
3813 "getSubscriptionSpecificCarrierName");
3814
chen xu25637222018-11-04 17:17:00 -08003815 final long identity = Binder.clearCallingIdentity();
3816 try {
3817 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003818 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003819 } finally {
3820 Binder.restoreCallingIdentity(identity);
3821 }
3822 }
3823
chen xu651eec72018-11-11 19:03:44 -08003824 @Override
chen xu864e11c2018-12-06 22:10:03 -08003825 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3826 if (!isSubscriptionMccMnc) {
3827 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3828 }
chen xu651eec72018-11-11 19:03:44 -08003829 final Phone phone = PhoneFactory.getPhone(slotIndex);
3830 if (phone == null) {
3831 return TelephonyManager.UNKNOWN_CARRIER_ID;
3832 }
joonhunshin4ac60942023-11-15 15:23:39 +00003833
3834 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3835 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromMccMnc");
3836
chen xu651eec72018-11-11 19:03:44 -08003837 final long identity = Binder.clearCallingIdentity();
3838 try {
3839 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3840 } finally {
3841 Binder.restoreCallingIdentity(identity);
3842 }
3843 }
3844
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003845 //
3846 // Internal helper methods.
3847 //
3848
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003849 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003850 * Make sure the caller is the calling package itself
3851 *
3852 * @throws SecurityException if the caller is not the calling package
3853 */
3854 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3855 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003856 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3857 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003858 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003859 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003860 } catch (PackageManager.NameNotFoundException e) {
3861 // packageUid is -1
3862 }
3863 if (packageUid != callingUid) {
3864 throw new SecurityException(message + ": Package " + callingPackage
3865 + " does not belong to " + callingUid);
3866 }
3867 }
3868
3869 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003870 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3871 *
3872 * @throws SecurityException if the caller does not have the required permission
3873 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003874 @VisibleForTesting
3875 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003876 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3877 }
3878
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003879 /**
arunvoddud7401012022-12-15 16:08:12 +00003880 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003881 *
3882 * @throws SecurityException if the caller does not have the required permission
3883 */
3884 @VisibleForTesting
3885 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003886 enforceReadPermission(null);
3887 }
3888
3889 /**
3890 * Make sure the caller has the READ_PHONE_STATE permissions.
3891 *
3892 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3893 */
3894 @VisibleForTesting
3895 public void enforceReadPermission(String msg) {
3896 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003897 }
3898
Shuo Qian3b6ee772019-11-13 17:43:31 -08003899 private void enforceActiveEmergencySessionPermission() {
3900 mApp.enforceCallingOrSelfPermission(
3901 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3902 }
3903
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003904 /**
3905 * Make sure the caller has the CALL_PHONE permission.
3906 *
3907 * @throws SecurityException if the caller does not have the required permission
3908 */
3909 private void enforceCallPermission() {
3910 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3911 }
3912
paulhu5a773602019-08-23 19:17:33 +08003913 private void enforceSettingsPermission() {
3914 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003915 }
3916
Michele Berionne5e411512020-11-13 02:36:59 +00003917 private void enforceRebootPermission() {
3918 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3919 }
3920
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003921 /**
3922 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3923 * @param message - log message to print.
3924 * @throws SecurityException if the caller does not have the required permission
3925 */
3926 private void enforceSatelliteCommunicationPermission(String message) {
3927 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3928 }
3929
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003930 private String createTelUrl(String number) {
3931 if (TextUtils.isEmpty(number)) {
3932 return null;
3933 }
3934
Jake Hambye994d462014-02-03 13:10:13 -08003935 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003936 }
3937
Ihab Awadf9e92732013-12-05 18:02:52 -08003938 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003939 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003940 }
3941
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003942 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003943 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003944 }
3945
Ihab Awadf9e92732013-12-05 18:02:52 -08003946 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003947 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003948 }
3949
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003950 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003951 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003952 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003953 }
3954
Sanket Padawe356d7632015-06-22 14:03:32 -07003955 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003956 public int getActivePhoneTypeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003957 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3958 PackageManager.FEATURE_TELEPHONY, "getActivePhoneTypeForSlot");
3959
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003960 final long identity = Binder.clearCallingIdentity();
3961 try {
3962 final Phone phone = PhoneFactory.getPhone(slotIndex);
3963 if (phone == null) {
3964 return PhoneConstants.PHONE_TYPE_NONE;
3965 } else {
3966 return phone.getPhoneType();
3967 }
3968 } finally {
3969 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003970 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003971 }
3972
3973 /**
3974 * Returns the CDMA ERI icon index to display
3975 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003976 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003977 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3978 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3979 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003980 }
3981
Sanket Padawe356d7632015-06-22 14:03:32 -07003982 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003983 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3984 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003985 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003986 mApp, subId, callingPackage, callingFeatureId,
3987 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003988 return -1;
3989 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003990
joonhunshin4ac60942023-11-15 15:23:39 +00003991 enforceTelephonyFeatureWithException(callingPackage,
3992 PackageManager.FEATURE_TELEPHONY_CDMA,
3993 "getCdmaEriIconIndexForSubscriber");
3994
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003995 final long identity = Binder.clearCallingIdentity();
3996 try {
3997 final Phone phone = getPhone(subId);
3998 if (phone != null) {
3999 return phone.getCdmaEriIconIndex();
4000 } else {
4001 return -1;
4002 }
4003 } finally {
4004 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004005 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004006 }
4007
4008 /**
4009 * Returns the CDMA ERI icon mode,
4010 * 0 - ON
4011 * 1 - FLASHING
4012 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004013 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004014 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
4015 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
4016 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004017 }
4018
Sanket Padawe356d7632015-06-22 14:03:32 -07004019 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004020 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
4021 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004022 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004023 mApp, subId, callingPackage, callingFeatureId,
4024 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004025 return -1;
4026 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004027
4028 final long identity = Binder.clearCallingIdentity();
4029 try {
4030 final Phone phone = getPhone(subId);
4031 if (phone != null) {
4032 return phone.getCdmaEriIconMode();
4033 } else {
4034 return -1;
4035 }
4036 } finally {
4037 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004038 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004039 }
4040
4041 /**
4042 * Returns the CDMA ERI text,
4043 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004044 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004045 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
4046 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
4047 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004048 }
4049
Sanket Padawe356d7632015-06-22 14:03:32 -07004050 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004051 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
4052 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004053 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004054 mApp, subId, callingPackage, callingFeatureId,
4055 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004056 return null;
4057 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004058
4059 final long identity = Binder.clearCallingIdentity();
4060 try {
4061 final Phone phone = getPhone(subId);
4062 if (phone != null) {
4063 return phone.getCdmaEriText();
4064 } else {
4065 return null;
4066 }
4067 } finally {
4068 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004069 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004070 }
4071
4072 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07004073 * Returns the CDMA MDN.
4074 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004075 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004076 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004077 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4078 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004079
joonhunshin4ac60942023-11-15 15:23:39 +00004080 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4081 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMdn");
4082
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004083 final long identity = Binder.clearCallingIdentity();
4084 try {
4085 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004086 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004087 return phone.getLine1Number();
4088 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004089 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004090 return null;
4091 }
4092 } finally {
4093 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004094 }
4095 }
4096
4097 /**
4098 * Returns the CDMA MIN.
4099 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004100 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004101 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004102 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4103 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004104
joonhunshin4ac60942023-11-15 15:23:39 +00004105 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4106 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMin");
4107
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004108 final long identity = Binder.clearCallingIdentity();
4109 try {
4110 final Phone phone = getPhone(subId);
4111 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
4112 return phone.getCdmaMin();
4113 } else {
4114 return null;
4115 }
4116 } finally {
4117 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004118 }
4119 }
4120
Hall Liud892bec2018-11-30 14:51:45 -08004121 @Override
4122 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
4123 INumberVerificationCallback callback, String callingPackage) {
4124 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
4125 != PERMISSION_GRANTED) {
4126 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
4127 }
4128 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4129
4130 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
4131 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08004132 throw new SecurityException("Calling package must be configured in the device config: "
4133 + "calling package: " + callingPackage
4134 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004135 }
4136
joonhunshin4ac60942023-11-15 15:23:39 +00004137 enforceTelephonyFeatureWithException(callingPackage,
4138 PackageManager.FEATURE_TELEPHONY_CALLING, "requestNumberVerification");
4139
Hall Liud892bec2018-11-30 14:51:45 -08004140 if (range == null) {
4141 throw new NullPointerException("Range must be non-null");
4142 }
4143
4144 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004145 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004146
4147 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4148 }
4149
Junda Liuca05d5d2014-08-14 22:36:34 -07004150 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004151 * Returns true if CDMA provisioning needs to run.
4152 */
4153 public boolean needsOtaServiceProvisioning() {
joonhunshin4ac60942023-11-15 15:23:39 +00004154 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4155 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needsOtaServiceProvisioning");
4156
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004157 final long identity = Binder.clearCallingIdentity();
4158 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004159 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004160 } finally {
4161 Binder.restoreCallingIdentity(identity);
4162 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004163 }
4164
4165 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004166 * Sets the voice mail number of a given subId.
4167 */
4168 @Override
4169 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004170 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4171 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004172
joonhunshin4ac60942023-11-15 15:23:39 +00004173 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4174 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceMailNumber");
4175
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004176 final long identity = Binder.clearCallingIdentity();
4177 try {
4178 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4179 new Pair<String, String>(alphaTag, number), new Integer(subId));
4180 return success;
4181 } finally {
4182 Binder.restoreCallingIdentity(identity);
4183 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004184 }
4185
Ta-wei Yen87c49842016-05-13 21:19:52 -07004186 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004187 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4188 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004189 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4190 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004191 if (!TextUtils.equals(callingPackage, systemDialer)) {
4192 throw new SecurityException("caller must be system dialer");
4193 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004194
joonhunshin4ac60942023-11-15 15:23:39 +00004195 enforceTelephonyFeatureWithException(callingPackage,
4196 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailSettings");
4197
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004198 final long identity = Binder.clearCallingIdentity();
4199 try {
4200 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4201 if (phoneAccountHandle == null) {
4202 return null;
4203 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004204 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004205 } finally {
4206 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004207 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004208 }
4209
4210 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004211 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4212 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004213 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004214 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004215 mApp, subId, callingPackage, callingFeatureId,
4216 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004217 return null;
4218 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004219
joonhunshin4ac60942023-11-15 15:23:39 +00004220 enforceTelephonyFeatureWithException(callingPackage,
4221 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailPackageName");
4222
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004223 final long identity = Binder.clearCallingIdentity();
4224 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004225 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004226 } finally {
4227 Binder.restoreCallingIdentity(identity);
4228 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004229 }
4230
4231 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004232 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4233 VisualVoicemailSmsFilterSettings settings) {
4234 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004235
joonhunshin4ac60942023-11-15 15:23:39 +00004236 enforceTelephonyFeatureWithException(callingPackage,
4237 PackageManager.FEATURE_TELEPHONY_CALLING, "enableVisualVoicemailSmsFilter");
4238
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004239 final long identity = Binder.clearCallingIdentity();
4240 try {
4241 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004242 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004243 } finally {
4244 Binder.restoreCallingIdentity(identity);
4245 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004246 }
4247
4248 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004249 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4250 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004251
joonhunshin4ac60942023-11-15 15:23:39 +00004252 enforceTelephonyFeatureWithException(callingPackage,
4253 PackageManager.FEATURE_TELEPHONY_CALLING, "disableVisualVoicemailSmsFilter");
4254
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004255 final long identity = Binder.clearCallingIdentity();
4256 try {
4257 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004258 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004259 } finally {
4260 Binder.restoreCallingIdentity(identity);
4261 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004262 }
4263
4264 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004265 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4266 String callingPackage, int subId) {
4267 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004268
4269 final long identity = Binder.clearCallingIdentity();
4270 try {
4271 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004272 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004273 } finally {
4274 Binder.restoreCallingIdentity(identity);
4275 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004276 }
4277
4278 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004279 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004280 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004281
4282 final long identity = Binder.clearCallingIdentity();
4283 try {
4284 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004285 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004286 } finally {
4287 Binder.restoreCallingIdentity(identity);
4288 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004289 }
4290
4291 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004292 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4293 String callingAttributionTag, int subId, String number, int port, String text,
4294 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004295 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004296 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004297 enforceSendSmsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00004298
4299 enforceTelephonyFeatureWithException(callingPackage,
4300 PackageManager.FEATURE_TELEPHONY_CALLING, "sendVisualVoicemailSmsForSubscriber");
4301
Amit Mahajandccb3f12019-05-13 13:48:32 -07004302 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004303 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4304 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004305 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004306
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004307 /**
fionaxu0152e512016-11-14 13:36:14 -08004308 * Sets the voice activation state of a given subId.
4309 */
4310 @Override
4311 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004312 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4313 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004314
joonhunshin4ac60942023-11-15 15:23:39 +00004315 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4316 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState");
4317
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004318 final long identity = Binder.clearCallingIdentity();
4319 try {
4320 final Phone phone = getPhone(subId);
4321 if (phone != null) {
4322 phone.setVoiceActivationState(activationState);
4323 } else {
4324 loge("setVoiceActivationState fails with invalid subId: " + subId);
4325 }
4326 } finally {
4327 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004328 }
4329 }
4330
4331 /**
4332 * Sets the data activation state of a given subId.
4333 */
4334 @Override
4335 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004336 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4337 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004338
joonhunshin4ac60942023-11-15 15:23:39 +00004339 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4340 PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState");
4341
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004342 final long identity = Binder.clearCallingIdentity();
4343 try {
4344 final Phone phone = getPhone(subId);
4345 if (phone != null) {
4346 phone.setDataActivationState(activationState);
4347 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004348 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004349 }
4350 } finally {
4351 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004352 }
4353 }
4354
4355 /**
4356 * Returns the voice activation state of a given subId.
4357 */
4358 @Override
4359 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004360 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004361
joonhunshin4ac60942023-11-15 15:23:39 +00004362 enforceTelephonyFeatureWithException(callingPackage,
4363 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState");
4364
fionaxu0152e512016-11-14 13:36:14 -08004365 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004366 final long identity = Binder.clearCallingIdentity();
4367 try {
4368 if (phone != null) {
4369 return phone.getVoiceActivationState();
4370 } else {
4371 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4372 }
4373 } finally {
4374 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004375 }
4376 }
4377
4378 /**
4379 * Returns the data activation state of a given subId.
4380 */
4381 @Override
4382 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004383 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004384
joonhunshin4ac60942023-11-15 15:23:39 +00004385 enforceTelephonyFeatureWithException(callingPackage,
4386 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState");
4387
fionaxu0152e512016-11-14 13:36:14 -08004388 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004389 final long identity = Binder.clearCallingIdentity();
4390 try {
4391 if (phone != null) {
4392 return phone.getDataActivationState();
4393 } else {
4394 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4395 }
4396 } finally {
4397 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004398 }
4399 }
4400
4401 /**
Wink Saville36469e72014-06-11 15:17:00 -07004402 * Returns the unread count of voicemails for a subId
4403 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004404 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004405 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4406 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004407 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004408 mApp, subId, callingPackage, callingFeatureId,
4409 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004410 return 0;
4411 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004412 final long identity = Binder.clearCallingIdentity();
4413 try {
4414 final Phone phone = getPhone(subId);
4415 if (phone != null) {
4416 return phone.getVoiceMessageCount();
4417 } else {
4418 return 0;
4419 }
4420 } finally {
4421 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004422 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004423 }
4424
4425 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004426 * returns true, if the device is in a state where both voice and data
4427 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004428 */
4429 @Override
4430 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00004431 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4432 PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed");
4433
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004434 final long identity = Binder.clearCallingIdentity();
4435 try {
Ling Mac28f0212023-03-24 16:07:15 -07004436 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004437 } finally {
4438 Binder.restoreCallingIdentity(identity);
4439 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004440 }
4441
4442 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004443 * Send the dialer code if called from the current default dialer or the caller has
4444 * carrier privilege.
4445 * @param inputCode The dialer code to send
4446 */
4447 @Override
4448 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004449 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004450 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004451 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4452 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004453 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004454 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004455 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004456 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004457
joonhunshin4ac60942023-11-15 15:23:39 +00004458 enforceTelephonyFeatureWithException(callingPackage,
4459 PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode");
4460
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004461 final long identity = Binder.clearCallingIdentity();
4462 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004463 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004464 } finally {
4465 Binder.restoreCallingIdentity(identity);
4466 }
fionaxu235cc5e2017-03-06 22:25:57 -08004467 }
4468
Pengquan Menga1bb6272018-09-06 09:59:22 -07004469 @Override
4470 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004471 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004472 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4473 mApp, subId, "getNetworkSelectionMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004474
4475 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4476 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode");
4477
shilufc958392020-01-20 11:36:01 -08004478 final long identity = Binder.clearCallingIdentity();
4479 try {
4480 if (!isActiveSubscription(subId)) {
4481 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4482 }
4483 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4484 } finally {
4485 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004486 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004487 }
4488
Brad Ebinger35c841c2018-10-01 10:40:55 -07004489 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004490 public boolean isInEmergencySmsMode() {
4491 enforceReadPrivilegedPermission("isInEmergencySmsMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004492
4493 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4494 PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode");
4495
Brad Ebingerb2b65522019-03-15 13:48:47 -07004496 final long identity = Binder.clearCallingIdentity();
4497 try {
4498 for (Phone phone : PhoneFactory.getPhones()) {
4499 if (phone.isInEmergencySmsMode()) {
4500 return true;
4501 }
4502 }
4503 } finally {
4504 Binder.restoreCallingIdentity(identity);
4505 }
4506 return false;
4507 }
4508
shilu366312e2019-12-17 09:28:10 -08004509 /**
4510 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4511 * @param subId The subscription to use to check the configuration.
4512 * @param c The callback that will be used to send the result.
4513 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004514 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004515 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4516 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004517 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004518 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004519
4520 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4521 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4522 "IMS not available on device.");
4523 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004524 final long token = Binder.clearCallingIdentity();
4525 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004526 int slotId = getSlotIndexOrException(subId);
4527 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004528
4529 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4530 if (controller != null) {
4531 ImsManager imsManager = controller.getImsManager(subId);
4532 if (imsManager != null) {
4533 imsManager.addRegistrationCallbackForSubscription(c, subId);
4534 } else {
4535 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4536 }
4537 } else {
4538 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4539 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004540 } catch (ImsException e) {
4541 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004542 } finally {
4543 Binder.restoreCallingIdentity(token);
4544 }
4545 }
4546
shilu366312e2019-12-17 09:28:10 -08004547 /**
4548 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4549 * @param subId The subscription to use to check the configuration.
4550 * @param c The callback that will be used to send the result.
4551 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004552 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004553 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004554 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004555 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004556 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4557 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4558 }
Meng Wangafbc5852019-09-19 17:37:13 -07004559 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004560
Meng Wangafbc5852019-09-19 17:37:13 -07004561 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004562 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4563 if (controller != null) {
4564 ImsManager imsManager = controller.getImsManager(subId);
4565 if (imsManager != null) {
4566 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4567 } else {
4568 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4569 + "is inactive, ignoring unregister.");
4570 // If the ImsManager is not valid, just return, since the callback
4571 // will already have been removed internally.
4572 }
4573 }
Meng Wangafbc5852019-09-19 17:37:13 -07004574 } finally {
4575 Binder.restoreCallingIdentity(token);
4576 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004577 }
4578
Brad Ebingera34a6c22019-10-22 17:36:18 -07004579 /**
Hidayat Khan99ea48f2023-12-11 04:37:45 +00004580 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4581 * @param subId The subscription to use to check the configuration.
4582 * @param c The callback that will be used to send the result.
4583 */
4584 @Override
4585 public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c)
4586 throws RemoteException {
4587 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4588 mApp, subId, "registerImsEmergencyRegistrationCallback");
4589
4590 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4591 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4592 "IMS not available on device.");
4593 }
4594 final long token = Binder.clearCallingIdentity();
4595 try {
4596 int slotId = getSlotIndexOrException(subId);
4597 verifyImsMmTelConfiguredOrThrow(slotId);
4598
4599 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4600 if (controller != null) {
4601 ImsManager imsManager = controller.getImsManager(subId);
4602 if (imsManager != null) {
4603 imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId);
4604 } else {
4605 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4606 }
4607 } else {
4608 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4609 }
4610 } catch (ImsException e) {
4611 throw new ServiceSpecificException(e.getCode());
4612 } finally {
4613 Binder.restoreCallingIdentity(token);
4614 }
4615 }
4616
4617 /**
4618 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4619 * @param subId The subscription to use to check the configuration.
4620 * @param c The callback that will be used to send the result.
4621 */
4622 @Override
4623 public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) {
4624 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4625 mApp, subId, "unregisterImsEmergencyRegistrationCallback");
4626 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4627 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4628 }
4629 final long token = Binder.clearCallingIdentity();
4630
4631 try {
4632 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4633 if (controller != null) {
4634 ImsManager imsManager = controller.getImsManager(subId);
4635 if (imsManager != null) {
4636 imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId);
4637 } else {
4638 Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId
4639 + "is inactive, ignoring unregister.");
4640 // If the ImsManager is not valid, just return, since the callback
4641 // will already have been removed internally.
4642 }
4643 }
4644 } finally {
4645 Binder.restoreCallingIdentity(token);
4646 }
4647 }
4648
4649 /**
Brad Ebingera34a6c22019-10-22 17:36:18 -07004650 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4651 */
4652 @Override
4653 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4654 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4655 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4656 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4657 "IMS not available on device.");
4658 }
4659 final long token = Binder.clearCallingIdentity();
4660 try {
4661 Phone phone = getPhone(subId);
4662 if (phone == null) {
4663 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4664 + subId + "'");
4665 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4666 }
4667 phone.getImsRegistrationState(regState -> {
4668 try {
4669 consumer.accept((regState == null)
4670 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4671 } catch (RemoteException e) {
4672 // Ignore if the remote process is no longer available to call back.
4673 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4674 }
4675 });
4676 } finally {
4677 Binder.restoreCallingIdentity(token);
4678 }
4679 }
4680
4681 /**
4682 * Get the transport type for the IMS service registration state.
4683 */
4684 @Override
4685 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004686 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004687 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004688 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4689 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4690 "IMS not available on device.");
4691 }
4692 final long token = Binder.clearCallingIdentity();
4693 try {
4694 Phone phone = getPhone(subId);
4695 if (phone == null) {
4696 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4697 + subId + "'");
4698 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4699 }
4700 phone.getImsRegistrationTech(regTech -> {
4701 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4702 int regTechConverted = (regTech == null)
4703 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4704 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4705 regTechConverted);
4706 try {
4707 consumer.accept(regTechConverted);
4708 } catch (RemoteException e) {
4709 // Ignore if the remote process is no longer available to call back.
4710 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4711 }
4712 });
4713 } finally {
4714 Binder.restoreCallingIdentity(token);
4715 }
4716 }
4717
shilu366312e2019-12-17 09:28:10 -08004718 /**
4719 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4720 * @param subId The subscription to use to check the configuration.
4721 * @param c The callback that will be used to send the result.
4722 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004723 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004724 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4725 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004726 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004727 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004728 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4729 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4730 "IMS not available on device.");
4731 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004732 final long token = Binder.clearCallingIdentity();
4733 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004734 int slotId = getSlotIndexOrException(subId);
4735 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004736
4737 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4738 if (controller != null) {
4739 ImsManager imsManager = controller.getImsManager(subId);
4740 if (imsManager != null) {
4741 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4742 } else {
4743 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4744 }
4745 } else {
4746 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4747 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004748 } catch (ImsException e) {
4749 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004750 } finally {
4751 Binder.restoreCallingIdentity(token);
4752 }
4753 }
4754
shilu366312e2019-12-17 09:28:10 -08004755 /**
4756 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4757 * @param subId The subscription to use to check the configuration.
4758 * @param c The callback that will be used to send the result.
4759 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004760 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004761 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004762 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004763 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004764 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4765 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4766 }
Meng Wangafbc5852019-09-19 17:37:13 -07004767
4768 final long token = Binder.clearCallingIdentity();
4769 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004770 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4771 if (controller != null) {
4772 ImsManager imsManager = controller.getImsManager(subId);
4773 if (imsManager != null) {
4774 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4775 } else {
4776 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4777 + " is inactive, ignoring unregister.");
4778 // If the ImsManager is not valid, just return, since the callback
4779 // will already have been removed internally.
4780 }
4781 }
Meng Wangafbc5852019-09-19 17:37:13 -07004782 } finally {
4783 Binder.restoreCallingIdentity(token);
4784 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004785 }
4786
4787 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004788 public boolean isCapable(int subId, int capability, int regTech) {
4789 enforceReadPrivilegedPermission("isCapable");
joonhunshin4ac60942023-11-15 15:23:39 +00004790
4791 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4792 FEATURE_TELEPHONY_IMS, "isCapable");
4793
Brad Ebinger35c841c2018-10-01 10:40:55 -07004794 final long token = Binder.clearCallingIdentity();
4795 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004796 int slotId = getSlotIndexOrException(subId);
4797 verifyImsMmTelConfiguredOrThrow(slotId);
4798 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4799 } catch (com.android.ims.ImsException e) {
4800 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4801 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004802 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004803 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4804 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004805 } finally {
4806 Binder.restoreCallingIdentity(token);
4807 }
4808 }
4809
4810 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004811 public boolean isAvailable(int subId, int capability, int regTech) {
4812 enforceReadPrivilegedPermission("isAvailable");
joonhunshin4ac60942023-11-15 15:23:39 +00004813
4814 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4815 FEATURE_TELEPHONY_IMS, "isAvailable");
4816
Brad Ebinger35c841c2018-10-01 10:40:55 -07004817 final long token = Binder.clearCallingIdentity();
4818 try {
4819 Phone phone = getPhone(subId);
4820 if (phone == null) return false;
4821 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004822 } catch (com.android.ims.ImsException e) {
4823 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4824 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004825 } finally {
4826 Binder.restoreCallingIdentity(token);
4827 }
4828 }
4829
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004830 /**
4831 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4832 * subscription.
4833 * @param subId The subscription to use to check the configuration.
4834 * @param callback The callback that will be used to send the result.
4835 * @param capability The MmTelFeature capability that will be used to send the result.
4836 * @param transportType The transport type of the MmTelFeature capability.
4837 */
4838 @Override
4839 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4840 int transportType) {
4841 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004842 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4843 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4844 "IMS not available on device.");
4845 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004846 final long token = Binder.clearCallingIdentity();
4847 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004848 int slotId = getSlotIndex(subId);
4849 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4850 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4851 + subId + "'");
4852 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4853 }
4854 verifyImsMmTelConfiguredOrThrow(slotId);
4855 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4856 transportType, aBoolean -> {
4857 try {
4858 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4859 } catch (RemoteException e) {
4860 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4861 + "running. Ignore");
4862 }
4863 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004864 } catch (ImsException e) {
4865 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004866 } finally {
4867 Binder.restoreCallingIdentity(token);
4868 }
4869 }
4870
shilu366312e2019-12-17 09:28:10 -08004871 /**
4872 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4873 * @param subId The subscription to use to check the configuration.
4874 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004875 @Override
4876 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004877 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004878 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004879
joonhunshin4ac60942023-11-15 15:23:39 +00004880 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4881 FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled");
4882
Brad Ebinger35c841c2018-10-01 10:40:55 -07004883 final long token = Binder.clearCallingIdentity();
4884 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004885 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004886 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004887 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004888 } catch (ImsException e) {
4889 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004890 } finally {
4891 Binder.restoreCallingIdentity(token);
4892 }
4893 }
4894
4895 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004896 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004897 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004898 "setAdvancedCallingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004899
4900 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4901 FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled");
4902
Brad Ebinger35c841c2018-10-01 10:40:55 -07004903 final long identity = Binder.clearCallingIdentity();
4904 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004905 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004906 // This setting doesn't require an active ImsService connection, so do not verify. The
4907 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004908 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004909 } catch (ImsException e) {
4910 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004911 } finally {
4912 Binder.restoreCallingIdentity(identity);
4913 }
4914 }
4915
shilu366312e2019-12-17 09:28:10 -08004916 /**
4917 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4918 * @param subId The subscription to use to check the configuration.
4919 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004920 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004921 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004922 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004923 mApp, subId, "isVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004924
4925 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4926 FEATURE_TELEPHONY_IMS, "isVtSettingEnabled");
4927
Brad Ebinger35c841c2018-10-01 10:40:55 -07004928 final long identity = Binder.clearCallingIdentity();
4929 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004930 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004931 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004932 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004933 } catch (ImsException e) {
4934 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004935 } finally {
4936 Binder.restoreCallingIdentity(identity);
4937 }
4938 }
4939
4940 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004941 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004942 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004943 "setVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004944
4945 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4946 FEATURE_TELEPHONY_IMS, "setVtSettingEnabled");
4947
Brad Ebinger35c841c2018-10-01 10:40:55 -07004948 final long identity = Binder.clearCallingIdentity();
4949 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004950 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004951 // This setting doesn't require an active ImsService connection, so do not verify. The
4952 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004953 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004954 } catch (ImsException e) {
4955 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004956 } finally {
4957 Binder.restoreCallingIdentity(identity);
4958 }
4959 }
4960
shilu366312e2019-12-17 09:28:10 -08004961 /**
4962 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4963 * @param subId The subscription to use to check the configuration.
4964 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004965 @Override
4966 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004967 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004968 mApp, subId, "isVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004969
4970 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4971 FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled");
4972
Brad Ebinger35c841c2018-10-01 10:40:55 -07004973 final long identity = Binder.clearCallingIdentity();
4974 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004975 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004976 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004977 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004978 } catch (ImsException e) {
4979 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004980 } finally {
4981 Binder.restoreCallingIdentity(identity);
4982 }
4983 }
4984
4985 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004986 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004987 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004988 "setVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004989
4990 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4991 FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled");
4992
Brad Ebinger35c841c2018-10-01 10:40:55 -07004993 final long identity = Binder.clearCallingIdentity();
4994 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004995 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004996 // This setting doesn't require an active ImsService connection, so do not verify. The
4997 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004998 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004999 } catch (ImsException e) {
5000 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005001 } finally {
5002 Binder.restoreCallingIdentity(identity);
5003 }
5004 }
5005
shilu366312e2019-12-17 09:28:10 -08005006 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005007 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
5008 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5009 * @param subId The subscription to use to check the configuration.
5010 */
5011 @Override
5012 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005013 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005014 mApp, subId, "isCrossSimCallingEnabledByUser");
joonhunshin4ac60942023-11-15 15:23:39 +00005015
5016 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5017 FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser");
5018
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005019 final long identity = Binder.clearCallingIdentity();
5020 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005021 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005022 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005023 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005024 } catch (ImsException e) {
5025 throw new ServiceSpecificException(e.getCode());
5026 } finally {
5027 Binder.restoreCallingIdentity(identity);
5028 }
5029 }
5030
5031 /**
5032 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
5033 * Requires MODIFY_PHONE_STATE permission.
5034 * @param subId The subscription to use to check the configuration.
5035 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
5036 * false otherwise
5037 */
5038 @Override
5039 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
5040 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5041 "setCrossSimCallingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005042
5043 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5044 FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled");
5045
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005046 final long identity = Binder.clearCallingIdentity();
5047 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005048 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005049 // This setting doesn't require an active ImsService connection, so do not verify. The
5050 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005051 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005052 } catch (ImsException e) {
5053 throw new ServiceSpecificException(e.getCode());
5054 } finally {
5055 Binder.restoreCallingIdentity(identity);
5056 }
5057 }
5058
5059 /**
shilu366312e2019-12-17 09:28:10 -08005060 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5061 * @param subId The subscription to use to check the configuration.
5062 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005063 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07005064
Brad Ebinger35c841c2018-10-01 10:40:55 -07005065 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005066 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005067 mApp, subId, "isVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005068
5069 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5070 FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled");
5071
Brad Ebinger35c841c2018-10-01 10:40:55 -07005072 final long identity = Binder.clearCallingIdentity();
5073 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005074 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005075 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005076 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005077 } catch (ImsException e) {
5078 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005079 } finally {
5080 Binder.restoreCallingIdentity(identity);
5081 }
5082 }
5083
5084 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005085 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005086 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005087 "setVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005088
5089 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5090 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled");
5091
Brad Ebinger35c841c2018-10-01 10:40:55 -07005092 final long identity = Binder.clearCallingIdentity();
5093 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005094 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005095 // This setting doesn't require an active ImsService connection, so do not verify. The
5096 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005097 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005098 } catch (ImsException e) {
5099 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005100 } finally {
5101 Binder.restoreCallingIdentity(identity);
5102 }
5103 }
5104
5105 @Override
5106 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
5107 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5108 "setVoWiFiNonPersistent");
joonhunshin4ac60942023-11-15 15:23:39 +00005109
5110 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5111 FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent");
5112
Brad Ebinger35c841c2018-10-01 10:40:55 -07005113 final long identity = Binder.clearCallingIdentity();
5114 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005115 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005116 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005117 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005118 } catch (ImsException e) {
5119 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005120 } finally {
5121 Binder.restoreCallingIdentity(identity);
5122 }
5123 }
5124
shilu366312e2019-12-17 09:28:10 -08005125 /**
5126 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5127 * @param subId The subscription to use to check the configuration.
5128 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005129 @Override
5130 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005131 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005132 mApp, subId, "getVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005133
5134 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5135 FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting");
5136
Brad Ebinger35c841c2018-10-01 10:40:55 -07005137 final long identity = Binder.clearCallingIdentity();
5138 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005139 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005140 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005141 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005142 } catch (ImsException e) {
5143 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005144 } finally {
5145 Binder.restoreCallingIdentity(identity);
5146 }
5147 }
5148
5149 @Override
5150 public void setVoWiFiModeSetting(int subId, int mode) {
5151 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5152 "setVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005153
5154 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5155 FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting");
5156
Brad Ebinger35c841c2018-10-01 10:40:55 -07005157 final long identity = Binder.clearCallingIdentity();
5158 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005159 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005160 // This setting doesn't require an active ImsService connection, so do not verify. The
5161 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005162 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005163 } catch (ImsException e) {
5164 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005165 } finally {
5166 Binder.restoreCallingIdentity(identity);
5167 }
5168 }
5169
5170 @Override
5171 public int getVoWiFiRoamingModeSetting(int subId) {
5172 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005173
5174 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5175 FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting");
5176
Brad Ebinger35c841c2018-10-01 10:40:55 -07005177 final long identity = Binder.clearCallingIdentity();
5178 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005179 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005180 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005181 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005182 } catch (ImsException e) {
5183 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005184 } finally {
5185 Binder.restoreCallingIdentity(identity);
5186 }
5187 }
5188
5189 @Override
5190 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
5191 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5192 "setVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005193
5194 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5195 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting");
5196
Brad Ebinger35c841c2018-10-01 10:40:55 -07005197 final long identity = Binder.clearCallingIdentity();
5198 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005199 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005200 // This setting doesn't require an active ImsService connection, so do not verify. The
5201 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005202 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005203 } catch (ImsException e) {
5204 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005205 } finally {
5206 Binder.restoreCallingIdentity(identity);
5207 }
5208 }
5209
5210 @Override
5211 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
5212 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5213 "setRttCapabilityEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005214
5215 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5216 FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting");
5217
Brad Ebinger35c841c2018-10-01 10:40:55 -07005218 final long identity = Binder.clearCallingIdentity();
5219 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005220 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005221 // This setting doesn't require an active ImsService connection, so do not verify. The
5222 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005223 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005224 } catch (ImsException e) {
5225 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005226 } finally {
5227 Binder.restoreCallingIdentity(identity);
5228 }
5229 }
5230
shilu366312e2019-12-17 09:28:10 -08005231 /**
5232 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5233 * @param subId The subscription to use to check the configuration.
5234 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005235 @Override
5236 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005237 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005238 mApp, subId, "isTtyOverVolteEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005239
5240 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5241 FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled");
5242
Brad Ebinger35c841c2018-10-01 10:40:55 -07005243 final long identity = Binder.clearCallingIdentity();
5244 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005245 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005246 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005247 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005248 } catch (ImsException e) {
5249 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005250 } finally {
5251 Binder.restoreCallingIdentity(identity);
5252 }
5253 }
5254
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005255 @Override
5256 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5257 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005258
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005259 final long identity = Binder.clearCallingIdentity();
5260 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005261 if (!isImsAvailableOnDevice()) {
5262 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5263 "IMS not available on device.");
5264 }
5265 int slotId = getSlotIndexOrException(subId);
5266 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005267
5268 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5269 if (controller != null) {
5270 ImsManager imsManager = controller.getImsManager(subId);
5271 if (imsManager != null) {
5272 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5273 } else {
5274 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5275 }
5276 } else {
5277 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5278 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005279 } catch (ImsException e) {
5280 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005281 } finally {
5282 Binder.restoreCallingIdentity(identity);
5283 }
5284 }
5285
5286 @Override
5287 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5288 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005289
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005290 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005291 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5292 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5293 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005294 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005295 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5296 if (controller != null) {
5297 ImsManager imsManager = controller.getImsManager(subId);
5298 if (imsManager != null) {
5299 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5300 } else {
5301 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5302 + " is inactive, ignoring unregister.");
5303 // If the ImsManager is not valid, just return, since the callback will already
5304 // have been removed internally.
5305 }
5306 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005307 } finally {
5308 Binder.restoreCallingIdentity(identity);
5309 }
5310 }
5311
joonhunshincffb7fc2021-11-28 07:32:01 +00005312 @Override
5313 public void registerFeatureProvisioningChangedCallback(int subId,
5314 IFeatureProvisioningCallback callback) {
5315 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5316 mApp, subId, "registerFeatureProvisioningChangedCallback");
5317
5318 final long identity = Binder.clearCallingIdentity();
5319 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5320 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5321 }
5322
joonhunshin91bc1952022-04-29 08:47:15 +00005323 try {
5324 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5325 if (controller == null) {
5326 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5327 "Device does not support IMS");
5328 }
5329 controller.addFeatureProvisioningChangedCallback(subId, callback);
5330 } finally {
5331 Binder.restoreCallingIdentity(identity);
5332 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005333 }
5334
5335 @Override
5336 public void unregisterFeatureProvisioningChangedCallback(int subId,
5337 IFeatureProvisioningCallback callback) {
5338 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5339 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5340
5341 final long identity = Binder.clearCallingIdentity();
5342 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5343 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5344 }
5345
joonhunshin91bc1952022-04-29 08:47:15 +00005346 try {
5347 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5348 if (controller == null) {
5349 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5350 return;
5351 }
5352 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5353 } finally {
5354 Binder.restoreCallingIdentity(identity);
5355 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005356 }
allenwtsu99c623b2020-01-03 18:24:23 +08005357
5358 private void checkModifyPhoneStatePermission(int subId, String message) {
5359 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5360 message);
5361 }
5362
allenwtsu99c623b2020-01-03 18:24:23 +08005363 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005364 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005365 boolean isProvisioned) {
5366 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5367
joonhunshin4ac60942023-11-15 15:23:39 +00005368 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5369 FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability");
5370
allenwtsu99c623b2020-01-03 18:24:23 +08005371 final long identity = Binder.clearCallingIdentity();
5372 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005373 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5374 if (controller == null) {
5375 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5376 return;
5377 }
5378 controller.setRcsProvisioningStatusForCapability(
5379 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005380 } finally {
5381 Binder.restoreCallingIdentity(identity);
5382 }
allenwtsu99c623b2020-01-03 18:24:23 +08005383 }
5384
5385
5386 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005387 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5388 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5389 mApp, subId, "getRcsProvisioningStatusForCapability");
5390
joonhunshin4ac60942023-11-15 15:23:39 +00005391 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5392 FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability");
5393
allenwtsu99c623b2020-01-03 18:24:23 +08005394 final long identity = Binder.clearCallingIdentity();
5395 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005396 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5397 if (controller == null) {
5398 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5399
5400 // device does not support IMS, this method will return true always.
5401 return true;
5402 }
5403 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005404 } finally {
5405 Binder.restoreCallingIdentity(identity);
5406 }
5407 }
5408
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005409 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005410 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5411 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005412 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005413
joonhunshin4ac60942023-11-15 15:23:39 +00005414 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5415 FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability");
5416
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005417 final long identity = Binder.clearCallingIdentity();
5418 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005419 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5420 if (controller == null) {
5421 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5422 return;
5423 }
5424 controller.setImsProvisioningStatusForCapability(
5425 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005426 } finally {
5427 Binder.restoreCallingIdentity(identity);
5428 }
5429 }
5430
5431 @Override
5432 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005433 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5434 mApp, subId, "getProvisioningStatusForCapability");
5435
joonhunshin4ac60942023-11-15 15:23:39 +00005436 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5437 FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability");
5438
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005439 final long identity = Binder.clearCallingIdentity();
5440 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005441 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5442 if (controller == null) {
5443 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005444
joonhunshin91bc1952022-04-29 08:47:15 +00005445 // device does not support IMS, this method will return true always.
5446 return true;
5447 }
5448 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005449 } finally {
5450 Binder.restoreCallingIdentity(identity);
5451 }
5452 }
5453
5454 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005455 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5456 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5457 mApp, subId, "isProvisioningRequiredForCapability");
5458
joonhunshin4ac60942023-11-15 15:23:39 +00005459 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5460 FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability");
5461
joonhunshincffb7fc2021-11-28 07:32:01 +00005462 final long identity = Binder.clearCallingIdentity();
5463 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005464 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5465 if (controller == null) {
5466 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5467
5468 // device does not support IMS, this method will return false
5469 return false;
5470 }
5471 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005472 } finally {
5473 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005474 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005475 }
5476
5477 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005478 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5479 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5480 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005481
joonhunshin4ac60942023-11-15 15:23:39 +00005482 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5483 FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability");
5484
joonhunshincffb7fc2021-11-28 07:32:01 +00005485 final long identity = Binder.clearCallingIdentity();
5486 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005487 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5488 if (controller == null) {
5489 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5490
5491 // device does not support IMS, this method will return false
5492 return false;
5493 }
5494 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005495 } finally {
5496 Binder.restoreCallingIdentity(identity);
5497 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005498 }
5499
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005500 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005501 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005502 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5503 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5504 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005505 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5506 mApp, subId, "getImsProvisioningInt");
5507
joonhunshin4ac60942023-11-15 15:23:39 +00005508 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5509 FEATURE_TELEPHONY_IMS, "getImsProvisioningInt");
5510
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005511 final long identity = Binder.clearCallingIdentity();
5512 try {
5513 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005514 int slotId = getSlotIndex(subId);
5515 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5516 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5517 + subId + "' for key:" + key);
5518 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5519 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005520
joonhunshin91bc1952022-04-29 08:47:15 +00005521 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5522 if (controller == null) {
5523 loge("getImsProvisioningInt: Device does not support IMS");
5524
5525 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5526 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5527 }
5528 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005529 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5530 return retVal;
5531 }
5532
calvinpanb5a34062021-02-08 19:59:36 +08005533 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005534 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005535 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5536 + subId + "' for key:" + key);
5537 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005538 } finally {
5539 Binder.restoreCallingIdentity(identity);
5540 }
5541 }
5542
5543 @Override
5544 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005545 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5546 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5547 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005548 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5549 mApp, subId, "getImsProvisioningString");
5550
joonhunshin4ac60942023-11-15 15:23:39 +00005551 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5552 FEATURE_TELEPHONY_IMS, "getImsProvisioningString");
5553
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005554 final long identity = Binder.clearCallingIdentity();
5555 try {
5556 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005557 int slotId = getSlotIndex(subId);
5558 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5559 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5560 + subId + "' for key:" + key);
5561 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5562 }
calvinpanb5a34062021-02-08 19:59:36 +08005563 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005564 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005565 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5566 + subId + "' for key:" + key);
5567 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005568 } finally {
5569 Binder.restoreCallingIdentity(identity);
5570 }
5571 }
5572
5573 @Override
5574 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005575 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5576 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5577 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005578 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5579 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005580
joonhunshin4ac60942023-11-15 15:23:39 +00005581 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5582 FEATURE_TELEPHONY_IMS, "setImsProvisioningInt");
5583
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005584 final long identity = Binder.clearCallingIdentity();
5585 try {
5586 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005587 int slotId = getSlotIndex(subId);
5588 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5589 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5590 + subId + "' for key:" + key);
5591 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5592 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005593
joonhunshin91bc1952022-04-29 08:47:15 +00005594 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5595 if (controller == null) {
5596 loge("setImsProvisioningInt: Device does not support IMS");
5597
5598 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5599 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5600 }
5601 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005602 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5603 return retVal;
5604 }
5605
calvinpanb5a34062021-02-08 19:59:36 +08005606 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5607 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005608 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005609 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005610 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005611 } finally {
5612 Binder.restoreCallingIdentity(identity);
5613 }
5614 }
5615
5616 @Override
5617 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005618 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5619 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5620 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005621 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5622 "setImsProvisioningString");
joonhunshin4ac60942023-11-15 15:23:39 +00005623
5624 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5625 FEATURE_TELEPHONY_IMS, "setImsProvisioningString");
5626
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005627 final long identity = Binder.clearCallingIdentity();
5628 try {
5629 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005630 int slotId = getSlotIndex(subId);
5631 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5632 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5633 + subId + "' for key:" + key);
5634 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5635 }
calvinpanb5a34062021-02-08 19:59:36 +08005636 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5637 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005638 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005639 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005640 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005641 } finally {
5642 Binder.restoreCallingIdentity(identity);
5643 }
5644 }
5645
Brad Ebinger919631e2021-06-02 17:46:35 -07005646 /**
5647 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5648 * for the given slot ID or no ImsResolver instance has been created.
5649 * @param slotId The slot ID that the IMS service is created for.
5650 * @throws ImsException If there is no ImsService configured for this slot.
5651 */
5652 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5653 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5654 ImsFeature.FEATURE_MMTEL)) {
5655 throw new ImsException("This subscription does not support MMTEL over IMS",
5656 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5657 }
5658 }
5659
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005660 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005661 int slotId = SubscriptionManager.getSlotIndex(subId);
5662 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005663 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5664 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005665 }
5666 return slotId;
5667 }
5668
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005669 private int getSlotIndex(int subId) {
5670 int slotId = SubscriptionManager.getSlotIndex(subId);
5671 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5672 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5673 }
5674 return slotId;
5675 }
5676
Wink Saville36469e72014-06-11 15:17:00 -07005677 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005678 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005679 */
5680 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005681 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5682 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005683 try {
5684 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5685 } catch (SecurityException se) {
5686 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5687 throw new SecurityException("Package " + callingPackage + " does not belong to "
5688 + Binder.getCallingUid());
5689 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005690 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005691 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005692 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005693 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005694 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005695 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005696 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005697 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5698 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005699
joonhunshin4ac60942023-11-15 15:23:39 +00005700 enforceTelephonyFeatureWithException(callingPackage,
5701 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber");
5702
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005703 final long identity = Binder.clearCallingIdentity();
5704 try {
5705 final Phone phone = getPhone(subId);
5706 if (phone != null) {
5707 return phone.getServiceState().getDataNetworkType();
5708 } else {
5709 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5710 }
5711 } finally {
5712 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005713 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005714 }
5715
5716 /**
5717 * Returns the data network type
5718 */
5719 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005720 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005721 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005722 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005723 }
5724
5725 /**
5726 * Returns the data network type for a subId
5727 */
5728 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005729 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5730 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005731 String functionName = "getDataNetworkTypeForSubscriber";
5732 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5733 mApp, functionName)) {
5734 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5735 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5736 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5737 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005738 }
5739
joonhunshin4ac60942023-11-15 15:23:39 +00005740 enforceTelephonyFeatureWithException(callingPackage,
5741 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber");
5742
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005743 final long identity = Binder.clearCallingIdentity();
5744 try {
5745 final Phone phone = getPhone(subId);
5746 if (phone != null) {
5747 return phone.getServiceState().getDataNetworkType();
5748 } else {
5749 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5750 }
5751 } finally {
5752 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005753 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005754 }
5755
5756 /**
Wink Saville36469e72014-06-11 15:17:00 -07005757 * Returns the Voice network type for a subId
5758 */
5759 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005760 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5761 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005762 String functionName = "getVoiceNetworkTypeForSubscriber";
5763 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5764 mApp, functionName)) {
5765 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5766 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5767 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5768 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005769 }
5770
joonhunshin4ac60942023-11-15 15:23:39 +00005771 enforceTelephonyFeatureWithException(callingPackage,
5772 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber");
5773
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005774 final long identity = Binder.clearCallingIdentity();
5775 try {
5776 final Phone phone = getPhone(subId);
5777 if (phone != null) {
5778 return phone.getServiceState().getVoiceNetworkType();
5779 } else {
5780 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5781 }
5782 } finally {
5783 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005784 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005785 }
5786
5787 /**
5788 * @return true if a ICC card is present
5789 */
5790 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005791 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005792 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005793 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005794 }
5795
5796 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005797 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005798 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005799 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005800 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00005801 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5802 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex");
5803
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005804 final long identity = Binder.clearCallingIdentity();
5805 try {
5806 final Phone phone = PhoneFactory.getPhone(slotIndex);
5807 if (phone != null) {
5808 return phone.getIccCard().hasIccCard();
5809 } else {
5810 return false;
5811 }
5812 } finally {
5813 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005814 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005815 }
5816
5817 /**
5818 * Return if the current radio is LTE on CDMA. This
5819 * is a tri-state return value as for a period of time
5820 * the mode may be unknown.
5821 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005822 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005823 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005824 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005825 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005826 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005827 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5828 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5829 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005830 }
5831
Sanket Padawe356d7632015-06-22 14:03:32 -07005832 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005833 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5834 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005835 try {
5836 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5837 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005838 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5839 }
5840
joonhunshin4ac60942023-11-15 15:23:39 +00005841 enforceTelephonyFeatureWithException(callingPackage,
5842 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber");
5843
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005844 final long identity = Binder.clearCallingIdentity();
5845 try {
5846 final Phone phone = getPhone(subId);
5847 if (phone == null) {
5848 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5849 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005850 return TelephonyProperties.lte_on_cdma_device()
5851 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005852 }
5853 } finally {
5854 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005855 }
Wink Saville36469e72014-06-11 15:17:00 -07005856 }
5857
Wink Saville36469e72014-06-11 15:17:00 -07005858 /**
5859 * {@hide}
5860 * Returns Default subId, 0 in the case of single standby.
5861 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005862 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005863 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005864 }
5865
Shishir Agrawala9f32182016-04-12 12:00:16 -07005866 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005867 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005868 }
5869
Wink Savilleb564aae2014-10-23 10:18:09 -07005870 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005871 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005872 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005873
Pengquan Menge92a50d2018-09-21 15:54:48 -07005874 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005875 return getSubscriptionManagerService().isActiveSubId(subId,
5876 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005877 }
5878
Ihab Awadf2177b72013-11-25 13:33:23 -08005879 /**
5880 * @see android.telephony.TelephonyManager.WifiCallingChoices
5881 */
5882 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005883 final long identity = Binder.clearCallingIdentity();
5884 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005885 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005886 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5887 getWhenToMakeWifiCallsDefaultPreference());
5888 } finally {
5889 Binder.restoreCallingIdentity(identity);
5890 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005891 }
5892
5893 /**
5894 * @see android.telephony.TelephonyManager.WifiCallingChoices
5895 */
5896 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005897 final long identity = Binder.clearCallingIdentity();
5898 try {
5899 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005900 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005901 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5902 } finally {
5903 Binder.restoreCallingIdentity(identity);
5904 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005905 }
5906
Sailesh Nepald1e68152013-12-12 19:08:02 -08005907 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005908 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005909 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005910 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005911
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005912 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5913 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5914 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005915 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005916 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005917 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005918 }
5919 return PhoneFactory.getPhone(phoneId);
5920 }
5921
Shishir Agrawal566b7612013-10-28 14:41:00 -07005922 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005923 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005924 @NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00005925
Rambo Wanga1782702021-11-10 20:15:19 -08005926 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5927 /*message=*/ "iccOpenLogicalChannel");
5928
5929 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5930 // Verify that the callingPackage in the request belongs to the calling UID
5931 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5932
joonhunshin4ac60942023-11-15 15:23:39 +00005933 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5934 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel");
5935
Rambo Wanga1782702021-11-10 20:15:19 -08005936 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005937 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005938
Rambo Wanga1782702021-11-10 20:15:19 -08005939 private Phone getPhoneFromValidIccLogicalChannelRequest(
5940 @NonNull IccLogicalChannelRequest request, String message) {
5941 Phone phone;
5942 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5943 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5944 mApp, request.subId, message);
5945 phone = getPhoneFromSubId(request.subId);
5946 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5947 enforceModifyPermission();
5948 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5949 } else {
5950 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005951 }
Rambo Wanga1782702021-11-10 20:15:19 -08005952 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005953 }
5954
5955 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005956 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005957 final long identity = Binder.clearCallingIdentity();
5958 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005959 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005960 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005961 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5962 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005963 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5964 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005965 loge("The calling package is not allowed to access ISD-R.");
5966 throw new SecurityException(
5967 "The calling package is not allowed to access ISD-R.");
5968 }
Derek Tan740e1672017-06-27 14:56:27 -07005969 }
Derek Tan740e1672017-06-27 14:56:27 -07005970
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005971 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005972 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5973 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005974 return response;
5975 } finally {
5976 Binder.restoreCallingIdentity(identity);
5977 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005978 }
5979
5980 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005981 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00005982 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5983 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel");
5984
Rambo Wanga1782702021-11-10 20:15:19 -08005985 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5986 /*message=*/"iccCloseLogicalChannel");
5987
5988 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5989
5990 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005991 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005992
Rambo Wanga1782702021-11-10 20:15:19 -08005993 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5994 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005995 // before this feature is enabled, this API should only return false if
5996 // the operation fails instead of throwing runtime exception for
5997 // backward-compatibility.
5998 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5999 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006000 final long identity = Binder.clearCallingIdentity();
6001 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006002 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08006003 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006004 }
Chen Xue9d737e2022-01-01 23:41:31 -08006005 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08006006 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08006007 Boolean success = false;
6008 if (result instanceof RuntimeException) {
6009 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08006010 if (shouldThrowExceptionOnFailure) {
6011 throw (RuntimeException) result;
6012 } else {
6013 return false;
6014 }
Chen Xue9d737e2022-01-01 23:41:31 -08006015 } else if (result instanceof Boolean) {
6016 success = (Boolean) result;
6017 } else {
6018 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
6019 }
Rambo Wanga1782702021-11-10 20:15:19 -08006020 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006021 return success;
6022 } finally {
6023 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006024 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006025 }
6026
6027 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006028 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07006029 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006030 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6031 mApp, subId, "iccTransmitApduLogicalChannel");
joonhunshin4ac60942023-11-15 15:23:39 +00006032
6033 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6034 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel");
6035
Jordan Liu4c733742019-02-28 12:03:40 -08006036 if (DBG) {
6037 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
6038 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
6039 + p3 + " data=" + data);
6040 }
6041 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
6042 command, p1, p2, p3, data);
6043 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006044
Jordan Liu4c733742019-02-28 12:03:40 -08006045 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006046 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006047 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006048 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006049
6050 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6051 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
6052 "iccTransmitApduLogicalChannelBySlot");
6053
Jordan Liu4c733742019-02-28 12:03:40 -08006054 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006055 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006056 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
6057 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006058 }
6059 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006060 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
6061 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006062 }
6063
6064 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
6065 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006066 final long identity = Binder.clearCallingIdentity();
6067 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07006068 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006069 return "";
6070 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006071
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006072 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006073 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
6074 null /* workSource */);
6075 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006076
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006077 // Append the returned status code to the end of the response payload.
6078 String s = Integer.toHexString(
6079 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6080 if (response.payload != null) {
6081 s = IccUtils.bytesToHexString(response.payload) + s;
6082 }
6083 return s;
6084 } finally {
6085 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006086 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006087 }
Jake Hambye994d462014-02-03 13:10:13 -08006088
Evan Charltonc66da362014-05-16 14:06:40 -07006089 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006090 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
6091 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006092 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6093 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006094 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006095
6096 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6097 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel");
6098
Jordan Liu4c733742019-02-28 12:03:40 -08006099 if (DBG) {
6100 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
6101 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
6102 }
6103 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
6104 cla, command, p1, p2, p3, data);
6105 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006106
Jordan Liu4c733742019-02-28 12:03:40 -08006107 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006108 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006109 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006110 enforceModifyPermission();
6111 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006112
6113 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6114 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot");
6115
Jordan Liu4c733742019-02-28 12:03:40 -08006116 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006117 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006118 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
6119 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006120 }
6121
6122 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006123 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
6124 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006125 }
6126
6127 // open APDU basic channel assuming the caller has sufficient permissions
6128 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
6129 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006130 final long identity = Binder.clearCallingIdentity();
6131 try {
6132 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
6133 && TextUtils.equals(ISDR_AID, data)) {
6134 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006135 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6136 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006137 if (bestComponent == null
6138 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
6139 loge("The calling package is not allowed to select ISD-R.");
6140 throw new SecurityException(
6141 "The calling package is not allowed to select ISD-R.");
6142 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006143 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006144
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006145 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006146 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
6147 null /* workSource */);
6148 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006149
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006150 // Append the returned status code to the end of the response payload.
6151 String s = Integer.toHexString(
6152 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6153 if (response.payload != null) {
6154 s = IccUtils.bytesToHexString(response.payload) + s;
6155 }
6156 return s;
6157 } finally {
6158 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006159 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006160 }
6161
6162 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006163 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006164 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006165 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6166 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006167
joonhunshin4ac60942023-11-15 15:23:39 +00006168 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6169 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO");
6170
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006171 final long identity = Binder.clearCallingIdentity();
6172 try {
6173 if (DBG) {
6174 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
6175 + p1 + " " + p2 + " " + p3 + ":" + filePath);
6176 }
6177
6178 IccIoResult response =
6179 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
6180 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
6181 subId);
6182
6183 if (DBG) {
6184 log("Exchange SIM_IO [R]" + response);
6185 }
6186
6187 byte[] result = null;
6188 int length = 2;
6189 if (response.payload != null) {
6190 length = 2 + response.payload.length;
6191 result = new byte[length];
6192 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
6193 } else {
6194 result = new byte[length];
6195 }
6196
6197 result[length - 1] = (byte) response.sw2;
6198 result[length - 2] = (byte) response.sw1;
6199 return result;
6200 } finally {
6201 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006202 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006203 }
6204
Nathan Haroldb3014052017-01-25 15:57:32 -08006205 /**
6206 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
6207 * on a particular subscription
6208 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006209 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
6210 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07006211 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006212 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07006213 return null;
6214 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006215
joonhunshin4ac60942023-11-15 15:23:39 +00006216 enforceTelephonyFeatureWithException(callingPackage,
6217 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns");
6218
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006219 final long identity = Binder.clearCallingIdentity();
6220 try {
6221 if (appType != TelephonyManager.APPTYPE_USIM
6222 && appType != TelephonyManager.APPTYPE_SIM) {
6223 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
6224 return null;
6225 }
6226 Object response = sendRequest(
6227 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
6228 if (response instanceof String[]) {
6229 return (String[]) response;
6230 }
yincheng zhao2737e882019-09-06 17:06:54 -07006231 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006232 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08006233 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006234 } finally {
6235 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08006236 }
Nathan Haroldb3014052017-01-25 15:57:32 -08006237 }
6238
yincheng zhao2737e882019-09-06 17:06:54 -07006239 /**
6240 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
6241 * subscription.
6242 *
6243 * @param subId the id of the subscription.
6244 * @param appType the uicc app type, must be USIM or SIM.
6245 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
6246 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006247 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07006248 * @return number of fplmns that is successfully written to the SIM.
6249 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006250 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
6251 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07006252 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6253 mApp, subId, "setForbiddenPlmns");
6254
joonhunshin4ac60942023-11-15 15:23:39 +00006255 enforceTelephonyFeatureWithException(callingPackage,
6256 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns");
6257
yincheng zhao2737e882019-09-06 17:06:54 -07006258 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
6259 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
6260 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
6261 }
6262 if (fplmns == null) {
6263 throw new IllegalArgumentException("Fplmn List provided is null");
6264 }
6265 for (String fplmn : fplmns) {
6266 if (!CellIdentity.isValidPlmn(fplmn)) {
6267 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
6268 }
6269 }
6270 final long identity = Binder.clearCallingIdentity();
6271 try {
6272 Object response = sendRequest(
6273 CMD_SET_FORBIDDEN_PLMNS,
6274 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
6275 subId);
6276 return (int) response;
6277 } finally {
6278 Binder.restoreCallingIdentity(identity);
6279 }
6280 }
6281
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006282 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006283 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006284 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6285 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07006286
joonhunshin4ac60942023-11-15 15:23:39 +00006287 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6288 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus");
6289
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006290 final long identity = Binder.clearCallingIdentity();
6291 try {
6292 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
6293 if (response.payload == null) {
6294 return "";
6295 }
Evan Charltonc66da362014-05-16 14:06:40 -07006296
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006297 // Append the returned status code to the end of the response payload.
6298 String s = Integer.toHexString(
6299 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6300 s = IccUtils.bytesToHexString(response.payload) + s;
6301 return s;
6302 } finally {
6303 Binder.restoreCallingIdentity(identity);
6304 }
Evan Charltonc66da362014-05-16 14:06:40 -07006305 }
6306
Jake Hambye994d462014-02-03 13:10:13 -08006307 /**
6308 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6309 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6310 *
6311 * @param itemID the ID of the item to read
6312 * @return the NV item as a String, or null on error.
6313 */
6314 @Override
6315 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006316 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006317 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6318 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006319
6320 final long identity = Binder.clearCallingIdentity();
6321 try {
6322 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07006323 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006324 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
6325 return value;
6326 } finally {
6327 Binder.restoreCallingIdentity(identity);
6328 }
Jake Hambye994d462014-02-03 13:10:13 -08006329 }
6330
6331 /**
6332 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6333 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6334 *
6335 * @param itemID the ID of the item to read
6336 * @param itemValue the value to write, as a String
6337 * @return true on success; false on any failure
6338 */
6339 @Override
6340 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006341 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006342 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6343 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006344
6345 final long identity = Binder.clearCallingIdentity();
6346 try {
6347 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6348 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006349 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006350 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6351 return success;
6352 } finally {
6353 Binder.restoreCallingIdentity(identity);
6354 }
Jake Hambye994d462014-02-03 13:10:13 -08006355 }
6356
6357 /**
6358 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6359 * Used for device configuration by some CDMA operators.
6360 *
6361 * @param preferredRoamingList byte array containing the new PRL
6362 * @return true on success; false on any failure
6363 */
6364 @Override
6365 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006366 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6367 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006368
6369 final long identity = Binder.clearCallingIdentity();
6370 try {
6371 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6372 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6373 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6374 return success;
6375 } finally {
6376 Binder.restoreCallingIdentity(identity);
6377 }
Jake Hambye994d462014-02-03 13:10:13 -08006378 }
6379
6380 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006381 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006382 * Used for device configuration by some CDMA operators.
6383 *
chen xu6dac5ab2018-10-26 17:39:23 -07006384 * @param slotIndex - device slot.
6385 *
Jake Hambye994d462014-02-03 13:10:13 -08006386 * @return true on success; false on any failure
6387 */
6388 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006389 public boolean resetModemConfig(int slotIndex) {
6390 Phone phone = PhoneFactory.getPhone(slotIndex);
6391 if (phone != null) {
6392 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6393 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006394
joonhunshin4ac60942023-11-15 15:23:39 +00006395 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6396 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig");
6397
chen xu6dac5ab2018-10-26 17:39:23 -07006398 final long identity = Binder.clearCallingIdentity();
6399 try {
6400 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6401 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6402 return success;
6403 } finally {
6404 Binder.restoreCallingIdentity(identity);
6405 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006406 }
chen xu6dac5ab2018-10-26 17:39:23 -07006407 return false;
6408 }
6409
6410 /**
6411 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6412 *
6413 * @param slotIndex - device slot.
6414 *
6415 * @return true on success; false on any failure
6416 */
6417 @Override
6418 public boolean rebootModem(int slotIndex) {
6419 Phone phone = PhoneFactory.getPhone(slotIndex);
6420 if (phone != null) {
6421 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6422 mApp, phone.getSubId(), "rebootModem");
6423
joonhunshin4ac60942023-11-15 15:23:39 +00006424 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6425 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem");
6426
chen xu6dac5ab2018-10-26 17:39:23 -07006427 final long identity = Binder.clearCallingIdentity();
6428 try {
6429 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6430 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6431 return success;
6432 } finally {
6433 Binder.restoreCallingIdentity(identity);
6434 }
6435 }
6436 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006437 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006438
Brad Ebinger51f743a2017-01-23 13:50:20 -08006439 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006440 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6441 * {@link #disableIms(int)}.
6442 * @param slotIndex device slot.
6443 */
6444 public void resetIms(int slotIndex) {
6445 enforceModifyPermission();
6446
joonhunshin4ac60942023-11-15 15:23:39 +00006447 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6448 PackageManager.FEATURE_TELEPHONY_IMS, "resetIms");
6449
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006450 final long identity = Binder.clearCallingIdentity();
6451 try {
6452 if (mImsResolver == null) {
6453 // may happen if the does not support IMS.
6454 return;
6455 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006456 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006457 } finally {
6458 Binder.restoreCallingIdentity(identity);
6459 }
6460 }
6461
6462 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006463 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6464 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006465 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006466 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006467 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006468
6469 final long identity = Binder.clearCallingIdentity();
6470 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006471 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006472 // may happen if the device does not support IMS.
6473 return;
6474 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006475 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006476 } finally {
6477 Binder.restoreCallingIdentity(identity);
6478 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006479 }
6480
6481 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006482 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6483 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006484 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006485 public void disableIms(int slotId) {
6486 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006487
6488 final long identity = Binder.clearCallingIdentity();
6489 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006490 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006491 // may happen if the device does not support IMS.
6492 return;
6493 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006494 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006495 } finally {
6496 Binder.restoreCallingIdentity(identity);
6497 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006498 }
6499
6500 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006501 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6502 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006503 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006504 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006505 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006506 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006507
6508 final long identity = Binder.clearCallingIdentity();
6509 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006510 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006511 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6512 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006513 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006514 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006515 } finally {
6516 Binder.restoreCallingIdentity(identity);
6517 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006518 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006519 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006520 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6521 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006522 @Override
6523 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006524 enforceModifyPermission();
6525
6526 final long identity = Binder.clearCallingIdentity();
6527 try {
6528 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006529 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006530 } finally {
6531 Binder.restoreCallingIdentity(identity);
6532 }
6533 }
6534
6535 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006536 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006537 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006538 */
6539 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6540 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006541
6542 final long identity = Binder.clearCallingIdentity();
6543 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006544 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006545 // may happen if the device does not support IMS.
6546 return null;
6547 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006548 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006549 } finally {
6550 Binder.restoreCallingIdentity(identity);
6551 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006552 }
6553
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006554 /**
6555 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006556 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006557 */
6558 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6559 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006560
6561 final long identity = Binder.clearCallingIdentity();
6562 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006563 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006564 // may happen if the device does not support IMS.
6565 return null;
6566 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006567 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006568 } finally {
6569 Binder.restoreCallingIdentity(identity);
6570 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006571 }
6572
Brad Ebinger884c07b2018-02-15 16:17:40 -08006573 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006574 * Sets the ImsService Package Name that Telephony will bind to.
6575 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006576 * @param slotIndex the slot ID that the ImsService should bind for.
6577 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006578 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006579 * @param featureTypes An integer array of feature types associated with a packageName.
6580 * @param packageName The name of the package that the current configuration will be replaced
6581 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006582 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006583 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006584 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6585 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006586 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006587 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006588 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006589
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006590 final long identity = Binder.clearCallingIdentity();
6591 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006592 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006593 // may happen if the device does not support IMS.
6594 return false;
6595 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006596 Map<Integer, String> featureConfig = new HashMap<>();
6597 for (int featureType : featureTypes) {
6598 featureConfig.put(featureType, packageName);
6599 }
6600 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6601 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006602 } finally {
6603 Binder.restoreCallingIdentity(identity);
6604 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006605 }
6606
6607 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006608 * Clears any carrier ImsService overrides for the slot index specified that were previously
6609 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6610 *
6611 * This should only be used for testing.
6612 *
6613 * @param slotIndex the slot ID that the ImsService should bind for.
6614 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6615 */
6616 @Override
6617 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006618 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6619 "clearCarrierImsServiceOverride");
6620 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006621 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006622
6623 final long identity = Binder.clearCallingIdentity();
6624 try {
6625 if (mImsResolver == null) {
6626 // may happen if the device does not support IMS.
6627 return false;
6628 }
6629 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6630 } finally {
6631 Binder.restoreCallingIdentity(identity);
6632 }
6633 }
6634
6635 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006636 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006637 *
6638 * @param slotId The slot that the ImsService is associated with.
6639 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6640 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006641 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006642 * @return the package name of the ImsService configuration.
6643 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006644 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6645 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006646 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006647 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6648 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006649
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006650 final long identity = Binder.clearCallingIdentity();
6651 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006652 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006653 // may happen if the device does not support IMS.
6654 return "";
6655 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006656 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006657 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6658 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006659 } finally {
6660 Binder.restoreCallingIdentity(identity);
6661 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006662 }
6663
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006664 /**
6665 * Get the MmTelFeature state associated with the requested subscription id.
6666 * @param subId The subscription that the MmTelFeature is associated with.
6667 * @param callback A callback with an integer containing the
6668 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6669 */
6670 @Override
6671 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6672 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006673 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6674 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6675 "IMS not available on device.");
6676 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006677 final long token = Binder.clearCallingIdentity();
6678 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006679 int slotId = getSlotIndex(subId);
6680 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6681 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6682 + subId + "'");
6683 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6684 }
6685 verifyImsMmTelConfiguredOrThrow(slotId);
6686 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6687 try {
6688 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6689 } catch (RemoteException e) {
6690 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6691 + "Ignore");
6692 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006693 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006694 } catch (ImsException e) {
6695 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006696 } finally {
6697 Binder.restoreCallingIdentity(token);
6698 }
6699 }
6700
Daniel Brightbb5840b2021-01-12 15:48:18 -08006701 /**
6702 * Sets the ims registration state on all valid {@link Phone}s.
6703 */
6704 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006705 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006706
6707 final long identity = Binder.clearCallingIdentity();
6708 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006709 // NOTE: Before S, this method only set the default phone.
6710 for (final Phone phone : PhoneFactory.getPhones()) {
6711 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6712 phone.setImsRegistrationState(registered);
6713 }
6714 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006715 } finally {
6716 Binder.restoreCallingIdentity(identity);
6717 }
Wink Saville36469e72014-06-11 15:17:00 -07006718 }
6719
6720 /**
Stuart Scott54788802015-03-30 13:18:01 -07006721 * Set the network selection mode to automatic.
6722 *
6723 */
6724 @Override
6725 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006726 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6727 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006728
joonhunshin4ac60942023-11-15 15:23:39 +00006729 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6730 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic");
6731
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006732 final long identity = Binder.clearCallingIdentity();
6733 try {
shilufc958392020-01-20 11:36:01 -08006734 if (!isActiveSubscription(subId)) {
6735 return;
6736 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006737 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006738 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6739 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006740 } finally {
6741 Binder.restoreCallingIdentity(identity);
6742 }
Stuart Scott54788802015-03-30 13:18:01 -07006743 }
6744
Jack Yud10cdd42020-09-28 20:28:01 -07006745 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006746 * Ask the radio to connect to the input network and change selection mode to manual.
6747 *
6748 * @param subId the id of the subscription.
6749 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6750 * the operator to attach to.
6751 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6752 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6753 * normal network selection next time.
6754 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006755 */
6756 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006757 public boolean setNetworkSelectionModeManual(
6758 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006759 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6760 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006761
joonhunshin4ac60942023-11-15 15:23:39 +00006762 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6763 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual");
6764
Jack Yu285100e2022-12-02 22:48:35 -08006765 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006766 if (!isActiveSubscription(subId)) {
6767 return false;
6768 }
6769
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006770 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006771 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006772 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006773 if (DBG) {
6774 log("setNetworkSelectionModeManual: subId: " + subId
6775 + " operator: " + operatorInfo);
6776 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006777 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6778 } finally {
6779 Binder.restoreCallingIdentity(identity);
6780 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006781 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006782 /**
shilu84f6e8b2019-12-19 13:58:01 -08006783 * Get the manual network selection
6784 *
6785 * @param subId the id of the subscription.
6786 *
6787 * @return the previously saved user selected PLMN
6788 */
6789 @Override
6790 public String getManualNetworkSelectionPlmn(int subId) {
6791 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006792 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6793 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006794
joonhunshin4ac60942023-11-15 15:23:39 +00006795 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6796 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn");
6797
shilu84f6e8b2019-12-19 13:58:01 -08006798 final long identity = Binder.clearCallingIdentity();
6799 try {
6800 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006801 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006802 }
6803
6804 final Phone phone = getPhone(subId);
6805 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006806 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006807 }
6808 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6809 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006810 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006811 } finally {
6812 Binder.restoreCallingIdentity(identity);
6813 }
6814 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006815
6816 /**
6817 * Scans for available networks.
6818 */
6819 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006820 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6821 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006822 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6823 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006824 LocationAccessPolicy.LocationPermissionResult locationResult =
6825 LocationAccessPolicy.checkLocationPermission(mApp,
6826 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6827 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006828 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006829 .setCallingPid(Binder.getCallingPid())
6830 .setCallingUid(Binder.getCallingUid())
6831 .setMethod("getCellNetworkScanResults")
6832 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006833 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6834 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006835 .build());
6836 switch (locationResult) {
6837 case DENIED_HARD:
6838 throw new SecurityException("Not allowed to access scan results -- location");
6839 case DENIED_SOFT:
6840 return null;
6841 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006842
Pengquan Menga1bb6272018-09-06 09:59:22 -07006843 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006844 try {
6845 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006846 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006847 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006848 } finally {
6849 Binder.restoreCallingIdentity(identity);
6850 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006851 }
6852
6853 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006854 * Get the call forwarding info, given the call forwarding reason.
6855 */
6856 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006857 public void getCallForwarding(int subId, int callForwardingReason,
6858 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006859 enforceReadPrivilegedPermission("getCallForwarding");
joonhunshin4ac60942023-11-15 15:23:39 +00006860
6861 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6862 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding");
6863
Shuo Qian4a594052020-01-23 11:59:30 -08006864 long identity = Binder.clearCallingIdentity();
6865 try {
6866 if (DBG) {
6867 log("getCallForwarding: subId " + subId
6868 + " callForwardingReason" + callForwardingReason);
6869 }
Hall Liu27d24262020-09-18 19:04:59 -07006870
6871 Phone phone = getPhone(subId);
6872 if (phone == null) {
6873 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006874 callback.onError(
6875 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006876 } catch (RemoteException e) {
6877 // ignore
6878 }
6879 return;
6880 }
6881
6882 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6883 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6884 @Override
6885 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6886 try {
6887 callback.onCallForwardingInfoAvailable(info);
6888 } catch (RemoteException e) {
6889 // ignore
6890 }
6891 }
6892
6893 @Override
6894 public void onError(int error) {
6895 try {
6896 callback.onError(error);
6897 } catch (RemoteException e) {
6898 // ignore
6899 }
6900 }
6901 });
6902 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006903 } finally {
6904 Binder.restoreCallingIdentity(identity);
6905 }
6906 }
6907
6908 /**
6909 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6910 * reason, the number to forward, and the timeout before the forwarding is attempted.
6911 */
6912 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006913 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6914 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006915 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006916
6917 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6918 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding");
6919
Shuo Qian4a594052020-01-23 11:59:30 -08006920 long identity = Binder.clearCallingIdentity();
6921 try {
6922 if (DBG) {
6923 log("setCallForwarding: subId " + subId
6924 + " callForwardingInfo" + callForwardingInfo);
6925 }
Hall Liu27d24262020-09-18 19:04:59 -07006926
6927 Phone phone = getPhone(subId);
6928 if (phone == null) {
6929 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006930 callback.accept(
6931 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006932 } catch (RemoteException e) {
6933 // ignore
6934 }
6935 return;
6936 }
6937
6938 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6939 FunctionalUtils.ignoreRemoteException(callback::accept));
6940
6941 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006942 } finally {
6943 Binder.restoreCallingIdentity(identity);
6944 }
6945 }
6946
6947 /**
Hall Liu27d24262020-09-18 19:04:59 -07006948 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006949 */
6950 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006951 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006952 enforceReadPrivilegedPermission("getCallWaitingStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00006953
6954 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6955 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus");
6956
Shuo Qian4a594052020-01-23 11:59:30 -08006957 long identity = Binder.clearCallingIdentity();
6958 try {
Hall Liu27d24262020-09-18 19:04:59 -07006959 Phone phone = getPhone(subId);
6960 if (phone == null) {
6961 try {
6962 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6963 } catch (RemoteException e) {
6964 // ignore
6965 }
6966 return;
6967 }
SongFerngWang0e767992021-03-31 22:08:45 +08006968 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6969 PersistableBundle c = configManager.getConfigForSubId(subId);
6970 boolean requireUssd = c.getBoolean(
6971 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006972
Shuo Qian4a594052020-01-23 11:59:30 -08006973 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006974 if (requireUssd) {
6975 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6976 getSubscriptionCarrierId(subId));
6977 String newUssdCommand = "";
6978 try {
6979 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006980 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006981 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6982 } catch (NullPointerException e) {
6983 loge("Failed to generate USSD number" + e);
6984 }
6985 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6986 mMainThreadHandler, callback, carrierXmlParser,
6987 CarrierXmlParser.SsEntry.SSAction.QUERY);
6988 final String ussdCommand = newUssdCommand;
6989 Executors.newSingleThreadExecutor().execute(() -> {
6990 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6991 });
6992 } else {
6993 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6994 callback::accept);
6995 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6996 }
Shuo Qian4a594052020-01-23 11:59:30 -08006997 } finally {
6998 Binder.restoreCallingIdentity(identity);
6999 }
7000 }
7001
7002 /**
Hall Liu27d24262020-09-18 19:04:59 -07007003 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007004 */
7005 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007006 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007007 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007008
7009 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7010 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus");
7011
Shuo Qian4a594052020-01-23 11:59:30 -08007012 long identity = Binder.clearCallingIdentity();
7013 try {
Hall Liu27d24262020-09-18 19:04:59 -07007014 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
7015
7016 Phone phone = getPhone(subId);
7017 if (phone == null) {
7018 try {
7019 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7020 } catch (RemoteException e) {
7021 // ignore
7022 }
7023 return;
7024 }
7025
SongFerngWang0e767992021-03-31 22:08:45 +08007026 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7027 PersistableBundle c = configManager.getConfigForSubId(subId);
7028 boolean requireUssd = c.getBoolean(
7029 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007030
SongFerngWang0e767992021-03-31 22:08:45 +08007031 if (DBG) log("getCallWaitingStatus: subId " + subId);
7032 if (requireUssd) {
7033 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7034 getSubscriptionCarrierId(subId));
7035 CarrierXmlParser.SsEntry.SSAction ssAction =
7036 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
7037 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
7038 String newUssdCommand = "";
7039 try {
7040 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007041 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007042 .makeCommand(ssAction, null);
7043 } catch (NullPointerException e) {
7044 loge("Failed to generate USSD number" + e);
7045 }
7046 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7047 mMainThreadHandler, callback, carrierXmlParser, ssAction);
7048 final String ussdCommand = newUssdCommand;
7049 Executors.newSingleThreadExecutor().execute(() -> {
7050 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7051 });
7052 } else {
7053 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
7054 FunctionalUtils.ignoreRemoteException(callback::accept));
7055
7056 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
7057 }
Shuo Qian4a594052020-01-23 11:59:30 -08007058 } finally {
7059 Binder.restoreCallingIdentity(identity);
7060 }
7061 }
7062
7063 /**
yinxub1bed742017-04-17 11:45:04 -07007064 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07007065 *
yinxub1bed742017-04-17 11:45:04 -07007066 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007067 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
7068 * location related information which will be sent if the caller already possess
7069 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07007070 * @param request contains the radio access networks with bands/channels to scan
7071 * @param messenger callback messenger for scan results or errors
7072 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07007073 * @return the id of the requested scan which can be used to stop the scan.
7074 */
7075 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007076 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
7077 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007078 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007079 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7080 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08007081 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007082 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
7083 if (!renounceFineLocationAccess) {
7084 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007085 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7086 .setCallingPackage(callingPackage)
7087 .setCallingFeatureId(callingFeatureId)
7088 .setCallingPid(Binder.getCallingPid())
7089 .setCallingUid(Binder.getCallingUid())
7090 .setMethod("requestNetworkScan")
7091 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7092 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7093 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7094 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007095 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08007096 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07007097 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
7098 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08007099 if (e != null) {
7100 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
7101 throw e;
7102 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07007103 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08007104 return TelephonyScanManager.INVALID_SCAN_ID;
7105 }
7106 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007107 }
joonhunshin4ac60942023-11-15 15:23:39 +00007108
7109 enforceTelephonyFeatureWithException(callingPackage,
7110 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan");
7111
Hall Liu912dfd32019-04-25 14:02:26 -07007112 int callingUid = Binder.getCallingUid();
7113 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07007114 final long identity = Binder.clearCallingIdentity();
7115 try {
7116 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07007117 renounceFineLocationAccess, request, messenger, binder,
7118 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07007119 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07007120 } finally {
7121 Binder.restoreCallingIdentity(identity);
7122 }
yinxu504e1392017-04-12 16:03:22 -07007123 }
7124
Hall Liub2ac8ef2019-02-28 15:56:23 -08007125 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07007126 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00007127 boolean hasCarrierPriv;
7128 final long identity = Binder.clearCallingIdentity();
7129 try {
7130 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
7131 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
7132 } finally {
7133 Binder.restoreCallingIdentity(identity);
7134 }
Hall Liu558027f2019-05-15 19:14:05 -07007135 boolean hasNetworkScanPermission =
7136 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007137 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07007138
7139 if (!hasCarrierPriv && !hasNetworkScanPermission) {
7140 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
7141 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08007142 }
7143
7144 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
7145 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08007146 if (ras.getChannels() != null && ras.getChannels().length > 0) {
7147 return new SecurityException("Specific channels must not be"
7148 + " scanned without location access.");
7149 }
7150 }
7151 }
7152
Hall Liub2ac8ef2019-02-28 15:56:23 -08007153 return null;
7154 }
7155
yinxu504e1392017-04-12 16:03:22 -07007156 /**
7157 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07007158 *
7159 * @param subId id of the subscription
7160 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07007161 */
7162 @Override
7163 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007164 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7165 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007166
Hall Liu912dfd32019-04-25 14:02:26 -07007167 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007168 final long identity = Binder.clearCallingIdentity();
7169 try {
Hall Liu912dfd32019-04-25 14:02:26 -07007170 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007171 } finally {
7172 Binder.restoreCallingIdentity(identity);
7173 }
yinxu504e1392017-04-12 16:03:22 -07007174 }
7175
7176 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08007177 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07007178 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08007179 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07007180 */
7181 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08007182 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08007183 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007184 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08007185 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007186
joonhunshin4ac60942023-11-15 15:23:39 +00007187 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7188 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask");
7189
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007190 final long identity = Binder.clearCallingIdentity();
7191 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007192 if (DBG) log("getAllowedNetworkTypesBitmask");
7193 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
7194 int networkTypesBitmask = (result != null ? result[0] : -1);
7195 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
7196 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007197 } finally {
7198 Binder.restoreCallingIdentity(identity);
7199 }
Jake Hamby7c27be32014-03-03 13:25:59 -08007200 }
7201
7202 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007203 * Get the allowed network types for certain reason.
7204 *
7205 * @param subId the id of the subscription.
7206 * @param reason the reason the allowed network type change is taking place
7207 * @return the allowed network types.
7208 */
7209 @Override
7210 public long getAllowedNetworkTypesForReason(int subId,
7211 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07007212 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007213 mApp, subId, "getAllowedNetworkTypesForReason");
joonhunshin4ac60942023-11-15 15:23:39 +00007214
7215 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7216 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesForReason");
7217
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007218 final long identity = Binder.clearCallingIdentity();
7219 try {
Jack Yu7247ac82023-03-02 23:52:10 -08007220 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007221 } finally {
7222 Binder.restoreCallingIdentity(identity);
7223 }
7224 }
7225
7226 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07007227 * Enable/Disable E-UTRA-NR Dual Connectivity
7228 * @param subId subscription id of the sim card
7229 * @param nrDualConnectivityState expected NR dual connectivity state
7230 * This can be passed following states
7231 * <ol>
7232 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
7233 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
7234 * <li>Disable NR dual connectivity and force secondary cell to be released
7235 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
7236 * </ol>
7237 * @return operation result.
7238 */
7239 @Override
7240 public int setNrDualConnectivityState(int subId,
7241 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
7242 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7243 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007244 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007245 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7246 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
7247 }
7248
Sooraj Sasindran37444802020-08-11 10:40:43 -07007249 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7250 final long identity = Binder.clearCallingIdentity();
7251 try {
7252 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
7253 nrDualConnectivityState, subId,
7254 workSource);
7255 if (DBG) log("enableNRDualConnectivity result: " + result);
7256 return result;
7257 } finally {
7258 Binder.restoreCallingIdentity(identity);
7259 }
7260 }
7261
7262 /**
7263 * Is E-UTRA-NR Dual Connectivity enabled
7264 * @return true if dual connectivity is enabled else false
7265 */
7266 @Override
7267 public boolean isNrDualConnectivityEnabled(int subId) {
7268 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007269 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07007270 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007271 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007272 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7273 return false;
7274 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07007275 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7276 final long identity = Binder.clearCallingIdentity();
7277 try {
7278 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
7279 null, subId, workSource);
7280 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
7281 return isEnabled;
7282 } finally {
7283 Binder.restoreCallingIdentity(identity);
7284 }
7285 }
7286
7287 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007288 * Set the allowed network types of the device and
7289 * provide the reason triggering the allowed network change.
7290 *
7291 * @param subId the id of the subscription.
7292 * @param reason the reason the allowed network type change is taking place
7293 * @param allowedNetworkTypes the allowed network types.
7294 * @return true on success; false on any failure.
7295 */
7296 @Override
7297 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08007298 @TelephonyManager.AllowedNetworkTypesReason int reason,
7299 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007300 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7301 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007302 // If the caller only has carrier privileges, then they should not be able to override
7303 // any network types which were set for security reasons.
7304 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
7305 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007306 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007307 throw new SecurityException(
7308 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007309 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007310 }
joonhunshin4ac60942023-11-15 15:23:39 +00007311
7312 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7313 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason");
7314
SongFerngWang3ef3e072020-12-21 16:41:52 +08007315 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007316 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08007317 return false;
7318 }
7319 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
7320 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007321 return false;
7322 }
7323
Jack Yu5b494332023-01-23 18:18:04 +00007324 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
7325 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007326
Jack Yue37dd262022-12-16 11:53:37 -08007327 Phone phone = getPhone(subId);
7328 if (phone == null) {
7329 return false;
7330 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007331
Jack Yue37dd262022-12-16 11:53:37 -08007332 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007333 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007334 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08007335 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007336
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007337 final long identity = Binder.clearCallingIdentity();
7338 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007339 Boolean success = (Boolean) sendRequest(
7340 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
7341 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
7342
7343 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
7344 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007345 } finally {
7346 Binder.restoreCallingIdentity(identity);
7347 }
7348 }
7349
7350 /**
Miaoa84611c2019-03-15 09:21:10 +08007351 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08007352 *
Miaoa84611c2019-03-15 09:21:10 +08007353 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07007354 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08007355 * @hide
7356 */
7357 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08007358 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007359 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007360
7361 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7362 PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber");
7363
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007364 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08007365 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007366 try {
Miaoa84611c2019-03-15 09:21:10 +08007367 if (phone != null) {
7368 return phone.hasMatchedTetherApnSetting();
7369 } else {
7370 return false;
7371 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007372 } finally {
7373 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007374 }
Junda Liu475951f2014-11-07 16:45:03 -08007375 }
7376
7377 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007378 * Get the user enabled state of Mobile Data.
7379 *
7380 * TODO: remove and use isUserDataEnabled.
7381 * This can't be removed now because some vendor codes
7382 * calls through ITelephony directly while they should
7383 * use TelephonyManager.
7384 *
7385 * @return true on enabled
7386 */
7387 @Override
7388 public boolean getDataEnabled(int subId) {
7389 return isUserDataEnabled(subId);
7390 }
7391
7392 /**
7393 * Get whether mobile data is enabled per user setting.
7394 *
7395 * There are other factors deciding whether mobile data is actually enabled, but they are
7396 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007397 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007398 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7399 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007400 *
7401 * @return {@code true} if data is enabled else {@code false}
7402 */
7403 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007404 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007405 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007406 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007407 try {
7408 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7409 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007410 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007411 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7412 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007413 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007414 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007415 mApp, subId, functionName);
7416
Robert Greenwalt646120a2014-05-23 11:54:03 -07007417 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007418
7419 final long identity = Binder.clearCallingIdentity();
7420 try {
Jack Yu285100e2022-12-02 22:48:35 -08007421 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007422 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7423 Phone phone = PhoneFactory.getPhone(phoneId);
7424 if (phone != null) {
7425 boolean retVal = phone.isUserDataEnabled();
7426 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7427 return retVal;
7428 } else {
7429 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7430 return false;
7431 }
7432 } finally {
7433 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007434 }
7435 }
7436
7437 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007438 * Checks if the device is capable of mobile data by considering whether whether the
7439 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7440 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007441 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007442 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007443 */
7444 @Override
7445 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007446 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007447 try {
7448 try {
7449 mApp.enforceCallingOrSelfPermission(
7450 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007451 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007452 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007453 try {
7454 mApp.enforceCallingOrSelfPermission(
7455 android.Manifest.permission.READ_PHONE_STATE,
7456 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007457 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007458 mApp.enforceCallingOrSelfPermission(
7459 permission.READ_BASIC_PHONE_STATE, functionName);
7460 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007461 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007462 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007463 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007464 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007465
joonhunshin4ac60942023-11-15 15:23:39 +00007466 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7467 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled");
7468
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007469 final long identity = Binder.clearCallingIdentity();
7470 try {
Jack Yu285100e2022-12-02 22:48:35 -08007471 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007472 Phone phone = PhoneFactory.getPhone(phoneId);
7473 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007474 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007475 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007476 return retVal;
7477 } else {
7478 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7479 return false;
7480 }
7481 } finally {
7482 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007483 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007484 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007485
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007486 /**
7487 * Check if data is enabled for a specific reason
7488 * @param subId Subscription index
7489 * @param reason the reason the data enable change is taking place
7490 * @return {@code true} if the overall data is enabled; {@code false} if not.
7491 */
7492 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007493 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007494 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007495 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007496 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007497 try {
7498 mApp.enforceCallingOrSelfPermission(
7499 android.Manifest.permission.ACCESS_NETWORK_STATE,
7500 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007501 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007502 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7503 functionName);
7504 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007505 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007506 try {
7507 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007508 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007509 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007510 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007511 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007512 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007513 }
7514
joonhunshin4ac60942023-11-15 15:23:39 +00007515 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7516 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007517
7518 final long identity = Binder.clearCallingIdentity();
7519 try {
Jack Yu285100e2022-12-02 22:48:35 -08007520 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007521 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007522 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007523 + " reason=" + reason);
7524 }
7525 Phone phone = PhoneFactory.getPhone(phoneId);
7526 if (phone != null) {
7527 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007528 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007529 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007530 return retVal;
7531 } else {
7532 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007533 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007534 + subId + " retVal=false");
7535 }
7536 return false;
7537 }
7538 } finally {
7539 Binder.restoreCallingIdentity(identity);
7540 }
7541 }
7542
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007543 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007544 public int getCarrierPrivilegeStatus(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00007545 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7546 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus");
7547
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007548 // No permission needed; this only lets the caller inspect their own status.
7549 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007550 }
Junda Liu29340342014-07-10 15:23:27 -07007551
7552 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007553 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007554 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
joonhunshin4ac60942023-11-15 15:23:39 +00007555
7556 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7557 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatusForUid");
7558
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007559 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7560 }
7561
7562 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7563 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007564 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007565 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007566 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7567 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007568 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7569 if (cpt == null) {
7570 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007571 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7572 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007573 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007574 }
7575
7576 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007577 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007578 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
joonhunshin4ac60942023-11-15 15:23:39 +00007579
7580 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7581 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage");
7582
chen xuf7e9fe82019-05-09 19:31:02 -07007583 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007584 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007585 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007586 Phone phone = getPhone(subId);
7587 if (phone == null) {
7588 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7589 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7590 }
7591 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7592 if (cpt == null) {
7593 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007594 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7595 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007596 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007597 }
7598
7599 @Override
7600 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007601 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007602
7603 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7604 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7605 "checkCarrierPrivilegesForPackageAnyPhone");
7606
Rambo Wange7209ce2022-02-23 13:41:02 -08007607 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7608 }
7609
7610 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007611 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007612 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007613 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007614 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007615 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7616 Phone phone = PhoneFactory.getPhone(phoneId);
7617 if (phone == null) {
7618 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007619 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007620 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7621 if (cpt == null) {
7622 continue;
7623 }
7624 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007625 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7626 break;
7627 }
7628 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007629 return result;
Junda Liu29340342014-07-10 15:23:27 -07007630 }
Derek Tan89e89d42014-07-08 17:00:10 -07007631
7632 @Override
Junda Liue64de782015-04-16 17:19:16 -07007633 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007634 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007635
7636 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7637 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7638 "getCarrierPackageNamesForIntentAndPhone");
7639
Rambo Wang8a247eb2022-02-08 21:11:18 +00007640 Phone phone = PhoneFactory.getPhone(phoneId);
7641 if (phone == null) {
7642 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007643 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007644 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7645 if (cpt == null) {
7646 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007647 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007648 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007649 }
7650
Amith Yamasani6e118872016-02-19 12:53:51 -08007651 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007652 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007653 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007654 Phone phone = PhoneFactory.getPhone(phoneId);
7655 if (phone == null) {
7656 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007657 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007658 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7659 if (cpt == null) {
7660 return Collections.emptyList();
7661 }
7662 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007663 }
7664
chen xuf7e9fe82019-05-09 19:31:02 -07007665 @Override
7666 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007667 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
joonhunshin4ac60942023-11-15 15:23:39 +00007668
7669 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7670 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7671 "getPackagesWithCarrierPrivilegesForAllPhones");
7672
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007673 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007674 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007675 try {
7676 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7677 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7678 }
7679 } finally {
7680 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007681 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007682 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007683 }
7684
Rambo Wang6812ffb2022-03-15 16:54:17 -07007685 @Override
7686 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7687 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7688
joonhunshin4ac60942023-11-15 15:23:39 +00007689 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7690 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7691 "getCarrierServicePackageNameForLogicalSlot");
7692
Rambo Wang6812ffb2022-03-15 16:54:17 -07007693 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7694 if (phone == null) {
7695 return null;
7696 }
7697 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7698 if (cpt == null) {
7699 return null;
7700 }
7701 return cpt.getCarrierServicePackageName();
7702 }
7703
Wink Savilleb564aae2014-10-23 10:18:09 -07007704 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007705 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007706 UiccPort port = phone == null ? null : phone.getUiccPort();
7707 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007708 return null;
7709 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007710 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007711 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007712 return null;
7713 }
7714 return iccId;
7715 }
7716
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007717 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007718 public void setCallComposerStatus(int subId, int status) {
7719 enforceModifyPermission();
7720
joonhunshin4ac60942023-11-15 15:23:39 +00007721 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7722 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus");
7723
Shuo Qiane4e11672020-12-15 22:15:33 -08007724 final long identity = Binder.clearCallingIdentity();
7725 try {
7726 Phone phone = getPhone(subId);
7727 if (phone != null) {
7728 Phone defaultPhone = phone.getImsPhone();
7729 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7730 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7731 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007732 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7733 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007734 }
7735 }
Shuo Qian284ae752020-12-22 19:10:14 -08007736 } catch (ImsException e) {
7737 throw new ServiceSpecificException(e.getCode());
7738 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007739 Binder.restoreCallingIdentity(identity);
7740 }
7741 }
7742
7743 @Override
7744 public int getCallComposerStatus(int subId) {
7745 enforceReadPrivilegedPermission("getCallComposerStatus");
7746
joonhunshin4ac60942023-11-15 15:23:39 +00007747 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7748 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus");
7749
Shuo Qiane4e11672020-12-15 22:15:33 -08007750 final long identity = Binder.clearCallingIdentity();
7751 try {
7752 Phone phone = getPhone(subId);
7753 if (phone != null) {
7754 Phone defaultPhone = phone.getImsPhone();
7755 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7756 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7757 return imsPhone.getCallComposerStatus();
7758 }
7759 }
7760 } finally {
7761 Binder.restoreCallingIdentity(identity);
7762 }
7763 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7764 }
7765
7766 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007767 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7768 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007769 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007770 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007771
joonhunshin4ac60942023-11-15 15:23:39 +00007772 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7773 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7774 "setLine1NumberForDisplayForSubscriber");
7775
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007776 final long identity = Binder.clearCallingIdentity();
7777 try {
7778 final String iccId = getIccId(subId);
7779 final Phone phone = getPhone(subId);
7780 if (phone == null) {
7781 return false;
7782 }
7783 final String subscriberId = phone.getSubscriberId();
7784
7785 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007786 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007787 + subscriberId + " to " + number);
7788 }
7789
7790 if (TextUtils.isEmpty(iccId)) {
7791 return false;
7792 }
7793
7794 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7795
7796 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7797 if (alphaTag == null) {
7798 editor.remove(alphaTagPrefKey);
7799 } else {
7800 editor.putString(alphaTagPrefKey, alphaTag);
7801 }
7802
7803 // Record both the line number and IMSI for this ICCID, since we need to
7804 // track all merged IMSIs based on line number
7805 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7806 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7807 if (number == null) {
7808 editor.remove(numberPrefKey);
7809 editor.remove(subscriberPrefKey);
7810 } else {
7811 editor.putString(numberPrefKey, number);
7812 editor.putString(subscriberPrefKey, subscriberId);
7813 }
7814
7815 editor.commit();
7816 return true;
7817 } finally {
7818 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007819 }
Derek Tan7226c842014-07-02 17:42:23 -07007820 }
7821
7822 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007823 public String getLine1NumberForDisplay(int subId, String callingPackage,
7824 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007825 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007826 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007827 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007828 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007829 return null;
7830 }
Derek Tan97ebb422014-09-05 16:55:38 -07007831
joonhunshin4ac60942023-11-15 15:23:39 +00007832 enforceTelephonyFeatureWithException(callingPackage,
7833 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay");
7834
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007835 final long identity = Binder.clearCallingIdentity();
7836 try {
7837 String iccId = getIccId(subId);
7838 if (iccId != null) {
7839 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7840 if (DBG_MERGE) {
7841 log("getLine1NumberForDisplay returning "
7842 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7843 }
7844 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007845 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007846 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7847 return null;
7848 } finally {
7849 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007850 }
Derek Tan7226c842014-07-02 17:42:23 -07007851 }
7852
7853 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007854 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7855 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007856 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007857 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007858 return null;
7859 }
Derek Tan97ebb422014-09-05 16:55:38 -07007860
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007861 final long identity = Binder.clearCallingIdentity();
7862 try {
7863 String iccId = getIccId(subId);
7864 if (iccId != null) {
7865 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7866 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7867 }
7868 return null;
7869 } finally {
7870 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007871 }
Derek Tan7226c842014-07-02 17:42:23 -07007872 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007873
7874 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007875 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7876 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007877 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7878 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007879 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007880 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007881 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007882 return null;
7883 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007884
Jordan Liub49b04b2019-05-06 14:45:15 -07007885 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7886 // the process, where TelephonyManager was instantiated.
7887 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007888 final long identity = Binder.clearCallingIdentity();
7889 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007890 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007891 final TelephonyManager tele = TelephonyManager.from(context);
7892 final SubscriptionManager sub = SubscriptionManager.from(context);
7893
7894 // Figure out what subscribers are currently active
7895 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007896
Jordan Liub49b04b2019-05-06 14:45:15 -07007897 // Only consider subs which match the current subId
7898 // This logic can be simplified. See b/131189269 for progress.
7899 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007900 activeSubscriberIds.add(tele.getSubscriberId(subId));
7901 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007902
7903 // First pass, find a number override for an active subscriber
7904 String mergeNumber = null;
7905 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7906 for (String key : prefs.keySet()) {
7907 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7908 final String subscriberId = (String) prefs.get(key);
7909 if (activeSubscriberIds.contains(subscriberId)) {
7910 final String iccId = key.substring(
7911 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7912 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7913 mergeNumber = (String) prefs.get(numberKey);
7914 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007915 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007916 + " for active subscriber " + subscriberId);
7917 }
7918 if (!TextUtils.isEmpty(mergeNumber)) {
7919 break;
7920 }
7921 }
7922 }
7923 }
7924
7925 // Shortcut when no active merged subscribers
7926 if (TextUtils.isEmpty(mergeNumber)) {
7927 return null;
7928 }
7929
7930 // Second pass, find all subscribers under that line override
7931 final ArraySet<String> result = new ArraySet<>();
7932 for (String key : prefs.keySet()) {
7933 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7934 final String number = (String) prefs.get(key);
7935 if (mergeNumber.equals(number)) {
7936 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7937 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7938 final String subscriberId = (String) prefs.get(subscriberKey);
7939 if (!TextUtils.isEmpty(subscriberId)) {
7940 result.add(subscriberId);
7941 }
7942 }
7943 }
7944 }
7945
7946 final String[] resultArray = result.toArray(new String[result.size()]);
7947 Arrays.sort(resultArray);
7948 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007949 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007950 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7951 }
7952 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007953 } finally {
7954 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007955 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007956 }
7957
7958 @Override
zoey chen38003472019-12-13 17:16:31 +08007959 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7960 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007961
joonhunshin4ac60942023-11-15 15:23:39 +00007962 enforceTelephonyFeatureWithException(callingPackage,
7963 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup");
7964
Malcolm Chen6ca97372019-07-01 16:28:21 -07007965 final long identity = Binder.clearCallingIdentity();
7966 try {
7967 final TelephonyManager telephonyManager = mApp.getSystemService(
7968 TelephonyManager.class);
7969 String subscriberId = telephonyManager.getSubscriberId(subId);
7970 if (subscriberId == null) {
7971 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007972 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007973 + subId);
7974 }
7975 return null;
7976 }
7977
Jack Yu3beaf9d2023-04-14 09:17:27 -07007978 final SubscriptionInfo info = getSubscriptionManagerService()
7979 .getSubscriptionInfo(subId);
7980 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07007981 // If it doesn't belong to any group, return just subscriberId of itself.
7982 if (groupUuid == null) {
7983 return new String[]{subscriberId};
7984 }
7985
7986 // Get all subscriberIds from the group.
7987 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07007988 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
7989 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7990 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007991 for (SubscriptionInfo subInfo : groupInfos) {
7992 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7993 if (subscriberId != null) {
7994 mergedSubscriberIds.add(subscriberId);
7995 }
7996 }
7997
7998 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7999 } finally {
8000 Binder.restoreCallingIdentity(identity);
8001
8002 }
8003 }
8004
8005 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008006 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008007 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08008008 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008009
joonhunshin4ac60942023-11-15 15:23:39 +00008010 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8011 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride");
8012
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008013 final long identity = Binder.clearCallingIdentity();
8014 try {
8015 final Phone phone = getPhone(subId);
8016 return phone == null ? false : phone.setOperatorBrandOverride(brand);
8017 } finally {
8018 Binder.restoreCallingIdentity(identity);
8019 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07008020 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05008021
8022 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008023 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008024 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
8025 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008026 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
8027 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008028
8029 final long identity = Binder.clearCallingIdentity();
8030 try {
8031 final Phone phone = getPhone(subId);
8032 if (phone == null) {
8033 return false;
8034 }
8035 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
8036 cdmaNonRoamingList);
8037 } finally {
8038 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008039 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008040 }
8041
8042 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07008043 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008044 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08008045 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008046 if (phone == null) {
8047 return raf;
8048 }
8049
Shuo Qiandee53402020-05-29 14:08:15 -07008050 try {
8051 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008052 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07008053 mApp, phone.getSubId(), "getRadioAccessFamily");
8054 } catch (SecurityException e) {
8055 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
8056 throw e;
8057 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008058
joonhunshin4ac60942023-11-15 15:23:39 +00008059 enforceTelephonyFeatureWithException(callingPackage,
8060 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily");
8061
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008062 final long identity = Binder.clearCallingIdentity();
8063 try {
chen xub97461a2018-10-26 14:17:57 -07008064 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008065 } finally {
8066 Binder.restoreCallingIdentity(identity);
8067 }
chen xub97461a2018-10-26 14:17:57 -07008068 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07008069 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008070
8071 @Override
Hall Liu82694d52020-12-11 18:22:04 -08008072 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08008073 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08008074 try {
8075 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
8076 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008077 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008078 }
8079 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008080 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008081 }
joonhunshin4ac60942023-11-15 15:23:39 +00008082
8083 enforceTelephonyFeatureWithException(callingPackage,
8084 PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture");
8085
Hall Liu82694d52020-12-11 18:22:04 -08008086 RoleManager rm = mApp.getSystemService(RoleManager.class);
8087 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
8088 if (!dialerRoleHolders.contains(callingPackage)) {
8089 throw new SecurityException("App must be the dialer role holder to"
8090 + " upload a call composer pic");
8091 }
8092
8093 Executors.newSingleThreadExecutor().execute(() -> {
8094 ByteArrayOutputStream output = new ByteArrayOutputStream(
8095 (int) TelephonyManager.getMaximumCallComposerPictureSize());
8096 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
8097 boolean readUntilEnd = false;
8098 int totalBytesRead = 0;
8099 byte[] buffer = new byte[16 * 1024];
8100 while (true) {
8101 int numRead;
8102 try {
8103 numRead = input.read(buffer);
8104 } catch (IOException e) {
8105 try {
8106 fd.checkError();
8107 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
8108 null);
8109 } catch (IOException e1) {
8110 // This means that the other side closed explicitly with an error. If this
8111 // happens, log and ignore.
8112 loge("Remote end of call composer picture pipe closed: " + e1);
8113 }
8114 break;
8115 }
8116 if (numRead == -1) {
8117 readUntilEnd = true;
8118 break;
8119 }
8120 totalBytesRead += numRead;
8121 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
8122 loge("Too many bytes read for call composer picture: " + totalBytesRead);
8123 try {
8124 input.close();
8125 } catch (IOException e) {
8126 // ignore
8127 }
8128 break;
8129 }
8130 output.write(buffer, 0, numRead);
8131 }
8132 // Generally, the remote end will close the file descriptors. The only case where we
8133 // close is above, where the picture size is too big.
8134
8135 try {
8136 fd.checkError();
8137 } catch (IOException e) {
8138 loge("Remote end for call composer closed with an error: " + e);
8139 return;
8140 }
8141
Hall Liuaa4211e2021-01-20 15:43:39 -08008142 if (!readUntilEnd) {
8143 loge("Did not finish reading entire image; aborting");
8144 return;
8145 }
Hall Liu82694d52020-12-11 18:22:04 -08008146
Hall Liuaa4211e2021-01-20 15:43:39 -08008147 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
8148 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
8149 new CallComposerPictureTransfer.Factory() {},
8150 imageData,
8151 (result) -> {
8152 if (result.first != null) {
8153 ParcelUuid parcelUuid = new ParcelUuid(result.first);
8154 Bundle outputResult = new Bundle();
8155 outputResult.putParcelable(
8156 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
8157 callback.send(TelephonyManager.CallComposerException.SUCCESS,
8158 outputResult);
8159 } else {
8160 callback.send(result.second, null);
8161 }
8162 }
8163 );
Hall Liu82694d52020-12-11 18:22:04 -08008164 });
8165 }
8166
8167 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07008168 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008169 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07008170 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008171
joonhunshin4ac60942023-11-15 15:23:39 +00008172 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8173 PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling");
8174
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008175 final long identity = Binder.clearCallingIdentity();
8176 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008177 ImsManager.getInstance(defaultPhone.getContext(),
8178 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008179 } finally {
8180 Binder.restoreCallingIdentity(identity);
8181 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008182 }
8183
8184 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008185 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008186 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008187 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
8188 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00008189 return false;
8190 }
Svet Ganovb320e182015-04-16 12:30:10 -07008191
joonhunshin4ac60942023-11-15 15:23:39 +00008192 enforceTelephonyFeatureWithException(callingPackage,
8193 PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled");
8194
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008195 final long identity = Binder.clearCallingIdentity();
8196 try {
8197 // Check the user preference and the system-level IMS setting. Even if the user has
8198 // enabled video calling, if IMS is disabled we aren't able to support video calling.
8199 // In the long run, we may instead need to check if there exists a connection service
8200 // which can support video calling.
8201 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008202 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008203 return imsManager.isVtEnabledByPlatform()
8204 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
8205 && imsManager.isVtEnabledByUser();
8206 } finally {
8207 Binder.restoreCallingIdentity(identity);
8208 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008209 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06008210
Andrew Leea1239f22015-03-02 17:44:07 -08008211 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008212 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
8213 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008214 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008215 mApp, subId, callingPackage, callingFeatureId,
8216 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008217 return false;
8218 }
8219
joonhunshin4ac60942023-11-15 15:23:39 +00008220 enforceTelephonyFeatureWithException(callingPackage,
8221 PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength");
8222
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008223 final long identity = Binder.clearCallingIdentity();
8224 try {
8225 CarrierConfigManager configManager =
8226 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008227 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008228 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
8229 } finally {
8230 Binder.restoreCallingIdentity(identity);
8231 }
Andrew Leea1239f22015-03-02 17:44:07 -08008232 }
8233
8234 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008235 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008236 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008237 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008238 return false;
8239 }
8240
joonhunshin4ac60942023-11-15 15:23:39 +00008241 enforceTelephonyFeatureWithException(callingPackage,
8242 PackageManager.FEATURE_TELEPHONY, "isWorldPhone");
8243
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008244 final long identity = Binder.clearCallingIdentity();
8245 try {
8246 CarrierConfigManager configManager =
8247 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008248 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008249 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
8250 } finally {
8251 Binder.restoreCallingIdentity(identity);
8252 }
Andrew Leea1239f22015-03-02 17:44:07 -08008253 }
8254
Andrew Lee9431b832015-03-09 18:46:45 -07008255 @Override
8256 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008257 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08008258 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07008259 }
8260
8261 @Override
8262 public boolean isHearingAidCompatibilitySupported() {
joonhunshin4ac60942023-11-15 15:23:39 +00008263 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8264 PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported");
8265
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008266 final long identity = Binder.clearCallingIdentity();
8267 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008268 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008269 } finally {
8270 Binder.restoreCallingIdentity(identity);
8271 }
Andrew Lee9431b832015-03-09 18:46:45 -07008272 }
8273
Hall Liuf6668912018-10-31 17:05:23 -07008274 /**
8275 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
8276 * support for the feature and device firmware support.
8277 *
8278 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
8279 */
8280 @Override
8281 public boolean isRttSupported(int subscriptionId) {
joonhunshin4ac60942023-11-15 15:23:39 +00008282 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8283 PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported");
8284
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008285 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008286 final Phone phone = getPhone(subscriptionId);
8287 if (phone == null) {
8288 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
8289 return false;
8290 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008291 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008292 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008293 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
joonhunshin4ac60942023-11-15 15:23:39 +00008294 boolean isDeviceSupported = (phone.getContext().getResources() != null)
8295 ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt)
8296 : false;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008297 return isCarrierSupported && isDeviceSupported;
8298 } finally {
8299 Binder.restoreCallingIdentity(identity);
8300 }
Hall Liu98187582018-01-22 19:15:32 -08008301 }
8302
Hall Liuf6668912018-10-31 17:05:23 -07008303 /**
Hall Liuf2daa022019-07-23 18:39:00 -07008304 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
8305 * RTT setting, will return true if the device and carrier both support RTT.
8306 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07008307 */
8308 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008309 final long identity = Binder.clearCallingIdentity();
8310 try {
joonhunshin4ac60942023-11-15 15:23:39 +00008311 if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) {
8312 if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
8313 return false;
8314 }
8315 }
8316
Hall Liu5bab75c2019-12-11 23:58:20 +00008317 boolean isRttSupported = isRttSupported(subscriptionId);
8318 boolean isUserRttSettingOn = Settings.Secure.getInt(
8319 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
8320 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
8321 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
8322 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008323 } finally {
8324 Binder.restoreCallingIdentity(identity);
8325 }
Hall Liu3ad5f012018-04-06 16:23:39 -07008326 }
8327
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008328 @Deprecated
8329 @Override
8330 public String getDeviceId(String callingPackage) {
8331 return getDeviceIdWithFeature(callingPackage, null);
8332 }
8333
Sanket Padawe7310cc72015-01-14 09:53:20 -08008334 /**
8335 * Returns the unique device ID of phone, for example, the IMEI for
8336 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
8337 *
8338 * <p>Requires Permission:
8339 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
8340 */
8341 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008342 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07008343 try {
8344 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
8345 } catch (SecurityException se) {
8346 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
8347 throw new SecurityException("Package " + callingPackage + " does not belong to "
8348 + Binder.getCallingUid());
8349 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008350 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008351 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008352 return null;
8353 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008354 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008355 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008356 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008357 return null;
8358 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008359
8360 final long identity = Binder.clearCallingIdentity();
8361 try {
8362 return phone.getDeviceId();
8363 } finally {
8364 Binder.restoreCallingIdentity(identity);
8365 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008366 }
8367
Ping Sunc67b7c22016-03-02 19:16:45 +08008368 /**
8369 * {@hide}
8370 * Returns the IMS Registration Status on a particular subid
8371 *
8372 * @param subId
8373 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008374 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008375 Phone phone = getPhone(subId);
8376 if (phone != null) {
8377 return phone.isImsRegistered();
8378 } else {
8379 return false;
8380 }
8381 }
8382
Santos Cordon7a1885b2015-02-03 11:15:19 -08008383 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008384 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008385 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008386 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008387 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008388 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8389 }
8390 final long identity = Binder.clearCallingIdentity();
8391 try {
8392 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8393 } finally {
8394 Binder.restoreCallingIdentity(identity);
8395 }
8396 }
8397
8398 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008399 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008400 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008401 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008402 mApp,
8403 subscriptionId,
8404 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
8405 + subscriptionId);
joonhunshin4ac60942023-11-15 15:23:39 +00008406
8407 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8408 PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId");
8409
Tyler Gunnf70ed162019-04-03 15:28:53 -07008410 final long identity = Binder.clearCallingIdentity();
8411 try {
8412 Phone phone = getPhone(subscriptionId);
8413 if (phone == null) {
8414 return null;
8415 }
8416 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8417 } finally {
8418 Binder.restoreCallingIdentity(identity);
8419 }
8420 }
8421
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008422 /**
8423 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008424 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008425 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008426 final long identity = Binder.clearCallingIdentity();
8427 try {
8428 Phone phone = getPhone(subId);
8429 if (phone != null) {
8430 return phone.isWifiCallingEnabled();
8431 } else {
8432 return false;
8433 }
8434 } finally {
8435 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008436 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008437 }
8438
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008439 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008440 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008441 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008442 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008443 final long identity = Binder.clearCallingIdentity();
8444 try {
8445 Phone phone = getPhone(subId);
8446 if (phone != null) {
8447 return phone.isVideoEnabled();
8448 } else {
8449 return false;
8450 }
8451 } finally {
8452 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008453 }
8454 }
8455
8456 /**
8457 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8458 * defined in {@link ImsRegistrationImplBase}.
8459 */
8460 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008461 final long identity = Binder.clearCallingIdentity();
8462 try {
8463 Phone phone = getPhone(subId);
8464 if (phone != null) {
8465 return phone.getImsRegistrationTech();
8466 } else {
8467 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8468 }
8469 } finally {
8470 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008471 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008472 }
8473
Stuart Scott8eef64f2015-04-08 15:13:54 -07008474 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008475 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008476 enforceSettingsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008477
8478 enforceTelephonyFeatureWithException(callingPackage,
8479 PackageManager.FEATURE_TELEPHONY, "factoryReset");
8480
Stuart Scott981d8582015-04-21 14:09:50 -07008481 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8482 return;
8483 }
Kai Shif70f46f2021-03-03 13:59:46 -08008484 Phone defaultPhone = getDefaultPhone();
8485 if (defaultPhone != null) {
8486 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8487 mApp, getDefaultPhone().getSubId(), "factoryReset");
8488 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008489 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008490
Svet Ganovcc087f82015-05-12 20:35:54 -07008491 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008492 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8493 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008494 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008495 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008496 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008497 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008498 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008499 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08008500 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008501 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008502 // There has been issues when Sms raw table somehow stores orphan
8503 // fragments. They lead to garbled message when new fragments come
8504 // in and combined with those stale ones. In case this happens again,
8505 // user can reset all network settings which will clean up this table.
8506 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008507 // Clean up IMS settings as well here.
8508 int slotId = getSlotIndex(subId);
8509 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
8510 ImsManager.getInstance(mApp, slotId).factoryReset();
8511 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008512
Kai Shif70f46f2021-03-03 13:59:46 -08008513 if (defaultPhone == null) {
8514 return;
8515 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008516 // Erase modem config if erase modem on network setting is enabled.
8517 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8518 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8519 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008520 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008521 }
Kai Shif70f46f2021-03-03 13:59:46 -08008522
8523 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008524 } finally {
8525 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008526 }
8527 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008528
SongFerngWangfd89b102021-05-27 22:44:54 +08008529 @VisibleForTesting
8530 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8531 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8532 return;
8533 }
8534 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8535 RILConstants.PREFERRED_NETWORK_MODE);
8536 SubscriptionManager.setSubscriptionProperty(subId,
8537 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8538 "user=" + defaultNetworkType);
8539 phone.loadAllowedNetworksFromSubscriptionDatabase();
8540 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8541 defaultNetworkType, null);
8542 }
8543
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008544 private void cleanUpSmsRawTable(Context context) {
8545 ContentResolver resolver = context.getContentResolver();
8546 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8547 resolver.delete(uri, null, null);
8548 }
8549
Narayan Kamath1c496c22015-04-16 14:40:19 +01008550 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008551 public String getSimLocaleForSubscriber(int subId) {
8552 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
joonhunshin4ac60942023-11-15 15:23:39 +00008553
8554 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8555 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber");
8556
chen xu5d3637b2019-01-21 23:31:38 -08008557 final Phone phone = getPhone(subId);
8558 if (phone == null) {
8559 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008560 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008561 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008562 final long identity = Binder.clearCallingIdentity();
8563 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008564 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
8565 phone.getContext().getOpPackageName(),
8566 phone.getContext().getAttributionTag());
8567 if (info == null) {
8568 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8569 return null;
chen xu6291c472019-02-04 12:55:53 -08008570 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008571 // Try and fetch the locale from the carrier properties or from the SIM language
8572 // preferences (EF-PL and EF-LI)...
8573 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008574 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008575 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8576 if (localeFromDefaultSim != null) {
8577 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8578 if (DBG) log("Using locale from subId: " + subId + " locale: "
8579 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008580 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008581 } else {
8582 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008583 }
8584 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008585
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008586 // The SIM language preferences only store a language (e.g. fr = French), not an
8587 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8588 // the SIM and carrier preferences does not include a country we add the country
8589 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008590 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008591 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008592 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008593 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008594 }
8595
8596 if (DBG) log("No locale found - returning null");
8597 return null;
8598 } finally {
8599 Binder.restoreCallingIdentity(identity);
8600 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008601 }
8602
tom hsu0b59d292022-09-29 23:49:21 +08008603 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008604 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008605 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008606 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008607 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008608 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8609 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008610 Locale.forLanguageTag(localeTag).getCountry())) {
8611 return localeTag;
8612 }
8613 }
8614 return inputLocale.toLanguageTag();
8615 }
8616
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008617 /**
8618 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8619 */
8620 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008621 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Ling Ma9fa67412023-11-13 14:13:19 -08008622 mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/);
Narayan Kamath1c496c22015-04-16 14:40:19 +01008623 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008624
Gary Jian3aa9a762022-01-24 16:41:19 +08008625 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8626 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008627
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008628 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008629 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8630 * representing the state of the modem.
8631 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008632 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8633 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008634 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008635 */
8636 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008637 public void requestModemActivityInfo(ResultReceiver result) {
8638 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008639
8640 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8641 PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo");
8642
vagdeviaf9a5b92018-08-15 16:01:53 -07008643 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008644
8645 final long identity = Binder.clearCallingIdentity();
8646 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008647 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008648 } finally {
8649 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008650 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008651 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008652
Gary Jian76280a42022-12-07 16:18:33 +08008653 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008654 // less than total activity duration.
8655 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8656 if (info == null) {
8657 return false;
8658 }
8659 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008660 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008661 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8662
Hall Liu49656c02020-10-09 19:00:11 -07008663 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8664
Siddharth Rayb8114062018-06-17 15:02:38 -07008665 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008666 && (info.getSleepTimeMillis() <= activityDurationMs)
8667 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008668 }
8669
Gary Jian3aa9a762022-01-24 16:41:19 +08008670 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8671 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8672 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8673 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8674
8675 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8676 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8677 }
8678
8679 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8680 mLastModemActivityInfo.setReceiveTimeMillis(
8681 rat,
8682 freq,
8683 info.getReceiveTimeMillis(rat, freq)
8684 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8685 }
8686
8687 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8688 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8689 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8690 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8691
8692 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8693 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8694 }
8695 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8696 mLastModemActivityInfo.setReceiveTimeMillis(
8697 rat,
8698 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8699 }
8700
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008701 /**
8702 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8703 * @param info recent ModemActivityInfo
8704 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008705 private void mergeModemActivityInfo(ModemActivityInfo info) {
8706 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008707 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008708 boolean matched;
8709 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8710 matched = false;
8711 int rat = info.getSpecificInfoRat(i);
8712 int freq = info.getSpecificInfoFrequencyRange(i);
8713 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8714 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8715 //if it already exists
8716 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8717 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8718 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8719 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8720 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8721 updateLastModemActivityInfo(info, rat, freq);
8722 matched = true;
8723 }
8724 } else {
8725 updateLastModemActivityInfo(info, rat);
8726 matched = true;
8727 }
8728 }
8729 }
8730
8731 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008732 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008733 new ActivityStatsTechSpecificInfo(
8734 rat,
8735 freq,
8736 info.getTransmitTimeMillis(rat, freq),
8737 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008738 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008739 }
8740 }
8741 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8742 mLastModemActivitySpecificInfo =
8743 new ActivityStatsTechSpecificInfo[merged.size()];
8744 merged.toArray(mLastModemActivitySpecificInfo);
8745
8746 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8747 mLastModemActivityInfo.setSleepTimeMillis(
8748 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008749 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008750 mLastModemActivityInfo.setIdleTimeMillis(
8751 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008752 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008753
8754 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008755 new ModemActivityInfo(
8756 mLastModemActivityInfo.getTimestampMillis(),
8757 mLastModemActivityInfo.getSleepTimeMillis(),
8758 mLastModemActivityInfo.getIdleTimeMillis(),
8759 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008760 }
8761
8762 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8763 ActivityStatsTechSpecificInfo[] info) {
8764 int infoSize = info.length;
8765 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8766 for (int i = 0; i < infoSize; i++) {
8767 ret[i] = new ActivityStatsTechSpecificInfo(
8768 info[i].getRat(), info[i].getFrequencyRange(),
8769 info[i].getTransmitTimeMillis(),
8770 (int) info[i].getReceiveTimeMillis());
8771 }
8772 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008773 }
8774
Jack Yu85bd38a2015-11-09 11:34:32 -08008775 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008776 * Returns the service state information on specified subscription.
8777 */
8778 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008779 public ServiceState getServiceStateForSubscriber(int subId,
8780 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8781 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008782 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008783 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008784 return null;
8785 }
8786
joonhunshin4ac60942023-11-15 15:23:39 +00008787 enforceTelephonyFeatureWithException(callingPackage,
8788 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber");
8789
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008790 boolean hasFinePermission = false;
8791 boolean hasCoarsePermission = false;
8792 if (!renounceFineLocationAccess) {
8793 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8794 LocationAccessPolicy.checkLocationPermission(mApp,
8795 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8796 .setCallingPackage(callingPackage)
8797 .setCallingFeatureId(callingFeatureId)
8798 .setCallingPid(Binder.getCallingPid())
8799 .setCallingUid(Binder.getCallingUid())
8800 .setMethod("getServiceStateForSubscriber")
8801 .setLogAsInfo(true)
8802 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8803 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8804 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8805 .build());
8806 hasFinePermission =
8807 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8808 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008809
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008810 if (!renounceCoarseLocationAccess) {
8811 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8812 LocationAccessPolicy.checkLocationPermission(mApp,
8813 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8814 .setCallingPackage(callingPackage)
8815 .setCallingFeatureId(callingFeatureId)
8816 .setCallingPid(Binder.getCallingPid())
8817 .setCallingUid(Binder.getCallingUid())
8818 .setMethod("getServiceStateForSubscriber")
8819 .setLogAsInfo(true)
8820 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8821 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8822 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8823 .build());
8824 hasCoarsePermission =
8825 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8826 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008827
Jack Yu479f40e2020-10-27 21:29:25 -07008828 final Phone phone = getPhone(subId);
8829 if (phone == null) {
8830 return null;
8831 }
8832
Jordan Liu0f2bc442020-11-18 16:47:37 -08008833 final long identity = Binder.clearCallingIdentity();
8834
Jack Yu479f40e2020-10-27 21:29:25 -07008835 boolean isCallingPackageDataService = phone.getDataServicePackages()
8836 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008837 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008838 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu3beaf9d2023-04-14 09:17:27 -07008839 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8840 .getSubscriptionInfoInternal(subId);
8841 if (subInfo == null || !subInfo.isActive()) {
8842 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8843 + "subId=" + subId);
8844 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008845 }
8846
Hall Liuf19c44f2018-11-27 14:38:17 -08008847 ServiceState ss = phone.getServiceState();
8848
8849 // Scrub out the location info in ServiceState depending on what level of access
8850 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008851 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008852 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8853 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008854 } finally {
8855 Binder.restoreCallingIdentity(identity);
8856 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008857 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008858
8859 /**
8860 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8861 *
8862 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8863 * voicemail ringtone.
8864 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8865 * PhoneAccount.
8866 */
8867 @Override
8868 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008869 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8870 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri");
8871
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008872 final long identity = Binder.clearCallingIdentity();
8873 try {
8874 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8875 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008876 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008877 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008878
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008879 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8880 } finally {
8881 Binder.restoreCallingIdentity(identity);
8882 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008883 }
8884
8885 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008886 * Sets the per-account voicemail ringtone.
8887 *
8888 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8889 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8890 *
8891 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8892 * voicemail ringtone.
8893 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8894 * PhoneAccount.
8895 */
8896 @Override
8897 public void setVoicemailRingtoneUri(String callingPackage,
8898 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008899 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008900 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008901 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8902 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008903 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8904 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8905 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008906 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008907
joonhunshin4ac60942023-11-15 15:23:39 +00008908 enforceTelephonyFeatureWithException(callingPackage,
8909 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri");
8910
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008911 final long identity = Binder.clearCallingIdentity();
8912 try {
8913 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8914 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008915 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008916 }
8917 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8918 } finally {
8919 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008920 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008921 }
8922
8923 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008924 * Returns whether vibration is set for voicemail notification in Phone settings.
8925 *
8926 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8927 * voicemail vibration setting.
8928 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8929 */
8930 @Override
8931 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008932 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8933 PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled");
8934
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008935 final long identity = Binder.clearCallingIdentity();
8936 try {
8937 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8938 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008939 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008940 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008941
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008942 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8943 } finally {
8944 Binder.restoreCallingIdentity(identity);
8945 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008946 }
8947
Youhan Wange64578a2016-05-02 15:32:42 -07008948 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008949 * Sets the per-account voicemail vibration.
8950 *
8951 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8952 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8953 *
8954 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8955 * voicemail vibration setting.
8956 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8957 * specific PhoneAccount.
8958 */
8959 @Override
8960 public void setVoicemailVibrationEnabled(String callingPackage,
8961 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008962 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008963 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008964 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8965 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008966 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8967 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8968 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008969 }
8970
joonhunshin4ac60942023-11-15 15:23:39 +00008971 enforceTelephonyFeatureWithException(callingPackage,
8972 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled");
8973
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008974 final long identity = Binder.clearCallingIdentity();
8975 try {
8976 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8977 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008978 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008979 }
8980 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8981 } finally {
8982 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008983 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008984 }
8985
8986 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008987 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8988 *
8989 * @throws SecurityException if the caller does not have the required permission
8990 */
arunvoddud7401012022-12-15 16:08:12 +00008991 @VisibleForTesting
8992 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008993 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008994 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008995 }
8996
8997 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008998 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8999 * permission.
9000 *
9001 * @throws SecurityException if the caller does not have the required permission
9002 */
9003 private void enforceSendSmsPermission() {
9004 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
9005 }
9006
9007 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00009008 * Make sure either called from same process as self (phone) or IPC caller has interact across
9009 * users permission.
9010 *
9011 * @throws SecurityException if the caller does not have the required permission
9012 */
9013 private void enforceInteractAcrossUsersPermission(String message) {
9014 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
9015 }
9016
9017 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009018 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009019 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009020 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009021 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009022 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009023 final long identity = Binder.clearCallingIdentity();
9024 try {
9025 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009026 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009027 if (componentName == null) {
9028 throw new SecurityException(
9029 "Caller not current active visual voicemail package[null]");
9030 }
9031 String vvmPackage = componentName.getPackageName();
9032 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00009033 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009034 }
9035 } finally {
9036 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009037 }
9038 }
9039
9040 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009041 * Return the application ID for the app type.
9042 *
9043 * @param subId the subscription ID that this request applies to.
9044 * @param appType the uicc app type.
9045 * @return Application ID for specificied app type, or null if no uicc.
9046 */
9047 @Override
9048 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009049 enforceReadPrivilegedPermission("getAidForAppType");
joonhunshin4ac60942023-11-15 15:23:39 +00009050
9051 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9052 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType");
9053
Youhan Wange64578a2016-05-02 15:32:42 -07009054 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009055
9056 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07009057 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009058 if (phone == null) {
9059 return null;
9060 }
9061 String aid = null;
9062 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009063 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009064 .getApplicationByType(appType).getAid();
9065 } catch (Exception e) {
9066 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
9067 }
9068 return aid;
9069 } finally {
9070 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07009071 }
Youhan Wange64578a2016-05-02 15:32:42 -07009072 }
9073
Youhan Wang4001d252016-05-11 10:29:41 -07009074 /**
9075 * Return the Electronic Serial Number.
9076 *
9077 * @param subId the subscription ID that this request applies to.
9078 * @return ESN or null if error.
9079 */
9080 @Override
9081 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009082 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07009083 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009084
9085 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07009086 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009087 if (phone == null) {
9088 return null;
9089 }
9090 String esn = null;
9091 try {
9092 esn = phone.getEsn();
9093 } catch (Exception e) {
9094 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
9095 }
9096 return esn;
9097 } finally {
9098 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07009099 }
Youhan Wang4001d252016-05-11 10:29:41 -07009100 }
9101
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009102 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009103 * Return the Preferred Roaming List Version.
9104 *
9105 * @param subId the subscription ID that this request applies to.
9106 * @return PRLVersion or null if error.
9107 */
9108 @Override
9109 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009110 enforceReadPrivilegedPermission("getCdmaPrlVersion");
joonhunshin4ac60942023-11-15 15:23:39 +00009111
9112 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9113 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion");
9114
Youhan Wang66ad5d72016-07-18 17:56:58 -07009115 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009116
9117 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009118 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009119 if (phone == null) {
9120 return null;
9121 }
9122 String cdmaPrlVersion = null;
9123 try {
9124 cdmaPrlVersion = phone.getCdmaPrlVersion();
9125 } catch (Exception e) {
9126 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9127 }
9128 return cdmaPrlVersion;
9129 } finally {
9130 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009131 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009132 }
9133
9134 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009135 * Get snapshot of Telephony histograms
9136 * @return List of Telephony histograms
9137 * @hide
9138 */
9139 @Override
9140 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009141 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9142 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009143
9144 final long identity = Binder.clearCallingIdentity();
9145 try {
9146 return RIL.getTelephonyRILTimingHistograms();
9147 } finally {
9148 Binder.restoreCallingIdentity(identity);
9149 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009150 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009151
9152 /**
9153 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009154 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9155 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009156 * Require system privileges. In the future we may add this to carrier APIs.
9157 *
Michele Berionne482f8202018-11-27 18:57:59 -08009158 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009159 */
9160 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009161 @TelephonyManager.SetCarrierRestrictionResult
9162 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009163 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009164
9165 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9166 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers");
9167
vagdeviaf9a5b92018-08-15 16:01:53 -07009168 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009169
Michele Berionne482f8202018-11-27 18:57:59 -08009170 if (carrierRestrictionRules == null) {
9171 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009172 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009173
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009174 final long identity = Binder.clearCallingIdentity();
9175 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009176 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009177 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009178 } finally {
9179 Binder.restoreCallingIdentity(identity);
9180 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009181 }
9182
9183 /**
9184 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009185 * Get the allowed carrier list and the excluded carrier list, including the priority between
9186 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009187 * Require system privileges. In the future we may add this to carrier APIs.
9188 *
Michele Berionne482f8202018-11-27 18:57:59 -08009189 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009190 */
9191 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009192 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009193 enforceReadPrivilegedPermission("getAllowedCarriers");
joonhunshin4ac60942023-11-15 15:23:39 +00009194
9195 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9196 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers");
9197
vagdeviaf9a5b92018-08-15 16:01:53 -07009198 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009199
9200 final long identity = Binder.clearCallingIdentity();
9201 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009202 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9203 if (response instanceof CarrierRestrictionRules) {
9204 return (CarrierRestrictionRules) response;
9205 }
9206 // Response is an Exception of some kind,
9207 // which is signalled to the user as a NULL retval
9208 return null;
9209 } catch (Exception e) {
9210 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9211 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009212 } finally {
9213 Binder.restoreCallingIdentity(identity);
9214 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009215 }
9216
fionaxu59545b42016-05-25 15:53:37 -07009217 /**
arunvoddud7401012022-12-15 16:08:12 +00009218 * Fetches the carrier restriction status of the device and sends the status to the caller
9219 * through the callback.
9220 *
9221 * @param callback The callback that will be used to send the result.
9222 * @throws SecurityException if the caller does not have the required permission/privileges or
9223 * the caller is not allowlisted.
9224 */
9225 @Override
9226 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
9227 enforceReadPermission("getCarrierRestrictionStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00009228
9229 enforceTelephonyFeatureWithException(packageName,
9230 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierRestrictionStatus");
9231
arunvoddud7401012022-12-15 16:08:12 +00009232 int carrierId = validateCallerAndGetCarrierId(packageName);
9233 if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) {
9234 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9235 throw new SecurityException("Not an authorized caller");
9236 }
9237 final long identity = Binder.clearCallingIdentity();
9238 try {
9239 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
9240 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId);
9241 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9242 } finally {
9243 Binder.restoreCallingIdentity(identity);
9244 }
9245 }
9246
arunvoddu567f2b42023-04-25 17:22:00 +00009247 @Override
9248 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
9249 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
9250 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9251 return allowListInfo.getShaIdList(pkgName, carrierId);
9252 }
9253
arunvoddud7401012022-12-15 16:08:12 +00009254 @VisibleForTesting
9255 public int validateCallerAndGetCarrierId(String packageName) {
9256 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9257 return allowListInfo.validateCallerAndGetCarrierId(packageName);
9258 }
9259
9260 /**
fionaxu59545b42016-05-25 15:53:37 -07009261 * Action set from carrier signalling broadcast receivers to enable/disable radio
9262 * @param subId the subscription ID that this action applies to.
9263 * @param enabled control enable or disable radio.
9264 * {@hide}
9265 */
9266 @Override
9267 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9268 enforceModifyPermission();
9269 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009270
9271 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009272 if (phone == null) {
9273 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9274 return;
9275 }
9276 try {
9277 phone.carrierActionSetRadioEnabled(enabled);
9278 } catch (Exception e) {
9279 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009280 } finally {
9281 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009282 }
9283 }
9284
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009285 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009286 * Enable or disable Voice over NR (VoNR)
9287 * @param subId the subscription ID that this action applies to.
9288 * @param enabled enable or disable VoNR.
9289 * @return operation result.
9290 */
9291 @Override
9292 public int setVoNrEnabled(int subId, boolean enabled) {
9293 enforceModifyPermission();
9294 final Phone phone = getPhone(subId);
9295
9296 final long identity = Binder.clearCallingIdentity();
9297 if (phone == null) {
9298 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9299 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9300 }
9301
9302 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9303 try {
9304 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9305 workSource);
9306 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009307
9308 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9309 if (DBG) {
9310 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9311 }
9312 SubscriptionManager.setSubscriptionProperty(
9313 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9314 (enabled ? "1" : "0"));
9315 }
9316
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009317 return result;
9318 } finally {
9319 Binder.restoreCallingIdentity(identity);
9320 }
9321 }
9322
9323 /**
9324 * Is voice over NR enabled
9325 * @return true if VoNR is enabled else false
9326 */
9327 @Override
9328 public boolean isVoNrEnabled(int subId) {
9329 enforceReadPrivilegedPermission("isVoNrEnabled");
9330 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9331 final long identity = Binder.clearCallingIdentity();
9332 try {
9333 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9334 null, subId, workSource);
9335 if (DBG) log("isVoNrEnabled: " + isEnabled);
9336 return isEnabled;
9337 } finally {
9338 Binder.restoreCallingIdentity(identity);
9339 }
9340 }
9341
9342 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009343 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9344 * network status based on which carrier apps could apply actions accordingly,
9345 * enable/disable default url handler for example.
9346 *
9347 * @param subId the subscription ID that this action applies to.
9348 * @param report control start/stop reporting the default network status.
9349 * {@hide}
9350 */
9351 @Override
9352 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9353 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009354
9355 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9356 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
9357 "carrierActionReportDefaultNetworkStatus");
9358
fionaxu8da9cb12017-05-23 15:02:46 -07009359 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009360
9361 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009362 if (phone == null) {
9363 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9364 return;
9365 }
9366 try {
9367 phone.carrierActionReportDefaultNetworkStatus(report);
9368 } catch (Exception e) {
9369 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009370 } finally {
9371 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009372 }
9373 }
9374
9375 /**
fionaxud9622282017-07-17 17:51:30 -07009376 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9377 * @param subId the subscription ID that this action applies to.
9378 * {@hide}
9379 */
9380 @Override
9381 public void carrierActionResetAll(int subId) {
9382 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009383
9384 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9385 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll");
9386
fionaxud9622282017-07-17 17:51:30 -07009387 final Phone phone = getPhone(subId);
9388 if (phone == null) {
9389 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9390 return;
9391 }
9392 try {
9393 phone.carrierActionResetAll();
9394 } catch (Exception e) {
9395 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9396 }
9397 }
9398
9399 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009400 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9401 * bug report is being generated.
9402 */
9403 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009404 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009405 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9406 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009407 writer.println("Permission Denial: can't dump Phone from pid="
9408 + Binder.getCallingPid()
9409 + ", uid=" + Binder.getCallingUid()
9410 + "without permission "
9411 + android.Manifest.permission.DUMP);
9412 return;
9413 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009414 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009415 }
Jack Yueb89b242016-06-22 13:27:47 -07009416
Brad Ebingerdac2f002018-04-03 15:17:52 -07009417 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009418 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9419 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9420 @NonNull String[] args) {
9421 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9422 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009423 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009424 }
9425
Jack Yueb89b242016-06-22 13:27:47 -07009426 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009427 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009428 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009429 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009430 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009431 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009432 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009433 */
9434 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009435 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009436 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009437 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9438 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9439 try {
9440 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009441 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009442 } catch (SecurityException se) {
9443 enforceModifyPermission();
9444 }
9445 } else {
9446 enforceModifyPermission();
9447 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009448
Nate Myrenae97d192023-06-09 15:22:31 -07009449 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
9450 && null != callingPackage && opEnableMobileDataByUser()) {
9451 mAppOps.noteOp(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER, Binder.getCallingUid(),
9452 callingPackage, null, null);
9453 }
9454
joonhunshin4ac60942023-11-15 15:23:39 +00009455 enforceTelephonyFeatureWithException(callingPackage,
9456 PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason");
9457
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009458 final long identity = Binder.clearCallingIdentity();
9459 try {
9460 Phone phone = getPhone(subId);
9461 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009462 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9463 phone.carrierActionSetMeteredApnsEnabled(enabled);
9464 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07009465 phone.getDataSettingsManager().setDataEnabled(
9466 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009467 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009468 }
9469 } finally {
9470 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009471 }
9472 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009473
9474 /**
9475 * Get Client request stats
9476 * @return List of Client Request Stats
9477 * @hide
9478 */
9479 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009480 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9481 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009482 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009483 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009484 return null;
9485 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009486 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009487
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009488 final long identity = Binder.clearCallingIdentity();
9489 try {
9490 if (phone != null) {
9491 return phone.getClientRequestStats();
9492 }
9493
9494 return null;
9495 } finally {
9496 Binder.restoreCallingIdentity(identity);
9497 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009498 }
9499
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009500 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009501 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009502 if (uid == Process.ROOT_UID && packageName == null) {
9503 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9504 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9505 // exception. ROOT_UID seems not to have a valid package name returned by
9506 // PackageManager, so just fake it here to avoid issues when running telephony shell
9507 // commands that plumb through the RIL as root, like so:
9508 // $ adb root
9509 // $ adb shell cmd phone ...
9510 packageName = "root";
9511 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009512 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009513 }
Jack Yueb4124c2017-02-16 15:32:43 -08009514
9515 /**
Grace Chen70990072017-03-24 17:21:30 -07009516 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009517 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009518 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009519 * @param state State of SIM (power down, power up, pass through)
9520 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9521 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9522 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009523 *
9524 **/
9525 @Override
Grace Chen70990072017-03-24 17:21:30 -07009526 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009527 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009528
9529 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9530 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot");
9531
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009532 Phone phone = PhoneFactory.getPhone(slotIndex);
9533
vagdeviaf9a5b92018-08-15 16:01:53 -07009534 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9535
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009536 final long identity = Binder.clearCallingIdentity();
9537 try {
9538 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009539 phone.setSimPowerState(state, null, workSource);
9540 }
9541 } finally {
9542 Binder.restoreCallingIdentity(identity);
9543 }
9544 }
9545
9546 /**
9547 * Set SIM card power state.
9548 *
9549 * @param slotIndex SIM slot id.
9550 * @param state State of SIM (power down, power up, pass through)
9551 * @param callback callback to trigger after success or failure
9552 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9553 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9554 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9555 *
9556 **/
9557 @Override
9558 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9559 IIntegerConsumer callback) {
9560 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009561
9562 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9563 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
9564 "setSimPowerStateForSlotWithCallback");
9565
Jordan Liu109698e2020-11-24 14:50:34 -08009566 Phone phone = PhoneFactory.getPhone(slotIndex);
9567
9568 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9569
9570 final long identity = Binder.clearCallingIdentity();
9571 try {
9572 if (phone != null) {
9573 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9574 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009575 }
9576 } finally {
9577 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009578 }
9579 }
Shuo Qiandd210312017-04-12 22:11:33 +00009580
Tyler Gunn65d45c22017-06-05 11:22:26 -07009581 private boolean isUssdApiAllowed(int subId) {
9582 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009583 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009584 if (configManager == null) {
9585 return false;
9586 }
9587 PersistableBundle pb = configManager.getConfigForSubId(subId);
9588 if (pb == null) {
9589 return false;
9590 }
9591 return pb.getBoolean(
9592 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9593 }
9594
Shuo Qiandd210312017-04-12 22:11:33 +00009595 /**
Ling Mac28f0212023-03-24 16:07:15 -07009596 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00009597 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07009598 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00009599 */
goneil9c5f4872017-12-05 14:07:56 -08009600 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009601 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009602 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
joonhunshin4ac60942023-11-15 15:23:39 +00009603
9604 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9605 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode");
9606
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009607 final long identity = Binder.clearCallingIdentity();
9608 try {
Ling Mac28f0212023-03-24 16:07:15 -07009609 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009610 } finally {
9611 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009612 }
9613 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009614
9615 /**
9616 * Get the current signal strength information for the given subscription.
9617 * Because this information is not updated when the device is in a low power state
9618 * it should not be relied-upon to be current.
9619 * @param subId Subscription index
9620 * @return the most recent cached signal strength info from the modem
9621 */
9622 @Override
9623 public SignalStrength getSignalStrength(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00009624 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9625 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength");
9626
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009627 final long identity = Binder.clearCallingIdentity();
9628 try {
9629 Phone p = getPhone(subId);
9630 if (p == null) {
9631 return null;
9632 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009633
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009634 return p.getSignalStrength();
9635 } finally {
9636 Binder.restoreCallingIdentity(identity);
9637 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009638 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009639
Pengquan Meng77b7f132018-08-22 14:49:57 -07009640 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009641 * Get the current modem radio state for the given slot.
9642 * @param slotIndex slot index.
9643 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009644 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009645 * @return the current radio power state from the modem
9646 */
9647 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009648 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009649 Phone phone = PhoneFactory.getPhone(slotIndex);
9650 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009651 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9652 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009653 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9654 }
9655
joonhunshin4ac60942023-11-15 15:23:39 +00009656 enforceTelephonyFeatureWithException(callingPackage,
9657 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState");
9658
Chen Xuf792fd62018-10-17 17:54:36 +00009659 final long identity = Binder.clearCallingIdentity();
9660 try {
9661 return phone.getRadioPowerState();
9662 } finally {
9663 Binder.restoreCallingIdentity(identity);
9664 }
9665 }
9666 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9667 }
9668
9669 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009670 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9671 *
9672 * <p>Requires one of the following permissions:
9673 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009674 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009675 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9676 * privileges.
9677 *
9678 * @param subId subscription id
9679 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9680 * {@code false}.
9681 */
9682 @Override
9683 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009684 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009685 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009686 try {
9687 mApp.enforceCallingOrSelfPermission(
9688 android.Manifest.permission.ACCESS_NETWORK_STATE,
9689 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009690 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009691 mApp.enforceCallingOrSelfPermission(
9692 permission.READ_BASIC_PHONE_STATE, functionName);
9693 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009694 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009695 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009696 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009697 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009698
joonhunshin4ac60942023-11-15 15:23:39 +00009699 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9700 PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled");
9701
Pengquan Menga1bb6272018-09-06 09:59:22 -07009702 boolean isEnabled = false;
9703 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009704 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009705 Phone phone = getPhone(subId);
9706 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009707 } finally {
9708 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009709 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009710 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009711 }
9712
9713
9714 /**
9715 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9716 *
9717 * <p> Requires permission:
9718 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9719 * privileges.
9720 *
9721 * @param subId subscription id
9722 * @param isEnabled {@code true} means enable, {@code false} means disable.
9723 */
9724 @Override
9725 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009726 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9727 mApp, subId, "setDataRoamingEnabled");
9728
joonhunshin4ac60942023-11-15 15:23:39 +00009729 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9730 PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled");
9731
Pengquan Menga1bb6272018-09-06 09:59:22 -07009732 final long identity = Binder.clearCallingIdentity();
9733 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009734 Phone phone = getPhone(subId);
9735 if (phone != null) {
9736 phone.setDataRoamingEnabled(isEnabled);
9737 }
9738 } finally {
9739 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009740 }
9741 }
9742
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009743 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009744 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009745 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009746 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009747 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009748
joonhunshin4ac60942023-11-15 15:23:39 +00009749 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9750 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed");
9751
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009752 boolean isAllowed = true;
9753 final long identity = Binder.clearCallingIdentity();
9754 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009755 Phone phone = getPhone(subId);
9756 if (phone != null) {
9757 isAllowed = phone.isCspPlmnEnabled();
9758 }
9759 } finally {
9760 Binder.restoreCallingIdentity(identity);
9761 }
9762 return isAllowed;
9763 }
9764
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009765 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9766 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009767 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009768 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009769 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009770 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9771 if (phone == null) {
9772 return false;
9773 }
9774 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9775 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9776 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009777 }
9778
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009779 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009780 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009781 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009782 mApp.getSystemService(AppOpsManager.class)
9783 .checkPackage(Binder.getCallingUid(), callingPackage);
9784
Jordan Liu1e142fc2019-04-22 15:10:43 -07009785 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009786 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009787 try {
9788 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009789 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009790 } catch (SecurityException e) {
9791 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9792 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009793 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009794 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009795 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009796 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009797 }
joonhunshin4ac60942023-11-15 15:23:39 +00009798
9799 enforceTelephonyFeatureWithException(callingPackage,
9800 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo");
9801
sandeepjsb6c87872021-09-27 15:34:44 +00009802 // checking compatibility, if calling app's target SDK is T and beyond.
9803 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9804 Binder.getCallingUid())) {
9805 isIccIdAccessRestricted = true;
9806 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009807 final long identity = Binder.clearCallingIdentity();
9808 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009809 UiccController uiccController = UiccController.getInstance();
9810 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009811 if (hasReadPermission) {
9812 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009813 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009814
9815 // Remove private info if the caller doesn't have access
9816 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9817 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009818 //setting the value after compatibility check
9819 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009820 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9821 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009822 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009823 if (card == null) {
9824 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009825 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009826 continue;
9827 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009828 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9829 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009830 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009831 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009832 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009833 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9834 for (UiccPortInfo portInfo : portInfos) {
9835 UiccPort port = uiccController.getUiccPortForSlot(
9836 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9837 if (port == null) {
9838 // assume no access if port is null
9839 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9840 continue;
9841 }
9842 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9843 uiccPortInfos.add(portInfo);
9844 } else {
9845 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9846 }
9847 }
9848 filteredInfos.add(new UiccCardInfo(
9849 cardInfo.isEuicc(),
9850 cardInfo.getCardId(),
9851 null,
9852 cardInfo.getPhysicalSlotIndex(),
9853 cardInfo.isRemovable(),
9854 cardInfo.isMultipleEnabledProfilesSupported(),
9855 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009856 }
9857 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009858 } finally {
9859 Binder.restoreCallingIdentity(identity);
9860 }
9861 }
9862
sandeepjsb6c87872021-09-27 15:34:44 +00009863 /**
9864 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9865 * generally private and require carrier privileges to view.
9866 *
9867 * @hide
9868 */
9869 @NonNull
9870 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9871 List<UiccPortInfo> portinfo = new ArrayList<>();
9872 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9873 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9874 }
9875 return new UiccCardInfo(
9876 cardInfo.isEuicc(),
9877 cardInfo.getCardId(),
9878 null,
9879 cardInfo.getPhysicalSlotIndex(),
9880 cardInfo.isRemovable(),
9881 cardInfo.isMultipleEnabledProfilesSupported(),
9882 portinfo
9883 );
9884 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009885
sandeepjsb6c87872021-09-27 15:34:44 +00009886 /**
9887 * @hide
9888 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9889 * These values are generally private and require carrier privileges to view.
9890 */
9891 @NonNull
9892 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9893 return new UiccPortInfo(
9894 UiccPortInfo.ICCID_REDACTED,
9895 portInfo.getPortIndex(),
9896 portInfo.getLogicalSlotIndex(),
9897 portInfo.isActive()
9898 );
9899 }
9900 @Override
9901 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009902 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009903 mApp.getSystemService(AppOpsManager.class)
9904 .checkPackage(Binder.getCallingUid(), callingPackage);
9905
sandeepjsb6c87872021-09-27 15:34:44 +00009906 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009907
Aman Guptaf3c90b32022-03-17 04:54:16 +00009908 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9909 // we are reading iccId which is PII data.
9910 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009911
joonhunshin4ac60942023-11-15 15:23:39 +00009912 enforceTelephonyFeatureWithException(callingPackage,
9913 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo");
9914
sandeepjsb6c87872021-09-27 15:34:44 +00009915 // checking compatibility, if calling app's target SDK is T and beyond.
9916 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9917 Binder.getCallingUid())) {
9918 isLogicalSlotAccessRestricted = true;
9919 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009920 final long identity = Binder.clearCallingIdentity();
9921 try {
9922 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009923 if (slots == null || slots.length == 0) {
9924 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009925 return null;
9926 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009927 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9928 for (int i = 0; i < slots.length; i++) {
9929 UiccSlot slot = slots[i];
9930 if (slot == null) {
9931 continue;
9932 }
9933
Jordan Liu7be7e652019-05-06 18:55:02 +00009934 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009935 UiccCard card = slot.getUiccCard();
9936 if (card != null) {
9937 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009938 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009939 cardId = slot.getEid();
9940 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009941 // If cardId is null, use iccId of default port as cardId.
9942 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009943 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009944 }
9945
Jordan Liu857451f2019-05-09 16:35:35 -07009946 if (cardId != null) {
9947 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9948 // if cardId is an EID, it's all digits so this is fine
9949 cardId = IccUtils.stripTrailingFs(cardId);
9950 }
9951
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009952 int cardState = 0;
9953 switch (slot.getCardState()) {
9954 case CARDSTATE_ABSENT:
9955 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9956 break;
9957 case CARDSTATE_PRESENT:
9958 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9959 break;
9960 case CARDSTATE_ERROR:
9961 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9962 break;
9963 case CARDSTATE_RESTRICTED:
9964 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9965 break;
9966 default:
9967 break;
9968
9969 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009970 List<UiccPortInfo> portInfos = new ArrayList<>();
9971 int[] portIndexes = slot.getPortList();
9972 for (int portIdx : portIndexes) {
9973 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009974 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009975 portInfos.add(new UiccPortInfo(iccId, portIdx,
9976 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009977 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009978 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009979 slot.isEuicc(),
9980 cardId,
9981 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009982 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009983 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009984 //setting the value after compatibility check
9985 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009986 }
9987 return infos;
9988 } finally {
9989 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009990 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009991 }
9992
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009993 /* Returns null if doesn't have read permission or carrier privilege access. */
9994 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9995 boolean hasReadPermission) {
9996 String iccId = slot.getIccId(portIndex);
9997 if (hasReadPermission) { // if has read permission
9998 return iccId;
9999 } else {
10000 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
10001 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
10002 // if no read permission, checking carrier privilege access
10003 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
10004 return iccId;
10005 }
10006 }
10007 }
10008 // No read permission or carrier privilege access.
10009 return UiccPortInfo.ICCID_REDACTED;
10010 }
10011
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010012 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010013 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010014 public boolean switchSlots(int[] physicalSlots) {
10015 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010016
joonhunshin4ac60942023-11-15 15:23:39 +000010017 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10018 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots");
10019
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010020 final long identity = Binder.clearCallingIdentity();
10021 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010022 List<UiccSlotMapping> slotMappings = new ArrayList<>();
10023 for (int i = 0; i < physicalSlots.length; i++) {
10024 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
10025 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
10026 physicalSlots[i], i));
10027 }
10028 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010029 } finally {
10030 Binder.restoreCallingIdentity(identity);
10031 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010032 }
Jack Yu4c988042018-02-27 15:30:01 -080010033
10034 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010035 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
10036 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
10037 enforceModifyPermission();
10038
joonhunshin4ac60942023-11-15 15:23:39 +000010039 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10040 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping");
10041
sandeepjsb6c87872021-09-27 15:34:44 +000010042 final long identity = Binder.clearCallingIdentity();
10043 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010044 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +000010045 } finally {
10046 Binder.restoreCallingIdentity(identity);
10047 }
10048 }
10049
10050 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -080010051 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
joonhunshin4ac60942023-11-15 15:23:39 +000010052 enforceTelephonyFeatureWithException(callingPackage,
10053 PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc");
10054
Jordan Liu7de49fa2018-12-06 14:48:49 -080010055 final long identity = Binder.clearCallingIdentity();
10056 try {
10057 return UiccController.getInstance().getCardIdForDefaultEuicc();
10058 } finally {
10059 Binder.restoreCallingIdentity(identity);
10060 }
10061 }
10062
Pengquan Meng85728fb2018-03-12 16:31:21 -070010063 /**
goneil47ffb6e2018-04-06 15:40:58 -070010064 * A test API to reload the UICC profile.
10065 *
10066 * <p>Requires that the calling app has permission
10067 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
10068 * @hide
10069 */
10070 @Override
10071 public void refreshUiccProfile(int subId) {
10072 enforceModifyPermission();
10073
10074 final long identity = Binder.clearCallingIdentity();
10075 try {
10076 Phone phone = getPhone(subId);
10077 if (phone == null) {
10078 return;
10079 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010080 UiccPort uiccPort = phone.getUiccPort();
10081 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -070010082 return;
10083 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010084 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -070010085 if (uiccProfile == null) {
10086 return;
10087 }
10088 uiccProfile.refresh();
10089 } finally {
10090 Binder.restoreCallingIdentity(identity);
10091 }
10092 }
10093
10094 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010095 * Returns false if the mobile data is disabled by default, otherwise return true.
10096 */
10097 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010098 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010099 }
10100
10101 /**
10102 * Returns true if the data roaming is enabled by default, i.e the system property
10103 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
10104 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
10105 */
10106 private boolean getDefaultDataRoamingEnabled(int subId) {
10107 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010108 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -070010109 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010110 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
10111 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
10112 return isDataRoamingEnabled;
10113 }
10114
10115 /**
10116 * Returns the default network type for the given {@code subId}, if the default network type is
10117 * not set, return {@link Phone#PREFERRED_NT_MODE}.
10118 */
10119 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010120 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -080010121 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +090010122 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
10123 return list.get(phoneId);
10124 }
10125 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -070010126 }
fionaxua13278b2018-03-21 00:08:13 -070010127
10128 @Override
10129 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -070010130 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -070010131 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010132
10133 final long identity = Binder.clearCallingIdentity();
10134 try {
10135 final Phone phone = getPhone(subId);
10136 if (phone == null) {
10137 loge("setCarrierTestOverride fails with invalid subId: " + subId);
10138 return;
10139 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -080010140 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10141 if (cpt != null) {
10142 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
10143 }
10144 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -070010145 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
10146 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -070010147 if (carrierPrivilegeRules == null) {
10148 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
10149 } else {
10150 mCarrierPrivilegeTestOverrideSubIds.add(subId);
10151 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010152 } finally {
10153 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010154 }
fionaxua13278b2018-03-21 00:08:13 -070010155 }
10156
10157 @Override
Benedict Wong66477622023-02-03 23:30:57 +000010158 public void setCarrierServicePackageOverride(
10159 int subId, String carrierServicePackage, String callingPackage) {
10160 TelephonyPermissions.enforceShellOnly(
10161 Binder.getCallingUid(), "setCarrierServicePackageOverride");
10162
Benedict Wong66477622023-02-03 23:30:57 +000010163 final long identity = Binder.clearCallingIdentity();
10164 try {
10165 final Phone phone = getPhone(subId);
10166 if (phone == null || phone.getSubId() != subId) {
10167 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
10168 throw new IllegalArgumentException("No phone for subid");
10169 }
10170 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10171 if (cpt == null) {
10172 loge("setCarrierServicePackageOverride failed with no CPT for phone");
10173 throw new IllegalStateException("No CPT for phone");
10174 }
10175 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
10176 } finally {
10177 Binder.restoreCallingIdentity(identity);
10178 }
10179 }
10180
10181 @Override
fionaxua13278b2018-03-21 00:08:13 -070010182 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -070010183 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010184
10185 final long identity = Binder.clearCallingIdentity();
10186 try {
10187 final Phone phone = getPhone(subId);
10188 if (phone == null) {
10189 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
10190 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
10191 }
10192 return phone.getCarrierIdListVersion();
10193 } finally {
10194 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010195 }
fionaxua13278b2018-03-21 00:08:13 -070010196 }
Malcolm Chen2c63d402018-08-14 16:00:53 -070010197
10198 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010199 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
10200 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010201 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010202 mApp, subId, callingPackage, callingFeatureId,
10203 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010204 return -1;
10205 }
10206
10207 final long identity = Binder.clearCallingIdentity();
10208 try {
10209 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10210 } finally {
10211 Binder.restoreCallingIdentity(identity);
10212 }
10213 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010214
10215 @Override
10216 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +080010217 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010218 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010219 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010220
joonhunshin4ac60942023-11-15 15:23:39 +000010221 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10222 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode");
10223
Pengquan Menga1bb6272018-09-06 09:59:22 -070010224 final long identity = Binder.clearCallingIdentity();
10225 try {
10226 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10227 } finally {
10228 Binder.restoreCallingIdentity(identity);
10229 }
10230 }
10231
10232 @Override
10233 public boolean setCdmaRoamingMode(int subId, int mode) {
10234 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10235 mApp, subId, "setCdmaRoamingMode");
10236
joonhunshin4ac60942023-11-15 15:23:39 +000010237 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10238 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode");
10239
Pengquan Menga1bb6272018-09-06 09:59:22 -070010240 final long identity = Binder.clearCallingIdentity();
10241 try {
10242 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10243 } finally {
10244 Binder.restoreCallingIdentity(identity);
10245 }
10246 }
10247
10248 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010249 public int getCdmaSubscriptionMode(int subId) {
10250 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010251 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010252 mApp, subId, "getCdmaSubscriptionMode");
10253
joonhunshin4ac60942023-11-15 15:23:39 +000010254 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10255 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode");
10256
Sarah Chinbaab1432020-10-28 13:46:24 -070010257 final long identity = Binder.clearCallingIdentity();
10258 try {
10259 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10260 } finally {
10261 Binder.restoreCallingIdentity(identity);
10262 }
10263 }
10264
10265 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010266 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10267 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10268 mApp, subId, "setCdmaSubscriptionMode");
10269
joonhunshin4ac60942023-11-15 15:23:39 +000010270 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10271 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode");
10272
Pengquan Menga1bb6272018-09-06 09:59:22 -070010273 final long identity = Binder.clearCallingIdentity();
10274 try {
10275 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10276 } finally {
10277 Binder.restoreCallingIdentity(identity);
10278 }
10279 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010280
sqianc5eccab2018-10-19 18:46:41 -070010281 @Override
sqian8c685422019-02-22 15:55:18 -080010282 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010283 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010284 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010285 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10286 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010287 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10288 }
joonhunshin4ac60942023-11-15 15:23:39 +000010289
10290 enforceTelephonyFeatureWithException(callingPackage,
10291 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList");
10292
sqian11b7a0e2018-12-05 18:48:28 -080010293 final long identity = Binder.clearCallingIdentity();
10294 try {
sqian854d44b2018-12-12 16:48:18 -080010295 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10296 for (Phone phone: PhoneFactory.getPhones()) {
10297 if (phone.getEmergencyNumberTracker() != null
10298 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10299 emergencyNumberListInternal.put(
10300 phone.getSubId(),
10301 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10302 }
sqian11b7a0e2018-12-05 18:48:28 -080010303 }
sqian854d44b2018-12-12 16:48:18 -080010304 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010305 } finally {
10306 Binder.restoreCallingIdentity(identity);
10307 }
sqianc5eccab2018-10-19 18:46:41 -070010308 }
10309
10310 @Override
sqian8c685422019-02-22 15:55:18 -080010311 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010312 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010313 if (!exactMatch) {
10314 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010315 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010316 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010317 }
joonhunshin4ac60942023-11-15 15:23:39 +000010318
10319 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10320 PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber");
10321
sqian11b7a0e2018-12-05 18:48:28 -080010322 final long identity = Binder.clearCallingIdentity();
10323 try {
sqian854d44b2018-12-12 16:48:18 -080010324 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010325 //Note: we ignore passed in param exactMatch. We can remove it once
10326 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010327 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010328 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010329 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010330 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010331 }
sqian11b7a0e2018-12-05 18:48:28 -080010332 }
10333 return false;
10334 } finally {
10335 Binder.restoreCallingIdentity(identity);
10336 }
10337 }
10338
sqianf4ca7ed2019-01-15 18:32:07 -080010339 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010340 * Start emergency callback mode for GsmCdmaPhone for testing.
10341 */
10342 @Override
10343 public void startEmergencyCallbackMode() {
10344 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10345 "startEmergencyCallbackMode");
10346 enforceModifyPermission();
10347 final long identity = Binder.clearCallingIdentity();
10348 try {
10349 for (Phone phone : PhoneFactory.getPhones()) {
10350 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10351 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10352 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10353 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10354 gsmCdmaPhone.obtainMessage(
10355 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10356 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10357 }
10358 }
10359 } finally {
10360 Binder.restoreCallingIdentity(identity);
10361 }
10362 }
10363
10364 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010365 * Update emergency number list for test mode.
10366 */
10367 @Override
10368 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10369 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10370 "updateEmergencyNumberListTestMode");
10371
10372 final long identity = Binder.clearCallingIdentity();
10373 try {
10374 for (Phone phone: PhoneFactory.getPhones()) {
10375 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10376 if (tracker != null) {
10377 tracker.executeEmergencyNumberTestModeCommand(action, num);
10378 }
10379 }
10380 } finally {
10381 Binder.restoreCallingIdentity(identity);
10382 }
10383 }
10384
10385 /**
10386 * Get the full emergency number list for test mode.
10387 */
10388 @Override
10389 public List<String> getEmergencyNumberListTestMode() {
10390 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10391 "getEmergencyNumberListTestMode");
10392
10393 final long identity = Binder.clearCallingIdentity();
10394 try {
10395 Set<String> emergencyNumbers = new HashSet<>();
10396 for (Phone phone: PhoneFactory.getPhones()) {
10397 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10398 if (tracker != null) {
10399 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10400 emergencyNumbers.add(num.getNumber());
10401 }
10402 }
10403 }
10404 return new ArrayList<>(emergencyNumbers);
10405 } finally {
10406 Binder.restoreCallingIdentity(identity);
10407 }
10408 }
10409
chen xud6b45bd2018-10-30 22:27:10 -070010410 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010411 public int getEmergencyNumberDbVersion(int subId) {
10412 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10413
joonhunshin4ac60942023-11-15 15:23:39 +000010414 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10415 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion");
10416
Shuo Qian3b6ee772019-11-13 17:43:31 -080010417 final long identity = Binder.clearCallingIdentity();
10418 try {
10419 final Phone phone = getPhone(subId);
10420 if (phone == null) {
10421 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10422 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10423 }
10424 return phone.getEmergencyNumberDbVersion();
10425 } finally {
10426 Binder.restoreCallingIdentity(identity);
10427 }
10428 }
10429
10430 @Override
10431 public void notifyOtaEmergencyNumberDbInstalled() {
10432 enforceModifyPermission();
10433
joonhunshin4ac60942023-11-15 15:23:39 +000010434 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10435 PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled");
10436
Shuo Qian3b6ee772019-11-13 17:43:31 -080010437 final long identity = Binder.clearCallingIdentity();
10438 try {
10439 for (Phone phone: PhoneFactory.getPhones()) {
10440 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10441 if (tracker != null) {
10442 tracker.updateOtaEmergencyNumberDatabase();
10443 }
10444 }
10445 } finally {
10446 Binder.restoreCallingIdentity(identity);
10447 }
10448 }
10449
10450 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010451 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010452 enforceActiveEmergencySessionPermission();
10453
joonhunshin4ac60942023-11-15 15:23:39 +000010454 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10455 PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath");
10456
Shuo Qian3b6ee772019-11-13 17:43:31 -080010457 final long identity = Binder.clearCallingIdentity();
10458 try {
10459 for (Phone phone: PhoneFactory.getPhones()) {
10460 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10461 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010462 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10463 }
10464 }
10465 } finally {
10466 Binder.restoreCallingIdentity(identity);
10467 }
10468 }
10469
10470 @Override
10471 public void resetOtaEmergencyNumberDbFilePath() {
10472 enforceActiveEmergencySessionPermission();
10473
joonhunshin4ac60942023-11-15 15:23:39 +000010474 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10475 PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath");
10476
Shuo Qianc373f112020-03-05 17:55:34 -080010477 final long identity = Binder.clearCallingIdentity();
10478 try {
10479 for (Phone phone: PhoneFactory.getPhones()) {
10480 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10481 if (tracker != null) {
10482 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010483 }
10484 }
10485 } finally {
10486 Binder.restoreCallingIdentity(identity);
10487 }
10488 }
10489
10490 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010491 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10492 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10493 Phone phone = getPhone(subId);
10494 if (phone == null) {
10495 return null;
10496 }
10497 final long identity = Binder.clearCallingIdentity();
10498 try {
10499 UiccProfile profile = UiccController.getInstance()
10500 .getUiccProfileForPhone(phone.getPhoneId());
10501 if (profile != null) {
10502 return profile.getCertsFromCarrierPrivilegeAccessRules();
10503 }
10504 } finally {
10505 Binder.restoreCallingIdentity(identity);
10506 }
10507 return null;
10508 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010509
10510 /**
10511 * Enable or disable a modem stack.
10512 */
10513 @Override
10514 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10515 enforceModifyPermission();
10516
joonhunshin4ac60942023-11-15 15:23:39 +000010517 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10518 PackageManager.FEATURE_TELEPHONY, "enableModemForSlot");
10519
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010520 final long identity = Binder.clearCallingIdentity();
10521 try {
10522 Phone phone = PhoneFactory.getPhone(slotIndex);
10523 if (phone == null) {
10524 return false;
10525 } else {
10526 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10527 }
10528 } finally {
10529 Binder.restoreCallingIdentity(identity);
10530 }
10531 }
Michelecea4cf22018-12-21 15:00:11 -080010532
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010533 /**
10534 * Whether a modem stack is enabled or not.
10535 */
10536 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010537 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10538 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010539 Phone phone = PhoneFactory.getPhone(slotIndex);
10540 if (phone == null) return false;
10541
10542 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010543 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10544 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010545 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10546 }
10547
joonhunshin4ac60942023-11-15 15:23:39 +000010548 enforceTelephonyFeatureWithException(callingPackage,
10549 PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot");
10550
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010551 final long identity = Binder.clearCallingIdentity();
10552 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010553 try {
10554 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10555 } catch (NoSuchElementException ex) {
10556 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10557 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010558 } finally {
10559 Binder.restoreCallingIdentity(identity);
10560 }
10561 }
10562
Michelecea4cf22018-12-21 15:00:11 -080010563 @Override
Michele0ea7d782019-03-19 14:58:42 -070010564 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010565 enforceModifyPermission();
10566
joonhunshin4ac60942023-11-15 15:23:39 +000010567 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10568 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction");
10569
Michelecea4cf22018-12-21 15:00:11 -080010570 final long identity = Binder.clearCallingIdentity();
10571 try {
10572 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010573 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010574 .commit();
10575 } finally {
10576 Binder.restoreCallingIdentity(identity);
10577 }
10578 }
10579
10580 @Override
Michele0ea7d782019-03-19 14:58:42 -070010581 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010582 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010583 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010584 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10585 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010586 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010587 }
Michelecea4cf22018-12-21 15:00:11 -080010588
joonhunshin4ac60942023-11-15 15:23:39 +000010589 enforceTelephonyFeatureWithException(callingPackage,
10590 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported");
10591
Michelecea4cf22018-12-21 15:00:11 -080010592 final long identity = Binder.clearCallingIdentity();
10593 try {
Michele0ea7d782019-03-19 14:58:42 -070010594 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010595 } finally {
10596 Binder.restoreCallingIdentity(identity);
10597 }
10598 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010599
Michele0ea7d782019-03-19 14:58:42 -070010600 @TelephonyManager.IsMultiSimSupportedResult
10601 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010602 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10603 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10604 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010605 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10606 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010607 }
10608 // Check if the hardware supports multisim functionality. If usage of multisim is not
10609 // supported by the modem, indicate that it is restricted.
10610 PhoneCapability staticCapability =
10611 mPhoneConfigurationManager.getStaticPhoneCapability();
10612 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010613 loge("isMultiSimSupportedInternal: no static configuration available");
10614 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010615 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010616 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010617 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10618 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010619 }
10620 // Check if support of multiple SIMs is restricted by carrier
10621 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010622 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010623 }
10624
Michele0ea7d782019-03-19 14:58:42 -070010625 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010626 }
10627
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010628 /**
10629 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010630 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10631 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10632 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010633 * @param numOfSims number of active sims we want to switch to
10634 */
10635 @Override
10636 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010637 if (numOfSims == 1) {
10638 enforceModifyPermission();
10639 } else {
10640 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10641 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10642 }
joonhunshin4ac60942023-11-15 15:23:39 +000010643
10644 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10645 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig");
10646
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010647 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010648
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010649 try {
Michele30b57b22019-03-01 12:01:14 -080010650 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010651 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010652 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10653 return;
10654 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010655 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10656 } finally {
10657 Binder.restoreCallingIdentity(identity);
10658 }
10659 }
10660
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010661 @Override
10662 public boolean isApplicationOnUicc(int subId, int appType) {
10663 enforceReadPrivilegedPermission("isApplicationOnUicc");
joonhunshin4ac60942023-11-15 15:23:39 +000010664
10665 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10666 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc");
10667
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010668 Phone phone = getPhone(subId);
10669 if (phone == null) {
10670 return false;
10671 }
10672 final long identity = Binder.clearCallingIdentity();
10673 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010674 UiccPort uiccPort = phone.getUiccPort();
10675 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010676 return false;
10677 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010678 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010679 if (uiccProfile == null) {
10680 return false;
10681 }
10682 if (TelephonyManager.APPTYPE_SIM <= appType
10683 && appType <= TelephonyManager.APPTYPE_ISIM) {
10684 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10685 }
10686 return false;
10687 } finally {
10688 Binder.restoreCallingIdentity(identity);
10689 }
10690 }
10691
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010692 /**
chen xub4baa772019-04-03 10:23:41 -070010693 * Get whether making changes to modem configurations will trigger reboot.
10694 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010695 */
10696 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010697 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10698 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010699 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010700 mApp, subId, callingPackage, callingFeatureId,
10701 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010702 return false;
10703 }
joonhunshin4ac60942023-11-15 15:23:39 +000010704
10705 enforceTelephonyFeatureWithException(callingPackage,
10706 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
10707 "doesSwitchMultiSimConfigTriggerReboot");
10708
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010709 final long identity = Binder.clearCallingIdentity();
10710 try {
10711 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10712 } finally {
10713 Binder.restoreCallingIdentity(identity);
10714 }
10715 }
10716
Nathan Harold29f5f052019-02-15 13:41:57 -080010717 private void updateModemStateMetrics() {
10718 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10719 // TODO: check the state for each modem if the api is ready.
10720 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10721 }
10722
Pengquan Meng3889a572019-01-23 11:16:29 -080010723 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010724 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010725 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010726 // Verify that the callingPackage belongs to the calling UID
10727 mApp.getSystemService(AppOpsManager.class)
10728 .checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000010729
10730 enforceTelephonyFeatureWithException(callingPackage,
10731 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping");
10732
Pengquan Meng3889a572019-01-23 11:16:29 -080010733 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010734 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010735 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010736 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10737 if (slotInfos != null) {
10738 for (int i = 0; i < slotInfos.length; i++) {
10739 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10740 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10741 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10742 portInfo.getLogicalSlotIndex()));
10743 }
10744 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010745 }
10746 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010747 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010748 } finally {
10749 Binder.restoreCallingIdentity(identity);
10750 }
10751 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010752
10753 /**
10754 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010755 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010756 */
jimsunf9ec1622022-09-13 21:18:43 +080010757 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010758 @Override
10759 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010760 return getHalVersion(HAL_SERVICE_RADIO);
10761 }
10762
10763 /**
10764 * Get the HAL Version of a specific service
10765 */
10766 @Override
10767 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010768 Phone phone = getDefaultPhone();
10769 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010770 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010771 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10772 return hv.major * 100 + hv.minor;
10773 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010774
10775 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010776 * Get the current calling package name.
sangyun097dcf72024-01-04 10:35:49 +090010777 *
10778 * @return the current calling package name, or null if there is no known package.
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010779 */
10780 @Override
sangyun097dcf72024-01-04 10:35:49 +090010781 public @Nullable String getCurrentPackageName() {
10782 PackageManager pm = mApp.getPackageManager();
10783 String[] packageNames = pm == null ? null : pm.getPackagesForUid(Binder.getCallingUid());
10784 return packageNames == null ? null : packageNames[0];
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010785 }
10786
10787 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010788 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10789 * corresponding network requests on a subId.
10790 *
10791 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010792 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010793 * 2) APN is un-metered for this subscription, or
10794 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010795 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010796 *
10797 * @return whether data is allowed for a apn type.
10798 *
10799 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010800 */
10801 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010802 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010803 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10804 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010805
joonhunshin4ac60942023-11-15 15:23:39 +000010806 enforceTelephonyFeatureWithException(callingPackage,
10807 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn");
10808
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010809 // Now that all security checks passes, perform the operation as ourselves.
10810 final long identity = Binder.clearCallingIdentity();
10811 try {
10812 Phone phone = getPhone(subId);
10813 if (phone == null) return false;
10814
Jack Yu27422a52022-03-21 10:38:05 -070010815 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010816 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010817 isMetered = phone.getDataNetworkController().getDataConfigManager()
10818 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10819 phone.getServiceState().getDataRoaming());
10820 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010821 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010822 } finally {
10823 Binder.restoreCallingIdentity(identity);
10824 }
10825 }
10826
10827 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010828 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010829 enforceReadPrivilegedPermission("isApnMetered");
10830
joonhunshin4ac60942023-11-15 15:23:39 +000010831 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10832 PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered");
10833
Malcolm Chene5ad5792019-04-18 13:51:02 -070010834 // Now that all security checks passes, perform the operation as ourselves.
10835 final long identity = Binder.clearCallingIdentity();
10836 try {
10837 Phone phone = getPhone(subId);
10838 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010839 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10840 DataUtils.apnTypeToNetworkCapability(apnType),
10841 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010842 } finally {
10843 Binder.restoreCallingIdentity(identity);
10844 }
10845 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010846
10847 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010848 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10849 int subscriptionId, IBooleanConsumer resultCallback) {
10850 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +000010851
10852 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10853 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels");
10854
Hall Liu73f5d362020-01-20 13:42:00 -080010855 long token = Binder.clearCallingIdentity();
10856 try {
10857 Phone phone = getPhone(subscriptionId);
10858 if (phone == null) {
10859 try {
10860 if (resultCallback != null) {
10861 resultCallback.accept(false);
10862 }
10863 } catch (RemoteException e) {
10864 // ignore
10865 }
10866 return;
10867 }
10868 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10869 Pair.create(specifiers, (x) -> {
10870 try {
10871 if (resultCallback != null) {
10872 resultCallback.accept(x);
10873 }
10874 } catch (RemoteException e) {
10875 // ignore
10876 }
10877 });
10878 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10879 } finally {
10880 Binder.restoreCallingIdentity(token);
10881 }
10882 }
10883
10884 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010885 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10886 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010887 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010888 mApp, subId, "getSystemSelectionChannels");
joonhunshin4ac60942023-11-15 15:23:39 +000010889
10890 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10891 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels");
10892
Sarah Chin679c08a2020-11-18 13:39:35 -080010893 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10894 final long identity = Binder.clearCallingIdentity();
10895 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010896 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10897 if (result instanceof IllegalStateException) {
10898 throw (IllegalStateException) result;
10899 }
10900 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010901 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10902 return specifiers;
10903 } finally {
10904 Binder.restoreCallingIdentity(identity);
10905 }
10906 }
10907
10908 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010909 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010910 enforceReadPrivilegedPermission("isMvnoMatched");
joonhunshin4ac60942023-11-15 15:23:39 +000010911
10912 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10913 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched");
10914
Jack Yu8b766fc2022-03-21 09:42:33 -070010915 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010916 }
10917
10918 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010919 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10920 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010921 if (callingPackage == null) {
10922 callingPackage = getCurrentPackageName();
10923 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010924 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10925 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010926 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10927 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010928 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10929 }
10930 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10931 Intent intent = new Intent();
10932 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10933 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10934 // Bring up choose default SMS subscription dialog right now
10935 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10936 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10937 mApp.startActivity(intent);
10938 }
chen xud5ca2d52019-05-28 15:20:57 -070010939
10940 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010941 public void showSwitchToManagedProfileDialog() {
10942 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000010943 try {
10944 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
10945 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
10946 // for work telephony.
10947 Intent intent = new Intent(Intent.ACTION_SENDTO);
10948 intent.setData(Uri.parse("smsto:"));
10949 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10950 mApp.startActivity(intent);
10951 } catch (ActivityNotFoundException e) {
10952 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
10953 Intent intent = new Intent();
10954 intent.setClass(mApp, ErrorDialogActivity.class);
10955 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10956 mApp.startActivity(intent);
10957 }
Ayush Sharma787854b2022-12-12 14:55:02 +000010958 }
10959
10960 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010961 public String getMmsUAProfUrl(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000010962 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10963 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl");
10964
chen xud5ca2d52019-05-28 15:20:57 -070010965 //TODO investigate if this API should require proper permission check in R b/133791609
10966 final long identity = Binder.clearCallingIdentity();
10967 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010968 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10969 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10970 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10971 return carrierUAProfUrl;
10972 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010973 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10974 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010975 } finally {
10976 Binder.restoreCallingIdentity(identity);
10977 }
10978 }
10979
10980 @Override
10981 public String getMmsUserAgent(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000010982 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10983 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent");
10984
chen xud5ca2d52019-05-28 15:20:57 -070010985 //TODO investigate if this API should require proper permission check in R b/133791609
10986 final long identity = Binder.clearCallingIdentity();
10987 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010988 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10989 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10990 if (!TextUtils.isEmpty(carrierUserAgent)) {
10991 return carrierUserAgent;
10992 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010993 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10994 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010995 } finally {
10996 Binder.restoreCallingIdentity(identity);
10997 }
10998 }
Jack Yub07d4972019-05-28 16:12:25 -070010999
11000 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070011001 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
11002 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070011003
joonhunshin4ac60942023-11-15 15:23:39 +000011004 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11005 PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled");
11006
Jack Yub07d4972019-05-28 16:12:25 -070011007 final long identity = Binder.clearCallingIdentity();
11008 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011009 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070011010 if (phone == null) return false;
11011
Ling Maf188d502022-09-16 15:22:36 -070011012 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070011013 } finally {
11014 Binder.restoreCallingIdentity(identity);
11015 }
11016 }
11017
11018 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080011019 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070011020 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080011021 enforceModifyPermission();
11022
joonhunshin4ac60942023-11-15 15:23:39 +000011023 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11024 PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled");
11025
changbettyd5c246e2019-12-24 15:40:37 +080011026 final long identity = Binder.clearCallingIdentity();
11027 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011028 Phone phone = getPhone(subscriptionId);
11029 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080011030
Ling Maf188d502022-09-16 15:22:36 -070011031 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080011032 } finally {
11033 Binder.restoreCallingIdentity(identity);
11034 }
11035 }
11036
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011037 /**
Hall Liu746e03c2020-09-25 11:13:49 -070011038 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011039 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
11040 * otherwise.
11041 */
11042 @Override
11043 public void setCepEnabled(boolean isCepEnabled) {
11044 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
11045
11046 final long identity = Binder.clearCallingIdentity();
11047 try {
11048 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
11049 for (Phone phone : PhoneFactory.getPhones()) {
11050 Phone defaultPhone = phone.getImsPhone();
11051 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
11052 ImsPhone imsPhone = (ImsPhone) defaultPhone;
11053 ImsPhoneCallTracker imsPhoneCallTracker =
11054 (ImsPhoneCallTracker) imsPhone.getCallTracker();
11055 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
11056 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
11057 + imsPhone.getMsisdn());
11058 }
11059 }
11060 } finally {
11061 Binder.restoreCallingIdentity(identity);
11062 }
11063 }
allenwtsu46dcc572020-01-08 18:24:03 +080011064
11065 /**
11066 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
11067 *
11068 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
11069 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
11070 * before being read.
11071 */
11072 @Override
11073 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
11074 isCompressed) {
11075 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11076 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011077 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11078 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11079 }
joonhunshin4ac60942023-11-15 15:23:39 +000011080
11081 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11082 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11083 Binder.getCallingUserHandle())) {
11084 if (!isImsAvailableOnDevice()) {
11085 // ProvisioningManager can not handle ServiceSpecificException.
11086 // Throw the IllegalStateException and annotate ProvisioningManager.
11087 throw new IllegalStateException("IMS not available on device.");
11088 }
11089 } else {
11090 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11091 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11092 "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011093 }
11094
11095 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080011096 try {
Hui Wang761a6682020-10-31 05:12:53 +000011097 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
11098 } finally {
11099 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080011100 }
11101 }
zoey chene02881a2019-12-30 16:11:23 +080011102
11103 @Override
11104 public boolean isIccLockEnabled(int subId) {
11105 enforceReadPrivilegedPermission("isIccLockEnabled");
11106
joonhunshin4ac60942023-11-15 15:23:39 +000011107 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11108 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled");
11109
zoey chene02881a2019-12-30 16:11:23 +080011110 // Now that all security checks passes, perform the operation as ourselves.
11111 final long identity = Binder.clearCallingIdentity();
11112 try {
11113 Phone phone = getPhone(subId);
11114 if (phone != null && phone.getIccCard() != null) {
11115 return phone.getIccCard().getIccLockEnabled();
11116 } else {
11117 return false;
11118 }
11119 } finally {
11120 Binder.restoreCallingIdentity(identity);
11121 }
11122 }
11123
11124 /**
11125 * Set the ICC pin lock enabled or disabled.
11126 *
11127 * @return an integer representing the status of IccLock enabled or disabled in the following
11128 * three cases:
11129 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
11130 * successfully.
11131 * - Positive number and zero for remaining password attempts.
11132 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11133 *
11134 */
11135 @Override
11136 public int setIccLockEnabled(int subId, boolean enabled, String password) {
11137 enforceModifyPermission();
11138
joonhunshin4ac60942023-11-15 15:23:39 +000011139 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11140 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled");
11141
zoey chene02881a2019-12-30 16:11:23 +080011142 Phone phone = getPhone(subId);
11143 if (phone == null) {
11144 return 0;
11145 }
11146 // Now that all security checks passes, perform the operation as ourselves.
11147 final long identity = Binder.clearCallingIdentity();
11148 try {
11149 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
11150 new Pair<Boolean, String>(enabled, password), phone, null);
11151 return attemptsRemaining;
11152
11153 } catch (Exception e) {
11154 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
11155 } finally {
11156 Binder.restoreCallingIdentity(identity);
11157 }
11158 return 0;
11159 }
11160
11161 /**
11162 * Change the ICC password used in ICC pin lock.
11163 *
11164 * @return an integer representing the status of IccLock changed in the following three cases:
11165 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
11166 * - Positive number and zero for remaining password attempts.
11167 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11168 *
11169 */
11170 @Override
11171 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
11172 enforceModifyPermission();
11173
joonhunshin4ac60942023-11-15 15:23:39 +000011174 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11175 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword");
11176
zoey chene02881a2019-12-30 16:11:23 +080011177 Phone phone = getPhone(subId);
11178 if (phone == null) {
11179 return 0;
11180 }
11181 // Now that all security checks passes, perform the operation as ourselves.
11182 final long identity = Binder.clearCallingIdentity();
11183 try {
11184 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
11185 new Pair<String, String>(oldPassword, newPassword), phone, null);
11186 return attemptsRemaining;
11187
11188 } catch (Exception e) {
11189 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
11190 } finally {
11191 Binder.restoreCallingIdentity(identity);
11192 }
11193 return 0;
11194 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080011195
11196 /**
11197 * Request for receiving user activity notification
11198 */
11199 @Override
11200 public void requestUserActivityNotification() {
11201 if (!mNotifyUserActivity.get()
11202 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
11203 mNotifyUserActivity.set(true);
11204 }
11205 }
11206
11207 /**
11208 * Called when userActivity is signalled in the power manager.
11209 * This is safe to call from any thread, with any window manager locks held or not.
11210 */
11211 @Override
11212 public void userActivity() {
11213 // ***************************************
11214 // * Inherited from PhoneWindowManager *
11215 // ***************************************
11216 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
11217 // WITH ITS LOCKS HELD.
11218 //
11219 // This code must be VERY careful about the locks
11220 // it acquires.
11221 // In fact, the current code acquires way too many,
11222 // and probably has lurking deadlocks.
11223
11224 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
11225 throw new SecurityException("Only the OS may call notifyUserActivity()");
11226 }
11227
11228 if (mNotifyUserActivity.getAndSet(false)) {
11229 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
11230 USER_ACTIVITY_NOTIFICATION_DELAY);
11231 }
11232 }
Malcolm Chen4639c562020-04-13 11:59:40 -070011233
11234 @Override
11235 public boolean canConnectTo5GInDsdsMode() {
11236 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
11237 }
Jack Yud10cdd42020-09-28 20:28:01 -070011238
11239 @Override
11240 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
11241 String callingFeatureId) {
11242 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
11243 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
11244 throw new SecurityException("Requires READ_PHONE_STATE permission.");
11245 }
11246
joonhunshin4ac60942023-11-15 15:23:39 +000011247 enforceTelephonyFeatureWithException(callingPackage,
11248 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns");
11249
Jack Yud10cdd42020-09-28 20:28:01 -070011250 Phone phone = getPhone(subId);
11251 if (phone == null) {
11252 throw new RuntimeException("phone is not available");
11253 }
11254 // Now that all security checks passes, perform the operation as ourselves.
11255 final long identity = Binder.clearCallingIdentity();
11256 try {
11257 return phone.getEquivalentHomePlmns();
11258 } finally {
11259 Binder.restoreCallingIdentity(identity);
11260 }
11261 }
Daniel Bright59e67312020-11-13 11:49:37 -080011262
11263 @Override
11264 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011265 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
joonhunshin4ac60942023-11-15 15:23:39 +000011266 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11267 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
11268 "isRadioInterfaceCapabilitySupported");
11269
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011270 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080011271 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080011272 if (radioInterfaceCapabilities == null) {
11273 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080011274 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011275 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080011276 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011277
Hui Wang641e81c2020-10-12 12:14:23 -070011278 @Override
11279 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
11280 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000011281 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
11282 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11283 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
11284 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11285 Manifest.permission.MODIFY_PHONE_STATE);
joonhunshin4ac60942023-11-15 15:23:39 +000011286
11287 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11288 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest");
11289
Hui Wang641e81c2020-10-12 12:14:23 -070011290 if (DBG) {
11291 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
11292 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
11293 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
11294 }
11295
11296 if (!SubscriptionManager.isValidSubscriptionId(subId)
11297 || appType < TelephonyManager.APPTYPE_UNKNOWN
11298 || appType > TelephonyManager.APPTYPE_ISIM
11299 || nafUrl == null || securityProtocol == null || callback == null) {
11300 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
11301 if (callback != null) {
11302 try {
11303 callback.onAuthenticationFailure(
11304 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
11305 } catch (RemoteException exception) {
11306 log("Fail to notify onAuthenticationFailure due to " + exception);
11307 }
11308 return;
11309 }
11310 }
11311
11312 final long token = Binder.clearCallingIdentity();
11313 try {
11314 getGbaManager(subId).bootstrapAuthenticationRequest(
11315 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011316 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070011317 } finally {
11318 Binder.restoreCallingIdentity(token);
11319 }
11320 }
11321
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011322 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011323 * Attempts to set the radio power state for all phones for thermal reason.
11324 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011325 * requested radio power state will actually be set. See {@link
11326 * PhoneInternalInterface#setRadioPowerForReason} for more details.
11327 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011328 * @param enable {@code true} if trying to turn radio on.
11329 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
11330 * false}.
11331 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011332 private boolean setRadioPowerForThermal(boolean enable) {
11333 boolean isPhoneAvailable = false;
11334 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
11335 Phone phone = PhoneFactory.getPhone(i);
11336 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011337 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011338 isPhoneAvailable = true;
11339 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011340 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011341
11342 // return true if successfully informed the phone object about the thermal radio power
11343 // request.
11344 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011345 }
11346
11347 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011348 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011349 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11350 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11351 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11352 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11353 throw new IllegalArgumentException("modem does not support data throttling");
11354 }
11355
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011356 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11357 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011358 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011359 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11360 }
11361
Sarah Chinecc78c42022-03-31 21:16:48 -070011362 setDataEnabledForReason(
11363 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011364
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011365 if (isDataThrottlingSupported) {
11366 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011367 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011368 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11369 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11370 } else if (thermalMitigationResult
11371 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011372 log("Modem likely does not support data throttling on secondary carrier. Data " +
11373 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11374 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011375 }
11376 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011377 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011378
11379 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011380 }
11381
Jack Nudelman644b91a2021-03-12 14:09:48 -080011382 private static List<String> getThermalMitigationAllowlist(Context context) {
11383 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11384 for (String pckg : context.getResources()
11385 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11386 sThermalMitigationAllowlistedPackages.add(pckg);
11387 }
11388 }
11389
11390 return sThermalMitigationAllowlistedPackages;
11391 }
11392
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011393 private boolean isAnyPhoneInEmergencyState() {
11394 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11395 if (tm.isInEmergencyCall()) {
11396 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11397 return true;
11398 }
11399 for (Phone phone : PhoneFactory.getPhones()) {
11400 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11401 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011402 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11403 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011404 return true;
11405 }
11406 }
11407
11408 return false;
11409 }
11410
Jack Nudelman644b91a2021-03-12 14:09:48 -080011411 /**
11412 * Used by shell commands to add an authorized package name for thermal mitigation.
11413 * @param packageName name of package to be allowlisted
11414 * @param context
11415 */
11416 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11417 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11418 sThermalMitigationAllowlistedPackages.add(packageName);
11419 }
11420
11421 /**
11422 * Used by shell commands to remove an authorized package name for thermal mitigation.
11423 * @param packageName name of package to remove from allowlist
11424 * @param context
11425 */
11426 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11427 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11428 sThermalMitigationAllowlistedPackages.remove(packageName);
11429 }
11430
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011431 /**
11432 * Thermal mitigation request to control functionalities at modem.
11433 *
11434 * @param subId the id of the subscription.
11435 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011436 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011437 *
11438 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11439 */
11440 @Override
11441 @ThermalMitigationResult
11442 public int sendThermalMitigationRequest(
11443 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011444 ThermalMitigationRequest thermalMitigationRequest,
11445 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011446 enforceModifyPermission();
11447
Jack Nudelman644b91a2021-03-12 14:09:48 -080011448 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000011449
11450 enforceTelephonyFeatureWithException(callingPackage,
11451 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest");
11452
Jack Nudelman644b91a2021-03-12 14:09:48 -080011453 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11454 .contains(callingPackage)) {
11455 throw new SecurityException("Calling package must be configured in the device config. "
11456 + "calling package: " + callingPackage);
11457 }
11458
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011459 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11460 final long identity = Binder.clearCallingIdentity();
11461
11462 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11463 try {
11464 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11465 switch (thermalMitigationAction) {
11466 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11467 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011468 handleDataThrottlingRequest(subId,
11469 thermalMitigationRequest.getDataThrottlingRequest(),
11470 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011471 break;
11472 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11473 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11474 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11475 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11476 }
11477
11478 // Ensure that radio is on. If not able to power on due to phone being
11479 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011480 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011481 thermalMitigationResult =
11482 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11483 break;
11484 }
11485
11486 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011487 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011488 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11489 break;
11490 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11491 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11492 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11493 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11494 }
11495
11496 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11497 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011498 Phone phone = getPhone(subId);
11499 if (phone == null) {
11500 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011501 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011502 break;
11503 }
11504
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011505 TelephonyConnectionService service =
11506 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011507 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011508 Log.e(LOG_TAG, "An emergency call is pending");
11509 thermalMitigationResult =
11510 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11511 break;
11512 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011513 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011514 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011515 break;
11516 }
11517 } else {
11518 thermalMitigationResult =
11519 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11520 break;
11521 }
11522
11523 // Turn radio off. If not able to power off due to phone being unavailable,
11524 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011525 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011526 thermalMitigationResult =
11527 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11528 break;
11529 }
11530 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011531 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011532 break;
11533 default:
11534 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11535 + "not exist. Requested action: " + thermalMitigationAction);
11536 }
11537 } catch (IllegalArgumentException e) {
11538 throw e;
11539 } catch (Exception e) {
11540 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11541 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11542 } finally {
11543 Binder.restoreCallingIdentity(identity);
11544 }
11545
11546 if (DBG) {
11547 log("thermalMitigationRequest returning with thermalMitigationResult: "
11548 + thermalMitigationResult);
11549 }
11550
11551 return thermalMitigationResult;
11552 }
Hui Wang641e81c2020-10-12 12:14:23 -070011553
11554 /**
11555 * Set the GbaService Package Name that Telephony will bind to.
11556 *
11557 * @param subId The sim that the GbaService is associated with.
11558 * @param packageName The name of the package to be replaced with.
11559 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11560 */
11561 @Override
11562 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11563 enforceModifyPermission();
11564
11565 final long identity = Binder.clearCallingIdentity();
11566 try {
11567 return getGbaManager(subId).overrideServicePackage(packageName);
11568 } finally {
11569 Binder.restoreCallingIdentity(identity);
11570 }
11571 }
11572
11573 /**
11574 * Return the package name of the currently bound GbaService.
11575 *
11576 * @param subId The sim that the GbaService is associated with.
11577 * @return the package name of the GbaService configuration, null if GBA is not supported.
11578 */
11579 @Override
11580 public String getBoundGbaService(int subId) {
11581 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11582
11583 final long identity = Binder.clearCallingIdentity();
11584 try {
11585 return getGbaManager(subId).getServicePackage();
11586 } finally {
11587 Binder.restoreCallingIdentity(identity);
11588 }
11589 }
11590
11591 /**
11592 * Set the release time for telephony to unbind GbaService.
11593 *
11594 * @param subId The sim that the GbaService is associated with.
11595 * @param interval The release time to unbind GbaService by millisecond.
11596 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11597 */
11598 @Override
11599 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11600 enforceModifyPermission();
11601
11602 final long identity = Binder.clearCallingIdentity();
11603 try {
11604 return getGbaManager(subId).overrideReleaseTime(interval);
11605 } finally {
11606 Binder.restoreCallingIdentity(identity);
11607 }
11608 }
11609
11610 /**
11611 * Return the release time for telephony to unbind GbaService.
11612 *
11613 * @param subId The sim that the GbaService is associated with.
11614 * @return The release time to unbind GbaService by millisecond.
11615 */
11616 @Override
11617 public int getGbaReleaseTime(int subId) {
11618 enforceReadPrivilegedPermission("getGbaReleaseTime");
11619
11620 final long identity = Binder.clearCallingIdentity();
11621 try {
11622 return getGbaManager(subId).getReleaseTime();
11623 } finally {
11624 Binder.restoreCallingIdentity(identity);
11625 }
11626 }
11627
11628 private GbaManager getGbaManager(int subId) {
11629 GbaManager instance = GbaManager.getInstance(subId);
11630 if (instance == null) {
11631 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11632 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11633 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11634 }
11635 return instance;
11636 }
Hui Wang761a6682020-10-31 05:12:53 +000011637
11638 /**
11639 * indicate whether the device and the carrier can support
11640 * RCS VoLTE single registration.
11641 */
11642 @Override
11643 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011644 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11645 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11646 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11647 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011648
11649 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11650 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11651 }
11652
11653 final long identity = Binder.clearCallingIdentity();
11654 try {
11655 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11656 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011657 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11658 if (isCapable != null) {
11659 return isCapable;
11660 }
Hui Wang761a6682020-10-31 05:12:53 +000011661 }
Hui Wang67af90e2021-06-04 16:57:15 -070011662 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11663 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011664 } finally {
11665 Binder.restoreCallingIdentity(identity);
11666 }
11667 }
11668
11669 /**
11670 * Register RCS provisioning callback.
11671 */
11672 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011673 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011674 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011675 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011676 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011677 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11678 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011679
11680 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11681 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11682 }
joonhunshin4ac60942023-11-15 15:23:39 +000011683 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11684 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11685 Binder.getCallingUserHandle())) {
11686 if (!isImsAvailableOnDevice()) {
11687 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11688 "IMS not available on device.");
11689 }
11690 } else {
11691 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11692 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011693 }
11694
11695 final long identity = Binder.clearCallingIdentity();
11696 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011697 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011698 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011699 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11700 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011701 }
Hui Wang761a6682020-10-31 05:12:53 +000011702 } finally {
11703 Binder.restoreCallingIdentity(identity);
11704 }
11705 }
11706
11707 /**
11708 * Unregister RCS provisioning callback.
11709 */
11710 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011711 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011712 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011713 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011714 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011715 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11716 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011717
11718 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11719 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11720 }
joonhunshin4ac60942023-11-15 15:23:39 +000011721
11722 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11723 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11724 Binder.getCallingUserHandle())) {
11725 if (!isImsAvailableOnDevice()) {
11726 // operation failed silently
11727 Rlog.w(LOG_TAG, "IMS not available on device.");
11728 return;
11729 }
11730 } else {
11731 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11732 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11733 "unregisterRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011734 }
11735
11736 final long identity = Binder.clearCallingIdentity();
11737 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011738 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011739 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011740 } finally {
11741 Binder.restoreCallingIdentity(identity);
11742 }
11743 }
11744
11745 /**
11746 * trigger RCS reconfiguration.
11747 */
11748 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011749 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11750 "triggerRcsReconfiguration",
11751 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011752
11753 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11754 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11755 }
joonhunshin4ac60942023-11-15 15:23:39 +000011756 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11757 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11758 Binder.getCallingUserHandle())) {
11759 if (!isImsAvailableOnDevice()) {
11760 // ProvisioningManager can not handle ServiceSpecificException.
11761 // Throw the IllegalStateException and annotate ProvisioningManager.
11762 throw new IllegalStateException("IMS not available on device.");
11763 }
11764 } else {
11765 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11766 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011767 }
11768
11769 final long identity = Binder.clearCallingIdentity();
11770 try {
11771 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11772 } finally {
11773 Binder.restoreCallingIdentity(identity);
11774 }
11775 }
11776
11777 /**
11778 * Provide the client configuration parameters of the RCS application.
11779 */
11780 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011781 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11782 "setRcsClientConfiguration",
11783 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011784
11785 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11786 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11787 }
joonhunshin4ac60942023-11-15 15:23:39 +000011788 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11789 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11790 Binder.getCallingUserHandle())) {
11791 if (!isImsAvailableOnDevice()) {
11792 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11793 "IMS not available on device.");
11794 }
11795 } else {
11796 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11797 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011798 }
11799
11800 final long identity = Binder.clearCallingIdentity();
11801
11802 try {
11803 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11804 if (configBinder == null) {
11805 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011806 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11807 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011808 } else {
11809 configBinder.setRcsClientConfiguration(rcc);
11810 }
joonhunshin3e154242021-09-17 06:33:39 +000011811
11812 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11813 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011814 } catch (RemoteException e) {
11815 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011816 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11817 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011818 } finally {
11819 Binder.restoreCallingIdentity(identity);
11820 }
11821 }
11822
11823 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011824 * Enables or disables the test mode for RCS VoLTE single registration.
11825 */
11826 @Override
11827 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11828 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11829 "setRcsSingleRegistrationTestModeEnabled");
11830
11831 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11832 }
11833
11834 /**
11835 * Gets the test mode for RCS VoLTE single registration.
11836 */
11837 @Override
11838 public boolean getRcsSingleRegistrationTestModeEnabled() {
11839 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11840 "getRcsSingleRegistrationTestModeEnabled");
11841
11842 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11843 }
11844
11845 /**
Hui Wang761a6682020-10-31 05:12:53 +000011846 * Overrides the config of RCS VoLTE single registration enabled for the device.
11847 */
11848 @Override
11849 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11850 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11851 "setDeviceSingleRegistrationEnabledOverride");
11852 enforceModifyPermission();
11853
11854 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11855 : Boolean.parseBoolean(enabledStr);
11856 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011857 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011858 }
11859
11860 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011861 * Sends a device to device communication message. Only usable via shell.
11862 * @param message message to send.
11863 * @param value message value.
11864 */
11865 @Override
11866 public void sendDeviceToDeviceMessage(int message, int value) {
11867 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011868 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011869 enforceModifyPermission();
11870
11871 final long identity = Binder.clearCallingIdentity();
11872 try {
11873 TelephonyConnectionService service =
11874 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11875 if (service == null) {
11876 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11877 return;
11878 }
11879 service.sendTestDeviceToDeviceMessage(message, value);
11880 } finally {
11881 Binder.restoreCallingIdentity(identity);
11882 }
11883 }
11884
Tyler Gunnbabbda02021-02-10 11:05:02 -080011885 /**
11886 * Sets the specified device to device transport active.
11887 * @param transport The transport to set active.
11888 */
11889 @Override
11890 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11891 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11892 "setActiveDeviceToDeviceTransport");
11893 enforceModifyPermission();
11894
11895 final long identity = Binder.clearCallingIdentity();
11896 try {
11897 TelephonyConnectionService service =
11898 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11899 if (service == null) {
11900 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11901 return;
11902 }
11903 service.setActiveDeviceToDeviceTransport(transport);
11904 } finally {
11905 Binder.restoreCallingIdentity(identity);
11906 }
11907 }
Tyler Gunn92479152021-01-20 16:30:10 -080011908
Tyler Gunnd4339262021-05-03 14:46:49 -070011909 @Override
11910 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11911 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11912 "setDeviceToDeviceForceEnabled");
11913
11914 final long identity = Binder.clearCallingIdentity();
11915 try {
11916 Arrays.stream(PhoneFactory.getPhones()).forEach(
11917 p -> {
11918 Phone thePhone = p.getImsPhone();
11919 if (thePhone != null && thePhone instanceof ImsPhone) {
11920 ImsPhone imsPhone = (ImsPhone) thePhone;
11921 CallTracker tracker = imsPhone.getCallTracker();
11922 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11923 ImsPhoneCallTracker imsPhoneCallTracker =
11924 (ImsPhoneCallTracker) tracker;
11925 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11926 }
11927 }
11928 }
11929 );
11930 } finally {
11931 Binder.restoreCallingIdentity(identity);
11932 }
11933 }
11934
Tyler Gunn92479152021-01-20 16:30:10 -080011935 /**
Hui Wang761a6682020-10-31 05:12:53 +000011936 * Gets the config of RCS VoLTE single registration enabled for the device.
11937 */
11938 @Override
11939 public boolean getDeviceSingleRegistrationEnabled() {
11940 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11941 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11942 }
11943
11944 /**
11945 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11946 */
11947 @Override
11948 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11949 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11950 "setCarrierSingleRegistrationEnabledOverride");
11951 enforceModifyPermission();
11952
11953 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11954 : Boolean.parseBoolean(enabledStr);
11955 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11956 subId, enabled);
11957 }
11958
11959 /**
11960 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11961 */
11962 @Override
11963 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11964 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11965 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11966 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011967
11968 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011969 * Overrides the ims feature validation result
11970 */
11971 @Override
11972 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11973 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11974 "setImsFeatureValidationOverride");
11975
11976 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11977 : Boolean.parseBoolean(enabledStr);
11978 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11979 subId, enabled);
11980 }
11981
11982 /**
11983 * Gets the ims feature validation override value
11984 */
11985 @Override
11986 public boolean getImsFeatureValidationOverride(int subId) {
11987 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11988 "getImsFeatureValidationOverride");
11989 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11990 }
11991
11992 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011993 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11994 * their mobile plan.
11995 */
11996 @Override
11997 public String getMobileProvisioningUrl() {
11998 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
11999 final long identity = Binder.clearCallingIdentity();
12000 try {
12001 return getDefaultPhone().getMobileProvisioningUrl();
12002 } finally {
12003 Binder.restoreCallingIdentity(identity);
12004 }
12005 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012006
James.cf Linbcdf8b32021-01-14 16:44:13 +080012007 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080012008 * Get the EAB contact from the EAB database.
12009 */
12010 @Override
12011 public String getContactFromEab(String contact) {
12012 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
12013 enforceModifyPermission();
12014 final long identity = Binder.clearCallingIdentity();
12015 try {
12016 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
12017 } finally {
12018 Binder.restoreCallingIdentity(identity);
12019 }
12020 }
12021
12022 /**
Calvin Pana1434322021-07-01 19:27:01 +080012023 * Get the EAB capability from the EAB database.
12024 */
12025 @Override
12026 public String getCapabilityFromEab(String contact) {
12027 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
12028 enforceModifyPermission();
12029 final long identity = Binder.clearCallingIdentity();
12030 try {
12031 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
12032 } finally {
12033 Binder.restoreCallingIdentity(identity);
12034 }
12035 }
12036
12037 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080012038 * Remove the EAB contacts from the EAB database.
12039 */
12040 @Override
12041 public int removeContactFromEab(int subId, String contacts) {
12042 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
12043 enforceModifyPermission();
12044 final long identity = Binder.clearCallingIdentity();
12045 try {
12046 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
12047 } finally {
12048 Binder.restoreCallingIdentity(identity);
12049 }
12050 }
12051
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012052 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080012053 public boolean getDeviceUceEnabled() {
12054 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
12055 final long identity = Binder.clearCallingIdentity();
12056 try {
12057 return mApp.getDeviceUceEnabled();
12058 } finally {
12059 Binder.restoreCallingIdentity(identity);
12060 }
12061 }
12062
12063 @Override
12064 public void setDeviceUceEnabled(boolean isEnabled) {
12065 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
12066 final long identity = Binder.clearCallingIdentity();
12067 try {
12068 mApp.setDeviceUceEnabled(isEnabled);
12069 } finally {
12070 Binder.restoreCallingIdentity(identity);
12071 }
12072 }
12073
Brad Ebinger14d467f2021-02-12 06:18:28 +000012074 /**
12075 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
12076 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12077 */
12078 // Used for SHELL command only right now.
12079 @Override
12080 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
12081 List<String> featureTags) {
12082 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12083 "addUceRegistrationOverrideShell");
12084 final long identity = Binder.clearCallingIdentity();
12085 try {
12086 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
12087 new ArraySet<>(featureTags));
12088 } catch (ImsException e) {
12089 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12090 } finally {
12091 Binder.restoreCallingIdentity(identity);
12092 }
12093 }
12094
12095 /**
12096 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
12097 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12098 */
12099 // Used for SHELL command only right now.
12100 @Override
12101 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
12102 List<String> featureTags) {
12103 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12104 "removeUceRegistrationOverrideShell");
12105 final long identity = Binder.clearCallingIdentity();
12106 try {
12107 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
12108 new ArraySet<>(featureTags));
12109 } catch (ImsException e) {
12110 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12111 } finally {
12112 Binder.restoreCallingIdentity(identity);
12113 }
12114 }
12115
12116 /**
12117 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
12118 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12119 */
12120 // Used for SHELL command only right now.
12121 @Override
12122 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
12123 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12124 "clearUceRegistrationOverrideShell");
12125 final long identity = Binder.clearCallingIdentity();
12126 try {
12127 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
12128 } catch (ImsException e) {
12129 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12130 } finally {
12131 Binder.restoreCallingIdentity(identity);
12132 }
12133 }
12134
12135 /**
12136 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12137 */
12138 // Used for SHELL command only right now.
12139 @Override
12140 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
12141 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12142 "getLatestRcsContactUceCapabilityShell");
12143 final long identity = Binder.clearCallingIdentity();
12144 try {
12145 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
12146 } catch (ImsException e) {
12147 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12148 } finally {
12149 Binder.restoreCallingIdentity(identity);
12150 }
12151 }
12152
12153 /**
12154 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
12155 * device does not have an active PUBLISH.
12156 */
12157 // Used for SHELL command only right now.
12158 @Override
12159 public String getLastUcePidfXmlShell(int subId) {
12160 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
12161 final long identity = Binder.clearCallingIdentity();
12162 try {
12163 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
12164 } catch (ImsException e) {
12165 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12166 } finally {
12167 Binder.restoreCallingIdentity(identity);
12168 }
12169 }
12170
James.cf Line8713a42021-04-29 16:04:26 +080012171 /**
12172 * Remove UCE requests cannot be sent to the network status.
12173 */
12174 // Used for SHELL command only right now.
12175 @Override
12176 public boolean removeUceRequestDisallowedStatus(int subId) {
12177 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
12178 final long identity = Binder.clearCallingIdentity();
12179 try {
12180 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
12181 } catch (ImsException e) {
12182 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12183 } finally {
12184 Binder.restoreCallingIdentity(identity);
12185 }
12186 }
12187
James.cf Lin18bb9002021-05-25 01:37:38 +080012188 /**
12189 * Remove UCE requests cannot be sent to the network status.
12190 */
12191 // Used for SHELL command only.
12192 @Override
12193 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
12194 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
12195 final long identity = Binder.clearCallingIdentity();
12196 try {
12197 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
12198 } catch (ImsException e) {
12199 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12200 } finally {
12201 Binder.restoreCallingIdentity(identity);
12202 }
12203 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000012204
James.cf Lin4b784aa2021-01-31 03:25:15 +080012205 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012206 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12207 String callingPackage) {
12208 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12209 mApp, subId, "setSignalStrengthUpdateRequest");
12210
joonhunshin4ac60942023-11-15 15:23:39 +000012211 enforceTelephonyFeatureWithException(callingPackage,
12212 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest");
12213
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012214 final int callingUid = Binder.getCallingUid();
12215 // Verify that tha callingPackage belongs to the calling UID
12216 mApp.getSystemService(AppOpsManager.class)
12217 .checkPackage(callingUid, callingPackage);
12218
Rambo Wang3607f502021-02-01 21:51:40 -080012219 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012220
12221 final long identity = Binder.clearCallingIdentity();
12222 try {
12223 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
12224 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12225
12226 if (result instanceof IllegalStateException) {
12227 throw (IllegalStateException) result;
12228 }
12229 } finally {
12230 Binder.restoreCallingIdentity(identity);
12231 }
12232 }
12233
12234 @Override
12235 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12236 String callingPackage) {
12237 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12238 mApp, subId, "clearSignalStrengthUpdateRequest");
12239
joonhunshin4ac60942023-11-15 15:23:39 +000012240 enforceTelephonyFeatureWithException(callingPackage,
12241 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest");
12242
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012243 final int callingUid = Binder.getCallingUid();
12244 // Verify that tha callingPackage belongs to the calling UID
12245 mApp.getSystemService(AppOpsManager.class)
12246 .checkPackage(callingUid, callingPackage);
12247
12248 final long identity = Binder.clearCallingIdentity();
12249 try {
12250 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
12251 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12252
12253 if (result instanceof IllegalStateException) {
12254 throw (IllegalStateException) result;
12255 }
12256 } finally {
12257 Binder.restoreCallingIdentity(identity);
12258 }
12259 }
12260
Rambo Wang3607f502021-02-01 21:51:40 -080012261 private static void validateSignalStrengthUpdateRequest(Context context,
12262 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012263 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
12264 // phone/system process do not have further restriction on request
12265 return;
12266 }
12267
12268 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080012269 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012270 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080012271 context.enforceCallingOrSelfPermission(
12272 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
12273 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012274 }
12275
12276 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000012277 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012278 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012279 || info.isEnabled()) {
12280 throw new IllegalArgumentException(
12281 "Only system can set hide fields in SignalThresholdInfo");
12282 }
12283
12284 // Thresholds length for each RAN need in range. This has been validated in
12285 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
12286 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
12287 final int[] thresholds = info.getThresholds();
12288 Objects.requireNonNull(thresholds);
12289 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
12290 || thresholds.length
12291 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
12292 throw new IllegalArgumentException(
12293 "thresholds length is out of range: " + thresholds.length);
12294 }
12295 }
12296 }
SongFerngWang8236caa2021-01-17 21:51:44 +080012297
12298 /**
12299 * Gets the current phone capability.
12300 *
12301 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
12302 * @return the PhoneCapability which describes the data connection capability of modem.
12303 * It's used to evaluate possible phone config change, for example from single
12304 * SIM device to multi-SIM device.
12305 */
12306 @Override
12307 public PhoneCapability getPhoneCapability() {
12308 enforceReadPrivilegedPermission("getPhoneCapability");
joonhunshin4ac60942023-11-15 15:23:39 +000012309
12310 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12311 PackageManager.FEATURE_TELEPHONY, "getPhoneCapability");
12312
SongFerngWang8236caa2021-01-17 21:51:44 +080012313 final long identity = Binder.clearCallingIdentity();
12314 try {
12315 return mPhoneConfigurationManager.getCurrentPhoneCapability();
12316 } finally {
12317 Binder.restoreCallingIdentity(identity);
12318 }
12319 }
Michele Berionne5e411512020-11-13 02:36:59 +000012320
12321 /**
12322 * Prepare TelephonyManager for an unattended reboot. The reboot is
12323 * required to be done shortly after the API is invoked.
12324 */
12325 @Override
12326 @TelephonyManager.PrepareUnattendedRebootResult
12327 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012328 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000012329 enforceRebootPermission();
12330
joonhunshin4ac60942023-11-15 15:23:39 +000012331 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12332 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot");
12333
Michele Berionne5e411512020-11-13 02:36:59 +000012334 final long identity = Binder.clearCallingIdentity();
12335 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012336 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000012337 } finally {
12338 Binder.restoreCallingIdentity(identity);
12339 }
12340 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012341
12342 /**
12343 * Request to get the current slicing configuration including URSP rules and
12344 * NSSAIs (configured, allowed and rejected).
12345 *
12346 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
12347 */
12348 @Override
12349 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000012350 TelephonyPermissions
12351 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
12352 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012353
joonhunshin4ac60942023-11-15 15:23:39 +000012354 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12355 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
12356 "getSlicingConfig");
12357
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012358 final long identity = Binder.clearCallingIdentity();
12359 try {
12360 Phone phone = getDefaultPhone();
12361 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
12362 } finally {
12363 Binder.restoreCallingIdentity(identity);
12364 }
12365 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012366
12367 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070012368 * Check whether the given premium capability is available for purchase from the carrier.
12369 *
12370 * @param capability The premium capability to check.
12371 * @param subId The subId to check the premium capability for.
12372 *
12373 * @return Whether the given premium capability is available to purchase.
12374 */
12375 @Override
12376 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
12377 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12378 mApp, "isPremiumCapabilityAvailableForPurchase")) {
12379 log("Premium capability "
12380 + TelephonyManager.convertPremiumCapabilityToString(capability)
12381 + " is not available for purchase due to missing permissions.");
12382 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
12383 + "permission READ_BASIC_PHONE_STATE.");
12384 }
12385
joonhunshin4ac60942023-11-15 15:23:39 +000012386 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12387 PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase");
12388
Sarah Chin2ec39f62022-08-31 17:03:26 -070012389 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080012390 if (phone == null) {
12391 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12392 return false;
12393 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012394 final long identity = Binder.clearCallingIdentity();
12395 try {
Sarah Chincc5446f2023-10-23 17:57:19 -070012396 return SlicePurchaseController.getInstance(phone, mFeatureFlags)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012397 .isPremiumCapabilityAvailableForPurchase(capability);
12398 } finally {
12399 Binder.restoreCallingIdentity(identity);
12400 }
12401 }
12402
12403 /**
12404 * Purchase the given premium capability from the carrier.
12405 *
12406 * @param capability The premium capability to purchase.
12407 * @param callback The result of the purchase request.
12408 * @param subId The subId to purchase the premium capability for.
12409 */
12410 @Override
12411 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12412 log("purchasePremiumCapability: capability="
12413 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12414 + getCurrentPackageName());
12415
12416 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12417 mApp, "purchasePremiumCapability")) {
12418 log("purchasePremiumCapability "
12419 + TelephonyManager.convertPremiumCapabilityToString(capability)
12420 + " failed due to missing permissions.");
12421 throw new SecurityException("purchasePremiumCapability requires permission "
12422 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012423 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12424 mApp, "purchasePremiumCapability")) {
12425 log("purchasePremiumCapability "
12426 + TelephonyManager.convertPremiumCapabilityToString(capability)
12427 + " failed due to missing permissions.");
12428 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012429 }
12430
joonhunshin4ac60942023-11-15 15:23:39 +000012431 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12432 PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability");
12433
Sarah Chin2ec39f62022-08-31 17:03:26 -070012434 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012435 if (phone == null) {
12436 try {
12437 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12438 callback.accept(result);
12439 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12440 } catch (RemoteException e) {
12441 String logStr = "Purchase premium capability "
12442 + TelephonyManager.convertPremiumCapabilityToString(capability)
12443 + " failed due to RemoteException handling null phone: " + e;
12444 if (DBG) log(logStr);
12445 AnomalyReporter.reportAnomaly(
12446 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12447 }
12448 return;
12449 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012450
12451 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012452 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012453 callingProcess = mApp.getPackageManager().getApplicationInfo(
12454 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070012455 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012456 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012457 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012458
12459 boolean isVisible = false;
12460 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12461 if (am != null) {
12462 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12463 if (processes != null) {
12464 for (ActivityManager.RunningAppProcessInfo process : processes) {
12465 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070012466 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080012467 if (process.processName.equals(callingProcess) && process.importance
12468 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12469 isVisible = true;
12470 break;
12471 }
12472 }
12473 }
12474 }
12475
12476 if (!isVisible) {
12477 try {
12478 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12479 callback.accept(result);
12480 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12481 } catch (RemoteException e) {
12482 String logStr = "Purchase premium capability "
12483 + TelephonyManager.convertPremiumCapabilityToString(capability)
12484 + " failed due to RemoteException handling background application: " + e;
12485 if (DBG) log(logStr);
12486 AnomalyReporter.reportAnomaly(
12487 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12488 }
12489 return;
12490 }
12491
Sarah Chin71b3a852022-09-28 15:54:19 -070012492 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012493 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012494 }
12495
12496 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012497 * Register an IMS connection state callback
12498 */
12499 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012500 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12501 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012502 if (feature == ImsFeature.FEATURE_MMTEL) {
12503 // ImsMmTelManager
12504 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12505 TelephonyPermissions
12506 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12507 mApp, subId, "registerImsStateCallback");
12508 } else if (feature == ImsFeature.FEATURE_RCS) {
12509 // ImsRcsManager or SipDelegateManager
12510 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12511 Binder.getCallingUid(), "registerImsStateCallback",
12512 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12513 Manifest.permission.READ_PRECISE_PHONE_STATE,
12514 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12515 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12516 }
12517
12518 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12519 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12520 "IMS not available on device.");
12521 }
12522
12523 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12524 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12525 }
12526
12527 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12528 if (controller == null) {
12529 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12530 "IMS not available on device.");
12531 }
12532
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012533 if (callingPackage == null) {
12534 callingPackage = getCurrentPackageName();
12535 }
12536
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012537 final long token = Binder.clearCallingIdentity();
12538 try {
12539 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012540 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012541 } catch (ImsException e) {
12542 throw new ServiceSpecificException(e.getCode());
12543 } finally {
12544 Binder.restoreCallingIdentity(token);
12545 }
12546 }
12547
12548 /**
12549 * Unregister an IMS connection state callback
12550 */
12551 @Override
12552 public void unregisterImsStateCallback(IImsStateCallback cb) {
12553 final long token = Binder.clearCallingIdentity();
12554 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12555 if (controller == null) {
12556 return;
12557 }
12558 try {
12559 controller.unregisterImsStateCallback(cb);
12560 } finally {
12561 Binder.restoreCallingIdentity(token);
12562 }
12563 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012564
12565 /**
12566 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12567 *
12568 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
12569 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
12570 * SecurityException.
12571 * If there is current registered network this value will be same as the registered cell
12572 * identity. If the device goes out of service the previous cell identity is cached and
12573 * will be returned. If the cache age of the Cell identity is more than 24 hours
12574 * it will be cleared and null will be returned.
12575 *
12576 */
12577 @Override
12578 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12579 String callingFeatureId) {
12580 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12581 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12582 LocationAccessPolicy.checkLocationPermission(mApp,
12583 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12584 .setCallingPackage(callingPackage)
12585 .setCallingFeatureId(callingFeatureId)
12586 .setCallingPid(Binder.getCallingPid())
12587 .setCallingUid(Binder.getCallingUid())
12588 .setMethod("getLastKnownCellIdentity")
12589 .setLogAsInfo(true)
12590 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12591 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12592 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12593 .build());
12594
12595 boolean hasFinePermission =
12596 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12597 if (!hasFinePermission
12598 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12599 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012600 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012601 }
12602
12603 final long identity = Binder.clearCallingIdentity();
12604 try {
Ling Mac28f0212023-03-24 16:07:15 -070012605 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012606 if (sst == null) return null;
12607 return sst.getLastKnownCellIdentity();
12608 } finally {
12609 Binder.restoreCallingIdentity(identity);
12610 }
12611 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012612
jimsun3b9ccac2021-10-26 15:01:23 +080012613 /**
12614 * Sets the modem service class Name that Telephony will bind to.
12615 *
12616 * @param serviceName The class name of the modem service.
12617 * @return true if the operation is succeed, otherwise false.
12618 */
12619 public boolean setModemService(String serviceName) {
12620 Log.d(LOG_TAG, "setModemService - " + serviceName);
12621 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12622 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012623 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12624 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012625 return mPhoneConfigurationManager.setModemService(serviceName);
12626 }
12627
12628 /**
12629 * Return the class name of the currently bounded modem service.
12630 *
12631 * @return the class name of the modem service.
12632 */
12633 public String getModemService() {
12634 String result;
12635 Log.d(LOG_TAG, "getModemService");
12636 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12637 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012638 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012639 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12640 "getModemService");
12641 result = mPhoneConfigurationManager.getModemService();
12642 Log.d(LOG_TAG, "result = " + result);
12643 return result;
12644 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012645
12646 @Override
12647 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12648 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12649 mApp.enforceCallingOrSelfPermission(
12650 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12651 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12652
12653 final long identity = Binder.clearCallingIdentity();
12654 try {
12655 Phone phone = getPhone(subId);
12656 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012657 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12658 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012659 phone.setVoiceServiceStateOverride(hasService);
12660 } finally {
12661 Binder.restoreCallingIdentity(identity);
12662 }
12663 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012664
12665 /**
12666 * set removable eSIM as default eUICC.
12667 *
12668 * @hide
12669 */
12670 @Override
12671 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12672 enforceModifyPermission();
12673 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12674
12675 final long identity = Binder.clearCallingIdentity();
12676 try {
12677 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12678 } finally {
12679 Binder.restoreCallingIdentity(identity);
12680 }
12681 }
12682
12683 /**
12684 * Returns whether the removable eSIM is default eUICC or not.
12685 *
12686 * @hide
12687 */
12688 @Override
12689 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12690 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12691 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12692
12693 final long identity = Binder.clearCallingIdentity();
12694 try {
12695 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12696 } finally {
12697 Binder.restoreCallingIdentity(identity);
12698 }
12699 }
12700
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012701 /**
12702 * Get the component name of the default app to direct respond-via-message intent for the
12703 * user associated with this subscription, update the cache if there is no respond-via-message
12704 * application currently configured for this user.
12705 * @return component name of the app and class to direct Respond Via Message intent to, or
12706 * {@code null} if the functionality is not supported.
12707 * @hide
12708 */
12709 @Override
12710 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12711 boolean updateIfNeeded) {
12712 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012713
joonhunshin4ac60942023-11-15 15:23:39 +000012714 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12715 PackageManager.FEATURE_TELEPHONY_MESSAGING,
12716 "getDefaultRespondViaMessageApplication");
12717
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012718 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12719
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012720 UserHandle userHandle = null;
12721 final long identity = Binder.clearCallingIdentity();
12722 try {
12723 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12724 } finally {
12725 Binder.restoreCallingIdentity(identity);
12726 }
12727 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12728 updateIfNeeded, userHandle);
12729 }
Jack Yuf5badd92022-12-08 00:50:53 -080012730
12731 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012732 * Set whether the device is able to connect with null ciphering or integrity
12733 * algorithms. This is a global setting and will apply to all active subscriptions
12734 * and all new subscriptions after this.
12735 *
12736 * @param enabled when true, null cipher and integrity algorithms are allowed.
12737 * @hide
12738 */
12739 @Override
12740 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12741 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12742 enforceModifyPermission();
12743 checkForNullCipherAndIntegritySupport();
12744
12745 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12746 // for listening to these preference changes and applying them immediately.
12747 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12748 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12749 editor.apply();
12750
12751 for (Phone phone: PhoneFactory.getPhones()) {
12752 phone.handleNullCipherEnabledChange();
12753 }
12754 }
12755
12756
12757 /**
12758 * Get whether the device is able to connect with null ciphering or integrity
12759 * algorithms. Note that this retrieves the phone-global preference and not
12760 * the state of the radio.
12761 *
12762 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12763 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12764 * version for this feature.
12765 * @hide
12766 */
12767 @Override
12768 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12769 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12770 enforceReadPermission();
12771 checkForNullCipherAndIntegritySupport();
12772 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12773 }
12774
12775 private void checkForNullCipherAndIntegritySupport() {
12776 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12777 throw new UnsupportedOperationException(
12778 "Null cipher and integrity operations require HAL 2.1 or above");
12779 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012780 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12781 throw new UnsupportedOperationException(
12782 "Null cipher and integrity operations unsupported by modem");
12783 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012784 }
12785
Gil Cukierman06403e12023-11-29 16:33:03 +000012786 private void checkForIdentifierDisclosureNotificationSupport() {
12787 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) {
12788 throw new UnsupportedOperationException(
12789 "Cellular identifier disclosure transparency operations require HAL 2.2 or "
12790 + "above");
12791 }
12792 if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) {
12793 throw new UnsupportedOperationException(
12794 "Cellular identifier disclosure transparency operations unsupported by modem");
12795 }
12796 }
12797
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012798 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012799 * Get the SIM state for the slot index.
12800 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12801 *
12802 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12803 */
12804 @Override
12805 @SimState
12806 public int getSimStateForSlotIndex(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +000012807 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12808 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex");
12809
Jack Yuf5badd92022-12-08 00:50:53 -080012810 IccCardConstants.State simState;
12811 if (slotIndex < 0) {
12812 simState = IccCardConstants.State.UNKNOWN;
12813 } else {
12814 Phone phone = null;
12815 try {
12816 phone = PhoneFactory.getPhone(slotIndex);
12817 } catch (IllegalStateException e) {
12818 // ignore
12819 }
12820 if (phone == null) {
12821 simState = IccCardConstants.State.UNKNOWN;
12822 } else {
12823 IccCard icc = phone.getIccCard();
12824 if (icc == null) {
12825 simState = IccCardConstants.State.UNKNOWN;
12826 } else {
12827 simState = icc.getState();
12828 }
12829 }
12830 }
12831 return simState.ordinal();
12832 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012833
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012834 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
12835 boolean enableLogcat,
12836 long logcatStartTimestampMillis, boolean enableTelecomDump,
12837 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012838 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
12839 TelephonyManager.EmergencyCallDiagnosticParams edp =
12840 new TelephonyManager.EmergencyCallDiagnosticParams();
12841 edp.setLogcatCollection(enableLogcat, logcatStartTimestampMillis);
12842 edp.setTelephonyDumpSysCollection(enableTelephonyDump);
12843 edp.setTelecomDumpSysCollection(enableTelecomDump);
12844 Log.d(LOG_TAG, "persisting with Params " + edp.toString());
12845 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
12846 Executors.newCachedThreadPool(), db,
12847 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
12848 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), edp, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012849 }
12850
12851 /**
12852 * Request telephony to persist state for debugging emergency call failures.
12853 *
12854 * @param dropBoxTag Tag to use when persisting data to dropbox service.
12855 * @param enableLogcat whether to collect logcat output
12856 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
12857 * @param enableTelecomDump whether to collect telecom dumpsys
12858 * @param enableTelephonyDump whether to collect telephony dumpsys
12859 */
12860 @Override
12861 @RequiresPermission(android.Manifest.permission.DUMP)
12862 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
12863 long logcatStartTimestampMillis, boolean enableTelecomDump,
12864 boolean enableTelephonyDump) {
12865 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
12866 "persistEmergencyCallDiagnosticData");
12867 final long identity = Binder.clearCallingIdentity();
12868 try {
12869 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
12870 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
12871
12872 } finally {
12873 Binder.restoreCallingIdentity(identity);
12874 }
12875 }
12876
Hui Wang9b5793a2022-12-05 14:38:06 -060012877 /**
12878 * Get current cell broadcast ranges.
12879 */
12880 @Override
12881 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12882 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12883 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12884 "getCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012885
12886 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12887 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges");
12888
Hui Wang9b5793a2022-12-05 14:38:06 -060012889 final long identity = Binder.clearCallingIdentity();
12890 try {
12891 return getPhone(subId).getCellBroadcastIdRanges();
12892 } finally {
12893 Binder.restoreCallingIdentity(identity);
12894 }
12895 }
12896
12897 /**
12898 * Set reception of cell broadcast messages with the list of the given ranges
12899 *
12900 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12901 */
12902 @Override
12903 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12904 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12905 @Nullable IIntegerConsumer callback) {
12906 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12907 "setCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012908
12909 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12910 PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges");
12911
Hui Wang9b5793a2022-12-05 14:38:06 -060012912 final long identity = Binder.clearCallingIdentity();
12913 try {
12914 Phone phone = getPhoneFromSubId(subId);
12915 if (DBG) {
12916 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12917 }
12918 phone.setCellBroadcastIdRanges(ranges, result -> {
12919 if (callback != null) {
12920 try {
12921 callback.accept(result);
12922 } catch (RemoteException e) {
12923 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12924 }
12925 }
12926 });
12927 } finally {
12928 Binder.restoreCallingIdentity(identity);
12929 }
12930 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012931
12932 /**
12933 * Returns whether the device supports the domain selection service.
12934 *
12935 * @return {@code true} if the device supports the domain selection service.
12936 */
12937 @Override
12938 public boolean isDomainSelectionSupported() {
12939 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12940 "isDomainSelectionSupported");
12941
12942 final long identity = Binder.clearCallingIdentity();
12943 try {
12944 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12945 } finally {
12946 Binder.restoreCallingIdentity(identity);
12947 }
12948 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012949
12950 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012951 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
12952 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
12953 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080012954 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012955 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chinabf081b2023-03-09 23:00:57 -080012956 * @param enableSatellite {@code true} to enable the satellite modem and
12957 * {@code false} to disable.
12958 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
12959 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080012960 *
12961 * @throws SecurityException if the caller doesn't have the required permission.
12962 */
12963 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012964 public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode,
12965 @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012966 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080012967 ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) {
12968 @Override
12969 protected void onReceiveResult(int resultCode, Bundle resultData) {
12970 Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode
12971 + ", resultData=" + resultData);
12972 boolean isAllowed = false;
12973 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept);
12974 if (resultCode == SATELLITE_RESULT_SUCCESS) {
12975 if (resultData != null
12976 && resultData.containsKey(KEY_SATELLITE_COMMUNICATION_ALLOWED)) {
12977 isAllowed = resultData.getBoolean(KEY_SATELLITE_COMMUNICATION_ALLOWED);
12978 } else {
12979 loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist.");
12980 }
12981 } else {
12982 result.accept(resultCode);
12983 return;
12984 }
12985 if (isAllowed) {
12986 mSatelliteController.requestSatelliteEnabled(
12987 subId, enableSatellite, enableDemoMode, callback);
12988 } else {
12989 result.accept(SATELLITE_RESULT_ACCESS_BARRED);
12990 }
12991 }
12992 };
12993 mSatelliteAccessController.requestIsSatelliteCommunicationAllowedForCurrentLocation(
12994 subId, resultReceiver);
Sarah Chin503828c2023-02-01 23:54:20 -080012995 }
12996
12997 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012998 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080012999 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013000 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013001 * @param result The result receiver that returns whether the satellite modem is enabled
13002 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013003 *
13004 * @throws SecurityException if the caller doesn't have the required permission.
13005 */
13006 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013007 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
13008 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013009 mSatelliteController.requestIsSatelliteEnabled(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013010 }
13011
13012 /**
Sarah Chin43457982023-02-15 17:50:38 -080013013 * Request to get whether the satellite service demo mode is enabled.
13014 *
13015 * @param subId The subId of the subscription to check whether the satellite demo mode
13016 * is enabled for.
13017 * @param result The result receiver that returns whether the satellite demo mode is enabled
13018 * if the request is successful or an error code if the request failed.
13019 *
13020 * @throws SecurityException if the caller doesn't have the required permission.
13021 */
13022 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013023 public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
13024 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
13025 mSatelliteController.requestIsDemoModeEnabled(subId, result);
Sarah Chin43457982023-02-15 17:50:38 -080013026 }
13027
13028 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013029 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080013030 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013031 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013032 * @param result The result receiver that returns whether the satellite service is supported on
13033 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013034 */
13035 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013036 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013037 mSatelliteController.requestIsSatelliteSupported(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013038 }
13039
13040 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013041 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080013042 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013043 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013044 * @param result The result receiver that returns the {@link SatelliteCapabilities}
13045 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013046 *
13047 * @throws SecurityException if the caller doesn't have required permission.
13048 */
13049 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013050 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
13051 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013052 mSatelliteController.requestSatelliteCapabilities(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013053 }
13054
13055 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013056 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013057 * This can be called by the pointing UI when the user starts pointing to the satellite.
13058 * Modem should continue to report the pointing input as the device or satellite moves.
13059 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013060 * @param subId The subId of the subscription to start satellite transmission updates for.
13061 * @param resultCallback The callback to get the result of the request.
13062 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080013063 *
13064 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013065 */
13066 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013067 public void startSatelliteTransmissionUpdates(int subId,
13068 @NonNull IIntegerConsumer resultCallback,
13069 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13070 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
13071 mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080013072 }
13073
13074 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013075 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013076 * This can be called by the pointing UI when the user stops pointing to the satellite.
13077 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013078 * @param subId The subId of the subscription to stop satellite transmission updates for.
13079 * @param resultCallback The callback to get the result of the request.
13080 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
13081 * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080013082 *
13083 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013084 */
13085 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013086 public void stopSatelliteTransmissionUpdates(int subId,
13087 @NonNull IIntegerConsumer resultCallback,
13088 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13089 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
13090 mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013091 }
13092
13093 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013094 * Register the subscription with a satellite provider.
13095 * This is needed to register the subscription if the provider allows dynamic registration.
13096 *
13097 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013098 * @param token The token to be used as a unique identifier for provisioning with satellite
13099 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013100 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080013101 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013102 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013103 * @return The signal transport used by the caller to cancel the provision request,
13104 * or {@code null} if the request failed.
13105 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013106 * @throws SecurityException if the caller doesn't have the required permission.
13107 */
13108 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013109 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013110 @NonNull String token, @NonNull byte[] provisionData,
13111 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013112 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013113 return mSatelliteController.provisionSatelliteService(subId, token, provisionData,
13114 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013115 }
13116
13117 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013118 * Unregister the device/subscription with the satellite provider.
13119 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013120 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013121 * should report as deprovisioned.
13122 *
13123 * @param subId The subId of the subscription to be deprovisioned.
13124 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080013125 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013126 *
13127 * @throws SecurityException if the caller doesn't have the required permission.
13128 */
13129 @Override
13130 public void deprovisionSatelliteService(int subId,
13131 @NonNull String token, @NonNull IIntegerConsumer callback) {
13132 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013133 mSatelliteController.deprovisionSatelliteService(subId, token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013134 }
13135
13136 /**
Sarah Chin43457982023-02-15 17:50:38 -080013137 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013138 *
Sarah Chin43457982023-02-15 17:50:38 -080013139 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013140 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013141 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013142 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013143 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013144 * @throws SecurityException if the caller doesn't have the required permission.
13145 */
13146 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013147 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
13148 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013149 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013150 return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013151 }
13152
13153 /**
Sarah Chin43457982023-02-15 17:50:38 -080013154 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013155 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013156 *
Sarah Chin43457982023-02-15 17:50:38 -080013157 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013158 * @param callback The callback that was passed to
13159 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013160 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013161 * @throws SecurityException if the caller doesn't have the required permission.
13162 */
13163 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013164 public void unregisterForSatelliteProvisionStateChanged(
13165 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013166 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013167 mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013168 }
13169
13170 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013171 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013172 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013173 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013174 * @param result The result receiver that returns whether the device is provisioned with a
13175 * satellite provider if the request is successful or an error code if the
13176 * request failed.
13177 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013178 * @throws SecurityException if the caller doesn't have the required permission.
13179 */
13180 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013181 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
13182 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013183 mSatelliteController.requestIsSatelliteProvisioned(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013184 }
13185
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013186 /**
Sarah Chin43457982023-02-15 17:50:38 -080013187 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013188 *
Sarah Chin43457982023-02-15 17:50:38 -080013189 * @param subId The subId of the subscription to register for satellite modem state changed.
13190 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080013191 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013192 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013193 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013194 * @throws SecurityException if the caller doesn't have the required permission.
13195 */
13196 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013197 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013198 @NonNull ISatelliteStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080013199 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013200 return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013201 }
13202
13203 /**
Sarah Chin43457982023-02-15 17:50:38 -080013204 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013205 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013206 *
Sarah Chin43457982023-02-15 17:50:38 -080013207 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080013208 * @param callback The callback that was passed to
Sarah Chin43457982023-02-15 17:50:38 -080013209 * {@link #registerForSatelliteModemStateChanged(int, ISatelliteStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013210 *
13211 * @throws SecurityException if the caller doesn't have the required permission.
13212 */
13213 @Override
Sarah Chin43457982023-02-15 17:50:38 -080013214 public void unregisterForSatelliteModemStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013215 @NonNull ISatelliteStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080013216 enforceSatelliteCommunicationPermission("unregisterForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013217 mSatelliteController.unregisterForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013218 }
13219
13220 /**
13221 * Register to receive incoming datagrams over satellite.
13222 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013223 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Sarah Chindf715ec2023-02-13 13:46:24 -080013224 * @param callback The callback to handle incoming datagrams over satellite.
13225 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013226 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013227 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013228 * @throws SecurityException if the caller doesn't have the required permission.
13229 */
13230 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013231 @SatelliteManager.SatelliteResult public int registerForSatelliteDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013232 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013233 enforceSatelliteCommunicationPermission("registerForSatelliteDatagram");
Sarah Chinabf081b2023-03-09 23:00:57 -080013234 return mSatelliteController.registerForSatelliteDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013235 }
13236
13237 /**
13238 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013239 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013240 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013241 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
13242 * @param callback The callback that was passed to
Sarah Chinabf081b2023-03-09 23:00:57 -080013243 * {@link #registerForSatelliteDatagram(int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013244 *
13245 * @throws SecurityException if the caller doesn't have the required permission.
13246 */
13247 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013248 public void unregisterForSatelliteDatagram(int subId,
13249 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013250 enforceSatelliteCommunicationPermission("unregisterForSatelliteDatagram");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013251 mSatelliteController.unregisterForSatelliteDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013252 }
13253
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013254 /**
13255 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013256 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013257 * This method requests modem to check if there are any pending datagrams to be received over
13258 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000013259 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080013260 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013261 * @param subId The subId of the subscription used for receiving datagrams.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013262 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013263 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013264 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013265 */
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013266 @Override
13267 public void pollPendingSatelliteDatagrams(int subId, IIntegerConsumer callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013268 enforceSatelliteCommunicationPermission("pollPendingSatelliteDatagrams");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013269 mSatelliteController.pollPendingSatelliteDatagrams(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013270 }
13271
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013272 /**
13273 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013274 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013275 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
13276 * input to this method. Datagram received here will be passed down to modem without any
13277 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080013278 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013279 * @param subId The subId of the subscription to send satellite datagrams for.
13280 * @param datagramType datagram type indicating whether the datagram is of type
13281 * SOS_SMS or LOCATION_SHARING.
13282 * @param datagram encoded gateway datagram which is encrypted by the caller.
13283 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000013284 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
13285 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013286 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013287 *
13288 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013289 */
13290 @Override
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000013291 public void sendSatelliteDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
13292 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
13293 @NonNull IIntegerConsumer callback) {
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013294 enforceSatelliteCommunicationPermission("sendSatelliteDatagram");
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000013295 mSatelliteController.sendSatelliteDatagram(subId, datagramType, datagram,
13296 needFullScreenPointingUI, callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013297 }
13298
Sarah Chindf715ec2023-02-13 13:46:24 -080013299 /**
13300 * Request to get whether satellite communication is allowed for the current location.
13301 *
13302 * @param subId The subId of the subscription to check whether satellite communication is
13303 * allowed for the current location for.
13304 * @param result The result receiver that returns whether satellite communication is allowed
13305 * for the current location if the request is successful or an error code
13306 * if the request failed.
13307 *
13308 * @throws SecurityException if the caller doesn't have the required permission.
13309 */
13310 @Override
13311 public void requestIsSatelliteCommunicationAllowedForCurrentLocation(int subId,
13312 @NonNull ResultReceiver result) {
13313 enforceSatelliteCommunicationPermission(
13314 "requestIsSatelliteCommunicationAllowedForCurrentLocation");
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013315 mSatelliteAccessController.requestIsSatelliteCommunicationAllowedForCurrentLocation(
13316 subId, result);
Sarah Chindf715ec2023-02-13 13:46:24 -080013317 }
13318
13319 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013320 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080013321 *
Sarah Chin5f57c582023-02-14 04:16:10 -080013322 * @param subId The subId to get the time after which the satellite will be visible for.
13323 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080013324 * be visible if the request is successful or an error code if the request failed.
13325 *
13326 * @throws SecurityException if the caller doesn't have the required permission.
13327 */
13328 @Override
13329 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
13330 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013331 mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013332 }
13333
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013334 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013335 * Inform that Device is aligned to satellite for demo mode.
13336 *
13337 * @param subId The subId to get the time after which the satellite will be visible for.
13338 * @param isAligned {@code true} Device is aligned with the satellite for demo mode
13339 * {@code false} Device fails to align with the satellite for demo mode.
13340 *
13341 * @throws SecurityException if the caller doesn't have required permission.
13342 */
13343 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
13344
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013345 public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) {
Hakjun Choiae365972023-04-25 11:00:31 +000013346 enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite");
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013347 mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned);
Hakjun Choiae365972023-04-25 11:00:31 +000013348 }
13349
13350 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000013351 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
13352 * by modem.
13353 *
13354 * @param subId The subId of the subscription to request for.
13355 * @param reason Reason for disallowing satellite communication for carrier.
13356 * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the
13357 * operation.
13358 *
13359 * @throws SecurityException if the caller doesn't have required permission.
13360 */
13361 public void addSatelliteAttachRestrictionForCarrier(int subId,
13362 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13363 @NonNull IIntegerConsumer callback) {
13364 enforceSatelliteCommunicationPermission("addSatelliteAttachRestrictionForCarrier");
13365 final long identity = Binder.clearCallingIdentity();
13366 try {
13367 mSatelliteController.addSatelliteAttachRestrictionForCarrier(subId, reason, callback);
13368 } finally {
13369 Binder.restoreCallingIdentity(identity);
13370 }
13371 }
13372
13373 /**
13374 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
13375 * by modem.
13376 *
13377 * @param subId The subId of the subscription to request for.
13378 * @param reason Reason for disallowing satellite communication.
13379 * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the
13380 * operation.
13381 *
13382 * @throws SecurityException if the caller doesn't have required permission.
13383 */
13384 public void removeSatelliteAttachRestrictionForCarrier(int subId,
13385 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13386 @NonNull IIntegerConsumer callback) {
13387 enforceSatelliteCommunicationPermission("removeSatelliteAttachRestrictionForCarrier");
13388 final long identity = Binder.clearCallingIdentity();
13389 try {
13390 mSatelliteController.removeSatelliteAttachRestrictionForCarrier(subId, reason,
13391 callback);
13392 } finally {
13393 Binder.restoreCallingIdentity(identity);
13394 }
13395 }
13396
13397 /**
13398 * Get reasons for disallowing satellite communication, as requested by
13399 * {@link #addSatelliteAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
13400 *
13401 * @param subId The subId of the subscription to request for.
13402 *
13403 * @return Integer array of reasons for disallowing satellite communication.
13404 *
13405 * @throws SecurityException if the caller doesn't have the required permission.
13406 */
13407 public @NonNull int[] getSatelliteAttachRestrictionReasonsForCarrier(
13408 int subId) {
13409 enforceSatelliteCommunicationPermission("getSatelliteAttachRestrictionReasonsForCarrier");
13410 final long identity = Binder.clearCallingIdentity();
13411 try {
13412 Set<Integer> reasonSet =
13413 mSatelliteController.getSatelliteAttachRestrictionReasonsForCarrier(subId);
13414 return reasonSet.stream().mapToInt(i->i).toArray();
13415 } finally {
13416 Binder.restoreCallingIdentity(identity);
13417 }
13418 }
13419
13420 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000013421 * Request to get the signal strength of the satellite connection.
13422 *
13423 * @param subId The subId of the subscription to request for.
13424 * @param result Result receiver to get the error code of the request and the current signal
13425 * strength of the satellite connection.
13426 *
13427 * @throws SecurityException if the caller doesn't have required permission.
13428 */
13429 @Override
13430 public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) {
13431 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
13432 final long identity = Binder.clearCallingIdentity();
13433 try {
13434 mSatelliteController.requestNtnSignalStrength(subId, result);
13435 } finally {
13436 Binder.restoreCallingIdentity(identity);
13437 }
13438 }
13439
13440 /**
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013441 * Registers for NTN signal strength changed from satellite modem. If the registration operation
13442 * is not successful, a {@link ServiceSpecificException} that contains
13443 * {@link SatelliteManager.SatelliteResult} will be thrown.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013444 *
13445 * @param subId The subId of the subscription to request for.
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013446 * @param callback The callback to handle the NTN signal strength changed event. If the
13447 * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged(
13448 * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of
13449 * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial
13450 * network has changed.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013451 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013452 * @throws SecurityException If the caller doesn't have the required permission.
13453 * @throws ServiceSpecificException If the callback registration operation fails.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013454 */
13455 @Override
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013456 public void registerForNtnSignalStrengthChanged(int subId,
13457 @NonNull INtnSignalStrengthCallback callback) throws RemoteException {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013458 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
13459 final long identity = Binder.clearCallingIdentity();
13460 try {
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013461 mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013462 } finally {
13463 Binder.restoreCallingIdentity(identity);
13464 }
13465 }
13466
13467 /**
13468 * Unregisters for NTN signal strength changed from satellite modem.
13469 * If callback was not registered before, the request will be ignored.
13470 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013471 * @param subId The subId of the subscription to unregister for listening NTN signal strength
13472 * changed event.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013473 * @param callback The callback that was passed to
13474 * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)}
13475 *
13476 * @throws SecurityException if the caller doesn't have the required permission.
13477 */
13478 @Override
13479 public void unregisterForNtnSignalStrengthChanged(
13480 int subId, @NonNull INtnSignalStrengthCallback callback) {
13481 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
13482 final long identity = Binder.clearCallingIdentity();
13483 try {
13484 mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback);
13485 } finally {
13486 Binder.restoreCallingIdentity(identity);
13487 }
13488 }
13489
13490 /**
Hakjun Choi8d96a562023-10-26 15:01:40 +000013491 * Registers for satellite capabilities change event from the satellite service.
13492 *
13493 * @param subId The subId of the subscription to request for.
13494 * @param callback The callback to handle the satellite capabilities changed event.
13495 *
13496 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13497 *
13498 * @throws SecurityException if the caller doesn't have required permission.
13499 */
13500 @Override
13501 @SatelliteManager.SatelliteResult public int registerForSatelliteCapabilitiesChanged(
13502 int subId, @NonNull ISatelliteCapabilitiesCallback callback) {
13503 enforceSatelliteCommunicationPermission("registerForSatelliteCapabilitiesChanged");
13504 final long identity = Binder.clearCallingIdentity();
13505 try {
13506 return mSatelliteController.registerForSatelliteCapabilitiesChanged(subId, callback);
13507 } finally {
13508 Binder.restoreCallingIdentity(identity);
13509 }
13510 }
13511
13512 /**
13513 * Unregisters for satellite capabilities change event from the satellite service.
13514 * If callback was not registered before, the request will be ignored.
13515 *
13516 * @param subId The subId of the subscription to unregister for satellite capabilities change.
13517 * @param callback The callback that was passed to.
13518 * {@link #registerForSatelliteCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}.
13519 *
13520 * @throws SecurityException if the caller doesn't have required permission.
13521 */
13522 @Override
13523 public void unregisterForSatelliteCapabilitiesChanged(
13524 int subId, @NonNull ISatelliteCapabilitiesCallback callback) {
13525 enforceSatelliteCommunicationPermission("unregisterForSatelliteCapabilitiesChanged");
13526 final long identity = Binder.clearCallingIdentity();
13527 try {
13528 mSatelliteController.unregisterForSatelliteCapabilitiesChanged(subId, callback);
13529 } finally {
13530 Binder.restoreCallingIdentity(identity);
13531 }
13532 }
13533
13534 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013535 * This API can be used by only CTS to update satellite vendor service package name.
13536 *
13537 * @param servicePackageName The package name of the satellite vendor service.
13538 * @return {@code true} if the satellite vendor service is set successfully,
13539 * {@code false} otherwise.
13540 */
13541 public boolean setSatelliteServicePackageName(String servicePackageName) {
13542 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName);
13543 TelephonyPermissions.enforceShellOnly(
13544 Binder.getCallingUid(), "setSatelliteServicePackageName");
13545 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13546 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13547 "setSatelliteServicePackageName");
13548 return mSatelliteController.setSatelliteServicePackageName(servicePackageName);
13549 }
13550
13551 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070013552 * This API can be used by only CTS to update satellite gateway service package name.
13553 *
13554 * @param servicePackageName The package name of the satellite gateway service.
13555 * @return {@code true} if the satellite gateway service is set successfully,
13556 * {@code false} otherwise.
13557 */
13558 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
13559 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
13560 TelephonyPermissions.enforceShellOnly(
13561 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
13562 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13563 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13564 "setSatelliteGatewayServicePackageName");
13565 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
13566 }
13567
13568 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070013569 * This API can be used by only CTS to update satellite pointing UI app package and class names.
13570 *
13571 * @param packageName The package name of the satellite pointing UI app.
13572 * @param className The class name of the satellite pointing UI app.
13573 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
13574 * {@code false} otherwise.
13575 */
13576 public boolean setSatellitePointingUiClassName(
13577 @Nullable String packageName, @Nullable String className) {
13578 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
13579 + ", className=" + className);
13580 TelephonyPermissions.enforceShellOnly(
13581 Binder.getCallingUid(), "setSatellitePointingUiClassName");
13582 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13583 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13584 "setSatelliteGatewayServicePackageName");
13585 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
13586 }
13587
13588 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070013589 * This API can be used by only CTS to update the timeout duration in milliseconds that
13590 * satellite should stay at listening mode to wait for the next incoming page before disabling
13591 * listening mode.
13592 *
13593 * @param timeoutMillis The timeout duration in millisecond.
13594 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13595 */
13596 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
13597 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
13598 TelephonyPermissions.enforceShellOnly(
13599 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
13600 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13601 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13602 "setSatelliteListeningTimeoutDuration");
13603 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
13604 }
13605
13606 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013607 * This API can be used by only CTS to update the timeout duration in milliseconds whether
13608 * the device is aligned with the satellite for demo mode
13609 *
13610 * @param timeoutMillis The timeout duration in millisecond.
13611 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13612 */
13613 public boolean setSatelliteDeviceAlignedTimeoutDuration(long timeoutMillis) {
13614 Log.d(LOG_TAG, "setDeviceAlignedTimeoutDuration - " + timeoutMillis);
13615 TelephonyPermissions.enforceShellOnly(
13616 Binder.getCallingUid(), "setDeviceAlignedTimeoutDuration");
13617 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13618 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13619 "setDeviceAlignedTimeoutDuration");
13620 return mSatelliteController.setSatelliteDeviceAlignedTimeoutDuration(timeoutMillis);
13621 }
13622
13623 /**
Thomas Nguyen11a051f2023-10-25 10:14:55 -070013624 * This API can be used in only testing to override connectivity status in monitoring emergency
13625 * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.
13626 *
13627 * @param handoverType The type of handover from emergency call to satellite messaging. Use one
13628 * of the following values to enable the override:
13629 * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS
13630 * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911
13631 * To disable the override, use -1 for handoverType.
13632 * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer
13633 * delaySeconds after the emergency call starts.
13634 * @return {@code true} if the handover type is set successfully, {@code false} otherwise.
13635 */
13636 public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) {
13637 Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType);
13638 TelephonyPermissions.enforceShellOnly(
13639 Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType");
13640 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13641 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13642 "setEmergencyCallToSatelliteHandoverType");
13643 return mSatelliteController.setEmergencyCallToSatelliteHandoverType(
13644 handoverType, delaySeconds);
13645 }
13646
13647 /**
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013648 * This API should be used by only CTS tests to forcefully set telephony country codes.
13649 *
13650 * @return {@code true} if the country code is set successfully, {@code false} otherwise.
13651 */
13652 public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes,
13653 Map cachedNetworkCountryCodes, String locationCountryCode,
13654 long locationCountryCodeTimestampNanos) {
13655 Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes="
13656 + String.join(", ", currentNetworkCountryCodes)
13657 + ", locationCountryCode=" + locationCountryCode
13658 + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos
13659 + ", reset=" + reset + ", cachedNetworkCountryCodes="
13660 + String.join(", ", cachedNetworkCountryCodes.keySet()));
13661 TelephonyPermissions.enforceShellOnly(
13662 Binder.getCallingUid(), "setCachedLocationCountryCode");
13663 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13664 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13665 "setCachedLocationCountryCode");
13666 return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext()).setCountryCodes(
13667 reset, currentNetworkCountryCodes, cachedNetworkCountryCodes, locationCountryCode,
13668 locationCountryCodeTimestampNanos);
13669 }
13670
13671 /**
13672 * This API should be used by only CTS tests to override the overlay configs of satellite
13673 * access controller.
13674 *
13675 * @param reset {@code true} mean the overridden configs should not be used, {@code false}
13676 * otherwise.
13677 * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise.
13678 */
13679 public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed,
13680 String s2CellFile, long locationFreshDurationNanos,
13681 List<String> satelliteCountryCodes) {
13682 Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset
13683 + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile
13684 + ", locationFreshDurationNanos=" + locationFreshDurationNanos
13685 + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null)
13686 ? String.join(", ", satelliteCountryCodes) : null));
13687 TelephonyPermissions.enforceShellOnly(
13688 Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs");
13689 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13690 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13691 "setSatelliteAccessControlOverlayConfigs");
13692 return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset, isAllowed,
13693 s2CellFile, locationFreshDurationNanos, satelliteCountryCodes);
13694 }
13695
13696 /**
Hakjun Choibc6ce992023-11-07 16:04:33 +000013697 * This API can be used by only CTS to override the cached value for the device overlay config
13698 * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether
13699 * outgoing satellite datagrams should be sent to modem in demo mode.
13700 *
13701 * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to
13702 * satellite modem or not.
13703 *
13704 * @return {@code true} if the operation is successful, {@code false} otherwise.
13705 */
13706 public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) {
13707 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
13708 Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is "
13709 + "disabled");
13710 return false;
13711 }
13712 Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode");
13713 TelephonyPermissions.enforceShellOnly(
13714 Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode");
13715 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13716 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13717 "setShouldSendDatagramToModemInDemoMode");
13718 return mSatelliteController.setShouldSendDatagramToModemInDemoMode(
13719 shouldSendToModemInDemoMode);
13720 }
13721
13722 /**
Gil Cukierman06403e12023-11-29 16:33:03 +000013723 * Enable or disable notifications sent for cellular identifier disclosure events.
13724 *
13725 * Disclosure events are defined as instances where a device has sent a cellular identifier
13726 * on the Non-access stratum (NAS) before a security context is established. As a result the
13727 * identifier is sent in the clear, which has privacy implications for the user.
13728 *
13729 * @param enable if notifications about disclosure events should be enabled
13730 * @throws SecurityException if the caller does not have the required privileges
13731 * @throws UnsupportedOperationException if the modem does not support this feature.
13732 */
13733 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000013734 public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) {
Gil Cukierman06403e12023-11-29 16:33:03 +000013735 enforceModifyPermission();
13736 checkForIdentifierDisclosureNotificationSupport();
13737
13738 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
13739 editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable);
13740 editor.apply();
13741
13742 // Each phone instance is responsible for updating its respective modem immediately
13743 // after we've made a preference change.
13744 for (Phone phone : PhoneFactory.getPhones()) {
13745 phone.handleIdentifierDisclosureNotificationPreferenceChange();
13746 }
13747 }
13748
13749 /**
13750 * Get whether or not cellular identifier disclosure notifications are enabled.
13751 *
13752 * @throws SecurityException if the caller does not have the required privileges
13753 * @throws UnsupportedOperationException if the modem does not support this feature.
13754 */
13755 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000013756 public boolean isCellularIdentifierDisclosureNotificationsEnabled() {
Gil Cukierman06403e12023-11-29 16:33:03 +000013757 enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled");
13758 checkForIdentifierDisclosureNotificationSupport();
13759 return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled();
13760 }
13761
13762 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000013763 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
13764 *
13765 * <p>This method behaves in one of the following ways:
13766 * <ul>
13767 * <li>return true : if the calling package has the appop permission {@link
13768 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
13769 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
13770 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
13771 * Owner device identifier access check, or the calling package has carrier privileges</>
13772 * <li>throw SecurityException: if the caller does not meet any of the requirements.
13773 * </ul>
13774 */
13775 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
13776 String callingPackage, @Nullable String callingFeatureId, String message) {
13777 for (Phone phone : PhoneFactory.getPhones()) {
13778 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
13779 phone.getSubId(), callingPackage, callingFeatureId, message)) {
13780 return true;
13781 }
13782 }
13783 return false;
13784 }
arunvoddud7401012022-12-15 16:08:12 +000013785
13786 /**
Jack Yufa8ed012023-02-11 15:42:28 -080013787 * @return The subscription manager service instance.
13788 */
13789 public SubscriptionManagerService getSubscriptionManagerService() {
13790 return SubscriptionManagerService.getInstance();
13791 }
13792
13793 /**
arunvoddud7401012022-12-15 16:08:12 +000013794 * Class binds the consumer[callback] and carrierId.
13795 */
13796 private static class CallerCallbackInfo {
13797 private final Consumer<Integer> mConsumer;
13798 private final int mCarrierId;
13799
13800 public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) {
13801 mConsumer = consumer;
13802 mCarrierId = carrierId;
13803 }
13804
13805 public Consumer<Integer> getConsumer() {
13806 return mConsumer;
13807 }
13808
13809 public int getCarrierId() {
13810 return mCarrierId;
13811 }
13812 }
joonhunshin4ac60942023-11-15 15:23:39 +000013813
13814 /*
13815 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
13816 * But the context that is passed in is unused if the phone app is already alive.
13817 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
13818 */
13819 @VisibleForTesting
13820 public void setPackageManager(PackageManager packageManager) {
13821 mPackageManager = packageManager;
13822 }
13823
13824 /*
13825 * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags.
13826 * But the FeatureFlags that is passed in is unused if the phone app is already alive.
13827 * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test.
13828 */
13829 @VisibleForTesting
13830 public void setFeatureFlags(FeatureFlags featureFlags) {
13831 mFeatureFlags = featureFlags;
13832 }
13833
13834 /**
13835 * Make sure the device has required telephony feature
13836 *
13837 * @throws UnsupportedOperationException if the device does not have required telephony feature
13838 */
13839 private void enforceTelephonyFeatureWithException(@Nullable String callingPackage,
13840 @NonNull String telephonyFeature, @NonNull String methodName) {
13841 if (callingPackage == null || mPackageManager == null) {
13842 return;
13843 }
13844
13845 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
13846 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage,
13847 Binder.getCallingUserHandle())) {
13848 return;
13849 }
13850
13851 if (!mPackageManager.hasSystemFeature(telephonyFeature)) {
13852 throw new UnsupportedOperationException(
13853 methodName + " is unsupported without " + telephonyFeature);
13854 }
13855 }
Jack Yufa8ed012023-02-11 15:42:28 -080013856}