blob: 1751778698ed872a7b62a760c932dfe0f45689df [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
joonhunshin4ac60942023-11-15 15:23:39 +000019import static android.content.pm.PackageManager.FEATURE_TELEPHONY_IMS;
20import static android.content.pm.PackageManager.FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION;
Hall Liud892bec2018-11-30 14:51:45 -080021import static android.content.pm.PackageManager.PERMISSION_GRANTED;
Nate Myrenae97d192023-06-09 15:22:31 -070022import static android.permission.flags.Flags.opEnableMobileDataByUser;
joonhunshin4ac60942023-11-15 15:23:39 +000023import static android.telephony.TelephonyManager.ENABLE_FEATURE_MAPPING;
Gil Cukierman1c0eb932022-12-06 22:28:24 +000024import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK;
jimsunf9ec1622022-09-13 21:18:43 +080025import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080026import static android.telephony.satellite.SatelliteManager.KEY_SATELLITE_COMMUNICATION_ALLOWED;
27import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_ACCESS_BARRED;
Thomas Nguyena8062672024-02-05 14:18:19 -080028import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_REQUEST_NOT_SUPPORTED;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080029import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_SUCCESS;
Hall Liud892bec2018-11-30 14:51:45 -080030
Shuo Qianccbaf742021-02-22 18:32:21 -080031import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
32import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070033import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070034import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000035import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070036
Brad Ebinger34c09a52021-02-17 23:23:21 +000037import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080038import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080039import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070040import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000041import android.annotation.RequiresPermission;
Sarah Chin532d6bb2022-12-28 22:50:43 -080042import android.app.ActivityManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070043import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080044import android.app.PendingIntent;
Tyler Gunn64144d92022-03-17 14:16:41 -070045import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000046import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080047import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000048import android.compat.annotation.ChangeId;
49import android.compat.annotation.EnabledSince;
Anthony Alridge70ba5572023-05-02 12:14:14 +000050import android.content.ActivityNotFoundException;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070051import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070052import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.content.Context;
54import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070055import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070056import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070057import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070058import android.net.Uri;
59import android.os.AsyncResult;
60import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080061import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070062import android.os.Bundle;
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080063import android.os.DropBoxManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070065import android.os.IBinder;
Thomas Nguyen8ee49682023-02-01 11:46:09 -080066import android.os.ICancellationSignal;
tom hsu0b59d292022-09-29 23:49:21 +080067import android.os.LocaleList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070068import android.os.Looper;
69import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070070import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080071import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070072import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070073import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080074import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080075import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070076import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070077import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080078import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070079import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070080import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070081import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070082import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070083import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080084import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070085import android.provider.Telephony;
arunvoddud7401012022-12-15 16:08:12 +000086import android.service.carrier.CarrierIdentifier;
Inseob Kim14bb3d02018-12-13 17:11:34 +090087import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080088import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080089import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070090import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080091import android.telephony.AccessNetworkConstants;
92import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070093import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070094import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080095import android.telephony.Annotation.ThermalMitigationResult;
Sarah Chin2ec39f62022-08-31 17:03:26 -070096import android.telephony.AnomalyReporter;
Shuo Qian4a594052020-01-23 11:59:30 -080097import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070098import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080099import android.telephony.CarrierRestrictionRules;
Hui Wang9b5793a2022-12-05 14:38:06 -0600100import android.telephony.CellBroadcastIdRange;
yincheng zhao2737e882019-09-06 17:06:54 -0700101import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -0800102import android.telephony.CellIdentityCdma;
103import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700104import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -0700105import android.telephony.CellInfoGsm;
106import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700107import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800108import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -0700109import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700110import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700111import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -0800112import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700113import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -0800114import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -0700115import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -0800116import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800117import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700118import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800119import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700120import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800121import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800122import android.telephony.SignalStrengthUpdateRequest;
123import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800124import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800125import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800126import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700127import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700128import android.telephony.TelephonyManager;
Jack Yuf5badd92022-12-08 00:50:53 -0800129import android.telephony.TelephonyManager.SimState;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800130import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800131import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800132import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000133import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000134import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000135import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700136import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700137import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800138import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800139import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700140import android.telephony.gba.GbaAuthRequest;
141import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700142import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800143import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000144import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000145import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700146import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000147import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700148import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800149import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700150import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800151import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700152import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000153import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700154import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800155import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800156import android.telephony.ims.stub.ImsRegistrationImplBase;
Hakjun Choifa3e6172023-09-22 03:56:34 +0000157import android.telephony.satellite.INtnSignalStrengthCallback;
Hakjun Choi8d96a562023-10-26 15:01:40 +0000158import android.telephony.satellite.ISatelliteCapabilitiesCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800159import android.telephony.satellite.ISatelliteDatagramCallback;
Hakjun Choid4a52a22023-12-13 09:48:24 +0000160import android.telephony.satellite.ISatelliteModemStateCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800161import android.telephony.satellite.ISatelliteProvisionStateCallback;
Sarah Chinabf081b2023-03-09 23:00:57 -0800162import android.telephony.satellite.ISatelliteTransmissionUpdateCallback;
Hakjun Choi4c3668a2023-12-05 11:55:36 +0000163import android.telephony.satellite.NtnSignalStrength;
164import android.telephony.satellite.NtnSignalStrengthCallback;
Sarah Chin503828c2023-02-01 23:54:20 -0800165import android.telephony.satellite.SatelliteCapabilities;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000166import android.telephony.satellite.SatelliteDatagram;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800167import android.telephony.satellite.SatelliteDatagramCallback;
Sarah Chineccfbd12023-01-20 19:00:35 -0800168import android.telephony.satellite.SatelliteManager;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800169import android.telephony.satellite.SatelliteProvisionStateCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700170import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800171import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700172import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700173import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800174import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800175
Andrew Lee312e8172014-10-23 17:01:36 -0700176import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800177import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800178import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800179import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800180import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700181import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700182import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700183import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800184import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800185import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700186import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700187import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800188import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700189import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800190import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800191import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800192import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700193import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000194import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700195import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800196import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700197import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800198import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800199import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800200import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700201import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700202import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700203import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700204import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700205import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800206import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700207import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700208import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700209import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700210import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800211import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800212import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700213import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000214import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700215import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700216import com.android.internal.telephony.SmsPermissions;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800217import com.android.internal.telephony.TelephonyCountryDetector;
Peter Wang59571be2020-01-27 12:35:15 +0800218import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800219import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700220import com.android.internal.telephony.data.DataUtils;
Hunsuk Choi42cc62a2022-10-16 06:03:40 +0000221import com.android.internal.telephony.domainselection.DomainSelectionResolver;
sqianf4ca7ed2019-01-15 18:32:07 -0800222import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700223import com.android.internal.telephony.euicc.EuiccConnector;
Sarah Chincc5446f2023-10-23 17:57:19 -0700224import com.android.internal.telephony.flags.FeatureFlags;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800225import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700226import com.android.internal.telephony.imsphone.ImsPhone;
227import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000228import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800229import com.android.internal.telephony.metrics.TelephonyMetrics;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000230import com.android.internal.telephony.satellite.SatelliteController;
Jack Yu285100e2022-12-02 22:48:35 -0800231import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
232import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700233import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700234import com.android.internal.telephony.uicc.IccIoResult;
235import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800236import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700237import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800238import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700239import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000240import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800241import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000242import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800243import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000244import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700245import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700246import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800247import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800248import com.android.phone.callcomposer.CallComposerPictureManager;
249import com.android.phone.callcomposer.CallComposerPictureTransfer;
250import com.android.phone.callcomposer.ImageData;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800251import com.android.phone.satellite.accesscontrol.SatelliteAccessController;
Hyosun Kim240214a2023-11-02 13:30:15 +0000252import com.android.phone.satellite.entitlement.SatelliteEntitlementController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700253import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700254import com.android.phone.slice.SlicePurchaseController;
arunvoddud7401012022-12-15 16:08:12 +0000255import com.android.phone.utils.CarrierAllowListInfo;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700256import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800257import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700258import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700259import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -0800260import com.android.server.feature.flags.Flags;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800261import com.android.services.telephony.TelecomAccountRegistry;
262import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800263import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800264
Hall Liu82694d52020-12-11 18:22:04 -0800265import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700266import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800267import java.io.IOException;
268import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700269import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700270import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800271import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000272import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800273import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800274import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800275import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800276import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100277import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800278import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700279import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800280import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800281import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700282import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800283import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800284import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800285import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700286
287/**
288 * Implementation of the ITelephony interface.
289 */
Santos Cordon117fee72014-05-16 17:56:12 -0700290public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700291 private static final String LOG_TAG = "PhoneInterfaceManager";
292 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
293 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800294 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700295
296 // Message codes used with mMainThreadHandler
297 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700298 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
299 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700300 private static final int CMD_OPEN_CHANNEL = 9;
301 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
302 private static final int CMD_CLOSE_CHANNEL = 11;
303 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800304 private static final int CMD_NV_READ_ITEM = 13;
305 private static final int EVENT_NV_READ_ITEM_DONE = 14;
306 private static final int CMD_NV_WRITE_ITEM = 15;
307 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
308 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
309 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700310 private static final int CMD_RESET_MODEM_CONFIG = 19;
311 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800312 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
313 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800314 private static final int CMD_SEND_ENVELOPE = 25;
315 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700316 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
317 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
318 private static final int CMD_EXCHANGE_SIM_IO = 31;
319 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800320 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
321 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700322 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
323 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700324 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
325 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700326 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
327 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
328 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
329 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700330 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
331 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
332 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
333 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700334 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800335 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
336 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000337 private static final int CMD_SWITCH_SLOTS = 50;
338 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700339 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
340 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
341 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
342 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
343 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
344 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
345 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
346 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700347 private static final int CMD_GET_ALL_CELL_INFO = 60;
348 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
349 private static final int CMD_GET_CELL_LOCATION = 62;
350 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700351 private static final int CMD_MODEM_REBOOT = 64;
352 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700353 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
354 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800355 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
356 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700357 private static final int CMD_GET_MODEM_STATUS = 70;
358 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700359 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
360 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700361 private static final int CMD_ERASE_MODEM_CONFIG = 74;
362 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800363 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
364 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
365 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
366 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800367 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
368 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800369 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800370 private static final int CMD_GET_CALL_FORWARDING = 83;
371 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
372 private static final int CMD_SET_CALL_FORWARDING = 85;
373 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
374 private static final int CMD_GET_CALL_WAITING = 87;
375 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
376 private static final int CMD_SET_CALL_WAITING = 89;
377 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700378 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
379 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
380 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
381 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700382 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
383 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800384 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
385 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800386 private static final int CMD_SET_DATA_THROTTLING = 99;
387 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800388 private static final int CMD_SET_SIM_POWER = 101;
389 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800390 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
391 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
392 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
393 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800394 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
395 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000396 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800397 private static final int CMD_GET_SLICING_CONFIG = 110;
398 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800399 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700400 private static final int CMD_ENABLE_VONR = 113;
401 private static final int EVENT_ENABLE_VONR_DONE = 114;
402 private static final int CMD_IS_VONR_ENABLED = 115;
403 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700404 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
405 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000406
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800407 // Parameters of select command.
408 private static final int SELECT_COMMAND = 0xA4;
409 private static final int SELECT_P1 = 0x04;
410 private static final int SELECT_P2 = 0;
411 private static final int SELECT_P3 = 0x10;
412
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000413 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
414 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
Gil Cukierman06403e12023-11-29 16:33:03 +0000415 // Cellular identifier disclosure transparency was added in IRadioNetwork 2.2
416 private static final int MIN_IDENTIFIER_DISCLOSURE_VERSION = 202;
Michael Groover826b71d2023-12-21 22:08:06 -0600417 // Null cipher notification support was added in IRadioNetwork 2.2
418 private static final int MIN_NULL_CIPHER_NOTIFICATION_VERSION = 202;
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000419
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700420 /** The singleton instance. */
421 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800422 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700423
Sarah Chin4beb2b72023-02-14 14:47:54 -0800424 private final PhoneGlobals mApp;
joonhunshin4ac60942023-11-15 15:23:39 +0000425 private FeatureFlags mFeatureFlags;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -0800426 private com.android.server.telecom.flags.FeatureFlags mTelecomFeatureFlags;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800427 private final CallManager mCM;
428 private final ImsResolver mImsResolver;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000429
430 private final SatelliteController mSatelliteController;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800431 private final SatelliteAccessController mSatelliteAccessController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800432 private final UserManager mUserManager;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800433 private final MainThreadHandler mMainThreadHandler;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800434 private final SharedPreferences mTelephonySharedPreferences;
435 private final PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800436 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Nate Myren453c3472024-03-13 11:28:11 -0700437 private AppOpsManager mAppOps;
joonhunshin4ac60942023-11-15 15:23:39 +0000438 private PackageManager mPackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700439
Peter Wangdafb9ac2020-01-15 14:13:38 -0800440 /** User Activity */
Sarah Chin4beb2b72023-02-14 14:47:54 -0800441 private final AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800442 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800443 private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800444
Derek Tan97ebb422014-09-05 16:55:38 -0700445 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
446 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800447 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800448 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700449
Michelecea4cf22018-12-21 15:00:11 -0800450 // String to store multi SIM allowed
451 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
452
Derek Tan740e1672017-06-27 14:56:27 -0700453 // The AID of ISD-R.
454 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
455
yinxub1bed742017-04-17 11:45:04 -0700456 private NetworkScanRequestTracker mNetworkScanRequestTracker;
457
David Kelly5e06a7f2018-03-12 14:10:59 +0000458 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
459 private static final int MANUFACTURER_CODE_LENGTH = 8;
460
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800461 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800462 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800463
Sarah Chin2ec39f62022-08-31 17:03:26 -0700464 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
465 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
466
Derek Tan89e89d42014-07-08 17:00:10 -0700467 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700468 * Experiment flag to enable erase modem config on reset network, default value is false
469 */
470 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
471 "reset_network_erase_modem_config_enabled";
472
Rambo Wang0f050d82021-02-12 11:43:36 -0800473 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800474
Gary Jian76280a42022-12-07 16:18:33 +0800475 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
476
sandeepjsb6c87872021-09-27 15:34:44 +0000477 /**
478 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
479 * one ICCID active at the same time.
480 * Apps should use below API signatures if targeting SDK is T and beyond.
481 *
482 * @hide
483 */
484 @ChangeId
485 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
486 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800487
Naina Nallurid63128d2019-09-17 14:10:30 -0700488 /**
Chen Xu540470b2021-12-14 17:15:47 -0800489 * Apps targeting on Android T and beyond will get exception whenever icc close channel
490 * operation fails.
491 */
492 @ChangeId
493 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
494 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
495
496 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700497 * A request object to use for transmitting data to an ICC.
498 */
499 private static final class IccAPDUArgument {
500 public int channel, cla, command, p1, p2, p3;
501 public String data;
502
503 public IccAPDUArgument(int channel, int cla, int command,
504 int p1, int p2, int p3, String data) {
505 this.channel = channel;
506 this.cla = cla;
507 this.command = command;
508 this.p1 = p1;
509 this.p2 = p2;
510 this.p3 = p3;
511 this.data = data;
512 }
513 }
514
515 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700516 * A request object to use for transmitting data to an ICC.
517 */
518 private static final class ManualNetworkSelectionArgument {
519 public OperatorInfo operatorInfo;
520 public boolean persistSelection;
521
522 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
523 this.operatorInfo = operatorInfo;
524 this.persistSelection = persistSelection;
525 }
526 }
527
Sarah Chin71b3a852022-09-28 15:54:19 -0700528 private static final class PurchasePremiumCapabilityArgument {
529 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700530 public @NonNull IIntegerConsumer callback;
531
532 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800533 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700534 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700535 this.callback = callback;
536 }
537 }
538
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700539 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700540 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
541 * request after sending. The main thread will notify the request when it is complete.
542 */
543 private static final class MainThreadRequest {
544 /** The argument to use for the request */
545 public Object argument;
546 /** The result of the request that is run on the main thread */
547 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800548 // The subscriber id that this request applies to. Defaults to
549 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
550 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700551
Nathan Harold92bed182018-10-12 18:16:49 -0700552 // In cases where subId is unavailable, the caller needs to specify the phone.
553 public Phone phone;
554
vagdeviaf9a5b92018-08-15 16:01:53 -0700555 public WorkSource workSource;
556
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700557 public MainThreadRequest(Object argument) {
558 this.argument = argument;
559 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800560
Nathan Harold92bed182018-10-12 18:16:49 -0700561 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
562 this.argument = argument;
563 if (phone != null) {
564 this.phone = phone;
565 }
566 this.workSource = workSource;
567 }
568
vagdeviaf9a5b92018-08-15 16:01:53 -0700569 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800570 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800571 if (subId != null) {
572 this.subId = subId;
573 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700574 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800575 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700576 }
577
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800578 private static final class IncomingThirdPartyCallArgs {
579 public final ComponentName component;
580 public final String callId;
581 public final String callerDisplayName;
582
583 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
584 String callerDisplayName) {
585 this.component = component;
586 this.callId = callId;
587 this.callerDisplayName = callerDisplayName;
588 }
589 }
590
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700591 /**
592 * A handler that processes messages on the main thread in the phone process. Since many
593 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
594 * inbound binder threads to the main thread in the phone process. The Binder thread
595 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
596 * on, which will be notified when the operation completes and will contain the result of the
597 * request.
598 *
599 * <p>If a MainThreadRequest object is provided in the msg.obj field,
600 * note that request.result must be set to something non-null for the calling thread to
601 * unblock.
602 */
603 private final class MainThreadHandler extends Handler {
604 @Override
605 public void handleMessage(Message msg) {
606 MainThreadRequest request;
607 Message onCompleted;
608 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000609 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700610 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800611 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700612
613 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700614 case CMD_HANDLE_USSD_REQUEST: {
615 request = (MainThreadRequest) msg.obj;
616 final Phone phone = getPhoneFromRequest(request);
617 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800618 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700619 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700620
Pengquan Menga1bb6272018-09-06 09:59:22 -0700621 if (!isUssdApiAllowed(request.subId)) {
622 // Carrier does not support use of this API, return failure.
623 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
624 UssdResponse response = new UssdResponse(ussdRequest, null);
625 Bundle returnData = new Bundle();
626 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
627 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700628
Pengquan Menga1bb6272018-09-06 09:59:22 -0700629 request.result = true;
630 notifyRequester(request);
631 return;
632 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700633
Pengquan Menga1bb6272018-09-06 09:59:22 -0700634 try {
635 request.result = phone != null
636 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
637 } catch (CallStateException cse) {
638 request.result = false;
639 }
640 // Wake up the requesting thread
641 notifyRequester(request);
642 break;
pkanwar32d516d2016-10-14 19:37:38 -0700643 }
644
Yorke Lee716f67e2015-06-17 15:39:16 -0700645 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700646 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700647 final Phone phone = getPhoneFromRequest(request);
648 request.result = phone != null ?
649 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
650 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700651 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700652 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700653 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700654 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700655
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700656 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700657 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700658 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000659 uiccPort = getUiccPortFromRequest(request);
660 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700661 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800662 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700663 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700664 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700665 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800666 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000667 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800668 iccArgument.channel, iccArgument.cla, iccArgument.command,
669 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
670 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700671 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700672 break;
673
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700674 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700675 ar = (AsyncResult) msg.obj;
676 request = (MainThreadRequest) ar.userObj;
677 if (ar.exception == null && ar.result != null) {
678 request.result = ar.result;
679 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800680 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700681 if (ar.result == null) {
682 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800683 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700684 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800685 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700686 } else {
687 loge("iccTransmitApduLogicalChannel: Unknown exception");
688 }
689 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700690 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700691 break;
692
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700693 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
694 request = (MainThreadRequest) msg.obj;
695 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000696 uiccPort = getUiccPortFromRequest(request);
697 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700698 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800699 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700700 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700701 } else {
702 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800703 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000704 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800705 iccArgument.cla, iccArgument.command, iccArgument.p1,
706 iccArgument.p2,
707 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700708 }
709 break;
710
711 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
712 ar = (AsyncResult) msg.obj;
713 request = (MainThreadRequest) ar.userObj;
714 if (ar.exception == null && ar.result != null) {
715 request.result = ar.result;
716 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800717 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700718 if (ar.result == null) {
719 loge("iccTransmitApduBasicChannel: Empty response");
720 } else if (ar.exception instanceof CommandException) {
721 loge("iccTransmitApduBasicChannel: CommandException: " +
722 ar.exception);
723 } else {
724 loge("iccTransmitApduBasicChannel: Unknown exception");
725 }
726 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700727 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700728 break;
729
730 case CMD_EXCHANGE_SIM_IO:
731 request = (MainThreadRequest) msg.obj;
732 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000733 uiccPort = getUiccPortFromRequest(request);
734 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700735 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800736 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700737 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700738 } else {
739 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
740 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000741 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700742 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
743 iccArgument.data, onCompleted);
744 }
745 break;
746
747 case EVENT_EXCHANGE_SIM_IO_DONE:
748 ar = (AsyncResult) msg.obj;
749 request = (MainThreadRequest) ar.userObj;
750 if (ar.exception == null && ar.result != null) {
751 request.result = ar.result;
752 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800753 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700754 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700755 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700756 break;
757
Derek Tan4d5e5c12014-02-04 11:54:58 -0800758 case CMD_SEND_ENVELOPE:
759 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000760 uiccPort = getUiccPortFromRequest(request);
761 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700762 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800763 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700764 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700765 } else {
766 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800767 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700768 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800769 break;
770
771 case EVENT_SEND_ENVELOPE_DONE:
772 ar = (AsyncResult) msg.obj;
773 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700774 if (ar.exception == null && ar.result != null) {
775 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800776 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800777 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700778 if (ar.result == null) {
779 loge("sendEnvelopeWithStatus: Empty response");
780 } else if (ar.exception instanceof CommandException) {
781 loge("sendEnvelopeWithStatus: CommandException: " +
782 ar.exception);
783 } else {
784 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
785 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800786 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700787 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800788 break;
789
Shishir Agrawal566b7612013-10-28 14:41:00 -0700790 case CMD_OPEN_CHANNEL:
791 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000792 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800793 IccLogicalChannelRequest openChannelRequest =
794 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000795 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700796 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800797 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800798 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700799 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700800 } else {
801 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800802 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
803 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700804 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700805 break;
806
807 case EVENT_OPEN_CHANNEL_DONE:
808 ar = (AsyncResult) msg.obj;
809 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700810 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700811 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700812 int[] result = (int[]) ar.result;
813 int channelId = result[0];
814 byte[] selectResponse = null;
815 if (result.length > 1) {
816 selectResponse = new byte[result.length - 1];
817 for (int i = 1; i < result.length; ++i) {
818 selectResponse[i - 1] = (byte) result[i];
819 }
820 }
821 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800822 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800823
824 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700825 if (uiccPort == null) {
826 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
827 } else {
828 IccLogicalChannelRequest channelRequest =
829 (IccLogicalChannelRequest) request.argument;
830 channelRequest.channel = channelId;
831 uiccPort.onLogicalChannelOpened(channelRequest);
832 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700833 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700834 if (ar.result == null) {
835 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700836 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700837 if (ar.exception != null) {
838 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
839 }
840
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700841 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700842 if (ar.exception instanceof CommandException) {
843 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800844 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700845 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700846 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700847 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700848 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700849 }
850 }
851 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800852 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700853 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700854 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700855 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700856 break;
857
858 case CMD_CLOSE_CHANNEL:
859 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000860 uiccPort = getUiccPortFromRequest(request);
861 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700862 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800863 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800864 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800865 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700866 } else {
867 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000868 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700869 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700870 break;
871
872 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800873 ar = (AsyncResult) msg.obj;
874 request = (MainThreadRequest) ar.userObj;
875 if (ar.exception == null) {
876 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800877 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700878 if (uiccPort == null) {
879 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
880 } else {
881 final int channelId = (Integer) request.argument;
882 uiccPort.onLogicalChannelClosed(channelId);
883 }
Chen Xu540470b2021-12-14 17:15:47 -0800884 } else {
885 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800886 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800887 if (ar.exception instanceof CommandException) {
888 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
889 CommandException.Error error =
890 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800891 if (error == CommandException.Error.INVALID_ARGUMENTS) {
892 // should only throw exceptions from the binder threads.
893 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800894 "iccCloseLogicalChannel: invalid argument ");
895 }
896 } else {
897 loge("iccCloseLogicalChannel: Unknown exception");
898 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800899 request.result = (exception != null) ? exception :
900 new IllegalStateException(
901 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800902 }
903 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800904 break;
905
906 case CMD_NV_READ_ITEM:
907 request = (MainThreadRequest) msg.obj;
908 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800909 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
910 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800911 break;
912
913 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700914 ar = (AsyncResult) msg.obj;
915 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800916 if (ar.exception == null && ar.result != null) {
917 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700918 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800919 request.result = "";
920 if (ar.result == null) {
921 loge("nvReadItem: Empty response");
922 } else if (ar.exception instanceof CommandException) {
923 loge("nvReadItem: CommandException: " +
924 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700925 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800926 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700927 }
928 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700929 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700930 break;
931
Jake Hambye994d462014-02-03 13:10:13 -0800932 case CMD_NV_WRITE_ITEM:
933 request = (MainThreadRequest) msg.obj;
934 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
935 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800936 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700937 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800938 break;
939
940 case EVENT_NV_WRITE_ITEM_DONE:
941 handleNullReturnEvent(msg, "nvWriteItem");
942 break;
943
944 case CMD_NV_WRITE_CDMA_PRL:
945 request = (MainThreadRequest) msg.obj;
946 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800947 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800948 break;
949
950 case EVENT_NV_WRITE_CDMA_PRL_DONE:
951 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
952 break;
953
chen xu6dac5ab2018-10-26 17:39:23 -0700954 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800955 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700956 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800957 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800958 break;
959
chen xu6dac5ab2018-10-26 17:39:23 -0700960 case EVENT_RESET_MODEM_CONFIG_DONE:
961 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800962 break;
963
Sooraj Sasindran37444802020-08-11 10:40:43 -0700964 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
965 request = (MainThreadRequest) msg.obj;
966 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
967 request);
968 Phone phone = getPhoneFromRequest(request);
969 if (phone != null) {
970 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
971 } else {
972 loge("isNRDualConnectivityEnabled: No phone object");
973 request.result = false;
974 notifyRequester(request);
975 }
976 break;
977 }
978
979 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
980 ar = (AsyncResult) msg.obj;
981 request = (MainThreadRequest) ar.userObj;
982 if (ar.exception == null && ar.result != null) {
983 request.result = ar.result;
984 } else {
985 // request.result must be set to something non-null
986 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700987 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700988 request.result = ar.result;
989 } else {
990 request.result = false;
991 }
992 if (ar.result == null) {
993 loge("isNRDualConnectivityEnabled: Empty response");
994 } else if (ar.exception instanceof CommandException) {
995 loge("isNRDualConnectivityEnabled: CommandException: "
996 + ar.exception);
997 } else {
998 loge("isNRDualConnectivityEnabled: Unknown exception");
999 }
1000 }
1001 notifyRequester(request);
1002 break;
1003
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001004 case CMD_IS_VONR_ENABLED: {
1005 request = (MainThreadRequest) msg.obj;
1006 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
1007 request);
1008 Phone phone = getPhoneFromRequest(request);
1009 if (phone != null) {
1010 phone.isVoNrEnabled(onCompleted, request.workSource);
1011 } else {
1012 loge("isVoNrEnabled: No phone object");
1013 request.result = false;
1014 notifyRequester(request);
1015 }
1016 break;
1017 }
1018
1019 case EVENT_IS_VONR_ENABLED_DONE:
1020 ar = (AsyncResult) msg.obj;
1021 request = (MainThreadRequest) ar.userObj;
1022 if (ar.exception == null && ar.result != null) {
1023 request.result = ar.result;
1024 } else {
1025 // request.result must be set to something non-null
1026 // for the calling thread to unblock
1027 if (ar.result != null) {
1028 request.result = ar.result;
1029 } else {
1030 request.result = false;
1031 }
1032 if (ar.result == null) {
1033 loge("isVoNrEnabled: Empty response");
1034 } else if (ar.exception instanceof CommandException) {
1035 loge("isVoNrEnabled: CommandException: "
1036 + ar.exception);
1037 } else {
1038 loge("isVoNrEnabled: Unknown exception");
1039 }
1040 }
1041 notifyRequester(request);
1042 break;
1043
Sooraj Sasindran37444802020-08-11 10:40:43 -07001044 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1045 request = (MainThreadRequest) msg.obj;
1046 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1047 Phone phone = getPhoneFromRequest(request);
1048 if (phone != null) {
1049 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1050 request.workSource);
1051 } else {
1052 loge("enableNrDualConnectivity: No phone object");
1053 request.result =
1054 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1055 notifyRequester(request);
1056 }
1057 break;
1058 }
1059
1060 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1061 ar = (AsyncResult) msg.obj;
1062 request = (MainThreadRequest) ar.userObj;
1063 if (ar.exception == null) {
1064 request.result =
1065 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1066 } else {
1067 request.result =
1068 TelephonyManager
1069 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1070 if (ar.exception instanceof CommandException) {
1071 CommandException.Error error =
1072 ((CommandException) (ar.exception)).getCommandError();
1073 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1074 request.result =
1075 TelephonyManager
1076 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001077 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1078 request.result =
1079 TelephonyManager
1080 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001081 }
1082 loge("enableNrDualConnectivity" + ": CommandException: "
1083 + ar.exception);
1084 } else {
1085 loge("enableNrDualConnectivity" + ": Unknown exception");
1086 }
1087 }
1088 notifyRequester(request);
1089 break;
1090 }
1091
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001092 case CMD_ENABLE_VONR: {
1093 request = (MainThreadRequest) msg.obj;
1094 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1095 Phone phone = getPhoneFromRequest(request);
1096 if (phone != null) {
1097 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1098 request.workSource);
1099 } else {
1100 loge("setVoNrEnabled: No phone object");
1101 request.result =
1102 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1103 notifyRequester(request);
1104 }
1105 break;
1106 }
1107
1108 case EVENT_ENABLE_VONR_DONE: {
1109 ar = (AsyncResult) msg.obj;
1110 request = (MainThreadRequest) ar.userObj;
1111 if (ar.exception == null) {
1112 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1113 } else {
1114 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1115 if (ar.exception instanceof CommandException) {
1116 CommandException.Error error =
1117 ((CommandException) (ar.exception)).getCommandError();
1118 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1119 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1120 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1121 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1122 } else {
1123 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1124 }
1125 loge("setVoNrEnabled" + ": CommandException: "
1126 + ar.exception);
1127 } else {
1128 loge("setVoNrEnabled" + ": Unknown exception");
1129 }
1130 }
1131 notifyRequester(request);
1132 break;
1133 }
1134
SongFerngWang3ef3e072020-12-21 16:41:52 +08001135 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001136 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001137 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1138 request);
1139 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001140 break;
1141
SongFerngWang3ef3e072020-12-21 16:41:52 +08001142 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001143 ar = (AsyncResult) msg.obj;
1144 request = (MainThreadRequest) ar.userObj;
1145 if (ar.exception == null && ar.result != null) {
1146 request.result = ar.result; // Integer
1147 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301148 // request.result must be set to something non-null
1149 // for the calling thread to unblock
1150 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001151 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001152 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001153 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001154 loge("getAllowedNetworkTypesBitmask: CommandException: "
1155 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001156 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001157 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001158 }
1159 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001160 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001161 break;
1162
SongFerngWang3ef3e072020-12-21 16:41:52 +08001163 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001164 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001165 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1166 request);
1167 Pair<Integer, Long> reasonWithNetworkTypes =
1168 (Pair<Integer, Long>) request.argument;
1169 getPhoneFromRequest(request).setAllowedNetworkTypes(
1170 reasonWithNetworkTypes.first,
1171 reasonWithNetworkTypes.second,
1172 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001173 break;
1174
SongFerngWang3ef3e072020-12-21 16:41:52 +08001175 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1176 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001177 break;
1178
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001179 case CMD_SET_VOICEMAIL_NUMBER:
1180 request = (MainThreadRequest) msg.obj;
1181 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1182 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001183 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1184 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001185 break;
1186
1187 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1188 handleNullReturnEvent(msg, "setVoicemailNumber");
1189 break;
1190
Stuart Scott54788802015-03-30 13:18:01 -07001191 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1192 request = (MainThreadRequest) msg.obj;
1193 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1194 request);
1195 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1196 break;
1197
1198 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1199 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1200 break;
1201
Shishir Agrawal302c8692015-06-19 13:49:39 -07001202 case CMD_PERFORM_NETWORK_SCAN:
1203 request = (MainThreadRequest) msg.obj;
1204 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1205 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1206 break;
1207
Hall Liu27d24262020-09-18 19:04:59 -07001208 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001209 request = (MainThreadRequest) msg.obj;
1210 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001211 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1212 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1213 request.argument;
1214 int callForwardingReason = args.first;
1215 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001216 break;
Hall Liu27d24262020-09-18 19:04:59 -07001217 }
1218 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001219 ar = (AsyncResult) msg.obj;
1220 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001221 TelephonyManager.CallForwardingInfoCallback callback =
1222 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1223 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001224 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001225 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001226 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1227 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1228 // Service Class is a bit mask per 3gpp 27.007. Search for
1229 // any service for voice call.
1230 if ((callForwardInfo.serviceClass
1231 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001232 callForwardingInfo = new CallForwardingInfo(
1233 callForwardInfo.status
1234 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001235 callForwardInfo.reason,
1236 callForwardInfo.number,
1237 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001238 break;
1239 }
1240 }
1241 // Didn't find a call forward info for voice call.
1242 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001243 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1244 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001245 }
Hall Liu27d24262020-09-18 19:04:59 -07001246 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001247 } else {
1248 if (ar.result == null) {
1249 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1250 }
1251 if (ar.exception != null) {
1252 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1253 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001254 int errorCode = TelephonyManager
1255 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001256 if (ar.exception instanceof CommandException) {
1257 CommandException.Error error =
1258 ((CommandException) (ar.exception)).getCommandError();
1259 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001260 errorCode = TelephonyManager
1261 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001262 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001263 errorCode = TelephonyManager
1264 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001265 }
1266 }
Hall Liu27d24262020-09-18 19:04:59 -07001267 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001268 }
Shuo Qian4a594052020-01-23 11:59:30 -08001269 break;
Hall Liu27d24262020-09-18 19:04:59 -07001270 }
Shuo Qian4a594052020-01-23 11:59:30 -08001271
Hall Liu27d24262020-09-18 19:04:59 -07001272 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001273 request = (MainThreadRequest) msg.obj;
1274 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001275 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001276 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001277 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1278 request.argument).first;
1279 request.phone.setCallForwardingOption(
1280 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001281 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001282 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001283 callForwardingInfoToSet.getReason(),
1284 callForwardingInfoToSet.getNumber(),
1285 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1286 break;
Hall Liu27d24262020-09-18 19:04:59 -07001287 }
Shuo Qian4a594052020-01-23 11:59:30 -08001288
Hall Liu27d24262020-09-18 19:04:59 -07001289 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001290 ar = (AsyncResult) msg.obj;
1291 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001292 Consumer<Integer> callback =
1293 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1294 request.argument).second;
1295 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001296 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001297 int errorCode = TelephonyManager.CallForwardingInfoCallback
1298 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001299 if (ar.exception instanceof CommandException) {
1300 CommandException.Error error =
1301 ((CommandException) (ar.exception)).getCommandError();
1302 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001303 errorCode = TelephonyManager.CallForwardingInfoCallback
1304 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001305 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001306 errorCode = TelephonyManager.CallForwardingInfoCallback
1307 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001308 }
1309 }
1310 callback.accept(errorCode);
1311 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001312 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001313 }
Shuo Qian4a594052020-01-23 11:59:30 -08001314 break;
Hall Liu27d24262020-09-18 19:04:59 -07001315 }
Shuo Qian4a594052020-01-23 11:59:30 -08001316
Hall Liu27d24262020-09-18 19:04:59 -07001317 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001318 request = (MainThreadRequest) msg.obj;
1319 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1320 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1321 break;
Hall Liu27d24262020-09-18 19:04:59 -07001322 }
Shuo Qian4a594052020-01-23 11:59:30 -08001323
Hall Liu27d24262020-09-18 19:04:59 -07001324 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001325 ar = (AsyncResult) msg.obj;
1326 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001327 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001328 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001329 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001330 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001331 // Service Class is a bit mask per 3gpp 27.007.
1332 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001333 if (callForwardResults.length > 1
1334 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001335 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001336 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001337 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1338 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001339 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001340 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001341 }
1342 } else {
1343 if (ar.result == null) {
1344 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1345 }
1346 if (ar.exception != null) {
1347 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1348 }
1349 if (ar.exception instanceof CommandException) {
1350 CommandException.Error error =
1351 ((CommandException) (ar.exception)).getCommandError();
1352 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001353 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001354 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001355 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1356 callWaitingStatus =
1357 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001358 }
1359 }
1360 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001361 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001362 break;
Hall Liu27d24262020-09-18 19:04:59 -07001363 }
Shuo Qian4a594052020-01-23 11:59:30 -08001364
Hall Liu27d24262020-09-18 19:04:59 -07001365 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001366 request = (MainThreadRequest) msg.obj;
1367 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001368 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1369 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001370 break;
Hall Liu27d24262020-09-18 19:04:59 -07001371 }
Shuo Qian4a594052020-01-23 11:59:30 -08001372
Hall Liu27d24262020-09-18 19:04:59 -07001373 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001374 ar = (AsyncResult) msg.obj;
1375 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001376 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1377 Consumer<Integer> callback =
1378 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1379 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001380 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001381 if (ar.exception instanceof CommandException) {
1382 CommandException.Error error =
1383 ((CommandException) (ar.exception)).getCommandError();
1384 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1385 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001386 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1387 callback.accept(
1388 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001389 } else {
1390 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1391 }
1392 } else {
1393 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1394 }
1395 } else {
1396 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1397 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001398 }
Shuo Qian4a594052020-01-23 11:59:30 -08001399 break;
Hall Liu27d24262020-09-18 19:04:59 -07001400 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001401 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1402 ar = (AsyncResult) msg.obj;
1403 request = (MainThreadRequest) ar.userObj;
1404 CellNetworkScanResult cellScanResult;
1405 if (ar.exception == null && ar.result != null) {
1406 cellScanResult = new CellNetworkScanResult(
1407 CellNetworkScanResult.STATUS_SUCCESS,
1408 (List<OperatorInfo>) ar.result);
1409 } else {
1410 if (ar.result == null) {
1411 loge("getCellNetworkScanResults: Empty response");
1412 }
1413 if (ar.exception != null) {
1414 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1415 }
1416 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1417 if (ar.exception instanceof CommandException) {
1418 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001419 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001420 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1421 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1422 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1423 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1424 }
1425 }
1426 cellScanResult = new CellNetworkScanResult(errorCode, null);
1427 }
1428 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001429 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001430 break;
1431
1432 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1433 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001434 ManualNetworkSelectionArgument selArg =
1435 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001436 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1437 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001438 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1439 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001440 break;
1441
1442 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001443 ar = (AsyncResult) msg.obj;
1444 request = (MainThreadRequest) ar.userObj;
1445 if (ar.exception == null) {
1446 request.result = true;
1447 } else {
1448 request.result = false;
1449 loge("setNetworkSelectionModeManual " + ar.exception);
1450 }
1451 notifyRequester(request);
1452 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001453 break;
1454
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001455 case CMD_GET_MODEM_ACTIVITY_INFO:
1456 request = (MainThreadRequest) msg.obj;
1457 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001458 if (defaultPhone != null) {
1459 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001460 } else {
1461 ResultReceiver result = (ResultReceiver) request.argument;
1462 Bundle bundle = new Bundle();
1463 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001464 new ModemActivityInfo(0, 0, 0,
1465 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001466 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001467 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001468 break;
1469
Hall Liud0f208c2020-10-14 16:54:44 -07001470 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001471 ar = (AsyncResult) msg.obj;
1472 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001473 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001474 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001475 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001476 if (mLastModemActivityInfo == null) {
1477 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1478 mLastModemActivitySpecificInfo[0] =
1479 new ActivityStatsTechSpecificInfo(
1480 0,
1481 0,
1482 new int[ModemActivityInfo.getNumTxPowerLevels()],
1483 0);
1484 mLastModemActivityInfo =
1485 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1486 }
1487
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001488 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001489 // Update the last modem activity info and the result of the request.
1490 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1491 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001492 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001493 } else {
1494 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001495 }
Kai Shi917fdc62022-11-28 14:01:02 -08001496 // This is needed to decouple ret from mLastModemActivityInfo
1497 // We don't want to return mLastModemActivityInfo which is updated
1498 // inside mergeModemActivityInfo()
1499 ret = new ModemActivityInfo(
1500 mLastModemActivityInfo.getTimestampMillis(),
1501 mLastModemActivityInfo.getSleepTimeMillis(),
1502 mLastModemActivityInfo.getIdleTimeMillis(),
1503 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001504
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001505 } else {
1506 if (ar.result == null) {
1507 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001508 error = TelephonyManager.ModemActivityInfoException
1509 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001510 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001511 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001512 error = TelephonyManager.ModemActivityInfoException
1513 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001514 } else {
1515 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001516 error = TelephonyManager.ModemActivityInfoException
1517 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001518 }
1519 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001520 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001521 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001522 bundle.putParcelable(
1523 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001524 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001525 } else {
1526 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1527 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001528 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001529 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001530 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001531 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001532
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001533 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001534 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001535 CarrierRestrictionRules argument =
1536 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001537 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001538 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001539 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001540 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001541
1542 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1543 ar = (AsyncResult) msg.obj;
1544 request = (MainThreadRequest) ar.userObj;
1545 if (ar.exception == null && ar.result != null) {
1546 request.result = ar.result;
1547 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001548 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1549 if (ar.exception instanceof CommandException) {
1550 loge("setAllowedCarriers: CommandException: " + ar.exception);
1551 CommandException.Error error =
1552 ((CommandException) (ar.exception)).getCommandError();
1553 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1554 request.result =
1555 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1556 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001557 } else {
1558 loge("setAllowedCarriers: Unknown exception");
1559 }
1560 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001561 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001562 break;
1563
1564 case CMD_GET_ALLOWED_CARRIERS:
1565 request = (MainThreadRequest) msg.obj;
1566 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001567 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001568 break;
1569
1570 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1571 ar = (AsyncResult) msg.obj;
1572 request = (MainThreadRequest) ar.userObj;
1573 if (ar.exception == null && ar.result != null) {
1574 request.result = ar.result;
1575 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001576 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001577 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001578 if (ar.result == null) {
1579 loge("getAllowedCarriers: Empty response");
1580 } else if (ar.exception instanceof CommandException) {
1581 loge("getAllowedCarriers: CommandException: " +
1582 ar.exception);
1583 } else {
1584 loge("getAllowedCarriers: Unknown exception");
1585 }
1586 }
arunvoddud7401012022-12-15 16:08:12 +00001587 if (request.argument != null) {
1588 // This is for the implementation of carrierRestrictionStatus.
1589 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1590 Consumer<Integer> callback = callbackInfo.getConsumer();
1591 int callerCarrierId = callbackInfo.getCarrierId();
1592 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1593 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1594 CarrierRestrictionRules carrierRestrictionRules =
1595 (CarrierRestrictionRules) ar.result;
1596 int carrierId = -1;
1597 try {
1598 CarrierIdentifier carrierIdentifier =
1599 carrierRestrictionRules.getAllowedCarriers().get(0);
1600 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1601 carrierIdentifier);
1602 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1603 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1604 }
1605 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
1606 if (carrierId != -1 && callerCarrierId == carrierId && lockStatus
1607 == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001608 lockStatus = TelephonyManager
1609 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001610 }
1611 } else {
1612 Rlog.e(LOG_TAG,
1613 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1614 }
1615 callback.accept(lockStatus);
1616 } else {
1617 // This is for the implementation of getAllowedCarriers.
1618 notifyRequester(request);
1619 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001620 break;
1621
Nathan Haroldb3014052017-01-25 15:57:32 -08001622 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1623 ar = (AsyncResult) msg.obj;
1624 request = (MainThreadRequest) ar.userObj;
1625 if (ar.exception == null && ar.result != null) {
1626 request.result = ar.result;
1627 } else {
1628 request.result = new IllegalArgumentException(
1629 "Failed to retrieve Forbidden Plmns");
1630 if (ar.result == null) {
1631 loge("getForbiddenPlmns: Empty response");
1632 } else {
1633 loge("getForbiddenPlmns: Unknown exception");
1634 }
1635 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001636 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001637 break;
1638
1639 case CMD_GET_FORBIDDEN_PLMNS:
1640 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001641 uiccPort = getUiccPortFromRequest(request);
1642 if (uiccPort == null) {
1643 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001644 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001645 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001646 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001647 break;
1648 }
1649 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001650 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001651 if (uiccApp == null) {
1652 loge("getForbiddenPlmns() no app with specified type -- "
1653 + appType);
1654 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001655 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001656 break;
1657 } else {
1658 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1659 + " specified type -- " + appType);
1660 }
1661 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1662 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001663 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001664 break;
1665
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001666 case CMD_SWITCH_SLOTS:
1667 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001668 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001669 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001670 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001671 break;
1672
1673 case EVENT_SWITCH_SLOTS_DONE:
1674 ar = (AsyncResult) msg.obj;
1675 request = (MainThreadRequest) ar.userObj;
1676 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001677 notifyRequester(request);
1678 break;
1679 case CMD_GET_NETWORK_SELECTION_MODE:
1680 request = (MainThreadRequest) msg.obj;
1681 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1682 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1683 break;
1684
1685 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1686 ar = (AsyncResult) msg.obj;
1687 request = (MainThreadRequest) ar.userObj;
1688 if (ar.exception != null) {
1689 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1690 } else {
1691 int mode = ((int[]) ar.result)[0];
1692 if (mode == 0) {
1693 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1694 } else {
1695 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1696 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001697 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001698 notifyRequester(request);
1699 break;
1700 case CMD_GET_CDMA_ROAMING_MODE:
1701 request = (MainThreadRequest) msg.obj;
1702 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1703 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1704 break;
1705 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1706 ar = (AsyncResult) msg.obj;
1707 request = (MainThreadRequest) ar.userObj;
1708 if (ar.exception != null) {
1709 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1710 } else {
1711 request.result = ((int[]) ar.result)[0];
1712 }
1713 notifyRequester(request);
1714 break;
1715 case CMD_SET_CDMA_ROAMING_MODE:
1716 request = (MainThreadRequest) msg.obj;
1717 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1718 int mode = (int) request.argument;
1719 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1720 break;
1721 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1722 ar = (AsyncResult) msg.obj;
1723 request = (MainThreadRequest) ar.userObj;
1724 request.result = ar.exception == null;
1725 notifyRequester(request);
1726 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001727 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1728 request = (MainThreadRequest) msg.obj;
1729 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1730 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1731 break;
1732 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1733 ar = (AsyncResult) msg.obj;
1734 request = (MainThreadRequest) ar.userObj;
1735 if (ar.exception != null) {
1736 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1737 } else {
1738 request.result = ((int[]) ar.result)[0];
1739 }
1740 notifyRequester(request);
1741 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001742 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1743 request = (MainThreadRequest) msg.obj;
1744 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1745 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001746 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1747 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001748 break;
1749 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1750 ar = (AsyncResult) msg.obj;
1751 request = (MainThreadRequest) ar.userObj;
1752 request.result = ar.exception == null;
1753 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001754 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001755 case CMD_GET_ALL_CELL_INFO:
1756 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001757 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001758 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001759 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001760 case EVENT_GET_ALL_CELL_INFO_DONE:
1761 ar = (AsyncResult) msg.obj;
1762 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001763 // If a timeout occurs, the response will be null
1764 request.result = (ar.exception == null && ar.result != null)
1765 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001766 synchronized (request) {
1767 request.notifyAll();
1768 }
1769 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001770 case CMD_REQUEST_CELL_INFO_UPDATE:
1771 request = (MainThreadRequest) msg.obj;
1772 request.phone.requestCellInfoUpdate(request.workSource,
1773 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1774 break;
1775 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1776 ar = (AsyncResult) msg.obj;
1777 request = (MainThreadRequest) ar.userObj;
1778 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1779 try {
1780 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001781 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001782 cb.onError(
1783 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1784 ar.exception.getClass().getName(),
1785 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001786 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001787 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001788 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001789 } else {
1790 // use the result as returned
1791 cb.onCellInfo((List<CellInfo>) ar.result);
1792 }
1793 } catch (RemoteException re) {
1794 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1795 }
1796 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001797 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001798 request = (MainThreadRequest) msg.obj;
1799 WorkSource ws = (WorkSource) request.argument;
1800 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001801 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001802 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001803 }
1804 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001805 ar = (AsyncResult) msg.obj;
1806 request = (MainThreadRequest) ar.userObj;
1807 if (ar.exception == null) {
1808 request.result = ar.result;
1809 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001810 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001811 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001812 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001813 }
1814
1815 synchronized (request) {
1816 request.notifyAll();
1817 }
1818 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001819 }
chen xu6dac5ab2018-10-26 17:39:23 -07001820 case CMD_MODEM_REBOOT:
1821 request = (MainThreadRequest) msg.obj;
1822 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001823 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001824 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001825 case EVENT_CMD_MODEM_REBOOT_DONE:
1826 handleNullReturnEvent(msg, "rebootModem");
1827 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001828 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001829 request = (MainThreadRequest) msg.obj;
1830 boolean enable = (boolean) request.argument;
1831 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001832 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001833 PhoneConfigurationManager.getInstance()
1834 .enablePhone(request.phone, enable, onCompleted);
1835 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001836 }
Michele Berionne5e411512020-11-13 02:36:59 +00001837 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001838 ar = (AsyncResult) msg.obj;
1839 request = (MainThreadRequest) ar.userObj;
1840 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001841 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001842 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001843 if ((boolean) request.result) {
1844 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1845 updateModemStateMetrics();
1846 } else {
1847 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1848 + ar.exception);
1849 }
1850 notifyRequester(request);
1851 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001852 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001853 case CMD_GET_MODEM_STATUS:
1854 request = (MainThreadRequest) msg.obj;
1855 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1856 PhoneConfigurationManager.getInstance()
1857 .getPhoneStatusFromModem(request.phone, onCompleted);
1858 break;
1859 case EVENT_GET_MODEM_STATUS_DONE:
1860 ar = (AsyncResult) msg.obj;
1861 request = (MainThreadRequest) ar.userObj;
1862 int id = request.phone.getPhoneId();
1863 if (ar.exception == null && ar.result != null) {
1864 request.result = ar.result;
1865 //update the cache as modem status has changed
1866 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1867 (boolean) request.result);
1868 } else {
1869 // Return true if modem status cannot be retrieved. For most cases,
1870 // modem status is on. And for older version modems, GET_MODEM_STATUS
1871 // and disable modem are not supported. Modem is always on.
1872 // TODO: this should be fixed in R to support a third
1873 // status UNKNOWN b/131631629
1874 request.result = true;
1875 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1876 + ar.exception);
1877 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001878 notifyRequester(request);
1879 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001880 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1881 request = (MainThreadRequest) msg.obj;
1882 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1883 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1884 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1885 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1886 break;
1887 }
1888 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1889 ar = (AsyncResult) msg.obj;
1890 request = (MainThreadRequest) ar.userObj;
1891 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1892 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1893 args.second.accept(ar.exception == null);
1894 notifyRequester(request);
1895 break;
1896 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001897 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1898 request = (MainThreadRequest) msg.obj;
1899 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1900 Phone phone = getPhoneFromRequest(request);
1901 if (phone != null) {
1902 phone.getSystemSelectionChannels(onCompleted);
1903 } else {
1904 loge("getSystemSelectionChannels: No phone object");
1905 request.result = new ArrayList<RadioAccessSpecifier>();
1906 notifyRequester(request);
1907 }
1908 break;
1909 }
1910 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1911 ar = (AsyncResult) msg.obj;
1912 request = (MainThreadRequest) ar.userObj;
1913 if (ar.exception == null && ar.result != null) {
1914 request.result = ar.result;
1915 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001916 request.result = new IllegalStateException(
1917 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001918 if (ar.result == null) {
1919 loge("getSystemSelectionChannels: Empty response");
1920 } else {
1921 loge("getSystemSelectionChannels: Unknown exception");
1922 }
1923 }
1924 notifyRequester(request);
1925 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001926 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1927 ar = (AsyncResult) msg.obj;
1928 request = (MainThreadRequest) ar.userObj;
1929 if (ar.exception == null && ar.result != null) {
1930 request.result = ar.result;
1931 } else {
1932 request.result = -1;
1933 loge("Failed to set Forbidden Plmns");
1934 if (ar.result == null) {
1935 loge("setForbidenPlmns: Empty response");
1936 } else if (ar.exception != null) {
1937 loge("setForbiddenPlmns: Exception: " + ar.exception);
1938 request.result = -1;
1939 } else {
1940 loge("setForbiddenPlmns: Unknown exception");
1941 }
1942 }
1943 notifyRequester(request);
1944 break;
1945 case CMD_SET_FORBIDDEN_PLMNS:
1946 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001947 uiccPort = getUiccPortFromRequest(request);
1948 if (uiccPort == null) {
1949 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001950 request.result = -1;
1951 notifyRequester(request);
1952 break;
1953 }
1954 Pair<Integer, List<String>> setFplmnsArgs =
1955 (Pair<Integer, List<String>>) request.argument;
1956 appType = setFplmnsArgs.first;
1957 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001958 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001959 if (uiccApp == null) {
1960 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1961 request.result = -1;
1962 loge("Failed to get UICC App");
1963 notifyRequester(request);
1964 } else {
1965 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1966 ((SIMRecords) uiccApp.getIccRecords())
1967 .setForbiddenPlmns(onCompleted, fplmns);
1968 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001969 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001970 case CMD_ERASE_MODEM_CONFIG:
1971 request = (MainThreadRequest) msg.obj;
1972 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1973 defaultPhone.eraseModemConfig(onCompleted);
1974 break;
1975 case EVENT_ERASE_MODEM_CONFIG_DONE:
1976 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001977 break;
zoey chene02881a2019-12-30 16:11:23 +08001978
Kai Shif70f46f2021-03-03 13:59:46 -08001979 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1980 request = (MainThreadRequest) msg.obj;
1981 request.result = defaultPhone.eraseDataInSharedPreferences();
1982 notifyRequester(request);
1983 break;
1984
zoey chene02881a2019-12-30 16:11:23 +08001985 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1986 request = (MainThreadRequest) msg.obj;
1987 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1988 Pair<String, String> changed = (Pair<String, String>) request.argument;
1989 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1990 changed.first, changed.second, onCompleted);
1991 break;
1992 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1993 ar = (AsyncResult) msg.obj;
1994 request = (MainThreadRequest) ar.userObj;
1995 if (ar.exception == null) {
1996 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001997 // If the operation is successful, update the PIN storage
1998 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1999 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00002000 UiccController.getInstance().getPinStorage()
2001 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08002002 } else {
2003 request.result = msg.arg1;
2004 }
2005 notifyRequester(request);
2006 break;
2007
Michele Berionne5e411512020-11-13 02:36:59 +00002008 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08002009 request = (MainThreadRequest) msg.obj;
2010 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
2011 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2012 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2013 enabled.first, enabled.second, onCompleted);
2014 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002015 }
zoey chene02881a2019-12-30 16:11:23 +08002016 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2017 ar = (AsyncResult) msg.obj;
2018 request = (MainThreadRequest) ar.userObj;
2019 if (ar.exception == null) {
2020 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002021 // If the operation is successful, update the PIN storage
2022 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2023 int phoneId = getPhoneFromRequest(request).getPhoneId();
2024 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002025 UiccController.getInstance().getPinStorage()
2026 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002027 } else {
2028 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2029 }
zoey chene02881a2019-12-30 16:11:23 +08002030 } else {
2031 request.result = msg.arg1;
2032 }
Michele Berionne5e411512020-11-13 02:36:59 +00002033
2034
zoey chene02881a2019-12-30 16:11:23 +08002035 notifyRequester(request);
2036 break;
2037
Peter Wangdafb9ac2020-01-15 14:13:38 -08002038 case MSG_NOTIFY_USER_ACTIVITY:
2039 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002040 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002041 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2042 getDefaultPhone().getContext().sendBroadcastAsUser(
2043 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2044 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002045
2046 case CMD_SET_DATA_THROTTLING: {
2047 request = (MainThreadRequest) msg.obj;
2048 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2049 DataThrottlingRequest dataThrottlingRequest =
2050 (DataThrottlingRequest) request.argument;
2051 Phone phone = getPhoneFromRequest(request);
2052 if (phone != null) {
2053 phone.setDataThrottling(onCompleted,
2054 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2055 dataThrottlingRequest.getCompletionDurationMillis());
2056 } else {
2057 loge("setDataThrottling: No phone object");
2058 request.result =
2059 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2060 notifyRequester(request);
2061 }
2062
2063 break;
2064 }
2065 case EVENT_SET_DATA_THROTTLING_DONE:
2066 ar = (AsyncResult) msg.obj;
2067 request = (MainThreadRequest) ar.userObj;
2068
2069 if (ar.exception == null) {
2070 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2071 } else if (ar.exception instanceof CommandException) {
2072 loge("setDataThrottling: CommandException: " + ar.exception);
2073 CommandException.Error error =
2074 ((CommandException) (ar.exception)).getCommandError();
2075
2076 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2077 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002078 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002079 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2080 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002081 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2082 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002083 } else {
2084 request.result =
2085 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2086 }
2087 } else {
2088 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2089 }
2090 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2091 notifyRequester(request);
2092 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002093
2094 case CMD_SET_SIM_POWER: {
2095 request = (MainThreadRequest) msg.obj;
2096 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2097 request = (MainThreadRequest) msg.obj;
2098 int stateToSet =
2099 ((Pair<Integer, IIntegerConsumer>)
2100 request.argument).first;
2101 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2102 break;
2103 }
2104 case EVENT_SET_SIM_POWER_DONE: {
2105 ar = (AsyncResult) msg.obj;
2106 request = (MainThreadRequest) ar.userObj;
2107 IIntegerConsumer callback =
2108 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2109 if (ar.exception != null) {
2110 loge("setSimPower exception: " + ar.exception);
2111 int errorCode = TelephonyManager.CallForwardingInfoCallback
2112 .RESULT_ERROR_UNKNOWN;
2113 if (ar.exception instanceof CommandException) {
2114 CommandException.Error error =
2115 ((CommandException) (ar.exception)).getCommandError();
2116 if (error == CommandException.Error.SIM_ERR) {
2117 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2118 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2119 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2120 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2121 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2122 } else {
2123 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2124 }
2125 }
2126 try {
2127 callback.accept(errorCode);
2128 } catch (RemoteException e) {
2129 // Ignore if the remote process is no longer available to call back.
2130 Log.w(LOG_TAG, "setSimPower: callback not available.");
2131 }
2132 } else {
2133 try {
2134 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2135 } catch (RemoteException e) {
2136 // Ignore if the remote process is no longer available to call back.
2137 Log.w(LOG_TAG, "setSimPower: callback not available.");
2138 }
2139 }
2140 break;
2141 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002142 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2143 request = (MainThreadRequest) msg.obj;
2144
2145 final Phone phone = getPhoneFromRequest(request);
2146 if (phone == null || phone.getServiceStateTracker() == null) {
2147 request.result = new IllegalStateException("Phone or SST is null");
2148 notifyRequester(request);
2149 break;
2150 }
2151
2152 Pair<Integer, SignalStrengthUpdateRequest> pair =
2153 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2154 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2155 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002156 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002157 request.subId, pair.first /*callingUid*/,
2158 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002159 break;
2160 }
2161 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2162 ar = (AsyncResult) msg.obj;
2163 request = (MainThreadRequest) ar.userObj;
2164 // request.result will be the exception of ar if present, true otherwise.
2165 // Be cautious not to leave result null which will wait() forever
2166 request.result = ar.exception != null ? ar.exception : true;
2167 notifyRequester(request);
2168 break;
2169 }
2170 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2171 request = (MainThreadRequest) msg.obj;
2172
2173 Phone phone = getPhoneFromRequest(request);
2174 if (phone == null || phone.getServiceStateTracker() == null) {
2175 request.result = new IllegalStateException("Phone or SST is null");
2176 notifyRequester(request);
2177 break;
2178 }
2179
2180 Pair<Integer, SignalStrengthUpdateRequest> pair =
2181 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2182 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2183 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002184 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002185 request.subId, pair.first /*callingUid*/,
2186 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002187 break;
2188 }
2189 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2190 ar = (AsyncResult) msg.obj;
2191 request = (MainThreadRequest) ar.userObj;
2192 request.result = ar.exception != null ? ar.exception : true;
2193 notifyRequester(request);
2194 break;
2195 }
Jordan Liu109698e2020-11-24 14:50:34 -08002196
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002197 case CMD_GET_SLICING_CONFIG: {
2198 request = (MainThreadRequest) msg.obj;
2199 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2200 request.phone.getSlicingConfig(onCompleted);
2201 break;
2202 }
2203 case EVENT_GET_SLICING_CONFIG_DONE: {
2204 ar = (AsyncResult) msg.obj;
2205 request = (MainThreadRequest) ar.userObj;
2206 ResultReceiver result = (ResultReceiver) request.argument;
2207
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002208 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002209 Bundle bundle = new Bundle();
2210 int resultCode = 0;
2211 if (ar.exception != null) {
2212 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2213 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002214 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002215 } else if (ar.result == null) {
2216 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002217 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002218 } else {
2219 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002220 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2221 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002222 }
2223
2224 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002225 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002226 }
2227 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2228 result.send(resultCode, bundle);
2229 notifyRequester(request);
2230 break;
2231 }
2232
Sarah Chin71b3a852022-09-28 15:54:19 -07002233 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002234 request = (MainThreadRequest) msg.obj;
2235 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002236 PurchasePremiumCapabilityArgument arg =
2237 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chincc5446f2023-10-23 17:57:19 -07002238 SlicePurchaseController.getInstance(request.phone, mFeatureFlags)
2239 .purchasePremiumCapability(arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002240 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002241 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002242
Sarah Chin71b3a852022-09-28 15:54:19 -07002243 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002244 ar = (AsyncResult) msg.obj;
2245 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002246 PurchasePremiumCapabilityArgument arg =
2247 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002248 try {
2249 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002250 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002251 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002252 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chinff8b1802023-04-11 14:22:14 -07002253 + ", result="
Sarah Chin2ec39f62022-08-31 17:03:26 -07002254 + TelephonyManager.convertPurchaseResultToString(result));
2255 } catch (RemoteException e) {
2256 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002257 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002258 + " failed: " + e;
2259 if (DBG) log(logStr);
2260 AnomalyReporter.reportAnomaly(
2261 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2262 }
2263 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002264 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002265
Michele Berionne5e411512020-11-13 02:36:59 +00002266 case CMD_PREPARE_UNATTENDED_REBOOT:
2267 request = (MainThreadRequest) msg.obj;
2268 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002269 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002270 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002271 notifyRequester(request);
2272 break;
2273
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002274 default:
2275 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2276 break;
2277 }
2278 }
Jake Hambye994d462014-02-03 13:10:13 -08002279
Pengquan Menga1bb6272018-09-06 09:59:22 -07002280 private void notifyRequester(MainThreadRequest request) {
2281 synchronized (request) {
2282 request.notifyAll();
2283 }
2284 }
2285
Jake Hambye994d462014-02-03 13:10:13 -08002286 private void handleNullReturnEvent(Message msg, String command) {
2287 AsyncResult ar = (AsyncResult) msg.obj;
2288 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2289 if (ar.exception == null) {
2290 request.result = true;
2291 } else {
2292 request.result = false;
2293 if (ar.exception instanceof CommandException) {
2294 loge(command + ": CommandException: " + ar.exception);
2295 } else {
2296 loge(command + ": Unknown exception");
2297 }
2298 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002299 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002300 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002301 }
2302
2303 /**
2304 * Posts the specified command to be executed on the main thread,
2305 * waits for the request to complete, and returns the result.
2306 * @see #sendRequestAsync
2307 */
2308 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002309 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2310 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002311 }
2312
2313 /**
2314 * Posts the specified command to be executed on the main thread,
2315 * waits for the request to complete, and returns the result.
2316 * @see #sendRequestAsync
2317 */
2318 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2319 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002320 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002321 }
2322
2323 /**
2324 * Posts the specified command to be executed on the main thread,
2325 * waits for the request to complete, and returns the result.
2326 * @see #sendRequestAsync
2327 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002328 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002329 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2330 }
2331
2332 /**
2333 * Posts the specified command to be executed on the main thread,
2334 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2335 * if not timeout or null otherwise.
2336 * @see #sendRequestAsync
2337 */
2338 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2339 long timeoutInMs) {
2340 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002341 }
2342
2343 /**
2344 * Posts the specified command to be executed on the main thread,
2345 * waits for the request to complete, and returns the result.
2346 * @see #sendRequestAsync
2347 */
Nathan Harold92bed182018-10-12 18:16:49 -07002348 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002349 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002350 }
2351
2352 /**
2353 * Posts the specified command to be executed on the main thread,
2354 * waits for the request to complete, and returns the result.
2355 * @see #sendRequestAsync
2356 */
2357 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002358 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2359 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002360 }
2361
2362 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002363 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2364 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2365 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002366 * @see #sendRequestAsync
2367 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002368 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2369 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002370 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2371 throw new RuntimeException("This method will deadlock if called from the main thread.");
2372 }
2373
Nathan Harold92bed182018-10-12 18:16:49 -07002374 MainThreadRequest request = null;
2375 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2376 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2377 } else if (phone != null) {
2378 request = new MainThreadRequest(argument, phone, workSource);
2379 } else {
2380 request = new MainThreadRequest(argument, subId, workSource);
2381 }
2382
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002383 Message msg = mMainThreadHandler.obtainMessage(command, request);
2384 msg.sendToTarget();
2385
Rambo Wang0f050d82021-02-12 11:43:36 -08002386
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002387 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002388 if (timeoutInMs >= 0) {
2389 // Wait for at least timeoutInMs before returning null request result
2390 long now = SystemClock.elapsedRealtime();
2391 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002392 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002393 try {
2394 request.wait(deadline - now);
2395 } catch (InterruptedException e) {
2396 // Do nothing, go back and check if request is completed or timeout
2397 } finally {
2398 now = SystemClock.elapsedRealtime();
2399 }
2400 }
2401 } else {
2402 // Wait for the request to complete
2403 while (request.result == null) {
2404 try {
2405 request.wait();
2406 } catch (InterruptedException e) {
2407 // Do nothing, go back and wait until the request is complete
2408 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002409 }
2410 }
2411 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002412 if (request.result == null) {
2413 Log.wtf(LOG_TAG,
2414 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2415 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002416 return request.result;
2417 }
2418
2419 /**
2420 * Asynchronous ("fire and forget") version of sendRequest():
2421 * Posts the specified command to be executed on the main thread, and
2422 * returns immediately.
2423 * @see #sendRequest
2424 */
2425 private void sendRequestAsync(int command) {
2426 mMainThreadHandler.sendEmptyMessage(command);
2427 }
2428
2429 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002430 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002431 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002432 */
2433 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002434 sendRequestAsync(command, argument, null, null);
2435 }
2436
2437 /**
2438 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2439 * @see {@link #sendRequest(int,Object)}
2440 */
2441 private void sendRequestAsync(
2442 int command, Object argument, Phone phone, WorkSource workSource) {
2443 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002444 Message msg = mMainThreadHandler.obtainMessage(command, request);
2445 msg.sendToTarget();
2446 }
2447
2448 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002449 * Initialize the singleton PhoneInterfaceManager instance.
2450 * This is only done once, at startup, from PhoneApp.onCreate().
2451 */
Sarah Chincc5446f2023-10-23 17:57:19 -07002452 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002453 synchronized (PhoneInterfaceManager.class) {
2454 if (sInstance == null) {
Sarah Chincc5446f2023-10-23 17:57:19 -07002455 sInstance = new PhoneInterfaceManager(app, featureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002456 } else {
2457 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2458 }
2459 return sInstance;
2460 }
2461 }
2462
2463 /** Private constructor; @see init() */
Sarah Chincc5446f2023-10-23 17:57:19 -07002464 private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002465 mApp = app;
Sarah Chincc5446f2023-10-23 17:57:19 -07002466 mFeatureFlags = featureFlags;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -08002467 mTelecomFeatureFlags = new com.android.server.telecom.flags.FeatureFlagsImpl();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002468 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002469 mImsResolver = ImsResolver.getInstance();
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +00002470 mSatelliteController = SatelliteController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002471 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002472 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2473 mMainThreadHandler = new MainThreadHandler();
Sarah Chin4beb2b72023-02-14 14:47:54 -08002474 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002475 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002476 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002477 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002478 mNotifyUserActivity = new AtomicBoolean(false);
joonhunshin4ac60942023-11-15 15:23:39 +00002479 mPackageManager = app.getPackageManager();
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -08002480 mSatelliteAccessController = SatelliteAccessController.getOrCreateInstance(
2481 getDefaultPhone().getContext(), featureFlags);
Tyler Gunn64144d92022-03-17 14:16:41 -07002482 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002483 publish();
arunvoddud7401012022-12-15 16:08:12 +00002484 CarrierAllowListInfo.loadInstance(mApp);
Hyosun Kim240214a2023-11-02 13:30:15 +00002485
2486 // Create the SatelliteEntitlementController singleton, for using the get the
2487 // entitlementStatus for satellite service.
2488 SatelliteEntitlementController.make(mApp, mFeatureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002489 }
2490
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002491 @VisibleForTesting
2492 public SharedPreferences getSharedPreferences() {
2493 return mTelephonySharedPreferences;
2494 }
2495
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002496 /**
2497 * Get the default phone for this device.
2498 */
2499 @VisibleForTesting
2500 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002501 Phone thePhone = getPhone(getDefaultSubscription());
2502 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2503 }
2504
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002505 private void publish() {
2506 if (DBG) log("publish: " + this);
2507
Peter Wangc035ce42020-01-08 21:00:22 -08002508 TelephonyFrameworkInitializer
2509 .getTelephonyServiceManager()
2510 .getTelephonyServiceRegisterer()
2511 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002512 }
2513
Stuart Scott584921c2015-01-15 17:10:34 -08002514 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002515 if (request.phone != null) {
2516 return request.phone;
2517 } else {
2518 return getPhoneFromSubId(request.subId);
2519 }
2520 }
2521
2522 private Phone getPhoneFromSubId(int subId) {
2523 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2524 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002525 }
2526
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002527 /**
2528 * Get phone object associated with a subscription.
2529 * Return default phone if phone object associated with subscription is null
2530 * @param subId - subscriptionId
2531 * @return phone object associated with a subscription or default phone if null.
2532 */
Ling Mac28f0212023-03-24 16:07:15 -07002533 private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) {
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002534 Phone phone = getPhoneFromSubId(subId);
2535 if (phone == null) {
Ling Mac28f0212023-03-24 16:07:15 -07002536 loge("Called with invalid subId: " + subId + ". Retrying with default phone.");
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002537 phone = getDefaultPhone();
2538 }
2539 return phone;
2540 }
2541
Rambo Wange53e07d2022-05-10 13:01:13 -07002542 @Nullable
2543 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002544 Phone phone = getPhoneFromRequest(request);
2545 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002546 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002547 }
2548
Ling Mac28f0212023-03-24 16:07:15 -07002549 /**
2550 * @param subId The sub Id that associates the phone. If the device has no active SIM, passing
2551 * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <=
2552 * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}.
2553 * @return The Phone associated the sub Id
2554 */
2555 private @Nullable Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002556 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002557 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002558
Kai Shif70f46f2021-03-03 13:59:46 -08002559 private void sendEraseModemConfig(@NonNull Phone phone) {
2560 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2561 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2562 }
2563
2564 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2565 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2566 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002567 }
2568
Peter Wang44b186e2020-01-13 23:33:09 -08002569 private boolean isImsAvailableOnDevice() {
2570 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2571 if (pm == null) {
2572 // For some reason package manger is not available.. This will fail internally anyway,
2573 // so do not throw error and allow.
2574 return true;
2575 }
2576 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2577 }
2578
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002579 public void dial(String number) {
joonhunshin4ac60942023-11-15 15:23:39 +00002580 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2581 PackageManager.FEATURE_TELEPHONY_CALLING, "dial");
2582
Wink Savilleadd7cc52014-09-08 14:23:09 -07002583 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002584 }
2585
Wink Savilleb564aae2014-10-23 10:18:09 -07002586 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002587 if (DBG) log("dial: " + number);
2588 // No permission check needed here: This is just a wrapper around the
2589 // ACTION_DIAL intent, which is available to any app since it puts up
2590 // the UI before it does anything.
2591
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002592 final long identity = Binder.clearCallingIdentity();
2593 try {
2594 String url = createTelUrl(number);
2595 if (url == null) {
2596 return;
2597 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002598
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002599 // PENDING: should we just silently fail if phone is offhook or ringing?
2600 PhoneConstants.State state = mCM.getState(subId);
2601 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2602 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2603 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2604 mApp.startActivity(intent);
2605 }
2606 } finally {
2607 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002608 }
2609 }
2610
2611 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002612 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002613 }
2614
Wink Savilleb564aae2014-10-23 10:18:09 -07002615 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002616 if (DBG) log("call: " + number);
2617
2618 // This is just a wrapper around the ACTION_CALL intent, but we still
2619 // need to do a permission check since we're calling startActivity()
2620 // from the context of the phone app.
2621 enforceCallPermission();
2622
Jordan Liu1617b712019-07-10 15:06:26 -07002623 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002624 != AppOpsManager.MODE_ALLOWED) {
2625 return;
2626 }
2627
joonhunshin4ac60942023-11-15 15:23:39 +00002628 enforceTelephonyFeatureWithException(callingPackage,
2629 PackageManager.FEATURE_TELEPHONY_CALLING, "call");
2630
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002631 final long identity = Binder.clearCallingIdentity();
2632 try {
2633 String url = createTelUrl(number);
2634 if (url == null) {
2635 return;
2636 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002637
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002638 boolean isValid = false;
2639 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2640 if (slist != null) {
2641 for (SubscriptionInfo subInfoRecord : slist) {
2642 if (subInfoRecord.getSubscriptionId() == subId) {
2643 isValid = true;
2644 break;
2645 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002646 }
Wink Saville08874612014-08-31 19:19:58 -07002647 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002648 if (!isValid) {
2649 return;
2650 }
Wink Saville08874612014-08-31 19:19:58 -07002651
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002652 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2653 intent.putExtra(SUBSCRIPTION_KEY, subId);
2654 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2655 mApp.startActivity(intent);
2656 } finally {
2657 Binder.restoreCallingIdentity(identity);
2658 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002659 }
2660
Wink Savilleb564aae2014-10-23 10:18:09 -07002661 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002662 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002663 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2664 }
2665
Wink Savilleb564aae2014-10-23 10:18:09 -07002666 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002667 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002668 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2669 }
2670
Wink Savilleb564aae2014-10-23 10:18:09 -07002671 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002672 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002673
joonhunshin4ac60942023-11-15 15:23:39 +00002674 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2675 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
2676 "supplyPinReportResultForSubscriber");
2677
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002678 final long identity = Binder.clearCallingIdentity();
2679 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002680 Phone phone = getPhone(subId);
2681 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002682 checkSimPin.start();
2683 return checkSimPin.unlockSim(null, pin);
2684 } finally {
2685 Binder.restoreCallingIdentity(identity);
2686 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002687 }
2688
Wink Savilleb564aae2014-10-23 10:18:09 -07002689 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002690 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002691
joonhunshin4ac60942023-11-15 15:23:39 +00002692 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2693 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "supplyPukForSubscriber");
2694
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002695 final long identity = Binder.clearCallingIdentity();
2696 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002697 Phone phone = getPhone(subId);
2698 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002699 checkSimPuk.start();
2700 return checkSimPuk.unlockSim(puk, pin);
2701 } finally {
2702 Binder.restoreCallingIdentity(identity);
2703 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002704 }
2705
2706 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002707 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002708 * a synchronous one.
2709 */
2710 private static class UnlockSim extends Thread {
2711
2712 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002713 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002714
2715 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002716 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2717 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002718
2719 // For replies from SimCard interface
2720 private Handler mHandler;
2721
2722 // For async handler to identify request type
2723 private static final int SUPPLY_PIN_COMPLETE = 100;
2724
Michele Berionne5e411512020-11-13 02:36:59 +00002725 UnlockSim(int phoneId, IccCard simCard) {
2726 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002727 mSimCard = simCard;
2728 }
2729
2730 @Override
2731 public void run() {
2732 Looper.prepare();
2733 synchronized (UnlockSim.this) {
2734 mHandler = new Handler() {
2735 @Override
2736 public void handleMessage(Message msg) {
2737 AsyncResult ar = (AsyncResult) msg.obj;
2738 switch (msg.what) {
2739 case SUPPLY_PIN_COMPLETE:
2740 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2741 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002742 mRetryCount = msg.arg1;
2743 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002744 CommandException.Error error = null;
2745 if (ar.exception instanceof CommandException) {
2746 error = ((CommandException) (ar.exception))
2747 .getCommandError();
2748 }
2749 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07002750 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002751 } else if (error == CommandException.Error.ABORTED) {
2752 /* When UiccCardApp dispose, handle message and return
2753 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08002754 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002755 } else {
2756 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2757 }
2758 } else {
2759 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2760 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002761 mDone = true;
2762 UnlockSim.this.notifyAll();
2763 }
2764 break;
2765 }
2766 }
2767 };
2768 UnlockSim.this.notifyAll();
2769 }
2770 Looper.loop();
2771 }
2772
2773 /*
2774 * Use PIN or PUK to unlock SIM card
2775 *
2776 * If PUK is null, unlock SIM card with PIN
2777 *
2778 * If PUK is not null, unlock SIM card with PUK and set PIN code
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302779 *
2780 * Besides, since it is reused in class level, the thread's looper will be stopped to avoid
2781 * its thread leak.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002782 */
Wink Saville9de0f752013-10-22 19:04:03 -07002783 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002784
2785 while (mHandler == null) {
2786 try {
2787 wait();
2788 } catch (InterruptedException e) {
2789 Thread.currentThread().interrupt();
2790 }
2791 }
2792 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2793
2794 if (puk == null) {
2795 mSimCard.supplyPin(pin, callback);
2796 } else {
2797 mSimCard.supplyPuk(puk, pin, callback);
2798 }
2799
2800 while (!mDone) {
2801 try {
2802 Log.d(LOG_TAG, "wait for done");
2803 wait();
2804 } catch (InterruptedException e) {
2805 // Restore the interrupted status
2806 Thread.currentThread().interrupt();
2807 }
2808 }
2809 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002810 int[] resultArray = new int[2];
2811 resultArray[0] = mResult;
2812 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002813
2814 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002815 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002816 }
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302817 // This instance is no longer reused, so quit its thread's looper.
2818 mHandler.getLooper().quitSafely();
Michele Berionne5e411512020-11-13 02:36:59 +00002819
Wink Saville9de0f752013-10-22 19:04:03 -07002820 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002821 }
2822 }
2823
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002824 /**
2825 * This method has been removed due to privacy and stability concerns.
2826 */
2827 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002828 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002829 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2830 return;
Wink Saville36469e72014-06-11 15:17:00 -07002831 }
2832
Nathan Harold1f889d82020-06-04 17:05:26 -07002833 @Override
2834 public void updateServiceLocationWithPackageName(String callingPackage) {
2835 mApp.getSystemService(AppOpsManager.class)
2836 .checkPackage(Binder.getCallingUid(), callingPackage);
2837
Nathan Haroldf096d982020-11-18 17:18:06 -08002838 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002839 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2840 // Callers targeting S have no business invoking this method.
2841 return;
2842 }
2843
2844 LocationAccessPolicy.LocationPermissionResult locationResult =
2845 LocationAccessPolicy.checkLocationPermission(mApp,
2846 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2847 .setCallingPackage(callingPackage)
2848 .setCallingFeatureId(null)
2849 .setCallingPid(Binder.getCallingPid())
2850 .setCallingUid(Binder.getCallingUid())
2851 .setMethod("updateServiceLocation")
2852 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2853 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2854 .build());
2855 // Apps that lack location permission have no business calling this method;
2856 // however, because no permission was declared in the public API, denials must
2857 // all be "soft".
2858 switch (locationResult) {
2859 case DENIED_HARD: /* fall through */
2860 case DENIED_SOFT:
2861 return;
2862 }
2863
2864 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002865 final long identity = Binder.clearCallingIdentity();
2866 try {
Ling Mac28f0212023-03-24 16:07:15 -07002867 getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002868 } finally {
2869 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002870 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002871 }
2872
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002873 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002874 @Override
2875 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002876 return isRadioOnWithFeature(callingPackage, null);
2877 }
2878
2879
2880 @Override
2881 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2882 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2883 callingFeatureId);
2884 }
2885
2886 @Deprecated
2887 @Override
2888 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2889 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002890 }
2891
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002892 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002893 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2894 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002895 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002896 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002897 return false;
2898 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002899
joonhunshin4ac60942023-11-15 15:23:39 +00002900 enforceTelephonyFeatureWithException(callingPackage,
2901 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isRadioOnWithFeature");
2902
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002903 final long identity = Binder.clearCallingIdentity();
2904 try {
2905 return isRadioOnForSubscriber(subId);
2906 } finally {
2907 Binder.restoreCallingIdentity(identity);
2908 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002909 }
2910
2911 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002912 final long identity = Binder.clearCallingIdentity();
2913 try {
2914 final Phone phone = getPhone(subId);
2915 if (phone != null) {
2916 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2917 } else {
2918 return false;
2919 }
2920 } finally {
2921 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002922 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002923 }
2924
2925 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002926 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002927 }
Wink Saville36469e72014-06-11 15:17:00 -07002928
Wink Savilleb564aae2014-10-23 10:18:09 -07002929 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002930 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002931
joonhunshin4ac60942023-11-15 15:23:39 +00002932 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2933 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "toggleRadioOnOffForSubscriber");
2934
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002935 final long identity = Binder.clearCallingIdentity();
2936 try {
2937 final Phone phone = getPhone(subId);
2938 if (phone != null) {
2939 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2940 }
2941 } finally {
2942 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002943 }
Wink Saville36469e72014-06-11 15:17:00 -07002944 }
2945
2946 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002947 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002948 }
2949
Wink Savilleb564aae2014-10-23 10:18:09 -07002950 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002951 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002952
2953 final long identity = Binder.clearCallingIdentity();
2954 try {
2955 final Phone phone = getPhone(subId);
2956 if (phone == null) {
2957 return false;
2958 }
2959 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2960 toggleRadioOnOffForSubscriber(subId);
2961 }
2962 return true;
2963 } finally {
2964 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002965 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002966 }
Wink Saville36469e72014-06-11 15:17:00 -07002967
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002968 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002969 enforceReadPrivilegedPermission("needMobileRadioShutdown");
joonhunshin4ac60942023-11-15 15:23:39 +00002970
2971 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2972 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needMobileRadioShutdown");
2973
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002974 /*
2975 * If any of the Radios are available, it will need to be
2976 * shutdown. So return true if any Radio is available.
2977 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002978 final long identity = Binder.clearCallingIdentity();
2979 try {
2980 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2981 Phone phone = PhoneFactory.getPhone(i);
2982 if (phone != null && phone.isRadioAvailable()) return true;
2983 }
2984 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2985 return false;
2986 } finally {
2987 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002988 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002989 }
2990
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002991 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002992 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002993 enforceModifyPermission();
2994
joonhunshin4ac60942023-11-15 15:23:39 +00002995 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2996 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "shutdownMobileRadios");
2997
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002998 final long identity = Binder.clearCallingIdentity();
2999 try {
3000 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3001 logv("Shutting down Phone " + i);
3002 shutdownRadioUsingPhoneId(i);
3003 }
3004 } finally {
3005 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003006 }
3007 }
3008
3009 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003010 Phone phone = PhoneFactory.getPhone(phoneId);
3011 if (phone != null && phone.isRadioAvailable()) {
3012 phone.shutdownRadio();
3013 }
3014 }
3015
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003016 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07003017 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003018
Ling Ma83dc5ea2023-01-12 15:06:04 -08003019 if (!turnOn) {
3020 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
3021 }
3022
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003023 final long identity = Binder.clearCallingIdentity();
3024 try {
3025 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
3026 if (defaultPhone != null) {
3027 defaultPhone.setRadioPower(turnOn);
3028 return true;
3029 } else {
3030 loge("There's no default phone.");
3031 return false;
3032 }
3033 } finally {
3034 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07003035 }
Wink Saville36469e72014-06-11 15:17:00 -07003036 }
3037
Wink Savilleb564aae2014-10-23 10:18:09 -07003038 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003039 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003040
Ling Ma83dc5ea2023-01-12 15:06:04 -08003041 if (!turnOn) {
3042 log("setRadioPowerForSubscriber off: subId=" + subId
3043 + ",callingPackage=" + getCurrentPackageName());
3044 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003045 final long identity = Binder.clearCallingIdentity();
3046 try {
3047 final Phone phone = getPhone(subId);
3048 if (phone != null) {
3049 phone.setRadioPower(turnOn);
3050 return true;
3051 } else {
3052 return false;
3053 }
3054 } finally {
3055 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003056 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003057 }
3058
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003059 /**
3060 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3061 * no reason to power it off. When any of the voters want to power it off, it will be turned
3062 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3063 * powering it off, and these radio off votes will be cleared.
3064 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3065 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3066 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3067 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3068 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3069 * check its vote.
3070 *
3071 * @param subId The subscription ID.
3072 * @param reason The reason for powering off radio.
3073 * @return true on success and false on failure.
3074 */
3075 public boolean requestRadioPowerOffForReason(int subId,
3076 @TelephonyManager.RadioPowerReason int reason) {
3077 enforceModifyPermission();
3078
joonhunshin4ac60942023-11-15 15:23:39 +00003079 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3080 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestRadioPowerOffForReason");
3081
Ling Ma83dc5ea2023-01-12 15:06:04 -08003082 log("requestRadioPowerOffForReason: subId=" + subId
3083 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003084 final long identity = Binder.clearCallingIdentity();
3085 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003086 boolean result = false;
3087 for (Phone phone : PhoneFactory.getPhones()) {
3088 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003089 phone.setRadioPowerForReason(false, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003090 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003091 if (!result) {
3092 loge("requestRadioPowerOffForReason: no phone exists");
3093 }
3094 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003095 } finally {
3096 Binder.restoreCallingIdentity(identity);
3097 }
3098 }
3099
3100 /**
3101 * Remove the vote on powering off the radio for a reason, as requested by
3102 * {@link requestRadioPowerOffForReason}.
3103 *
3104 * @param subId The subscription ID.
3105 * @param reason The reason for powering off radio.
3106 * @return true on success and false on failure.
3107 */
3108 public boolean clearRadioPowerOffForReason(int subId,
3109 @TelephonyManager.RadioPowerReason int reason) {
3110 enforceModifyPermission();
3111
joonhunshin4ac60942023-11-15 15:23:39 +00003112 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3113 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearRadioPowerOffForReason");
3114
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003115 final long identity = Binder.clearCallingIdentity();
3116 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003117 boolean result = false;
3118 for (Phone phone : PhoneFactory.getPhones()) {
3119 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003120 phone.setRadioPowerForReason(true, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003121 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003122 if (!result) {
3123 loge("clearRadioPowerOffForReason: no phone exists");
3124 }
3125 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003126 } finally {
3127 Binder.restoreCallingIdentity(identity);
3128 }
3129 }
3130
3131 /**
3132 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3133 *
3134 * @param subId The subscription ID.
3135 * @param callingPackage The package making the call.
3136 * @param callingFeatureId The feature in the package.
3137 * @return List of reasons for powering off radio.
3138 */
3139 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3140 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3141
joonhunshin4ac60942023-11-15 15:23:39 +00003142 enforceTelephonyFeatureWithException(callingPackage,
3143 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerOffReasons");
3144
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003145 final long identity = Binder.clearCallingIdentity();
3146 List result = new ArrayList();
3147 try {
3148 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3149 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3150 return result;
3151 }
3152
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003153 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003154 if (phone != null) {
3155 result.addAll(phone.getRadioPowerOffReasons());
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003156 } else {
3157 loge("getRadioPowerOffReasons: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003158 }
3159 } finally {
3160 Binder.restoreCallingIdentity(identity);
3161 }
3162 return result;
3163 }
3164
Wink Saville36469e72014-06-11 15:17:00 -07003165 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003166 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003167 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003168 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003169
joonhunshin4ac60942023-11-15 15:23:39 +00003170 enforceTelephonyFeatureWithException(callingPackage,
3171 PackageManager.FEATURE_TELEPHONY_DATA, "enableDataConnectivity");
3172
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003173 final long identity = Binder.clearCallingIdentity();
3174 try {
Jack Yu285100e2022-12-02 22:48:35 -08003175 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003176 final Phone phone = getPhone(subId);
3177 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003178 phone.getDataSettingsManager().setDataEnabled(
3179 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003180 return true;
3181 } else {
3182 return false;
3183 }
3184 } finally {
3185 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003186 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003187 }
3188
Wink Saville36469e72014-06-11 15:17:00 -07003189 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003190 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003191 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003192 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003193
joonhunshin4ac60942023-11-15 15:23:39 +00003194 enforceTelephonyFeatureWithException(callingPackage,
3195 PackageManager.FEATURE_TELEPHONY_DATA, "disableDataConnectivity");
3196
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003197 final long identity = Binder.clearCallingIdentity();
3198 try {
Jack Yu285100e2022-12-02 22:48:35 -08003199 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003200 final Phone phone = getPhone(subId);
3201 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003202 phone.getDataSettingsManager().setDataEnabled(
3203 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003204 return true;
3205 } else {
3206 return false;
3207 }
3208 } finally {
3209 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003210 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003211 }
3212
Sanket Padawe356d7632015-06-22 14:03:32 -07003213 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003214 public boolean isDataConnectivityPossible(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003215 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3216 PackageManager.FEATURE_TELEPHONY_DATA, "isDataConnectivityPossible");
3217
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003218 final long identity = Binder.clearCallingIdentity();
3219 try {
3220 final Phone phone = getPhone(subId);
3221 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003222 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003223 } else {
3224 return false;
3225 }
3226 } finally {
3227 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003228 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003229 }
3230
3231 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003232 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003233 }
3234
pkanwarae03a6b2016-11-06 20:37:09 -08003235 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003236 enforceCallPermission();
3237
joonhunshin4ac60942023-11-15 15:23:39 +00003238 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3239 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "handleUssdRequest");
3240
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003241 final long identity = Binder.clearCallingIdentity();
3242 try {
3243 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3244 return;
3245 }
3246 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3247 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3248 } finally {
3249 Binder.restoreCallingIdentity(identity);
3250 }
pkanwar32d516d2016-10-14 19:37:38 -07003251 };
3252
Wink Savilleb564aae2014-10-23 10:18:09 -07003253 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003254 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003255
joonhunshin4ac60942023-11-15 15:23:39 +00003256 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3257 PackageManager.FEATURE_TELEPHONY_CALLING, "handlePinMmiForSubscriber");
3258
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003259 final long identity = Binder.clearCallingIdentity();
3260 try {
3261 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3262 return false;
3263 }
3264 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3265 } finally {
3266 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003267 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003268 }
3269
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003270 /**
3271 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3272 * tag on getCallState Binder call.
3273 */
3274 @Deprecated
3275 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003276 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003277 if (CompatChanges.isChangeEnabled(
3278 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3279 Binder.getCallingUid())) {
3280 // Do not allow this API to be called on API version 31+, it should only be
3281 // called on old apps using this Binder call directly.
3282 throw new SecurityException("This method can only be used for applications "
3283 + "targeting API version 30 or less.");
3284 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003285 final long identity = Binder.clearCallingIdentity();
3286 try {
Ling Mac28f0212023-03-24 16:07:15 -07003287 Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription());
3288 return PhoneConstantConversions.convertCallState(phone.getState());
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003289 } finally {
3290 Binder.restoreCallingIdentity(identity);
3291 }
3292 }
3293
3294 @Override
3295 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3296 if (CompatChanges.isChangeEnabled(
3297 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3298 Binder.getCallingUid())) {
3299 // Check READ_PHONE_STATE for API version 31+
3300 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3301 featureId, "getCallStateForSubscription")) {
3302 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3303 + "targeting API level 31+.");
3304 }
3305 }
joonhunshin4ac60942023-11-15 15:23:39 +00003306
3307 enforceTelephonyFeatureWithException(callingPackage,
3308 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallStateForSubscription");
3309
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003310 final long identity = Binder.clearCallingIdentity();
3311 try {
3312 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003313 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3314 PhoneConstantConversions.convertCallState(phone.getState());
3315 } finally {
3316 Binder.restoreCallingIdentity(identity);
3317 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003318 }
3319
Sanket Padawe356d7632015-06-22 14:03:32 -07003320 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003321 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003322 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003323 }
3324
3325 @Override
3326 public int getDataStateForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003327 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3328 PackageManager.FEATURE_TELEPHONY_DATA, "getDataStateForSubId");
3329
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003330 final long identity = Binder.clearCallingIdentity();
3331 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003332 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003333 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003334 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003335 } else {
3336 return PhoneConstantConversions.convertDataState(
3337 PhoneConstants.DataState.DISCONNECTED);
3338 }
3339 } finally {
3340 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003341 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003342 }
3343
Sanket Padawe356d7632015-06-22 14:03:32 -07003344 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003345 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003346 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003347 }
3348
3349 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003350 public @DataActivityType int getDataActivityForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003351 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3352 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivityForSubId");
3353
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003354 final long identity = Binder.clearCallingIdentity();
3355 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003356 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003357 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003358 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003359 } else {
3360 return TelephonyManager.DATA_ACTIVITY_NONE;
3361 }
3362 } finally {
3363 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003364 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003365 }
3366
3367 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003368 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003369 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003370 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003371
3372 LocationAccessPolicy.LocationPermissionResult locationResult =
3373 LocationAccessPolicy.checkLocationPermission(mApp,
3374 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3375 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003376 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003377 .setCallingPid(Binder.getCallingPid())
3378 .setCallingUid(Binder.getCallingUid())
3379 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003380 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003381 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3382 .build());
3383 switch (locationResult) {
3384 case DENIED_HARD:
3385 throw new SecurityException("Not allowed to access cell location");
3386 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003387 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3388 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003389 }
3390
joonhunshin4ac60942023-11-15 15:23:39 +00003391 enforceTelephonyFeatureWithException(callingPackage,
3392 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getCellLocation");
3393
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003394 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003395 final long identity = Binder.clearCallingIdentity();
3396 try {
3397 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003398 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003399 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003400 } finally {
3401 Binder.restoreCallingIdentity(identity);
3402 }
Svetoslav64fad262015-04-14 14:35:21 -07003403 }
3404
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003405 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003406 public String getNetworkCountryIsoForPhone(int phoneId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003407 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3408 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkCountryIsoForPhone");
3409
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003410 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3411 // registered cell info, so return a NULL country instead.
3412 final long identity = Binder.clearCallingIdentity();
3413 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003414 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3415 // Get default phone in this case.
3416 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3417 }
Jack Yu285100e2022-12-02 22:48:35 -08003418 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003419 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003420 if (phone == null) return "";
3421 ServiceStateTracker sst = phone.getServiceStateTracker();
3422 if (sst == null) return "";
3423 LocaleTracker lt = sst.getLocaleTracker();
3424 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003425 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003426 } finally {
3427 Binder.restoreCallingIdentity(identity);
3428 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003429 }
3430
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003431 /**
3432 * This method was removed due to potential issues caused by performing partial
3433 * updates of service state, and lack of a credible use case.
3434 *
3435 * This has the ability to break the telephony implementation by disabling notification of
3436 * changes in device connectivity. DO NOT USE THIS!
3437 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003438 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003439 public void enableLocationUpdates() {
3440 mApp.enforceCallingOrSelfPermission(
3441 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003442 }
3443
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003444 /**
3445 * This method was removed due to potential issues caused by performing partial
3446 * updates of service state, and lack of a credible use case.
3447 *
3448 * This has the ability to break the telephony implementation by disabling notification of
3449 * changes in device connectivity. DO NOT USE THIS!
3450 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003451 @Override
3452 public void disableLocationUpdates() {
3453 mApp.enforceCallingOrSelfPermission(
3454 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003455 }
3456
3457 @Override
3458 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003459 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3460 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003461 try {
3462 mApp.getSystemService(AppOpsManager.class)
3463 .checkPackage(Binder.getCallingUid(), callingPackage);
3464 } catch (SecurityException e) {
3465 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3466 throw e;
3467 }
3468
Nathan Haroldf096d982020-11-18 17:18:06 -08003469 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003470 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3471 throw new SecurityException(
3472 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3473 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003474
Jordan Liu1617b712019-07-10 15:06:26 -07003475 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003476 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3477 return null;
3478 }
Svetoslav64fad262015-04-14 14:35:21 -07003479
joonhunshin4ac60942023-11-15 15:23:39 +00003480 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3481 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNeighboringCellInfo");
3482
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003483 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003484
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003485 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003486 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003487
Nathan Haroldf180aac2018-06-01 18:43:55 -07003488 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3489 for (CellInfo ci : info) {
3490 if (ci instanceof CellInfoGsm) {
3491 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3492 } else if (ci instanceof CellInfoWcdma) {
3493 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3494 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003495 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003496 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003497 }
3498
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003499 private List<CellInfo> getCachedCellInfo() {
3500 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3501 for (Phone phone : PhoneFactory.getPhones()) {
3502 List<CellInfo> info = phone.getAllCellInfo();
3503 if (info != null) cellInfos.addAll(info);
3504 }
3505 return cellInfos;
3506 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003507
3508 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003509 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003510 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003511 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003512
3513 LocationAccessPolicy.LocationPermissionResult locationResult =
3514 LocationAccessPolicy.checkLocationPermission(mApp,
3515 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3516 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003517 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003518 .setCallingPid(Binder.getCallingPid())
3519 .setCallingUid(Binder.getCallingUid())
3520 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003521 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003522 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3523 .build());
3524 switch (locationResult) {
3525 case DENIED_HARD:
3526 throw new SecurityException("Not allowed to access cell info");
3527 case DENIED_SOFT:
3528 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003529 }
3530
Nathan Haroldf096d982020-11-18 17:18:06 -08003531 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003532 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3533 return getCachedCellInfo();
3534 }
3535
joonhunshin4ac60942023-11-15 15:23:39 +00003536 enforceTelephonyFeatureWithException(callingPackage,
3537 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllCellInfo");
3538
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003539 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003540 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003541 final long identity = Binder.clearCallingIdentity();
3542 try {
3543 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3544 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003545 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003546 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003547 if (info != null) cellInfos.addAll(info);
3548 }
3549 return cellInfos;
3550 } finally {
3551 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003552 }
3553 }
3554
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003555 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003556 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3557 String callingFeatureId) {
3558 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3559 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003560 }
3561
3562 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003563 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3564 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003565 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003566 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003567 }
3568
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003569 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3570 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003571 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003572 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003573
3574 LocationAccessPolicy.LocationPermissionResult locationResult =
3575 LocationAccessPolicy.checkLocationPermission(mApp,
3576 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3577 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003578 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003579 .setCallingPid(Binder.getCallingPid())
3580 .setCallingUid(Binder.getCallingUid())
3581 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003582 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3583 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003584 .build());
3585 switch (locationResult) {
3586 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003587 if (TelephonyPermissions
3588 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003589 // Safetynet logging for b/154934934
3590 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3591 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003592 throw new SecurityException("Not allowed to access cell info");
3593 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003594 if (TelephonyPermissions
3595 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003596 // Safetynet logging for b/154934934
3597 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3598 }
Nathan Harold5320c422019-05-09 10:26:08 -07003599 try {
3600 cb.onCellInfo(new ArrayList<CellInfo>());
3601 } catch (RemoteException re) {
3602 // Drop without consequences
3603 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003604 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003605 }
3606
joonhunshin4ac60942023-11-15 15:23:39 +00003607 enforceTelephonyFeatureWithException(callingPackage,
3608 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestCellInfoUpdateInternal");
Nathan Harolda939a962019-05-09 10:13:47 -07003609
3610 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003611 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3612
3613 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3614 }
3615
3616 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003617 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003618 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003619 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003620
3621 final long identity = Binder.clearCallingIdentity();
3622 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003623 Phone phone = getPhone(subId);
3624 if (phone == null) {
3625 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3626 } else {
3627 phone.setCellInfoListRate(rateInMillis, workSource);
3628 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003629 } finally {
3630 Binder.restoreCallingIdentity(identity);
3631 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003632 }
3633
Shishir Agrawala9f32182016-04-12 12:00:16 -07003634 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003635 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003636 Phone phone = PhoneFactory.getPhone(slotIndex);
3637 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003638 return null;
3639 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003640 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003641 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003642 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003643 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003644 return null;
3645 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003646
joonhunshin4ac60942023-11-15 15:23:39 +00003647 enforceTelephonyFeatureWithException(callingPackage,
3648 PackageManager.FEATURE_TELEPHONY_GSM, "getImeiForSlot");
3649
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003650 final long identity = Binder.clearCallingIdentity();
3651 try {
3652 return phone.getImei();
3653 } finally {
3654 Binder.restoreCallingIdentity(identity);
3655 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003656 }
3657
3658 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003659 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3660 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3661 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3662 callingFeatureId, "getPrimaryImei")) {
3663 throw new SecurityException("Caller does not have permission");
3664 }
joonhunshin4ac60942023-11-15 15:23:39 +00003665
3666 enforceTelephonyFeatureWithException(callingPackage,
3667 PackageManager.FEATURE_TELEPHONY_GSM, "getPrimaryImei");
3668
arunvoddud5c6ce02022-12-11 06:03:12 +00003669 final long identity = Binder.clearCallingIdentity();
3670 try {
3671 for (Phone phone : PhoneFactory.getPhones()) {
3672 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3673 return phone.getImei();
3674 }
3675 }
3676 throw new UnsupportedOperationException("Operation not supported");
3677 } finally {
3678 Binder.restoreCallingIdentity(identity);
3679 }
3680 }
3681
3682 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003683 public String getTypeAllocationCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003684 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3685 PackageManager.FEATURE_TELEPHONY_GSM, "getTypeAllocationCodeForSlot");
3686
David Kelly5e06a7f2018-03-12 14:10:59 +00003687 Phone phone = PhoneFactory.getPhone(slotIndex);
3688 String tac = null;
3689 if (phone != null) {
3690 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003691 try {
3692 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3693 } catch (IndexOutOfBoundsException e) {
3694 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3695 return null;
3696 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003697 }
3698 return tac;
3699 }
3700
3701 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003702 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003703 try {
3704 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3705 } catch (SecurityException se) {
3706 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3707 throw new SecurityException("Package " + callingPackage + " does not belong to "
3708 + Binder.getCallingUid());
3709 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003710 Phone phone = PhoneFactory.getPhone(slotIndex);
3711 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003712 return null;
3713 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003714
Jeff Davidson913390f2018-02-23 17:11:49 -08003715 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003716 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003717 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003718 return null;
3719 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003720
joonhunshin4ac60942023-11-15 15:23:39 +00003721 enforceTelephonyFeatureWithException(callingPackage,
3722 PackageManager.FEATURE_TELEPHONY_CDMA, "getMeidForSlot");
3723
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003724 final long identity = Binder.clearCallingIdentity();
3725 try {
3726 return phone.getMeid();
3727 } finally {
3728 Binder.restoreCallingIdentity(identity);
3729 }
Jack Yu2af8d712017-03-15 17:14:14 -07003730 }
3731
3732 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003733 public String getManufacturerCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003734 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3735 PackageManager.FEATURE_TELEPHONY_CDMA, "getManufacturerCodeForSlot");
3736
David Kelly5e06a7f2018-03-12 14:10:59 +00003737 Phone phone = PhoneFactory.getPhone(slotIndex);
3738 String manufacturerCode = null;
3739 if (phone != null) {
3740 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003741 try {
3742 manufacturerCode =
3743 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3744 } catch (IndexOutOfBoundsException e) {
3745 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3746 return null;
3747 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003748 }
3749 return manufacturerCode;
3750 }
3751
3752 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003753 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3754 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003755 Phone phone = PhoneFactory.getPhone(slotIndex);
3756 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003757 return null;
3758 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003759 int subId = phone.getSubId();
3760 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003761 mApp, subId, callingPackage, callingFeatureId,
3762 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003763 return null;
3764 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003765
joonhunshin4ac60942023-11-15 15:23:39 +00003766 enforceTelephonyFeatureWithException(callingPackage,
3767 PackageManager.FEATURE_TELEPHONY, "getDeviceSoftwareVersionForSlot");
3768
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003769 final long identity = Binder.clearCallingIdentity();
3770 try {
3771 return phone.getDeviceSvn();
3772 } finally {
3773 Binder.restoreCallingIdentity(identity);
3774 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003775 }
3776
fionaxu43304da2017-11-27 22:51:16 -08003777 @Override
3778 public int getSubscriptionCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003779 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3780 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierId");
3781
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003782 final long identity = Binder.clearCallingIdentity();
3783 try {
3784 final Phone phone = getPhone(subId);
3785 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3786 } finally {
3787 Binder.restoreCallingIdentity(identity);
3788 }
fionaxu43304da2017-11-27 22:51:16 -08003789 }
3790
3791 @Override
3792 public String getSubscriptionCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003793 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3794 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierName");
3795
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003796 final long identity = Binder.clearCallingIdentity();
3797 try {
3798 final Phone phone = getPhone(subId);
3799 return phone == null ? null : phone.getCarrierName();
3800 } finally {
3801 Binder.restoreCallingIdentity(identity);
3802 }
fionaxu43304da2017-11-27 22:51:16 -08003803 }
3804
calvinpanffe225e2018-11-01 19:43:06 +08003805 @Override
chen xu0026ca62019-03-06 15:28:50 -08003806 public int getSubscriptionSpecificCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003807 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3808 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionSpecificCarrierId");
3809
chen xu25637222018-11-04 17:17:00 -08003810 final long identity = Binder.clearCallingIdentity();
3811 try {
3812 final Phone phone = getPhone(subId);
3813 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003814 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003815 } finally {
3816 Binder.restoreCallingIdentity(identity);
3817 }
3818 }
3819
3820 @Override
chen xu0026ca62019-03-06 15:28:50 -08003821 public String getSubscriptionSpecificCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003822 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3823 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
3824 "getSubscriptionSpecificCarrierName");
3825
chen xu25637222018-11-04 17:17:00 -08003826 final long identity = Binder.clearCallingIdentity();
3827 try {
3828 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003829 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003830 } finally {
3831 Binder.restoreCallingIdentity(identity);
3832 }
3833 }
3834
chen xu651eec72018-11-11 19:03:44 -08003835 @Override
chen xu864e11c2018-12-06 22:10:03 -08003836 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3837 if (!isSubscriptionMccMnc) {
3838 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3839 }
chen xu651eec72018-11-11 19:03:44 -08003840 final Phone phone = PhoneFactory.getPhone(slotIndex);
3841 if (phone == null) {
3842 return TelephonyManager.UNKNOWN_CARRIER_ID;
3843 }
joonhunshin4ac60942023-11-15 15:23:39 +00003844
3845 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3846 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromMccMnc");
3847
chen xu651eec72018-11-11 19:03:44 -08003848 final long identity = Binder.clearCallingIdentity();
3849 try {
3850 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3851 } finally {
3852 Binder.restoreCallingIdentity(identity);
3853 }
3854 }
3855
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003856 //
3857 // Internal helper methods.
3858 //
3859
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003860 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003861 * Make sure the caller is the calling package itself
3862 *
3863 * @throws SecurityException if the caller is not the calling package
3864 */
3865 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3866 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003867 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3868 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003869 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003870 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003871 } catch (PackageManager.NameNotFoundException e) {
3872 // packageUid is -1
3873 }
3874 if (packageUid != callingUid) {
3875 throw new SecurityException(message + ": Package " + callingPackage
3876 + " does not belong to " + callingUid);
3877 }
3878 }
3879
3880 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003881 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3882 *
3883 * @throws SecurityException if the caller does not have the required permission
3884 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003885 @VisibleForTesting
3886 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003887 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3888 }
3889
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003890 /**
arunvoddud7401012022-12-15 16:08:12 +00003891 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003892 *
3893 * @throws SecurityException if the caller does not have the required permission
3894 */
3895 @VisibleForTesting
3896 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003897 enforceReadPermission(null);
3898 }
3899
3900 /**
3901 * Make sure the caller has the READ_PHONE_STATE permissions.
3902 *
3903 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3904 */
3905 @VisibleForTesting
3906 public void enforceReadPermission(String msg) {
3907 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003908 }
3909
Shuo Qian3b6ee772019-11-13 17:43:31 -08003910 private void enforceActiveEmergencySessionPermission() {
3911 mApp.enforceCallingOrSelfPermission(
3912 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3913 }
3914
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003915 /**
3916 * Make sure the caller has the CALL_PHONE permission.
3917 *
3918 * @throws SecurityException if the caller does not have the required permission
3919 */
3920 private void enforceCallPermission() {
3921 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3922 }
3923
paulhu5a773602019-08-23 19:17:33 +08003924 private void enforceSettingsPermission() {
3925 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003926 }
3927
Michele Berionne5e411512020-11-13 02:36:59 +00003928 private void enforceRebootPermission() {
3929 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3930 }
3931
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003932 /**
3933 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3934 * @param message - log message to print.
3935 * @throws SecurityException if the caller does not have the required permission
3936 */
3937 private void enforceSatelliteCommunicationPermission(String message) {
3938 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3939 }
3940
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003941 private String createTelUrl(String number) {
3942 if (TextUtils.isEmpty(number)) {
3943 return null;
3944 }
3945
Jake Hambye994d462014-02-03 13:10:13 -08003946 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003947 }
3948
Ihab Awadf9e92732013-12-05 18:02:52 -08003949 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003950 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003951 }
3952
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003953 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003954 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003955 }
3956
Ihab Awadf9e92732013-12-05 18:02:52 -08003957 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003958 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003959 }
3960
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003961 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003962 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003963 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003964 }
3965
Sanket Padawe356d7632015-06-22 14:03:32 -07003966 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003967 public int getActivePhoneTypeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003968 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3969 PackageManager.FEATURE_TELEPHONY, "getActivePhoneTypeForSlot");
3970
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003971 final long identity = Binder.clearCallingIdentity();
3972 try {
3973 final Phone phone = PhoneFactory.getPhone(slotIndex);
3974 if (phone == null) {
3975 return PhoneConstants.PHONE_TYPE_NONE;
3976 } else {
3977 return phone.getPhoneType();
3978 }
3979 } finally {
3980 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003981 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003982 }
3983
3984 /**
3985 * Returns the CDMA ERI icon index to display
3986 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003987 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003988 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3989 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3990 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003991 }
3992
Sanket Padawe356d7632015-06-22 14:03:32 -07003993 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003994 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3995 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003996 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003997 mApp, subId, callingPackage, callingFeatureId,
3998 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003999 return -1;
4000 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004001
joonhunshin4ac60942023-11-15 15:23:39 +00004002 enforceTelephonyFeatureWithException(callingPackage,
4003 PackageManager.FEATURE_TELEPHONY_CDMA,
4004 "getCdmaEriIconIndexForSubscriber");
4005
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004006 final long identity = Binder.clearCallingIdentity();
4007 try {
4008 final Phone phone = getPhone(subId);
4009 if (phone != null) {
4010 return phone.getCdmaEriIconIndex();
4011 } else {
4012 return -1;
4013 }
4014 } finally {
4015 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004016 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004017 }
4018
4019 /**
4020 * Returns the CDMA ERI icon mode,
4021 * 0 - ON
4022 * 1 - FLASHING
4023 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004024 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004025 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
4026 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
4027 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004028 }
4029
Sanket Padawe356d7632015-06-22 14:03:32 -07004030 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004031 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
4032 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004033 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004034 mApp, subId, callingPackage, callingFeatureId,
4035 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004036 return -1;
4037 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004038
4039 final long identity = Binder.clearCallingIdentity();
4040 try {
4041 final Phone phone = getPhone(subId);
4042 if (phone != null) {
4043 return phone.getCdmaEriIconMode();
4044 } else {
4045 return -1;
4046 }
4047 } finally {
4048 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004049 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004050 }
4051
4052 /**
4053 * Returns the CDMA ERI text,
4054 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004055 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004056 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
4057 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
4058 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004059 }
4060
Sanket Padawe356d7632015-06-22 14:03:32 -07004061 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004062 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
4063 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004064 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004065 mApp, subId, callingPackage, callingFeatureId,
4066 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004067 return null;
4068 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004069
4070 final long identity = Binder.clearCallingIdentity();
4071 try {
4072 final Phone phone = getPhone(subId);
4073 if (phone != null) {
4074 return phone.getCdmaEriText();
4075 } else {
4076 return null;
4077 }
4078 } finally {
4079 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004080 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004081 }
4082
4083 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07004084 * Returns the CDMA MDN.
4085 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004086 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004087 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004088 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4089 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004090
joonhunshin4ac60942023-11-15 15:23:39 +00004091 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4092 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMdn");
4093
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004094 final long identity = Binder.clearCallingIdentity();
4095 try {
4096 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004097 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004098 return phone.getLine1Number();
4099 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004100 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004101 return null;
4102 }
4103 } finally {
4104 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004105 }
4106 }
4107
4108 /**
4109 * Returns the CDMA MIN.
4110 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004111 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004112 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004113 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4114 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004115
joonhunshin4ac60942023-11-15 15:23:39 +00004116 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4117 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMin");
4118
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004119 final long identity = Binder.clearCallingIdentity();
4120 try {
4121 final Phone phone = getPhone(subId);
4122 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
4123 return phone.getCdmaMin();
4124 } else {
4125 return null;
4126 }
4127 } finally {
4128 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004129 }
4130 }
4131
Hall Liud892bec2018-11-30 14:51:45 -08004132 @Override
4133 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
4134 INumberVerificationCallback callback, String callingPackage) {
4135 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
4136 != PERMISSION_GRANTED) {
4137 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
4138 }
4139 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4140
4141 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
4142 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08004143 throw new SecurityException("Calling package must be configured in the device config: "
4144 + "calling package: " + callingPackage
4145 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004146 }
4147
joonhunshin4ac60942023-11-15 15:23:39 +00004148 enforceTelephonyFeatureWithException(callingPackage,
4149 PackageManager.FEATURE_TELEPHONY_CALLING, "requestNumberVerification");
4150
Hall Liud892bec2018-11-30 14:51:45 -08004151 if (range == null) {
4152 throw new NullPointerException("Range must be non-null");
4153 }
4154
4155 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004156 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004157
4158 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4159 }
4160
Junda Liuca05d5d2014-08-14 22:36:34 -07004161 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004162 * Returns true if CDMA provisioning needs to run.
4163 */
4164 public boolean needsOtaServiceProvisioning() {
joonhunshin4ac60942023-11-15 15:23:39 +00004165 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4166 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needsOtaServiceProvisioning");
4167
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004168 final long identity = Binder.clearCallingIdentity();
4169 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004170 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004171 } finally {
4172 Binder.restoreCallingIdentity(identity);
4173 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004174 }
4175
4176 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004177 * Sets the voice mail number of a given subId.
4178 */
4179 @Override
4180 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004181 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4182 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004183
joonhunshin4ac60942023-11-15 15:23:39 +00004184 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4185 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceMailNumber");
4186
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004187 final long identity = Binder.clearCallingIdentity();
4188 try {
4189 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4190 new Pair<String, String>(alphaTag, number), new Integer(subId));
4191 return success;
4192 } finally {
4193 Binder.restoreCallingIdentity(identity);
4194 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004195 }
4196
Ta-wei Yen87c49842016-05-13 21:19:52 -07004197 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004198 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4199 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004200 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4201 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004202 if (!TextUtils.equals(callingPackage, systemDialer)) {
4203 throw new SecurityException("caller must be system dialer");
4204 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004205
joonhunshin4ac60942023-11-15 15:23:39 +00004206 enforceTelephonyFeatureWithException(callingPackage,
4207 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailSettings");
4208
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004209 final long identity = Binder.clearCallingIdentity();
4210 try {
4211 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4212 if (phoneAccountHandle == null) {
4213 return null;
4214 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004215 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004216 } finally {
4217 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004218 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004219 }
4220
4221 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004222 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4223 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004224 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004225 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004226 mApp, subId, callingPackage, callingFeatureId,
4227 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004228 return null;
4229 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004230
joonhunshin4ac60942023-11-15 15:23:39 +00004231 enforceTelephonyFeatureWithException(callingPackage,
4232 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailPackageName");
4233
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004234 final long identity = Binder.clearCallingIdentity();
4235 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004236 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004237 } finally {
4238 Binder.restoreCallingIdentity(identity);
4239 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004240 }
4241
4242 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004243 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4244 VisualVoicemailSmsFilterSettings settings) {
4245 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004246
joonhunshin4ac60942023-11-15 15:23:39 +00004247 enforceTelephonyFeatureWithException(callingPackage,
4248 PackageManager.FEATURE_TELEPHONY_CALLING, "enableVisualVoicemailSmsFilter");
4249
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004250 final long identity = Binder.clearCallingIdentity();
4251 try {
4252 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004253 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004254 } finally {
4255 Binder.restoreCallingIdentity(identity);
4256 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004257 }
4258
4259 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004260 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4261 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004262
joonhunshin4ac60942023-11-15 15:23:39 +00004263 enforceTelephonyFeatureWithException(callingPackage,
4264 PackageManager.FEATURE_TELEPHONY_CALLING, "disableVisualVoicemailSmsFilter");
4265
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004266 final long identity = Binder.clearCallingIdentity();
4267 try {
4268 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004269 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004270 } finally {
4271 Binder.restoreCallingIdentity(identity);
4272 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004273 }
4274
4275 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004276 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4277 String callingPackage, int subId) {
4278 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004279
4280 final long identity = Binder.clearCallingIdentity();
4281 try {
4282 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004283 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004284 } finally {
4285 Binder.restoreCallingIdentity(identity);
4286 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004287 }
4288
4289 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004290 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004291 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004292
4293 final long identity = Binder.clearCallingIdentity();
4294 try {
4295 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004296 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004297 } finally {
4298 Binder.restoreCallingIdentity(identity);
4299 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004300 }
4301
4302 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004303 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4304 String callingAttributionTag, int subId, String number, int port, String text,
4305 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004306 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004307 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004308 enforceSendSmsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00004309
4310 enforceTelephonyFeatureWithException(callingPackage,
4311 PackageManager.FEATURE_TELEPHONY_CALLING, "sendVisualVoicemailSmsForSubscriber");
4312
Amit Mahajandccb3f12019-05-13 13:48:32 -07004313 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004314 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4315 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004316 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004317
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004318 /**
fionaxu0152e512016-11-14 13:36:14 -08004319 * Sets the voice activation state of a given subId.
4320 */
4321 @Override
4322 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004323 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4324 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004325
joonhunshin4ac60942023-11-15 15:23:39 +00004326 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4327 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState");
4328
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004329 final long identity = Binder.clearCallingIdentity();
4330 try {
4331 final Phone phone = getPhone(subId);
4332 if (phone != null) {
4333 phone.setVoiceActivationState(activationState);
4334 } else {
4335 loge("setVoiceActivationState fails with invalid subId: " + subId);
4336 }
4337 } finally {
4338 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004339 }
4340 }
4341
4342 /**
4343 * Sets the data activation state of a given subId.
4344 */
4345 @Override
4346 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004347 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4348 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004349
joonhunshin4ac60942023-11-15 15:23:39 +00004350 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4351 PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState");
4352
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004353 final long identity = Binder.clearCallingIdentity();
4354 try {
4355 final Phone phone = getPhone(subId);
4356 if (phone != null) {
4357 phone.setDataActivationState(activationState);
4358 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004359 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004360 }
4361 } finally {
4362 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004363 }
4364 }
4365
4366 /**
4367 * Returns the voice activation state of a given subId.
4368 */
4369 @Override
4370 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004371 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004372
joonhunshin4ac60942023-11-15 15:23:39 +00004373 enforceTelephonyFeatureWithException(callingPackage,
4374 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState");
4375
fionaxu0152e512016-11-14 13:36:14 -08004376 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004377 final long identity = Binder.clearCallingIdentity();
4378 try {
4379 if (phone != null) {
4380 return phone.getVoiceActivationState();
4381 } else {
4382 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4383 }
4384 } finally {
4385 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004386 }
4387 }
4388
4389 /**
4390 * Returns the data activation state of a given subId.
4391 */
4392 @Override
4393 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004394 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004395
joonhunshin4ac60942023-11-15 15:23:39 +00004396 enforceTelephonyFeatureWithException(callingPackage,
4397 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState");
4398
fionaxu0152e512016-11-14 13:36:14 -08004399 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004400 final long identity = Binder.clearCallingIdentity();
4401 try {
4402 if (phone != null) {
4403 return phone.getDataActivationState();
4404 } else {
4405 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4406 }
4407 } finally {
4408 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004409 }
4410 }
4411
4412 /**
Wink Saville36469e72014-06-11 15:17:00 -07004413 * Returns the unread count of voicemails for a subId
4414 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004415 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004416 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4417 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004418 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004419 mApp, subId, callingPackage, callingFeatureId,
4420 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004421 return 0;
4422 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004423 final long identity = Binder.clearCallingIdentity();
4424 try {
4425 final Phone phone = getPhone(subId);
4426 if (phone != null) {
4427 return phone.getVoiceMessageCount();
4428 } else {
4429 return 0;
4430 }
4431 } finally {
4432 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004433 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004434 }
4435
4436 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004437 * returns true, if the device is in a state where both voice and data
4438 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004439 */
4440 @Override
4441 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00004442 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4443 PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed");
4444
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004445 final long identity = Binder.clearCallingIdentity();
4446 try {
Ling Mac28f0212023-03-24 16:07:15 -07004447 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004448 } finally {
4449 Binder.restoreCallingIdentity(identity);
4450 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004451 }
4452
4453 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004454 * Send the dialer code if called from the current default dialer or the caller has
4455 * carrier privilege.
4456 * @param inputCode The dialer code to send
4457 */
4458 @Override
4459 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004460 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004461 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004462 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4463 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004464 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004465 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004466 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004467 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004468
joonhunshin4ac60942023-11-15 15:23:39 +00004469 enforceTelephonyFeatureWithException(callingPackage,
4470 PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode");
4471
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004472 final long identity = Binder.clearCallingIdentity();
4473 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004474 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004475 } finally {
4476 Binder.restoreCallingIdentity(identity);
4477 }
fionaxu235cc5e2017-03-06 22:25:57 -08004478 }
4479
Pengquan Menga1bb6272018-09-06 09:59:22 -07004480 @Override
4481 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004482 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004483 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4484 mApp, subId, "getNetworkSelectionMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004485
4486 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4487 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode");
4488
shilufc958392020-01-20 11:36:01 -08004489 final long identity = Binder.clearCallingIdentity();
4490 try {
4491 if (!isActiveSubscription(subId)) {
4492 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4493 }
4494 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4495 } finally {
4496 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004497 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004498 }
4499
Brad Ebinger35c841c2018-10-01 10:40:55 -07004500 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004501 public boolean isInEmergencySmsMode() {
4502 enforceReadPrivilegedPermission("isInEmergencySmsMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004503
4504 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4505 PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode");
4506
Brad Ebingerb2b65522019-03-15 13:48:47 -07004507 final long identity = Binder.clearCallingIdentity();
4508 try {
4509 for (Phone phone : PhoneFactory.getPhones()) {
4510 if (phone.isInEmergencySmsMode()) {
4511 return true;
4512 }
4513 }
4514 } finally {
4515 Binder.restoreCallingIdentity(identity);
4516 }
4517 return false;
4518 }
4519
shilu366312e2019-12-17 09:28:10 -08004520 /**
4521 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4522 * @param subId The subscription to use to check the configuration.
4523 * @param c The callback that will be used to send the result.
4524 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004525 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004526 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4527 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004528 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004529 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004530
4531 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4532 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4533 "IMS not available on device.");
4534 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004535 final long token = Binder.clearCallingIdentity();
4536 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004537 int slotId = getSlotIndexOrException(subId);
4538 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004539
4540 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4541 if (controller != null) {
4542 ImsManager imsManager = controller.getImsManager(subId);
4543 if (imsManager != null) {
4544 imsManager.addRegistrationCallbackForSubscription(c, subId);
4545 } else {
4546 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4547 }
4548 } else {
4549 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4550 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004551 } catch (ImsException e) {
4552 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004553 } finally {
4554 Binder.restoreCallingIdentity(token);
4555 }
4556 }
4557
shilu366312e2019-12-17 09:28:10 -08004558 /**
4559 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4560 * @param subId The subscription to use to check the configuration.
4561 * @param c The callback that will be used to send the result.
4562 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004563 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004564 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004565 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004566 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004567 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4568 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4569 }
Meng Wangafbc5852019-09-19 17:37:13 -07004570 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004571
Meng Wangafbc5852019-09-19 17:37:13 -07004572 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004573 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4574 if (controller != null) {
4575 ImsManager imsManager = controller.getImsManager(subId);
4576 if (imsManager != null) {
4577 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4578 } else {
4579 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4580 + "is inactive, ignoring unregister.");
4581 // If the ImsManager is not valid, just return, since the callback
4582 // will already have been removed internally.
4583 }
4584 }
Meng Wangafbc5852019-09-19 17:37:13 -07004585 } finally {
4586 Binder.restoreCallingIdentity(token);
4587 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004588 }
4589
Brad Ebingera34a6c22019-10-22 17:36:18 -07004590 /**
Hidayat Khan99ea48f2023-12-11 04:37:45 +00004591 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4592 * @param subId The subscription to use to check the configuration.
4593 * @param c The callback that will be used to send the result.
4594 */
4595 @Override
4596 public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c)
4597 throws RemoteException {
4598 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4599 mApp, subId, "registerImsEmergencyRegistrationCallback");
4600
4601 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4602 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4603 "IMS not available on device.");
4604 }
4605 final long token = Binder.clearCallingIdentity();
4606 try {
4607 int slotId = getSlotIndexOrException(subId);
4608 verifyImsMmTelConfiguredOrThrow(slotId);
4609
4610 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4611 if (controller != null) {
4612 ImsManager imsManager = controller.getImsManager(subId);
4613 if (imsManager != null) {
4614 imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId);
4615 } else {
4616 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4617 }
4618 } else {
4619 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4620 }
4621 } catch (ImsException e) {
4622 throw new ServiceSpecificException(e.getCode());
4623 } finally {
4624 Binder.restoreCallingIdentity(token);
4625 }
4626 }
4627
4628 /**
4629 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4630 * @param subId The subscription to use to check the configuration.
4631 * @param c The callback that will be used to send the result.
4632 */
4633 @Override
4634 public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) {
4635 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4636 mApp, subId, "unregisterImsEmergencyRegistrationCallback");
4637 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4638 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4639 }
4640 final long token = Binder.clearCallingIdentity();
4641
4642 try {
4643 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4644 if (controller != null) {
4645 ImsManager imsManager = controller.getImsManager(subId);
4646 if (imsManager != null) {
4647 imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId);
4648 } else {
4649 Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId
4650 + "is inactive, ignoring unregister.");
4651 // If the ImsManager is not valid, just return, since the callback
4652 // will already have been removed internally.
4653 }
4654 }
4655 } finally {
4656 Binder.restoreCallingIdentity(token);
4657 }
4658 }
4659
4660 /**
Brad Ebingera34a6c22019-10-22 17:36:18 -07004661 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4662 */
4663 @Override
4664 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4665 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4666 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4667 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4668 "IMS not available on device.");
4669 }
4670 final long token = Binder.clearCallingIdentity();
4671 try {
4672 Phone phone = getPhone(subId);
4673 if (phone == null) {
4674 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4675 + subId + "'");
4676 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4677 }
4678 phone.getImsRegistrationState(regState -> {
4679 try {
4680 consumer.accept((regState == null)
4681 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4682 } catch (RemoteException e) {
4683 // Ignore if the remote process is no longer available to call back.
4684 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4685 }
4686 });
4687 } finally {
4688 Binder.restoreCallingIdentity(token);
4689 }
4690 }
4691
4692 /**
4693 * Get the transport type for the IMS service registration state.
4694 */
4695 @Override
4696 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004697 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004698 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004699 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4700 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4701 "IMS not available on device.");
4702 }
4703 final long token = Binder.clearCallingIdentity();
4704 try {
4705 Phone phone = getPhone(subId);
4706 if (phone == null) {
4707 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4708 + subId + "'");
4709 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4710 }
4711 phone.getImsRegistrationTech(regTech -> {
4712 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4713 int regTechConverted = (regTech == null)
4714 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4715 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4716 regTechConverted);
4717 try {
4718 consumer.accept(regTechConverted);
4719 } catch (RemoteException e) {
4720 // Ignore if the remote process is no longer available to call back.
4721 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4722 }
4723 });
4724 } finally {
4725 Binder.restoreCallingIdentity(token);
4726 }
4727 }
4728
shilu366312e2019-12-17 09:28:10 -08004729 /**
4730 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4731 * @param subId The subscription to use to check the configuration.
4732 * @param c The callback that will be used to send the result.
4733 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004734 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004735 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4736 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004737 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004738 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004739 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4740 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4741 "IMS not available on device.");
4742 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004743 final long token = Binder.clearCallingIdentity();
4744 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004745 int slotId = getSlotIndexOrException(subId);
4746 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004747
4748 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4749 if (controller != null) {
4750 ImsManager imsManager = controller.getImsManager(subId);
4751 if (imsManager != null) {
4752 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4753 } else {
4754 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4755 }
4756 } else {
4757 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4758 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004759 } catch (ImsException e) {
4760 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004761 } finally {
4762 Binder.restoreCallingIdentity(token);
4763 }
4764 }
4765
shilu366312e2019-12-17 09:28:10 -08004766 /**
4767 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4768 * @param subId The subscription to use to check the configuration.
4769 * @param c The callback that will be used to send the result.
4770 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004771 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004772 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004773 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004774 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004775 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4776 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4777 }
Meng Wangafbc5852019-09-19 17:37:13 -07004778
4779 final long token = Binder.clearCallingIdentity();
4780 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004781 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4782 if (controller != null) {
4783 ImsManager imsManager = controller.getImsManager(subId);
4784 if (imsManager != null) {
4785 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4786 } else {
4787 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4788 + " is inactive, ignoring unregister.");
4789 // If the ImsManager is not valid, just return, since the callback
4790 // will already have been removed internally.
4791 }
4792 }
Meng Wangafbc5852019-09-19 17:37:13 -07004793 } finally {
4794 Binder.restoreCallingIdentity(token);
4795 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004796 }
4797
4798 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004799 public boolean isCapable(int subId, int capability, int regTech) {
4800 enforceReadPrivilegedPermission("isCapable");
joonhunshin4ac60942023-11-15 15:23:39 +00004801
4802 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4803 FEATURE_TELEPHONY_IMS, "isCapable");
4804
Brad Ebinger35c841c2018-10-01 10:40:55 -07004805 final long token = Binder.clearCallingIdentity();
4806 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004807 int slotId = getSlotIndexOrException(subId);
4808 verifyImsMmTelConfiguredOrThrow(slotId);
4809 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4810 } catch (com.android.ims.ImsException e) {
4811 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4812 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004813 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004814 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4815 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004816 } finally {
4817 Binder.restoreCallingIdentity(token);
4818 }
4819 }
4820
4821 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004822 public boolean isAvailable(int subId, int capability, int regTech) {
4823 enforceReadPrivilegedPermission("isAvailable");
joonhunshin4ac60942023-11-15 15:23:39 +00004824
4825 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4826 FEATURE_TELEPHONY_IMS, "isAvailable");
4827
Brad Ebinger35c841c2018-10-01 10:40:55 -07004828 final long token = Binder.clearCallingIdentity();
4829 try {
4830 Phone phone = getPhone(subId);
4831 if (phone == null) return false;
4832 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004833 } catch (com.android.ims.ImsException e) {
4834 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4835 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004836 } finally {
4837 Binder.restoreCallingIdentity(token);
4838 }
4839 }
4840
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004841 /**
4842 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4843 * subscription.
4844 * @param subId The subscription to use to check the configuration.
4845 * @param callback The callback that will be used to send the result.
4846 * @param capability The MmTelFeature capability that will be used to send the result.
4847 * @param transportType The transport type of the MmTelFeature capability.
4848 */
4849 @Override
4850 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4851 int transportType) {
4852 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004853 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4854 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4855 "IMS not available on device.");
4856 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004857 final long token = Binder.clearCallingIdentity();
4858 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004859 int slotId = getSlotIndex(subId);
4860 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4861 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4862 + subId + "'");
4863 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4864 }
4865 verifyImsMmTelConfiguredOrThrow(slotId);
4866 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4867 transportType, aBoolean -> {
4868 try {
4869 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4870 } catch (RemoteException e) {
4871 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4872 + "running. Ignore");
4873 }
4874 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004875 } catch (ImsException e) {
4876 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004877 } finally {
4878 Binder.restoreCallingIdentity(token);
4879 }
4880 }
4881
shilu366312e2019-12-17 09:28:10 -08004882 /**
4883 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4884 * @param subId The subscription to use to check the configuration.
4885 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004886 @Override
4887 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004888 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004889 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004890
joonhunshin4ac60942023-11-15 15:23:39 +00004891 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4892 FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled");
4893
Brad Ebinger35c841c2018-10-01 10:40:55 -07004894 final long token = Binder.clearCallingIdentity();
4895 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004896 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004897 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004898 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004899 } catch (ImsException e) {
4900 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004901 } finally {
4902 Binder.restoreCallingIdentity(token);
4903 }
4904 }
4905
4906 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004907 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004908 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004909 "setAdvancedCallingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004910
4911 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4912 FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled");
4913
Brad Ebinger35c841c2018-10-01 10:40:55 -07004914 final long identity = Binder.clearCallingIdentity();
4915 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004916 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004917 // This setting doesn't require an active ImsService connection, so do not verify. The
4918 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004919 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004920 } catch (ImsException e) {
4921 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004922 } finally {
4923 Binder.restoreCallingIdentity(identity);
4924 }
4925 }
4926
shilu366312e2019-12-17 09:28:10 -08004927 /**
4928 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4929 * @param subId The subscription to use to check the configuration.
4930 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004931 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004932 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004933 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004934 mApp, subId, "isVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004935
4936 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4937 FEATURE_TELEPHONY_IMS, "isVtSettingEnabled");
4938
Brad Ebinger35c841c2018-10-01 10:40:55 -07004939 final long identity = Binder.clearCallingIdentity();
4940 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004941 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004942 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004943 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004944 } catch (ImsException e) {
4945 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004946 } finally {
4947 Binder.restoreCallingIdentity(identity);
4948 }
4949 }
4950
4951 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004952 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004953 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004954 "setVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004955
4956 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4957 FEATURE_TELEPHONY_IMS, "setVtSettingEnabled");
4958
Brad Ebinger35c841c2018-10-01 10:40:55 -07004959 final long identity = Binder.clearCallingIdentity();
4960 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004961 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004962 // This setting doesn't require an active ImsService connection, so do not verify. The
4963 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004964 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004965 } catch (ImsException e) {
4966 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004967 } finally {
4968 Binder.restoreCallingIdentity(identity);
4969 }
4970 }
4971
shilu366312e2019-12-17 09:28:10 -08004972 /**
4973 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4974 * @param subId The subscription to use to check the configuration.
4975 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004976 @Override
4977 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004978 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004979 mApp, subId, "isVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004980
4981 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4982 FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled");
4983
Brad Ebinger35c841c2018-10-01 10:40:55 -07004984 final long identity = Binder.clearCallingIdentity();
4985 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004986 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004987 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004988 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004989 } catch (ImsException e) {
4990 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004991 } finally {
4992 Binder.restoreCallingIdentity(identity);
4993 }
4994 }
4995
4996 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004997 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004998 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004999 "setVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005000
5001 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5002 FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled");
5003
Brad Ebinger35c841c2018-10-01 10:40:55 -07005004 final long identity = Binder.clearCallingIdentity();
5005 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005006 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005007 // This setting doesn't require an active ImsService connection, so do not verify. The
5008 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005009 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005010 } catch (ImsException e) {
5011 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005012 } finally {
5013 Binder.restoreCallingIdentity(identity);
5014 }
5015 }
5016
shilu366312e2019-12-17 09:28:10 -08005017 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005018 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
5019 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5020 * @param subId The subscription to use to check the configuration.
5021 */
5022 @Override
5023 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005024 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005025 mApp, subId, "isCrossSimCallingEnabledByUser");
joonhunshin4ac60942023-11-15 15:23:39 +00005026
5027 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5028 FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser");
5029
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005030 final long identity = Binder.clearCallingIdentity();
5031 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005032 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005033 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005034 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005035 } catch (ImsException e) {
5036 throw new ServiceSpecificException(e.getCode());
5037 } finally {
5038 Binder.restoreCallingIdentity(identity);
5039 }
5040 }
5041
5042 /**
5043 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
5044 * Requires MODIFY_PHONE_STATE permission.
5045 * @param subId The subscription to use to check the configuration.
5046 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
5047 * false otherwise
5048 */
5049 @Override
5050 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
5051 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5052 "setCrossSimCallingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005053
5054 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5055 FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled");
5056
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005057 final long identity = Binder.clearCallingIdentity();
5058 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005059 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005060 // This setting doesn't require an active ImsService connection, so do not verify. The
5061 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005062 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005063 } catch (ImsException e) {
5064 throw new ServiceSpecificException(e.getCode());
5065 } finally {
5066 Binder.restoreCallingIdentity(identity);
5067 }
5068 }
5069
5070 /**
shilu366312e2019-12-17 09:28:10 -08005071 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5072 * @param subId The subscription to use to check the configuration.
5073 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005074 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07005075
Brad Ebinger35c841c2018-10-01 10:40:55 -07005076 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005077 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005078 mApp, subId, "isVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005079
5080 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5081 FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled");
5082
Brad Ebinger35c841c2018-10-01 10:40:55 -07005083 final long identity = Binder.clearCallingIdentity();
5084 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005085 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005086 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005087 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005088 } catch (ImsException e) {
5089 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005090 } finally {
5091 Binder.restoreCallingIdentity(identity);
5092 }
5093 }
5094
5095 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005096 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005097 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005098 "setVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005099
5100 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5101 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled");
5102
Brad Ebinger35c841c2018-10-01 10:40:55 -07005103 final long identity = Binder.clearCallingIdentity();
5104 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005105 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005106 // This setting doesn't require an active ImsService connection, so do not verify. The
5107 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005108 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005109 } catch (ImsException e) {
5110 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005111 } finally {
5112 Binder.restoreCallingIdentity(identity);
5113 }
5114 }
5115
5116 @Override
5117 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
5118 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5119 "setVoWiFiNonPersistent");
joonhunshin4ac60942023-11-15 15:23:39 +00005120
5121 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5122 FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent");
5123
Brad Ebinger35c841c2018-10-01 10:40:55 -07005124 final long identity = Binder.clearCallingIdentity();
5125 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005126 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005127 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005128 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005129 } catch (ImsException e) {
5130 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005131 } finally {
5132 Binder.restoreCallingIdentity(identity);
5133 }
5134 }
5135
shilu366312e2019-12-17 09:28:10 -08005136 /**
5137 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5138 * @param subId The subscription to use to check the configuration.
5139 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005140 @Override
5141 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005142 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005143 mApp, subId, "getVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005144
5145 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5146 FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting");
5147
Brad Ebinger35c841c2018-10-01 10:40:55 -07005148 final long identity = Binder.clearCallingIdentity();
5149 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005150 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005151 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005152 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005153 } catch (ImsException e) {
5154 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005155 } finally {
5156 Binder.restoreCallingIdentity(identity);
5157 }
5158 }
5159
5160 @Override
5161 public void setVoWiFiModeSetting(int subId, int mode) {
5162 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5163 "setVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005164
5165 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5166 FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting");
5167
Brad Ebinger35c841c2018-10-01 10:40:55 -07005168 final long identity = Binder.clearCallingIdentity();
5169 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005170 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005171 // This setting doesn't require an active ImsService connection, so do not verify. The
5172 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005173 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005174 } catch (ImsException e) {
5175 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005176 } finally {
5177 Binder.restoreCallingIdentity(identity);
5178 }
5179 }
5180
5181 @Override
5182 public int getVoWiFiRoamingModeSetting(int subId) {
5183 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005184
5185 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5186 FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting");
5187
Brad Ebinger35c841c2018-10-01 10:40:55 -07005188 final long identity = Binder.clearCallingIdentity();
5189 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005190 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005191 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005192 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005193 } catch (ImsException e) {
5194 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005195 } finally {
5196 Binder.restoreCallingIdentity(identity);
5197 }
5198 }
5199
5200 @Override
5201 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
5202 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5203 "setVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005204
5205 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5206 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting");
5207
Brad Ebinger35c841c2018-10-01 10:40:55 -07005208 final long identity = Binder.clearCallingIdentity();
5209 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005210 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005211 // This setting doesn't require an active ImsService connection, so do not verify. The
5212 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005213 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005214 } catch (ImsException e) {
5215 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005216 } finally {
5217 Binder.restoreCallingIdentity(identity);
5218 }
5219 }
5220
5221 @Override
5222 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
5223 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5224 "setRttCapabilityEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005225
5226 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5227 FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting");
5228
Brad Ebinger35c841c2018-10-01 10:40:55 -07005229 final long identity = Binder.clearCallingIdentity();
5230 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005231 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005232 // This setting doesn't require an active ImsService connection, so do not verify. The
5233 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005234 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005235 } catch (ImsException e) {
5236 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005237 } finally {
5238 Binder.restoreCallingIdentity(identity);
5239 }
5240 }
5241
shilu366312e2019-12-17 09:28:10 -08005242 /**
5243 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5244 * @param subId The subscription to use to check the configuration.
5245 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005246 @Override
5247 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005248 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005249 mApp, subId, "isTtyOverVolteEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005250
5251 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5252 FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled");
5253
Brad Ebinger35c841c2018-10-01 10:40:55 -07005254 final long identity = Binder.clearCallingIdentity();
5255 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005256 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005257 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005258 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005259 } catch (ImsException e) {
5260 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005261 } finally {
5262 Binder.restoreCallingIdentity(identity);
5263 }
5264 }
5265
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005266 @Override
5267 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5268 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005269
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005270 final long identity = Binder.clearCallingIdentity();
5271 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005272 if (!isImsAvailableOnDevice()) {
5273 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5274 "IMS not available on device.");
5275 }
5276 int slotId = getSlotIndexOrException(subId);
5277 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005278
5279 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5280 if (controller != null) {
5281 ImsManager imsManager = controller.getImsManager(subId);
5282 if (imsManager != null) {
5283 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5284 } else {
5285 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5286 }
5287 } else {
5288 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5289 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005290 } catch (ImsException e) {
5291 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005292 } finally {
5293 Binder.restoreCallingIdentity(identity);
5294 }
5295 }
5296
5297 @Override
5298 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5299 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005300
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005301 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005302 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5303 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5304 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005305 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005306 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5307 if (controller != null) {
5308 ImsManager imsManager = controller.getImsManager(subId);
5309 if (imsManager != null) {
5310 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5311 } else {
5312 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5313 + " is inactive, ignoring unregister.");
5314 // If the ImsManager is not valid, just return, since the callback will already
5315 // have been removed internally.
5316 }
5317 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005318 } finally {
5319 Binder.restoreCallingIdentity(identity);
5320 }
5321 }
5322
joonhunshincffb7fc2021-11-28 07:32:01 +00005323 @Override
5324 public void registerFeatureProvisioningChangedCallback(int subId,
5325 IFeatureProvisioningCallback callback) {
5326 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5327 mApp, subId, "registerFeatureProvisioningChangedCallback");
5328
5329 final long identity = Binder.clearCallingIdentity();
5330 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5331 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5332 }
5333
joonhunshin91bc1952022-04-29 08:47:15 +00005334 try {
5335 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5336 if (controller == null) {
5337 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5338 "Device does not support IMS");
5339 }
5340 controller.addFeatureProvisioningChangedCallback(subId, callback);
5341 } finally {
5342 Binder.restoreCallingIdentity(identity);
5343 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005344 }
5345
5346 @Override
5347 public void unregisterFeatureProvisioningChangedCallback(int subId,
5348 IFeatureProvisioningCallback callback) {
5349 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5350 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5351
5352 final long identity = Binder.clearCallingIdentity();
5353 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5354 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5355 }
5356
joonhunshin91bc1952022-04-29 08:47:15 +00005357 try {
5358 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5359 if (controller == null) {
5360 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5361 return;
5362 }
5363 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5364 } finally {
5365 Binder.restoreCallingIdentity(identity);
5366 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005367 }
allenwtsu99c623b2020-01-03 18:24:23 +08005368
5369 private void checkModifyPhoneStatePermission(int subId, String message) {
5370 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5371 message);
5372 }
5373
allenwtsu99c623b2020-01-03 18:24:23 +08005374 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005375 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005376 boolean isProvisioned) {
5377 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5378
joonhunshin4ac60942023-11-15 15:23:39 +00005379 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5380 FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability");
5381
allenwtsu99c623b2020-01-03 18:24:23 +08005382 final long identity = Binder.clearCallingIdentity();
5383 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005384 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5385 if (controller == null) {
5386 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5387 return;
5388 }
5389 controller.setRcsProvisioningStatusForCapability(
5390 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005391 } finally {
5392 Binder.restoreCallingIdentity(identity);
5393 }
allenwtsu99c623b2020-01-03 18:24:23 +08005394 }
5395
5396
5397 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005398 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5399 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5400 mApp, subId, "getRcsProvisioningStatusForCapability");
5401
joonhunshin4ac60942023-11-15 15:23:39 +00005402 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5403 FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability");
5404
allenwtsu99c623b2020-01-03 18:24:23 +08005405 final long identity = Binder.clearCallingIdentity();
5406 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005407 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5408 if (controller == null) {
5409 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5410
5411 // device does not support IMS, this method will return true always.
5412 return true;
5413 }
5414 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005415 } finally {
5416 Binder.restoreCallingIdentity(identity);
5417 }
5418 }
5419
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005420 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005421 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5422 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005423 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005424
joonhunshin4ac60942023-11-15 15:23:39 +00005425 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5426 FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability");
5427
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005428 final long identity = Binder.clearCallingIdentity();
5429 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005430 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5431 if (controller == null) {
5432 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5433 return;
5434 }
5435 controller.setImsProvisioningStatusForCapability(
5436 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005437 } finally {
5438 Binder.restoreCallingIdentity(identity);
5439 }
5440 }
5441
5442 @Override
5443 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005444 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5445 mApp, subId, "getProvisioningStatusForCapability");
5446
joonhunshin4ac60942023-11-15 15:23:39 +00005447 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5448 FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability");
5449
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005450 final long identity = Binder.clearCallingIdentity();
5451 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005452 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5453 if (controller == null) {
5454 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005455
joonhunshin91bc1952022-04-29 08:47:15 +00005456 // device does not support IMS, this method will return true always.
5457 return true;
5458 }
5459 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005460 } finally {
5461 Binder.restoreCallingIdentity(identity);
5462 }
5463 }
5464
5465 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005466 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5467 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5468 mApp, subId, "isProvisioningRequiredForCapability");
5469
joonhunshin4ac60942023-11-15 15:23:39 +00005470 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5471 FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability");
5472
joonhunshincffb7fc2021-11-28 07:32:01 +00005473 final long identity = Binder.clearCallingIdentity();
5474 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005475 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5476 if (controller == null) {
5477 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5478
5479 // device does not support IMS, this method will return false
5480 return false;
5481 }
5482 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005483 } finally {
5484 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005485 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005486 }
5487
5488 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005489 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5490 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5491 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005492
joonhunshin4ac60942023-11-15 15:23:39 +00005493 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5494 FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability");
5495
joonhunshincffb7fc2021-11-28 07:32:01 +00005496 final long identity = Binder.clearCallingIdentity();
5497 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005498 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5499 if (controller == null) {
5500 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5501
5502 // device does not support IMS, this method will return false
5503 return false;
5504 }
5505 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005506 } finally {
5507 Binder.restoreCallingIdentity(identity);
5508 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005509 }
5510
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005511 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005512 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005513 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5514 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5515 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005516 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5517 mApp, subId, "getImsProvisioningInt");
5518
joonhunshin4ac60942023-11-15 15:23:39 +00005519 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5520 FEATURE_TELEPHONY_IMS, "getImsProvisioningInt");
5521
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005522 final long identity = Binder.clearCallingIdentity();
5523 try {
5524 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005525 int slotId = getSlotIndex(subId);
5526 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5527 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5528 + subId + "' for key:" + key);
5529 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5530 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005531
joonhunshin91bc1952022-04-29 08:47:15 +00005532 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5533 if (controller == null) {
5534 loge("getImsProvisioningInt: Device does not support IMS");
5535
5536 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5537 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5538 }
5539 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005540 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5541 return retVal;
5542 }
5543
calvinpanb5a34062021-02-08 19:59:36 +08005544 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005545 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005546 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5547 + subId + "' for key:" + key);
5548 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005549 } finally {
5550 Binder.restoreCallingIdentity(identity);
5551 }
5552 }
5553
5554 @Override
5555 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005556 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5557 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5558 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005559 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5560 mApp, subId, "getImsProvisioningString");
5561
joonhunshin4ac60942023-11-15 15:23:39 +00005562 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5563 FEATURE_TELEPHONY_IMS, "getImsProvisioningString");
5564
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005565 final long identity = Binder.clearCallingIdentity();
5566 try {
5567 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005568 int slotId = getSlotIndex(subId);
5569 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5570 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5571 + subId + "' for key:" + key);
5572 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5573 }
calvinpanb5a34062021-02-08 19:59:36 +08005574 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005575 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005576 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5577 + subId + "' for key:" + key);
5578 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005579 } finally {
5580 Binder.restoreCallingIdentity(identity);
5581 }
5582 }
5583
5584 @Override
5585 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005586 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5587 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5588 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005589 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5590 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005591
joonhunshin4ac60942023-11-15 15:23:39 +00005592 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5593 FEATURE_TELEPHONY_IMS, "setImsProvisioningInt");
5594
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005595 final long identity = Binder.clearCallingIdentity();
5596 try {
5597 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005598 int slotId = getSlotIndex(subId);
5599 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5600 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5601 + subId + "' for key:" + key);
5602 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5603 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005604
joonhunshin91bc1952022-04-29 08:47:15 +00005605 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5606 if (controller == null) {
5607 loge("setImsProvisioningInt: Device does not support IMS");
5608
5609 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5610 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5611 }
5612 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005613 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5614 return retVal;
5615 }
5616
calvinpanb5a34062021-02-08 19:59:36 +08005617 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5618 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005619 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005620 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005621 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005622 } finally {
5623 Binder.restoreCallingIdentity(identity);
5624 }
5625 }
5626
5627 @Override
5628 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005629 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5630 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5631 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005632 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5633 "setImsProvisioningString");
joonhunshin4ac60942023-11-15 15:23:39 +00005634
5635 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5636 FEATURE_TELEPHONY_IMS, "setImsProvisioningString");
5637
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005638 final long identity = Binder.clearCallingIdentity();
5639 try {
5640 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005641 int slotId = getSlotIndex(subId);
5642 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5643 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5644 + subId + "' for key:" + key);
5645 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5646 }
calvinpanb5a34062021-02-08 19:59:36 +08005647 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5648 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005649 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005650 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005651 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005652 } finally {
5653 Binder.restoreCallingIdentity(identity);
5654 }
5655 }
5656
Brad Ebinger919631e2021-06-02 17:46:35 -07005657 /**
5658 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5659 * for the given slot ID or no ImsResolver instance has been created.
5660 * @param slotId The slot ID that the IMS service is created for.
5661 * @throws ImsException If there is no ImsService configured for this slot.
5662 */
5663 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5664 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5665 ImsFeature.FEATURE_MMTEL)) {
5666 throw new ImsException("This subscription does not support MMTEL over IMS",
5667 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5668 }
5669 }
5670
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005671 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005672 int slotId = SubscriptionManager.getSlotIndex(subId);
5673 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005674 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5675 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005676 }
5677 return slotId;
5678 }
5679
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005680 private int getSlotIndex(int subId) {
5681 int slotId = SubscriptionManager.getSlotIndex(subId);
5682 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5683 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5684 }
5685 return slotId;
5686 }
5687
Wink Saville36469e72014-06-11 15:17:00 -07005688 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005689 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005690 */
5691 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005692 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5693 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005694 try {
5695 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5696 } catch (SecurityException se) {
5697 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5698 throw new SecurityException("Package " + callingPackage + " does not belong to "
5699 + Binder.getCallingUid());
5700 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005701 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005702 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005703 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005704 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005705 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005706 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005707 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005708 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5709 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005710
joonhunshin4ac60942023-11-15 15:23:39 +00005711 enforceTelephonyFeatureWithException(callingPackage,
5712 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber");
5713
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005714 final long identity = Binder.clearCallingIdentity();
5715 try {
5716 final Phone phone = getPhone(subId);
5717 if (phone != null) {
5718 return phone.getServiceState().getDataNetworkType();
5719 } else {
5720 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5721 }
5722 } finally {
5723 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005724 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005725 }
5726
5727 /**
5728 * Returns the data network type
5729 */
5730 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005731 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005732 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005733 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005734 }
5735
5736 /**
5737 * Returns the data network type for a subId
5738 */
5739 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005740 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5741 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005742 String functionName = "getDataNetworkTypeForSubscriber";
5743 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5744 mApp, functionName)) {
5745 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5746 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5747 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5748 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005749 }
5750
joonhunshin4ac60942023-11-15 15:23:39 +00005751 enforceTelephonyFeatureWithException(callingPackage,
5752 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber");
5753
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005754 final long identity = Binder.clearCallingIdentity();
5755 try {
5756 final Phone phone = getPhone(subId);
5757 if (phone != null) {
5758 return phone.getServiceState().getDataNetworkType();
5759 } else {
5760 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5761 }
5762 } finally {
5763 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005764 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005765 }
5766
5767 /**
Wink Saville36469e72014-06-11 15:17:00 -07005768 * Returns the Voice network type for a subId
5769 */
5770 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005771 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5772 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005773 String functionName = "getVoiceNetworkTypeForSubscriber";
5774 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5775 mApp, functionName)) {
5776 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5777 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5778 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5779 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005780 }
5781
joonhunshin4ac60942023-11-15 15:23:39 +00005782 enforceTelephonyFeatureWithException(callingPackage,
5783 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber");
5784
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005785 final long identity = Binder.clearCallingIdentity();
5786 try {
5787 final Phone phone = getPhone(subId);
5788 if (phone != null) {
5789 return phone.getServiceState().getVoiceNetworkType();
5790 } else {
5791 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5792 }
5793 } finally {
5794 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005795 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005796 }
5797
5798 /**
5799 * @return true if a ICC card is present
5800 */
5801 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005802 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005803 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005804 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005805 }
5806
5807 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005808 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005809 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005810 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005811 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00005812 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5813 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex");
5814
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005815 final long identity = Binder.clearCallingIdentity();
5816 try {
5817 final Phone phone = PhoneFactory.getPhone(slotIndex);
5818 if (phone != null) {
5819 return phone.getIccCard().hasIccCard();
5820 } else {
5821 return false;
5822 }
5823 } finally {
5824 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005825 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005826 }
5827
5828 /**
5829 * Return if the current radio is LTE on CDMA. This
5830 * is a tri-state return value as for a period of time
5831 * the mode may be unknown.
5832 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005833 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005834 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005835 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005836 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005837 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005838 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5839 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5840 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005841 }
5842
Sanket Padawe356d7632015-06-22 14:03:32 -07005843 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005844 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5845 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005846 try {
5847 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5848 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005849 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5850 }
5851
joonhunshin4ac60942023-11-15 15:23:39 +00005852 enforceTelephonyFeatureWithException(callingPackage,
5853 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber");
5854
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005855 final long identity = Binder.clearCallingIdentity();
5856 try {
5857 final Phone phone = getPhone(subId);
5858 if (phone == null) {
5859 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5860 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005861 return TelephonyProperties.lte_on_cdma_device()
5862 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005863 }
5864 } finally {
5865 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005866 }
Wink Saville36469e72014-06-11 15:17:00 -07005867 }
5868
Wink Saville36469e72014-06-11 15:17:00 -07005869 /**
5870 * {@hide}
5871 * Returns Default subId, 0 in the case of single standby.
5872 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005873 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005874 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005875 }
5876
Shishir Agrawala9f32182016-04-12 12:00:16 -07005877 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005878 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005879 }
5880
Wink Savilleb564aae2014-10-23 10:18:09 -07005881 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005882 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005883 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005884
Pengquan Menge92a50d2018-09-21 15:54:48 -07005885 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005886 return getSubscriptionManagerService().isActiveSubId(subId,
5887 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005888 }
5889
Ihab Awadf2177b72013-11-25 13:33:23 -08005890 /**
5891 * @see android.telephony.TelephonyManager.WifiCallingChoices
5892 */
5893 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005894 final long identity = Binder.clearCallingIdentity();
5895 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005896 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005897 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5898 getWhenToMakeWifiCallsDefaultPreference());
5899 } finally {
5900 Binder.restoreCallingIdentity(identity);
5901 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005902 }
5903
5904 /**
5905 * @see android.telephony.TelephonyManager.WifiCallingChoices
5906 */
5907 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005908 final long identity = Binder.clearCallingIdentity();
5909 try {
5910 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005911 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005912 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5913 } finally {
5914 Binder.restoreCallingIdentity(identity);
5915 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005916 }
5917
Sailesh Nepald1e68152013-12-12 19:08:02 -08005918 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005919 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005920 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005921 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005922
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005923 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5924 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5925 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005926 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005927 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005928 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005929 }
5930 return PhoneFactory.getPhone(phoneId);
5931 }
5932
Shishir Agrawal566b7612013-10-28 14:41:00 -07005933 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005934 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005935 @NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00005936
Rambo Wanga1782702021-11-10 20:15:19 -08005937 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5938 /*message=*/ "iccOpenLogicalChannel");
5939
5940 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5941 // Verify that the callingPackage in the request belongs to the calling UID
5942 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5943
joonhunshin4ac60942023-11-15 15:23:39 +00005944 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5945 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel");
5946
Rambo Wanga1782702021-11-10 20:15:19 -08005947 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005948 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005949
Rambo Wanga1782702021-11-10 20:15:19 -08005950 private Phone getPhoneFromValidIccLogicalChannelRequest(
5951 @NonNull IccLogicalChannelRequest request, String message) {
5952 Phone phone;
5953 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5954 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5955 mApp, request.subId, message);
5956 phone = getPhoneFromSubId(request.subId);
5957 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5958 enforceModifyPermission();
5959 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5960 } else {
5961 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005962 }
Rambo Wanga1782702021-11-10 20:15:19 -08005963 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005964 }
5965
5966 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005967 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005968 final long identity = Binder.clearCallingIdentity();
5969 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005970 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005971 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005972 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5973 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005974 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5975 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005976 loge("The calling package is not allowed to access ISD-R.");
5977 throw new SecurityException(
5978 "The calling package is not allowed to access ISD-R.");
5979 }
Derek Tan740e1672017-06-27 14:56:27 -07005980 }
Derek Tan740e1672017-06-27 14:56:27 -07005981
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005982 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005983 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5984 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005985 return response;
5986 } finally {
5987 Binder.restoreCallingIdentity(identity);
5988 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005989 }
5990
5991 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005992 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00005993 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5994 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel");
5995
Rambo Wanga1782702021-11-10 20:15:19 -08005996 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5997 /*message=*/"iccCloseLogicalChannel");
5998
5999 if (DBG) log("iccCloseLogicalChannel: request=" + request);
6000
6001 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006002 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006003
Rambo Wanga1782702021-11-10 20:15:19 -08006004 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
6005 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08006006 // before this feature is enabled, this API should only return false if
6007 // the operation fails instead of throwing runtime exception for
6008 // backward-compatibility.
6009 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
6010 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006011 final long identity = Binder.clearCallingIdentity();
6012 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006013 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08006014 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006015 }
Chen Xue9d737e2022-01-01 23:41:31 -08006016 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08006017 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08006018 Boolean success = false;
6019 if (result instanceof RuntimeException) {
6020 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08006021 if (shouldThrowExceptionOnFailure) {
6022 throw (RuntimeException) result;
6023 } else {
6024 return false;
6025 }
Chen Xue9d737e2022-01-01 23:41:31 -08006026 } else if (result instanceof Boolean) {
6027 success = (Boolean) result;
6028 } else {
6029 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
6030 }
Rambo Wanga1782702021-11-10 20:15:19 -08006031 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006032 return success;
6033 } finally {
6034 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006035 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006036 }
6037
6038 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006039 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07006040 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006041 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6042 mApp, subId, "iccTransmitApduLogicalChannel");
joonhunshin4ac60942023-11-15 15:23:39 +00006043
6044 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6045 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel");
6046
Jordan Liu4c733742019-02-28 12:03:40 -08006047 if (DBG) {
6048 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
6049 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
6050 + p3 + " data=" + data);
6051 }
6052 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
6053 command, p1, p2, p3, data);
6054 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006055
Jordan Liu4c733742019-02-28 12:03:40 -08006056 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006057 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006058 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006059 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006060
6061 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6062 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
6063 "iccTransmitApduLogicalChannelBySlot");
6064
Jordan Liu4c733742019-02-28 12:03:40 -08006065 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006066 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006067 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
6068 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006069 }
6070 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006071 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
6072 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006073 }
6074
6075 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
6076 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006077 final long identity = Binder.clearCallingIdentity();
6078 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07006079 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006080 return "";
6081 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006082
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006083 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006084 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
6085 null /* workSource */);
6086 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006087
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006088 // Append the returned status code to the end of the response payload.
6089 String s = Integer.toHexString(
6090 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6091 if (response.payload != null) {
6092 s = IccUtils.bytesToHexString(response.payload) + s;
6093 }
6094 return s;
6095 } finally {
6096 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006097 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006098 }
Jake Hambye994d462014-02-03 13:10:13 -08006099
Evan Charltonc66da362014-05-16 14:06:40 -07006100 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006101 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
6102 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006103 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6104 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006105 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006106
6107 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6108 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel");
6109
Jordan Liu4c733742019-02-28 12:03:40 -08006110 if (DBG) {
6111 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
6112 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
6113 }
6114 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
6115 cla, command, p1, p2, p3, data);
6116 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006117
Jordan Liu4c733742019-02-28 12:03:40 -08006118 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006119 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006120 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006121 enforceModifyPermission();
6122 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006123
6124 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6125 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot");
6126
Jordan Liu4c733742019-02-28 12:03:40 -08006127 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006128 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006129 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
6130 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006131 }
6132
6133 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006134 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
6135 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006136 }
6137
6138 // open APDU basic channel assuming the caller has sufficient permissions
6139 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
6140 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006141 final long identity = Binder.clearCallingIdentity();
6142 try {
6143 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
6144 && TextUtils.equals(ISDR_AID, data)) {
6145 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006146 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6147 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006148 if (bestComponent == null
6149 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
6150 loge("The calling package is not allowed to select ISD-R.");
6151 throw new SecurityException(
6152 "The calling package is not allowed to select ISD-R.");
6153 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006154 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006155
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006156 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006157 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
6158 null /* workSource */);
6159 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006160
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006161 // Append the returned status code to the end of the response payload.
6162 String s = Integer.toHexString(
6163 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6164 if (response.payload != null) {
6165 s = IccUtils.bytesToHexString(response.payload) + s;
6166 }
6167 return s;
6168 } finally {
6169 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006170 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006171 }
6172
6173 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006174 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006175 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006176 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6177 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006178
joonhunshin4ac60942023-11-15 15:23:39 +00006179 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6180 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO");
6181
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006182 final long identity = Binder.clearCallingIdentity();
6183 try {
6184 if (DBG) {
6185 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
6186 + p1 + " " + p2 + " " + p3 + ":" + filePath);
6187 }
6188
6189 IccIoResult response =
6190 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
6191 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
6192 subId);
6193
6194 if (DBG) {
6195 log("Exchange SIM_IO [R]" + response);
6196 }
6197
6198 byte[] result = null;
6199 int length = 2;
6200 if (response.payload != null) {
6201 length = 2 + response.payload.length;
6202 result = new byte[length];
6203 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
6204 } else {
6205 result = new byte[length];
6206 }
6207
6208 result[length - 1] = (byte) response.sw2;
6209 result[length - 2] = (byte) response.sw1;
6210 return result;
6211 } finally {
6212 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006213 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006214 }
6215
Nathan Haroldb3014052017-01-25 15:57:32 -08006216 /**
6217 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
6218 * on a particular subscription
6219 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006220 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
6221 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07006222 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006223 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07006224 return null;
6225 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006226
joonhunshin4ac60942023-11-15 15:23:39 +00006227 enforceTelephonyFeatureWithException(callingPackage,
6228 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns");
6229
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006230 final long identity = Binder.clearCallingIdentity();
6231 try {
6232 if (appType != TelephonyManager.APPTYPE_USIM
6233 && appType != TelephonyManager.APPTYPE_SIM) {
6234 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
6235 return null;
6236 }
6237 Object response = sendRequest(
6238 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
6239 if (response instanceof String[]) {
6240 return (String[]) response;
6241 }
yincheng zhao2737e882019-09-06 17:06:54 -07006242 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006243 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08006244 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006245 } finally {
6246 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08006247 }
Nathan Haroldb3014052017-01-25 15:57:32 -08006248 }
6249
yincheng zhao2737e882019-09-06 17:06:54 -07006250 /**
6251 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
6252 * subscription.
6253 *
6254 * @param subId the id of the subscription.
6255 * @param appType the uicc app type, must be USIM or SIM.
6256 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
6257 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006258 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07006259 * @return number of fplmns that is successfully written to the SIM.
6260 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006261 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
6262 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07006263 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6264 mApp, subId, "setForbiddenPlmns");
6265
joonhunshin4ac60942023-11-15 15:23:39 +00006266 enforceTelephonyFeatureWithException(callingPackage,
6267 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns");
6268
yincheng zhao2737e882019-09-06 17:06:54 -07006269 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
6270 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
6271 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
6272 }
6273 if (fplmns == null) {
6274 throw new IllegalArgumentException("Fplmn List provided is null");
6275 }
6276 for (String fplmn : fplmns) {
6277 if (!CellIdentity.isValidPlmn(fplmn)) {
6278 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
6279 }
6280 }
6281 final long identity = Binder.clearCallingIdentity();
6282 try {
6283 Object response = sendRequest(
6284 CMD_SET_FORBIDDEN_PLMNS,
6285 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
6286 subId);
6287 return (int) response;
6288 } finally {
6289 Binder.restoreCallingIdentity(identity);
6290 }
6291 }
6292
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006293 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006294 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006295 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6296 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07006297
joonhunshin4ac60942023-11-15 15:23:39 +00006298 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6299 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus");
6300
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006301 final long identity = Binder.clearCallingIdentity();
6302 try {
6303 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
6304 if (response.payload == null) {
6305 return "";
6306 }
Evan Charltonc66da362014-05-16 14:06:40 -07006307
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006308 // Append the returned status code to the end of the response payload.
6309 String s = Integer.toHexString(
6310 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6311 s = IccUtils.bytesToHexString(response.payload) + s;
6312 return s;
6313 } finally {
6314 Binder.restoreCallingIdentity(identity);
6315 }
Evan Charltonc66da362014-05-16 14:06:40 -07006316 }
6317
Jake Hambye994d462014-02-03 13:10:13 -08006318 /**
6319 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6320 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6321 *
6322 * @param itemID the ID of the item to read
6323 * @return the NV item as a String, or null on error.
6324 */
6325 @Override
6326 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006327 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006328 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6329 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006330
6331 final long identity = Binder.clearCallingIdentity();
6332 try {
6333 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07006334 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006335 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
6336 return value;
6337 } finally {
6338 Binder.restoreCallingIdentity(identity);
6339 }
Jake Hambye994d462014-02-03 13:10:13 -08006340 }
6341
6342 /**
6343 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6344 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6345 *
6346 * @param itemID the ID of the item to read
6347 * @param itemValue the value to write, as a String
6348 * @return true on success; false on any failure
6349 */
6350 @Override
6351 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006352 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006353 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6354 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006355
6356 final long identity = Binder.clearCallingIdentity();
6357 try {
6358 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6359 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006360 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006361 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6362 return success;
6363 } finally {
6364 Binder.restoreCallingIdentity(identity);
6365 }
Jake Hambye994d462014-02-03 13:10:13 -08006366 }
6367
6368 /**
6369 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6370 * Used for device configuration by some CDMA operators.
6371 *
6372 * @param preferredRoamingList byte array containing the new PRL
6373 * @return true on success; false on any failure
6374 */
6375 @Override
6376 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006377 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6378 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006379
6380 final long identity = Binder.clearCallingIdentity();
6381 try {
6382 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6383 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6384 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6385 return success;
6386 } finally {
6387 Binder.restoreCallingIdentity(identity);
6388 }
Jake Hambye994d462014-02-03 13:10:13 -08006389 }
6390
6391 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006392 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006393 * Used for device configuration by some CDMA operators.
6394 *
chen xu6dac5ab2018-10-26 17:39:23 -07006395 * @param slotIndex - device slot.
6396 *
Jake Hambye994d462014-02-03 13:10:13 -08006397 * @return true on success; false on any failure
6398 */
6399 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006400 public boolean resetModemConfig(int slotIndex) {
6401 Phone phone = PhoneFactory.getPhone(slotIndex);
6402 if (phone != null) {
6403 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6404 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006405
joonhunshin4ac60942023-11-15 15:23:39 +00006406 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6407 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig");
6408
chen xu6dac5ab2018-10-26 17:39:23 -07006409 final long identity = Binder.clearCallingIdentity();
6410 try {
6411 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6412 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6413 return success;
6414 } finally {
6415 Binder.restoreCallingIdentity(identity);
6416 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006417 }
chen xu6dac5ab2018-10-26 17:39:23 -07006418 return false;
6419 }
6420
6421 /**
6422 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6423 *
6424 * @param slotIndex - device slot.
6425 *
6426 * @return true on success; false on any failure
6427 */
6428 @Override
6429 public boolean rebootModem(int slotIndex) {
6430 Phone phone = PhoneFactory.getPhone(slotIndex);
6431 if (phone != null) {
6432 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6433 mApp, phone.getSubId(), "rebootModem");
6434
joonhunshin4ac60942023-11-15 15:23:39 +00006435 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6436 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem");
6437
chen xu6dac5ab2018-10-26 17:39:23 -07006438 final long identity = Binder.clearCallingIdentity();
6439 try {
6440 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6441 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6442 return success;
6443 } finally {
6444 Binder.restoreCallingIdentity(identity);
6445 }
6446 }
6447 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006448 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006449
Brad Ebinger51f743a2017-01-23 13:50:20 -08006450 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006451 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6452 * {@link #disableIms(int)}.
6453 * @param slotIndex device slot.
6454 */
6455 public void resetIms(int slotIndex) {
6456 enforceModifyPermission();
6457
joonhunshin4ac60942023-11-15 15:23:39 +00006458 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6459 PackageManager.FEATURE_TELEPHONY_IMS, "resetIms");
6460
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006461 final long identity = Binder.clearCallingIdentity();
6462 try {
6463 if (mImsResolver == null) {
6464 // may happen if the does not support IMS.
6465 return;
6466 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006467 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006468 } finally {
6469 Binder.restoreCallingIdentity(identity);
6470 }
6471 }
6472
6473 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006474 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6475 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006476 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006477 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006478 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006479
6480 final long identity = Binder.clearCallingIdentity();
6481 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006482 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006483 // may happen if the device does not support IMS.
6484 return;
6485 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006486 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006487 } finally {
6488 Binder.restoreCallingIdentity(identity);
6489 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006490 }
6491
6492 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006493 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6494 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006495 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006496 public void disableIms(int slotId) {
6497 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006498
6499 final long identity = Binder.clearCallingIdentity();
6500 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006501 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006502 // may happen if the device does not support IMS.
6503 return;
6504 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006505 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006506 } finally {
6507 Binder.restoreCallingIdentity(identity);
6508 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006509 }
6510
6511 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006512 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6513 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006514 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006515 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006516 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006517 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006518
6519 final long identity = Binder.clearCallingIdentity();
6520 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006521 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006522 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6523 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006524 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006525 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006526 } finally {
6527 Binder.restoreCallingIdentity(identity);
6528 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006529 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006530 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006531 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6532 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006533 @Override
6534 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006535 enforceModifyPermission();
6536
6537 final long identity = Binder.clearCallingIdentity();
6538 try {
6539 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006540 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006541 } finally {
6542 Binder.restoreCallingIdentity(identity);
6543 }
6544 }
6545
6546 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006547 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006548 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006549 */
6550 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6551 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006552
6553 final long identity = Binder.clearCallingIdentity();
6554 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006555 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006556 // may happen if the device does not support IMS.
6557 return null;
6558 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006559 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006560 } finally {
6561 Binder.restoreCallingIdentity(identity);
6562 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006563 }
6564
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006565 /**
6566 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006567 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006568 */
6569 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6570 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006571
6572 final long identity = Binder.clearCallingIdentity();
6573 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006574 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006575 // may happen if the device does not support IMS.
6576 return null;
6577 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006578 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006579 } finally {
6580 Binder.restoreCallingIdentity(identity);
6581 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006582 }
6583
Brad Ebinger884c07b2018-02-15 16:17:40 -08006584 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006585 * Sets the ImsService Package Name that Telephony will bind to.
6586 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006587 * @param slotIndex the slot ID that the ImsService should bind for.
6588 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006589 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006590 * @param featureTypes An integer array of feature types associated with a packageName.
6591 * @param packageName The name of the package that the current configuration will be replaced
6592 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006593 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006594 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006595 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6596 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006597 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006598 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006599 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006600
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006601 final long identity = Binder.clearCallingIdentity();
6602 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006603 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006604 // may happen if the device does not support IMS.
6605 return false;
6606 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006607 Map<Integer, String> featureConfig = new HashMap<>();
6608 for (int featureType : featureTypes) {
6609 featureConfig.put(featureType, packageName);
6610 }
6611 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6612 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006613 } finally {
6614 Binder.restoreCallingIdentity(identity);
6615 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006616 }
6617
6618 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006619 * Clears any carrier ImsService overrides for the slot index specified that were previously
6620 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6621 *
6622 * This should only be used for testing.
6623 *
6624 * @param slotIndex the slot ID that the ImsService should bind for.
6625 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6626 */
6627 @Override
6628 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006629 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6630 "clearCarrierImsServiceOverride");
6631 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006632 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006633
6634 final long identity = Binder.clearCallingIdentity();
6635 try {
6636 if (mImsResolver == null) {
6637 // may happen if the device does not support IMS.
6638 return false;
6639 }
6640 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6641 } finally {
6642 Binder.restoreCallingIdentity(identity);
6643 }
6644 }
6645
6646 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006647 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006648 *
6649 * @param slotId The slot that the ImsService is associated with.
6650 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6651 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006652 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006653 * @return the package name of the ImsService configuration.
6654 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006655 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6656 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006657 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006658 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6659 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006660
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006661 final long identity = Binder.clearCallingIdentity();
6662 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006663 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006664 // may happen if the device does not support IMS.
6665 return "";
6666 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006667 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006668 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6669 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006670 } finally {
6671 Binder.restoreCallingIdentity(identity);
6672 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006673 }
6674
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006675 /**
6676 * Get the MmTelFeature state associated with the requested subscription id.
6677 * @param subId The subscription that the MmTelFeature is associated with.
6678 * @param callback A callback with an integer containing the
6679 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6680 */
6681 @Override
6682 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6683 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006684 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6685 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6686 "IMS not available on device.");
6687 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006688 final long token = Binder.clearCallingIdentity();
6689 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006690 int slotId = getSlotIndex(subId);
6691 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6692 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6693 + subId + "'");
6694 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6695 }
6696 verifyImsMmTelConfiguredOrThrow(slotId);
6697 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6698 try {
6699 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6700 } catch (RemoteException e) {
6701 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6702 + "Ignore");
6703 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006704 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006705 } catch (ImsException e) {
6706 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006707 } finally {
6708 Binder.restoreCallingIdentity(token);
6709 }
6710 }
6711
Daniel Brightbb5840b2021-01-12 15:48:18 -08006712 /**
6713 * Sets the ims registration state on all valid {@link Phone}s.
6714 */
6715 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006716 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006717
6718 final long identity = Binder.clearCallingIdentity();
6719 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006720 // NOTE: Before S, this method only set the default phone.
6721 for (final Phone phone : PhoneFactory.getPhones()) {
6722 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6723 phone.setImsRegistrationState(registered);
6724 }
6725 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006726 } finally {
6727 Binder.restoreCallingIdentity(identity);
6728 }
Wink Saville36469e72014-06-11 15:17:00 -07006729 }
6730
6731 /**
Stuart Scott54788802015-03-30 13:18:01 -07006732 * Set the network selection mode to automatic.
6733 *
6734 */
6735 @Override
6736 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006737 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6738 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006739
joonhunshin4ac60942023-11-15 15:23:39 +00006740 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6741 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic");
6742
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006743 final long identity = Binder.clearCallingIdentity();
6744 try {
shilufc958392020-01-20 11:36:01 -08006745 if (!isActiveSubscription(subId)) {
6746 return;
6747 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006748 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006749 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6750 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006751 } finally {
6752 Binder.restoreCallingIdentity(identity);
6753 }
Stuart Scott54788802015-03-30 13:18:01 -07006754 }
6755
Jack Yud10cdd42020-09-28 20:28:01 -07006756 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006757 * Ask the radio to connect to the input network and change selection mode to manual.
6758 *
6759 * @param subId the id of the subscription.
6760 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6761 * the operator to attach to.
6762 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6763 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6764 * normal network selection next time.
6765 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006766 */
6767 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006768 public boolean setNetworkSelectionModeManual(
6769 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006770 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6771 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006772
joonhunshin4ac60942023-11-15 15:23:39 +00006773 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6774 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual");
6775
Jack Yu285100e2022-12-02 22:48:35 -08006776 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006777 if (!isActiveSubscription(subId)) {
6778 return false;
6779 }
6780
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006781 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006782 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006783 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006784 if (DBG) {
6785 log("setNetworkSelectionModeManual: subId: " + subId
6786 + " operator: " + operatorInfo);
6787 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006788 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6789 } finally {
6790 Binder.restoreCallingIdentity(identity);
6791 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006792 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006793 /**
shilu84f6e8b2019-12-19 13:58:01 -08006794 * Get the manual network selection
6795 *
6796 * @param subId the id of the subscription.
6797 *
6798 * @return the previously saved user selected PLMN
6799 */
6800 @Override
6801 public String getManualNetworkSelectionPlmn(int subId) {
6802 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006803 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6804 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006805
joonhunshin4ac60942023-11-15 15:23:39 +00006806 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6807 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn");
6808
shilu84f6e8b2019-12-19 13:58:01 -08006809 final long identity = Binder.clearCallingIdentity();
6810 try {
6811 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006812 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006813 }
6814
6815 final Phone phone = getPhone(subId);
6816 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006817 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006818 }
6819 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6820 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006821 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006822 } finally {
6823 Binder.restoreCallingIdentity(identity);
6824 }
6825 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006826
6827 /**
6828 * Scans for available networks.
6829 */
6830 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006831 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6832 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006833 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6834 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006835 LocationAccessPolicy.LocationPermissionResult locationResult =
6836 LocationAccessPolicy.checkLocationPermission(mApp,
6837 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6838 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006839 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006840 .setCallingPid(Binder.getCallingPid())
6841 .setCallingUid(Binder.getCallingUid())
6842 .setMethod("getCellNetworkScanResults")
6843 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006844 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6845 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006846 .build());
6847 switch (locationResult) {
6848 case DENIED_HARD:
6849 throw new SecurityException("Not allowed to access scan results -- location");
6850 case DENIED_SOFT:
6851 return null;
6852 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006853
Pengquan Menga1bb6272018-09-06 09:59:22 -07006854 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006855 try {
6856 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006857 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006858 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006859 } finally {
6860 Binder.restoreCallingIdentity(identity);
6861 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006862 }
6863
6864 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006865 * Get the call forwarding info, given the call forwarding reason.
6866 */
6867 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006868 public void getCallForwarding(int subId, int callForwardingReason,
6869 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006870 enforceReadPrivilegedPermission("getCallForwarding");
joonhunshin4ac60942023-11-15 15:23:39 +00006871
6872 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6873 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding");
6874
Shuo Qian4a594052020-01-23 11:59:30 -08006875 long identity = Binder.clearCallingIdentity();
6876 try {
6877 if (DBG) {
6878 log("getCallForwarding: subId " + subId
6879 + " callForwardingReason" + callForwardingReason);
6880 }
Hall Liu27d24262020-09-18 19:04:59 -07006881
6882 Phone phone = getPhone(subId);
6883 if (phone == null) {
6884 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006885 callback.onError(
6886 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006887 } catch (RemoteException e) {
6888 // ignore
6889 }
6890 return;
6891 }
6892
6893 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6894 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6895 @Override
6896 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6897 try {
6898 callback.onCallForwardingInfoAvailable(info);
6899 } catch (RemoteException e) {
6900 // ignore
6901 }
6902 }
6903
6904 @Override
6905 public void onError(int error) {
6906 try {
6907 callback.onError(error);
6908 } catch (RemoteException e) {
6909 // ignore
6910 }
6911 }
6912 });
6913 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006914 } finally {
6915 Binder.restoreCallingIdentity(identity);
6916 }
6917 }
6918
6919 /**
6920 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6921 * reason, the number to forward, and the timeout before the forwarding is attempted.
6922 */
6923 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006924 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6925 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006926 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006927
6928 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6929 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding");
6930
Shuo Qian4a594052020-01-23 11:59:30 -08006931 long identity = Binder.clearCallingIdentity();
6932 try {
6933 if (DBG) {
6934 log("setCallForwarding: subId " + subId
6935 + " callForwardingInfo" + callForwardingInfo);
6936 }
Hall Liu27d24262020-09-18 19:04:59 -07006937
6938 Phone phone = getPhone(subId);
6939 if (phone == null) {
6940 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006941 callback.accept(
6942 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006943 } catch (RemoteException e) {
6944 // ignore
6945 }
6946 return;
6947 }
6948
6949 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6950 FunctionalUtils.ignoreRemoteException(callback::accept));
6951
6952 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006953 } finally {
6954 Binder.restoreCallingIdentity(identity);
6955 }
6956 }
6957
6958 /**
Hall Liu27d24262020-09-18 19:04:59 -07006959 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006960 */
6961 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006962 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006963 enforceReadPrivilegedPermission("getCallWaitingStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00006964
6965 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6966 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus");
6967
Shuo Qian4a594052020-01-23 11:59:30 -08006968 long identity = Binder.clearCallingIdentity();
6969 try {
Hall Liu27d24262020-09-18 19:04:59 -07006970 Phone phone = getPhone(subId);
6971 if (phone == null) {
6972 try {
6973 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6974 } catch (RemoteException e) {
6975 // ignore
6976 }
6977 return;
6978 }
SongFerngWang0e767992021-03-31 22:08:45 +08006979 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6980 PersistableBundle c = configManager.getConfigForSubId(subId);
6981 boolean requireUssd = c.getBoolean(
6982 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006983
Shuo Qian4a594052020-01-23 11:59:30 -08006984 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006985 if (requireUssd) {
6986 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6987 getSubscriptionCarrierId(subId));
6988 String newUssdCommand = "";
6989 try {
6990 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006991 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006992 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6993 } catch (NullPointerException e) {
6994 loge("Failed to generate USSD number" + e);
6995 }
6996 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6997 mMainThreadHandler, callback, carrierXmlParser,
6998 CarrierXmlParser.SsEntry.SSAction.QUERY);
6999 final String ussdCommand = newUssdCommand;
7000 Executors.newSingleThreadExecutor().execute(() -> {
7001 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7002 });
7003 } else {
7004 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
7005 callback::accept);
7006 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
7007 }
Shuo Qian4a594052020-01-23 11:59:30 -08007008 } finally {
7009 Binder.restoreCallingIdentity(identity);
7010 }
7011 }
7012
7013 /**
Hall Liu27d24262020-09-18 19:04:59 -07007014 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007015 */
7016 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007017 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007018 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007019
7020 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7021 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus");
7022
Shuo Qian4a594052020-01-23 11:59:30 -08007023 long identity = Binder.clearCallingIdentity();
7024 try {
Hall Liu27d24262020-09-18 19:04:59 -07007025 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
7026
7027 Phone phone = getPhone(subId);
7028 if (phone == null) {
7029 try {
7030 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7031 } catch (RemoteException e) {
7032 // ignore
7033 }
7034 return;
7035 }
7036
SongFerngWang0e767992021-03-31 22:08:45 +08007037 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7038 PersistableBundle c = configManager.getConfigForSubId(subId);
7039 boolean requireUssd = c.getBoolean(
7040 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007041
SongFerngWang0e767992021-03-31 22:08:45 +08007042 if (DBG) log("getCallWaitingStatus: subId " + subId);
7043 if (requireUssd) {
7044 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7045 getSubscriptionCarrierId(subId));
7046 CarrierXmlParser.SsEntry.SSAction ssAction =
7047 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
7048 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
7049 String newUssdCommand = "";
7050 try {
7051 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007052 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007053 .makeCommand(ssAction, null);
7054 } catch (NullPointerException e) {
7055 loge("Failed to generate USSD number" + e);
7056 }
7057 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7058 mMainThreadHandler, callback, carrierXmlParser, ssAction);
7059 final String ussdCommand = newUssdCommand;
7060 Executors.newSingleThreadExecutor().execute(() -> {
7061 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7062 });
7063 } else {
7064 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
7065 FunctionalUtils.ignoreRemoteException(callback::accept));
7066
7067 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
7068 }
Shuo Qian4a594052020-01-23 11:59:30 -08007069 } finally {
7070 Binder.restoreCallingIdentity(identity);
7071 }
7072 }
7073
7074 /**
yinxub1bed742017-04-17 11:45:04 -07007075 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07007076 *
yinxub1bed742017-04-17 11:45:04 -07007077 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007078 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
7079 * location related information which will be sent if the caller already possess
7080 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07007081 * @param request contains the radio access networks with bands/channels to scan
7082 * @param messenger callback messenger for scan results or errors
7083 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07007084 * @return the id of the requested scan which can be used to stop the scan.
7085 */
7086 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007087 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
7088 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007089 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007090 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7091 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08007092 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007093 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
7094 if (!renounceFineLocationAccess) {
7095 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007096 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7097 .setCallingPackage(callingPackage)
7098 .setCallingFeatureId(callingFeatureId)
7099 .setCallingPid(Binder.getCallingPid())
7100 .setCallingUid(Binder.getCallingUid())
7101 .setMethod("requestNetworkScan")
7102 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7103 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7104 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7105 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007106 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08007107 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07007108 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
7109 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08007110 if (e != null) {
7111 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
7112 throw e;
7113 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07007114 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08007115 return TelephonyScanManager.INVALID_SCAN_ID;
7116 }
7117 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007118 }
joonhunshin4ac60942023-11-15 15:23:39 +00007119
7120 enforceTelephonyFeatureWithException(callingPackage,
7121 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan");
7122
Hall Liu912dfd32019-04-25 14:02:26 -07007123 int callingUid = Binder.getCallingUid();
7124 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07007125 final long identity = Binder.clearCallingIdentity();
7126 try {
7127 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07007128 renounceFineLocationAccess, request, messenger, binder,
7129 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07007130 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07007131 } finally {
7132 Binder.restoreCallingIdentity(identity);
7133 }
yinxu504e1392017-04-12 16:03:22 -07007134 }
7135
Hall Liub2ac8ef2019-02-28 15:56:23 -08007136 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07007137 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00007138 boolean hasCarrierPriv;
7139 final long identity = Binder.clearCallingIdentity();
7140 try {
7141 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
7142 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
7143 } finally {
7144 Binder.restoreCallingIdentity(identity);
7145 }
Hall Liu558027f2019-05-15 19:14:05 -07007146 boolean hasNetworkScanPermission =
7147 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007148 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07007149
7150 if (!hasCarrierPriv && !hasNetworkScanPermission) {
7151 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
7152 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08007153 }
7154
7155 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
7156 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08007157 if (ras.getChannels() != null && ras.getChannels().length > 0) {
7158 return new SecurityException("Specific channels must not be"
7159 + " scanned without location access.");
7160 }
7161 }
7162 }
7163
Hall Liub2ac8ef2019-02-28 15:56:23 -08007164 return null;
7165 }
7166
yinxu504e1392017-04-12 16:03:22 -07007167 /**
7168 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07007169 *
7170 * @param subId id of the subscription
7171 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07007172 */
7173 @Override
7174 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007175 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7176 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007177
Hall Liu912dfd32019-04-25 14:02:26 -07007178 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007179 final long identity = Binder.clearCallingIdentity();
7180 try {
Hall Liu912dfd32019-04-25 14:02:26 -07007181 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007182 } finally {
7183 Binder.restoreCallingIdentity(identity);
7184 }
yinxu504e1392017-04-12 16:03:22 -07007185 }
7186
7187 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08007188 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07007189 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08007190 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07007191 */
7192 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08007193 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08007194 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007195 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08007196 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007197
joonhunshin4ac60942023-11-15 15:23:39 +00007198 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7199 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask");
7200
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007201 final long identity = Binder.clearCallingIdentity();
7202 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007203 if (DBG) log("getAllowedNetworkTypesBitmask");
7204 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
7205 int networkTypesBitmask = (result != null ? result[0] : -1);
7206 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
7207 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007208 } finally {
7209 Binder.restoreCallingIdentity(identity);
7210 }
Jake Hamby7c27be32014-03-03 13:25:59 -08007211 }
7212
7213 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007214 * Get the allowed network types for certain reason.
7215 *
7216 * @param subId the id of the subscription.
7217 * @param reason the reason the allowed network type change is taking place
7218 * @return the allowed network types.
7219 */
7220 @Override
7221 public long getAllowedNetworkTypesForReason(int subId,
7222 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07007223 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007224 mApp, subId, "getAllowedNetworkTypesForReason");
joonhunshin4ac60942023-11-15 15:23:39 +00007225
7226 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7227 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesForReason");
7228
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007229 final long identity = Binder.clearCallingIdentity();
7230 try {
Jack Yu7247ac82023-03-02 23:52:10 -08007231 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007232 } finally {
7233 Binder.restoreCallingIdentity(identity);
7234 }
7235 }
7236
7237 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07007238 * Enable/Disable E-UTRA-NR Dual Connectivity
7239 * @param subId subscription id of the sim card
7240 * @param nrDualConnectivityState expected NR dual connectivity state
7241 * This can be passed following states
7242 * <ol>
7243 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
7244 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
7245 * <li>Disable NR dual connectivity and force secondary cell to be released
7246 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
7247 * </ol>
7248 * @return operation result.
7249 */
7250 @Override
7251 public int setNrDualConnectivityState(int subId,
7252 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
7253 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7254 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007255 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007256 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7257 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
7258 }
7259
Sooraj Sasindran37444802020-08-11 10:40:43 -07007260 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7261 final long identity = Binder.clearCallingIdentity();
7262 try {
7263 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
7264 nrDualConnectivityState, subId,
7265 workSource);
7266 if (DBG) log("enableNRDualConnectivity result: " + result);
7267 return result;
7268 } finally {
7269 Binder.restoreCallingIdentity(identity);
7270 }
7271 }
7272
7273 /**
7274 * Is E-UTRA-NR Dual Connectivity enabled
7275 * @return true if dual connectivity is enabled else false
7276 */
7277 @Override
7278 public boolean isNrDualConnectivityEnabled(int subId) {
7279 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007280 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07007281 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007282 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007283 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7284 return false;
7285 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07007286 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7287 final long identity = Binder.clearCallingIdentity();
7288 try {
7289 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
7290 null, subId, workSource);
7291 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
7292 return isEnabled;
7293 } finally {
7294 Binder.restoreCallingIdentity(identity);
7295 }
7296 }
7297
7298 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007299 * Set the allowed network types of the device and
7300 * provide the reason triggering the allowed network change.
7301 *
7302 * @param subId the id of the subscription.
7303 * @param reason the reason the allowed network type change is taking place
7304 * @param allowedNetworkTypes the allowed network types.
7305 * @return true on success; false on any failure.
7306 */
7307 @Override
7308 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08007309 @TelephonyManager.AllowedNetworkTypesReason int reason,
7310 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007311 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7312 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007313 // If the caller only has carrier privileges, then they should not be able to override
7314 // any network types which were set for security reasons.
7315 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
7316 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007317 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007318 throw new SecurityException(
7319 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007320 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007321 }
joonhunshin4ac60942023-11-15 15:23:39 +00007322
7323 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7324 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason");
7325
SongFerngWang3ef3e072020-12-21 16:41:52 +08007326 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007327 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08007328 return false;
7329 }
7330 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
7331 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007332 return false;
7333 }
7334
Jack Yu5b494332023-01-23 18:18:04 +00007335 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
7336 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007337
Jack Yue37dd262022-12-16 11:53:37 -08007338 Phone phone = getPhone(subId);
7339 if (phone == null) {
7340 return false;
7341 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007342
Jack Yue37dd262022-12-16 11:53:37 -08007343 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007344 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007345 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08007346 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007347
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007348 final long identity = Binder.clearCallingIdentity();
7349 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007350 Boolean success = (Boolean) sendRequest(
7351 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
7352 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
7353
7354 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
7355 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007356 } finally {
7357 Binder.restoreCallingIdentity(identity);
7358 }
7359 }
7360
7361 /**
Miaoa84611c2019-03-15 09:21:10 +08007362 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08007363 *
Miaoa84611c2019-03-15 09:21:10 +08007364 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07007365 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08007366 * @hide
7367 */
7368 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08007369 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007370 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007371
7372 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7373 PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber");
7374
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007375 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08007376 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007377 try {
Miaoa84611c2019-03-15 09:21:10 +08007378 if (phone != null) {
7379 return phone.hasMatchedTetherApnSetting();
7380 } else {
7381 return false;
7382 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007383 } finally {
7384 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007385 }
Junda Liu475951f2014-11-07 16:45:03 -08007386 }
7387
7388 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007389 * Get the user enabled state of Mobile Data.
7390 *
7391 * TODO: remove and use isUserDataEnabled.
7392 * This can't be removed now because some vendor codes
7393 * calls through ITelephony directly while they should
7394 * use TelephonyManager.
7395 *
7396 * @return true on enabled
7397 */
7398 @Override
7399 public boolean getDataEnabled(int subId) {
7400 return isUserDataEnabled(subId);
7401 }
7402
7403 /**
7404 * Get whether mobile data is enabled per user setting.
7405 *
7406 * There are other factors deciding whether mobile data is actually enabled, but they are
7407 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007408 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007409 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7410 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007411 *
7412 * @return {@code true} if data is enabled else {@code false}
7413 */
7414 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007415 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007416 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007417 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007418 try {
7419 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7420 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007421 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007422 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7423 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007424 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007425 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007426 mApp, subId, functionName);
7427
Robert Greenwalt646120a2014-05-23 11:54:03 -07007428 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007429
7430 final long identity = Binder.clearCallingIdentity();
7431 try {
Jack Yu285100e2022-12-02 22:48:35 -08007432 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007433 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7434 Phone phone = PhoneFactory.getPhone(phoneId);
7435 if (phone != null) {
7436 boolean retVal = phone.isUserDataEnabled();
7437 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7438 return retVal;
7439 } else {
7440 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7441 return false;
7442 }
7443 } finally {
7444 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007445 }
7446 }
7447
7448 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007449 * Checks if the device is capable of mobile data by considering whether whether the
7450 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7451 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007452 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007453 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007454 */
7455 @Override
7456 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007457 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007458 try {
7459 try {
7460 mApp.enforceCallingOrSelfPermission(
7461 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007462 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007463 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007464 try {
7465 mApp.enforceCallingOrSelfPermission(
7466 android.Manifest.permission.READ_PHONE_STATE,
7467 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007468 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007469 mApp.enforceCallingOrSelfPermission(
7470 permission.READ_BASIC_PHONE_STATE, functionName);
7471 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007472 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007473 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007474 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007475 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007476
joonhunshin4ac60942023-11-15 15:23:39 +00007477 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7478 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled");
7479
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007480 final long identity = Binder.clearCallingIdentity();
7481 try {
Jack Yu285100e2022-12-02 22:48:35 -08007482 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007483 Phone phone = PhoneFactory.getPhone(phoneId);
7484 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007485 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007486 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007487 return retVal;
7488 } else {
7489 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7490 return false;
7491 }
7492 } finally {
7493 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007494 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007495 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007496
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007497 /**
7498 * Check if data is enabled for a specific reason
7499 * @param subId Subscription index
7500 * @param reason the reason the data enable change is taking place
7501 * @return {@code true} if the overall data is enabled; {@code false} if not.
7502 */
7503 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007504 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007505 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007506 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007507 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007508 try {
7509 mApp.enforceCallingOrSelfPermission(
7510 android.Manifest.permission.ACCESS_NETWORK_STATE,
7511 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007512 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007513 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7514 functionName);
7515 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007516 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007517 try {
7518 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007519 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007520 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007521 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007522 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007523 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007524 }
7525
joonhunshin4ac60942023-11-15 15:23:39 +00007526 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7527 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007528
7529 final long identity = Binder.clearCallingIdentity();
7530 try {
Jack Yu285100e2022-12-02 22:48:35 -08007531 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007532 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007533 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007534 + " reason=" + reason);
7535 }
7536 Phone phone = PhoneFactory.getPhone(phoneId);
7537 if (phone != null) {
7538 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007539 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007540 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007541 return retVal;
7542 } else {
7543 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007544 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007545 + subId + " retVal=false");
7546 }
7547 return false;
7548 }
7549 } finally {
7550 Binder.restoreCallingIdentity(identity);
7551 }
7552 }
7553
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007554 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007555 public int getCarrierPrivilegeStatus(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00007556 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7557 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus");
7558
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007559 // No permission needed; this only lets the caller inspect their own status.
7560 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007561 }
Junda Liu29340342014-07-10 15:23:27 -07007562
7563 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007564 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007565 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
joonhunshin4ac60942023-11-15 15:23:39 +00007566
7567 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7568 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatusForUid");
7569
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007570 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7571 }
7572
7573 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7574 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007575 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007576 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007577 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7578 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007579 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7580 if (cpt == null) {
7581 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007582 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7583 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007584 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007585 }
7586
7587 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007588 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007589 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
joonhunshin4ac60942023-11-15 15:23:39 +00007590
7591 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7592 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage");
7593
chen xuf7e9fe82019-05-09 19:31:02 -07007594 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007595 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007596 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007597 Phone phone = getPhone(subId);
7598 if (phone == null) {
7599 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7600 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7601 }
7602 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7603 if (cpt == null) {
7604 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007605 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7606 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007607 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007608 }
7609
7610 @Override
7611 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007612 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007613
7614 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7615 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7616 "checkCarrierPrivilegesForPackageAnyPhone");
7617
Rambo Wange7209ce2022-02-23 13:41:02 -08007618 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7619 }
7620
7621 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007622 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007623 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007624 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007625 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007626 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7627 Phone phone = PhoneFactory.getPhone(phoneId);
7628 if (phone == null) {
7629 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007630 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007631 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7632 if (cpt == null) {
7633 continue;
7634 }
7635 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007636 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7637 break;
7638 }
7639 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007640 return result;
Junda Liu29340342014-07-10 15:23:27 -07007641 }
Derek Tan89e89d42014-07-08 17:00:10 -07007642
7643 @Override
Junda Liue64de782015-04-16 17:19:16 -07007644 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007645 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007646
7647 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7648 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7649 "getCarrierPackageNamesForIntentAndPhone");
7650
Rambo Wang8a247eb2022-02-08 21:11:18 +00007651 Phone phone = PhoneFactory.getPhone(phoneId);
7652 if (phone == null) {
7653 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007654 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007655 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7656 if (cpt == null) {
7657 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007658 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007659 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007660 }
7661
Amith Yamasani6e118872016-02-19 12:53:51 -08007662 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007663 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007664 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007665 Phone phone = PhoneFactory.getPhone(phoneId);
7666 if (phone == null) {
7667 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007668 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007669 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7670 if (cpt == null) {
7671 return Collections.emptyList();
7672 }
7673 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007674 }
7675
chen xuf7e9fe82019-05-09 19:31:02 -07007676 @Override
7677 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007678 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
joonhunshin4ac60942023-11-15 15:23:39 +00007679
7680 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7681 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7682 "getPackagesWithCarrierPrivilegesForAllPhones");
7683
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007684 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007685 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007686 try {
7687 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7688 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7689 }
7690 } finally {
7691 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007692 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007693 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007694 }
7695
Rambo Wang6812ffb2022-03-15 16:54:17 -07007696 @Override
7697 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7698 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7699
joonhunshin4ac60942023-11-15 15:23:39 +00007700 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7701 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7702 "getCarrierServicePackageNameForLogicalSlot");
7703
Rambo Wang6812ffb2022-03-15 16:54:17 -07007704 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7705 if (phone == null) {
7706 return null;
7707 }
7708 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7709 if (cpt == null) {
7710 return null;
7711 }
7712 return cpt.getCarrierServicePackageName();
7713 }
7714
Wink Savilleb564aae2014-10-23 10:18:09 -07007715 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007716 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007717 UiccPort port = phone == null ? null : phone.getUiccPort();
7718 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007719 return null;
7720 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007721 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007722 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007723 return null;
7724 }
7725 return iccId;
7726 }
7727
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007728 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007729 public void setCallComposerStatus(int subId, int status) {
7730 enforceModifyPermission();
7731
joonhunshin4ac60942023-11-15 15:23:39 +00007732 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7733 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus");
7734
Shuo Qiane4e11672020-12-15 22:15:33 -08007735 final long identity = Binder.clearCallingIdentity();
7736 try {
7737 Phone phone = getPhone(subId);
7738 if (phone != null) {
7739 Phone defaultPhone = phone.getImsPhone();
7740 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7741 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7742 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007743 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7744 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007745 }
7746 }
Shuo Qian284ae752020-12-22 19:10:14 -08007747 } catch (ImsException e) {
7748 throw new ServiceSpecificException(e.getCode());
7749 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007750 Binder.restoreCallingIdentity(identity);
7751 }
7752 }
7753
7754 @Override
7755 public int getCallComposerStatus(int subId) {
7756 enforceReadPrivilegedPermission("getCallComposerStatus");
7757
joonhunshin4ac60942023-11-15 15:23:39 +00007758 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7759 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus");
7760
Shuo Qiane4e11672020-12-15 22:15:33 -08007761 final long identity = Binder.clearCallingIdentity();
7762 try {
7763 Phone phone = getPhone(subId);
7764 if (phone != null) {
7765 Phone defaultPhone = phone.getImsPhone();
7766 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7767 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7768 return imsPhone.getCallComposerStatus();
7769 }
7770 }
7771 } finally {
7772 Binder.restoreCallingIdentity(identity);
7773 }
7774 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7775 }
7776
7777 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007778 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7779 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007780 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007781 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007782
joonhunshin4ac60942023-11-15 15:23:39 +00007783 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7784 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7785 "setLine1NumberForDisplayForSubscriber");
7786
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007787 final long identity = Binder.clearCallingIdentity();
7788 try {
7789 final String iccId = getIccId(subId);
7790 final Phone phone = getPhone(subId);
7791 if (phone == null) {
7792 return false;
7793 }
7794 final String subscriberId = phone.getSubscriberId();
7795
7796 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007797 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007798 + subscriberId + " to " + number);
7799 }
7800
7801 if (TextUtils.isEmpty(iccId)) {
7802 return false;
7803 }
7804
7805 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7806
7807 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7808 if (alphaTag == null) {
7809 editor.remove(alphaTagPrefKey);
7810 } else {
7811 editor.putString(alphaTagPrefKey, alphaTag);
7812 }
7813
7814 // Record both the line number and IMSI for this ICCID, since we need to
7815 // track all merged IMSIs based on line number
7816 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7817 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7818 if (number == null) {
7819 editor.remove(numberPrefKey);
7820 editor.remove(subscriberPrefKey);
7821 } else {
7822 editor.putString(numberPrefKey, number);
7823 editor.putString(subscriberPrefKey, subscriberId);
7824 }
7825
7826 editor.commit();
7827 return true;
7828 } finally {
7829 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007830 }
Derek Tan7226c842014-07-02 17:42:23 -07007831 }
7832
7833 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007834 public String getLine1NumberForDisplay(int subId, String callingPackage,
7835 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007836 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007837 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007838 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007839 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007840 return null;
7841 }
Derek Tan97ebb422014-09-05 16:55:38 -07007842
joonhunshin4ac60942023-11-15 15:23:39 +00007843 enforceTelephonyFeatureWithException(callingPackage,
7844 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay");
7845
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007846 final long identity = Binder.clearCallingIdentity();
7847 try {
7848 String iccId = getIccId(subId);
7849 if (iccId != null) {
7850 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7851 if (DBG_MERGE) {
7852 log("getLine1NumberForDisplay returning "
7853 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7854 }
7855 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007856 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007857 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7858 return null;
7859 } finally {
7860 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007861 }
Derek Tan7226c842014-07-02 17:42:23 -07007862 }
7863
7864 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007865 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7866 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007867 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007868 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007869 return null;
7870 }
Derek Tan97ebb422014-09-05 16:55:38 -07007871
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007872 final long identity = Binder.clearCallingIdentity();
7873 try {
7874 String iccId = getIccId(subId);
7875 if (iccId != null) {
7876 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7877 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7878 }
7879 return null;
7880 } finally {
7881 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007882 }
Derek Tan7226c842014-07-02 17:42:23 -07007883 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007884
7885 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007886 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7887 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007888 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7889 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007890 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007891 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007892 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007893 return null;
7894 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007895
Jordan Liub49b04b2019-05-06 14:45:15 -07007896 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7897 // the process, where TelephonyManager was instantiated.
7898 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007899 final long identity = Binder.clearCallingIdentity();
7900 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007901 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007902 final TelephonyManager tele = TelephonyManager.from(context);
7903 final SubscriptionManager sub = SubscriptionManager.from(context);
7904
7905 // Figure out what subscribers are currently active
7906 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007907
Jordan Liub49b04b2019-05-06 14:45:15 -07007908 // Only consider subs which match the current subId
7909 // This logic can be simplified. See b/131189269 for progress.
7910 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007911 activeSubscriberIds.add(tele.getSubscriberId(subId));
7912 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007913
7914 // First pass, find a number override for an active subscriber
7915 String mergeNumber = null;
7916 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7917 for (String key : prefs.keySet()) {
7918 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7919 final String subscriberId = (String) prefs.get(key);
7920 if (activeSubscriberIds.contains(subscriberId)) {
7921 final String iccId = key.substring(
7922 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7923 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7924 mergeNumber = (String) prefs.get(numberKey);
7925 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007926 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007927 + " for active subscriber " + subscriberId);
7928 }
7929 if (!TextUtils.isEmpty(mergeNumber)) {
7930 break;
7931 }
7932 }
7933 }
7934 }
7935
7936 // Shortcut when no active merged subscribers
7937 if (TextUtils.isEmpty(mergeNumber)) {
7938 return null;
7939 }
7940
7941 // Second pass, find all subscribers under that line override
7942 final ArraySet<String> result = new ArraySet<>();
7943 for (String key : prefs.keySet()) {
7944 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7945 final String number = (String) prefs.get(key);
7946 if (mergeNumber.equals(number)) {
7947 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7948 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7949 final String subscriberId = (String) prefs.get(subscriberKey);
7950 if (!TextUtils.isEmpty(subscriberId)) {
7951 result.add(subscriberId);
7952 }
7953 }
7954 }
7955 }
7956
7957 final String[] resultArray = result.toArray(new String[result.size()]);
7958 Arrays.sort(resultArray);
7959 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007960 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007961 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7962 }
7963 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007964 } finally {
7965 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007966 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007967 }
7968
7969 @Override
zoey chen38003472019-12-13 17:16:31 +08007970 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7971 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007972
joonhunshin4ac60942023-11-15 15:23:39 +00007973 enforceTelephonyFeatureWithException(callingPackage,
7974 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup");
7975
Malcolm Chen6ca97372019-07-01 16:28:21 -07007976 final long identity = Binder.clearCallingIdentity();
7977 try {
7978 final TelephonyManager telephonyManager = mApp.getSystemService(
7979 TelephonyManager.class);
7980 String subscriberId = telephonyManager.getSubscriberId(subId);
7981 if (subscriberId == null) {
7982 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007983 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007984 + subId);
7985 }
7986 return null;
7987 }
7988
Jack Yu3beaf9d2023-04-14 09:17:27 -07007989 final SubscriptionInfo info = getSubscriptionManagerService()
7990 .getSubscriptionInfo(subId);
7991 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07007992 // If it doesn't belong to any group, return just subscriberId of itself.
7993 if (groupUuid == null) {
7994 return new String[]{subscriberId};
7995 }
7996
7997 // Get all subscriberIds from the group.
7998 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07007999 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
8000 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
8001 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07008002 for (SubscriptionInfo subInfo : groupInfos) {
8003 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
8004 if (subscriberId != null) {
8005 mergedSubscriberIds.add(subscriberId);
8006 }
8007 }
8008
8009 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
8010 } finally {
8011 Binder.restoreCallingIdentity(identity);
8012
8013 }
8014 }
8015
8016 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008017 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008018 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08008019 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008020
joonhunshin4ac60942023-11-15 15:23:39 +00008021 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8022 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride");
8023
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008024 final long identity = Binder.clearCallingIdentity();
8025 try {
8026 final Phone phone = getPhone(subId);
8027 return phone == null ? false : phone.setOperatorBrandOverride(brand);
8028 } finally {
8029 Binder.restoreCallingIdentity(identity);
8030 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07008031 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05008032
8033 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008034 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008035 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
8036 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008037 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
8038 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008039
8040 final long identity = Binder.clearCallingIdentity();
8041 try {
8042 final Phone phone = getPhone(subId);
8043 if (phone == null) {
8044 return false;
8045 }
8046 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
8047 cdmaNonRoamingList);
8048 } finally {
8049 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008050 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008051 }
8052
8053 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07008054 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008055 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08008056 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008057 if (phone == null) {
8058 return raf;
8059 }
8060
Shuo Qiandee53402020-05-29 14:08:15 -07008061 try {
8062 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008063 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07008064 mApp, phone.getSubId(), "getRadioAccessFamily");
8065 } catch (SecurityException e) {
8066 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
8067 throw e;
8068 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008069
joonhunshin4ac60942023-11-15 15:23:39 +00008070 enforceTelephonyFeatureWithException(callingPackage,
8071 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily");
8072
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008073 final long identity = Binder.clearCallingIdentity();
8074 try {
chen xub97461a2018-10-26 14:17:57 -07008075 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008076 } finally {
8077 Binder.restoreCallingIdentity(identity);
8078 }
chen xub97461a2018-10-26 14:17:57 -07008079 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07008080 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008081
8082 @Override
Hall Liu82694d52020-12-11 18:22:04 -08008083 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08008084 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08008085 try {
8086 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
8087 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008088 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008089 }
8090 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008091 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008092 }
joonhunshin4ac60942023-11-15 15:23:39 +00008093
8094 enforceTelephonyFeatureWithException(callingPackage,
8095 PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture");
8096
Hall Liu82694d52020-12-11 18:22:04 -08008097 RoleManager rm = mApp.getSystemService(RoleManager.class);
8098 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
8099 if (!dialerRoleHolders.contains(callingPackage)) {
8100 throw new SecurityException("App must be the dialer role holder to"
8101 + " upload a call composer pic");
8102 }
8103
8104 Executors.newSingleThreadExecutor().execute(() -> {
8105 ByteArrayOutputStream output = new ByteArrayOutputStream(
8106 (int) TelephonyManager.getMaximumCallComposerPictureSize());
8107 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
8108 boolean readUntilEnd = false;
8109 int totalBytesRead = 0;
8110 byte[] buffer = new byte[16 * 1024];
8111 while (true) {
8112 int numRead;
8113 try {
8114 numRead = input.read(buffer);
8115 } catch (IOException e) {
8116 try {
8117 fd.checkError();
8118 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
8119 null);
8120 } catch (IOException e1) {
8121 // This means that the other side closed explicitly with an error. If this
8122 // happens, log and ignore.
8123 loge("Remote end of call composer picture pipe closed: " + e1);
8124 }
8125 break;
8126 }
8127 if (numRead == -1) {
8128 readUntilEnd = true;
8129 break;
8130 }
8131 totalBytesRead += numRead;
8132 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
8133 loge("Too many bytes read for call composer picture: " + totalBytesRead);
8134 try {
8135 input.close();
8136 } catch (IOException e) {
8137 // ignore
8138 }
8139 break;
8140 }
8141 output.write(buffer, 0, numRead);
8142 }
8143 // Generally, the remote end will close the file descriptors. The only case where we
8144 // close is above, where the picture size is too big.
8145
8146 try {
8147 fd.checkError();
8148 } catch (IOException e) {
8149 loge("Remote end for call composer closed with an error: " + e);
8150 return;
8151 }
8152
Hall Liuaa4211e2021-01-20 15:43:39 -08008153 if (!readUntilEnd) {
8154 loge("Did not finish reading entire image; aborting");
8155 return;
8156 }
Hall Liu82694d52020-12-11 18:22:04 -08008157
Hall Liuaa4211e2021-01-20 15:43:39 -08008158 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
8159 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
8160 new CallComposerPictureTransfer.Factory() {},
8161 imageData,
8162 (result) -> {
8163 if (result.first != null) {
8164 ParcelUuid parcelUuid = new ParcelUuid(result.first);
8165 Bundle outputResult = new Bundle();
8166 outputResult.putParcelable(
8167 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
8168 callback.send(TelephonyManager.CallComposerException.SUCCESS,
8169 outputResult);
8170 } else {
8171 callback.send(result.second, null);
8172 }
8173 }
8174 );
Hall Liu82694d52020-12-11 18:22:04 -08008175 });
8176 }
8177
8178 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07008179 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008180 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07008181 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008182
joonhunshin4ac60942023-11-15 15:23:39 +00008183 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8184 PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling");
8185
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008186 final long identity = Binder.clearCallingIdentity();
8187 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008188 ImsManager.getInstance(defaultPhone.getContext(),
8189 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008190 } finally {
8191 Binder.restoreCallingIdentity(identity);
8192 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008193 }
8194
8195 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008196 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008197 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008198 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
8199 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00008200 return false;
8201 }
Svet Ganovb320e182015-04-16 12:30:10 -07008202
joonhunshin4ac60942023-11-15 15:23:39 +00008203 enforceTelephonyFeatureWithException(callingPackage,
8204 PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled");
8205
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008206 final long identity = Binder.clearCallingIdentity();
8207 try {
8208 // Check the user preference and the system-level IMS setting. Even if the user has
8209 // enabled video calling, if IMS is disabled we aren't able to support video calling.
8210 // In the long run, we may instead need to check if there exists a connection service
8211 // which can support video calling.
8212 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008213 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008214 return imsManager.isVtEnabledByPlatform()
8215 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
8216 && imsManager.isVtEnabledByUser();
8217 } finally {
8218 Binder.restoreCallingIdentity(identity);
8219 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008220 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06008221
Andrew Leea1239f22015-03-02 17:44:07 -08008222 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008223 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
8224 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008225 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008226 mApp, subId, callingPackage, callingFeatureId,
8227 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008228 return false;
8229 }
8230
joonhunshin4ac60942023-11-15 15:23:39 +00008231 enforceTelephonyFeatureWithException(callingPackage,
8232 PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength");
8233
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008234 final long identity = Binder.clearCallingIdentity();
8235 try {
8236 CarrierConfigManager configManager =
8237 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008238 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008239 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
8240 } finally {
8241 Binder.restoreCallingIdentity(identity);
8242 }
Andrew Leea1239f22015-03-02 17:44:07 -08008243 }
8244
8245 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008246 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008247 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008248 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008249 return false;
8250 }
8251
joonhunshin4ac60942023-11-15 15:23:39 +00008252 enforceTelephonyFeatureWithException(callingPackage,
8253 PackageManager.FEATURE_TELEPHONY, "isWorldPhone");
8254
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008255 final long identity = Binder.clearCallingIdentity();
8256 try {
8257 CarrierConfigManager configManager =
8258 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008259 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008260 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
8261 } finally {
8262 Binder.restoreCallingIdentity(identity);
8263 }
Andrew Leea1239f22015-03-02 17:44:07 -08008264 }
8265
Andrew Lee9431b832015-03-09 18:46:45 -07008266 @Override
8267 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008268 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08008269 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07008270 }
8271
8272 @Override
8273 public boolean isHearingAidCompatibilitySupported() {
joonhunshin4ac60942023-11-15 15:23:39 +00008274 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8275 PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported");
8276
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008277 final long identity = Binder.clearCallingIdentity();
8278 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008279 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008280 } finally {
8281 Binder.restoreCallingIdentity(identity);
8282 }
Andrew Lee9431b832015-03-09 18:46:45 -07008283 }
8284
Hall Liuf6668912018-10-31 17:05:23 -07008285 /**
8286 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
8287 * support for the feature and device firmware support.
8288 *
8289 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
8290 */
8291 @Override
8292 public boolean isRttSupported(int subscriptionId) {
joonhunshin4ac60942023-11-15 15:23:39 +00008293 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8294 PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported");
8295
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008296 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008297 final Phone phone = getPhone(subscriptionId);
8298 if (phone == null) {
8299 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
8300 return false;
8301 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008302 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008303 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008304 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
joonhunshin4ac60942023-11-15 15:23:39 +00008305 boolean isDeviceSupported = (phone.getContext().getResources() != null)
8306 ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt)
8307 : false;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008308 return isCarrierSupported && isDeviceSupported;
8309 } finally {
8310 Binder.restoreCallingIdentity(identity);
8311 }
Hall Liu98187582018-01-22 19:15:32 -08008312 }
8313
Hall Liuf6668912018-10-31 17:05:23 -07008314 /**
Hall Liuf2daa022019-07-23 18:39:00 -07008315 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
8316 * RTT setting, will return true if the device and carrier both support RTT.
8317 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07008318 */
8319 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008320 final long identity = Binder.clearCallingIdentity();
8321 try {
joonhunshin4ac60942023-11-15 15:23:39 +00008322 if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) {
8323 if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
8324 return false;
8325 }
8326 }
8327
Hall Liu5bab75c2019-12-11 23:58:20 +00008328 boolean isRttSupported = isRttSupported(subscriptionId);
8329 boolean isUserRttSettingOn = Settings.Secure.getInt(
8330 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
8331 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
8332 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
8333 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008334 } finally {
8335 Binder.restoreCallingIdentity(identity);
8336 }
Hall Liu3ad5f012018-04-06 16:23:39 -07008337 }
8338
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008339 @Deprecated
8340 @Override
8341 public String getDeviceId(String callingPackage) {
8342 return getDeviceIdWithFeature(callingPackage, null);
8343 }
8344
Sanket Padawe7310cc72015-01-14 09:53:20 -08008345 /**
8346 * Returns the unique device ID of phone, for example, the IMEI for
8347 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
8348 *
8349 * <p>Requires Permission:
8350 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
8351 */
8352 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008353 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07008354 try {
8355 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
8356 } catch (SecurityException se) {
8357 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
8358 throw new SecurityException("Package " + callingPackage + " does not belong to "
8359 + Binder.getCallingUid());
8360 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008361 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008362 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008363 return null;
8364 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008365 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008366 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008367 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008368 return null;
8369 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008370
8371 final long identity = Binder.clearCallingIdentity();
8372 try {
8373 return phone.getDeviceId();
8374 } finally {
8375 Binder.restoreCallingIdentity(identity);
8376 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008377 }
8378
Ping Sunc67b7c22016-03-02 19:16:45 +08008379 /**
8380 * {@hide}
8381 * Returns the IMS Registration Status on a particular subid
8382 *
8383 * @param subId
8384 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008385 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008386 Phone phone = getPhone(subId);
8387 if (phone != null) {
8388 return phone.isImsRegistered();
8389 } else {
8390 return false;
8391 }
8392 }
8393
Santos Cordon7a1885b2015-02-03 11:15:19 -08008394 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008395 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008396 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008397 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008398 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008399 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8400 }
8401 final long identity = Binder.clearCallingIdentity();
8402 try {
8403 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8404 } finally {
8405 Binder.restoreCallingIdentity(identity);
8406 }
8407 }
8408
8409 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008410 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008411 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008412 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008413 mApp,
8414 subscriptionId,
8415 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
8416 + subscriptionId);
joonhunshin4ac60942023-11-15 15:23:39 +00008417
8418 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8419 PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId");
8420
Tyler Gunnf70ed162019-04-03 15:28:53 -07008421 final long identity = Binder.clearCallingIdentity();
8422 try {
8423 Phone phone = getPhone(subscriptionId);
8424 if (phone == null) {
8425 return null;
8426 }
8427 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8428 } finally {
8429 Binder.restoreCallingIdentity(identity);
8430 }
8431 }
8432
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008433 /**
8434 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008435 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008436 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008437 final long identity = Binder.clearCallingIdentity();
8438 try {
8439 Phone phone = getPhone(subId);
8440 if (phone != null) {
8441 return phone.isWifiCallingEnabled();
8442 } else {
8443 return false;
8444 }
8445 } finally {
8446 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008447 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008448 }
8449
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008450 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008451 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008452 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008453 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008454 final long identity = Binder.clearCallingIdentity();
8455 try {
8456 Phone phone = getPhone(subId);
8457 if (phone != null) {
8458 return phone.isVideoEnabled();
8459 } else {
8460 return false;
8461 }
8462 } finally {
8463 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008464 }
8465 }
8466
8467 /**
8468 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8469 * defined in {@link ImsRegistrationImplBase}.
8470 */
8471 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008472 final long identity = Binder.clearCallingIdentity();
8473 try {
8474 Phone phone = getPhone(subId);
8475 if (phone != null) {
8476 return phone.getImsRegistrationTech();
8477 } else {
8478 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8479 }
8480 } finally {
8481 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008482 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008483 }
8484
Stuart Scott8eef64f2015-04-08 15:13:54 -07008485 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008486 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008487 enforceSettingsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008488
8489 enforceTelephonyFeatureWithException(callingPackage,
8490 PackageManager.FEATURE_TELEPHONY, "factoryReset");
8491
Stuart Scott981d8582015-04-21 14:09:50 -07008492 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8493 return;
8494 }
Kai Shif70f46f2021-03-03 13:59:46 -08008495 Phone defaultPhone = getDefaultPhone();
8496 if (defaultPhone != null) {
8497 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8498 mApp, getDefaultPhone().getSubId(), "factoryReset");
8499 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008500 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008501
Svet Ganovcc087f82015-05-12 20:35:54 -07008502 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008503 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8504 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008505 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008506 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008507 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008508 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008509 cleanUpAllowedNetworkTypes(phone, subId);
Rambo Wang71f6aa62024-02-23 20:16:22 +00008510 setDataRoamingEnabled(subId, phone == null ? false
8511 : phone.getDataSettingsManager().isDefaultDataRoamingEnabled());
Jordan Liu857e73a2021-03-05 16:24:04 -08008512 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008513 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008514 // There has been issues when Sms raw table somehow stores orphan
8515 // fragments. They lead to garbled message when new fragments come
8516 // in and combined with those stale ones. In case this happens again,
8517 // user can reset all network settings which will clean up this table.
8518 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008519 // Clean up IMS settings as well here.
8520 int slotId = getSlotIndex(subId);
8521 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
8522 ImsManager.getInstance(mApp, slotId).factoryReset();
8523 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008524
Kai Shif70f46f2021-03-03 13:59:46 -08008525 if (defaultPhone == null) {
8526 return;
8527 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008528 // Erase modem config if erase modem on network setting is enabled.
8529 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8530 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8531 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008532 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008533 }
Kai Shif70f46f2021-03-03 13:59:46 -08008534
8535 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008536 } finally {
8537 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008538 }
8539 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008540
SongFerngWangfd89b102021-05-27 22:44:54 +08008541 @VisibleForTesting
8542 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8543 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8544 return;
8545 }
8546 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8547 RILConstants.PREFERRED_NETWORK_MODE);
8548 SubscriptionManager.setSubscriptionProperty(subId,
8549 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8550 "user=" + defaultNetworkType);
8551 phone.loadAllowedNetworksFromSubscriptionDatabase();
8552 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8553 defaultNetworkType, null);
8554 }
8555
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008556 private void cleanUpSmsRawTable(Context context) {
8557 ContentResolver resolver = context.getContentResolver();
8558 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8559 resolver.delete(uri, null, null);
8560 }
8561
Narayan Kamath1c496c22015-04-16 14:40:19 +01008562 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008563 public String getSimLocaleForSubscriber(int subId) {
8564 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
joonhunshin4ac60942023-11-15 15:23:39 +00008565
8566 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8567 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber");
8568
chen xu5d3637b2019-01-21 23:31:38 -08008569 final Phone phone = getPhone(subId);
8570 if (phone == null) {
8571 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008572 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008573 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008574 final long identity = Binder.clearCallingIdentity();
8575 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008576 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
8577 phone.getContext().getOpPackageName(),
8578 phone.getContext().getAttributionTag());
8579 if (info == null) {
8580 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8581 return null;
chen xu6291c472019-02-04 12:55:53 -08008582 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008583 // Try and fetch the locale from the carrier properties or from the SIM language
8584 // preferences (EF-PL and EF-LI)...
8585 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008586 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008587 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8588 if (localeFromDefaultSim != null) {
8589 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8590 if (DBG) log("Using locale from subId: " + subId + " locale: "
8591 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008592 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008593 } else {
8594 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008595 }
8596 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008597
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008598 // The SIM language preferences only store a language (e.g. fr = French), not an
8599 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8600 // the SIM and carrier preferences does not include a country we add the country
8601 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008602 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008603 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008604 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008605 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008606 }
8607
8608 if (DBG) log("No locale found - returning null");
8609 return null;
8610 } finally {
8611 Binder.restoreCallingIdentity(identity);
8612 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008613 }
8614
tom hsu0b59d292022-09-29 23:49:21 +08008615 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008616 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008617 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008618 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008619 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008620 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8621 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008622 Locale.forLanguageTag(localeTag).getCountry())) {
8623 return localeTag;
8624 }
8625 }
8626 return inputLocale.toLanguageTag();
8627 }
8628
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008629 /**
8630 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8631 */
8632 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008633 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Ling Ma9fa67412023-11-13 14:13:19 -08008634 mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/);
Narayan Kamath1c496c22015-04-16 14:40:19 +01008635 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008636
Gary Jian3aa9a762022-01-24 16:41:19 +08008637 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8638 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008639
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008640 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008641 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8642 * representing the state of the modem.
8643 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008644 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8645 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008646 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008647 */
8648 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008649 public void requestModemActivityInfo(ResultReceiver result) {
8650 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008651
8652 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8653 PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo");
8654
vagdeviaf9a5b92018-08-15 16:01:53 -07008655 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008656
8657 final long identity = Binder.clearCallingIdentity();
8658 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008659 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008660 } finally {
8661 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008662 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008663 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008664
Gary Jian76280a42022-12-07 16:18:33 +08008665 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008666 // less than total activity duration.
8667 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8668 if (info == null) {
8669 return false;
8670 }
8671 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008672 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008673 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8674
Hall Liu49656c02020-10-09 19:00:11 -07008675 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8676
Siddharth Rayb8114062018-06-17 15:02:38 -07008677 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008678 && (info.getSleepTimeMillis() <= activityDurationMs)
8679 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008680 }
8681
Gary Jian3aa9a762022-01-24 16:41:19 +08008682 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8683 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8684 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8685 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8686
8687 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8688 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8689 }
8690
8691 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8692 mLastModemActivityInfo.setReceiveTimeMillis(
8693 rat,
8694 freq,
8695 info.getReceiveTimeMillis(rat, freq)
8696 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8697 }
8698
8699 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8700 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8701 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8702 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8703
8704 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8705 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8706 }
8707 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8708 mLastModemActivityInfo.setReceiveTimeMillis(
8709 rat,
8710 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8711 }
8712
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008713 /**
8714 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8715 * @param info recent ModemActivityInfo
8716 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008717 private void mergeModemActivityInfo(ModemActivityInfo info) {
8718 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008719 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008720 boolean matched;
8721 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8722 matched = false;
8723 int rat = info.getSpecificInfoRat(i);
8724 int freq = info.getSpecificInfoFrequencyRange(i);
8725 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8726 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8727 //if it already exists
8728 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8729 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8730 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8731 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8732 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8733 updateLastModemActivityInfo(info, rat, freq);
8734 matched = true;
8735 }
8736 } else {
8737 updateLastModemActivityInfo(info, rat);
8738 matched = true;
8739 }
8740 }
8741 }
8742
8743 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008744 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008745 new ActivityStatsTechSpecificInfo(
8746 rat,
8747 freq,
8748 info.getTransmitTimeMillis(rat, freq),
8749 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008750 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008751 }
8752 }
8753 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8754 mLastModemActivitySpecificInfo =
8755 new ActivityStatsTechSpecificInfo[merged.size()];
8756 merged.toArray(mLastModemActivitySpecificInfo);
8757
8758 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8759 mLastModemActivityInfo.setSleepTimeMillis(
8760 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008761 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008762 mLastModemActivityInfo.setIdleTimeMillis(
8763 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008764 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008765
8766 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008767 new ModemActivityInfo(
8768 mLastModemActivityInfo.getTimestampMillis(),
8769 mLastModemActivityInfo.getSleepTimeMillis(),
8770 mLastModemActivityInfo.getIdleTimeMillis(),
8771 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008772 }
8773
8774 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8775 ActivityStatsTechSpecificInfo[] info) {
8776 int infoSize = info.length;
8777 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8778 for (int i = 0; i < infoSize; i++) {
8779 ret[i] = new ActivityStatsTechSpecificInfo(
8780 info[i].getRat(), info[i].getFrequencyRange(),
8781 info[i].getTransmitTimeMillis(),
8782 (int) info[i].getReceiveTimeMillis());
8783 }
8784 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008785 }
8786
Jack Yu85bd38a2015-11-09 11:34:32 -08008787 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008788 * Returns the service state information on specified subscription.
8789 */
8790 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008791 public ServiceState getServiceStateForSubscriber(int subId,
8792 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8793 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008794 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008795 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008796 return null;
8797 }
8798
joonhunshin4ac60942023-11-15 15:23:39 +00008799 enforceTelephonyFeatureWithException(callingPackage,
8800 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber");
8801
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008802 boolean hasFinePermission = false;
8803 boolean hasCoarsePermission = false;
8804 if (!renounceFineLocationAccess) {
8805 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8806 LocationAccessPolicy.checkLocationPermission(mApp,
8807 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8808 .setCallingPackage(callingPackage)
8809 .setCallingFeatureId(callingFeatureId)
8810 .setCallingPid(Binder.getCallingPid())
8811 .setCallingUid(Binder.getCallingUid())
8812 .setMethod("getServiceStateForSubscriber")
8813 .setLogAsInfo(true)
8814 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8815 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8816 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8817 .build());
8818 hasFinePermission =
8819 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8820 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008821
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008822 if (!renounceCoarseLocationAccess) {
8823 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8824 LocationAccessPolicy.checkLocationPermission(mApp,
8825 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8826 .setCallingPackage(callingPackage)
8827 .setCallingFeatureId(callingFeatureId)
8828 .setCallingPid(Binder.getCallingPid())
8829 .setCallingUid(Binder.getCallingUid())
8830 .setMethod("getServiceStateForSubscriber")
8831 .setLogAsInfo(true)
8832 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8833 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8834 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8835 .build());
8836 hasCoarsePermission =
8837 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8838 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008839
Jack Yu479f40e2020-10-27 21:29:25 -07008840 final Phone phone = getPhone(subId);
8841 if (phone == null) {
8842 return null;
8843 }
8844
Jordan Liu0f2bc442020-11-18 16:47:37 -08008845 final long identity = Binder.clearCallingIdentity();
8846
Jack Yu479f40e2020-10-27 21:29:25 -07008847 boolean isCallingPackageDataService = phone.getDataServicePackages()
8848 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008849 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008850 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu3beaf9d2023-04-14 09:17:27 -07008851 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8852 .getSubscriptionInfoInternal(subId);
8853 if (subInfo == null || !subInfo.isActive()) {
8854 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8855 + "subId=" + subId);
8856 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008857 }
8858
Hall Liuf19c44f2018-11-27 14:38:17 -08008859 ServiceState ss = phone.getServiceState();
8860
8861 // Scrub out the location info in ServiceState depending on what level of access
8862 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008863 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008864 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8865 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008866 } finally {
8867 Binder.restoreCallingIdentity(identity);
8868 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008869 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008870
8871 /**
8872 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8873 *
8874 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8875 * voicemail ringtone.
8876 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8877 * PhoneAccount.
8878 */
8879 @Override
8880 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008881 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8882 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri");
8883
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008884 final long identity = Binder.clearCallingIdentity();
8885 try {
8886 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8887 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008888 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008889 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008890
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008891 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8892 } finally {
8893 Binder.restoreCallingIdentity(identity);
8894 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008895 }
8896
8897 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008898 * Sets the per-account voicemail ringtone.
8899 *
8900 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8901 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8902 *
8903 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8904 * voicemail ringtone.
8905 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8906 * PhoneAccount.
8907 */
8908 @Override
8909 public void setVoicemailRingtoneUri(String callingPackage,
8910 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008911 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008912 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008913 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8914 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008915 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8916 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8917 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008918 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008919
joonhunshin4ac60942023-11-15 15:23:39 +00008920 enforceTelephonyFeatureWithException(callingPackage,
8921 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri");
8922
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008923 final long identity = Binder.clearCallingIdentity();
8924 try {
8925 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8926 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008927 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008928 }
8929 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8930 } finally {
8931 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008932 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008933 }
8934
8935 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008936 * Returns whether vibration is set for voicemail notification in Phone settings.
8937 *
8938 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8939 * voicemail vibration setting.
8940 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8941 */
8942 @Override
8943 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008944 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8945 PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled");
8946
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008947 final long identity = Binder.clearCallingIdentity();
8948 try {
8949 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8950 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008951 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008952 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008953
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008954 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8955 } finally {
8956 Binder.restoreCallingIdentity(identity);
8957 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008958 }
8959
Youhan Wange64578a2016-05-02 15:32:42 -07008960 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008961 * Sets the per-account voicemail vibration.
8962 *
8963 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8964 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8965 *
8966 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8967 * voicemail vibration setting.
8968 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8969 * specific PhoneAccount.
8970 */
8971 @Override
8972 public void setVoicemailVibrationEnabled(String callingPackage,
8973 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008974 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008975 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008976 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8977 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008978 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8979 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8980 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008981 }
8982
joonhunshin4ac60942023-11-15 15:23:39 +00008983 enforceTelephonyFeatureWithException(callingPackage,
8984 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled");
8985
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008986 final long identity = Binder.clearCallingIdentity();
8987 try {
8988 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8989 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008990 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008991 }
8992 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8993 } finally {
8994 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008995 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008996 }
8997
8998 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008999 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
9000 *
9001 * @throws SecurityException if the caller does not have the required permission
9002 */
arunvoddud7401012022-12-15 16:08:12 +00009003 @VisibleForTesting
9004 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07009005 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07009006 message);
Youhan Wange64578a2016-05-02 15:32:42 -07009007 }
9008
9009 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009010 * Make sure either called from same process as self (phone) or IPC caller has send SMS
9011 * permission.
9012 *
9013 * @throws SecurityException if the caller does not have the required permission
9014 */
9015 private void enforceSendSmsPermission() {
9016 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
9017 }
9018
9019 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00009020 * Make sure either called from same process as self (phone) or IPC caller has interact across
9021 * users permission.
9022 *
9023 * @throws SecurityException if the caller does not have the required permission
9024 */
9025 private void enforceInteractAcrossUsersPermission(String message) {
9026 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
9027 }
9028
9029 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009030 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009031 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009032 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009033 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009034 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009035 final long identity = Binder.clearCallingIdentity();
9036 try {
9037 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009038 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009039 if (componentName == null) {
9040 throw new SecurityException(
9041 "Caller not current active visual voicemail package[null]");
9042 }
9043 String vvmPackage = componentName.getPackageName();
9044 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00009045 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009046 }
9047 } finally {
9048 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009049 }
9050 }
9051
9052 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009053 * Return the application ID for the app type.
9054 *
9055 * @param subId the subscription ID that this request applies to.
9056 * @param appType the uicc app type.
9057 * @return Application ID for specificied app type, or null if no uicc.
9058 */
9059 @Override
9060 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009061 enforceReadPrivilegedPermission("getAidForAppType");
joonhunshin4ac60942023-11-15 15:23:39 +00009062
9063 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9064 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType");
9065
Youhan Wange64578a2016-05-02 15:32:42 -07009066 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009067
9068 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07009069 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009070 if (phone == null) {
9071 return null;
9072 }
9073 String aid = null;
9074 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009075 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009076 .getApplicationByType(appType).getAid();
9077 } catch (Exception e) {
9078 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
9079 }
9080 return aid;
9081 } finally {
9082 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07009083 }
Youhan Wange64578a2016-05-02 15:32:42 -07009084 }
9085
Youhan Wang4001d252016-05-11 10:29:41 -07009086 /**
9087 * Return the Electronic Serial Number.
9088 *
9089 * @param subId the subscription ID that this request applies to.
9090 * @return ESN or null if error.
9091 */
9092 @Override
9093 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009094 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07009095 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009096
9097 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07009098 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009099 if (phone == null) {
9100 return null;
9101 }
9102 String esn = null;
9103 try {
9104 esn = phone.getEsn();
9105 } catch (Exception e) {
9106 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
9107 }
9108 return esn;
9109 } finally {
9110 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07009111 }
Youhan Wang4001d252016-05-11 10:29:41 -07009112 }
9113
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009114 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009115 * Return the Preferred Roaming List Version.
9116 *
9117 * @param subId the subscription ID that this request applies to.
9118 * @return PRLVersion or null if error.
9119 */
9120 @Override
9121 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009122 enforceReadPrivilegedPermission("getCdmaPrlVersion");
joonhunshin4ac60942023-11-15 15:23:39 +00009123
9124 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9125 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion");
9126
Youhan Wang66ad5d72016-07-18 17:56:58 -07009127 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009128
9129 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009130 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009131 if (phone == null) {
9132 return null;
9133 }
9134 String cdmaPrlVersion = null;
9135 try {
9136 cdmaPrlVersion = phone.getCdmaPrlVersion();
9137 } catch (Exception e) {
9138 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9139 }
9140 return cdmaPrlVersion;
9141 } finally {
9142 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009143 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009144 }
9145
9146 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009147 * Get snapshot of Telephony histograms
9148 * @return List of Telephony histograms
9149 * @hide
9150 */
9151 @Override
9152 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009153 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9154 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009155
9156 final long identity = Binder.clearCallingIdentity();
9157 try {
9158 return RIL.getTelephonyRILTimingHistograms();
9159 } finally {
9160 Binder.restoreCallingIdentity(identity);
9161 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009162 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009163
9164 /**
9165 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009166 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9167 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009168 * Require system privileges. In the future we may add this to carrier APIs.
9169 *
Michele Berionne482f8202018-11-27 18:57:59 -08009170 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009171 */
9172 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009173 @TelephonyManager.SetCarrierRestrictionResult
9174 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009175 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009176
9177 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9178 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers");
9179
vagdeviaf9a5b92018-08-15 16:01:53 -07009180 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009181
Michele Berionne482f8202018-11-27 18:57:59 -08009182 if (carrierRestrictionRules == null) {
9183 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009184 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009185
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009186 final long identity = Binder.clearCallingIdentity();
9187 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009188 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009189 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009190 } finally {
9191 Binder.restoreCallingIdentity(identity);
9192 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009193 }
9194
9195 /**
9196 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009197 * Get the allowed carrier list and the excluded carrier list, including the priority between
9198 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009199 * Require system privileges. In the future we may add this to carrier APIs.
9200 *
Michele Berionne482f8202018-11-27 18:57:59 -08009201 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009202 */
9203 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009204 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009205 enforceReadPrivilegedPermission("getAllowedCarriers");
joonhunshin4ac60942023-11-15 15:23:39 +00009206
9207 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9208 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers");
9209
vagdeviaf9a5b92018-08-15 16:01:53 -07009210 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009211
9212 final long identity = Binder.clearCallingIdentity();
9213 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009214 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9215 if (response instanceof CarrierRestrictionRules) {
9216 return (CarrierRestrictionRules) response;
9217 }
9218 // Response is an Exception of some kind,
9219 // which is signalled to the user as a NULL retval
9220 return null;
9221 } catch (Exception e) {
9222 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9223 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009224 } finally {
9225 Binder.restoreCallingIdentity(identity);
9226 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009227 }
9228
fionaxu59545b42016-05-25 15:53:37 -07009229 /**
arunvoddud7401012022-12-15 16:08:12 +00009230 * Fetches the carrier restriction status of the device and sends the status to the caller
9231 * through the callback.
9232 *
9233 * @param callback The callback that will be used to send the result.
9234 * @throws SecurityException if the caller does not have the required permission/privileges or
9235 * the caller is not allowlisted.
9236 */
9237 @Override
9238 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
9239 enforceReadPermission("getCarrierRestrictionStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00009240
9241 enforceTelephonyFeatureWithException(packageName,
9242 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierRestrictionStatus");
9243
arunvoddud7401012022-12-15 16:08:12 +00009244 int carrierId = validateCallerAndGetCarrierId(packageName);
9245 if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) {
9246 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9247 throw new SecurityException("Not an authorized caller");
9248 }
9249 final long identity = Binder.clearCallingIdentity();
9250 try {
9251 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
9252 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId);
9253 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9254 } finally {
9255 Binder.restoreCallingIdentity(identity);
9256 }
9257 }
9258
arunvoddu567f2b42023-04-25 17:22:00 +00009259 @Override
9260 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
9261 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
9262 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9263 return allowListInfo.getShaIdList(pkgName, carrierId);
9264 }
9265
arunvoddud7401012022-12-15 16:08:12 +00009266 @VisibleForTesting
9267 public int validateCallerAndGetCarrierId(String packageName) {
9268 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9269 return allowListInfo.validateCallerAndGetCarrierId(packageName);
9270 }
9271
9272 /**
fionaxu59545b42016-05-25 15:53:37 -07009273 * Action set from carrier signalling broadcast receivers to enable/disable radio
9274 * @param subId the subscription ID that this action applies to.
9275 * @param enabled control enable or disable radio.
9276 * {@hide}
9277 */
9278 @Override
9279 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9280 enforceModifyPermission();
9281 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009282
9283 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009284 if (phone == null) {
9285 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9286 return;
9287 }
9288 try {
9289 phone.carrierActionSetRadioEnabled(enabled);
9290 } catch (Exception e) {
9291 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009292 } finally {
9293 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009294 }
9295 }
9296
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009297 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009298 * Enable or disable Voice over NR (VoNR)
9299 * @param subId the subscription ID that this action applies to.
9300 * @param enabled enable or disable VoNR.
9301 * @return operation result.
9302 */
9303 @Override
9304 public int setVoNrEnabled(int subId, boolean enabled) {
9305 enforceModifyPermission();
9306 final Phone phone = getPhone(subId);
9307
9308 final long identity = Binder.clearCallingIdentity();
9309 if (phone == null) {
9310 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9311 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9312 }
9313
9314 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9315 try {
9316 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9317 workSource);
9318 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009319
9320 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9321 if (DBG) {
9322 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9323 }
9324 SubscriptionManager.setSubscriptionProperty(
9325 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9326 (enabled ? "1" : "0"));
9327 }
9328
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009329 return result;
9330 } finally {
9331 Binder.restoreCallingIdentity(identity);
9332 }
9333 }
9334
9335 /**
9336 * Is voice over NR enabled
9337 * @return true if VoNR is enabled else false
9338 */
9339 @Override
9340 public boolean isVoNrEnabled(int subId) {
9341 enforceReadPrivilegedPermission("isVoNrEnabled");
9342 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9343 final long identity = Binder.clearCallingIdentity();
9344 try {
9345 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9346 null, subId, workSource);
9347 if (DBG) log("isVoNrEnabled: " + isEnabled);
9348 return isEnabled;
9349 } finally {
9350 Binder.restoreCallingIdentity(identity);
9351 }
9352 }
9353
9354 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009355 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9356 * network status based on which carrier apps could apply actions accordingly,
9357 * enable/disable default url handler for example.
9358 *
9359 * @param subId the subscription ID that this action applies to.
9360 * @param report control start/stop reporting the default network status.
9361 * {@hide}
9362 */
9363 @Override
9364 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9365 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009366
9367 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9368 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
9369 "carrierActionReportDefaultNetworkStatus");
9370
fionaxu8da9cb12017-05-23 15:02:46 -07009371 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009372
9373 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009374 if (phone == null) {
9375 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9376 return;
9377 }
9378 try {
9379 phone.carrierActionReportDefaultNetworkStatus(report);
9380 } catch (Exception e) {
9381 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009382 } finally {
9383 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009384 }
9385 }
9386
9387 /**
fionaxud9622282017-07-17 17:51:30 -07009388 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9389 * @param subId the subscription ID that this action applies to.
9390 * {@hide}
9391 */
9392 @Override
9393 public void carrierActionResetAll(int subId) {
9394 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009395
9396 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9397 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll");
9398
fionaxud9622282017-07-17 17:51:30 -07009399 final Phone phone = getPhone(subId);
9400 if (phone == null) {
9401 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9402 return;
9403 }
9404 try {
9405 phone.carrierActionResetAll();
9406 } catch (Exception e) {
9407 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9408 }
9409 }
9410
9411 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009412 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9413 * bug report is being generated.
9414 */
9415 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009416 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009417 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9418 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009419 writer.println("Permission Denial: can't dump Phone from pid="
9420 + Binder.getCallingPid()
9421 + ", uid=" + Binder.getCallingUid()
9422 + "without permission "
9423 + android.Manifest.permission.DUMP);
9424 return;
9425 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009426 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009427 }
Jack Yueb89b242016-06-22 13:27:47 -07009428
Brad Ebingerdac2f002018-04-03 15:17:52 -07009429 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009430 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9431 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9432 @NonNull String[] args) {
9433 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9434 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009435 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009436 }
9437
Jack Yueb89b242016-06-22 13:27:47 -07009438 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009439 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009440 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009441 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009442 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009443 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009444 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009445 */
9446 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009447 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009448 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009449 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9450 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9451 try {
9452 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009453 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009454 } catch (SecurityException se) {
9455 enforceModifyPermission();
9456 }
9457 } else {
9458 enforceModifyPermission();
9459 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009460
joonhunshin4ac60942023-11-15 15:23:39 +00009461 enforceTelephonyFeatureWithException(callingPackage,
9462 PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason");
9463
Nate Myren116695d2024-02-09 09:36:01 -08009464 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009465 final long identity = Binder.clearCallingIdentity();
9466 try {
Nate Myren116695d2024-02-09 09:36:01 -08009467 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
9468 && null != callingPackage && opEnableMobileDataByUser()) {
Nate Myren453c3472024-03-13 11:28:11 -07009469 mAppOps.noteOpNoThrow(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER,
Nate Myren116695d2024-02-09 09:36:01 -08009470 callingUid, callingPackage, null, null);
9471 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009472 Phone phone = getPhone(subId);
9473 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009474 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9475 phone.carrierActionSetMeteredApnsEnabled(enabled);
9476 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07009477 phone.getDataSettingsManager().setDataEnabled(
9478 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009479 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009480 }
9481 } finally {
9482 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009483 }
9484 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009485
9486 /**
9487 * Get Client request stats
9488 * @return List of Client Request Stats
9489 * @hide
9490 */
9491 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009492 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9493 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009494 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009495 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009496 return null;
9497 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009498 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009499
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009500 final long identity = Binder.clearCallingIdentity();
9501 try {
9502 if (phone != null) {
9503 return phone.getClientRequestStats();
9504 }
9505
9506 return null;
9507 } finally {
9508 Binder.restoreCallingIdentity(identity);
9509 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009510 }
9511
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009512 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009513 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009514 if (uid == Process.ROOT_UID && packageName == null) {
9515 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9516 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9517 // exception. ROOT_UID seems not to have a valid package name returned by
9518 // PackageManager, so just fake it here to avoid issues when running telephony shell
9519 // commands that plumb through the RIL as root, like so:
9520 // $ adb root
9521 // $ adb shell cmd phone ...
9522 packageName = "root";
9523 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009524 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009525 }
Jack Yueb4124c2017-02-16 15:32:43 -08009526
9527 /**
Grace Chen70990072017-03-24 17:21:30 -07009528 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009529 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009530 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009531 * @param state State of SIM (power down, power up, pass through)
9532 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9533 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9534 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009535 *
9536 **/
9537 @Override
Grace Chen70990072017-03-24 17:21:30 -07009538 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009539 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009540
9541 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9542 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot");
9543
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009544 Phone phone = PhoneFactory.getPhone(slotIndex);
9545
vagdeviaf9a5b92018-08-15 16:01:53 -07009546 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9547
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009548 final long identity = Binder.clearCallingIdentity();
9549 try {
9550 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009551 phone.setSimPowerState(state, null, workSource);
9552 }
9553 } finally {
9554 Binder.restoreCallingIdentity(identity);
9555 }
9556 }
9557
9558 /**
9559 * Set SIM card power state.
9560 *
9561 * @param slotIndex SIM slot id.
9562 * @param state State of SIM (power down, power up, pass through)
9563 * @param callback callback to trigger after success or failure
9564 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9565 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9566 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9567 *
9568 **/
9569 @Override
9570 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9571 IIntegerConsumer callback) {
9572 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009573
9574 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9575 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
9576 "setSimPowerStateForSlotWithCallback");
9577
Jordan Liu109698e2020-11-24 14:50:34 -08009578 Phone phone = PhoneFactory.getPhone(slotIndex);
9579
9580 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9581
9582 final long identity = Binder.clearCallingIdentity();
9583 try {
9584 if (phone != null) {
9585 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9586 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009587 }
9588 } finally {
9589 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009590 }
9591 }
Shuo Qiandd210312017-04-12 22:11:33 +00009592
Tyler Gunn65d45c22017-06-05 11:22:26 -07009593 private boolean isUssdApiAllowed(int subId) {
9594 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009595 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009596 if (configManager == null) {
9597 return false;
9598 }
9599 PersistableBundle pb = configManager.getConfigForSubId(subId);
9600 if (pb == null) {
9601 return false;
9602 }
9603 return pb.getBoolean(
9604 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9605 }
9606
Shuo Qiandd210312017-04-12 22:11:33 +00009607 /**
Ling Mac28f0212023-03-24 16:07:15 -07009608 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00009609 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07009610 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00009611 */
goneil9c5f4872017-12-05 14:07:56 -08009612 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009613 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009614 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
joonhunshin4ac60942023-11-15 15:23:39 +00009615
9616 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9617 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode");
9618
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009619 final long identity = Binder.clearCallingIdentity();
9620 try {
Ling Mac28f0212023-03-24 16:07:15 -07009621 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009622 } finally {
9623 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009624 }
9625 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009626
9627 /**
9628 * Get the current signal strength information for the given subscription.
9629 * Because this information is not updated when the device is in a low power state
9630 * it should not be relied-upon to be current.
9631 * @param subId Subscription index
9632 * @return the most recent cached signal strength info from the modem
9633 */
9634 @Override
9635 public SignalStrength getSignalStrength(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00009636 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9637 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength");
9638
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009639 final long identity = Binder.clearCallingIdentity();
9640 try {
9641 Phone p = getPhone(subId);
9642 if (p == null) {
9643 return null;
9644 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009645
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009646 return p.getSignalStrength();
9647 } finally {
9648 Binder.restoreCallingIdentity(identity);
9649 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009650 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009651
Pengquan Meng77b7f132018-08-22 14:49:57 -07009652 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009653 * Get the current modem radio state for the given slot.
9654 * @param slotIndex slot index.
9655 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009656 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009657 * @return the current radio power state from the modem
9658 */
9659 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009660 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009661 Phone phone = PhoneFactory.getPhone(slotIndex);
9662 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009663 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9664 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009665 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9666 }
9667
joonhunshin4ac60942023-11-15 15:23:39 +00009668 enforceTelephonyFeatureWithException(callingPackage,
9669 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState");
9670
Chen Xuf792fd62018-10-17 17:54:36 +00009671 final long identity = Binder.clearCallingIdentity();
9672 try {
9673 return phone.getRadioPowerState();
9674 } finally {
9675 Binder.restoreCallingIdentity(identity);
9676 }
9677 }
9678 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9679 }
9680
9681 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009682 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9683 *
9684 * <p>Requires one of the following permissions:
9685 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009686 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009687 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9688 * privileges.
9689 *
9690 * @param subId subscription id
9691 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9692 * {@code false}.
9693 */
9694 @Override
9695 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009696 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009697 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009698 try {
9699 mApp.enforceCallingOrSelfPermission(
9700 android.Manifest.permission.ACCESS_NETWORK_STATE,
9701 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009702 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009703 mApp.enforceCallingOrSelfPermission(
9704 permission.READ_BASIC_PHONE_STATE, functionName);
9705 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009706 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009707 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009708 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009709 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009710
joonhunshin4ac60942023-11-15 15:23:39 +00009711 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9712 PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled");
9713
Pengquan Menga1bb6272018-09-06 09:59:22 -07009714 boolean isEnabled = false;
9715 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009716 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009717 Phone phone = getPhone(subId);
9718 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009719 } finally {
9720 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009721 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009722 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009723 }
9724
9725
9726 /**
9727 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9728 *
9729 * <p> Requires permission:
9730 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9731 * privileges.
9732 *
9733 * @param subId subscription id
9734 * @param isEnabled {@code true} means enable, {@code false} means disable.
9735 */
9736 @Override
9737 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009738 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9739 mApp, subId, "setDataRoamingEnabled");
9740
joonhunshin4ac60942023-11-15 15:23:39 +00009741 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9742 PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled");
9743
Pengquan Menga1bb6272018-09-06 09:59:22 -07009744 final long identity = Binder.clearCallingIdentity();
9745 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009746 Phone phone = getPhone(subId);
9747 if (phone != null) {
9748 phone.setDataRoamingEnabled(isEnabled);
9749 }
9750 } finally {
9751 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009752 }
9753 }
9754
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009755 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009756 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009757 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009758 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009759 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009760
joonhunshin4ac60942023-11-15 15:23:39 +00009761 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9762 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed");
9763
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009764 boolean isAllowed = true;
9765 final long identity = Binder.clearCallingIdentity();
9766 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009767 Phone phone = getPhone(subId);
9768 if (phone != null) {
9769 isAllowed = phone.isCspPlmnEnabled();
9770 }
9771 } finally {
9772 Binder.restoreCallingIdentity(identity);
9773 }
9774 return isAllowed;
9775 }
9776
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009777 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9778 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009779 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009780 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009781 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009782 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9783 if (phone == null) {
9784 return false;
9785 }
9786 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9787 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9788 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009789 }
9790
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009791 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009792 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009793 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009794 mApp.getSystemService(AppOpsManager.class)
9795 .checkPackage(Binder.getCallingUid(), callingPackage);
9796
Jordan Liu1e142fc2019-04-22 15:10:43 -07009797 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009798 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009799 try {
9800 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009801 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009802 } catch (SecurityException e) {
9803 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9804 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009805 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009806 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009807 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009808 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009809 }
joonhunshin4ac60942023-11-15 15:23:39 +00009810
9811 enforceTelephonyFeatureWithException(callingPackage,
9812 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo");
9813
sandeepjsb6c87872021-09-27 15:34:44 +00009814 // checking compatibility, if calling app's target SDK is T and beyond.
9815 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9816 Binder.getCallingUid())) {
9817 isIccIdAccessRestricted = true;
9818 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009819 final long identity = Binder.clearCallingIdentity();
9820 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009821 UiccController uiccController = UiccController.getInstance();
9822 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009823 if (hasReadPermission) {
9824 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009825 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009826
9827 // Remove private info if the caller doesn't have access
9828 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9829 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009830 //setting the value after compatibility check
9831 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009832 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9833 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009834 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009835 if (card == null) {
9836 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009837 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009838 continue;
9839 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009840 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9841 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009842 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009843 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009844 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009845 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9846 for (UiccPortInfo portInfo : portInfos) {
9847 UiccPort port = uiccController.getUiccPortForSlot(
9848 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9849 if (port == null) {
9850 // assume no access if port is null
9851 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9852 continue;
9853 }
9854 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9855 uiccPortInfos.add(portInfo);
9856 } else {
9857 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9858 }
9859 }
9860 filteredInfos.add(new UiccCardInfo(
9861 cardInfo.isEuicc(),
9862 cardInfo.getCardId(),
9863 null,
9864 cardInfo.getPhysicalSlotIndex(),
9865 cardInfo.isRemovable(),
9866 cardInfo.isMultipleEnabledProfilesSupported(),
9867 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009868 }
9869 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009870 } finally {
9871 Binder.restoreCallingIdentity(identity);
9872 }
9873 }
9874
sandeepjsb6c87872021-09-27 15:34:44 +00009875 /**
9876 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9877 * generally private and require carrier privileges to view.
9878 *
9879 * @hide
9880 */
9881 @NonNull
9882 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9883 List<UiccPortInfo> portinfo = new ArrayList<>();
9884 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9885 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9886 }
9887 return new UiccCardInfo(
9888 cardInfo.isEuicc(),
9889 cardInfo.getCardId(),
9890 null,
9891 cardInfo.getPhysicalSlotIndex(),
9892 cardInfo.isRemovable(),
9893 cardInfo.isMultipleEnabledProfilesSupported(),
9894 portinfo
9895 );
9896 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009897
sandeepjsb6c87872021-09-27 15:34:44 +00009898 /**
9899 * @hide
9900 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9901 * These values are generally private and require carrier privileges to view.
9902 */
9903 @NonNull
9904 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9905 return new UiccPortInfo(
9906 UiccPortInfo.ICCID_REDACTED,
9907 portInfo.getPortIndex(),
9908 portInfo.getLogicalSlotIndex(),
9909 portInfo.isActive()
9910 );
9911 }
9912 @Override
9913 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009914 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009915 mApp.getSystemService(AppOpsManager.class)
9916 .checkPackage(Binder.getCallingUid(), callingPackage);
9917
sandeepjsb6c87872021-09-27 15:34:44 +00009918 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009919
Aman Guptaf3c90b32022-03-17 04:54:16 +00009920 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9921 // we are reading iccId which is PII data.
9922 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009923
joonhunshin4ac60942023-11-15 15:23:39 +00009924 enforceTelephonyFeatureWithException(callingPackage,
9925 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo");
9926
sandeepjsb6c87872021-09-27 15:34:44 +00009927 // checking compatibility, if calling app's target SDK is T and beyond.
9928 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9929 Binder.getCallingUid())) {
9930 isLogicalSlotAccessRestricted = true;
9931 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009932 final long identity = Binder.clearCallingIdentity();
9933 try {
9934 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009935 if (slots == null || slots.length == 0) {
9936 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009937 return null;
9938 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009939 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9940 for (int i = 0; i < slots.length; i++) {
9941 UiccSlot slot = slots[i];
9942 if (slot == null) {
9943 continue;
9944 }
9945
Jordan Liu7be7e652019-05-06 18:55:02 +00009946 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009947 UiccCard card = slot.getUiccCard();
9948 if (card != null) {
9949 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009950 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009951 cardId = slot.getEid();
9952 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009953 // If cardId is null, use iccId of default port as cardId.
9954 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009955 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009956 }
9957
Jordan Liu857451f2019-05-09 16:35:35 -07009958 if (cardId != null) {
9959 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9960 // if cardId is an EID, it's all digits so this is fine
9961 cardId = IccUtils.stripTrailingFs(cardId);
9962 }
9963
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009964 int cardState = 0;
9965 switch (slot.getCardState()) {
9966 case CARDSTATE_ABSENT:
9967 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9968 break;
9969 case CARDSTATE_PRESENT:
9970 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9971 break;
9972 case CARDSTATE_ERROR:
9973 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9974 break;
9975 case CARDSTATE_RESTRICTED:
9976 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9977 break;
9978 default:
9979 break;
9980
9981 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009982 List<UiccPortInfo> portInfos = new ArrayList<>();
9983 int[] portIndexes = slot.getPortList();
9984 for (int portIdx : portIndexes) {
9985 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009986 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009987 portInfos.add(new UiccPortInfo(iccId, portIdx,
9988 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009989 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009990 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009991 slot.isEuicc(),
9992 cardId,
9993 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009994 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009995 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009996 //setting the value after compatibility check
9997 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009998 }
9999 return infos;
10000 } finally {
10001 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -070010002 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010003 }
10004
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010005 /* Returns null if doesn't have read permission or carrier privilege access. */
10006 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
10007 boolean hasReadPermission) {
10008 String iccId = slot.getIccId(portIndex);
10009 if (hasReadPermission) { // if has read permission
10010 return iccId;
10011 } else {
10012 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
10013 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
10014 // if no read permission, checking carrier privilege access
10015 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
10016 return iccId;
10017 }
10018 }
10019 }
10020 // No read permission or carrier privilege access.
10021 return UiccPortInfo.ICCID_REDACTED;
10022 }
10023
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010024 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010025 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010026 public boolean switchSlots(int[] physicalSlots) {
10027 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010028
joonhunshin4ac60942023-11-15 15:23:39 +000010029 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10030 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots");
10031
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010032 final long identity = Binder.clearCallingIdentity();
10033 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010034 List<UiccSlotMapping> slotMappings = new ArrayList<>();
10035 for (int i = 0; i < physicalSlots.length; i++) {
10036 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
10037 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
10038 physicalSlots[i], i));
10039 }
10040 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010041 } finally {
10042 Binder.restoreCallingIdentity(identity);
10043 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010044 }
Jack Yu4c988042018-02-27 15:30:01 -080010045
10046 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010047 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
10048 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
10049 enforceModifyPermission();
10050
joonhunshin4ac60942023-11-15 15:23:39 +000010051 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10052 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping");
10053
sandeepjsb6c87872021-09-27 15:34:44 +000010054 final long identity = Binder.clearCallingIdentity();
10055 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010056 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +000010057 } finally {
10058 Binder.restoreCallingIdentity(identity);
10059 }
10060 }
10061
10062 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -080010063 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
joonhunshin4ac60942023-11-15 15:23:39 +000010064 enforceTelephonyFeatureWithException(callingPackage,
10065 PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc");
10066
Jordan Liu7de49fa2018-12-06 14:48:49 -080010067 final long identity = Binder.clearCallingIdentity();
10068 try {
10069 return UiccController.getInstance().getCardIdForDefaultEuicc();
10070 } finally {
10071 Binder.restoreCallingIdentity(identity);
10072 }
10073 }
10074
Pengquan Meng85728fb2018-03-12 16:31:21 -070010075 /**
goneil47ffb6e2018-04-06 15:40:58 -070010076 * A test API to reload the UICC profile.
10077 *
10078 * <p>Requires that the calling app has permission
10079 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
10080 * @hide
10081 */
10082 @Override
10083 public void refreshUiccProfile(int subId) {
10084 enforceModifyPermission();
10085
10086 final long identity = Binder.clearCallingIdentity();
10087 try {
10088 Phone phone = getPhone(subId);
10089 if (phone == null) {
10090 return;
10091 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010092 UiccPort uiccPort = phone.getUiccPort();
10093 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -070010094 return;
10095 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010096 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -070010097 if (uiccProfile == null) {
10098 return;
10099 }
10100 uiccProfile.refresh();
10101 } finally {
10102 Binder.restoreCallingIdentity(identity);
10103 }
10104 }
10105
10106 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010107 * Returns false if the mobile data is disabled by default, otherwise return true.
10108 */
10109 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010110 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010111 }
10112
10113 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010114 * Returns the default network type for the given {@code subId}, if the default network type is
10115 * not set, return {@link Phone#PREFERRED_NT_MODE}.
10116 */
10117 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010118 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -080010119 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +090010120 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
10121 return list.get(phoneId);
10122 }
10123 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -070010124 }
fionaxua13278b2018-03-21 00:08:13 -070010125
10126 @Override
10127 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -070010128 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -070010129 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010130
10131 final long identity = Binder.clearCallingIdentity();
10132 try {
10133 final Phone phone = getPhone(subId);
10134 if (phone == null) {
10135 loge("setCarrierTestOverride fails with invalid subId: " + subId);
10136 return;
10137 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -080010138 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10139 if (cpt != null) {
10140 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
10141 }
10142 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -070010143 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
10144 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -070010145 if (carrierPrivilegeRules == null) {
10146 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
10147 } else {
10148 mCarrierPrivilegeTestOverrideSubIds.add(subId);
10149 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010150 } finally {
10151 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010152 }
fionaxua13278b2018-03-21 00:08:13 -070010153 }
10154
10155 @Override
Benedict Wong66477622023-02-03 23:30:57 +000010156 public void setCarrierServicePackageOverride(
10157 int subId, String carrierServicePackage, String callingPackage) {
10158 TelephonyPermissions.enforceShellOnly(
10159 Binder.getCallingUid(), "setCarrierServicePackageOverride");
10160
Benedict Wong66477622023-02-03 23:30:57 +000010161 final long identity = Binder.clearCallingIdentity();
10162 try {
10163 final Phone phone = getPhone(subId);
10164 if (phone == null || phone.getSubId() != subId) {
10165 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
10166 throw new IllegalArgumentException("No phone for subid");
10167 }
10168 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10169 if (cpt == null) {
10170 loge("setCarrierServicePackageOverride failed with no CPT for phone");
10171 throw new IllegalStateException("No CPT for phone");
10172 }
10173 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
10174 } finally {
10175 Binder.restoreCallingIdentity(identity);
10176 }
10177 }
10178
10179 @Override
fionaxua13278b2018-03-21 00:08:13 -070010180 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -070010181 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010182
10183 final long identity = Binder.clearCallingIdentity();
10184 try {
10185 final Phone phone = getPhone(subId);
10186 if (phone == null) {
10187 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
10188 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
10189 }
10190 return phone.getCarrierIdListVersion();
10191 } finally {
10192 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010193 }
fionaxua13278b2018-03-21 00:08:13 -070010194 }
Malcolm Chen2c63d402018-08-14 16:00:53 -070010195
10196 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010197 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
10198 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010199 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010200 mApp, subId, callingPackage, callingFeatureId,
10201 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010202 return -1;
10203 }
10204
10205 final long identity = Binder.clearCallingIdentity();
10206 try {
10207 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10208 } finally {
10209 Binder.restoreCallingIdentity(identity);
10210 }
10211 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010212
10213 @Override
10214 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +080010215 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010216 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010217 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010218
joonhunshin4ac60942023-11-15 15:23:39 +000010219 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10220 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode");
10221
Pengquan Menga1bb6272018-09-06 09:59:22 -070010222 final long identity = Binder.clearCallingIdentity();
10223 try {
10224 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10225 } finally {
10226 Binder.restoreCallingIdentity(identity);
10227 }
10228 }
10229
10230 @Override
10231 public boolean setCdmaRoamingMode(int subId, int mode) {
10232 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10233 mApp, subId, "setCdmaRoamingMode");
10234
joonhunshin4ac60942023-11-15 15:23:39 +000010235 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10236 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode");
10237
Pengquan Menga1bb6272018-09-06 09:59:22 -070010238 final long identity = Binder.clearCallingIdentity();
10239 try {
10240 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10241 } finally {
10242 Binder.restoreCallingIdentity(identity);
10243 }
10244 }
10245
10246 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010247 public int getCdmaSubscriptionMode(int subId) {
10248 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010249 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010250 mApp, subId, "getCdmaSubscriptionMode");
10251
joonhunshin4ac60942023-11-15 15:23:39 +000010252 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10253 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode");
10254
Sarah Chinbaab1432020-10-28 13:46:24 -070010255 final long identity = Binder.clearCallingIdentity();
10256 try {
10257 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10258 } finally {
10259 Binder.restoreCallingIdentity(identity);
10260 }
10261 }
10262
10263 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010264 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10265 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10266 mApp, subId, "setCdmaSubscriptionMode");
10267
joonhunshin4ac60942023-11-15 15:23:39 +000010268 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10269 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode");
10270
Pengquan Menga1bb6272018-09-06 09:59:22 -070010271 final long identity = Binder.clearCallingIdentity();
10272 try {
10273 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10274 } finally {
10275 Binder.restoreCallingIdentity(identity);
10276 }
10277 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010278
sqianc5eccab2018-10-19 18:46:41 -070010279 @Override
sqian8c685422019-02-22 15:55:18 -080010280 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010281 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010282 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010283 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10284 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010285 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10286 }
joonhunshin4ac60942023-11-15 15:23:39 +000010287
10288 enforceTelephonyFeatureWithException(callingPackage,
10289 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList");
10290
sqian11b7a0e2018-12-05 18:48:28 -080010291 final long identity = Binder.clearCallingIdentity();
10292 try {
sqian854d44b2018-12-12 16:48:18 -080010293 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10294 for (Phone phone: PhoneFactory.getPhones()) {
10295 if (phone.getEmergencyNumberTracker() != null
10296 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10297 emergencyNumberListInternal.put(
10298 phone.getSubId(),
10299 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10300 }
sqian11b7a0e2018-12-05 18:48:28 -080010301 }
sqian854d44b2018-12-12 16:48:18 -080010302 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010303 } finally {
10304 Binder.restoreCallingIdentity(identity);
10305 }
sqianc5eccab2018-10-19 18:46:41 -070010306 }
10307
10308 @Override
sqian8c685422019-02-22 15:55:18 -080010309 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010310 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010311 if (!exactMatch) {
10312 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010313 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010314 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010315 }
joonhunshin4ac60942023-11-15 15:23:39 +000010316
10317 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10318 PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber");
10319
sqian11b7a0e2018-12-05 18:48:28 -080010320 final long identity = Binder.clearCallingIdentity();
10321 try {
sqian854d44b2018-12-12 16:48:18 -080010322 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010323 //Note: we ignore passed in param exactMatch. We can remove it once
10324 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010325 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010326 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010327 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010328 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010329 }
sqian11b7a0e2018-12-05 18:48:28 -080010330 }
10331 return false;
10332 } finally {
10333 Binder.restoreCallingIdentity(identity);
10334 }
10335 }
10336
sqianf4ca7ed2019-01-15 18:32:07 -080010337 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010338 * Start emergency callback mode for GsmCdmaPhone for testing.
10339 */
10340 @Override
10341 public void startEmergencyCallbackMode() {
10342 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10343 "startEmergencyCallbackMode");
10344 enforceModifyPermission();
10345 final long identity = Binder.clearCallingIdentity();
10346 try {
10347 for (Phone phone : PhoneFactory.getPhones()) {
10348 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10349 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10350 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10351 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10352 gsmCdmaPhone.obtainMessage(
10353 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10354 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10355 }
10356 }
10357 } finally {
10358 Binder.restoreCallingIdentity(identity);
10359 }
10360 }
10361
10362 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010363 * Update emergency number list for test mode.
10364 */
10365 @Override
10366 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10367 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10368 "updateEmergencyNumberListTestMode");
10369
10370 final long identity = Binder.clearCallingIdentity();
10371 try {
10372 for (Phone phone: PhoneFactory.getPhones()) {
10373 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10374 if (tracker != null) {
10375 tracker.executeEmergencyNumberTestModeCommand(action, num);
10376 }
10377 }
10378 } finally {
10379 Binder.restoreCallingIdentity(identity);
10380 }
10381 }
10382
10383 /**
10384 * Get the full emergency number list for test mode.
10385 */
10386 @Override
10387 public List<String> getEmergencyNumberListTestMode() {
10388 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10389 "getEmergencyNumberListTestMode");
10390
10391 final long identity = Binder.clearCallingIdentity();
10392 try {
10393 Set<String> emergencyNumbers = new HashSet<>();
10394 for (Phone phone: PhoneFactory.getPhones()) {
10395 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10396 if (tracker != null) {
10397 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10398 emergencyNumbers.add(num.getNumber());
10399 }
10400 }
10401 }
10402 return new ArrayList<>(emergencyNumbers);
10403 } finally {
10404 Binder.restoreCallingIdentity(identity);
10405 }
10406 }
10407
chen xud6b45bd2018-10-30 22:27:10 -070010408 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010409 public int getEmergencyNumberDbVersion(int subId) {
10410 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10411
joonhunshin4ac60942023-11-15 15:23:39 +000010412 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10413 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion");
10414
Shuo Qian3b6ee772019-11-13 17:43:31 -080010415 final long identity = Binder.clearCallingIdentity();
10416 try {
10417 final Phone phone = getPhone(subId);
10418 if (phone == null) {
10419 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10420 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10421 }
10422 return phone.getEmergencyNumberDbVersion();
10423 } finally {
10424 Binder.restoreCallingIdentity(identity);
10425 }
10426 }
10427
10428 @Override
10429 public void notifyOtaEmergencyNumberDbInstalled() {
10430 enforceModifyPermission();
10431
joonhunshin4ac60942023-11-15 15:23:39 +000010432 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10433 PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled");
10434
Shuo Qian3b6ee772019-11-13 17:43:31 -080010435 final long identity = Binder.clearCallingIdentity();
10436 try {
10437 for (Phone phone: PhoneFactory.getPhones()) {
10438 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10439 if (tracker != null) {
10440 tracker.updateOtaEmergencyNumberDatabase();
10441 }
10442 }
10443 } finally {
10444 Binder.restoreCallingIdentity(identity);
10445 }
10446 }
10447
10448 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010449 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010450 enforceActiveEmergencySessionPermission();
10451
joonhunshin4ac60942023-11-15 15:23:39 +000010452 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10453 PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath");
10454
Shuo Qian3b6ee772019-11-13 17:43:31 -080010455 final long identity = Binder.clearCallingIdentity();
10456 try {
10457 for (Phone phone: PhoneFactory.getPhones()) {
10458 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10459 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010460 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10461 }
10462 }
10463 } finally {
10464 Binder.restoreCallingIdentity(identity);
10465 }
10466 }
10467
10468 @Override
10469 public void resetOtaEmergencyNumberDbFilePath() {
10470 enforceActiveEmergencySessionPermission();
10471
joonhunshin4ac60942023-11-15 15:23:39 +000010472 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10473 PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath");
10474
Shuo Qianc373f112020-03-05 17:55:34 -080010475 final long identity = Binder.clearCallingIdentity();
10476 try {
10477 for (Phone phone: PhoneFactory.getPhones()) {
10478 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10479 if (tracker != null) {
10480 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010481 }
10482 }
10483 } finally {
10484 Binder.restoreCallingIdentity(identity);
10485 }
10486 }
10487
10488 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010489 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10490 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10491 Phone phone = getPhone(subId);
10492 if (phone == null) {
10493 return null;
10494 }
10495 final long identity = Binder.clearCallingIdentity();
10496 try {
10497 UiccProfile profile = UiccController.getInstance()
10498 .getUiccProfileForPhone(phone.getPhoneId());
10499 if (profile != null) {
10500 return profile.getCertsFromCarrierPrivilegeAccessRules();
10501 }
10502 } finally {
10503 Binder.restoreCallingIdentity(identity);
10504 }
10505 return null;
10506 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010507
10508 /**
10509 * Enable or disable a modem stack.
10510 */
10511 @Override
10512 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10513 enforceModifyPermission();
10514
joonhunshin4ac60942023-11-15 15:23:39 +000010515 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10516 PackageManager.FEATURE_TELEPHONY, "enableModemForSlot");
10517
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010518 final long identity = Binder.clearCallingIdentity();
10519 try {
10520 Phone phone = PhoneFactory.getPhone(slotIndex);
10521 if (phone == null) {
10522 return false;
10523 } else {
10524 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10525 }
10526 } finally {
10527 Binder.restoreCallingIdentity(identity);
10528 }
10529 }
Michelecea4cf22018-12-21 15:00:11 -080010530
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010531 /**
10532 * Whether a modem stack is enabled or not.
10533 */
10534 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010535 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10536 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010537 Phone phone = PhoneFactory.getPhone(slotIndex);
10538 if (phone == null) return false;
10539
10540 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010541 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10542 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010543 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10544 }
10545
joonhunshin4ac60942023-11-15 15:23:39 +000010546 enforceTelephonyFeatureWithException(callingPackage,
10547 PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot");
10548
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010549 final long identity = Binder.clearCallingIdentity();
10550 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010551 try {
10552 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10553 } catch (NoSuchElementException ex) {
10554 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10555 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010556 } finally {
10557 Binder.restoreCallingIdentity(identity);
10558 }
10559 }
10560
Michelecea4cf22018-12-21 15:00:11 -080010561 @Override
Michele0ea7d782019-03-19 14:58:42 -070010562 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010563 enforceModifyPermission();
10564
joonhunshin4ac60942023-11-15 15:23:39 +000010565 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10566 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction");
10567
Michelecea4cf22018-12-21 15:00:11 -080010568 final long identity = Binder.clearCallingIdentity();
10569 try {
10570 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010571 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010572 .commit();
10573 } finally {
10574 Binder.restoreCallingIdentity(identity);
10575 }
10576 }
10577
10578 @Override
Michele0ea7d782019-03-19 14:58:42 -070010579 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010580 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010581 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010582 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10583 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010584 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010585 }
Michelecea4cf22018-12-21 15:00:11 -080010586
joonhunshin4ac60942023-11-15 15:23:39 +000010587 enforceTelephonyFeatureWithException(callingPackage,
10588 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported");
10589
Michelecea4cf22018-12-21 15:00:11 -080010590 final long identity = Binder.clearCallingIdentity();
10591 try {
Michele0ea7d782019-03-19 14:58:42 -070010592 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010593 } finally {
10594 Binder.restoreCallingIdentity(identity);
10595 }
10596 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010597
Michele0ea7d782019-03-19 14:58:42 -070010598 @TelephonyManager.IsMultiSimSupportedResult
10599 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010600 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10601 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10602 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010603 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10604 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010605 }
10606 // Check if the hardware supports multisim functionality. If usage of multisim is not
10607 // supported by the modem, indicate that it is restricted.
10608 PhoneCapability staticCapability =
10609 mPhoneConfigurationManager.getStaticPhoneCapability();
10610 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010611 loge("isMultiSimSupportedInternal: no static configuration available");
10612 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010613 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010614 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010615 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10616 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010617 }
10618 // Check if support of multiple SIMs is restricted by carrier
10619 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010620 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010621 }
10622
Michele0ea7d782019-03-19 14:58:42 -070010623 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010624 }
10625
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010626 /**
10627 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010628 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10629 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10630 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010631 * @param numOfSims number of active sims we want to switch to
10632 */
10633 @Override
10634 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010635 if (numOfSims == 1) {
10636 enforceModifyPermission();
10637 } else {
10638 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10639 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10640 }
joonhunshin4ac60942023-11-15 15:23:39 +000010641
10642 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10643 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig");
10644
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010645 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010646
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010647 try {
Michele30b57b22019-03-01 12:01:14 -080010648 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010649 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010650 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10651 return;
10652 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010653 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10654 } finally {
10655 Binder.restoreCallingIdentity(identity);
10656 }
10657 }
10658
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010659 @Override
10660 public boolean isApplicationOnUicc(int subId, int appType) {
10661 enforceReadPrivilegedPermission("isApplicationOnUicc");
joonhunshin4ac60942023-11-15 15:23:39 +000010662
10663 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10664 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc");
10665
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010666 Phone phone = getPhone(subId);
10667 if (phone == null) {
10668 return false;
10669 }
10670 final long identity = Binder.clearCallingIdentity();
10671 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010672 UiccPort uiccPort = phone.getUiccPort();
10673 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010674 return false;
10675 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010676 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010677 if (uiccProfile == null) {
10678 return false;
10679 }
10680 if (TelephonyManager.APPTYPE_SIM <= appType
10681 && appType <= TelephonyManager.APPTYPE_ISIM) {
10682 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10683 }
10684 return false;
10685 } finally {
10686 Binder.restoreCallingIdentity(identity);
10687 }
10688 }
10689
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010690 /**
chen xub4baa772019-04-03 10:23:41 -070010691 * Get whether making changes to modem configurations will trigger reboot.
10692 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010693 */
10694 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010695 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10696 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010697 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010698 mApp, subId, callingPackage, callingFeatureId,
10699 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010700 return false;
10701 }
joonhunshin4ac60942023-11-15 15:23:39 +000010702
10703 enforceTelephonyFeatureWithException(callingPackage,
10704 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
10705 "doesSwitchMultiSimConfigTriggerReboot");
10706
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010707 final long identity = Binder.clearCallingIdentity();
10708 try {
10709 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10710 } finally {
10711 Binder.restoreCallingIdentity(identity);
10712 }
10713 }
10714
Nathan Harold29f5f052019-02-15 13:41:57 -080010715 private void updateModemStateMetrics() {
10716 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10717 // TODO: check the state for each modem if the api is ready.
10718 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10719 }
10720
Pengquan Meng3889a572019-01-23 11:16:29 -080010721 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010722 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010723 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010724 // Verify that the callingPackage belongs to the calling UID
10725 mApp.getSystemService(AppOpsManager.class)
10726 .checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000010727
10728 enforceTelephonyFeatureWithException(callingPackage,
10729 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping");
10730
Pengquan Meng3889a572019-01-23 11:16:29 -080010731 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010732 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010733 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010734 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10735 if (slotInfos != null) {
10736 for (int i = 0; i < slotInfos.length; i++) {
10737 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10738 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10739 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10740 portInfo.getLogicalSlotIndex()));
10741 }
10742 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010743 }
10744 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010745 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010746 } finally {
10747 Binder.restoreCallingIdentity(identity);
10748 }
10749 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010750
10751 /**
10752 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010753 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010754 */
jimsunf9ec1622022-09-13 21:18:43 +080010755 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010756 @Override
10757 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010758 return getHalVersion(HAL_SERVICE_RADIO);
10759 }
10760
10761 /**
10762 * Get the HAL Version of a specific service
10763 */
10764 @Override
10765 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010766 Phone phone = getDefaultPhone();
10767 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010768 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010769 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10770 return hv.major * 100 + hv.minor;
10771 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010772
10773 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010774 * Get the current calling package name.
sangyun097dcf72024-01-04 10:35:49 +090010775 *
10776 * @return the current calling package name, or null if there is no known package.
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010777 */
10778 @Override
sangyun097dcf72024-01-04 10:35:49 +090010779 public @Nullable String getCurrentPackageName() {
10780 PackageManager pm = mApp.getPackageManager();
10781 String[] packageNames = pm == null ? null : pm.getPackagesForUid(Binder.getCallingUid());
10782 return packageNames == null ? null : packageNames[0];
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010783 }
10784
10785 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010786 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10787 * corresponding network requests on a subId.
10788 *
10789 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010790 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010791 * 2) APN is un-metered for this subscription, or
10792 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010793 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010794 *
10795 * @return whether data is allowed for a apn type.
10796 *
10797 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010798 */
10799 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010800 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010801 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10802 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010803
joonhunshin4ac60942023-11-15 15:23:39 +000010804 enforceTelephonyFeatureWithException(callingPackage,
10805 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn");
10806
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010807 // Now that all security checks passes, perform the operation as ourselves.
10808 final long identity = Binder.clearCallingIdentity();
10809 try {
10810 Phone phone = getPhone(subId);
10811 if (phone == null) return false;
10812
Jack Yu27422a52022-03-21 10:38:05 -070010813 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010814 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010815 isMetered = phone.getDataNetworkController().getDataConfigManager()
10816 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10817 phone.getServiceState().getDataRoaming());
10818 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010819 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010820 } finally {
10821 Binder.restoreCallingIdentity(identity);
10822 }
10823 }
10824
10825 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010826 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010827 enforceReadPrivilegedPermission("isApnMetered");
10828
joonhunshin4ac60942023-11-15 15:23:39 +000010829 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10830 PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered");
10831
Malcolm Chene5ad5792019-04-18 13:51:02 -070010832 // Now that all security checks passes, perform the operation as ourselves.
10833 final long identity = Binder.clearCallingIdentity();
10834 try {
10835 Phone phone = getPhone(subId);
10836 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010837 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10838 DataUtils.apnTypeToNetworkCapability(apnType),
10839 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010840 } finally {
10841 Binder.restoreCallingIdentity(identity);
10842 }
10843 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010844
10845 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010846 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10847 int subscriptionId, IBooleanConsumer resultCallback) {
10848 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +000010849
10850 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10851 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels");
10852
Hall Liu73f5d362020-01-20 13:42:00 -080010853 long token = Binder.clearCallingIdentity();
10854 try {
10855 Phone phone = getPhone(subscriptionId);
10856 if (phone == null) {
10857 try {
10858 if (resultCallback != null) {
10859 resultCallback.accept(false);
10860 }
10861 } catch (RemoteException e) {
10862 // ignore
10863 }
10864 return;
10865 }
10866 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10867 Pair.create(specifiers, (x) -> {
10868 try {
10869 if (resultCallback != null) {
10870 resultCallback.accept(x);
10871 }
10872 } catch (RemoteException e) {
10873 // ignore
10874 }
10875 });
10876 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10877 } finally {
10878 Binder.restoreCallingIdentity(token);
10879 }
10880 }
10881
10882 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010883 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10884 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010885 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010886 mApp, subId, "getSystemSelectionChannels");
joonhunshin4ac60942023-11-15 15:23:39 +000010887
10888 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10889 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels");
10890
Sarah Chin679c08a2020-11-18 13:39:35 -080010891 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10892 final long identity = Binder.clearCallingIdentity();
10893 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010894 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10895 if (result instanceof IllegalStateException) {
10896 throw (IllegalStateException) result;
10897 }
10898 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010899 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10900 return specifiers;
10901 } finally {
10902 Binder.restoreCallingIdentity(identity);
10903 }
10904 }
10905
10906 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010907 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010908 enforceReadPrivilegedPermission("isMvnoMatched");
joonhunshin4ac60942023-11-15 15:23:39 +000010909
10910 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10911 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched");
10912
Jack Yu8b766fc2022-03-21 09:42:33 -070010913 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010914 }
10915
10916 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010917 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10918 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010919 if (callingPackage == null) {
10920 callingPackage = getCurrentPackageName();
10921 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010922 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10923 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010924 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10925 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010926 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10927 }
10928 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10929 Intent intent = new Intent();
10930 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10931 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10932 // Bring up choose default SMS subscription dialog right now
10933 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10934 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10935 mApp.startActivity(intent);
10936 }
chen xud5ca2d52019-05-28 15:20:57 -070010937
10938 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010939 public void showSwitchToManagedProfileDialog() {
10940 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000010941 try {
10942 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
10943 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
10944 // for work telephony.
10945 Intent intent = new Intent(Intent.ACTION_SENDTO);
10946 intent.setData(Uri.parse("smsto:"));
10947 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10948 mApp.startActivity(intent);
10949 } catch (ActivityNotFoundException e) {
10950 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
10951 Intent intent = new Intent();
10952 intent.setClass(mApp, ErrorDialogActivity.class);
10953 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10954 mApp.startActivity(intent);
10955 }
Ayush Sharma787854b2022-12-12 14:55:02 +000010956 }
10957
10958 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010959 public String getMmsUAProfUrl(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000010960 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10961 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl");
10962
chen xud5ca2d52019-05-28 15:20:57 -070010963 //TODO investigate if this API should require proper permission check in R b/133791609
10964 final long identity = Binder.clearCallingIdentity();
10965 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010966 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10967 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10968 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10969 return carrierUAProfUrl;
10970 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010971 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10972 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010973 } finally {
10974 Binder.restoreCallingIdentity(identity);
10975 }
10976 }
10977
10978 @Override
10979 public String getMmsUserAgent(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000010980 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10981 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent");
10982
chen xud5ca2d52019-05-28 15:20:57 -070010983 //TODO investigate if this API should require proper permission check in R b/133791609
10984 final long identity = Binder.clearCallingIdentity();
10985 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010986 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10987 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10988 if (!TextUtils.isEmpty(carrierUserAgent)) {
10989 return carrierUserAgent;
10990 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010991 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10992 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010993 } finally {
10994 Binder.restoreCallingIdentity(identity);
10995 }
10996 }
Jack Yub07d4972019-05-28 16:12:25 -070010997
10998 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010999 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
11000 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070011001
joonhunshin4ac60942023-11-15 15:23:39 +000011002 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11003 PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled");
11004
Jack Yub07d4972019-05-28 16:12:25 -070011005 final long identity = Binder.clearCallingIdentity();
11006 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011007 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070011008 if (phone == null) return false;
11009
Ling Maf188d502022-09-16 15:22:36 -070011010 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070011011 } finally {
11012 Binder.restoreCallingIdentity(identity);
11013 }
11014 }
11015
11016 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080011017 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070011018 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080011019 enforceModifyPermission();
11020
joonhunshin4ac60942023-11-15 15:23:39 +000011021 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11022 PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled");
11023
changbettyd5c246e2019-12-24 15:40:37 +080011024 final long identity = Binder.clearCallingIdentity();
11025 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011026 Phone phone = getPhone(subscriptionId);
11027 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080011028
Ling Maf188d502022-09-16 15:22:36 -070011029 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080011030 } finally {
11031 Binder.restoreCallingIdentity(identity);
11032 }
11033 }
11034
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011035 /**
Hall Liu746e03c2020-09-25 11:13:49 -070011036 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011037 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
11038 * otherwise.
11039 */
11040 @Override
11041 public void setCepEnabled(boolean isCepEnabled) {
11042 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
11043
11044 final long identity = Binder.clearCallingIdentity();
11045 try {
11046 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
11047 for (Phone phone : PhoneFactory.getPhones()) {
11048 Phone defaultPhone = phone.getImsPhone();
11049 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
11050 ImsPhone imsPhone = (ImsPhone) defaultPhone;
11051 ImsPhoneCallTracker imsPhoneCallTracker =
11052 (ImsPhoneCallTracker) imsPhone.getCallTracker();
11053 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
11054 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
11055 + imsPhone.getMsisdn());
11056 }
11057 }
11058 } finally {
11059 Binder.restoreCallingIdentity(identity);
11060 }
11061 }
allenwtsu46dcc572020-01-08 18:24:03 +080011062
11063 /**
11064 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
11065 *
11066 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
11067 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
11068 * before being read.
11069 */
11070 @Override
11071 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
11072 isCompressed) {
11073 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11074 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011075 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11076 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11077 }
joonhunshin4ac60942023-11-15 15:23:39 +000011078
11079 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11080 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11081 Binder.getCallingUserHandle())) {
11082 if (!isImsAvailableOnDevice()) {
11083 // ProvisioningManager can not handle ServiceSpecificException.
11084 // Throw the IllegalStateException and annotate ProvisioningManager.
11085 throw new IllegalStateException("IMS not available on device.");
11086 }
11087 } else {
11088 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11089 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11090 "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011091 }
11092
11093 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080011094 try {
Hui Wang761a6682020-10-31 05:12:53 +000011095 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
11096 } finally {
11097 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080011098 }
11099 }
zoey chene02881a2019-12-30 16:11:23 +080011100
11101 @Override
11102 public boolean isIccLockEnabled(int subId) {
11103 enforceReadPrivilegedPermission("isIccLockEnabled");
11104
joonhunshin4ac60942023-11-15 15:23:39 +000011105 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11106 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled");
11107
zoey chene02881a2019-12-30 16:11:23 +080011108 // Now that all security checks passes, perform the operation as ourselves.
11109 final long identity = Binder.clearCallingIdentity();
11110 try {
11111 Phone phone = getPhone(subId);
11112 if (phone != null && phone.getIccCard() != null) {
11113 return phone.getIccCard().getIccLockEnabled();
11114 } else {
11115 return false;
11116 }
11117 } finally {
11118 Binder.restoreCallingIdentity(identity);
11119 }
11120 }
11121
11122 /**
11123 * Set the ICC pin lock enabled or disabled.
11124 *
11125 * @return an integer representing the status of IccLock enabled or disabled in the following
11126 * three cases:
11127 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
11128 * successfully.
11129 * - Positive number and zero for remaining password attempts.
11130 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11131 *
11132 */
11133 @Override
11134 public int setIccLockEnabled(int subId, boolean enabled, String password) {
11135 enforceModifyPermission();
11136
joonhunshin4ac60942023-11-15 15:23:39 +000011137 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11138 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled");
11139
zoey chene02881a2019-12-30 16:11:23 +080011140 Phone phone = getPhone(subId);
11141 if (phone == null) {
11142 return 0;
11143 }
11144 // Now that all security checks passes, perform the operation as ourselves.
11145 final long identity = Binder.clearCallingIdentity();
11146 try {
11147 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
11148 new Pair<Boolean, String>(enabled, password), phone, null);
11149 return attemptsRemaining;
11150
11151 } catch (Exception e) {
11152 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
11153 } finally {
11154 Binder.restoreCallingIdentity(identity);
11155 }
11156 return 0;
11157 }
11158
11159 /**
11160 * Change the ICC password used in ICC pin lock.
11161 *
11162 * @return an integer representing the status of IccLock changed in the following three cases:
11163 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
11164 * - Positive number and zero for remaining password attempts.
11165 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11166 *
11167 */
11168 @Override
11169 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
11170 enforceModifyPermission();
11171
joonhunshin4ac60942023-11-15 15:23:39 +000011172 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11173 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword");
11174
zoey chene02881a2019-12-30 16:11:23 +080011175 Phone phone = getPhone(subId);
11176 if (phone == null) {
11177 return 0;
11178 }
11179 // Now that all security checks passes, perform the operation as ourselves.
11180 final long identity = Binder.clearCallingIdentity();
11181 try {
11182 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
11183 new Pair<String, String>(oldPassword, newPassword), phone, null);
11184 return attemptsRemaining;
11185
11186 } catch (Exception e) {
11187 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
11188 } finally {
11189 Binder.restoreCallingIdentity(identity);
11190 }
11191 return 0;
11192 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080011193
11194 /**
11195 * Request for receiving user activity notification
11196 */
11197 @Override
11198 public void requestUserActivityNotification() {
11199 if (!mNotifyUserActivity.get()
11200 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
11201 mNotifyUserActivity.set(true);
11202 }
11203 }
11204
11205 /**
11206 * Called when userActivity is signalled in the power manager.
11207 * This is safe to call from any thread, with any window manager locks held or not.
11208 */
11209 @Override
11210 public void userActivity() {
11211 // ***************************************
11212 // * Inherited from PhoneWindowManager *
11213 // ***************************************
11214 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
11215 // WITH ITS LOCKS HELD.
11216 //
11217 // This code must be VERY careful about the locks
11218 // it acquires.
11219 // In fact, the current code acquires way too many,
11220 // and probably has lurking deadlocks.
11221
11222 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
11223 throw new SecurityException("Only the OS may call notifyUserActivity()");
11224 }
11225
11226 if (mNotifyUserActivity.getAndSet(false)) {
11227 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
11228 USER_ACTIVITY_NOTIFICATION_DELAY);
11229 }
11230 }
Malcolm Chen4639c562020-04-13 11:59:40 -070011231
11232 @Override
11233 public boolean canConnectTo5GInDsdsMode() {
11234 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
11235 }
Jack Yud10cdd42020-09-28 20:28:01 -070011236
11237 @Override
11238 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
11239 String callingFeatureId) {
11240 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
11241 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
11242 throw new SecurityException("Requires READ_PHONE_STATE permission.");
11243 }
11244
joonhunshin4ac60942023-11-15 15:23:39 +000011245 enforceTelephonyFeatureWithException(callingPackage,
11246 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns");
11247
Jack Yud10cdd42020-09-28 20:28:01 -070011248 Phone phone = getPhone(subId);
11249 if (phone == null) {
11250 throw new RuntimeException("phone is not available");
11251 }
11252 // Now that all security checks passes, perform the operation as ourselves.
11253 final long identity = Binder.clearCallingIdentity();
11254 try {
11255 return phone.getEquivalentHomePlmns();
11256 } finally {
11257 Binder.restoreCallingIdentity(identity);
11258 }
11259 }
Daniel Bright59e67312020-11-13 11:49:37 -080011260
11261 @Override
11262 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011263 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
joonhunshin4ac60942023-11-15 15:23:39 +000011264 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11265 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
11266 "isRadioInterfaceCapabilitySupported");
11267
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011268 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080011269 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080011270 if (radioInterfaceCapabilities == null) {
11271 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080011272 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011273 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080011274 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011275
Hui Wang641e81c2020-10-12 12:14:23 -070011276 @Override
11277 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
11278 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000011279 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
11280 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11281 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
11282 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11283 Manifest.permission.MODIFY_PHONE_STATE);
joonhunshin4ac60942023-11-15 15:23:39 +000011284
11285 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11286 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest");
11287
Hui Wang641e81c2020-10-12 12:14:23 -070011288 if (DBG) {
11289 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
11290 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
11291 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
11292 }
11293
11294 if (!SubscriptionManager.isValidSubscriptionId(subId)
11295 || appType < TelephonyManager.APPTYPE_UNKNOWN
11296 || appType > TelephonyManager.APPTYPE_ISIM
11297 || nafUrl == null || securityProtocol == null || callback == null) {
11298 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
11299 if (callback != null) {
11300 try {
11301 callback.onAuthenticationFailure(
11302 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
11303 } catch (RemoteException exception) {
11304 log("Fail to notify onAuthenticationFailure due to " + exception);
11305 }
11306 return;
11307 }
11308 }
11309
11310 final long token = Binder.clearCallingIdentity();
11311 try {
11312 getGbaManager(subId).bootstrapAuthenticationRequest(
11313 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011314 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070011315 } finally {
11316 Binder.restoreCallingIdentity(token);
11317 }
11318 }
11319
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011320 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011321 * Attempts to set the radio power state for all phones for thermal reason.
11322 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011323 * requested radio power state will actually be set. See {@link
11324 * PhoneInternalInterface#setRadioPowerForReason} for more details.
11325 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011326 * @param enable {@code true} if trying to turn radio on.
11327 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
11328 * false}.
11329 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011330 private boolean setRadioPowerForThermal(boolean enable) {
11331 boolean isPhoneAvailable = false;
11332 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
11333 Phone phone = PhoneFactory.getPhone(i);
11334 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011335 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011336 isPhoneAvailable = true;
11337 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011338 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011339
11340 // return true if successfully informed the phone object about the thermal radio power
11341 // request.
11342 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011343 }
11344
11345 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011346 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011347 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11348 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11349 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11350 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11351 throw new IllegalArgumentException("modem does not support data throttling");
11352 }
11353
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011354 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11355 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011356 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011357 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11358 }
11359
Sarah Chinecc78c42022-03-31 21:16:48 -070011360 setDataEnabledForReason(
11361 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011362
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011363 if (isDataThrottlingSupported) {
11364 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011365 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011366 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11367 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11368 } else if (thermalMitigationResult
11369 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011370 log("Modem likely does not support data throttling on secondary carrier. Data " +
11371 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11372 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011373 }
11374 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011375 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011376
11377 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011378 }
11379
Jack Nudelman644b91a2021-03-12 14:09:48 -080011380 private static List<String> getThermalMitigationAllowlist(Context context) {
11381 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11382 for (String pckg : context.getResources()
11383 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11384 sThermalMitigationAllowlistedPackages.add(pckg);
11385 }
11386 }
11387
11388 return sThermalMitigationAllowlistedPackages;
11389 }
11390
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011391 private boolean isAnyPhoneInEmergencyState() {
11392 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11393 if (tm.isInEmergencyCall()) {
11394 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11395 return true;
11396 }
11397 for (Phone phone : PhoneFactory.getPhones()) {
11398 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11399 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011400 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11401 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011402 return true;
11403 }
11404 }
11405
11406 return false;
11407 }
11408
Jack Nudelman644b91a2021-03-12 14:09:48 -080011409 /**
11410 * Used by shell commands to add an authorized package name for thermal mitigation.
11411 * @param packageName name of package to be allowlisted
11412 * @param context
11413 */
11414 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11415 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11416 sThermalMitigationAllowlistedPackages.add(packageName);
11417 }
11418
11419 /**
11420 * Used by shell commands to remove an authorized package name for thermal mitigation.
11421 * @param packageName name of package to remove from allowlist
11422 * @param context
11423 */
11424 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11425 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11426 sThermalMitigationAllowlistedPackages.remove(packageName);
11427 }
11428
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011429 /**
11430 * Thermal mitigation request to control functionalities at modem.
11431 *
11432 * @param subId the id of the subscription.
11433 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011434 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011435 *
11436 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11437 */
11438 @Override
11439 @ThermalMitigationResult
11440 public int sendThermalMitigationRequest(
11441 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011442 ThermalMitigationRequest thermalMitigationRequest,
11443 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011444 enforceModifyPermission();
11445
Jack Nudelman644b91a2021-03-12 14:09:48 -080011446 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000011447
11448 enforceTelephonyFeatureWithException(callingPackage,
11449 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest");
11450
Jack Nudelman644b91a2021-03-12 14:09:48 -080011451 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11452 .contains(callingPackage)) {
11453 throw new SecurityException("Calling package must be configured in the device config. "
11454 + "calling package: " + callingPackage);
11455 }
11456
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011457 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11458 final long identity = Binder.clearCallingIdentity();
11459
11460 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11461 try {
11462 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11463 switch (thermalMitigationAction) {
11464 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11465 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011466 handleDataThrottlingRequest(subId,
11467 thermalMitigationRequest.getDataThrottlingRequest(),
11468 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011469 break;
11470 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11471 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11472 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11473 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11474 }
11475
11476 // Ensure that radio is on. If not able to power on due to phone being
11477 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011478 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011479 thermalMitigationResult =
11480 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11481 break;
11482 }
11483
11484 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011485 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011486 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11487 break;
11488 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11489 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11490 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11491 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11492 }
11493
11494 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11495 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011496 Phone phone = getPhone(subId);
11497 if (phone == null) {
11498 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011499 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011500 break;
11501 }
11502
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011503 TelephonyConnectionService service =
11504 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011505 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011506 Log.e(LOG_TAG, "An emergency call is pending");
11507 thermalMitigationResult =
11508 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11509 break;
11510 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011511 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011512 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011513 break;
11514 }
11515 } else {
11516 thermalMitigationResult =
11517 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11518 break;
11519 }
11520
11521 // Turn radio off. If not able to power off due to phone being unavailable,
11522 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011523 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011524 thermalMitigationResult =
11525 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11526 break;
11527 }
11528 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011529 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011530 break;
11531 default:
11532 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11533 + "not exist. Requested action: " + thermalMitigationAction);
11534 }
11535 } catch (IllegalArgumentException e) {
11536 throw e;
11537 } catch (Exception e) {
11538 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11539 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11540 } finally {
11541 Binder.restoreCallingIdentity(identity);
11542 }
11543
11544 if (DBG) {
11545 log("thermalMitigationRequest returning with thermalMitigationResult: "
11546 + thermalMitigationResult);
11547 }
11548
11549 return thermalMitigationResult;
11550 }
Hui Wang641e81c2020-10-12 12:14:23 -070011551
11552 /**
11553 * Set the GbaService Package Name that Telephony will bind to.
11554 *
11555 * @param subId The sim that the GbaService is associated with.
11556 * @param packageName The name of the package to be replaced with.
11557 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11558 */
11559 @Override
11560 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11561 enforceModifyPermission();
11562
11563 final long identity = Binder.clearCallingIdentity();
11564 try {
11565 return getGbaManager(subId).overrideServicePackage(packageName);
11566 } finally {
11567 Binder.restoreCallingIdentity(identity);
11568 }
11569 }
11570
11571 /**
11572 * Return the package name of the currently bound GbaService.
11573 *
11574 * @param subId The sim that the GbaService is associated with.
11575 * @return the package name of the GbaService configuration, null if GBA is not supported.
11576 */
11577 @Override
11578 public String getBoundGbaService(int subId) {
11579 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11580
11581 final long identity = Binder.clearCallingIdentity();
11582 try {
11583 return getGbaManager(subId).getServicePackage();
11584 } finally {
11585 Binder.restoreCallingIdentity(identity);
11586 }
11587 }
11588
11589 /**
11590 * Set the release time for telephony to unbind GbaService.
11591 *
11592 * @param subId The sim that the GbaService is associated with.
11593 * @param interval The release time to unbind GbaService by millisecond.
11594 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11595 */
11596 @Override
11597 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11598 enforceModifyPermission();
11599
11600 final long identity = Binder.clearCallingIdentity();
11601 try {
11602 return getGbaManager(subId).overrideReleaseTime(interval);
11603 } finally {
11604 Binder.restoreCallingIdentity(identity);
11605 }
11606 }
11607
11608 /**
11609 * Return the release time for telephony to unbind GbaService.
11610 *
11611 * @param subId The sim that the GbaService is associated with.
11612 * @return The release time to unbind GbaService by millisecond.
11613 */
11614 @Override
11615 public int getGbaReleaseTime(int subId) {
11616 enforceReadPrivilegedPermission("getGbaReleaseTime");
11617
11618 final long identity = Binder.clearCallingIdentity();
11619 try {
11620 return getGbaManager(subId).getReleaseTime();
11621 } finally {
11622 Binder.restoreCallingIdentity(identity);
11623 }
11624 }
11625
11626 private GbaManager getGbaManager(int subId) {
11627 GbaManager instance = GbaManager.getInstance(subId);
11628 if (instance == null) {
11629 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11630 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11631 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11632 }
11633 return instance;
11634 }
Hui Wang761a6682020-10-31 05:12:53 +000011635
11636 /**
11637 * indicate whether the device and the carrier can support
11638 * RCS VoLTE single registration.
11639 */
11640 @Override
11641 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011642 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11643 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11644 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11645 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011646
11647 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11648 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11649 }
11650
11651 final long identity = Binder.clearCallingIdentity();
11652 try {
11653 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11654 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011655 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11656 if (isCapable != null) {
11657 return isCapable;
11658 }
Hui Wang761a6682020-10-31 05:12:53 +000011659 }
Hui Wang67af90e2021-06-04 16:57:15 -070011660 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11661 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011662 } finally {
11663 Binder.restoreCallingIdentity(identity);
11664 }
11665 }
11666
11667 /**
11668 * Register RCS provisioning callback.
11669 */
11670 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011671 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011672 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011673 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011674 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011675 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11676 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011677
11678 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11679 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11680 }
joonhunshin4ac60942023-11-15 15:23:39 +000011681 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11682 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11683 Binder.getCallingUserHandle())) {
11684 if (!isImsAvailableOnDevice()) {
11685 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11686 "IMS not available on device.");
11687 }
11688 } else {
11689 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11690 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011691 }
11692
11693 final long identity = Binder.clearCallingIdentity();
11694 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011695 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011696 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011697 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11698 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011699 }
Hui Wang761a6682020-10-31 05:12:53 +000011700 } finally {
11701 Binder.restoreCallingIdentity(identity);
11702 }
11703 }
11704
11705 /**
11706 * Unregister RCS provisioning callback.
11707 */
11708 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011709 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011710 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011711 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011712 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011713 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11714 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011715
11716 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11717 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11718 }
joonhunshin4ac60942023-11-15 15:23:39 +000011719
11720 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11721 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11722 Binder.getCallingUserHandle())) {
11723 if (!isImsAvailableOnDevice()) {
11724 // operation failed silently
11725 Rlog.w(LOG_TAG, "IMS not available on device.");
11726 return;
11727 }
11728 } else {
11729 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11730 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11731 "unregisterRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011732 }
11733
11734 final long identity = Binder.clearCallingIdentity();
11735 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011736 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011737 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011738 } finally {
11739 Binder.restoreCallingIdentity(identity);
11740 }
11741 }
11742
11743 /**
11744 * trigger RCS reconfiguration.
11745 */
11746 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011747 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11748 "triggerRcsReconfiguration",
11749 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011750
11751 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11752 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11753 }
joonhunshin4ac60942023-11-15 15:23:39 +000011754 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11755 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11756 Binder.getCallingUserHandle())) {
11757 if (!isImsAvailableOnDevice()) {
11758 // ProvisioningManager can not handle ServiceSpecificException.
11759 // Throw the IllegalStateException and annotate ProvisioningManager.
11760 throw new IllegalStateException("IMS not available on device.");
11761 }
11762 } else {
11763 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11764 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011765 }
11766
11767 final long identity = Binder.clearCallingIdentity();
11768 try {
11769 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11770 } finally {
11771 Binder.restoreCallingIdentity(identity);
11772 }
11773 }
11774
11775 /**
11776 * Provide the client configuration parameters of the RCS application.
11777 */
11778 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011779 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11780 "setRcsClientConfiguration",
11781 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011782
11783 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11784 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11785 }
joonhunshin4ac60942023-11-15 15:23:39 +000011786 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11787 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11788 Binder.getCallingUserHandle())) {
11789 if (!isImsAvailableOnDevice()) {
11790 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11791 "IMS not available on device.");
11792 }
11793 } else {
11794 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11795 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011796 }
11797
11798 final long identity = Binder.clearCallingIdentity();
11799
11800 try {
11801 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11802 if (configBinder == null) {
11803 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011804 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11805 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011806 } else {
11807 configBinder.setRcsClientConfiguration(rcc);
11808 }
joonhunshin3e154242021-09-17 06:33:39 +000011809
11810 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11811 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011812 } catch (RemoteException e) {
11813 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011814 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11815 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011816 } finally {
11817 Binder.restoreCallingIdentity(identity);
11818 }
11819 }
11820
11821 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011822 * Enables or disables the test mode for RCS VoLTE single registration.
11823 */
11824 @Override
11825 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11826 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11827 "setRcsSingleRegistrationTestModeEnabled");
11828
11829 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11830 }
11831
11832 /**
11833 * Gets the test mode for RCS VoLTE single registration.
11834 */
11835 @Override
11836 public boolean getRcsSingleRegistrationTestModeEnabled() {
11837 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11838 "getRcsSingleRegistrationTestModeEnabled");
11839
11840 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11841 }
11842
11843 /**
Hui Wang761a6682020-10-31 05:12:53 +000011844 * Overrides the config of RCS VoLTE single registration enabled for the device.
11845 */
11846 @Override
11847 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11848 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11849 "setDeviceSingleRegistrationEnabledOverride");
11850 enforceModifyPermission();
11851
11852 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11853 : Boolean.parseBoolean(enabledStr);
11854 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011855 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011856 }
11857
11858 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011859 * Sends a device to device communication message. Only usable via shell.
11860 * @param message message to send.
11861 * @param value message value.
11862 */
11863 @Override
11864 public void sendDeviceToDeviceMessage(int message, int value) {
11865 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011866 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011867 enforceModifyPermission();
11868
11869 final long identity = Binder.clearCallingIdentity();
11870 try {
11871 TelephonyConnectionService service =
11872 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11873 if (service == null) {
11874 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11875 return;
11876 }
11877 service.sendTestDeviceToDeviceMessage(message, value);
11878 } finally {
11879 Binder.restoreCallingIdentity(identity);
11880 }
11881 }
11882
Tyler Gunnbabbda02021-02-10 11:05:02 -080011883 /**
11884 * Sets the specified device to device transport active.
11885 * @param transport The transport to set active.
11886 */
11887 @Override
11888 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11889 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11890 "setActiveDeviceToDeviceTransport");
11891 enforceModifyPermission();
11892
11893 final long identity = Binder.clearCallingIdentity();
11894 try {
11895 TelephonyConnectionService service =
11896 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11897 if (service == null) {
11898 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11899 return;
11900 }
11901 service.setActiveDeviceToDeviceTransport(transport);
11902 } finally {
11903 Binder.restoreCallingIdentity(identity);
11904 }
11905 }
Tyler Gunn92479152021-01-20 16:30:10 -080011906
Tyler Gunnd4339262021-05-03 14:46:49 -070011907 @Override
11908 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11909 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11910 "setDeviceToDeviceForceEnabled");
11911
11912 final long identity = Binder.clearCallingIdentity();
11913 try {
11914 Arrays.stream(PhoneFactory.getPhones()).forEach(
11915 p -> {
11916 Phone thePhone = p.getImsPhone();
11917 if (thePhone != null && thePhone instanceof ImsPhone) {
11918 ImsPhone imsPhone = (ImsPhone) thePhone;
11919 CallTracker tracker = imsPhone.getCallTracker();
11920 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11921 ImsPhoneCallTracker imsPhoneCallTracker =
11922 (ImsPhoneCallTracker) tracker;
11923 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11924 }
11925 }
11926 }
11927 );
11928 } finally {
11929 Binder.restoreCallingIdentity(identity);
11930 }
11931 }
11932
Tyler Gunn92479152021-01-20 16:30:10 -080011933 /**
Hui Wang761a6682020-10-31 05:12:53 +000011934 * Gets the config of RCS VoLTE single registration enabled for the device.
11935 */
11936 @Override
11937 public boolean getDeviceSingleRegistrationEnabled() {
11938 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11939 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11940 }
11941
11942 /**
11943 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11944 */
11945 @Override
11946 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11947 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11948 "setCarrierSingleRegistrationEnabledOverride");
11949 enforceModifyPermission();
11950
11951 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11952 : Boolean.parseBoolean(enabledStr);
11953 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11954 subId, enabled);
11955 }
11956
11957 /**
11958 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11959 */
11960 @Override
11961 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11962 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11963 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11964 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011965
11966 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011967 * Overrides the ims feature validation result
11968 */
11969 @Override
11970 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11971 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11972 "setImsFeatureValidationOverride");
11973
11974 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11975 : Boolean.parseBoolean(enabledStr);
11976 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11977 subId, enabled);
11978 }
11979
11980 /**
11981 * Gets the ims feature validation override value
11982 */
11983 @Override
11984 public boolean getImsFeatureValidationOverride(int subId) {
11985 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11986 "getImsFeatureValidationOverride");
11987 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11988 }
11989
11990 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011991 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11992 * their mobile plan.
11993 */
11994 @Override
11995 public String getMobileProvisioningUrl() {
11996 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
11997 final long identity = Binder.clearCallingIdentity();
11998 try {
11999 return getDefaultPhone().getMobileProvisioningUrl();
12000 } finally {
12001 Binder.restoreCallingIdentity(identity);
12002 }
12003 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012004
James.cf Linbcdf8b32021-01-14 16:44:13 +080012005 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080012006 * Get the EAB contact from the EAB database.
12007 */
12008 @Override
12009 public String getContactFromEab(String contact) {
12010 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
12011 enforceModifyPermission();
12012 final long identity = Binder.clearCallingIdentity();
12013 try {
12014 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
12015 } finally {
12016 Binder.restoreCallingIdentity(identity);
12017 }
12018 }
12019
12020 /**
Calvin Pana1434322021-07-01 19:27:01 +080012021 * Get the EAB capability from the EAB database.
12022 */
12023 @Override
12024 public String getCapabilityFromEab(String contact) {
12025 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
12026 enforceModifyPermission();
12027 final long identity = Binder.clearCallingIdentity();
12028 try {
12029 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
12030 } finally {
12031 Binder.restoreCallingIdentity(identity);
12032 }
12033 }
12034
12035 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080012036 * Remove the EAB contacts from the EAB database.
12037 */
12038 @Override
12039 public int removeContactFromEab(int subId, String contacts) {
12040 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
12041 enforceModifyPermission();
12042 final long identity = Binder.clearCallingIdentity();
12043 try {
12044 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
12045 } finally {
12046 Binder.restoreCallingIdentity(identity);
12047 }
12048 }
12049
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012050 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080012051 public boolean getDeviceUceEnabled() {
12052 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
12053 final long identity = Binder.clearCallingIdentity();
12054 try {
12055 return mApp.getDeviceUceEnabled();
12056 } finally {
12057 Binder.restoreCallingIdentity(identity);
12058 }
12059 }
12060
12061 @Override
12062 public void setDeviceUceEnabled(boolean isEnabled) {
12063 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
12064 final long identity = Binder.clearCallingIdentity();
12065 try {
12066 mApp.setDeviceUceEnabled(isEnabled);
12067 } finally {
12068 Binder.restoreCallingIdentity(identity);
12069 }
12070 }
12071
Brad Ebinger14d467f2021-02-12 06:18:28 +000012072 /**
12073 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
12074 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12075 */
12076 // Used for SHELL command only right now.
12077 @Override
12078 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
12079 List<String> featureTags) {
12080 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12081 "addUceRegistrationOverrideShell");
12082 final long identity = Binder.clearCallingIdentity();
12083 try {
12084 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
12085 new ArraySet<>(featureTags));
12086 } catch (ImsException e) {
12087 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12088 } finally {
12089 Binder.restoreCallingIdentity(identity);
12090 }
12091 }
12092
12093 /**
12094 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
12095 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12096 */
12097 // Used for SHELL command only right now.
12098 @Override
12099 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
12100 List<String> featureTags) {
12101 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12102 "removeUceRegistrationOverrideShell");
12103 final long identity = Binder.clearCallingIdentity();
12104 try {
12105 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
12106 new ArraySet<>(featureTags));
12107 } catch (ImsException e) {
12108 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12109 } finally {
12110 Binder.restoreCallingIdentity(identity);
12111 }
12112 }
12113
12114 /**
12115 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
12116 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12117 */
12118 // Used for SHELL command only right now.
12119 @Override
12120 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
12121 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12122 "clearUceRegistrationOverrideShell");
12123 final long identity = Binder.clearCallingIdentity();
12124 try {
12125 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
12126 } catch (ImsException e) {
12127 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12128 } finally {
12129 Binder.restoreCallingIdentity(identity);
12130 }
12131 }
12132
12133 /**
12134 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12135 */
12136 // Used for SHELL command only right now.
12137 @Override
12138 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
12139 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12140 "getLatestRcsContactUceCapabilityShell");
12141 final long identity = Binder.clearCallingIdentity();
12142 try {
12143 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
12144 } catch (ImsException e) {
12145 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12146 } finally {
12147 Binder.restoreCallingIdentity(identity);
12148 }
12149 }
12150
12151 /**
12152 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
12153 * device does not have an active PUBLISH.
12154 */
12155 // Used for SHELL command only right now.
12156 @Override
12157 public String getLastUcePidfXmlShell(int subId) {
12158 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
12159 final long identity = Binder.clearCallingIdentity();
12160 try {
12161 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
12162 } catch (ImsException e) {
12163 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12164 } finally {
12165 Binder.restoreCallingIdentity(identity);
12166 }
12167 }
12168
James.cf Line8713a42021-04-29 16:04:26 +080012169 /**
12170 * Remove UCE requests cannot be sent to the network status.
12171 */
12172 // Used for SHELL command only right now.
12173 @Override
12174 public boolean removeUceRequestDisallowedStatus(int subId) {
12175 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
12176 final long identity = Binder.clearCallingIdentity();
12177 try {
12178 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
12179 } catch (ImsException e) {
12180 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12181 } finally {
12182 Binder.restoreCallingIdentity(identity);
12183 }
12184 }
12185
James.cf Lin18bb9002021-05-25 01:37:38 +080012186 /**
12187 * Remove UCE requests cannot be sent to the network status.
12188 */
12189 // Used for SHELL command only.
12190 @Override
12191 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
12192 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
12193 final long identity = Binder.clearCallingIdentity();
12194 try {
12195 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
12196 } catch (ImsException e) {
12197 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12198 } finally {
12199 Binder.restoreCallingIdentity(identity);
12200 }
12201 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000012202
James.cf Lin4b784aa2021-01-31 03:25:15 +080012203 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012204 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12205 String callingPackage) {
12206 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12207 mApp, subId, "setSignalStrengthUpdateRequest");
12208
joonhunshin4ac60942023-11-15 15:23:39 +000012209 enforceTelephonyFeatureWithException(callingPackage,
12210 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest");
12211
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012212 final int callingUid = Binder.getCallingUid();
12213 // Verify that tha callingPackage belongs to the calling UID
12214 mApp.getSystemService(AppOpsManager.class)
12215 .checkPackage(callingUid, callingPackage);
12216
Rambo Wang3607f502021-02-01 21:51:40 -080012217 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012218
12219 final long identity = Binder.clearCallingIdentity();
12220 try {
12221 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
12222 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12223
12224 if (result instanceof IllegalStateException) {
12225 throw (IllegalStateException) result;
12226 }
12227 } finally {
12228 Binder.restoreCallingIdentity(identity);
12229 }
12230 }
12231
12232 @Override
12233 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12234 String callingPackage) {
12235 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12236 mApp, subId, "clearSignalStrengthUpdateRequest");
12237
joonhunshin4ac60942023-11-15 15:23:39 +000012238 enforceTelephonyFeatureWithException(callingPackage,
12239 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest");
12240
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012241 final int callingUid = Binder.getCallingUid();
12242 // Verify that tha callingPackage belongs to the calling UID
12243 mApp.getSystemService(AppOpsManager.class)
12244 .checkPackage(callingUid, callingPackage);
12245
12246 final long identity = Binder.clearCallingIdentity();
12247 try {
12248 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
12249 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12250
12251 if (result instanceof IllegalStateException) {
12252 throw (IllegalStateException) result;
12253 }
12254 } finally {
12255 Binder.restoreCallingIdentity(identity);
12256 }
12257 }
12258
Rambo Wang3607f502021-02-01 21:51:40 -080012259 private static void validateSignalStrengthUpdateRequest(Context context,
12260 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012261 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
12262 // phone/system process do not have further restriction on request
12263 return;
12264 }
12265
12266 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080012267 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012268 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080012269 context.enforceCallingOrSelfPermission(
12270 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
12271 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012272 }
12273
12274 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000012275 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012276 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012277 || info.isEnabled()) {
12278 throw new IllegalArgumentException(
12279 "Only system can set hide fields in SignalThresholdInfo");
12280 }
12281
12282 // Thresholds length for each RAN need in range. This has been validated in
12283 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
12284 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
12285 final int[] thresholds = info.getThresholds();
12286 Objects.requireNonNull(thresholds);
12287 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
12288 || thresholds.length
12289 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
12290 throw new IllegalArgumentException(
12291 "thresholds length is out of range: " + thresholds.length);
12292 }
12293 }
12294 }
SongFerngWang8236caa2021-01-17 21:51:44 +080012295
12296 /**
12297 * Gets the current phone capability.
12298 *
12299 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
12300 * @return the PhoneCapability which describes the data connection capability of modem.
12301 * It's used to evaluate possible phone config change, for example from single
12302 * SIM device to multi-SIM device.
12303 */
12304 @Override
12305 public PhoneCapability getPhoneCapability() {
12306 enforceReadPrivilegedPermission("getPhoneCapability");
joonhunshin4ac60942023-11-15 15:23:39 +000012307
12308 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12309 PackageManager.FEATURE_TELEPHONY, "getPhoneCapability");
12310
SongFerngWang8236caa2021-01-17 21:51:44 +080012311 final long identity = Binder.clearCallingIdentity();
12312 try {
12313 return mPhoneConfigurationManager.getCurrentPhoneCapability();
12314 } finally {
12315 Binder.restoreCallingIdentity(identity);
12316 }
12317 }
Michele Berionne5e411512020-11-13 02:36:59 +000012318
12319 /**
12320 * Prepare TelephonyManager for an unattended reboot. The reboot is
12321 * required to be done shortly after the API is invoked.
12322 */
12323 @Override
12324 @TelephonyManager.PrepareUnattendedRebootResult
12325 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012326 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000012327 enforceRebootPermission();
12328
joonhunshin4ac60942023-11-15 15:23:39 +000012329 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12330 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot");
12331
Michele Berionne5e411512020-11-13 02:36:59 +000012332 final long identity = Binder.clearCallingIdentity();
12333 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012334 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000012335 } finally {
12336 Binder.restoreCallingIdentity(identity);
12337 }
12338 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012339
12340 /**
12341 * Request to get the current slicing configuration including URSP rules and
12342 * NSSAIs (configured, allowed and rejected).
12343 *
12344 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
12345 */
12346 @Override
12347 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000012348 TelephonyPermissions
12349 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
12350 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012351
joonhunshin4ac60942023-11-15 15:23:39 +000012352 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12353 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
12354 "getSlicingConfig");
12355
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012356 final long identity = Binder.clearCallingIdentity();
12357 try {
12358 Phone phone = getDefaultPhone();
12359 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
12360 } finally {
12361 Binder.restoreCallingIdentity(identity);
12362 }
12363 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012364
12365 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070012366 * Check whether the given premium capability is available for purchase from the carrier.
12367 *
12368 * @param capability The premium capability to check.
12369 * @param subId The subId to check the premium capability for.
12370 *
12371 * @return Whether the given premium capability is available to purchase.
12372 */
12373 @Override
12374 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
12375 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12376 mApp, "isPremiumCapabilityAvailableForPurchase")) {
12377 log("Premium capability "
12378 + TelephonyManager.convertPremiumCapabilityToString(capability)
12379 + " is not available for purchase due to missing permissions.");
12380 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
12381 + "permission READ_BASIC_PHONE_STATE.");
12382 }
12383
joonhunshin4ac60942023-11-15 15:23:39 +000012384 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12385 PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase");
12386
Sarah Chin2ec39f62022-08-31 17:03:26 -070012387 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080012388 if (phone == null) {
12389 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12390 return false;
12391 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012392 final long identity = Binder.clearCallingIdentity();
12393 try {
Sarah Chincc5446f2023-10-23 17:57:19 -070012394 return SlicePurchaseController.getInstance(phone, mFeatureFlags)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012395 .isPremiumCapabilityAvailableForPurchase(capability);
12396 } finally {
12397 Binder.restoreCallingIdentity(identity);
12398 }
12399 }
12400
12401 /**
12402 * Purchase the given premium capability from the carrier.
12403 *
12404 * @param capability The premium capability to purchase.
12405 * @param callback The result of the purchase request.
12406 * @param subId The subId to purchase the premium capability for.
12407 */
12408 @Override
12409 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12410 log("purchasePremiumCapability: capability="
12411 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12412 + getCurrentPackageName());
12413
12414 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12415 mApp, "purchasePremiumCapability")) {
12416 log("purchasePremiumCapability "
12417 + TelephonyManager.convertPremiumCapabilityToString(capability)
12418 + " failed due to missing permissions.");
12419 throw new SecurityException("purchasePremiumCapability requires permission "
12420 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012421 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12422 mApp, "purchasePremiumCapability")) {
12423 log("purchasePremiumCapability "
12424 + TelephonyManager.convertPremiumCapabilityToString(capability)
12425 + " failed due to missing permissions.");
12426 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012427 }
12428
joonhunshin4ac60942023-11-15 15:23:39 +000012429 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12430 PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability");
12431
Sarah Chin2ec39f62022-08-31 17:03:26 -070012432 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012433 if (phone == null) {
12434 try {
12435 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12436 callback.accept(result);
12437 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12438 } catch (RemoteException e) {
12439 String logStr = "Purchase premium capability "
12440 + TelephonyManager.convertPremiumCapabilityToString(capability)
12441 + " failed due to RemoteException handling null phone: " + e;
12442 if (DBG) log(logStr);
12443 AnomalyReporter.reportAnomaly(
12444 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12445 }
12446 return;
12447 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012448
12449 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012450 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012451 callingProcess = mApp.getPackageManager().getApplicationInfo(
12452 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070012453 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012454 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012455 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012456
12457 boolean isVisible = false;
12458 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12459 if (am != null) {
12460 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12461 if (processes != null) {
12462 for (ActivityManager.RunningAppProcessInfo process : processes) {
12463 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070012464 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080012465 if (process.processName.equals(callingProcess) && process.importance
12466 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12467 isVisible = true;
12468 break;
12469 }
12470 }
12471 }
12472 }
12473
12474 if (!isVisible) {
12475 try {
12476 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12477 callback.accept(result);
12478 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12479 } catch (RemoteException e) {
12480 String logStr = "Purchase premium capability "
12481 + TelephonyManager.convertPremiumCapabilityToString(capability)
12482 + " failed due to RemoteException handling background application: " + e;
12483 if (DBG) log(logStr);
12484 AnomalyReporter.reportAnomaly(
12485 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12486 }
12487 return;
12488 }
12489
Sarah Chin71b3a852022-09-28 15:54:19 -070012490 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012491 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012492 }
12493
12494 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012495 * Register an IMS connection state callback
12496 */
12497 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012498 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12499 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012500 if (feature == ImsFeature.FEATURE_MMTEL) {
12501 // ImsMmTelManager
12502 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12503 TelephonyPermissions
12504 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12505 mApp, subId, "registerImsStateCallback");
12506 } else if (feature == ImsFeature.FEATURE_RCS) {
12507 // ImsRcsManager or SipDelegateManager
12508 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12509 Binder.getCallingUid(), "registerImsStateCallback",
12510 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12511 Manifest.permission.READ_PRECISE_PHONE_STATE,
12512 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12513 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12514 }
12515
12516 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12517 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12518 "IMS not available on device.");
12519 }
12520
12521 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12522 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12523 }
12524
12525 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12526 if (controller == null) {
12527 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12528 "IMS not available on device.");
12529 }
12530
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012531 if (callingPackage == null) {
12532 callingPackage = getCurrentPackageName();
12533 }
12534
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012535 final long token = Binder.clearCallingIdentity();
12536 try {
12537 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012538 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012539 } catch (ImsException e) {
12540 throw new ServiceSpecificException(e.getCode());
12541 } finally {
12542 Binder.restoreCallingIdentity(token);
12543 }
12544 }
12545
12546 /**
12547 * Unregister an IMS connection state callback
12548 */
12549 @Override
12550 public void unregisterImsStateCallback(IImsStateCallback cb) {
12551 final long token = Binder.clearCallingIdentity();
12552 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12553 if (controller == null) {
12554 return;
12555 }
12556 try {
12557 controller.unregisterImsStateCallback(cb);
12558 } finally {
12559 Binder.restoreCallingIdentity(token);
12560 }
12561 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012562
12563 /**
12564 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12565 *
12566 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012567 * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012568 * SecurityException.
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012569 *
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012570 * If there is current registered network this value will be same as the registered cell
12571 * identity. If the device goes out of service the previous cell identity is cached and
12572 * will be returned. If the cache age of the Cell identity is more than 24 hours
12573 * it will be cleared and null will be returned.
12574 *
12575 */
12576 @Override
12577 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12578 String callingFeatureId) {
12579 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12580 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12581 LocationAccessPolicy.checkLocationPermission(mApp,
12582 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12583 .setCallingPackage(callingPackage)
12584 .setCallingFeatureId(callingFeatureId)
12585 .setCallingPid(Binder.getCallingPid())
12586 .setCallingUid(Binder.getCallingUid())
12587 .setMethod("getLastKnownCellIdentity")
12588 .setLogAsInfo(true)
12589 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12590 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12591 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12592 .build());
12593
12594 boolean hasFinePermission =
12595 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12596 if (!hasFinePermission
12597 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12598 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012599 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012600 }
12601
12602 final long identity = Binder.clearCallingIdentity();
12603 try {
Ling Mac28f0212023-03-24 16:07:15 -070012604 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012605 if (sst == null) return null;
12606 return sst.getLastKnownCellIdentity();
12607 } finally {
12608 Binder.restoreCallingIdentity(identity);
12609 }
12610 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012611
jimsun3b9ccac2021-10-26 15:01:23 +080012612 /**
12613 * Sets the modem service class Name that Telephony will bind to.
12614 *
12615 * @param serviceName The class name of the modem service.
12616 * @return true if the operation is succeed, otherwise false.
12617 */
12618 public boolean setModemService(String serviceName) {
12619 Log.d(LOG_TAG, "setModemService - " + serviceName);
12620 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12621 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012622 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12623 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012624 return mPhoneConfigurationManager.setModemService(serviceName);
12625 }
12626
12627 /**
12628 * Return the class name of the currently bounded modem service.
12629 *
12630 * @return the class name of the modem service.
12631 */
12632 public String getModemService() {
12633 String result;
12634 Log.d(LOG_TAG, "getModemService");
12635 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12636 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012637 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012638 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12639 "getModemService");
12640 result = mPhoneConfigurationManager.getModemService();
12641 Log.d(LOG_TAG, "result = " + result);
12642 return result;
12643 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012644
Hakjun Choi3ee81112023-12-19 15:40:58 +000012645 /**
12646 * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources,
12647 * including carrier config, entitlement server, and config update.
12648 *
12649 * @param subId subId The subscription ID of the carrier.
12650 *
12651 * @return List of plmns for carrier satellite service. If no plmn is available, empty list will
12652 * be returned.
12653 *
12654 * @throws SecurityException if the caller doesn't have the required permission.
12655 */
Hakjun Choi74c16be2024-01-19 08:18:09 +000012656 @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) {
12657 enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier");
Hakjun Choi3ee81112023-12-19 15:40:58 +000012658 final long identity = Binder.clearCallingIdentity();
12659 try {
Hakjun Choi74c16be2024-01-19 08:18:09 +000012660 return mSatelliteController.getSatellitePlmnsForCarrier(subId);
Hakjun Choi3ee81112023-12-19 15:40:58 +000012661 } finally {
12662 Binder.restoreCallingIdentity(identity);
12663 }
12664 }
12665
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012666 @Override
12667 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12668 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12669 mApp.enforceCallingOrSelfPermission(
12670 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12671 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12672
12673 final long identity = Binder.clearCallingIdentity();
12674 try {
12675 Phone phone = getPhone(subId);
12676 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012677 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12678 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012679 phone.setVoiceServiceStateOverride(hasService);
12680 } finally {
12681 Binder.restoreCallingIdentity(identity);
12682 }
12683 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012684
12685 /**
12686 * set removable eSIM as default eUICC.
12687 *
12688 * @hide
12689 */
12690 @Override
12691 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12692 enforceModifyPermission();
12693 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12694
12695 final long identity = Binder.clearCallingIdentity();
12696 try {
12697 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12698 } finally {
12699 Binder.restoreCallingIdentity(identity);
12700 }
12701 }
12702
12703 /**
12704 * Returns whether the removable eSIM is default eUICC or not.
12705 *
12706 * @hide
12707 */
12708 @Override
12709 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12710 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12711 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12712
12713 final long identity = Binder.clearCallingIdentity();
12714 try {
12715 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12716 } finally {
12717 Binder.restoreCallingIdentity(identity);
12718 }
12719 }
12720
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012721 /**
12722 * Get the component name of the default app to direct respond-via-message intent for the
12723 * user associated with this subscription, update the cache if there is no respond-via-message
12724 * application currently configured for this user.
12725 * @return component name of the app and class to direct Respond Via Message intent to, or
12726 * {@code null} if the functionality is not supported.
12727 * @hide
12728 */
12729 @Override
12730 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12731 boolean updateIfNeeded) {
12732 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012733
joonhunshin4ac60942023-11-15 15:23:39 +000012734 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12735 PackageManager.FEATURE_TELEPHONY_MESSAGING,
12736 "getDefaultRespondViaMessageApplication");
12737
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012738 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12739
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012740 UserHandle userHandle = null;
12741 final long identity = Binder.clearCallingIdentity();
12742 try {
12743 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12744 } finally {
12745 Binder.restoreCallingIdentity(identity);
12746 }
12747 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12748 updateIfNeeded, userHandle);
12749 }
Jack Yuf5badd92022-12-08 00:50:53 -080012750
12751 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012752 * Set whether the device is able to connect with null ciphering or integrity
12753 * algorithms. This is a global setting and will apply to all active subscriptions
12754 * and all new subscriptions after this.
12755 *
12756 * @param enabled when true, null cipher and integrity algorithms are allowed.
12757 * @hide
12758 */
12759 @Override
12760 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12761 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12762 enforceModifyPermission();
12763 checkForNullCipherAndIntegritySupport();
12764
12765 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12766 // for listening to these preference changes and applying them immediately.
12767 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12768 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12769 editor.apply();
12770
12771 for (Phone phone: PhoneFactory.getPhones()) {
12772 phone.handleNullCipherEnabledChange();
12773 }
12774 }
12775
12776
12777 /**
12778 * Get whether the device is able to connect with null ciphering or integrity
12779 * algorithms. Note that this retrieves the phone-global preference and not
12780 * the state of the radio.
12781 *
12782 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12783 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12784 * version for this feature.
12785 * @hide
12786 */
12787 @Override
12788 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12789 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12790 enforceReadPermission();
12791 checkForNullCipherAndIntegritySupport();
12792 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12793 }
12794
12795 private void checkForNullCipherAndIntegritySupport() {
12796 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12797 throw new UnsupportedOperationException(
12798 "Null cipher and integrity operations require HAL 2.1 or above");
12799 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012800 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12801 throw new UnsupportedOperationException(
12802 "Null cipher and integrity operations unsupported by modem");
12803 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012804 }
12805
Gil Cukierman06403e12023-11-29 16:33:03 +000012806 private void checkForIdentifierDisclosureNotificationSupport() {
12807 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) {
12808 throw new UnsupportedOperationException(
12809 "Cellular identifier disclosure transparency operations require HAL 2.2 or "
12810 + "above");
12811 }
12812 if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) {
12813 throw new UnsupportedOperationException(
12814 "Cellular identifier disclosure transparency operations unsupported by modem");
12815 }
12816 }
12817
Michael Groover826b71d2023-12-21 22:08:06 -060012818 private void checkForNullCipherNotificationSupport() {
12819 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) {
12820 throw new UnsupportedOperationException(
12821 "Null cipher notification operations require HAL 2.2 or above");
12822 }
12823 if (!getDefaultPhone().isNullCipherNotificationSupported()) {
12824 throw new UnsupportedOperationException(
12825 "Null cipher notification operations unsupported by modem");
12826 }
12827 }
12828
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012829 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012830 * Get the SIM state for the slot index.
12831 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12832 *
12833 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12834 */
12835 @Override
12836 @SimState
12837 public int getSimStateForSlotIndex(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +000012838 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12839 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex");
12840
Jack Yuf5badd92022-12-08 00:50:53 -080012841 IccCardConstants.State simState;
12842 if (slotIndex < 0) {
12843 simState = IccCardConstants.State.UNKNOWN;
12844 } else {
12845 Phone phone = null;
12846 try {
12847 phone = PhoneFactory.getPhone(slotIndex);
12848 } catch (IllegalStateException e) {
12849 // ignore
12850 }
12851 if (phone == null) {
12852 simState = IccCardConstants.State.UNKNOWN;
12853 } else {
12854 IccCard icc = phone.getIccCard();
12855 if (icc == null) {
12856 simState = IccCardConstants.State.UNKNOWN;
12857 } else {
12858 simState = icc.getState();
12859 }
12860 }
12861 }
12862 return simState.ordinal();
12863 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012864
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012865 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
12866 boolean enableLogcat,
12867 long logcatStartTimestampMillis, boolean enableTelecomDump,
12868 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012869 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012870 TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder =
12871 new TelephonyManager.EmergencyCallDiagnosticData.Builder();
12872 ecdDataBuilder
12873 .setTelecomDumpsysCollectionEnabled(enableTelecomDump)
12874 .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012875 if (enableLogcat) {
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012876 ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012877 }
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012878 TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build();
12879 Log.d(LOG_TAG, "persisting with Params " + ecdData.toString());
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012880 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
12881 Executors.newCachedThreadPool(), db,
12882 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012883 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012884 }
12885
12886 /**
12887 * Request telephony to persist state for debugging emergency call failures.
12888 *
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012889 * @param dropboxTag Tag to use when persisting data to dropbox service.
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012890 * @param enableLogcat whether to collect logcat output
12891 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
12892 * @param enableTelecomDump whether to collect telecom dumpsys
12893 * @param enableTelephonyDump whether to collect telephony dumpsys
12894 */
12895 @Override
12896 @RequiresPermission(android.Manifest.permission.DUMP)
12897 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
12898 long logcatStartTimestampMillis, boolean enableTelecomDump,
12899 boolean enableTelephonyDump) {
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -080012900 // Verify that the caller has READ_DROPBOX_DATA permission.
12901 if (mTelecomFeatureFlags.telecomResolveHiddenDependencies()
12902 && Flags.enableReadDropboxPermission()) {
12903 mApp.enforceCallingPermission(permission.READ_DROPBOX_DATA,
12904 "persistEmergencyCallDiagnosticData");
12905 } else {
12906 // Otherwise, enforce legacy permission.
12907 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
12908 "persistEmergencyCallDiagnosticData");
12909 }
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012910 final long identity = Binder.clearCallingIdentity();
12911 try {
12912 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
12913 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
12914
12915 } finally {
12916 Binder.restoreCallingIdentity(identity);
12917 }
12918 }
12919
Hui Wang9b5793a2022-12-05 14:38:06 -060012920 /**
12921 * Get current cell broadcast ranges.
12922 */
12923 @Override
12924 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12925 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12926 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12927 "getCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012928
12929 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12930 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges");
12931
Hui Wang9b5793a2022-12-05 14:38:06 -060012932 final long identity = Binder.clearCallingIdentity();
12933 try {
12934 return getPhone(subId).getCellBroadcastIdRanges();
12935 } finally {
12936 Binder.restoreCallingIdentity(identity);
12937 }
12938 }
12939
12940 /**
12941 * Set reception of cell broadcast messages with the list of the given ranges
12942 *
12943 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12944 */
12945 @Override
12946 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12947 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12948 @Nullable IIntegerConsumer callback) {
12949 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12950 "setCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012951
12952 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12953 PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges");
12954
Hui Wang9b5793a2022-12-05 14:38:06 -060012955 final long identity = Binder.clearCallingIdentity();
12956 try {
12957 Phone phone = getPhoneFromSubId(subId);
12958 if (DBG) {
12959 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12960 }
12961 phone.setCellBroadcastIdRanges(ranges, result -> {
12962 if (callback != null) {
12963 try {
12964 callback.accept(result);
12965 } catch (RemoteException e) {
12966 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12967 }
12968 }
12969 });
12970 } finally {
12971 Binder.restoreCallingIdentity(identity);
12972 }
12973 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012974
12975 /**
12976 * Returns whether the device supports the domain selection service.
12977 *
12978 * @return {@code true} if the device supports the domain selection service.
12979 */
12980 @Override
12981 public boolean isDomainSelectionSupported() {
12982 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12983 "isDomainSelectionSupported");
12984
12985 final long identity = Binder.clearCallingIdentity();
12986 try {
12987 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12988 } finally {
12989 Binder.restoreCallingIdentity(identity);
12990 }
12991 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012992
12993 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012994 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
12995 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
12996 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080012997 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012998 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chinabf081b2023-03-09 23:00:57 -080012999 * @param enableSatellite {@code true} to enable the satellite modem and
13000 * {@code false} to disable.
13001 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
Thomas Nguyena8062672024-02-05 14:18:19 -080013002 * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise.
Sarah Chinabf081b2023-03-09 23:00:57 -080013003 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080013004 *
13005 * @throws SecurityException if the caller doesn't have the required permission.
13006 */
13007 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013008 public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode,
Thomas Nguyena8062672024-02-05 14:18:19 -080013009 boolean isEmergency, @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013010 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013011 if (enableSatellite) {
13012 ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) {
13013 @Override
13014 protected void onReceiveResult(int resultCode, Bundle resultData) {
13015 Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode
13016 + ", resultData=" + resultData);
13017 boolean isAllowed = false;
13018 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(
13019 callback::accept);
13020 if (resultCode == SATELLITE_RESULT_SUCCESS) {
13021 if (resultData != null
13022 && resultData.containsKey(KEY_SATELLITE_COMMUNICATION_ALLOWED)) {
13023 isAllowed = resultData.getBoolean(KEY_SATELLITE_COMMUNICATION_ALLOWED);
13024 } else {
13025 loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist.");
13026 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013027 } else {
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013028 result.accept(resultCode);
13029 return;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013030 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013031 if (isAllowed) {
13032 mSatelliteController.requestSatelliteEnabled(
13033 subId, enableSatellite, enableDemoMode, callback);
13034 } else {
13035 result.accept(SATELLITE_RESULT_ACCESS_BARRED);
13036 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013037 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013038 };
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013039 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013040 subId, resultReceiver);
13041 } else {
13042 // No need to check if satellite is allowed at current location when disabling satellite
13043 mSatelliteController.requestSatelliteEnabled(
13044 subId, enableSatellite, enableDemoMode, callback);
13045 }
Sarah Chin503828c2023-02-01 23:54:20 -080013046 }
13047
13048 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013049 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080013050 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013051 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013052 * @param result The result receiver that returns whether the satellite modem is enabled
13053 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013054 *
13055 * @throws SecurityException if the caller doesn't have the required permission.
13056 */
13057 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013058 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
13059 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013060 mSatelliteController.requestIsSatelliteEnabled(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013061 }
13062
13063 /**
Sarah Chin43457982023-02-15 17:50:38 -080013064 * Request to get whether the satellite service demo mode is enabled.
13065 *
13066 * @param subId The subId of the subscription to check whether the satellite demo mode
13067 * is enabled for.
13068 * @param result The result receiver that returns whether the satellite demo mode is enabled
13069 * if the request is successful or an error code if the request failed.
13070 *
13071 * @throws SecurityException if the caller doesn't have the required permission.
13072 */
13073 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013074 public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
13075 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
13076 mSatelliteController.requestIsDemoModeEnabled(subId, result);
Sarah Chin43457982023-02-15 17:50:38 -080013077 }
13078
13079 /**
Thomas Nguyena8062672024-02-05 14:18:19 -080013080 * Request to get whether the satellite service is enabled with emergency mode.
13081 *
13082 * @param subId The subId of the subscription to check whether the satellite demo mode
13083 * is enabled for.
13084 * @param result The result receiver that returns whether the satellite emergency mode is
13085 * enabled if the request is successful or an error code if the request failed.
13086 *
13087 * @throws SecurityException if the caller doesn't have the required permission.
13088 */
13089 @Override
13090 public void requestIsEmergencyModeEnabled(int subId, @NonNull ResultReceiver result) {
13091 enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled");
13092 result.send(SATELLITE_RESULT_REQUEST_NOT_SUPPORTED, null);
13093 }
13094
13095 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013096 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080013097 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013098 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013099 * @param result The result receiver that returns whether the satellite service is supported on
13100 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013101 */
13102 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013103 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013104 mSatelliteController.requestIsSatelliteSupported(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013105 }
13106
13107 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013108 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080013109 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013110 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013111 * @param result The result receiver that returns the {@link SatelliteCapabilities}
13112 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013113 *
13114 * @throws SecurityException if the caller doesn't have required permission.
13115 */
13116 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013117 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
13118 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013119 mSatelliteController.requestSatelliteCapabilities(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013120 }
13121
13122 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013123 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013124 * This can be called by the pointing UI when the user starts pointing to the satellite.
13125 * Modem should continue to report the pointing input as the device or satellite moves.
13126 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013127 * @param subId The subId of the subscription to start satellite transmission updates for.
13128 * @param resultCallback The callback to get the result of the request.
13129 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080013130 *
13131 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013132 */
13133 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013134 public void startSatelliteTransmissionUpdates(int subId,
13135 @NonNull IIntegerConsumer resultCallback,
13136 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13137 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
13138 mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080013139 }
13140
13141 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013142 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013143 * This can be called by the pointing UI when the user stops pointing to the satellite.
13144 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013145 * @param subId The subId of the subscription to stop satellite transmission updates for.
13146 * @param resultCallback The callback to get the result of the request.
13147 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
13148 * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080013149 *
13150 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013151 */
13152 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013153 public void stopSatelliteTransmissionUpdates(int subId,
13154 @NonNull IIntegerConsumer resultCallback,
13155 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13156 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
13157 mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013158 }
13159
13160 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013161 * Register the subscription with a satellite provider.
13162 * This is needed to register the subscription if the provider allows dynamic registration.
13163 *
13164 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013165 * @param token The token to be used as a unique identifier for provisioning with satellite
13166 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013167 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080013168 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013169 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013170 * @return The signal transport used by the caller to cancel the provision request,
13171 * or {@code null} if the request failed.
13172 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013173 * @throws SecurityException if the caller doesn't have the required permission.
13174 */
13175 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013176 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013177 @NonNull String token, @NonNull byte[] provisionData,
13178 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013179 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013180 return mSatelliteController.provisionSatelliteService(subId, token, provisionData,
13181 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013182 }
13183
13184 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013185 * Unregister the device/subscription with the satellite provider.
13186 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013187 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013188 * should report as deprovisioned.
13189 *
13190 * @param subId The subId of the subscription to be deprovisioned.
13191 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080013192 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013193 *
13194 * @throws SecurityException if the caller doesn't have the required permission.
13195 */
13196 @Override
13197 public void deprovisionSatelliteService(int subId,
13198 @NonNull String token, @NonNull IIntegerConsumer callback) {
13199 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013200 mSatelliteController.deprovisionSatelliteService(subId, token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013201 }
13202
13203 /**
Sarah Chin43457982023-02-15 17:50:38 -080013204 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013205 *
Sarah Chin43457982023-02-15 17:50:38 -080013206 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013207 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013208 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013209 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013210 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013211 * @throws SecurityException if the caller doesn't have the required permission.
13212 */
13213 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013214 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
13215 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013216 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013217 return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013218 }
13219
13220 /**
Sarah Chin43457982023-02-15 17:50:38 -080013221 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013222 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013223 *
Sarah Chin43457982023-02-15 17:50:38 -080013224 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013225 * @param callback The callback that was passed to
13226 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013227 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013228 * @throws SecurityException if the caller doesn't have the required permission.
13229 */
13230 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013231 public void unregisterForSatelliteProvisionStateChanged(
13232 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013233 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013234 mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013235 }
13236
13237 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013238 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013239 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013240 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013241 * @param result The result receiver that returns whether the device is provisioned with a
13242 * satellite provider if the request is successful or an error code if the
13243 * request failed.
13244 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013245 * @throws SecurityException if the caller doesn't have the required permission.
13246 */
13247 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013248 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
13249 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013250 mSatelliteController.requestIsSatelliteProvisioned(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013251 }
13252
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013253 /**
Sarah Chin43457982023-02-15 17:50:38 -080013254 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013255 *
Sarah Chin43457982023-02-15 17:50:38 -080013256 * @param subId The subId of the subscription to register for satellite modem state changed.
13257 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080013258 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013259 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013260 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013261 * @throws SecurityException if the caller doesn't have the required permission.
13262 */
13263 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013264 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013265 @NonNull ISatelliteModemStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080013266 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013267 return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013268 }
13269
13270 /**
Sarah Chin43457982023-02-15 17:50:38 -080013271 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013272 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013273 *
Sarah Chin43457982023-02-15 17:50:38 -080013274 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080013275 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013276 * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013277 *
13278 * @throws SecurityException if the caller doesn't have the required permission.
13279 */
13280 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013281 public void unregisterForModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013282 @NonNull ISatelliteModemStateCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013283 enforceSatelliteCommunicationPermission("unregisterForModemStateChanged");
13284 mSatelliteController.unregisterForModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013285 }
13286
13287 /**
13288 * Register to receive incoming datagrams over satellite.
13289 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013290 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Sarah Chindf715ec2023-02-13 13:46:24 -080013291 * @param callback The callback to handle incoming datagrams over satellite.
13292 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013293 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013294 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013295 * @throws SecurityException if the caller doesn't have the required permission.
13296 */
13297 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013298 @SatelliteManager.SatelliteResult public int registerForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013299 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013300 enforceSatelliteCommunicationPermission("registerForIncomingDatagram");
13301 return mSatelliteController.registerForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013302 }
13303
13304 /**
13305 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013306 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013307 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013308 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
13309 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013310 * {@link #registerForIncomingDatagram(int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013311 *
13312 * @throws SecurityException if the caller doesn't have the required permission.
13313 */
13314 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013315 public void unregisterForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013316 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013317 enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram");
13318 mSatelliteController.unregisterForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013319 }
13320
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013321 /**
13322 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013323 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013324 * This method requests modem to check if there are any pending datagrams to be received over
13325 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000013326 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080013327 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013328 * @param subId The subId of the subscription used for receiving datagrams.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013329 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013330 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013331 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013332 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013333 public void pollPendingDatagrams(int subId, IIntegerConsumer callback) {
13334 enforceSatelliteCommunicationPermission("pollPendingDatagrams");
13335 mSatelliteController.pollPendingDatagrams(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013336 }
13337
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013338 /**
13339 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013340 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013341 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
13342 * input to this method. Datagram received here will be passed down to modem without any
13343 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080013344 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013345 * @param subId The subId of the subscription to send satellite datagrams for.
13346 * @param datagramType datagram type indicating whether the datagram is of type
13347 * SOS_SMS or LOCATION_SHARING.
13348 * @param datagram encoded gateway datagram which is encrypted by the caller.
13349 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000013350 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
13351 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013352 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013353 *
13354 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013355 */
13356 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013357 public void sendDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000013358 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
13359 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013360 enforceSatelliteCommunicationPermission("sendDatagram");
13361 mSatelliteController.sendDatagram(subId, datagramType, datagram, needFullScreenPointingUI,
13362 callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013363 }
13364
Sarah Chindf715ec2023-02-13 13:46:24 -080013365 /**
13366 * Request to get whether satellite communication is allowed for the current location.
13367 *
13368 * @param subId The subId of the subscription to check whether satellite communication is
13369 * allowed for the current location for.
13370 * @param result The result receiver that returns whether satellite communication is allowed
13371 * for the current location if the request is successful or an error code
13372 * if the request failed.
13373 *
13374 * @throws SecurityException if the caller doesn't have the required permission.
13375 */
13376 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013377 public void requestIsCommunicationAllowedForCurrentLocation(int subId,
Sarah Chindf715ec2023-02-13 13:46:24 -080013378 @NonNull ResultReceiver result) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013379 enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation");
13380 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(subId,
13381 result);
Sarah Chindf715ec2023-02-13 13:46:24 -080013382 }
13383
13384 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013385 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080013386 *
Sarah Chin5f57c582023-02-14 04:16:10 -080013387 * @param subId The subId to get the time after which the satellite will be visible for.
13388 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080013389 * be visible if the request is successful or an error code if the request failed.
13390 *
13391 * @throws SecurityException if the caller doesn't have the required permission.
13392 */
13393 @Override
13394 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
13395 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013396 mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013397 }
13398
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013399 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013400 * Inform that Device is aligned to satellite for demo mode.
13401 *
13402 * @param subId The subId to get the time after which the satellite will be visible for.
13403 * @param isAligned {@code true} Device is aligned with the satellite for demo mode
13404 * {@code false} Device fails to align with the satellite for demo mode.
13405 *
13406 * @throws SecurityException if the caller doesn't have required permission.
13407 */
13408 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
13409
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013410 public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) {
Hakjun Choiae365972023-04-25 11:00:31 +000013411 enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite");
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013412 mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned);
Hakjun Choiae365972023-04-25 11:00:31 +000013413 }
13414
13415 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000013416 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
13417 * by modem.
13418 *
13419 * @param subId The subId of the subscription to request for.
13420 * @param reason Reason for disallowing satellite communication for carrier.
13421 * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the
13422 * operation.
13423 *
13424 * @throws SecurityException if the caller doesn't have required permission.
13425 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013426 public void addAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013427 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13428 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013429 enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013430 final long identity = Binder.clearCallingIdentity();
13431 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013432 mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013433 } finally {
13434 Binder.restoreCallingIdentity(identity);
13435 }
13436 }
13437
13438 /**
13439 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
13440 * by modem.
13441 *
13442 * @param subId The subId of the subscription to request for.
13443 * @param reason Reason for disallowing satellite communication.
13444 * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the
13445 * operation.
13446 *
13447 * @throws SecurityException if the caller doesn't have required permission.
13448 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013449 public void removeAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013450 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13451 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013452 enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013453 final long identity = Binder.clearCallingIdentity();
13454 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013455 mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013456 } finally {
13457 Binder.restoreCallingIdentity(identity);
13458 }
13459 }
13460
13461 /**
13462 * Get reasons for disallowing satellite communication, as requested by
13463 * {@link #addSatelliteAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
13464 *
13465 * @param subId The subId of the subscription to request for.
13466 *
13467 * @return Integer array of reasons for disallowing satellite communication.
13468 *
13469 * @throws SecurityException if the caller doesn't have the required permission.
13470 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013471 public @NonNull int[] getAttachRestrictionReasonsForCarrier(
Hakjun Choicb39db92023-07-14 15:51:12 +000013472 int subId) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013473 enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013474 final long identity = Binder.clearCallingIdentity();
13475 try {
13476 Set<Integer> reasonSet =
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013477 mSatelliteController.getAttachRestrictionReasonsForCarrier(subId);
Hakjun Choicb39db92023-07-14 15:51:12 +000013478 return reasonSet.stream().mapToInt(i->i).toArray();
13479 } finally {
13480 Binder.restoreCallingIdentity(identity);
13481 }
13482 }
13483
13484 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000013485 * Request to get the signal strength of the satellite connection.
13486 *
13487 * @param subId The subId of the subscription to request for.
13488 * @param result Result receiver to get the error code of the request and the current signal
13489 * strength of the satellite connection.
13490 *
13491 * @throws SecurityException if the caller doesn't have required permission.
13492 */
13493 @Override
13494 public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) {
13495 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
13496 final long identity = Binder.clearCallingIdentity();
13497 try {
13498 mSatelliteController.requestNtnSignalStrength(subId, result);
13499 } finally {
13500 Binder.restoreCallingIdentity(identity);
13501 }
13502 }
13503
13504 /**
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013505 * Registers for NTN signal strength changed from satellite modem. If the registration operation
13506 * is not successful, a {@link ServiceSpecificException} that contains
13507 * {@link SatelliteManager.SatelliteResult} will be thrown.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013508 *
13509 * @param subId The subId of the subscription to request for.
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013510 * @param callback The callback to handle the NTN signal strength changed event. If the
13511 * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged(
13512 * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of
13513 * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial
13514 * network has changed.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013515 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013516 * @throws SecurityException If the caller doesn't have the required permission.
13517 * @throws ServiceSpecificException If the callback registration operation fails.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013518 */
13519 @Override
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013520 public void registerForNtnSignalStrengthChanged(int subId,
13521 @NonNull INtnSignalStrengthCallback callback) throws RemoteException {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013522 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
13523 final long identity = Binder.clearCallingIdentity();
13524 try {
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013525 mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013526 } finally {
13527 Binder.restoreCallingIdentity(identity);
13528 }
13529 }
13530
13531 /**
13532 * Unregisters for NTN signal strength changed from satellite modem.
13533 * If callback was not registered before, the request will be ignored.
13534 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013535 * @param subId The subId of the subscription to unregister for listening NTN signal strength
13536 * changed event.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013537 * @param callback The callback that was passed to
13538 * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)}
13539 *
13540 * @throws SecurityException if the caller doesn't have the required permission.
13541 */
13542 @Override
13543 public void unregisterForNtnSignalStrengthChanged(
13544 int subId, @NonNull INtnSignalStrengthCallback callback) {
13545 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
13546 final long identity = Binder.clearCallingIdentity();
13547 try {
13548 mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback);
13549 } finally {
13550 Binder.restoreCallingIdentity(identity);
13551 }
13552 }
13553
13554 /**
Hakjun Choi8d96a562023-10-26 15:01:40 +000013555 * Registers for satellite capabilities change event from the satellite service.
13556 *
13557 * @param subId The subId of the subscription to request for.
13558 * @param callback The callback to handle the satellite capabilities changed event.
13559 *
13560 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13561 *
13562 * @throws SecurityException if the caller doesn't have required permission.
13563 */
13564 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013565 @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged(
Hakjun Choi8d96a562023-10-26 15:01:40 +000013566 int subId, @NonNull ISatelliteCapabilitiesCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013567 enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013568 final long identity = Binder.clearCallingIdentity();
13569 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013570 return mSatelliteController.registerForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013571 } finally {
13572 Binder.restoreCallingIdentity(identity);
13573 }
13574 }
13575
13576 /**
13577 * Unregisters for satellite capabilities change event from the satellite service.
13578 * If callback was not registered before, the request will be ignored.
13579 *
13580 * @param subId The subId of the subscription to unregister for satellite capabilities change.
13581 * @param callback The callback that was passed to.
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013582 * {@link #registerForCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}.
Hakjun Choi8d96a562023-10-26 15:01:40 +000013583 *
13584 * @throws SecurityException if the caller doesn't have required permission.
13585 */
13586 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013587 public void unregisterForCapabilitiesChanged(int subId,
13588 @NonNull ISatelliteCapabilitiesCallback callback) {
13589 enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013590 final long identity = Binder.clearCallingIdentity();
13591 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013592 mSatelliteController.unregisterForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013593 } finally {
13594 Binder.restoreCallingIdentity(identity);
13595 }
13596 }
13597
13598 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013599 * This API can be used by only CTS to update satellite vendor service package name.
13600 *
13601 * @param servicePackageName The package name of the satellite vendor service.
13602 * @return {@code true} if the satellite vendor service is set successfully,
13603 * {@code false} otherwise.
13604 */
13605 public boolean setSatelliteServicePackageName(String servicePackageName) {
13606 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName);
13607 TelephonyPermissions.enforceShellOnly(
13608 Binder.getCallingUid(), "setSatelliteServicePackageName");
13609 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13610 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13611 "setSatelliteServicePackageName");
13612 return mSatelliteController.setSatelliteServicePackageName(servicePackageName);
13613 }
13614
13615 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070013616 * This API can be used by only CTS to update satellite gateway service package name.
13617 *
13618 * @param servicePackageName The package name of the satellite gateway service.
13619 * @return {@code true} if the satellite gateway service is set successfully,
13620 * {@code false} otherwise.
13621 */
13622 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
13623 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
13624 TelephonyPermissions.enforceShellOnly(
13625 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
13626 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13627 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13628 "setSatelliteGatewayServicePackageName");
13629 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
13630 }
13631
13632 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070013633 * This API can be used by only CTS to update satellite pointing UI app package and class names.
13634 *
13635 * @param packageName The package name of the satellite pointing UI app.
13636 * @param className The class name of the satellite pointing UI app.
13637 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
13638 * {@code false} otherwise.
13639 */
13640 public boolean setSatellitePointingUiClassName(
13641 @Nullable String packageName, @Nullable String className) {
13642 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
13643 + ", className=" + className);
13644 TelephonyPermissions.enforceShellOnly(
13645 Binder.getCallingUid(), "setSatellitePointingUiClassName");
13646 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13647 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13648 "setSatelliteGatewayServicePackageName");
13649 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
13650 }
13651
13652 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070013653 * This API can be used by only CTS to update the timeout duration in milliseconds that
13654 * satellite should stay at listening mode to wait for the next incoming page before disabling
13655 * listening mode.
13656 *
13657 * @param timeoutMillis The timeout duration in millisecond.
13658 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13659 */
13660 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
13661 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
13662 TelephonyPermissions.enforceShellOnly(
13663 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
13664 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13665 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13666 "setSatelliteListeningTimeoutDuration");
13667 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
13668 }
13669
13670 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013671 * This API can be used by only CTS to override the timeout durations used by the
13672 * DatagramController module.
Hakjun Choiae365972023-04-25 11:00:31 +000013673 *
13674 * @param timeoutMillis The timeout duration in millisecond.
13675 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13676 */
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013677 public boolean setDatagramControllerTimeoutDuration(
13678 boolean reset, int timeoutType, long timeoutMillis) {
13679 Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset="
13680 + reset + ", timeoutMillis=" + timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013681 TelephonyPermissions.enforceShellOnly(
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013682 Binder.getCallingUid(), "setDatagramControllerTimeoutDuration");
Hakjun Choiae365972023-04-25 11:00:31 +000013683 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13684 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013685 "setDatagramControllerTimeoutDuration");
13686 return mSatelliteController.setDatagramControllerTimeoutDuration(
13687 reset, timeoutType, timeoutMillis);
13688 }
13689
13690 /**
13691 * This API can be used by only CTS to override the timeout durations used by the
13692 * SatelliteController module.
13693 *
13694 * @param timeoutMillis The timeout duration in millisecond.
13695 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13696 */
13697 public boolean setSatelliteControllerTimeoutDuration(
13698 boolean reset, int timeoutType, long timeoutMillis) {
13699 Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset="
13700 + reset + ", timeoutMillis=" + timeoutMillis);
13701 TelephonyPermissions.enforceShellOnly(
13702 Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration");
13703 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13704 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13705 "setSatelliteControllerTimeoutDuration");
13706 return mSatelliteController.setSatelliteControllerTimeoutDuration(
13707 reset, timeoutType, timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013708 }
13709
13710 /**
Thomas Nguyen11a051f2023-10-25 10:14:55 -070013711 * This API can be used in only testing to override connectivity status in monitoring emergency
13712 * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.
13713 *
13714 * @param handoverType The type of handover from emergency call to satellite messaging. Use one
13715 * of the following values to enable the override:
13716 * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS
13717 * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911
13718 * To disable the override, use -1 for handoverType.
13719 * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer
13720 * delaySeconds after the emergency call starts.
13721 * @return {@code true} if the handover type is set successfully, {@code false} otherwise.
13722 */
13723 public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) {
13724 Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType);
13725 TelephonyPermissions.enforceShellOnly(
13726 Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType");
13727 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13728 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13729 "setEmergencyCallToSatelliteHandoverType");
13730 return mSatelliteController.setEmergencyCallToSatelliteHandoverType(
13731 handoverType, delaySeconds);
13732 }
13733
13734 /**
Thomas Nguyen3d602742024-01-19 11:29:35 -080013735 * This API can be used in only testing to override oem-enabled satellite provision status.
13736 *
13737 * @param reset {@code true} mean the overriding status should not be used, {@code false}
13738 * otherwise.
13739 * @param isProvisioned The overriding provision status.
13740 * @return {@code true} if the provision status is set successfully, {@code false} otherwise.
13741 */
13742 public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) {
13743 Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset
13744 + ", isProvisioned=" + isProvisioned);
13745 TelephonyPermissions.enforceShellOnly(
13746 Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus");
13747 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13748 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13749 "setOemEnabledSatelliteProvisionStatus");
13750 return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned);
13751 }
13752
13753 /**
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013754 * This API should be used by only CTS tests to forcefully set telephony country codes.
13755 *
13756 * @return {@code true} if the country code is set successfully, {@code false} otherwise.
13757 */
13758 public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes,
13759 Map cachedNetworkCountryCodes, String locationCountryCode,
13760 long locationCountryCodeTimestampNanos) {
13761 Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes="
13762 + String.join(", ", currentNetworkCountryCodes)
13763 + ", locationCountryCode=" + locationCountryCode
13764 + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos
13765 + ", reset=" + reset + ", cachedNetworkCountryCodes="
13766 + String.join(", ", cachedNetworkCountryCodes.keySet()));
13767 TelephonyPermissions.enforceShellOnly(
13768 Binder.getCallingUid(), "setCachedLocationCountryCode");
13769 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13770 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13771 "setCachedLocationCountryCode");
13772 return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext()).setCountryCodes(
13773 reset, currentNetworkCountryCodes, cachedNetworkCountryCodes, locationCountryCode,
13774 locationCountryCodeTimestampNanos);
13775 }
13776
13777 /**
13778 * This API should be used by only CTS tests to override the overlay configs of satellite
13779 * access controller.
13780 *
13781 * @param reset {@code true} mean the overridden configs should not be used, {@code false}
13782 * otherwise.
13783 * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise.
13784 */
13785 public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed,
13786 String s2CellFile, long locationFreshDurationNanos,
13787 List<String> satelliteCountryCodes) {
13788 Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset
13789 + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile
13790 + ", locationFreshDurationNanos=" + locationFreshDurationNanos
13791 + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null)
13792 ? String.join(", ", satelliteCountryCodes) : null));
13793 TelephonyPermissions.enforceShellOnly(
13794 Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs");
13795 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13796 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13797 "setSatelliteAccessControlOverlayConfigs");
13798 return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset, isAllowed,
13799 s2CellFile, locationFreshDurationNanos, satelliteCountryCodes);
13800 }
13801
13802 /**
Hakjun Choibc6ce992023-11-07 16:04:33 +000013803 * This API can be used by only CTS to override the cached value for the device overlay config
13804 * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether
13805 * outgoing satellite datagrams should be sent to modem in demo mode.
13806 *
13807 * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to
13808 * satellite modem or not.
13809 *
13810 * @return {@code true} if the operation is successful, {@code false} otherwise.
13811 */
13812 public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) {
13813 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
13814 Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is "
13815 + "disabled");
13816 return false;
13817 }
13818 Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode");
13819 TelephonyPermissions.enforceShellOnly(
13820 Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode");
13821 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13822 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13823 "setShouldSendDatagramToModemInDemoMode");
13824 return mSatelliteController.setShouldSendDatagramToModemInDemoMode(
13825 shouldSendToModemInDemoMode);
13826 }
13827
13828 /**
Hunsuk Choi13078be2023-09-13 10:55:21 +000013829 * Sets the service defined in ComponentName to be bound.
13830 *
13831 * This should only be used for testing.
13832 * @return {@code true} if the DomainSelectionService to bind to was set,
13833 * {@code false} otherwise.
13834 */
13835 @Override
13836 public boolean setDomainSelectionServiceOverride(ComponentName componentName) {
13837 Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName);
13838
13839 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
13840 "setDomainSelectionServiceOverride");
13841 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13842 getDefaultSubscription(), "setDomainSelectionServiceOverride");
13843
13844 final long identity = Binder.clearCallingIdentity();
13845 try {
13846 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13847 return DomainSelectionResolver.getInstance()
13848 .setDomainSelectionServiceOverride(componentName);
13849 }
13850 } finally {
13851 Binder.restoreCallingIdentity(identity);
13852 }
13853 return false;
13854 }
13855
13856 /**
13857 * Clears the DomainSelectionService override.
13858 *
13859 * This should only be used for testing.
13860 * @return {@code true} if the DomainSelectionService override was cleared,
13861 * {@code false} otherwise.
13862 */
13863 @Override
13864 public boolean clearDomainSelectionServiceOverride() {
13865 Log.i(LOG_TAG, "clearDomainSelectionServiceOverride");
13866
13867 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
13868 "clearDomainSelectionServiceOverride");
13869 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13870 getDefaultSubscription(), "clearDomainSelectionServiceOverride");
13871
13872 final long identity = Binder.clearCallingIdentity();
13873 try {
13874 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13875 return DomainSelectionResolver.getInstance()
13876 .clearDomainSelectionServiceOverride();
13877 }
13878 } finally {
13879 Binder.restoreCallingIdentity(identity);
13880 }
13881 return false;
13882 }
13883
13884 /**
Gil Cukierman06403e12023-11-29 16:33:03 +000013885 * Enable or disable notifications sent for cellular identifier disclosure events.
13886 *
13887 * Disclosure events are defined as instances where a device has sent a cellular identifier
13888 * on the Non-access stratum (NAS) before a security context is established. As a result the
13889 * identifier is sent in the clear, which has privacy implications for the user.
13890 *
13891 * @param enable if notifications about disclosure events should be enabled
13892 * @throws SecurityException if the caller does not have the required privileges
13893 * @throws UnsupportedOperationException if the modem does not support this feature.
13894 */
13895 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000013896 public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) {
Gil Cukierman06403e12023-11-29 16:33:03 +000013897 enforceModifyPermission();
13898 checkForIdentifierDisclosureNotificationSupport();
13899
13900 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
13901 editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable);
13902 editor.apply();
13903
13904 // Each phone instance is responsible for updating its respective modem immediately
13905 // after we've made a preference change.
13906 for (Phone phone : PhoneFactory.getPhones()) {
13907 phone.handleIdentifierDisclosureNotificationPreferenceChange();
13908 }
13909 }
13910
13911 /**
13912 * Get whether or not cellular identifier disclosure notifications are enabled.
13913 *
13914 * @throws SecurityException if the caller does not have the required privileges
13915 * @throws UnsupportedOperationException if the modem does not support this feature.
13916 */
13917 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000013918 public boolean isCellularIdentifierDisclosureNotificationsEnabled() {
Gil Cukierman06403e12023-11-29 16:33:03 +000013919 enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled");
13920 checkForIdentifierDisclosureNotificationSupport();
13921 return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled();
13922 }
13923
13924 /**
Michael Groover826b71d2023-12-21 22:08:06 -060013925 * Enables or disables notifications sent when cellular null cipher or integrity algorithms
13926 * are in use by the cellular modem.
13927 *
13928 * @throws IllegalStateException if the Telephony process is not currently available
13929 * @throws SecurityException if the caller does not have the required privileges
13930 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
13931 * and integrity algorithms in use
13932 * @hide
13933 */
13934 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Michael Grooverae447b22024-01-24 22:35:46 -060013935 public void setNullCipherNotificationsEnabled(boolean enable) {
Michael Groover826b71d2023-12-21 22:08:06 -060013936 enforceModifyPermission();
13937 checkForNullCipherNotificationSupport();
13938
13939 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
13940 editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable);
13941 editor.apply();
13942
13943 // Each phone instance is responsible for updating its respective modem immediately
13944 // after a preference change.
13945 for (Phone phone : PhoneFactory.getPhones()) {
13946 phone.handleNullCipherNotificationPreferenceChanged();
13947 }
13948 }
13949
13950 /**
13951 * Get whether notifications are enabled for null cipher or integrity algorithms in use by the
13952 * cellular modem.
13953 *
13954 * @throws IllegalStateException if the Telephony process is not currently available
13955 * @throws SecurityException if the caller does not have the required privileges
13956 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
13957 * and integrity algorithms in use
13958 * @hide
13959 */
13960 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
13961 public boolean isNullCipherNotificationsEnabled() {
13962 enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled");
13963 checkForNullCipherNotificationSupport();
13964 return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled();
13965 }
13966
13967 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000013968 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
13969 *
13970 * <p>This method behaves in one of the following ways:
13971 * <ul>
13972 * <li>return true : if the calling package has the appop permission {@link
13973 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
13974 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
13975 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
13976 * Owner device identifier access check, or the calling package has carrier privileges</>
13977 * <li>throw SecurityException: if the caller does not meet any of the requirements.
13978 * </ul>
13979 */
13980 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
13981 String callingPackage, @Nullable String callingFeatureId, String message) {
13982 for (Phone phone : PhoneFactory.getPhones()) {
13983 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
13984 phone.getSubId(), callingPackage, callingFeatureId, message)) {
13985 return true;
13986 }
13987 }
13988 return false;
13989 }
arunvoddud7401012022-12-15 16:08:12 +000013990
13991 /**
Jack Yufa8ed012023-02-11 15:42:28 -080013992 * @return The subscription manager service instance.
13993 */
13994 public SubscriptionManagerService getSubscriptionManagerService() {
13995 return SubscriptionManagerService.getInstance();
13996 }
13997
13998 /**
arunvoddud7401012022-12-15 16:08:12 +000013999 * Class binds the consumer[callback] and carrierId.
14000 */
14001 private static class CallerCallbackInfo {
14002 private final Consumer<Integer> mConsumer;
14003 private final int mCarrierId;
14004
14005 public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) {
14006 mConsumer = consumer;
14007 mCarrierId = carrierId;
14008 }
14009
14010 public Consumer<Integer> getConsumer() {
14011 return mConsumer;
14012 }
14013
14014 public int getCarrierId() {
14015 return mCarrierId;
14016 }
14017 }
joonhunshin4ac60942023-11-15 15:23:39 +000014018
14019 /*
14020 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14021 * But the context that is passed in is unused if the phone app is already alive.
14022 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14023 */
14024 @VisibleForTesting
14025 public void setPackageManager(PackageManager packageManager) {
14026 mPackageManager = packageManager;
14027 }
14028
14029 /*
Nate Myren453c3472024-03-13 11:28:11 -070014030 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14031 * But the context that is passed in is unused if the phone app is already alive.
14032 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14033 */
14034 @VisibleForTesting
14035 public void setAppOpsManager(AppOpsManager appOps) {
14036 mAppOps = appOps;
14037 }
14038
14039 /*
joonhunshin4ac60942023-11-15 15:23:39 +000014040 * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags.
14041 * But the FeatureFlags that is passed in is unused if the phone app is already alive.
14042 * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test.
14043 */
14044 @VisibleForTesting
14045 public void setFeatureFlags(FeatureFlags featureFlags) {
14046 mFeatureFlags = featureFlags;
14047 }
14048
14049 /**
14050 * Make sure the device has required telephony feature
14051 *
14052 * @throws UnsupportedOperationException if the device does not have required telephony feature
14053 */
14054 private void enforceTelephonyFeatureWithException(@Nullable String callingPackage,
14055 @NonNull String telephonyFeature, @NonNull String methodName) {
14056 if (callingPackage == null || mPackageManager == null) {
14057 return;
14058 }
14059
14060 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
14061 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage,
14062 Binder.getCallingUserHandle())) {
14063 return;
14064 }
14065
14066 if (!mPackageManager.hasSystemFeature(telephonyFeature)) {
14067 throw new UnsupportedOperationException(
14068 methodName + " is unsupported without " + telephonyFeature);
14069 }
14070 }
Jack Yufa8ed012023-02-11 15:42:28 -080014071}